Cleanup
This commit is contained in:
parent
952ea803b2
commit
f0df9f94d4
1 changed files with 10 additions and 20 deletions
|
@ -1,6 +1,5 @@
|
||||||
package btools.routingapp;
|
package btools.routingapp;
|
||||||
|
|
||||||
import android.app.Notification;
|
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
@ -40,13 +39,13 @@ public class DownloadWorker extends Worker {
|
||||||
private static final String SEGMENT_DIFF_SUFFIX = ".df5";
|
private static final String SEGMENT_DIFF_SUFFIX = ".df5";
|
||||||
private static final String SEGMENT_SUFFIX = ".rd5";
|
private static final String SEGMENT_SUFFIX = ".rd5";
|
||||||
|
|
||||||
private NotificationManager notificationManager;
|
private final NotificationManager notificationManager;
|
||||||
private ServerConfig mServerConfig;
|
private final ServerConfig mServerConfig;
|
||||||
private File baseDir;
|
private final File baseDir;
|
||||||
private ProgressListener diffProgressListener;
|
private final ProgressListener diffProgressListener;
|
||||||
private DownloadProgressListener downloadProgressListener;
|
private final DownloadProgressListener downloadProgressListener;
|
||||||
private Data.Builder progressBuilder = new Data.Builder();
|
private final Data.Builder progressBuilder = new Data.Builder();
|
||||||
private NotificationCompat.Builder notificationBuilder;
|
private final NotificationCompat.Builder notificationBuilder;
|
||||||
|
|
||||||
public DownloadWorker(
|
public DownloadWorker(
|
||||||
@NonNull Context context,
|
@NonNull Context context,
|
||||||
|
@ -76,7 +75,7 @@ public class DownloadWorker extends Worker {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadInfo(String info) {
|
public void onDownloadInfo(String info) {
|
||||||
notificationBuilder.setContentText(info);
|
notificationBuilder.setContentText(currentDownloadName + ": " + info);
|
||||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,16 +128,15 @@ public class DownloadWorker extends Worker {
|
||||||
if (segmentNames == null) {
|
if (segmentNames == null) {
|
||||||
return Result.failure();
|
return Result.failure();
|
||||||
}
|
}
|
||||||
|
notificationBuilder.setContentText("Starting Download");
|
||||||
// Mark the Worker as important
|
// Mark the Worker as important
|
||||||
setForegroundAsync(new ForegroundInfo(NOTIFICATION_ID, createNotification("Starting Download")));
|
setForegroundAsync(new ForegroundInfo(NOTIFICATION_ID, notificationBuilder.build()));
|
||||||
try {
|
try {
|
||||||
downloadLookupAndProfiles();
|
downloadLookupAndProfiles();
|
||||||
|
|
||||||
int segmentIndex = 1;
|
|
||||||
for (String segmentName : segmentNames) {
|
for (String segmentName : segmentNames) {
|
||||||
downloadProgressListener.onDownloadStart(segmentName, DownloadType.SEGMENT);
|
downloadProgressListener.onDownloadStart(segmentName, DownloadType.SEGMENT);
|
||||||
downloadSegment(mServerConfig.getSegmentUrl(), segmentName + SEGMENT_SUFFIX);
|
downloadSegment(mServerConfig.getSegmentUrl(), segmentName + SEGMENT_SUFFIX);
|
||||||
segmentIndex++;
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return Result.failure();
|
return Result.failure();
|
||||||
|
@ -291,14 +289,6 @@ public class DownloadWorker extends Worker {
|
||||||
.addAction(android.R.drawable.ic_delete, cancel, intent);
|
.addAction(android.R.drawable.ic_delete, cancel, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private Notification createNotification(@NonNull String content) {
|
|
||||||
notificationBuilder.setContentText(content);
|
|
||||||
// Reset progress from previous download
|
|
||||||
notificationBuilder.setProgress(0, 0, false);
|
|
||||||
return notificationBuilder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
private void createChannel() {
|
private void createChannel() {
|
||||||
CharSequence name = getApplicationContext().getString(R.string.channel_name);
|
CharSequence name = getApplicationContext().getString(R.string.channel_name);
|
||||||
|
|
Loading…
Reference in a new issue