mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Move download completion logic to onComplete subscription
This commit is contained in:
parent
d214ff9450
commit
ebf995b3f7
@ -150,22 +150,15 @@ public class DownloadFragment extends Fragment {
|
||||
return arg0;
|
||||
}
|
||||
|
||||
public void updateProgress(int progress, int notificationID) {
|
||||
if (isAdded()) {
|
||||
public void complete(int notificationID) {
|
||||
int position = Arrays.asList(mKeys).indexOf(notificationID);
|
||||
ViewGroup viewGroup = (ViewGroup) listView.getChildAt(position - listView.getFirstVisiblePosition());
|
||||
if (viewGroup == null) {
|
||||
if (progress == 100) {
|
||||
mDownloads.remove(mKeys[position]);
|
||||
mDownloadFiles.remove(mKeys[position]);
|
||||
downloadAdapter.notifyDataSetChanged();
|
||||
updateNoDownloads();
|
||||
}
|
||||
return;
|
||||
}
|
||||
ProgressBar downloadProgress = (ProgressBar) viewGroup.findViewById(R.id.downloadProgress);
|
||||
downloadProgress.setProgress(progress);
|
||||
if (progress == 100) {
|
||||
ImageView pause = (ImageView) viewGroup.findViewById(R.id.pause);
|
||||
pause.setEnabled(false);
|
||||
String fileName = FileUtils.getFileName(mDownloadFiles.get(mKeys[position]));
|
||||
@ -185,6 +178,16 @@ public class DownloadFragment extends Fragment {
|
||||
downloadAdapter.notifyDataSetChanged();
|
||||
updateNoDownloads();
|
||||
}
|
||||
|
||||
public void updateProgress(int progress, int notificationID) {
|
||||
if (isAdded()) {
|
||||
int position = Arrays.asList(mKeys).indexOf(notificationID);
|
||||
ViewGroup viewGroup = (ViewGroup) listView.getChildAt(position - listView.getFirstVisiblePosition());
|
||||
if (viewGroup == null) {
|
||||
return;
|
||||
}
|
||||
ProgressBar downloadProgress = (ProgressBar) viewGroup.findViewById(R.id.downloadProgress);
|
||||
downloadProgress.setProgress(progress);
|
||||
TextView timeRemaining = (TextView) viewGroup.findViewById(R.id.time_remaining);
|
||||
int secLeft = LibraryFragment.mService.timeRemaining.get(mKeys[position], -1);
|
||||
if (secLeft != -1)
|
||||
|
@ -273,7 +273,7 @@ public class DownloadService extends Service {
|
||||
.flatMap(metaLink -> getMetaLinkContentLength(metaLink.getRelevantUrl().getValue()))
|
||||
.flatMap(pair -> Observable.from(ChunkUtils.getChunks(pair.first, pair.second, notificationID)))
|
||||
.concatMap(this::downloadChunk)
|
||||
.distinctUntilChanged()
|
||||
.distinctUntilChanged().doOnCompleted(() -> {updateDownloadFragmentComplete(notificationID);})
|
||||
.subscribe(progress -> {
|
||||
if (progress == 100) {
|
||||
notification.get(notificationID).setOngoing(false);
|
||||
@ -319,6 +319,19 @@ public class DownloadService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDownloadFragmentComplete(int notificationID) {
|
||||
if (DownloadFragment.mDownloads != null && DownloadFragment.mDownloads.get(notificationID) != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (DownloadFragment.mDownloads.get(notificationID) != null) {
|
||||
DownloadFragment.downloadAdapter.complete(notificationID);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateForeground() {
|
||||
// Allow notification to be dismissible while ensuring integrity of service if active downloads
|
||||
stopForeground(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user