atv channels: performance tweaks

This commit is contained in:
Yuriy Liskov
2024-12-24 01:22:38 +02:00
parent 1e29d86a27
commit 274c583d04
7 changed files with 18 additions and 14 deletions

View File

@@ -89,7 +89,7 @@ public class AppUpdatePresenter extends BasePresenter<Void> implements AppUpdate
private void showUpdateDialog(String versionName, List<String> changelog, String apkPath) {
// Don't show update dialog if the player opened or the app is collapsed
if (getContext() == null || ViewManager.instance(getContext()).isPlayerInForeground() || !Utils.isAppInForeground()) {
if (getContext() == null || ViewManager.instance(getContext()).isPlayerInForeground() || !Utils.isAppInForegroundFixed()) {
return;
}

View File

@@ -98,7 +98,7 @@ public class ViewManager {
*/
public void startView(Class<?> viewClass, boolean forceStart) {
// Skip starting activity twice to get rid of pausing/resuming activity cycle
if (Utils.isAppInForeground() && getTopView() != null && getTopView() == viewClass) {
if (Utils.isAppInForegroundFixed() && getTopView() != null && getTopView() == viewClass) {
return;
}
@@ -454,11 +454,11 @@ public class ViewManager {
}
public boolean isPlayerInForeground() {
return Utils.isAppInForeground() && getTopView() == PlaybackView.class;
return Utils.isAppInForegroundFixed() && getTopView() == PlaybackView.class;
}
public void moveAppToForeground() {
if (!Utils.isAppInForeground()) {
if (!Utils.isAppInForegroundFixed()) {
startView(SplashView.class);
}
}

View File

@@ -37,6 +37,7 @@ public class GDriveBackupWorker extends Worker {
private static final String TAG = GDriveBackupWorker.class.getSimpleName();
private static final String WORK_NAME = TAG;
private static final String BLOCKED_FILE_NAME = "blocked";
private static final long REPEAT_INTERVAL_DAYS = 1;
private static Disposable sAction;
private final GDriveBackupManager mTask;
@@ -54,7 +55,7 @@ public class GDriveBackupWorker extends Worker {
workManager.enqueueUniquePeriodicWork(
WORK_NAME,
ExistingPeriodicWorkPolicy.UPDATE, // fix duplicates (when old worker is running)
new PeriodicWorkRequest.Builder(GDriveBackupWorker.class, 1, TimeUnit.DAYS).addTag(WORK_NAME).build()
new PeriodicWorkRequest.Builder(GDriveBackupWorker.class, REPEAT_INTERVAL_DAYS, TimeUnit.DAYS).addTag(WORK_NAME).build()
);
}
}

View File

@@ -190,11 +190,9 @@ public class Utils {
return Uri.parse(url);
}
public static boolean isAppInForeground() {
ActivityManager.RunningAppProcessInfo appProcessInfo = new ActivityManager.RunningAppProcessInfo();
ActivityManager.getMyMemoryState(appProcessInfo);
// Skip situation when splash presenter still running
return appProcessInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && SplashPresenter.instance(null).getView() == null;
public static boolean isAppInForegroundFixed() {
// Skip situation when the splash presenter still running
return Helpers.isAppInForeground() && SplashPresenter.instance(null).getView() == null;
}
/**

View File

@@ -10,6 +10,7 @@ import androidx.work.WorkManager;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import com.liskovsoft.sharedutils.helpers.Helpers;
import com.liskovsoft.sharedutils.mylogger.Log;
import com.liskovsoft.sharedutils.prefs.GlobalPreferences;
@@ -27,6 +28,7 @@ import java.util.concurrent.TimeUnit;
public class UpdateChannelsWorker extends Worker {
private static final String TAG = UpdateChannelsWorker.class.getSimpleName();
private static final String WORK_NAME = "Update channels";
private static final long REPEAT_INTERVAL_MINUTES = 15; // 15 - minimal interval
private final UpdateChannelsTask mTask;
public UpdateChannelsWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
@@ -43,7 +45,7 @@ public class UpdateChannelsWorker extends Worker {
workManager.enqueueUniquePeriodicWork(
WORK_NAME,
ExistingPeriodicWorkPolicy.UPDATE, // fix duplicates (when old worker is running)
new PeriodicWorkRequest.Builder(UpdateChannelsWorker.class, 20, TimeUnit.MINUTES).addTag(WORK_NAME).build()
new PeriodicWorkRequest.Builder(UpdateChannelsWorker.class, REPEAT_INTERVAL_MINUTES, TimeUnit.MINUTES).addTag(WORK_NAME).build()
);
}
}
@@ -62,7 +64,10 @@ public class UpdateChannelsWorker extends Worker {
public Result doWork() {
Log.d(TAG, "Starting worker %s...", this);
mTask.run();
// Improve performance. Run task when the app paused.
if (!Helpers.isAppInForeground()) {
mTask.run();
}
return Result.success();
}