mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 02:18:24 +01:00
Minor changes
This commit is contained in:
parent
95581007df
commit
9407d9b4f5
@ -61,23 +61,13 @@ public class Page implements NetworkHelper.ProgressListener {
|
|||||||
|
|
||||||
public void setStatus(int status) {
|
public void setStatus(int status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
if (statusSubject != null)
|
notifyStatus();
|
||||||
statusSubject.onNext(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getProgress() {
|
public int getProgress() {
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Page{" +
|
|
||||||
"pageNumber=" + pageNumber +
|
|
||||||
", url='" + url + '\'' +
|
|
||||||
", imageUrl='" + imageUrl + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(long bytesRead, long contentLength, boolean done) {
|
public void update(long bytesRead, long contentLength, boolean done) {
|
||||||
progress = (int) ((100 * bytesRead) / contentLength);
|
progress = (int) ((100 * bytesRead) / contentLength);
|
||||||
@ -85,6 +75,12 @@ public class Page implements NetworkHelper.ProgressListener {
|
|||||||
|
|
||||||
public void setStatusSubject(BehaviorSubject<Integer> subject) {
|
public void setStatusSubject(BehaviorSubject<Integer> subject) {
|
||||||
this.statusSubject = subject;
|
this.statusSubject = subject;
|
||||||
|
notifyStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyStatus() {
|
||||||
|
if (statusSubject != null)
|
||||||
|
statusSubject.onNext(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,6 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
EventBus.getDefault().removeStickyEvent(SourceChapterEvent.class);
|
|
||||||
source.savePageList(chapter.url, pageList);
|
source.savePageList(chapter.url, pageList);
|
||||||
saveChapter();
|
saveChapter();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
@ -79,14 +78,13 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
|
|
||||||
@EventBusHook
|
@EventBusHook
|
||||||
public void onEventMainThread(SourceChapterEvent event) {
|
public void onEventMainThread(SourceChapterEvent event) {
|
||||||
if (source == null || chapter == null) {
|
|
||||||
source = event.getSource();
|
source = event.getSource();
|
||||||
chapter = event.getChapter();
|
chapter = event.getChapter();
|
||||||
if (chapter.last_page_read != 0)
|
if (chapter.last_page_read != 0 && !chapter.read)
|
||||||
currentPage = chapter.last_page_read;
|
currentPage = chapter.last_page_read;
|
||||||
|
|
||||||
start(1);
|
start(1);
|
||||||
}
|
EventBus.getDefault().removeStickyEvent(SourceChapterEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observable<List<Page>> getPageListObservable() {
|
private Observable<List<Page>> getPageListObservable() {
|
||||||
|
@ -14,6 +14,7 @@ import com.davemorrissey.labs.subscaleview.ImageSource;
|
|||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -124,12 +125,9 @@ public class ReaderPageFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void observeStatus() {
|
private void observeStatus() {
|
||||||
if (page == null)
|
if (page == null || statusSubscription != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (page.getStatus() == Page.READY) {
|
|
||||||
showImage();
|
|
||||||
} else {
|
|
||||||
BehaviorSubject<Integer> statusSubject = BehaviorSubject.create();
|
BehaviorSubject<Integer> statusSubject = BehaviorSubject.create();
|
||||||
page.setStatusSubject(statusSubject);
|
page.setStatusSubject(statusSubject);
|
||||||
|
|
||||||
@ -137,16 +135,22 @@ public class ReaderPageFragment extends Fragment {
|
|||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::processStatus);
|
.subscribe(this::processStatus);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void observeProgress() {
|
private void observeProgress() {
|
||||||
|
if (progressSubscription != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
final AtomicInteger currentValue = new AtomicInteger(-1);
|
||||||
|
|
||||||
progressSubscription = Observable.interval(75, TimeUnit.MILLISECONDS)
|
progressSubscription = Observable.interval(75, TimeUnit.MILLISECONDS)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(tick -> {
|
.subscribe(tick -> {
|
||||||
if (page.getProgress() != 0)
|
// Refresh UI only if progress change
|
||||||
progressText.setText(
|
if (page.getProgress() != currentValue.get()) {
|
||||||
getString(R.string.download_progress, page.getProgress()));
|
currentValue.set(page.getProgress());
|
||||||
|
progressText.setText(getString(R.string.download_progress, page.getProgress()));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user