From 99fd3fe73139e5da36e34e282dbb8ab3a6846873 Mon Sep 17 00:00:00 2001 From: Yuriy Liskov Date: Tue, 16 Aug 2022 15:20:20 +0300 Subject: [PATCH] app: improve update checking --- MediaServiceCore | 2 +- .../app/presenters/BrowsePresenter.java | 12 +++--------- .../app/presenters/base/BasePresenter.java | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/MediaServiceCore b/MediaServiceCore index ca837d1eb..0929b7895 160000 --- a/MediaServiceCore +++ b/MediaServiceCore @@ -1 +1 @@ -Subproject commit ca837d1ebf7e9f08d55a4ed93c5f307587549fe0 +Subproject commit 0929b789522c351fee7167bf5b590262f52e5740 diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/BrowsePresenter.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/BrowsePresenter.java index 79622467c..61520adcc 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/BrowsePresenter.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/BrowsePresenter.java @@ -113,6 +113,8 @@ public class BrowsePresenter extends BasePresenter implements Sectio @Override public void onViewInitialized() { + super.onViewInitialized(); + if (getView() == null) { return; } @@ -123,8 +125,6 @@ public class BrowsePresenter extends BasePresenter implements Sectio int selectedSectionIndex = findSectionIndex(mSelectedSectionId); mSelectedSectionId = -1; getView().selectSection(selectedSectionIndex != -1 ? selectedSectionIndex : mBootSectionIndex, true); - showBootDialogs(); - Utils.updateRemoteControlService(getContext()); } private void initSections() { @@ -142,7 +142,7 @@ public class BrowsePresenter extends BasePresenter implements Sectio mSectionsMapping.put(MediaGroup.TYPE_HOME, new BrowseSection(MediaGroup.TYPE_HOME, getContext().getString(R.string.header_home), BrowseSection.TYPE_ROW, R.drawable.icon_home)); mSectionsMapping.put(MediaGroup.TYPE_GAMING, new BrowseSection(MediaGroup.TYPE_GAMING, getContext().getString(R.string.header_gaming), BrowseSection.TYPE_ROW, R.drawable.icon_gaming)); - if (!Helpers.equalsAny(country, "RU")) { + if (!Helpers.equalsAny(country, "RU", "BY")) { mSectionsMapping.put(MediaGroup.TYPE_NEWS, new BrowseSection(MediaGroup.TYPE_NEWS, getContext().getString(R.string.header_news), BrowseSection.TYPE_ROW, R.drawable.icon_news)); } mSectionsMapping.put(MediaGroup.TYPE_MUSIC, new BrowseSection(MediaGroup.TYPE_MUSIC, getContext().getString(R.string.header_music), BrowseSection.TYPE_ROW, R.drawable.icon_music)); @@ -478,12 +478,6 @@ public class BrowsePresenter extends BasePresenter implements Sectio } } - private void showBootDialogs() { - BootDialogPresenter updatePresenter = BootDialogPresenter.instance(getContext()); - updatePresenter.start(); - updatePresenter.unhold(); - } - public void refresh() { if (mCurrentSection != null) { updateSection(mCurrentSection.getId()); diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/base/BasePresenter.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/base/BasePresenter.java index 11b6f6ebf..9a5d9667e 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/base/BasePresenter.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/base/BasePresenter.java @@ -6,6 +6,8 @@ import androidx.fragment.app.Fragment; import com.liskovsoft.smartyoutubetv2.common.app.models.data.Playlist; import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video; import com.liskovsoft.smartyoutubetv2.common.app.models.data.VideoGroup; +import com.liskovsoft.smartyoutubetv2.common.app.presenters.BrowsePresenter; +import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.BootDialogPresenter; import com.liskovsoft.smartyoutubetv2.common.app.presenters.interfaces.Presenter; import com.liskovsoft.smartyoutubetv2.common.app.views.BrowseView; import com.liskovsoft.smartyoutubetv2.common.app.views.ChannelUploadsView; @@ -24,6 +26,7 @@ public abstract class BasePresenter implements Presenter { private WeakReference mApplicationContext = new WeakReference<>(null); private Runnable mOnDone; private static boolean sRunOnce; + private long mUpdateCheckMs; public BasePresenter(Context context) { setContext(context); @@ -84,7 +87,7 @@ public abstract class BasePresenter implements Presenter { @Override public void onViewInitialized() { - // NOP + showBootDialogs(); } @Override @@ -100,6 +103,8 @@ public abstract class BasePresenter implements Presenter { // NOTE: don't place cleanup in the onViewResumed!!! This could cause errors when view is resumed. syncItem(Playlist.instance().getChangedItems()); } + + showBootDialogs(); } @Override @@ -184,4 +189,16 @@ public abstract class BasePresenter implements Presenter { sSync = true; Playlist.instance().onNewSession(); } + + private void showBootDialogs() { + long currentTimeMs = System.currentTimeMillis(); + + if (this instanceof BrowsePresenter && currentTimeMs - mUpdateCheckMs > 60 * 60 * 1_000) { + BootDialogPresenter updatePresenter = BootDialogPresenter.instance(getContext()); + updatePresenter.start(); + updatePresenter.unhold(); + Utils.updateRemoteControlService(getContext()); + mUpdateCheckMs = currentTimeMs; + } + } }