diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index fceb7dda..2bd3538b 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -2713,11 +2713,12 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener JSONObject item = array.getJSONObject(i); String claimId = item.getString("claim_id"); String channelName = item.getString("channel_name"); + boolean isNotificationsDisabled = item.getBoolean("is_notifications_disabled"); LbryUri url = new LbryUri(); url.setChannelName(channelName); url.setClaimId(claimId); - subscriptions.add(new Subscription(channelName, url.toString())); + subscriptions.add(new Subscription(channelName, url.toString(), isNotificationsDisabled)); subUrls.add(url.toString()); } Lbryio.subscriptions = subscriptions; diff --git a/app/src/main/java/io/lbry/browser/data/DatabaseHelper.java b/app/src/main/java/io/lbry/browser/data/DatabaseHelper.java index 9aece297..1d1a18f6 100644 --- a/app/src/main/java/io/lbry/browser/data/DatabaseHelper.java +++ b/app/src/main/java/io/lbry/browser/data/DatabaseHelper.java @@ -21,13 +21,13 @@ import io.lbry.browser.utils.Helper; import io.lbry.browser.utils.LbryUri; public class DatabaseHelper extends SQLiteOpenHelper { - public static final int DATABASE_VERSION = 7; + public static final int DATABASE_VERSION = 8; public static final String DATABASE_NAME = "LbryApp.db"; private static DatabaseHelper instance; private static final String[] SQL_CREATE_TABLES = { // local subscription store - "CREATE TABLE subscriptions (url TEXT PRIMARY KEY NOT NULL, channel_name TEXT NOT NULL)", + "CREATE TABLE subscriptions (url TEXT PRIMARY KEY NOT NULL, channel_name TEXT NOT NULL, is_notifications_disabled INTEGER DEFAULT 0 NOT NULL)", // url entry / suggestion history "CREATE TABLE url_history (id INTEGER PRIMARY KEY NOT NULL, value TEXT NOT NULL, url TEXT, type INTEGER NOT NULL, timestamp TEXT NOT NULL)", // tags (known and followed) @@ -105,11 +105,15 @@ public class DatabaseHelper extends SQLiteOpenHelper { "CREATE TABLE shuffle_watched (id INTEGER PRIMARY KEY NOT NULL, claim_id TEXT NOT NULL)", "CREATE UNIQUE INDEX idx_shuffle_watched_claim ON shuffle_watched (claim_id)" }; + private static final String[] SQL_V7_V8_UPGRADE = { + "AlTER TABLE subscriptions ADD COLUMN is_notifications_disabled INTEGER DEFAULT 0 NOT NULL" + }; - private static final String SQL_INSERT_SUBSCRIPTION = "REPLACE INTO subscriptions (channel_name, url) VALUES (?, ?)"; + private static final String SQL_INSERT_SUBSCRIPTION = "REPLACE INTO subscriptions (channel_name, url, is_notifications_disabled) VALUES (?, ?, ?)"; + private static final String SQL_UPDATE_SUBSCRIPTION_NOTIFICATION = "UPDATE subscriptions SET is_notification_disabled = ? WHERE url = ?"; private static final String SQL_CLEAR_SUBSCRIPTIONS = "DELETE FROM subscriptions"; private static final String SQL_DELETE_SUBSCRIPTION = "DELETE FROM subscriptions WHERE url = ?"; - private static final String SQL_GET_SUBSCRIPTIONS = "SELECT channel_name, url FROM subscriptions"; + private static final String SQL_GET_SUBSCRIPTIONS = "SELECT channel_name, url, is_notifications_disabled FROM subscriptions"; private static final String SQL_INSERT_URL_HISTORY = "REPLACE INTO url_history (value, url, type, timestamp) VALUES (?, ?, ?, ?)"; private static final String SQL_CLEAR_URL_HISTORY = "DELETE FROM url_history"; @@ -188,6 +192,11 @@ public class DatabaseHelper extends SQLiteOpenHelper { db.execSQL(sql); } } + if (oldVersion < 8) { + for (String sql : SQL_V7_V8_UPGRADE) { + db.execSQL(sql); + } + } } public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { @@ -304,7 +313,14 @@ public class DatabaseHelper extends SQLiteOpenHelper { } public static void createOrUpdateSubscription(Subscription subscription, SQLiteDatabase db) { - db.execSQL(SQL_INSERT_SUBSCRIPTION, new Object[] { subscription.getChannelName(), subscription.getUrl() }); + db.execSQL(SQL_INSERT_SUBSCRIPTION, new Object[] { + subscription.getChannelName(), + subscription.getUrl(), + subscription.isNotificationsDisabled() ? 1 : 0 + }); + } + public static void setSubscriptionNotificationDisabled(boolean flag, String url, SQLiteDatabase db) { + db.execSQL(SQL_UPDATE_SUBSCRIPTION_NOTIFICATION, new Object[] { flag ? 1 : 0, url }); } public static void deleteSubscription(Subscription subscription, SQLiteDatabase db) { db.execSQL(SQL_DELETE_SUBSCRIPTION, new Object[] { subscription.getUrl() }); @@ -321,6 +337,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { Subscription subscription = new Subscription(); subscription.setChannelName(cursor.getString(0)); subscription.setUrl(cursor.getString(1)); + subscription.setNotificationsDisabled(cursor.getInt(2) == 1); subscriptions.add(subscription); } } finally { diff --git a/app/src/main/java/io/lbry/browser/model/lbryinc/Subscription.java b/app/src/main/java/io/lbry/browser/model/lbryinc/Subscription.java index 30f2412a..6d302e52 100644 --- a/app/src/main/java/io/lbry/browser/model/lbryinc/Subscription.java +++ b/app/src/main/java/io/lbry/browser/model/lbryinc/Subscription.java @@ -11,17 +11,21 @@ public class Subscription { @Getter @Setter private String url; + @Getter + @Setter + private boolean isNotificationsDisabled; public Subscription() { } - public Subscription(String channelName, String url) { + public Subscription(String channelName, String url, boolean isNotificationsDisabled) { this.channelName = channelName; this.url = url; + this.isNotificationsDisabled = isNotificationsDisabled; } public static Subscription fromClaim(Claim claim) { - return new Subscription(claim.getName(), claim.getPermanentUrl()); + return new Subscription(claim.getName(), claim.getPermanentUrl(), false); } public String toString() { return url; diff --git a/app/src/main/java/io/lbry/browser/tasks/MergeSubscriptionsTask.java b/app/src/main/java/io/lbry/browser/tasks/MergeSubscriptionsTask.java index 2d516e13..842c381e 100644 --- a/app/src/main/java/io/lbry/browser/tasks/MergeSubscriptionsTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/MergeSubscriptionsTask.java @@ -76,13 +76,15 @@ public class MergeSubscriptionsTask extends AsyncTask { options.put("claim_id", channelClaimId); if (!isUnsubscribing) { options.put("channel_name", subscription.getChannelName()); + options.put("notifications_disabled", String.valueOf(subscription.isNotificationsDisabled()).toLowerCase()); } String action = isUnsubscribing ? "delete" : "new"; - Lbryio.call("subscription", action, options, context); - + Object response = Lbryio.parseResponse(Lbryio.call("subscription", action, options, context)); if (!isUnsubscribing) { Lbryio.addSubscription(subscription); } else { diff --git a/app/src/main/java/io/lbry/browser/tasks/lbryinc/FetchSubscriptionsTask.java b/app/src/main/java/io/lbry/browser/tasks/lbryinc/FetchSubscriptionsTask.java index da886beb..e3c2a1f8 100644 --- a/app/src/main/java/io/lbry/browser/tasks/lbryinc/FetchSubscriptionsTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/lbryinc/FetchSubscriptionsTask.java @@ -49,11 +49,12 @@ public class FetchSubscriptionsTask extends AsyncTask()); commentChannelSpinnerAdapter.addPlaceholder(false); @@ -2524,13 +2558,18 @@ public class FileViewFragment extends BaseFragment implements private void checkIsFollowing() { if (claim != null && claim.getSigningChannel() != null) { boolean isFollowing = Lbryio.isFollowing(claim.getSigningChannel()); + boolean notificationsDisabled = Lbryio.isNotificationsDisabled(claim.getSigningChannel()); Context context = getContext(); View root = getView(); if (context != null && root != null) { OutlineIconView iconFollow = root.findViewById(R.id.file_view_icon_follow); SolidIconView iconUnfollow = root.findViewById(R.id.file_view_icon_unfollow); - Helper.setViewVisibility(iconFollow, !isFollowing ? View.VISIBLE: View.INVISIBLE); - Helper.setViewVisibility(iconUnfollow, isFollowing ? View.VISIBLE : View.INVISIBLE); + SolidIconView iconBell = root.findViewById(R.id.file_view_icon_bell); + Helper.setViewVisibility(iconFollow, !isFollowing ? View.VISIBLE: View.GONE); + Helper.setViewVisibility(iconUnfollow, isFollowing ? View.VISIBLE : View.GONE); + Helper.setViewVisibility(iconBell, isFollowing ? View.VISIBLE : View.GONE); + + iconBell.setText(notificationsDisabled ? R.string.fa_bell : R.string.fa_bell_slash); } } } diff --git a/app/src/main/java/io/lbry/browser/utils/Lbryio.java b/app/src/main/java/io/lbry/browser/utils/Lbryio.java index 796ac65d..51f99eb4 100644 --- a/app/src/main/java/io/lbry/browser/utils/Lbryio.java +++ b/app/src/main/java/io/lbry/browser/utils/Lbryio.java @@ -333,6 +333,15 @@ public final class Lbryio { } } + public static void updateSubscriptionNotificationsDisabled(Subscription subscription) { + synchronized (lock) { + int index = subscriptions.indexOf(subscription); + if (index > -1) { + subscriptions.get(index).setNotificationsDisabled(subscription.isNotificationsDisabled()); + } + } + } + public static void addSubscription(Subscription subscription) { synchronized (lock) { if (!subscriptions.contains(subscription)) { @@ -364,6 +373,15 @@ public final class Lbryio { public static boolean isFollowing(Claim claim) { return subscriptions.contains(Subscription.fromClaim(claim)); } + public static boolean isNotificationsDisabled(Claim claim) { + Subscription sub = Subscription.fromClaim(claim); + int index = subscriptions.indexOf(sub); + if (index > -1) { + Subscription actual = subscriptions.get(subscriptions.indexOf(sub)); + return actual.isNotificationsDisabled(); + } + return false; + } public static void updateRewardsLists(List rewards) { synchronized (lock) { diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index 9cd5b5a1..84797cb4 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -224,9 +224,27 @@ android:layout_width="24dp" android:layout_height="24dp" android:text="@string/fa_heart_broken" + android:textColor="@color/foreground" android:textSize="20dp" android:visibility="invisible"/> + + + diff --git a/app/src/main/res/layout/fragment_file_view.xml b/app/src/main/res/layout/fragment_file_view.xml index 97fa2df9..d62cbbfc 100644 --- a/app/src/main/res/layout/fragment_file_view.xml +++ b/app/src/main/res/layout/fragment_file_view.xml @@ -503,7 +503,6 @@ android:id="@+id/file_view_publisher_area" android:layout_width="match_parent" android:layout_height="wrap_content"> - + android:layout_toStartOf="@id/file_view_publisher_area_actions"> - + android:layout_alignParentEnd="true"> + - + + + + Content Website reposted + You will receive all notifications + You will not receive notifications for this channel %1$s follower %1$s followers