From 7522b5f083d0873d9d6ade33ab8add49208ef8fc Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 6 Jul 2021 11:26:24 -0400 Subject: [PATCH] finish up stories viewer UI close #537, close #1554 --- .../fragments/StoryViewerFragment.kt | 39 +++++++++++++++---- .../fragments/settings/PreferenceKeys.kt | 1 + .../settings/StoriesPreferencesFragment.java | 10 +++++ .../instagrabber/utils/SettingsHelper.kt | 1 + .../viewmodels/StoryFragmentViewModel.kt | 4 +- app/src/main/res/values/strings.xml | 2 + 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt index 121c8150..db28e689 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt @@ -240,6 +240,15 @@ class StoryViewerFragment : Fragment() { storyMedias.set(0, newItem) storiesAdapter!!.submitList(storyMedias) storiesViewModel.setMedia(0) + binding.listToggle.setEnabled(true) + binding.storiesList.setVisibility( + if (Utils.settingsHelper.getBoolean(PreferenceKeys.PREF_STORY_SHOW_LIST)) View.VISIBLE + else View.GONE + ) + } + else { + binding.listToggle.setEnabled(false) + binding.storiesList.setVisibility(View.GONE) } }) storiesViewModel.getDate().observe(fragmentActivity, { @@ -268,6 +277,12 @@ class StoryViewerFragment : Fragment() { binding.btnShare.setOnClickListener({ _ -> shareStoryViaDm() }) binding.btnReply.setOnClickListener({ _ -> createReplyDialog(null) }) binding.stickers.setOnClickListener({ _ -> showStickerMenu() }) + binding.listToggle.setOnClickListener({ _ -> + binding.storiesList.setVisibility( + if (binding.storiesList.visibility == View.GONE) View.VISIBLE + else View.GONE + ) + }) } @SuppressLint("ClickableViewAccessibility") @@ -297,10 +312,22 @@ class StoryViewerFragment : Fragment() { if (models != null) { when (it) { StoryPaginationType.FORWARD -> { - paginateStories(false, currentFeedStoryIndex == models.size - 2) + if (currentFeedStoryIndex == models.size - 1) + Toast.makeText( + context, + R.string.no_more_stories, + Toast.LENGTH_SHORT + ).show() + else paginateStories(false, currentFeedStoryIndex == models.size - 2) } StoryPaginationType.BACKWARD -> { - paginateStories(true, false) + if (currentFeedStoryIndex == 0) + Toast.makeText( + context, + R.string.no_more_stories, + Toast.LENGTH_SHORT + ).show() + else paginateStories(true, false) } StoryPaginationType.ERROR -> { Toast.makeText( @@ -356,7 +383,6 @@ class StoryViewerFragment : Fragment() { val context = context ?: return live = null if (menuProfile != null) menuProfile!!.isVisible = false - profileVisible = false binding.imageViewer.controller = null releasePlayer() val type = options!!.type @@ -435,6 +461,9 @@ class StoryViewerFragment : Fragment() { releasePlayer() + profileVisible = currentStory.user?.username != null + if (menuProfile != null) menuProfile!!.isVisible = profileVisible + binding.btnDownload.isEnabled = false binding.btnShare.isEnabled = currentStory.canReshare binding.btnReply.isEnabled = currentStory.canReply @@ -544,10 +573,6 @@ class StoryViewerFragment : Fragment() { wasCanceled: Boolean ) { binding.btnDownload.isEnabled = false - if (menuProfile != null) { - profileVisible = false - menuProfile!!.isVisible = false - } binding.progressView.visibility = View.GONE } }) diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.kt b/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.kt index 415bd829..d104c7b8 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.kt +++ b/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.kt @@ -11,6 +11,7 @@ object PreferenceKeys { const val PREF_SHOWN_COUNT_TOOLTIP = "shown_count_tooltip" const val PREF_SEARCH_FOCUS_KEYBOARD = "search_focus_keyboard" const val PREF_AUTO_BACKUP_ENABLED = "auto_backup_enabled" + const val PREF_STORY_SHOW_LIST = "story_show_list" // string prefs const val FOLDER_PATH = "custom_path" diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java index 2983d216..62b7c0ae 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java @@ -19,6 +19,7 @@ public class StoriesPreferencesFragment extends BasePreferencesFragment { screen.addPreference(getHideMutedReelsPreference(context)); screen.addPreference(getMarkStoriesSeenPreference(context)); screen.addPreference(getAutoPlayPreference(context)); + screen.addPreference(getStoryListPreference(context)); } private Preference getStorySortPreference(@NonNull final Context context) { @@ -62,4 +63,13 @@ public class StoriesPreferencesFragment extends BasePreferencesFragment { preference.setIconSpaceReserved(false); return preference; } + + private Preference getStoryListPreference(@NonNull final Context context) { + final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); + preference.setKey(PreferenceKeys.PREF_STORY_SHOW_LIST); + preference.setTitle(R.string.story_list_setting); + preference.setSummary(R.string.story_list_setting_summary); + preference.setIconSpaceReserved(false); + return preference; + } } diff --git a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.kt b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.kt index 8c6905cd..fdcd40b5 100755 --- a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.kt +++ b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.kt @@ -135,6 +135,7 @@ class SettingsHelper(context: Context) { PreferenceKeys.PLAY_IN_BACKGROUND, PreferenceKeys.PREF_SHOWN_COUNT_TOOLTIP, PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD, + PreferenceKeys.PREF_STORY_SHOW_LIST, PreferenceKeys.PREF_AUTO_BACKUP_ENABLED ) annotation class BooleanSettings diff --git a/app/src/main/java/awais/instagrabber/viewmodels/StoryFragmentViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/StoryFragmentViewModel.kt index 8fe4d0ab..a1040ca2 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/StoryFragmentViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/StoryFragmentViewModel.kt @@ -28,7 +28,7 @@ import kotlinx.coroutines.launch class StoryFragmentViewModel : ViewModel() { // large data - private val currentStory = MutableLiveData() + private val currentStory = MutableLiveData() private val currentMedia = MutableLiveData() // small data @@ -181,7 +181,7 @@ class StoryFragmentViewModel : ViewModel() { /* get functions */ - fun getCurrentStory(): LiveData { + fun getCurrentStory(): LiveData { return currentStory } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b17f849..3d934a96 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,6 +32,8 @@ Mark DM as seen after viewing Other members will know you viewed it Autoplay video stories + Display story list by default + For viewing stories Enable activity notifications Feed stories sort Error loading profile! Is the username valid? If so, you may be ratelimited.