Skip to content

Commit

Permalink
Remove deprecated IntentService
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov committed Dec 28, 2023
1 parent c8f0cfa commit 664e5e3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 267 deletions.
29 changes: 9 additions & 20 deletions app/src/main/java/mobi/maptrek/DownloadReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;

import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
Expand All @@ -31,7 +29,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import mobi.maptrek.maps.MapService;
import mobi.maptrek.maps.MapWorker;

public class DownloadReceiver extends BroadcastReceiver
Expand All @@ -53,24 +50,16 @@ public void onReceive(Context context, Intent intent)
int status = cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
if (status == DownloadManager.STATUS_SUCCESSFUL) {
String fileUri = cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI));
Uri uri = Uri.parse(fileUri);
logger.debug("Downloaded: {}", fileUri);
Intent importIntent = new Intent(Intent.ACTION_INSERT, uri, context, MapService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Data data = new Data.Builder()
.putString(MapWorker.KEY_ACTION, Intent.ACTION_INSERT)
.putString(MapWorker.KEY_FILE_URI, fileUri)
.build();
OneTimeWorkRequest importWorkRequest = new OneTimeWorkRequest.Builder(MapWorker.class)
.addTag(MapWorker.TAG)
.setInputData(data)
.build();
WorkManager.getInstance(context).enqueue(importWorkRequest);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(importIntent);
} else {
context.startService(importIntent);
}
Data data = new Data.Builder()
.putString(MapWorker.KEY_ACTION, Intent.ACTION_INSERT)
.putString(MapWorker.KEY_FILE_URI, fileUri)
.build();
OneTimeWorkRequest importWorkRequest = new OneTimeWorkRequest.Builder(MapWorker.class)
.addTag(MapWorker.TAG)
.setInputData(data)
.build();
WorkManager.getInstance(context).enqueue(importWorkRequest);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/mobi/maptrek/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@
import mobi.maptrek.location.INavigationService;
import mobi.maptrek.location.LocationService;
import mobi.maptrek.location.NavigationService;
import mobi.maptrek.maps.MapWorker;
import mobi.maptrek.plugin.PluginRepository;
import mobi.maptrek.util.ContextUtils;
import mobi.maptrek.util.SafeResultReceiver;
import mobi.maptrek.maps.MapFile;
import mobi.maptrek.maps.MapIndex;
import mobi.maptrek.maps.MapService;
import mobi.maptrek.maps.Themes;
import mobi.maptrek.maps.maptrek.Index;
import mobi.maptrek.maps.maptrek.LabelTileLoaderHook;
Expand Down Expand Up @@ -886,8 +886,8 @@ protected void onStart() {
DataLoader loader = (DataLoader) LoaderManager.getInstance(this).initLoader(0, null, this);
loader.setProgressHandler(mProgressHandler);

ContextCompat.registerReceiver(this, mBroadcastReceiver, new IntentFilter(MapService.BROADCAST_MAP_ADDED), ContextCompat.RECEIVER_NOT_EXPORTED);
ContextCompat.registerReceiver(this, mBroadcastReceiver, new IntentFilter(MapService.BROADCAST_MAP_REMOVED), ContextCompat.RECEIVER_NOT_EXPORTED);
ContextCompat.registerReceiver(this, mBroadcastReceiver, new IntentFilter(MapWorker.BROADCAST_MAP_ADDED), ContextCompat.RECEIVER_NOT_EXPORTED);
ContextCompat.registerReceiver(this, mBroadcastReceiver, new IntentFilter(MapWorker.BROADCAST_MAP_REMOVED), ContextCompat.RECEIVER_NOT_EXPORTED);
ContextCompat.registerReceiver(this, mBroadcastReceiver, new IntentFilter(BaseLocationService.BROADCAST_TRACK_SAVE), ContextCompat.RECEIVER_NOT_EXPORTED);
ContextCompat.registerReceiver(this, mBroadcastReceiver, new IntentFilter(NavigationService.BROADCAST_NAVIGATION_STATUS), ContextCompat.RECEIVER_NOT_EXPORTED);
ContextCompat.registerReceiver(this, mBroadcastReceiver, new IntentFilter(NavigationService.BROADCAST_NAVIGATION_STATE), ContextCompat.RECEIVER_NOT_EXPORTED);
Expand Down Expand Up @@ -4100,7 +4100,7 @@ public void onLoaderReset(@NonNull Loader<List<FileDataSource>> loader) {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
logger.debug("Broadcast: {}", action);
if (MapService.BROADCAST_MAP_ADDED.equals(action) || MapService.BROADCAST_MAP_REMOVED.equals(action)) {
if (MapWorker.BROADCAST_MAP_ADDED.equals(action) || MapWorker.BROADCAST_MAP_REMOVED.equals(action)) {
mMap.clearMap();
}
if (BaseLocationService.BROADCAST_TRACK_SAVE.equals(action)) {
Expand Down
26 changes: 8 additions & 18 deletions app/src/main/java/mobi/maptrek/MapTrek.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -74,7 +73,6 @@
import mobi.maptrek.data.source.WaypointDbDataSource;
import mobi.maptrek.maps.MapFile;
import mobi.maptrek.maps.MapIndex;
import mobi.maptrek.maps.MapService;
import mobi.maptrek.maps.MapWorker;
import mobi.maptrek.maps.maptrek.HillshadeDatabaseHelper;
import mobi.maptrek.maps.maptrek.Index;
Expand Down Expand Up @@ -360,23 +358,15 @@ private void findDebugMaps() {
return;
for (File mapFile : mapFiles) {
if (mapFile.getName().matches("\\d+-\\d+\\.mtiles")) {
Uri uri = Uri.fromFile(mapFile);
logger.error("Found debug map: {}", mapFile.getAbsolutePath());
Intent importIntent = new Intent(Intent.ACTION_INSERT, uri, this, MapService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Data data = new Data.Builder()
.putString(MapWorker.KEY_ACTION, Intent.ACTION_INSERT)
.putString(MapWorker.KEY_FILE_URI, mapFile.getAbsolutePath())
.build();
OneTimeWorkRequest importWorkRequest = new OneTimeWorkRequest.Builder(MapWorker.class)
.setInputData(data)
.build();
WorkManager.getInstance(this).enqueue(importWorkRequest);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(importIntent);
} else {
startService(importIntent);
}
Data data = new Data.Builder()
.putString(MapWorker.KEY_ACTION, Intent.ACTION_INSERT)
.putString(MapWorker.KEY_FILE_URI, mapFile.getAbsolutePath())
.build();
OneTimeWorkRequest importWorkRequest = new OneTimeWorkRequest.Builder(MapWorker.class)
.setInputData(data)
.build();
WorkManager.getInstance(this).enqueue(importWorkRequest);
}
}

Expand Down
207 changes: 0 additions & 207 deletions app/src/main/java/mobi/maptrek/maps/MapService.java

This file was deleted.

28 changes: 10 additions & 18 deletions app/src/main/java/mobi/maptrek/maps/maptrek/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import mobi.maptrek.Configuration;
import mobi.maptrek.MapTrek;
import mobi.maptrek.R;
import mobi.maptrek.maps.MapService;
import mobi.maptrek.maps.MapWorker;
import mobi.maptrek.util.ProgressListener;

Expand Down Expand Up @@ -799,23 +798,16 @@ public void manageNativeMaps(boolean hillshadesEnabled) {
if (mapStatus.action == ACTION.NONE)
continue;
if (mapStatus.action == ACTION.REMOVE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Data data = new Data.Builder()
.putString(MapWorker.KEY_ACTION, Intent.ACTION_DELETE)
.putInt(MapWorker.KEY_X, x)
.putInt(MapWorker.KEY_Y, y)
.build();
OneTimeWorkRequest deleteWorkRequest = new OneTimeWorkRequest.Builder(MapWorker.class)
.addTag(MapWorker.TAG)
.setInputData(data)
.build();
WorkManager.getInstance(mContext).enqueue(deleteWorkRequest);
} else {
Intent deleteIntent = new Intent(Intent.ACTION_DELETE, null, mContext, MapService.class);
deleteIntent.putExtra(MapService.EXTRA_X, x);
deleteIntent.putExtra(MapService.EXTRA_Y, y);
mContext.startService(deleteIntent);
}
Data data = new Data.Builder()
.putString(MapWorker.KEY_ACTION, Intent.ACTION_DELETE)
.putInt(MapWorker.KEY_X, x)
.putInt(MapWorker.KEY_Y, y)
.build();
OneTimeWorkRequest deleteWorkRequest = new OneTimeWorkRequest.Builder(MapWorker.class)
.addTag(MapWorker.TAG)
.setInputData(data)
.build();
WorkManager.getInstance(mContext).enqueue(deleteWorkRequest);
mapStatus.action = ACTION.NONE;
continue;
}
Expand Down

0 comments on commit 664e5e3

Please sign in to comment.