mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Fix a big issue with the download threads. Release 0.1.1
This commit is contained in:
parent
0332d8dd79
commit
0210fd8828
@ -39,8 +39,8 @@ android {
|
|||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
versionCode 1
|
versionCode 2
|
||||||
versionName "0.1.0"
|
versionName "0.1.1"
|
||||||
|
|
||||||
buildConfigField "String", "COMMIT_COUNT", "\"${getCommitCount()}\""
|
buildConfigField "String", "COMMIT_COUNT", "\"${getCommitCount()}\""
|
||||||
buildConfigField "String", "COMMIT_SHA", "\"${getGitSha()}\""
|
buildConfigField "String", "COMMIT_SHA", "\"${getGitSha()}\""
|
||||||
|
@ -41,7 +41,7 @@ public class DownloadManager {
|
|||||||
private PreferencesHelper preferences;
|
private PreferencesHelper preferences;
|
||||||
private Gson gson;
|
private Gson gson;
|
||||||
|
|
||||||
private PublishSubject<Download> downloadsQueueSubject;
|
private PublishSubject<List<Download>> downloadsQueueSubject;
|
||||||
private BehaviorSubject<Boolean> runningSubject;
|
private BehaviorSubject<Boolean> runningSubject;
|
||||||
private Subscription downloadsSubscription;
|
private Subscription downloadsSubscription;
|
||||||
|
|
||||||
@ -67,7 +67,8 @@ public class DownloadManager {
|
|||||||
downloadsSubscription.unsubscribe();
|
downloadsSubscription.unsubscribe();
|
||||||
|
|
||||||
downloadsSubscription = downloadsQueueSubject
|
downloadsSubscription = downloadsQueueSubject
|
||||||
.flatMap(this::downloadChapter, preferences.downloadThreads())
|
.concatMap(downloads -> Observable.from(downloads)
|
||||||
|
.flatMap(this::downloadChapter, preferences.downloadThreads()))
|
||||||
.onBackpressureBuffer()
|
.onBackpressureBuffer()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.map(download -> areAllDownloadsFinished())
|
.map(download -> areAllDownloadsFinished())
|
||||||
@ -102,6 +103,7 @@ public class DownloadManager {
|
|||||||
|
|
||||||
// Used to avoid downloading chapters with the same name
|
// Used to avoid downloading chapters with the same name
|
||||||
final List<String> addedChapters = new ArrayList<>();
|
final List<String> addedChapters = new ArrayList<>();
|
||||||
|
final List<Download> pending = new ArrayList<>();
|
||||||
|
|
||||||
for (Chapter chapter : event.getChapters()) {
|
for (Chapter chapter : event.getChapters()) {
|
||||||
if (addedChapters.contains(chapter.name))
|
if (addedChapters.contains(chapter.name))
|
||||||
@ -112,9 +114,10 @@ public class DownloadManager {
|
|||||||
|
|
||||||
if (!prepareDownload(download)) {
|
if (!prepareDownload(download)) {
|
||||||
queue.add(download);
|
queue.add(download);
|
||||||
if (isRunning) downloadsQueueSubject.onNext(download);
|
pending.add(download);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isRunning) downloadsQueueSubject.onNext(pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public method to check if a chapter is downloaded
|
// Public method to check if a chapter is downloaded
|
||||||
@ -386,18 +389,19 @@ public class DownloadManager {
|
|||||||
if (queue.isEmpty())
|
if (queue.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
boolean hasPendingDownloads = false;
|
|
||||||
if (downloadsSubscription == null)
|
if (downloadsSubscription == null)
|
||||||
initializeSubscriptions();
|
initializeSubscriptions();
|
||||||
|
|
||||||
|
final List<Download> pending = new ArrayList<>();
|
||||||
for (Download download : queue) {
|
for (Download download : queue) {
|
||||||
if (download.getStatus() != Download.DOWNLOADED) {
|
if (download.getStatus() != Download.DOWNLOADED) {
|
||||||
if (download.getStatus() != Download.QUEUE) download.setStatus(Download.QUEUE);
|
if (download.getStatus() != Download.QUEUE) download.setStatus(Download.QUEUE);
|
||||||
if (!hasPendingDownloads) hasPendingDownloads = true;
|
pending.add(download);
|
||||||
downloadsQueueSubject.onNext(download);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hasPendingDownloads;
|
downloadsQueueSubject.onNext(pending);
|
||||||
|
|
||||||
|
return !pending.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopDownloads() {
|
public void stopDownloads() {
|
||||||
|
@ -72,9 +72,9 @@ public class MainActivity extends BaseActivity {
|
|||||||
new PrimaryDrawerItem()
|
new PrimaryDrawerItem()
|
||||||
.withName(R.string.label_library)
|
.withName(R.string.label_library)
|
||||||
.withIdentifier(R.id.nav_drawer_library),
|
.withIdentifier(R.id.nav_drawer_library),
|
||||||
new PrimaryDrawerItem()
|
// new PrimaryDrawerItem()
|
||||||
.withName(R.string.label_recent_updates)
|
// .withName(R.string.label_recent_updates)
|
||||||
.withIdentifier(R.id.nav_drawer_recent_updates),
|
// .withIdentifier(R.id.nav_drawer_recent_updates),
|
||||||
new PrimaryDrawerItem()
|
new PrimaryDrawerItem()
|
||||||
.withName(R.string.label_catalogues)
|
.withName(R.string.label_catalogues)
|
||||||
.withIdentifier(R.id.nav_drawer_catalogues),
|
.withIdentifier(R.id.nav_drawer_catalogues),
|
||||||
|
Loading…
Reference in New Issue
Block a user