Skip to content

Commit 7522b5f

Browse files
finish up stories viewer UI
close #537, close #1554
1 parent cade09a commit 7522b5f

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt

+32-7
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ class StoryViewerFragment : Fragment() {
240240
storyMedias.set(0, newItem)
241241
storiesAdapter!!.submitList(storyMedias)
242242
storiesViewModel.setMedia(0)
243+
binding.listToggle.setEnabled(true)
244+
binding.storiesList.setVisibility(
245+
if (Utils.settingsHelper.getBoolean(PreferenceKeys.PREF_STORY_SHOW_LIST)) View.VISIBLE
246+
else View.GONE
247+
)
248+
}
249+
else {
250+
binding.listToggle.setEnabled(false)
251+
binding.storiesList.setVisibility(View.GONE)
243252
}
244253
})
245254
storiesViewModel.getDate().observe(fragmentActivity, {
@@ -268,6 +277,12 @@ class StoryViewerFragment : Fragment() {
268277
binding.btnShare.setOnClickListener({ _ -> shareStoryViaDm() })
269278
binding.btnReply.setOnClickListener({ _ -> createReplyDialog(null) })
270279
binding.stickers.setOnClickListener({ _ -> showStickerMenu() })
280+
binding.listToggle.setOnClickListener({ _ ->
281+
binding.storiesList.setVisibility(
282+
if (binding.storiesList.visibility == View.GONE) View.VISIBLE
283+
else View.GONE
284+
)
285+
})
271286
}
272287

273288
@SuppressLint("ClickableViewAccessibility")
@@ -297,10 +312,22 @@ class StoryViewerFragment : Fragment() {
297312
if (models != null) {
298313
when (it) {
299314
StoryPaginationType.FORWARD -> {
300-
paginateStories(false, currentFeedStoryIndex == models.size - 2)
315+
if (currentFeedStoryIndex == models.size - 1)
316+
Toast.makeText(
317+
context,
318+
R.string.no_more_stories,
319+
Toast.LENGTH_SHORT
320+
).show()
321+
else paginateStories(false, currentFeedStoryIndex == models.size - 2)
301322
}
302323
StoryPaginationType.BACKWARD -> {
303-
paginateStories(true, false)
324+
if (currentFeedStoryIndex == 0)
325+
Toast.makeText(
326+
context,
327+
R.string.no_more_stories,
328+
Toast.LENGTH_SHORT
329+
).show()
330+
else paginateStories(true, false)
304331
}
305332
StoryPaginationType.ERROR -> {
306333
Toast.makeText(
@@ -356,7 +383,6 @@ class StoryViewerFragment : Fragment() {
356383
val context = context ?: return
357384
live = null
358385
if (menuProfile != null) menuProfile!!.isVisible = false
359-
profileVisible = false
360386
binding.imageViewer.controller = null
361387
releasePlayer()
362388
val type = options!!.type
@@ -435,6 +461,9 @@ class StoryViewerFragment : Fragment() {
435461

436462
releasePlayer()
437463

464+
profileVisible = currentStory.user?.username != null
465+
if (menuProfile != null) menuProfile!!.isVisible = profileVisible
466+
438467
binding.btnDownload.isEnabled = false
439468
binding.btnShare.isEnabled = currentStory.canReshare
440469
binding.btnReply.isEnabled = currentStory.canReply
@@ -544,10 +573,6 @@ class StoryViewerFragment : Fragment() {
544573
wasCanceled: Boolean
545574
) {
546575
binding.btnDownload.isEnabled = false
547-
if (menuProfile != null) {
548-
profileVisible = false
549-
menuProfile!!.isVisible = false
550-
}
551576
binding.progressView.visibility = View.GONE
552577
}
553578
})

app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.kt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ object PreferenceKeys {
1111
const val PREF_SHOWN_COUNT_TOOLTIP = "shown_count_tooltip"
1212
const val PREF_SEARCH_FOCUS_KEYBOARD = "search_focus_keyboard"
1313
const val PREF_AUTO_BACKUP_ENABLED = "auto_backup_enabled"
14+
const val PREF_STORY_SHOW_LIST = "story_show_list"
1415

1516
// string prefs
1617
const val FOLDER_PATH = "custom_path"

app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void setupPreferenceScreen(final PreferenceScreen screen) {
1919
screen.addPreference(getHideMutedReelsPreference(context));
2020
screen.addPreference(getMarkStoriesSeenPreference(context));
2121
screen.addPreference(getAutoPlayPreference(context));
22+
screen.addPreference(getStoryListPreference(context));
2223
}
2324

2425
private Preference getStorySortPreference(@NonNull final Context context) {
@@ -62,4 +63,13 @@ private Preference getAutoPlayPreference(@NonNull final Context context) {
6263
preference.setIconSpaceReserved(false);
6364
return preference;
6465
}
66+
67+
private Preference getStoryListPreference(@NonNull final Context context) {
68+
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context);
69+
preference.setKey(PreferenceKeys.PREF_STORY_SHOW_LIST);
70+
preference.setTitle(R.string.story_list_setting);
71+
preference.setSummary(R.string.story_list_setting_summary);
72+
preference.setIconSpaceReserved(false);
73+
return preference;
74+
}
6575
}

app/src/main/java/awais/instagrabber/utils/SettingsHelper.kt

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class SettingsHelper(context: Context) {
135135
PreferenceKeys.PLAY_IN_BACKGROUND,
136136
PreferenceKeys.PREF_SHOWN_COUNT_TOOLTIP,
137137
PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD,
138+
PreferenceKeys.PREF_STORY_SHOW_LIST,
138139
PreferenceKeys.PREF_AUTO_BACKUP_ENABLED
139140
)
140141
annotation class BooleanSettings

app/src/main/java/awais/instagrabber/viewmodels/StoryFragmentViewModel.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import kotlinx.coroutines.launch
2828

2929
class StoryFragmentViewModel : ViewModel() {
3030
// large data
31-
private val currentStory = MutableLiveData<Story>()
31+
private val currentStory = MutableLiveData<Story?>()
3232
private val currentMedia = MutableLiveData<StoryMedia>()
3333

3434
// small data
@@ -181,7 +181,7 @@ class StoryFragmentViewModel : ViewModel() {
181181

182182
/* get functions */
183183

184-
fun getCurrentStory(): LiveData<Story> {
184+
fun getCurrentStory(): LiveData<Story?> {
185185
return currentStory
186186
}
187187

app/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<string name="dm_mark_as_seen_setting">Mark DM as seen after viewing</string>
3333
<string name="dm_mark_as_seen_setting_summary">Other members will know you viewed it</string>
3434
<string name="autoplay_stories_setting">Autoplay video stories</string>
35+
<string name="story_list_setting">Display story list by default</string>
36+
<string name="story_list_setting_summary">For viewing stories</string>
3537
<string name="activity_setting">Enable activity notifications</string>
3638
<string name="story_sort_setting">Feed stories sort</string>
3739
<string name="error_loading_profile">Error loading profile! Is the username valid? If so, you may be ratelimited.</string>

0 commit comments

Comments
 (0)