Home button refresh added. Possible fix for Grayjay starting playback after hours of being inactive. Scroll to top and reload feed.

This commit is contained in:
Koen J 2024-09-06 10:12:23 +02:00
parent 0f0f368a75
commit 0bf92b6aff
3 changed files with 43 additions and 15 deletions

View file

@ -368,7 +368,15 @@ class MenuBottomBarFragment : MainActivityFragment() {
//Add configurable buttons here
var buttonDefinitions = listOf(
ButtonDefinition(0, R.drawable.ic_home, R.drawable.ic_home_filled, R.string.home, canToggle = true, { it.currentMain is HomeFragment }, { it.navigate<HomeFragment>() }),
ButtonDefinition(0, R.drawable.ic_home, R.drawable.ic_home_filled, R.string.home, canToggle = true, { it.currentMain is HomeFragment }, {
val currentMain = it.currentMain
if (currentMain is HomeFragment) {
currentMain.reloadFeed()
currentMain.scrollToTop()
} else {
it.navigate<HomeFragment>()
}
}),
ButtonDefinition(1, R.drawable.ic_subscriptions, R.drawable.ic_subscriptions_filled, R.string.subscriptions, canToggle = true, { it.currentMain is SubscriptionsFeedFragment }, { it.navigate<SubscriptionsFeedFragment>() }),
ButtonDefinition(2, R.drawable.ic_creators, R.drawable.ic_creators_filled, R.string.creators, canToggle = false, { it.currentMain is CreatorsFragment }, { it.navigate<CreatorsFragment>() }),
ButtonDefinition(3, R.drawable.ic_sources, R.drawable.ic_sources_filled, R.string.sources, canToggle = false, { it.currentMain is SourcesFragment }, { it.navigate<SourcesFragment>() }),

View file

@ -46,6 +46,14 @@ class HomeFragment : MainFragment() {
private var _view: HomeView? = null;
private var _cachedRecyclerData: FeedView.RecyclerData<InsertedViewAdapterWithLoader<ContentPreviewViewHolder>, LinearLayoutManager, IPager<IPlatformContent>, IPlatformContent, IPlatformContent, InsertedViewHolder<ContentPreviewViewHolder>>? = null;
fun reloadFeed() {
_view?.reloadFeed()
}
fun scrollToTop() {
_view?.scrollToTop()
}
override fun onShownWithView(parameter: Any?, isBack: Boolean) {
super.onShownWithView(parameter, isBack);
_view?.onShown();
@ -138,16 +146,12 @@ class HomeFragment : MainFragment() {
fun onShown() {
val lastClients = recyclerData.lastClients;
val clients = StatePlatform.instance.getSortedEnabledClient().filter { if (it is JSClient) it.enableInHome else true };
val feedstyleChanged = recyclerData.loadedFeedStyle != feedStyle;
val clientsChanged = lastClients == null || lastClients.size != clients.size || !lastClients.containsAll(clients);
Logger.i(TAG, "onShown (recyclerData.loadedFeedStyle=${recyclerData.loadedFeedStyle}, recyclerData.lastLoad=${recyclerData.lastLoad}, feedstyleChanged=$feedstyleChanged, clientsChanged=$clientsChanged)")
if(feedstyleChanged || clientsChanged) {
recyclerData.lastLoad = OffsetDateTime.now();
recyclerData.loadedFeedStyle = feedStyle;
recyclerData.lastClients = clients;
loadResults();
reloadFeed()
} else {
setLoading(false);
}
@ -155,6 +159,17 @@ class HomeFragment : MainFragment() {
finishRefreshLayoutLoader();
}
fun scrollToTop() {
_recyclerResults.smoothScrollToPosition(0)
}
fun reloadFeed() {
recyclerData.lastLoad = OffsetDateTime.now();
recyclerData.loadedFeedStyle = feedStyle;
recyclerData.lastClients = StatePlatform.instance.getSortedEnabledClient().filter { if (it is JSClient) it.enableInHome else true };
loadResults();
}
override fun getEmptyPagerView(): View? {
val dp10 = 10.dp(resources);
val dp30 = 30.dp(resources);

View file

@ -412,16 +412,17 @@ class MediaPlaybackService : Service() {
AudioManager.AUDIOFOCUS_GAIN -> {
_hasFocus = true;
_isTransientLoss = false;
Log.i(TAG, "Audio focus gained (restartPlaybackAfterLoss = ${Settings.instance.playback.restartPlaybackAfterLoss}, _audioFocusLossTime_ms = $_audioFocusLossTime_ms)");
val audioFocusLossDuration = _audioFocusLossTime_ms?.let { System.currentTimeMillis() - it }
_audioFocusLossTime_ms = null
Log.i(TAG, "Audio focus gained (restartPlaybackAfterLoss = ${Settings.instance.playback.restartPlaybackAfterLoss}, _audioFocusLossTime_ms = $_audioFocusLossTime_ms, audioFocusLossDuration = ${audioFocusLossDuration})");
if (Settings.instance.playback.restartPlaybackAfterLoss == 1) {
val lossTime_ms = _audioFocusLossTime_ms
if (lossTime_ms != null && System.currentTimeMillis() - lossTime_ms < 1000 * 10) {
if (audioFocusLossDuration != null && audioFocusLossDuration < 1000 * 10) {
MediaControlReceiver.onPlayReceived.emit()
}
} else if (Settings.instance.playback.restartPlaybackAfterLoss == 2) {
val lossTime_ms = _audioFocusLossTime_ms
if (lossTime_ms != null && System.currentTimeMillis() - lossTime_ms < 1000 * 30) {
if (audioFocusLossDuration != null && audioFocusLossDuration < 1000 * 30) {
MediaControlReceiver.onPlayReceived.emit()
}
} else if (Settings.instance.playback.restartPlaybackAfterLoss == 3) {
@ -429,8 +430,10 @@ class MediaPlaybackService : Service() {
}
}
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
if (isPlaying) {
_audioFocusLossTime_ms = System.currentTimeMillis()
_audioFocusLossTime_ms = if (isPlaying) {
System.currentTimeMillis()
} else {
null
}
_hasFocus = false;
@ -444,8 +447,10 @@ class MediaPlaybackService : Service() {
_isTransientLoss = true;
}
AudioManager.AUDIOFOCUS_LOSS -> {
if (isPlaying) {
_audioFocusLossTime_ms = System.currentTimeMillis()
_audioFocusLossTime_ms = if (isPlaying) {
System.currentTimeMillis()
} else {
null
}
MediaControlReceiver.onPauseReceived.emit();