|
@@ -6,25 +6,35 @@ import android.support.v4.app.Fragment;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
|
|
+import android.widget.LinearLayout;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.davemorrissey.labs.subscaleview.ImageSource;
|
|
import com.davemorrissey.labs.subscaleview.ImageSource;
|
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
|
|
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+
|
|
import butterknife.Bind;
|
|
import butterknife.Bind;
|
|
import butterknife.ButterKnife;
|
|
import butterknife.ButterKnife;
|
|
import eu.kanade.mangafeed.R;
|
|
import eu.kanade.mangafeed.R;
|
|
import eu.kanade.mangafeed.data.models.Page;
|
|
import eu.kanade.mangafeed.data.models.Page;
|
|
import eu.kanade.mangafeed.ui.activity.ReaderActivity;
|
|
import eu.kanade.mangafeed.ui.activity.ReaderActivity;
|
|
|
|
+import rx.Observable;
|
|
|
|
+import rx.Subscription;
|
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
|
|
|
public class ReaderPageFragment extends Fragment {
|
|
public class ReaderPageFragment extends Fragment {
|
|
|
|
|
|
@Bind(R.id.page_image_view) SubsamplingScaleImageView imageView;
|
|
@Bind(R.id.page_image_view) SubsamplingScaleImageView imageView;
|
|
|
|
+ @Bind(R.id.progress_container) LinearLayout progressContainer;
|
|
@Bind(R.id.progress) ProgressBar progressBar;
|
|
@Bind(R.id.progress) ProgressBar progressBar;
|
|
|
|
+ @Bind(R.id.progress_text) TextView progressText;
|
|
@Bind(R.id.image_error) TextView errorText;
|
|
@Bind(R.id.image_error) TextView errorText;
|
|
|
|
|
|
private Page page;
|
|
private Page page;
|
|
|
|
+ private Subscription progressSubscription;
|
|
|
|
|
|
public static ReaderPageFragment newInstance(Page page) {
|
|
public static ReaderPageFragment newInstance(Page page) {
|
|
ReaderPageFragment fragment = new ReaderPageFragment();
|
|
ReaderPageFragment fragment = new ReaderPageFragment();
|
|
@@ -35,11 +45,11 @@ public class ReaderPageFragment extends Fragment {
|
|
@Override
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
-
|
|
|
|
setRetainInstance(true);
|
|
setRetainInstance(true);
|
|
}
|
|
}
|
|
|
|
|
|
public void replacePage(Page page) {
|
|
public void replacePage(Page page) {
|
|
|
|
+ unsubscribeProgress();
|
|
this.page = page;
|
|
this.page = page;
|
|
loadImage();
|
|
loadImage();
|
|
}
|
|
}
|
|
@@ -55,13 +65,13 @@ public class ReaderPageFragment extends Fragment {
|
|
switch (page.getStatus()) {
|
|
switch (page.getStatus()) {
|
|
case (Page.READY):
|
|
case (Page.READY):
|
|
imageView.setImage(ImageSource.uri(page.getImagePath()).tilingDisabled());
|
|
imageView.setImage(ImageSource.uri(page.getImagePath()).tilingDisabled());
|
|
- progressBar.setVisibility(View.GONE);
|
|
|
|
|
|
+ progressContainer.setVisibility(View.GONE);
|
|
break;
|
|
break;
|
|
case (Page.DOWNLOAD):
|
|
case (Page.DOWNLOAD):
|
|
- progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
+ progressContainer.setVisibility(View.VISIBLE);
|
|
break;
|
|
break;
|
|
case (Page.ERROR):
|
|
case (Page.ERROR):
|
|
- progressBar.setVisibility(View.GONE);
|
|
|
|
|
|
+ progressContainer.setVisibility(View.GONE);
|
|
errorText.setVisibility(View.VISIBLE);
|
|
errorText.setVisibility(View.VISIBLE);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -78,9 +88,42 @@ public class ReaderPageFragment extends Fragment {
|
|
imageView.setOnTouchListener((v, motionEvent) ->
|
|
imageView.setOnTouchListener((v, motionEvent) ->
|
|
((ReaderActivity) getActivity()).onImageTouch(motionEvent));
|
|
((ReaderActivity) getActivity()).onImageTouch(motionEvent));
|
|
|
|
|
|
|
|
+ observeProgress();
|
|
loadImage();
|
|
loadImage();
|
|
|
|
|
|
return view;
|
|
return view;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void onStop() {
|
|
|
|
+ super.onStop();
|
|
|
|
+ unsubscribeProgress();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void observeProgress() {
|
|
|
|
+ if (page == null || page.getStatus() != Page.DOWNLOAD)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ progressSubscription = Observable.interval(75, TimeUnit.MILLISECONDS)
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
+ .subscribe(tick -> {
|
|
|
|
+ if (page.getProgress() == 0) {
|
|
|
|
+ progressText.setText(R.string.downloading);
|
|
|
|
+ }
|
|
|
|
+ else if (page.getProgress() == 100) {
|
|
|
|
+ progressContainer.setVisibility(View.GONE);
|
|
|
|
+ unsubscribeProgress();
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ progressText.setText(getString(R.string.download_progress, page.getProgress()));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void unsubscribeProgress() {
|
|
|
|
+ if (progressSubscription != null)
|
|
|
|
+ progressSubscription.unsubscribe();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|