From 9cf5a4cac0c22caa8898e640e569e7dcd5c3a0e8 Mon Sep 17 00:00:00 2001 From: Bram van de Kerkhof Date: Thu, 28 Jul 2016 01:01:56 +0200 Subject: [PATCH] Minor Improvements (#405) --- .../tachiyomi/ui/category/CategoryActivity.kt | 4 +- .../ui/library/LibraryCategoryFragment.kt | 12 ++--- .../tachiyomi/ui/library/LibraryFragment.kt | 6 +-- .../tachiyomi/ui/library/LibraryHolder.kt | 3 -- .../tachiyomi/ui/library/LibraryListHolder.kt | 16 +++--- .../tachiyomi/ui/library/LibraryPresenter.kt | 7 ++- .../res/layout/fragment_library_category.xml | 1 + app/src/main/res/layout/item_library_list.xml | 49 +++++++++++-------- app/src/main/res/menu/library.xml | 28 +++++------ 9 files changed, 67 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryActivity.kt index 8a01bcacf..44d295b76 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryActivity.kt @@ -55,9 +55,9 @@ class CategoryActivity : BaseRxActivity(), ActionMode.Callbac } } - override fun onCreate(savedInstanceState: Bundle?) { + override fun onCreate(savedState: Bundle?) { setAppTheme() - super.onCreate(savedInstanceState) + super.onCreate(savedState) // Inflate activity_edit_categories.xml. setContentView(R.layout.activity_edit_categories) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt index 1085df828..814dec25a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt @@ -18,8 +18,6 @@ import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment import eu.kanade.tachiyomi.ui.manga.MangaActivity import eu.kanade.tachiyomi.util.toast -import kotlinx.android.synthetic.main.fragment_catalogue.* -import kotlinx.android.synthetic.main.fragment_library.* import kotlinx.android.synthetic.main.fragment_library_category.* import rx.Subscription import uy.kohesive.injekt.injectLazy @@ -69,7 +67,7 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli /** * display mode */ - private var displayAsList: Boolean = false; + private var displayAsList: Boolean = false companion object { /** @@ -109,6 +107,8 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli library_list.adapter = adapter library_list.layoutManager = LinearLayoutManager(activity) + + if (libraryFragment.actionMode != null) { setSelectionMode(FlexibleAdapter.MODE_MULTI) } @@ -119,7 +119,7 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli // Set again the adapter to recalculate the covers height .subscribe { recycler.adapter = adapter } - searchSubscription = libraryPresenter.searchSubject.subscribe { text -> + searchSubscription = libraryPresenter.searchSubject?.subscribe { text -> adapter.searchText = text adapter.updateDataSet() } @@ -179,7 +179,7 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli libraryMangaSubscription = libraryPresenter.libraryMangaSubject - .subscribe { onNextLibraryManga(it) } + ?.subscribe { onNextLibraryManga(it) } } @@ -247,7 +247,7 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli * * @param manga the manga to open. */ - protected fun openManga(manga: Manga) { + private fun openManga(manga: Manga) { // Notify the presenter a manga is being opened. libraryPresenter.onOpenManga() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt index 9e455a029..0916dfd2e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt @@ -138,7 +138,7 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback if (savedState != null) { activeCategory = savedState.getInt(CATEGORY_KEY) query = savedState.getString(QUERY_KEY) - presenter.searchSubject.onNext(query) + presenter.searchSubject?.onNext(query) } else { activeCategory = presenter.preferences.lastUsedCategory().getOrDefault() } @@ -283,7 +283,7 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback // Notify the subject the query has changed. if (isResumed) { - presenter.searchSubject.onNext(query) + presenter.searchSubject?.onNext(query) } } @@ -311,7 +311,7 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback view_pager.post { if (isAdded) tabs.setScrollPosition(view_pager.currentItem, 0f, true) } // Send the manga map to child fragments after the adapter is updated. - presenter.libraryMangaSubject.onNext(LibraryMangaEvent(mangaMap)) + presenter.libraryMangaSubject?.onNext(LibraryMangaEvent(mangaMap)) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt index 07f5add56..a9f2cfb23 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt @@ -1,11 +1,8 @@ package eu.kanade.tachiyomi.ui.library import android.view.View -import com.bumptech.glide.Glide -import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder -import kotlinx.android.synthetic.main.item_catalogue_grid.view.* /** * Generic class used to hold the displayed data of a manga in the library. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 78d9accee..2e561d38c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -30,24 +30,28 @@ class LibraryListHolder(private val view: View, */ override fun onSetValues(manga: Manga) { // Update the title of the manga. - view.title.text = manga.title + itemView.title.text = manga.title // Update the unread count and its visibility. - with(view.unread_text) { + with(itemView.unread_text) { visibility = if (manga.unread > 0) View.VISIBLE else View.GONE text = manga.unread.toString() } - + // Create thumbnail onclick to simulate long click + itemView.thumbnail.setOnClickListener { + // Simulate long click on this view to enter selection mode + onLongClick(itemView) + } // Update the cover. - Glide.clear(view.thumbnail) - Glide.with(view.context) + Glide.clear(itemView.thumbnail) + Glide.with(itemView.context) .load(manga) .diskCacheStrategy(DiskCacheStrategy.RESULT) .centerCrop() .dontAnimate() - .into(view.thumbnail) + .into(itemView.thumbnail) } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 26650cd04..39efd36d6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -39,12 +39,12 @@ class LibraryPresenter : BasePresenter() { /** * Search query of the library. */ - val searchSubject = BehaviorSubject.create() + val searchSubject: BehaviorSubject? = BehaviorSubject.create() /** * Subject to notify the library's viewpager for updates. */ - val libraryMangaSubject = BehaviorSubject.create() + val libraryMangaSubject: BehaviorSubject? = BehaviorSubject.create() /** * Database. @@ -247,7 +247,7 @@ class LibraryPresenter : BasePresenter() { * * @param mangas the list of manga. */ - fun getCommonCategories(mangas: List) = mangas.toSet() + fun getCommonCategories(mangas: List): Collection = mangas.toSet() .map { db.getCategoriesForManga(it).executeAsBlocking() } .reduce { set1: Iterable, set2 -> set1.intersect(set2) } @@ -307,7 +307,6 @@ class LibraryPresenter : BasePresenter() { * Changes the active display mode. */ fun swapDisplayMode() { - var currentMode: Boolean = displayAsList preferences.libraryAsList().set(!displayAsList) } diff --git a/app/src/main/res/layout/fragment_library_category.xml b/app/src/main/res/layout/fragment_library_category.xml index 77fd57c33..bc31c39c8 100644 --- a/app/src/main/res/layout/fragment_library_category.xml +++ b/app/src/main/res/layout/fragment_library_category.xml @@ -27,6 +27,7 @@ android:id="@+id/library_list" android:layout_width="match_parent" android:layout_height="match_parent" + android:paddingTop="@dimen/material_component_lists_padding_above_list" tools:listitem="@layout/item_library_list"/> diff --git a/app/src/main/res/layout/item_library_list.xml b/app/src/main/res/layout/item_library_list.xml index 7142650f4..cad62cfd0 100644 --- a/app/src/main/res/layout/item_library_list.xml +++ b/app/src/main/res/layout/item_library_list.xml @@ -2,34 +2,41 @@ + android:layout_width="@dimen/material_component_text_fields_icon_height" + android:layout_height="@dimen/material_component_text_fields_icon_height" + android:layout_gravity="center_vertical" + android:paddingEnd="0dp" + android:paddingLeft="@dimen/material_component_lists_icon_left_padding" + android:paddingRight="0dp" + android:paddingStart="@dimen/material_component_lists_icon_left_padding" + android:src="@drawable/icon"/> + android:id="@+id/title" + style="@style/TextAppearance.Regular.SubHeading" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:paddingEnd="0dp" + android:paddingLeft="@dimen/material_component_lists_text_left_padding" + android:paddingRight="0dp" + android:paddingStart="@dimen/material_component_lists_text_left_padding"/> + android:id="@+id/unread_text" + style="@style/TextAppearance.Regular.Caption.Hint" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical|end" + android:paddingEnd="@dimen/material_component_lists_right_padding" + android:paddingLeft="0dp" + android:paddingRight="@dimen/material_component_lists_right_padding" + android:paddingStart="0dp" + android:visibility="gone"/> \ No newline at end of file diff --git a/app/src/main/res/menu/library.xml b/app/src/main/res/menu/library.xml index 0af3d8b00..27fabce9b 100644 --- a/app/src/main/res/menu/library.xml +++ b/app/src/main/res/menu/library.xml @@ -2,10 +2,17 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> + + + android:id="@+id/action_update_library" + android:icon="@drawable/ic_refresh_white_24dp" + android:title="@string/action_update_library" + app:showAsAction="ifRoom" /> - - + android:title="@string/action_display_mode" + app:showAsAction="never"/>