From 864eb2126983977f9d7d7db12592fff0c8ede1cb Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 26 Aug 2019 17:50:44 +0800 Subject: Changing lazy mode interval in Settings is now available. --- app/src/main/AndroidManifest.xml | 3 +- .../infinityforreddit/LoginActivity.java | 9 ++++ .../infinityforreddit/MainActivity.java | 2 +- .../infinityforreddit/NotificationUtils.java | 9 ++-- .../infinityforreddit/PostFragment.java | 17 ++++-- .../infinityforreddit/PullNotificationWorker.java | 6 +-- .../infinityforreddit/SharedPreferencesUtils.java | 1 + app/src/main/res/layout/activity_login.xml | 21 ++++++-- app/src/main/res/layout/item_post_detail.xml | 62 ---------------------- app/src/main/res/values/arrays.xml | 16 ++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/main_preferences.xml | 9 ++++ 12 files changed, 77 insertions(+), 79 deletions(-) (limited to 'app') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5b41bd5d..46d43af7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -150,7 +150,8 @@ + android:parentActivityName=".MainActivity" + android:theme="@style/AppTheme.NoActionBar" /> = Build.VERSION_CODES.Q; int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); switch (themeType) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index 86446023..8488adbc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -1055,7 +1055,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe } } - public void changeNSFW(boolean nsfw) { + void changeNSFW(boolean nsfw) { if(frontPagePostFragment != null) { frontPagePostFragment.changeNSFW(nsfw); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java index ce71a57e..2fc832d5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java @@ -9,10 +9,11 @@ import androidx.core.app.NotificationManagerCompat; class NotificationUtils { static final String CHANNEL_POST_MEDIA = "Post Media"; - static final String CHANNEL_ID_NEW_COMMENTS = "new_comments"; - static final String CHANNEL_NEW_COMMENTS = "New Comments"; - static final int SUMMARY_BASE_ID_UNREAD_MESSAGE = 0; - static final int NOTIFICATION_BASE_ID_UNREAD_MESSAGE = 1; + static final String CHANNEL_ID_NEW_MESSAGES = "new_messages"; + static final String CHANNEL_NEW_MESSAGES = "New Messages"; + + private static final int SUMMARY_BASE_ID_UNREAD_MESSAGE = 0; + private static final int NOTIFICATION_BASE_ID_UNREAD_MESSAGE = 1; private static final String GROUP_USER_BASE = "ml.docilealligator.infinityforreddit."; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index a1267632..493d0a27 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -86,6 +86,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private Runnable lazyModeRunnable; private CountDownTimer resumeLazyModeCountDownTimer; + private float lazyModeInterval; + @Inject @Named("no_oauth") Retrofit mRetrofit; @@ -124,6 +126,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { lazyModeHandler = new Handler(); + lazyModeInterval = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.LAZY_MODE_INTERVAL_KEY, "2.5")); + smoothScroller = new LinearSmoothScroller(activity) { @Override protected int getVerticalSnapPreference() { @@ -157,11 +161,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mLinearLayoutManager.startSmoothScroll(smoothScroller); } } - lazyModeHandler.postDelayed(this, 2500); + lazyModeHandler.postDelayed(this, (long) (lazyModeInterval * 1000)); } }; - resumeLazyModeCountDownTimer = new CountDownTimer(2500, 2500) { + resumeLazyModeCountDownTimer = new CountDownTimer((long) (lazyModeInterval * 1000), (long) (lazyModeInterval * 1000)) { @Override public void onTick(long l) { @@ -416,9 +420,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator { public void startLazyMode() { isInLazyMode = true; isLazyModePaused = false; - lazyModeHandler.postDelayed(lazyModeRunnable, 2500); + + lazyModeInterval = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.LAZY_MODE_INTERVAL_KEY, "2.5")); + lazyModeHandler.postDelayed(lazyModeRunnable, (long) (lazyModeInterval * 1000)); window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - Toast.makeText(activity, getString(R.string.lazy_mode_start, 2.5), Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, getString(R.string.lazy_mode_start, lazyModeInterval), + Toast.LENGTH_SHORT).show(); } @Override @@ -439,7 +446,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if(resumeNow) { lazyModeHandler.post(lazyModeRunnable); } else { - lazyModeHandler.postDelayed(lazyModeRunnable, 2500); + lazyModeHandler.postDelayed(lazyModeRunnable, (long) (lazyModeInterval * 1000)); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java index 6c2e5f75..46cffca7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java @@ -77,7 +77,7 @@ public class PullNotificationWorker extends Worker { NotificationCompat.Builder summaryBuilder = NotificationUtils.buildSummaryNotification(context, notificationManager, accountName, context.getString(R.string.notification_new_messages, messages.size()), - NotificationUtils.CHANNEL_ID_NEW_COMMENTS, NotificationUtils.CHANNEL_NEW_COMMENTS, + NotificationUtils.CHANNEL_ID_NEW_MESSAGES, NotificationUtils.CHANNEL_NEW_MESSAGES, NotificationUtils.getAccountGroupName(accountName)); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); @@ -110,8 +110,8 @@ public class PullNotificationWorker extends Worker { NotificationCompat.Builder builder = NotificationUtils.buildNotification(notificationManager, context, title, message.getBody(), summary, - NotificationUtils.CHANNEL_ID_NEW_COMMENTS, - NotificationUtils.CHANNEL_NEW_COMMENTS, + NotificationUtils.CHANNEL_ID_NEW_MESSAGES, + NotificationUtils.CHANNEL_NEW_MESSAGES, NotificationUtils.getAccountGroupName(accountName)); if(kind.equals(Message.TYPE_COMMENT)) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java index d0673942..061c94df 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java @@ -7,6 +7,7 @@ package ml.docilealligator.infinityforreddit; public class SharedPreferencesUtils { public static final String ENABLE_NOTIFICATION_KEY = "enable_notification"; public static final String NOTIFICATION_INTERVAL_KEY = "notificaiton_interval"; + public static final String LAZY_MODE_INTERVAL_KEY = "lazy_mode_interval"; public static final String NSFW_KEY = "nsfw"; public static final String THEME_KEY = "theme"; } diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 236d52e4..e993cd2d 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -1,14 +1,29 @@ - + + + + + + + android:layout_height="match_parent" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> - + diff --git a/app/src/main/res/layout/item_post_detail.xml b/app/src/main/res/layout/item_post_detail.xml index b1299ca5..32a0f3b1 100644 --- a/app/src/main/res/layout/item_post_detail.xml +++ b/app/src/main/res/layout/item_post_detail.xml @@ -169,68 +169,6 @@ - - 1 2 + + + 2.5s + 3s + 5s + 7s + 10s + + + + 2.5 + 3 + 5 + 7 + 10 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 09740a2f..2d19ae76 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -258,6 +258,7 @@ Light Theme Dark Theme Device default + Lazy Mode Interval Enable NSFW Acknowledgement diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index 7ccfa301..7d482fae 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -16,6 +16,15 @@ app:title="@string/settings_theme_title" app:useSimpleSummaryProvider="true" /> + +