diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java index 1128f0b1e..a8acba499 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java @@ -68,9 +68,13 @@ public class Manga implements Serializable { public static final int COMPLETED = 2; public static final int LICENSED = 3; - public static final int SORT_AZ = 0; - public static final int SORT_ZA = 1; - public static final int SORT_MASK = 1; + public static final int SORT_AZ = 0x00000000; + public static final int SORT_ZA = 0x00000001; + public static final int SORT_MASK = 0x00000001; + + public static final int DISPLAY_NAME = 0x00000000; + public static final int DISPLAY_NUMBER = 0x00100000; + public static final int DISPLAY_MASK = 0x00100000; public Manga() {} @@ -124,16 +128,25 @@ public class Manga implements Serializable { } } - public void setFlags(int flag, int mask) { + public void setChapterOrder(int order) { + setFlags(order, SORT_MASK); + } + + public void setDisplayMode(int mode) { + setFlags(mode, DISPLAY_MASK); + } + + private void setFlags(int flag, int mask) { chapter_flags = (chapter_flags & ~mask) | (flag & mask); } - public boolean sortChaptersAZ () { - return (this.chapter_flags & SORT_MASK) == SORT_AZ; + public boolean sortChaptersAZ() { + return (chapter_flags & SORT_MASK) == SORT_AZ; } - public void setChapterOrder(int order) { - setFlags(order, SORT_MASK); + // Used to display the chapter's title one way or another + public int getDisplayMode() { + return chapter_flags & DISPLAY_MASK; } @Override diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.java index 0e0e64392..ba7db26bc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.java @@ -10,6 +10,7 @@ import java.util.List; import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.kanade.tachiyomi.R; import eu.kanade.tachiyomi.data.database.models.Chapter; +import eu.kanade.tachiyomi.data.database.models.Manga; public class ChaptersAdapter extends FlexibleAdapter { @@ -33,7 +34,8 @@ public class ChaptersAdapter extends FlexibleAdapter { @Override public void onBindViewHolder(ChaptersHolder holder, int position) { final Chapter chapter = getItem(position); - holder.onSetValues(fragment.getActivity(), chapter); + final Manga manga = fragment.getPresenter().getManga(); + holder.onSetValues(chapter, manga); //When user scrolls this bind the correct selection status holder.itemView.setActivated(isSelected(position)); diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java index 6fb96fa16..682aa34a5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java @@ -10,6 +10,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -62,6 +63,12 @@ public class ChaptersFragment extends BaseRxFragment implemen return new ChaptersFragment(); } + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + setHasOptionsMenu(true); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -92,6 +99,21 @@ public class ChaptersFragment extends BaseRxFragment implemen return view; } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.chapters, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_display_mode: + showDisplayModeDialog(); + return true; + } + return false; + } + public void onNextManga(Manga manga) { // Remove listeners before setting the values readCb.setOnCheckedChangeListener(null); @@ -157,6 +179,29 @@ public class ChaptersFragment extends BaseRxFragment implemen startActivity(intent); } + private void showDisplayModeDialog() { + final Manga manga = getPresenter().getManga(); + if (manga == null) + return; + + // Get available modes, ids and the selected mode + String[] modes = {getString(R.string.show_title), getString(R.string.show_chapter_number)}; + int[] ids = {Manga.DISPLAY_NAME, Manga.DISPLAY_NUMBER}; + int selectedIndex = manga.getDisplayMode() == Manga.DISPLAY_NAME ? 0 : 1; + + new MaterialDialog.Builder(getActivity()) + .items(modes) + .itemsIds(ids) + .itemsCallbackSingleChoice(selectedIndex, (dialog, itemView, which, text) -> { + // Save the new display mode + getPresenter().setDisplayMode(itemView.getId()); + // Refresh ui + adapter.notifyDataSetChanged(); + return true; + }) + .show(); + } + private void observeChapterDownloadProgress() { downloadProgressSubscription = getPresenter().getDownloadProgressObs() .subscribe(this::onDownloadProgressChange, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java index 373ace8de..a8c76fa82 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersHolder.java @@ -7,6 +7,8 @@ import android.widget.PopupMenu; import android.widget.RelativeLayout; import android.widget.TextView; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; import java.util.Date; @@ -14,40 +16,60 @@ import butterknife.Bind; import butterknife.ButterKnife; import eu.kanade.tachiyomi.R; import eu.kanade.tachiyomi.data.database.models.Chapter; +import eu.kanade.tachiyomi.data.database.models.Manga; import eu.kanade.tachiyomi.data.download.model.Download; import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder; import rx.Observable; public class ChaptersHolder extends FlexibleViewHolder { - private final ChaptersAdapter adapter; - private Chapter item; - @Bind(R.id.chapter_title) TextView title; @Bind(R.id.download_text) TextView downloadText; @Bind(R.id.chapter_menu) RelativeLayout chapterMenu; @Bind(R.id.chapter_pages) TextView pages; @Bind(R.id.chapter_date) TextView date; - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + private Context context; + + private final ChaptersAdapter adapter; + private Chapter item; private final int readColor; private final int unreadColor; + private final DecimalFormat decimalFormat; + private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + public ChaptersHolder(View view, ChaptersAdapter adapter, OnListItemClickListener listener) { super(view, adapter, listener); this.adapter = adapter; + context = view.getContext(); ButterKnife.bind(this, view); readColor = ContextCompat.getColor(view.getContext(), R.color.hint_text); unreadColor = ContextCompat.getColor(view.getContext(), R.color.primary_text); + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + symbols.setDecimalSeparator('.'); + decimalFormat = new DecimalFormat("#.###", symbols); + chapterMenu.setOnClickListener(v -> v.post(() -> showPopupMenu(v))); } - public void onSetValues(Context context, Chapter chapter) { + public void onSetValues(Chapter chapter, Manga manga) { this.item = chapter; - title.setText(chapter.name); + String name; + switch (manga.getDisplayMode()) { + case Manga.DISPLAY_NAME: + default: + name = chapter.name; + break; + case Manga.DISPLAY_NUMBER: + String formattedNumber = decimalFormat.format(chapter.chapter_number); + name = context.getString(R.string.display_mode_chapter, formattedNumber); + break; + } + title.setText(name); title.setTextColor(chapter.read ? readColor : unreadColor); if (!chapter.read && chapter.last_page_read > 0) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java index b87e35093..e981ec0e7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java @@ -264,6 +264,11 @@ public class ChaptersPresenter extends BasePresenter { refreshChapters(); } + public void setDisplayMode(int mode) { + manga.setDisplayMode(mode); + db.insertManga(manga).executeAsBlocking(); + } + public boolean getSortOrder() { return manga.sortChaptersAZ(); } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderMenu.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderMenu.java index 8f8a840a0..938cc2b9f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderMenu.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderMenu.java @@ -70,7 +70,7 @@ public class ReaderMenu { bottomMenu.setOnTouchListener((v, event) -> true); seekBar.setOnSeekBarChangeListener(new PageSeekBarChangeListener()); - decimalFormat = new DecimalFormat("#.##"); + decimalFormat = new DecimalFormat("#.###"); inverted = false; initializeOptions(); diff --git a/app/src/main/res/menu/chapters.xml b/app/src/main/res/menu/chapters.xml new file mode 100644 index 000000000..1d56f62b3 --- /dev/null +++ b/app/src/main/res/menu/chapters.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7ba24db68..bb72d2f5b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -157,12 +157,15 @@ Chapters No title + Chapter %1$s Downloaded Queued Downloading Downloading (%1$d/%2$d) Error Error while fetching chapters + Show title + Show chapter number Reading