Show selected decoder and background color in the popup menu. Reload adapter when the decoder changes.

This commit is contained in:
inorichi 2016-01-09 00:57:02 +01:00
parent d03e7e2f8c
commit 8be44c209c
18 changed files with 72 additions and 21 deletions

View File

@ -29,6 +29,7 @@ import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.database.models.Chapter; import eu.kanade.mangafeed.data.database.models.Chapter;
import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.data.database.models.Manga;
import eu.kanade.mangafeed.data.preference.PreferencesHelper; import eu.kanade.mangafeed.data.preference.PreferencesHelper;
import eu.kanade.mangafeed.ui.reader.viewer.base.BaseReader;
import icepick.State; import icepick.State;
import rx.Subscription; import rx.Subscription;
@ -245,8 +246,9 @@ public class ReaderMenu {
@Bind(R.id.show_page_number) CheckBox showPageNumber; @Bind(R.id.show_page_number) CheckBox showPageNumber;
@Bind(R.id.hide_status_bar) CheckBox hideStatusBar; @Bind(R.id.hide_status_bar) CheckBox hideStatusBar;
@Bind(R.id.keep_screen_on) CheckBox keepScreenOn; @Bind(R.id.keep_screen_on) CheckBox keepScreenOn;
@Bind(R.id.reader_theme) CheckBox readerTheme;
@Bind(R.id.image_decoder) TextView imageDecoder; @Bind(R.id.image_decoder) TextView imageDecoder;
@Bind(R.id.reader_theme) TextView readerTheme; @Bind(R.id.image_decoder_initial) TextView imageDecoderInitial;
public SettingsPopupWindow(View view) { public SettingsPopupWindow(View view) {
super(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); super(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
@ -261,6 +263,8 @@ public class ReaderMenu {
showPageNumber.setChecked(preferences.showPageNumber().get()); showPageNumber.setChecked(preferences.showPageNumber().get());
hideStatusBar.setChecked(preferences.hideStatusBar().get()); hideStatusBar.setChecked(preferences.hideStatusBar().get());
keepScreenOn.setChecked(preferences.keepScreenOn().get()); keepScreenOn.setChecked(preferences.keepScreenOn().get());
readerTheme.setChecked(preferences.readerTheme().get() == 1);
setDecoderInitial(preferences.imageDecoder().get());
// Add a listener to change the corresponding setting // Add a listener to change the corresponding setting
enableTransitions.setOnCheckedChangeListener((view, isChecked) -> enableTransitions.setOnCheckedChangeListener((view, isChecked) ->
@ -275,6 +279,9 @@ public class ReaderMenu {
keepScreenOn.setOnCheckedChangeListener((view, isChecked) -> keepScreenOn.setOnCheckedChangeListener((view, isChecked) ->
preferences.keepScreenOn().set(isChecked)); preferences.keepScreenOn().set(isChecked));
readerTheme.setOnCheckedChangeListener((view, isChecked) ->
preferences.readerTheme().set(isChecked ? 1 : 0));
imageDecoder.setOnClickListener(v -> { imageDecoder.setOnClickListener(v -> {
showImmersiveDialog(new MaterialDialog.Builder(activity) showImmersiveDialog(new MaterialDialog.Builder(activity)
.title(R.string.pref_image_decoder) .title(R.string.pref_image_decoder)
@ -282,22 +289,27 @@ public class ReaderMenu {
.itemsCallbackSingleChoice(preferences.imageDecoder().get(), .itemsCallbackSingleChoice(preferences.imageDecoder().get(),
(dialog, itemView, which, text) -> { (dialog, itemView, which, text) -> {
preferences.imageDecoder().set(which); preferences.imageDecoder().set(which);
setDecoderInitial(which);
return true; return true;
}) })
.build()); .build());
}); });
}
readerTheme.setOnClickListener(v -> { private void setDecoderInitial(int decoder) {
showImmersiveDialog(new MaterialDialog.Builder(activity) String initial;
.title(R.string.pref_reader_theme) switch (decoder) {
.items(R.array.reader_themes) case BaseReader.SKIA_DECODER:
.itemsCallbackSingleChoice(preferences.readerTheme().get(), initial = "S";
(dialog, itemView, which, text) -> { break;
preferences.readerTheme().set(which); case BaseReader.RAPID_DECODER:
return true; initial = "R";
}) break;
.build()); default:
}); initial = "";
break;
}
imageDecoderInitial.setText(initial);
} }
} }

View File

@ -61,4 +61,8 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonHolder> {
fragment.getReaderActivity().getPresenter().retryPage(page); fragment.getReaderActivity().getPresenter().retryPage(page);
} }
public WebtoonReader getReader() {
return fragment;
}
} }

View File

@ -26,9 +26,11 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
private Animation fadeInAnimation; private Animation fadeInAnimation;
private Page page; private Page page;
private WebtoonAdapter adapter;
public WebtoonHolder(View view, WebtoonAdapter adapter, View.OnTouchListener touchListener) { public WebtoonHolder(View view, WebtoonAdapter adapter, View.OnTouchListener touchListener) {
super(view); super(view);
this.adapter = adapter;
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
fadeInAnimation = AnimationUtils.loadAnimation(view.getContext(), R.anim.fade_in); fadeInAnimation = AnimationUtils.loadAnimation(view.getContext(), R.anim.fade_in);
@ -88,6 +90,7 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
setErrorButtonVisible(false); setErrorButtonVisible(false);
setProgressVisible(false); setProgressVisible(false);
setImageVisible(true); setImageVisible(true);
imageView.setRegionDecoderClass(adapter.getReader().getRegionDecoderClass());
imageView.setImage(ImageSource.uri(page.getImagePath())); imageView.setImage(ImageSource.uri(page.getImagePath()));
} }

View File

@ -27,6 +27,7 @@ public class WebtoonReader extends BaseReader {
private RecyclerView recycler; private RecyclerView recycler;
private PreCachingLayoutManager layoutManager; private PreCachingLayoutManager layoutManager;
private Subscription subscription; private Subscription subscription;
private Subscription decoderSubscription;
private GestureDetector gestureDetector; private GestureDetector gestureDetector;
@Nullable @Nullable
@ -42,6 +43,13 @@ public class WebtoonReader extends BaseReader {
recycler.setItemAnimator(null); recycler.setItemAnimator(null);
recycler.setAdapter(adapter); recycler.setAdapter(adapter);
decoderSubscription = getReaderActivity().getPreferences().imageDecoder()
.asObservable()
.doOnNext(this::setRegionDecoderClass)
.skip(1)
.distinctUntilChanged()
.subscribe(v -> adapter.notifyDataSetChanged());
gestureDetector = new GestureDetector(getActivity(), new SimpleOnGestureListener() { gestureDetector = new GestureDetector(getActivity(), new SimpleOnGestureListener() {
@Override @Override
public boolean onSingleTapConfirmed(MotionEvent e) { public boolean onSingleTapConfirmed(MotionEvent e) {
@ -63,6 +71,12 @@ public class WebtoonReader extends BaseReader {
return recycler; return recycler;
} }
@Override
public void onDestroyView() {
decoderSubscription.unsubscribe();
super.onDestroyView();
}
@Override @Override
public void onPause() { public void onPause() {
unsubscribeStatus(); unsubscribeStatus();

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/reader_background_checkbox_selected" />
<item android:drawable="@drawable/reader_background_checkbox_unselected" />
</selector>

View File

@ -8,17 +8,30 @@
android:paddingTop="5dp" android:paddingTop="5dp"
android:paddingBottom="5dp"> android:paddingBottom="5dp">
<TextView <LinearLayout
android:id="@+id/reader_theme" android:layout_width="wrap_content"
android:paddingLeft="32dp" android:layout_height="wrap_content">
style="@style/reader_menu_settings_item"
android:text="@string/pref_reader_theme"/>
<TextView <TextView
android:id="@+id/image_decoder" android:id="@+id/image_decoder_initial"
android:paddingLeft="32dp" android:layout_width="32dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:gravity="center"
android:textColor="@color/colorAccent"/>
<TextView
android:id="@+id/image_decoder"
style="@style/reader_menu_settings_item"
android:text="@string/pref_image_decoder"/>
</LinearLayout>
<CheckBox
android:id="@+id/reader_theme"
style="@style/reader_menu_settings_item" style="@style/reader_menu_settings_item"
android:text="@string/pref_image_decoder"/> android:button="@drawable/reader_background_checkbox"
android:text="@string/pref_reader_theme"/>
<CheckBox <CheckBox
android:id="@+id/enable_transitions" android:id="@+id/enable_transitions"