aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Luis Marti <joseluis.marti@gmail.com>2023-03-18 23:20:57 +0100
committerJose Luis Marti <joseluis.marti@gmail.com>2023-03-18 23:20:57 +0100
commit687ca6f2bf6803435fb01e8e598bcbdd3bb24fd3 (patch)
treed633ea273a82f1d192e17cd0ab07d47dbb69a500
parent4c40dac6c75996085cb52806f771795a48311f89 (diff)
[Android] Replace AsyncTask in SyncProgramsTask
-rw-r--r--tools/android/packaging/xbmc/src/channels/SyncProgramsJobService.java.in33
1 files changed, 26 insertions, 7 deletions
diff --git a/tools/android/packaging/xbmc/src/channels/SyncProgramsJobService.java.in b/tools/android/packaging/xbmc/src/channels/SyncProgramsJobService.java.in
index b7dc5f74ac..db6a71fdf7 100644
--- a/tools/android/packaging/xbmc/src/channels/SyncProgramsJobService.java.in
+++ b/tools/android/packaging/xbmc/src/channels/SyncProgramsJobService.java.in
@@ -20,8 +20,9 @@ import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
-import android.os.AsyncTask;
import android.os.PersistableBundle;
+import android.os.Handler;
+import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.tvprovider.media.tv.Channel;
@@ -42,6 +43,8 @@ import @APP_PACKAGE@.channels.util.TvUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
/**
* Syncs programs for a channel. A channel id is required to be passed via the {@link
@@ -74,7 +77,6 @@ public class SyncProgramsJobService extends JobService
@Override
protected void onPostExecute(Boolean finished)
{
- super.onPostExecute(finished);
// Daisy chain listening for the next change to the channel.
TvUtil.scheduleTriggeredSyncingProgramsForChannel(
SyncProgramsJobService.this, channelId);
@@ -92,7 +94,7 @@ public class SyncProgramsJobService extends JobService
{
if (mSyncProgramsTask != null)
{
- mSyncProgramsTask.cancel(true);
+ mSyncProgramsTask.cancel();
}
return true;
}
@@ -108,17 +110,34 @@ public class SyncProgramsJobService extends JobService
return extras.getLong(TvContractCompat.EXTRA_CHANNEL_ID, -1L);
}
- private class SyncProgramsTask extends AsyncTask<Long, Void, Boolean>
+ private class SyncProgramsTask
{
-
private final Context mContext;
+ private ExecutorService executor;
+ private Handler handler;
private SyncProgramsTask(Context context)
{
- this.mContext = context;
+ mContext = context;
+ executor = Executors.newSingleThreadExecutor();
+ handler = new Handler(Looper.getMainLooper());
+ }
+
+ public void execute(Long... channelIds)
+ {
+ executor.execute(() -> {
+ Boolean finished = doInBackground(channelIds);
+ handler.post(() -> onPostExecute(finished));
+ });
+ }
+
+ protected void onPostExecute(Boolean finished) {};
+
+ protected void cancel()
+ {
+ executor.shutdown();
}
- @Override
protected Boolean doInBackground(Long... channelIds)
{
XBMCJsonRPC json = new XBMCJsonRPC();