From 9e36dccf4d6e04df349c6e017d1ff199d8310788 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 9 Feb 2020 22:16:08 -0800 Subject: [PATCH 001/259] Recent Read Controller is no longer Rx Unfortunately to fix #72, an rx observer is needed since the reader adds to the db after the recents is back in view --- .../tachiyomi/ui/recently_read/RecentlyReadController.kt | 8 +++++--- .../tachiyomi/ui/recently_read/RecentlyReadPresenter.kt | 5 ++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index 983cc5ab1e..cbea59b673 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -105,16 +105,18 @@ class RecentlyReadController(bundle: Bundle? = null) : BaseController(bundle), * * @param mangaHistory list of manga history */ - fun onNextManga(mangaHistory: List) { + fun onNextManga(mangaHistory: List, freshList:Boolean = false) { val adapter = adapter ?: return adapter.updateDataSet(mangaHistory) adapter.onLoadMoreComplete(null) - if (recentItems == null) + if (recentItems == null || adapter.endlessTargetCount == 1) resetProgressItem() + else if (freshList && mangaHistory.size == recentItems!!.size) + onAddPageError() recentItems = mangaHistory.toMutableList() } - fun onAddPageError() { + private fun onAddPageError() { adapter?.onLoadMoreComplete(null) adapter?.endlessTargetCount = 1 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt index bcf73ba09b..30c0fbbb99 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt @@ -55,14 +55,13 @@ class RecentlyReadPresenter(private val view: RecentlyReadController) { } fun observe() { - readerSubscription?.unsubscribe() val cal = Calendar.getInstance() cal.time = Date() cal.add(Calendar.YEAR, -50) - readerSubscription = db.getRecentMangaLimit(cal.time, lastCount, "").asRxObservable().map { + db.getRecentMangaLimit(cal.time, lastCount, "").asRxObservable().map { val items = it.map(::RecentlyReadItem) launchUI { - view.onNextManga(items) + view.onNextManga(items, false) } }.observeOn(Schedulers.io()).skip(1).take(1).subscribe() } From 25df36c60d859dc505bfe32b84b979e4719f8270 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 1 Feb 2020 01:29:26 -0800 Subject: [PATCH 002/259] Start of MD2 + White theme --- app/build.gradle | 2 +- .../tachiyomi/ui/library/LibraryController.kt | 15 ++-- .../kanade/tachiyomi/ui/main/MainActivity.kt | 69 ++++++++++++++++--- .../ui/setting/SettingsMainController.kt | 24 ++++++- app/src/main/res/drawable/action_mode_bg.xml | 17 +++++ .../res/drawable/bottom_nav_item_selector.xml | 10 +++ .../res/drawable/ic_arrow_down_white_32dp.xml | 3 +- .../drawable/ic_arrow_forward_white_24dp.xml | 6 +- .../drawable/ic_content_copy_white_24dp.xml | 5 +- .../res/drawable/ic_delete_white_24dp.xml | 3 +- .../res/drawable/ic_done_all_white_24dp.xml | 5 +- .../main/res/drawable/ic_edit_white_24dp.xml | 6 +- .../drawable/ic_file_download_white_24dp.xml | 3 +- .../drawable/ic_filter_list_white_24dp.xml | 3 +- .../main/res/drawable/ic_label_white_24dp.xml | 3 +- .../res/drawable/ic_refresh_white_24dp.xml | 3 +- .../res/drawable/ic_search_white_24dp.xml | 3 +- .../res/drawable/ic_settings_white_24dp.xml | 3 +- .../main/res/drawable/ic_share_white_24dp.xml | 3 +- .../ic_sort_by_numeric_white_24dp.xml | 3 +- .../res/drawable/ic_swap_vert_white_24dp.xml | 6 ++ app/src/main/res/layout/main_activity.xml | 36 ++++++++-- .../res/layout/migration_bottom_sheet.xml | 1 + .../main/res/layout/navigation_view_group.xml | 2 +- .../res/layout/pre_migration_controller.xml | 3 +- .../layout/recent_chapters_section_item.xml | 2 +- app/src/main/res/layout/search_activity.xml | 3 +- app/src/main/res/menu/bottom_navigation.xml | 28 ++++++++ app/src/main/res/menu/library.xml | 9 ++- app/src/main/res/menu/library_selection.xml | 13 ++-- app/src/main/res/values-night/colors.xml | 2 + app/src/main/res/values-night/themes.xml | 5 ++ app/src/main/res/values/attrs.xml | 3 + app/src/main/res/values/colors.xml | 5 ++ app/src/main/res/values/strings.xml | 6 ++ app/src/main/res/values/styles.xml | 10 +++ app/src/main/res/values/themes.xml | 16 ++++- 37 files changed, 288 insertions(+), 51 deletions(-) create mode 100644 app/src/main/res/drawable/action_mode_bg.xml create mode 100644 app/src/main/res/drawable/bottom_nav_item_selector.xml create mode 100644 app/src/main/res/drawable/ic_swap_vert_white_24dp.xml create mode 100644 app/src/main/res/menu/bottom_navigation.xml diff --git a/app/build.gradle b/app/build.gradle index 6b272b21ae..cf15138ddb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -113,7 +113,7 @@ dependencies { // Android support library implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.cardview:cardview:1.0.0' - implementation 'com.google.android.material:material:1.0.0' + implementation 'com.google.android.material:material:1.2.0-alpha04' implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.preference:preference:1.1.0' implementation 'androidx.annotation:annotation:1.1.0' diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 842733af35..2dde9c1836 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.library import android.content.Context import android.content.res.Configuration import android.graphics.Color +import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.Menu @@ -11,6 +12,7 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.view.WindowInsets +import android.view.WindowManager import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode @@ -41,6 +43,7 @@ import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.category.CategoryController +import eu.kanade.tachiyomi.ui.download.DownloadController import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.migration.MigrationController @@ -443,9 +446,6 @@ class LibraryController( searchView.clearFocus() } - // Mutate the filter icon because it needs to be tinted and the resource is shared. - menu.findItem(R.id.action_filter).icon.mutate() - searchViewSubscription?.unsubscribe() searchViewSubscription = searchView.queryTextChanges() // Ignore events if this controller isn't at the top @@ -468,8 +468,10 @@ class LibraryController( val filterItem = menu.findItem(R.id.action_filter) // Tint icon if there's a filter active - val filterColor = if (navView.hasActiveFilters()) Color.rgb(255, 238, 7) else Color.WHITE - DrawableCompat.setTint(filterItem.icon, filterColor) + if (navView.hasActiveFilters()) + DrawableCompat.setTint(filterItem.icon, Color.rgb(255, 238, 7)) + else + DrawableCompat.clearColorFilter(filterItem.icon) } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -481,6 +483,9 @@ class LibraryController( R.id.action_edit_categories -> { router.pushController(CategoryController().withFadeTransaction()) } + R.id.action_downloads -> { + router.pushController(DownloadController().withFadeTransaction()) + } R.id.action_source_migration -> { router.pushController(MigrationController().withFadeTransaction()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index d34c7a0c11..e90bfb4095 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.main -import android.animation.ObjectAnimator import android.app.SearchManager import android.content.Intent import android.content.res.Configuration @@ -8,12 +7,12 @@ import android.graphics.Color import android.graphics.Rect import android.os.Build import android.os.Bundle +import android.provider.Settings import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.webkit.WebView import android.widget.FrameLayout -import android.widget.LinearLayout import android.widget.TextView import androidx.appcompat.graphics.drawable.DrawerArrowDrawable import androidx.biometric.BiometricManager @@ -126,7 +125,7 @@ open class MainActivity : BaseActivity() { setSupportActionBar(toolbar) drawerArrow = DrawerArrowDrawable(this) - drawerArrow?.color = Color.WHITE + drawerArrow?.color = getResourceColor(R.attr.actionBarTintColor) toolbar.navigationIcon = drawerArrow tabAnimator = TabsAnimator(tabs) @@ -158,9 +157,33 @@ open class MainActivity : BaseActivity() { true } + navigationView.setOnNavigationItemSelectedListener { item -> + val id = item.itemId + + val currentRoot = router.backstack.firstOrNull() + if (currentRoot?.tag()?.toIntOrNull() != id) { + when (id) { + R.id.nav_drawer_library -> setRoot(LibraryController(), id) + R.id.nav_drawer_recent_updates -> setRoot(RecentChaptersController(), id) + R.id.nav_drawer_recently_read -> setRoot(RecentlyReadController(), id) + R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id) + R.id.nav_drawer_extensions -> setRoot(ExtensionController(), id) + R.id.nav_drawer_downloads -> { + setRoot(DownloadController(), id) + } + R.id.nav_drawer_settings -> { + setRoot(SettingsMainController(), id) + } + R.id.nav_drawer_help -> { + openInBrowser(URL_HELP) + } + } + } + true + } val container: ViewGroup = findViewById(R.id.controller_container) - val content: LinearLayout = findViewById(R.id.main_content) + val content: ViewGroup = findViewById(R.id.main_content) container.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION @@ -209,6 +232,8 @@ open class MainActivity : BaseActivity() { if (Build.VERSION.SDK_INT >= 26 && currentNightMode == Configuration.UI_MODE_NIGHT_NO) { content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR } +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && currentNightMode == Configuration.UI_MODE_NIGHT_NO) { +// content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR val drawerContainer: FrameLayout = findViewById(R.id.drawer_container) drawerContainer.setOnApplyWindowInsetsListener { v, insets -> @@ -273,6 +298,23 @@ open class MainActivity : BaseActivity() { setExtensionsBadge() } + override fun startSupportActionMode(callback: androidx.appcompat.view.ActionMode.Callback): androidx.appcompat.view.ActionMode? { + window?.statusBarColor = getResourceColor(R.attr.colorPrimary) + return super.startSupportActionMode(callback) + } + + override fun onSupportActionModeFinished(mode: androidx.appcompat.view.ActionMode) { + launchUI { + val scale = Settings.Global.getFloat(contentResolver, Settings.Global + .ANIMATOR_DURATION_SCALE, 1.0f) + val duration = resources.getInteger(android.R.integer.config_mediumAnimTime) * scale + delay(duration.toLong()) + delay(100) + window?.statusBarColor = Color.TRANSPARENT + } + super.onSupportActionModeFinished(mode) + } + private fun setExtensionsBadge() { val extUpdateText: TextView = nav_view.menu.findItem( @@ -283,10 +325,12 @@ open class MainActivity : BaseActivity() { if (updates > 0) { extUpdateText.text = updates.toString() extUpdateText.visible() + navigationView.getOrCreateBadge(R.id.nav_drawer_settings).number = updates } else { extUpdateText.text = null extUpdateText.gone() + navigationView.getOrCreateBadge(R.id.nav_drawer_settings).clearNumber() } } @@ -390,8 +434,8 @@ open class MainActivity : BaseActivity() { val backstackSize = router.backstackSize if (drawer.isDrawerOpen(GravityCompat.START) || drawer.isDrawerOpen(GravityCompat.END)) { drawer.closeDrawers() - } else if (backstackSize == 1 && router.getControllerWithTag("$startScreenId") == null) { - setSelectedDrawerItem(startScreenId) + //} else if (backstackSize == 1 && router.getControllerWithTag("$startScreenId") == null) { + // setSelectedDrawerItem(startScreenId) } else if (!router.handleBack()) { unlocked = false super.onBackPressed() @@ -401,7 +445,9 @@ open class MainActivity : BaseActivity() { fun setSelectedDrawerItem(itemId: Int) { if (!isFinishing) { nav_view.setCheckedItem(itemId) + navigationView.selectedItemId = itemId nav_view.menu.performIdentifierAction(itemId, 0) + //navigationView.menu.performIdentifierAction(itemId, 0) } } @@ -441,13 +487,16 @@ open class MainActivity : BaseActivity() { } val showHamburger = router.backstackSize == 1 + drawer.setDrawerLockMode(androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED) if (showHamburger) { - drawer.setDrawerLockMode(androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_UNLOCKED) + toolbar.navigationIcon = null + //drawer.setDrawerLockMode(androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_UNLOCKED) } else { - drawer.setDrawerLockMode(androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED) + toolbar.navigationIcon = drawerArrow + // drawer.setDrawerLockMode(androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED) } - - ObjectAnimator.ofFloat(drawerArrow, "progress", if (showHamburger) 0f else 1f).start() + drawerArrow?.progress = 1f + //ObjectAnimator.ofFloat(drawerArrow, "alpha", if (showHamburger) 0f else 1f).start() if (from is TabbedController) { from.cleanupTabs(tabs) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt index 2ac8ea26ca..34cb4ab6c1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt @@ -1,17 +1,39 @@ package eu.kanade.tachiyomi.ui.setting import androidx.preference.PreferenceScreen +import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceKeys +import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.updater.UpdaterJob import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.ui.extension.ExtensionController +import uy.kohesive.injekt.injectLazy class SettingsMainController : SettingsController() { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { titleRes = R.string.label_settings val tintColor = context.getResourceColor(R.attr.colorAccent) + val preferencesH: PreferencesHelper by injectLazy() + + val updateCount = preferencesH.extensionUpdatesCount().getOrDefault() + preference { + iconRes = R.drawable.ic_extension_black_24dp + iconTint = tintColor + if (updateCount == 0) { + titleRes = R.string.label_extensions + } + else { + title = "${resources?.getString(R.string.label_extensions)} ${resources + ?.getQuantityString(R.plurals.extensions_updates_pendings, updateCount, + updateCount)}" + } + onClick { navigateTo(ExtensionController()) } + } preference { iconRes = R.drawable.ic_tune_black_24dp @@ -63,7 +85,7 @@ class SettingsMainController : SettingsController() { } } - private fun navigateTo(controller: SettingsController) { + private fun navigateTo(controller: Controller) { router.pushController(controller.withFadeTransaction()) } } diff --git a/app/src/main/res/drawable/action_mode_bg.xml b/app/src/main/res/drawable/action_mode_bg.xml new file mode 100644 index 0000000000..297a3310c1 --- /dev/null +++ b/app/src/main/res/drawable/action_mode_bg.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bottom_nav_item_selector.xml b/app/src/main/res/drawable/bottom_nav_item_selector.xml new file mode 100644 index 0000000000..e4e0225719 --- /dev/null +++ b/app/src/main/res/drawable/bottom_nav_item_selector.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_arrow_down_white_32dp.xml b/app/src/main/res/drawable/ic_arrow_down_white_32dp.xml index 47d9d1ca02..eea88a322b 100644 --- a/app/src/main/res/drawable/ic_arrow_down_white_32dp.xml +++ b/app/src/main/res/drawable/ic_arrow_down_white_32dp.xml @@ -2,7 +2,8 @@ android:width="32dp" android:height="32dp" android:viewportHeight="32" - android:viewportWidth="32"> + android:viewportWidth="32" + android:tint="?attr/actionBarTintColor"> + android:width="24dp" + xmlns:android="http://schemas.android.com/apk/res/android" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_content_copy_white_24dp.xml b/app/src/main/res/drawable/ic_content_copy_white_24dp.xml index 62ad953955..ebf0430c17 100644 --- a/app/src/main/res/drawable/ic_content_copy_white_24dp.xml +++ b/app/src/main/res/drawable/ic_content_copy_white_24dp.xml @@ -1,5 +1,6 @@ - + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_delete_white_24dp.xml b/app/src/main/res/drawable/ic_delete_white_24dp.xml index f9213d2b52..c804ca372d 100644 --- a/app/src/main/res/drawable/ic_delete_white_24dp.xml +++ b/app/src/main/res/drawable/ic_delete_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_done_all_white_24dp.xml b/app/src/main/res/drawable/ic_done_all_white_24dp.xml index 2479e86cea..dfec71ca44 100644 --- a/app/src/main/res/drawable/ic_done_all_white_24dp.xml +++ b/app/src/main/res/drawable/ic_done_all_white_24dp.xml @@ -1,5 +1,6 @@ - + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_edit_white_24dp.xml b/app/src/main/res/drawable/ic_edit_white_24dp.xml index 46462b5726..82decf34bd 100644 --- a/app/src/main/res/drawable/ic_edit_white_24dp.xml +++ b/app/src/main/res/drawable/ic_edit_white_24dp.xml @@ -1,5 +1,7 @@ - + android:width="24dp" + xmlns:android="http://schemas.android.com/apk/res/android" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_file_download_white_24dp.xml b/app/src/main/res/drawable/ic_file_download_white_24dp.xml index e43b8645a5..7fc108d2f7 100644 --- a/app/src/main/res/drawable/ic_file_download_white_24dp.xml +++ b/app/src/main/res/drawable/ic_file_download_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_filter_list_white_24dp.xml b/app/src/main/res/drawable/ic_filter_list_white_24dp.xml index 7d435fa2b8..c6c62aa87b 100644 --- a/app/src/main/res/drawable/ic_filter_list_white_24dp.xml +++ b/app/src/main/res/drawable/ic_filter_list_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_label_white_24dp.xml b/app/src/main/res/drawable/ic_label_white_24dp.xml index b3c9371449..a242b38e9b 100644 --- a/app/src/main/res/drawable/ic_label_white_24dp.xml +++ b/app/src/main/res/drawable/ic_label_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_refresh_white_24dp.xml b/app/src/main/res/drawable/ic_refresh_white_24dp.xml index a8175c316a..f7b235c8cf 100644 --- a/app/src/main/res/drawable/ic_refresh_white_24dp.xml +++ b/app/src/main/res/drawable/ic_refresh_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_search_white_24dp.xml b/app/src/main/res/drawable/ic_search_white_24dp.xml index 47432c174b..80b1837345 100644 --- a/app/src/main/res/drawable/ic_search_white_24dp.xml +++ b/app/src/main/res/drawable/ic_search_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_settings_white_24dp.xml b/app/src/main/res/drawable/ic_settings_white_24dp.xml index ce997a727d..1e5614c590 100644 --- a/app/src/main/res/drawable/ic_settings_white_24dp.xml +++ b/app/src/main/res/drawable/ic_settings_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_share_white_24dp.xml b/app/src/main/res/drawable/ic_share_white_24dp.xml index c5027c6598..63f2305b86 100644 --- a/app/src/main/res/drawable/ic_share_white_24dp.xml +++ b/app/src/main/res/drawable/ic_share_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportHeight="24.0" - android:viewportWidth="24.0"> + android:viewportWidth="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_sort_by_numeric_white_24dp.xml b/app/src/main/res/drawable/ic_sort_by_numeric_white_24dp.xml index 5bddea0f52..faa33a729b 100644 --- a/app/src/main/res/drawable/ic_sort_by_numeric_white_24dp.xml +++ b/app/src/main/res/drawable/ic_sort_by_numeric_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportHeight="24.0" - android:viewportWidth="24.0"> + android:viewportWidth="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_swap_vert_white_24dp.xml b/app/src/main/res/drawable/ic_swap_vert_white_24dp.xml new file mode 100644 index 0000000000..e1065c446b --- /dev/null +++ b/app/src/main/res/drawable/ic_swap_vert_white_24dp.xml @@ -0,0 +1,6 @@ + + + diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index dcf56075b1..868dfb7e58 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -13,7 +13,7 @@ android:layout_height="match_parent" android:fitsSystemWindows="true"> - @@ -49,9 +54,30 @@ + android:layout_height="0dp" + app:layout_constraintBottom_toTopOf="@+id/navigationView" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/appbar"> - + + + + + app:layout_constraintEnd_toEndOf="parent" + app:backgroundTint="?attr/colorAccent" /> \ No newline at end of file diff --git a/app/src/main/res/layout/recent_chapters_section_item.xml b/app/src/main/res/layout/recent_chapters_section_item.xml index 7068ec0cfe..e4925ace0d 100644 --- a/app/src/main/res/layout/recent_chapters_section_item.xml +++ b/app/src/main/res/layout/recent_chapters_section_item.xml @@ -13,7 +13,7 @@ android:id="@+id/section_text" style="@style/TextAppearance.Regular.SubHeading.Light.Bold" android:layout_width="wrap_content" - android:textColor="@color/md_white_1000" + android:textColor="?attr/actionBarTintColor" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:maxLines="1"/> diff --git a/app/src/main/res/layout/search_activity.xml b/app/src/main/res/layout/search_activity.xml index f86d95b044..91053cc7a7 100644 --- a/app/src/main/res/layout/search_activity.xml +++ b/app/src/main/res/layout/search_activity.xml @@ -30,7 +30,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/Theme.ActionBar.Tab" - app:tabIndicatorColor="@android:color/white" + app:tabIndicatorColor="?attr/actionBarTintColor" + app:tabTextColor="?attr/actionBarTintColor" app:tabInlineLabel="true" app:tabGravity="center" app:tabMode="scrollable" diff --git a/app/src/main/res/menu/bottom_navigation.xml b/app/src/main/res/menu/bottom_navigation.xml new file mode 100644 index 0000000000..2e363f6566 --- /dev/null +++ b/app/src/main/res/menu/bottom_navigation.xml @@ -0,0 +1,28 @@ + + + + + + + + + + diff --git a/app/src/main/res/menu/library.xml b/app/src/main/res/menu/library.xml index b7f6fa9a95..62e6974114 100644 --- a/app/src/main/res/menu/library.xml +++ b/app/src/main/res/menu/library.xml @@ -1,7 +1,8 @@ + tools:context=".MainActivity" + app:tint="@android:color/black"> + + - + + \ No newline at end of file diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 73f97a687b..ac24eb6c32 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -12,7 +12,9 @@ @color/md_white_1000_20 @color/md_grey_800 #3399FF + #212121 #212121 + @color/md_white_1000_38 @color/md_white_1000 @color/md_white_1000_70 diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 3774497356..da41c02c96 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -8,6 +8,11 @@ @color/readerDarkBackground + + + @@ -123,6 +129,8 @@ @dimen/fab_margin fitCenter bottom|right|end + @color/md_white_1000 + ?attr/colorAccent @color/md_white_1000 @@ -134,6 +142,8 @@ fitCenter bottom|right|end @color/md_white_1000 + @color/md_white_1000 + ?attr/colorAccent eu.kanade.tachiyomi.widget.FABMoveBehaviour diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 6be9fc8799..bffdee2160 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -6,7 +6,7 @@ diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index bffdee2160..6850e06f68 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -25,7 +25,6 @@ @style/CustomActionModeStyle @color/md_white_1000 @color/md_white_1000_76 - @color/rippleColor From a1d0d113b933221e6c3bea8c52827fdbce063235 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 1 Feb 2020 16:28:45 -0800 Subject: [PATCH 004/259] More work on the white + md2 --- app/src/main/AndroidManifest.xml | 1 + .../tachiyomi/ui/extension/ExtensionHolder.kt | 11 +++-- .../tachiyomi/ui/library/LibraryController.kt | 10 +++-- .../tachiyomi/ui/main/SearchActivity.kt | 12 +++-- .../manga/process/MigrationListController.kt | 11 +++-- .../tachiyomi/ui/setting/PreferenceDSL.kt | 5 +++ .../ui/setting/SettingsMainController.kt | 13 +----- .../tachiyomi/ui/webview/WebViewActivity.kt | 36 +++++++++------ .../widget/preference/ExtensionPreference.kt | 44 +++++++++++++++++++ .../res/drawable/button_bg_transparent.xml | 8 ++-- .../main/res/drawable/button_text_state.xml | 26 +++++++++++ .../drawable/ic_chevron_right_white_24dp.xml | 3 +- .../drawable/ic_expand_more_white_24dp.xml | 3 +- .../res/drawable/ic_select_all_white_24dp.xml | 3 +- .../main/res/drawable/ic_sort_white_24dp.xml | 3 +- .../res/drawable/ic_swap_calls_white_24dp.xml | 5 +++ .../main/res/layout/extension_card_item.xml | 8 ++-- .../res/layout/preference_update_text.xml | 15 +++++++ app/src/main/res/layout/search_activity.xml | 8 ++-- app/src/main/res/values-night/colors.xml | 1 + app/src/main/res/values-night/styles.xml | 2 +- app/src/main/res/values/colors.xml | 4 +- app/src/main/res/values/strings.xml | 6 +-- app/src/main/res/values/styles.xml | 8 ++-- app/src/main/res/values/themes.xml | 2 + 25 files changed, 187 insertions(+), 61 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/ExtensionPreference.kt create mode 100644 app/src/main/res/drawable/button_text_state.xml create mode 100644 app/src/main/res/drawable/ic_swap_calls_white_24dp.xml create mode 100644 app/src/main/res/layout/preference_update_text.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 493250655a..5f2ca60aae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,6 +30,7 @@ android:networkSecurityConfig="@xml/network_security_config"> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt index 5e92335b4a..8792fc9e17 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt @@ -1,5 +1,7 @@ package eu.kanade.tachiyomi.ui.extension +import android.content.res.ColorStateList +import android.graphics.Color import android.view.View import androidx.core.content.ContextCompat import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat @@ -60,8 +62,8 @@ class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) : isClickable = true isActivated = false - background = VectorDrawableCompat.create(resources!!, R.drawable.button_bg_transparent, null) - setTextColor(ContextCompat.getColorStateList(context, R.drawable.button_bg_transparent)) + //background = VectorDrawableCompat.create(resources!!, R.drawable.button_bg_transparent, null) + setTextColor(ContextCompat.getColorStateList(context, R.drawable.button_text_state)) val extension = item.extension @@ -82,11 +84,14 @@ class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) : when { extension.hasUpdate -> { isActivated = true + // backgroundTintList = ColorStateList(arrayOf(intArrayOf(0)), intArrayOf(Color + //.BLACK)) setText(R.string.ext_update) } extension.isObsolete -> { // Red outline - background = VectorDrawableCompat.create(resources, R.drawable.button_bg_error, null) + // background = VectorDrawableCompat.create(resources, R.drawable + // .button_bg_error, null) setTextColor(ContextCompat.getColorStateList(context, R.drawable.button_bg_error)) setText(R.string.ext_obsolete) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 2dde9c1836..78a1a1215b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -446,6 +446,9 @@ class LibraryController( searchView.clearFocus() } + // Mutate the filter icon because it needs to be tinted and the resource is shared. + menu.findItem(R.id.action_filter).icon.mutate() + searchViewSubscription?.unsubscribe() searchViewSubscription = searchView.queryTextChanges() // Ignore events if this controller isn't at the top @@ -468,10 +471,9 @@ class LibraryController( val filterItem = menu.findItem(R.id.action_filter) // Tint icon if there's a filter active - if (navView.hasActiveFilters()) - DrawableCompat.setTint(filterItem.icon, Color.rgb(255, 238, 7)) - else - DrawableCompat.clearColorFilter(filterItem.icon) + val filterColor = if (navView.hasActiveFilters()) Color.rgb(255, 238, 7) + else activity?.getResourceColor(R.attr.actionBarTintColor) ?: Color.WHITE + DrawableCompat.setTint(filterItem.icon, filterColor) } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/SearchActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/SearchActivity.kt index db0054b158..038ba7796e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/SearchActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/SearchActivity.kt @@ -39,7 +39,7 @@ class SearchActivity: MainActivity() { setSupportActionBar(sToolbar) drawerArrow = DrawerArrowDrawable(this) - drawerArrow?.color = Color.WHITE + drawerArrow?.color = getResourceColor(R.attr.actionBarTintColor) sToolbar.navigationIcon = drawerArrow tabAnimator = TabsAnimator(sTabs) @@ -87,9 +87,15 @@ class SearchActivity: MainActivity() { insets } val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - if (Build.VERSION.SDK_INT >= 26 && currentNightMode == Configuration.UI_MODE_NIGHT_NO) { - content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + if (Build.VERSION.SDK_INT >= 26 && currentNightMode == Configuration.UI_MODE_NIGHT_NO && + preferences.theme() >= 8) { + content.systemUiVisibility = content.systemUiVisibility.or(View + .SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && currentNightMode == Configuration + .UI_MODE_NIGHT_NO && preferences.theme() >= 8) + content.systemUiVisibility = content.systemUiVisibility.or(View + .SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) val drawerContainer: FrameLayout = findViewById(R.id.search_container) drawerContainer.setOnApplyWindowInsetsListener { v, insets -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt index b53d14efe5..473ac4cd09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt @@ -32,6 +32,7 @@ import eu.kanade.tachiyomi.util.system.await import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.system.toast +import eu.kanade.tachiyomi.util.system.getResourceColor import kotlinx.android.synthetic.main.chapters_controller.* import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope @@ -400,9 +401,13 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), resources!!, R.drawable.ic_done_white_24dp, null ) } - val translucentWhite = ColorUtils.setAlphaComponent(Color.WHITE, 127) - menuCopy.icon?.setTint(if (allMangasDone) Color.WHITE else translucentWhite) - menuMigrate?.icon?.setTint(if (allMangasDone) Color.WHITE else translucentWhite) + + menuCopy.icon.mutate() + menuMigrate.icon.mutate() + val tintColor = activity?.getResourceColor(R.attr.actionBarTintColor) ?: Color.WHITE + val translucentWhite = ColorUtils.setAlphaComponent(tintColor, 127) + menuCopy.icon?.setTint(if (allMangasDone) tintColor else translucentWhite) + menuMigrate?.icon?.setTint(if (allMangasDone) tintColor else translucentWhite) menuCopy.isEnabled = allMangasDone menuMigrate.isEnabled = allMangasDone } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt index 58037acb7f..58245c9be8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt @@ -9,6 +9,7 @@ import com.afollestad.materialdialogs.list.listItems import com.afollestad.materialdialogs.list.listItemsSingleChoice import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.widget.preference.ExtensionPreference import eu.kanade.tachiyomi.widget.preference.IntListMatPreference import eu.kanade.tachiyomi.widget.preference.IntListPreference import eu.kanade.tachiyomi.widget.preference.ListMatPreference @@ -29,6 +30,10 @@ inline fun PreferenceGroup.preference(block: (@DSL Preference).() -> Unit): Pref return initThenAdd(Preference(context), block) } +inline fun PreferenceGroup.extensionPreference(block: (@DSL Preference).() -> Unit): ExtensionPreference { + return initThenAdd(ExtensionPreference(context), block) +} + inline fun PreferenceGroup.switchPreference(block: (@DSL SwitchPreferenceCompat).() -> Unit): SwitchPreferenceCompat { return initThenAdd(SwitchPreferenceCompat(context), block) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt index 34cb4ab6c1..32bdc4f5d6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt @@ -18,20 +18,11 @@ class SettingsMainController : SettingsController() { titleRes = R.string.label_settings val tintColor = context.getResourceColor(R.attr.colorAccent) - val preferencesH: PreferencesHelper by injectLazy() - val updateCount = preferencesH.extensionUpdatesCount().getOrDefault() - preference { + extensionPreference { iconRes = R.drawable.ic_extension_black_24dp iconTint = tintColor - if (updateCount == 0) { - titleRes = R.string.label_extensions - } - else { - title = "${resources?.getString(R.string.label_extensions)} ${resources - ?.getQuantityString(R.plurals.extensions_updates_pendings, updateCount, - updateCount)}" - } + titleRes = R.string.label_extensions onClick { navigateTo(ExtensionController()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index d78609b60c..2167c9d77b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -71,6 +71,7 @@ class WebViewActivity : BaseActivity() { toolbar.setNavigationOnClickListener { super.onBackPressed() } + toolbar.navigationIcon?.setTint(getResourceColor(R.attr.actionBarTintColor)) val container:ViewGroup = findViewById(R.id.web_view_layout) val content: LinearLayout = findViewById(R.id.web_linear_layout) @@ -192,26 +193,34 @@ class WebViewActivity : BaseActivity() { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) + val currentNightMode = newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK + val lightMode = currentNightMode == Configuration.UI_MODE_NIGHT_NO window.statusBarColor = getResourceColor(R.attr.colorPrimary) toolbar.setBackgroundColor(getResourceColor(R.attr.colorPrimary)) + toolbar.popupTheme = if (lightMode) R.style.ThemeOverlay_MaterialComponents else R + .style.ThemeOverlay_MaterialComponents_Dark + val tintColor = getResourceColor(R.attr.actionBarTintColor) + toolbar.navigationIcon?.setTint(tintColor) + toolbar.overflowIcon?.mutate() + toolbar.setTitleTextColor(tintColor) + toolbar.overflowIcon?.setTint(tintColor) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) window.navigationBarColor = getResourceColor(android.R.attr.colorPrimary) else if (window.navigationBarColor != getColor(android.R.color.transparent)) window.navigationBarColor = getResourceColor(android.R.attr.colorBackground) - val currentNightMode = newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK - if (Build.VERSION.SDK_INT >= 26) { - if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) { - web_linear_layout.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - } else { - web_linear_layout.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or + web_linear_layout.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && lightMode) { + web_linear_layout.systemUiVisibility = web_linear_layout.systemUiVisibility.or(View + .SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && currentNightMode == Configuration - .UI_MODE_NIGHT_NO && preferences.theme() >= 8) - web_linear_layout.systemUiVisibility.or(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && lightMode && preferences.theme() >= 8) + web_linear_layout.systemUiVisibility = web_linear_layout.systemUiVisibility + .or(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) + invalidateOptionsMenu() } /** @@ -230,9 +239,10 @@ class WebViewActivity : BaseActivity() { val hasHistory = webview.canGoBack() || webview.canGoForward() backItem?.isVisible = hasHistory forwardItem?.isVisible = hasHistory - val translucentWhite = ColorUtils.setAlphaComponent(Color.WHITE, 127) - backItem.icon?.setTint(if (webview.canGoBack()) Color.WHITE else translucentWhite) - forwardItem?.icon?.setTint(if (webview.canGoForward()) Color.WHITE else translucentWhite) + val tintColor = getResourceColor(R.attr.actionBarTintColor) + val translucentWhite = ColorUtils.setAlphaComponent(tintColor, 127) + backItem.icon?.setTint(if (webview.canGoBack()) tintColor else translucentWhite) + forwardItem?.icon?.setTint(if (webview.canGoForward()) tintColor else translucentWhite) return super.onPrepareOptionsMenu(menu) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ExtensionPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ExtensionPreference.kt new file mode 100644 index 0000000000..00d16a3a22 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ExtensionPreference.kt @@ -0,0 +1,44 @@ +package eu.kanade.tachiyomi.widget.preference + +import android.content.Context +import androidx.preference.Preference +import androidx.preference.PreferenceViewHolder +import android.util.AttributeSet +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.util.gone +import eu.kanade.tachiyomi.util.visible +import kotlinx.android.synthetic.main.preference_update_text.view.* +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get + +class ExtensionPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + Preference(context, attrs) { + + init { + widgetLayoutResource = R.layout.preference_update_text + } + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + + val extUpdateText = holder.itemView.textView + + val updates = Injekt.get().extensionUpdatesCount().getOrDefault() + if (updates > 0) { + extUpdateText.text = context.resources.getQuantityString(R.plurals + .extensions_updates_available, updates, updates) + extUpdateText.visible() + } + else { + extUpdateText.text = null + extUpdateText.gone() + } + } + + override public fun notifyChanged() { + super.notifyChanged() + } + +} diff --git a/app/src/main/res/drawable/button_bg_transparent.xml b/app/src/main/res/drawable/button_bg_transparent.xml index c23d7a920d..8fc57a2aee 100644 --- a/app/src/main/res/drawable/button_bg_transparent.xml +++ b/app/src/main/res/drawable/button_bg_transparent.xml @@ -1,9 +1,9 @@ - + - + @@ -15,11 +15,11 @@ - + - + diff --git a/app/src/main/res/drawable/button_text_state.xml b/app/src/main/res/drawable/button_text_state.xml new file mode 100644 index 0000000000..67d93fbdf9 --- /dev/null +++ b/app/src/main/res/drawable/button_text_state.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_chevron_right_white_24dp.xml b/app/src/main/res/drawable/ic_chevron_right_white_24dp.xml index 36b411acea..df58d8e473 100644 --- a/app/src/main/res/drawable/ic_chevron_right_white_24dp.xml +++ b/app/src/main/res/drawable/ic_chevron_right_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_expand_more_white_24dp.xml b/app/src/main/res/drawable/ic_expand_more_white_24dp.xml index fd3ce4a468..89a9bc5175 100644 --- a/app/src/main/res/drawable/ic_expand_more_white_24dp.xml +++ b/app/src/main/res/drawable/ic_expand_more_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_select_all_white_24dp.xml b/app/src/main/res/drawable/ic_select_all_white_24dp.xml index 0fc49c9237..b3dc6b3583 100644 --- a/app/src/main/res/drawable/ic_select_all_white_24dp.xml +++ b/app/src/main/res/drawable/ic_select_all_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_sort_white_24dp.xml b/app/src/main/res/drawable/ic_sort_white_24dp.xml index a0c153ad01..5e666748a9 100644 --- a/app/src/main/res/drawable/ic_sort_white_24dp.xml +++ b/app/src/main/res/drawable/ic_sort_white_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/drawable/ic_swap_calls_white_24dp.xml b/app/src/main/res/drawable/ic_swap_calls_white_24dp.xml new file mode 100644 index 0000000000..141acfc7ce --- /dev/null +++ b/app/src/main/res/drawable/ic_swap_calls_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/extension_card_item.xml b/app/src/main/res/layout/extension_card_item.xml index 016ee06fc2..618c34854b 100644 --- a/app/src/main/res/layout/extension_card_item.xml +++ b/app/src/main/res/layout/extension_card_item.xml @@ -68,13 +68,13 @@ \ No newline at end of file diff --git a/app/src/main/res/menu/main_sort.xml b/app/src/main/res/menu/main_sort.xml index 6c4e187902..c65b085088 100644 --- a/app/src/main/res/menu/main_sort.xml +++ b/app/src/main/res/menu/main_sort.xml @@ -1,35 +1,35 @@ - + android:title="@string/title" + android:icon="@drawable/ic_blank_24dp"/> + android:title="@string/action_sort_last_read" + android:icon="@drawable/ic_blank_24dp"/> + android:title="@string/action_sort_last_updated" + android:icon="@drawable/ic_blank_24dp"/> + android:title="@string/action_filter_unread" + android:icon="@drawable/ic_blank_24dp"/> + android:title="@string/action_sort_total" + android:icon="@drawable/ic_blank_24dp"/> + android:title="@string/action_sort_drag_and_drop" + android:icon="@drawable/ic_blank_24dp"/> - - - \ 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 c54d0ec70c..9b175c3ac3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,6 +51,8 @@ Sorting by %1$s Sort by: %1$s + Sort library by: %1$s + Sort category by: %1$s Remove filter Alphabetically Enabled From 05cb2c0b6b7ee693a0b698dce814915133233fbb Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 8 Feb 2020 16:40:19 -0800 Subject: [PATCH 031/259] Added Unread badge option And with this, the filter bottom sheet is done --- .../data/preference/PreferencesHelper.kt | 2 + .../ui/catalogue/browse/CatalogueItem.kt | 8 ++- .../ui/library/LibraryCategoryView.kt | 11 ++- .../tachiyomi/ui/library/LibraryController.kt | 14 +++- .../tachiyomi/ui/library/LibraryGridHolder.kt | 19 +++-- .../tachiyomi/ui/library/LibraryItem.kt | 1 + .../tachiyomi/ui/library/LibraryListHolder.kt | 12 +++- .../tachiyomi/ui/library/LibraryPresenter.kt | 30 +++++++- .../ui/library/filter/FilterBottomSheet.kt | 71 +++++++++++++++---- .../res/drawable/ic_looks_two_white_24dp.xml | 5 ++ .../drawable/ic_unread_circle_white_24dp.xml | 5 ++ .../main/res/drawable/unread_circle_badge.xml | 31 ++++++++ .../res/layout-land/filter_bottom_sheet.xml | 36 ++++++++-- .../layout-sw600dp/filter_bottom_sheet.xml | 36 ++++++++-- .../main/res/layout/catalogue_grid_item.xml | 9 +++ .../main/res/layout/catalogue_list_item.xml | 57 +++++++++------ .../main/res/layout/filter_bottom_sheet.xml | 34 ++++++++- app/src/main/res/menu/unread_badge.xml | 17 +++++ app/src/main/res/values/strings.xml | 4 ++ 19 files changed, 339 insertions(+), 63 deletions(-) create mode 100644 app/src/main/res/drawable/ic_looks_two_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_unread_circle_white_24dp.xml create mode 100644 app/src/main/res/drawable/unread_circle_badge.xml create mode 100644 app/src/main/res/menu/unread_badge.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 8bf8e6dbd1..84842121c0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -239,6 +239,8 @@ class PreferencesHelper(val context: Context) { fun lastExtCheck() = rxPrefs.getLong("last_ext_check", 0) + fun unreadBadgeType() = rxPrefs.getInteger("unread_badge_type", 1) + fun upgradeFilters() { val filterDl = rxPrefs.getBoolean(Keys.filterDownloaded, false).getOrDefault() val filterUn = rxPrefs.getBoolean(Keys.filterUnread, false).getOrDefault() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt index 311bd46345..a31b5fbf86 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt @@ -12,6 +12,7 @@ import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.catalogue_grid_item.view.* @@ -29,8 +30,11 @@ class CatalogueItem(val manga: Manga, private val catalogueAsList: Preference v.updatePaddingRelative(bottom = padding.bottom + insets.systemWindowInsetBottom) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index d27378ead0..7d3ff9aecc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -228,7 +228,9 @@ class LibraryController( FilterBottomSheet.ACTION_FILTER -> onFilterChanged() FilterBottomSheet.ACTION_SORT -> onSortChanged() FilterBottomSheet.ACTION_DISPLAY -> reattachAdapter() - FilterBottomSheet.ACTION_BADGE -> onDownloadBadgeChanged() + FilterBottomSheet.ACTION_DOWNLOAD_BADGE -> + presenter.requestDownloadBadgesUpdate() + FilterBottomSheet.ACTION_UNREAD_BADGE -> presenter.requestUnreadBadgesUpdate() FilterBottomSheet.ACTION_CAT_SORT -> onCatSortChanged() } } @@ -566,8 +568,14 @@ class LibraryController( when (item.itemId) { R.id.action_search -> expandActionViewFromInteraction = true R.id.action_library_filter -> { - if (MainActivity.bottomNav) bottom_sheet.sheetBehavior?.state = - BottomSheetBehavior.STATE_EXPANDED + if (MainActivity.bottomNav) { + if (bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED) + bottom_sheet.sheetBehavior?.state = + BottomSheetBehavior.STATE_EXPANDED + else + bottom_sheet.sheetBehavior?.state = + BottomSheetBehavior.STATE_COLLAPSED + } else navView?.let { activity?.drawer?.openDrawer(GravityCompat.END) } } R.id.action_edit_categories -> { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 6d576fdf00..36ba87f93c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.library import android.view.View +import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.signature.ObjectKey @@ -9,6 +10,8 @@ import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource +import eu.kanade.tachiyomi.util.system.dpToPx +import eu.kanade.tachiyomi.util.view.updateLayoutParams import kotlinx.android.synthetic.main.catalogue_grid_item.* /** @@ -42,25 +45,27 @@ class LibraryGridHolder( // Update the unread count and its visibility. with(unread_text) { - visibility = if (item.manga.unread > 0) View.VISIBLE else View.GONE + visibility = + if (item.manga.unread > 0 && item.unreadType == 1) View.VISIBLE else View.GONE text = item.manga.unread.toString() } // Update the download count and its visibility. + unread_badge.visibility = + if (item.manga.unread > 0 && item.unreadType == 0) View.VISIBLE else View.GONE with(download_text) { visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE text = item.downloadCount.toString() } //set local visibility if its local manga - local_text.visibility = if(item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE + local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE // Update the cover. GlideApp.with(view.context).clear(thumbnail) GlideApp.with(view.context) - .load(item.manga) - .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) - .signature(ObjectKey(MangaImpl.getLastCoverFetch(item.manga.id!!).toString())) - .centerCrop() - .into(thumbnail) + .load(item.manga) + .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) + .signature(ObjectKey(MangaImpl.getLastCoverFetch(item.manga.id!!).toString())) + .centerCrop().into(thumbnail) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 062fb173eb..1e0a00308c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -23,6 +23,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference AbstractFlexibleItem(), IFilterable { var downloadCount = -1 + var unreadType = 1 override fun getLayoutRes(): Int { return if (libraryAsList.getOrDefault()) 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 ab3a2ca3d8..5e8e6862cf 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 @@ -10,6 +10,13 @@ import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.signature.ObjectKey import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.data.database.models.MangaImpl +import kotlinx.android.synthetic.main.catalogue_grid_item.* +import kotlinx.android.synthetic.main.catalogue_list_item.download_text +import kotlinx.android.synthetic.main.catalogue_list_item.local_text +import kotlinx.android.synthetic.main.catalogue_list_item.thumbnail +import kotlinx.android.synthetic.main.catalogue_list_item.title +import kotlinx.android.synthetic.main.catalogue_list_item.unread_badge +import kotlinx.android.synthetic.main.catalogue_list_item.unread_text /** * Class used to hold the displayed data of a manga in the library, like the cover or the title. @@ -38,9 +45,12 @@ class LibraryListHolder( // Update the unread count and its visibility. with(unread_text) { - visibility = if (item.manga.unread > 0) View.VISIBLE else View.GONE + visibility = if (item.manga.unread > 0 && item.unreadType == 1) View.VISIBLE else + View.GONE text = item.manga.unread.toString() } + unread_badge.visibility = + if (item.manga.unread > 0 && item.unreadType == 0) View.VISIBLE else View.GONE // Update the download count and its visibility. with(download_text) { visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE 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 b34f1e015f..60d077d820 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 @@ -217,6 +217,15 @@ class LibraryPresenter( } } + private fun setUnreadBadge(map: LibraryMap) { + val unreadType = preferences.unreadBadgeType().getOrDefault() + for ((_, itemList) in map) { + for (item in itemList) { + item.unreadType = unreadType + } + } + } + private fun applyCatSort(map: LibraryMap, catId: Int?): LibraryMap { if (catId == null) return map val categoryManga = map[catId] ?: return map @@ -400,11 +409,12 @@ class LibraryPresenter( val categories = db.getCategories().executeAsBlocking().toMutableList() val libraryAsList = preferences.libraryAsList() val showCategories = !preferences.hideCategories().getOrDefault() + val unreadBadgeType = preferences.unreadBadgeType().getOrDefault() var libraryManga = db.getLibraryMangas().executeAsBlocking() if (!showCategories) libraryManga = libraryManga.distinctBy { it.id } val libraryMap = libraryManga.map { manga -> - LibraryItem(manga, libraryAsList) + LibraryItem(manga, libraryAsList).apply { unreadType = unreadBadgeType } }.groupBy { if (showCategories) it.manga.category else 0 } @@ -488,7 +498,7 @@ class LibraryPresenter( } /** - * Requests the library to have download badges added. + * Requests the library to have download badges added/removed. */ fun requestDownloadBadgesUpdate() { //getLibrary() @@ -503,6 +513,22 @@ class LibraryPresenter( } } + /** + * Requests the library to have unread badges changed. + */ + fun requestUnreadBadgesUpdate() { + //getLibrary() + launchUI { + val mangaMap = rawMangaMap ?: return@launchUI + withContext(Dispatchers.IO) { setUnreadBadge(mangaMap) } + rawMangaMap = mangaMap + val current = currentMangaMap ?: return@launchUI + withContext(Dispatchers.IO) { setUnreadBadge(current) } + currentMangaMap = current + view?.onNextLibraryUpdate(categories, current) + } + } + /** * Requests the library to be sorted. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt index 561b9c5fcb..94b4bcb863 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt @@ -41,6 +41,7 @@ import kotlinx.coroutines.withContext import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy +import kotlin.math.min import kotlin.math.roundToInt class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) @@ -103,7 +104,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri topbar.setOnClickListener { if (sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED) { sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED - topbar.animate().alpha(0f).setDuration(100).start() + //topbar.animate().alpha(0f).setDuration(100).start() } else { sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED } @@ -131,8 +132,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } }) topbar.viewTreeObserver.addOnGlobalLayoutListener { - val phoneLandscape = (context.resources.configuration?.orientation == - Configuration.ORIENTATION_LANDSCAPE && !isTablet()) + val phoneLandscape = (isLandscape() && !isTablet()) sheetBehavior?.peekHeight = if (phoneLandscape) { if (shadow2.visibility != View.GONE) { shadow.gone() @@ -162,7 +162,11 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri downloadCheckbox.isChecked = preferences.downloadBadge().getOrDefault() downloadCheckbox.setOnCheckedChangeListener { _, isChecked -> preferences.downloadBadge().set(isChecked) - onGroupClicked(ACTION_BADGE) + onGroupClicked(ACTION_DOWNLOAD_BADGE) + } + setUnreadIcon() + unread_badge.setOnClickListener { + showUnreadMenu() } displayGroup.bindToPreference(preferences.libraryAsList()) @@ -376,7 +380,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri !preferences.librarySortingAscending().getOrDefault() -> R.drawable.ic_arrow_down_white_24dp else -> R.drawable.ic_arrow_up_white_24dp - }, android.R.attr.colorAccent + } ) // Finally show the PopupMenu @@ -417,8 +421,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri currentItem?.icon = tintVector( if (category.isAscending()) R.drawable.ic_arrow_up_white_24dp - else R.drawable.ic_arrow_down_white_24dp, - android.R.attr.colorAccent + else R.drawable.ic_arrow_down_white_24dp ) // Finally show the PopupMenu @@ -498,7 +501,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri sortId == LibrarySort.DRAG_AND_DROP -> R.drawable.ic_sort_white_24dp preferences.librarySortingAscending().getOrDefault() -> R.drawable.ic_arrow_up_white_24dp else -> R.drawable.ic_arrow_down_white_24dp - }, android.R.attr.colorAccent + } ) } mainSortTextView.text = withContext(Dispatchers.IO) { @@ -534,7 +537,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri sortId == LibrarySort.DRAG_AND_DROP -> R.drawable.ic_label_outline_white_24dp lastCategory?.isAscending() == true -> R.drawable.ic_arrow_up_white_24dp else -> R.drawable.ic_arrow_down_white_24dp - }, android.R.attr.colorAccent + } ) } catSortTextView.text = withContext(Dispatchers.IO) { @@ -573,9 +576,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri private fun Boolean.toInt() = if (this) 1 else 0 - private fun tintVector(resId: Int, attrId: Int? = null): Drawable? { + private fun tintVector(resId: Int): Drawable? { return ContextCompat.getDrawable(context, resId)?.mutate()?.apply { - setTint(context.getResourceColor(attrId ?: android.R.attr.textColorPrimary)) + setTint(context.getResourceColor(android.R.attr.colorAccent)) } } @@ -639,12 +642,54 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri filterScrollView.scrollTo(0, 0) } + private fun showUnreadMenu() { + val popup = PopupMenu(context, unread_badge) + + popup.menuInflater.inflate(R.menu.unread_badge, popup.menu) + + popup.menu.getItem(min(preferences.unreadBadgeType().getOrDefault(), 1) + 1).isChecked = + true + + popup.setOnMenuItemClickListener { menuItem -> + preferences.unreadBadgeType().set(when (menuItem.itemId) { + R.id.action_no_unread -> -1 + R.id.action_any_unread -> 0 + else -> 1 + }) + setUnreadIcon() + onGroupClicked(ACTION_UNREAD_BADGE) + true + } + + // Finally show the PopupMenu + popup.show() + } + + private fun setUnreadIcon() { + launchUI { + val unreadType = preferences.unreadBadgeType().getOrDefault() + val drawableL = withContext(Dispatchers.IO) { + tintVector( + when (unreadType){ + -1 -> R.drawable.ic_check_box_outline_blank_24dp + 0 -> R.drawable.ic_unread_circle_white_24dp + else -> R.drawable.ic_looks_two_white_24dp + } + ) + } + unread_badge.setCompoundDrawablesRelativeWithIntrinsicBounds( + drawableL, null, null, null + ) + } + } + companion object { const val ACTION_REFRESH = 0 const val ACTION_SORT = 1 const val ACTION_FILTER = 2 const val ACTION_DISPLAY = 3 - const val ACTION_BADGE = 4 - const val ACTION_CAT_SORT = 5 + const val ACTION_DOWNLOAD_BADGE = 4 + const val ACTION_UNREAD_BADGE = 5 + const val ACTION_CAT_SORT = 6 } } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_looks_two_white_24dp.xml b/app/src/main/res/drawable/ic_looks_two_white_24dp.xml new file mode 100644 index 0000000000..ee5c6813bd --- /dev/null +++ b/app/src/main/res/drawable/ic_looks_two_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_unread_circle_white_24dp.xml b/app/src/main/res/drawable/ic_unread_circle_white_24dp.xml new file mode 100644 index 0000000000..30ca019ba8 --- /dev/null +++ b/app/src/main/res/drawable/ic_unread_circle_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/unread_circle_badge.xml b/app/src/main/res/drawable/unread_circle_badge.xml new file mode 100644 index 0000000000..ddccd146f3 --- /dev/null +++ b/app/src/main/res/drawable/unread_circle_badge.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/filter_bottom_sheet.xml b/app/src/main/res/layout-land/filter_bottom_sheet.xml index a708f43901..30e8c0bcd2 100644 --- a/app/src/main/res/layout-land/filter_bottom_sheet.xml +++ b/app/src/main/res/layout-land/filter_bottom_sheet.xml @@ -127,7 +127,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="7dp" - android:layout_marginEnd="14dp" + android:layout_marginEnd="30dp" android:baselineAligned="false" android:gravity="center|start" android:orientation="horizontal"> @@ -166,11 +166,39 @@ - + android:orientation="horizontal" + android:baselineAligned="false" + android:gravity="center|start" + > + + + + + + diff --git a/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml b/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml index a708f43901..30e8c0bcd2 100644 --- a/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml +++ b/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml @@ -127,7 +127,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="7dp" - android:layout_marginEnd="14dp" + android:layout_marginEnd="30dp" android:baselineAligned="false" android:gravity="center|start" android:orientation="horizontal"> @@ -166,11 +166,39 @@ - + android:orientation="horizontal" + android:baselineAligned="false" + android:gravity="center|start" + > + + + + + + diff --git a/app/src/main/res/layout/catalogue_grid_item.xml b/app/src/main/res/layout/catalogue_grid_item.xml index 40f28733b3..818ad16e42 100644 --- a/app/src/main/res/layout/catalogue_grid_item.xml +++ b/app/src/main/res/layout/catalogue_grid_item.xml @@ -30,6 +30,7 @@ android:background="@drawable/gradient_shape"/> + + + diff --git a/app/src/main/res/layout/catalogue_list_item.xml b/app/src/main/res/layout/catalogue_list_item.xml index 9ebe487993..4a8c1374b9 100644 --- a/app/src/main/res/layout/catalogue_list_item.xml +++ b/app/src/main/res/layout/catalogue_list_item.xml @@ -59,6 +59,32 @@ android:textColor="@color/md_white_1000" tools:visibility="visible" android:layout_marginEnd="8dp" + app:layout_constraintEnd_toStartOf="@+id/download_text" + app:layout_constraintTop_toTopOf="parent" + android:layout_marginTop="8dp" + app:layout_constraintBottom_toBottomOf="parent" + android:layout_marginBottom="8dp"/> + + + + - + android:src="@drawable/unread_circle_badge"/> diff --git a/app/src/main/res/layout/filter_bottom_sheet.xml b/app/src/main/res/layout/filter_bottom_sheet.xml index 6fe0dba0af..d9f5008fd6 100644 --- a/app/src/main/res/layout/filter_bottom_sheet.xml +++ b/app/src/main/res/layout/filter_bottom_sheet.xml @@ -162,11 +162,39 @@ - + android:orientation="horizontal" + android:baselineAligned="false" + android:gravity="center|start" + > + + + + + + diff --git a/app/src/main/res/menu/unread_badge.xml b/app/src/main/res/menu/unread_badge.xml new file mode 100644 index 0000000000..c38db226fd --- /dev/null +++ b/app/src/main/res/menu/unread_badge.xml @@ -0,0 +1,17 @@ + + + + + + + + + \ 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 9b175c3ac3..519ef79208 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -97,6 +97,10 @@ Grid List Download badges + Unread badges + All unread + Any unread + Hide unread Set filter Cancel Sort From d4153a9f413dbe7c37a1c76cfc086bb731cc98dc Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 8 Feb 2020 18:59:51 -0800 Subject: [PATCH 032/259] Refactoring Library and Filter Bottom Sheet Library controller is no longer rx Library presenter is no longer rx --- .../tachiyomi/ui/library/LibraryController.kt | 76 ++++---- .../tachiyomi/ui/library/LibraryPresenter.kt | 100 +---------- .../ui/library/filter/SortBottomSheet.kt | 168 ------------------ ...ottomSheet.kt => SortFilterBottomSheet.kt} | 88 ++++----- .../kanade/tachiyomi/ui/main/MainActivity.kt | 28 +-- .../recently_read/RecentlyReadController.kt | 2 +- .../ui/setting/SettingsGeneralController.kt | 1 + .../res/drawable/ic_history_white_128dp.xml | 6 + .../res/layout-land/filter_bottom_sheet.xml | 36 ++-- .../layout-sw600dp/filter_bottom_sheet.xml | 36 ++-- .../main/res/layout/filter_bottom_sheet.xml | 36 ++-- 11 files changed, 166 insertions(+), 411 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortBottomSheet.kt rename app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/{FilterBottomSheet.kt => SortFilterBottomSheet.kt} (90%) create mode 100644 app/src/main/res/drawable/ic_history_white_128dp.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 7d3ff9aecc..63cff94a1d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -27,8 +27,6 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayout -import com.jakewharton.rxbinding.support.v4.view.pageSelections -import com.jakewharton.rxbinding.support.v7.widget.queryTextChanges import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.PublishRelay import eu.kanade.tachiyomi.R @@ -41,13 +39,13 @@ import eu.kanade.tachiyomi.data.library.LibraryServiceListener import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault -import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.category.CategoryController import eu.kanade.tachiyomi.ui.download.DownloadController -import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet +import eu.kanade.tachiyomi.ui.library.filter.SortFilterBottomSheet import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.migration.MigrationController @@ -75,7 +73,7 @@ import uy.kohesive.injekt.api.get class LibraryController( bundle: Bundle? = null, private val preferences: PreferencesHelper = Injekt.get() -) : NucleusController(bundle), +) : BaseController(bundle), TabbedController, SecondaryDrawerController, ActionMode.Callback, @@ -154,18 +152,16 @@ class LibraryController( /** * Drawer listener to allow swipe only for closing the drawer. */ - private var drawerListener: DrawerLayout.DrawerListener? = null - private var tabsVisibilityRelay: BehaviorRelay = BehaviorRelay.create(false) private var tabsVisibilitySubscription: Subscription? = null - private var searchViewSubscription: Subscription? = null - var snack: Snackbar? = null private var reorderMenuItem:MenuItem? = null + private var presenter = LibraryPresenter(this) + init { setHasOptionsMenu(true) retainViewMode = RetainViewMode.RETAIN_DETACH @@ -174,11 +170,6 @@ class LibraryController( override fun getTitle(): String? { return resources?.getString(R.string.label_library) } - - override fun createPresenter(): LibraryPresenter { - return LibraryPresenter() - } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { return inflater.inflate(R.layout.library_controller, container, false) } @@ -188,10 +179,20 @@ class LibraryController( adapter = LibraryAdapter(this) library_pager.adapter = adapter - library_pager.pageSelections().skip(1).subscribeUntilDestroy { - preferences.lastUsedCategory().set(it) - activeCategory = it - } + library_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageSelected(position: Int) { + preferences.lastUsedCategory().set(position) + activeCategory = position + } + + override fun onPageScrollStateChanged(state: Int) { } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { } + }) library_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { override fun onPageSelected(position: Int) { @@ -209,11 +210,7 @@ class LibraryController( override fun onPageScrollStateChanged(state: Int) { } }) - getColumnsPreferenceForCurrentOrientation().asObservable() - .doOnNext { mangaPerRow = it } - .skip(1) - // Set again the adapter to recalculate the covers height - .subscribeUntilDestroy { reattachAdapter() } + mangaPerRow = getColumnsPreferenceForCurrentOrientation().getOrDefault() if (selectedMangas.isNotEmpty()) { createActionModeIfNeeded() @@ -224,14 +221,14 @@ class LibraryController( bottom_sheet.onGroupClicked = { when (it) { - FilterBottomSheet.ACTION_REFRESH -> onRefresh() - FilterBottomSheet.ACTION_FILTER -> onFilterChanged() - FilterBottomSheet.ACTION_SORT -> onSortChanged() - FilterBottomSheet.ACTION_DISPLAY -> reattachAdapter() - FilterBottomSheet.ACTION_DOWNLOAD_BADGE -> + SortFilterBottomSheet.ACTION_REFRESH -> onRefresh() + SortFilterBottomSheet.ACTION_FILTER -> onFilterChanged() + SortFilterBottomSheet.ACTION_SORT -> onSortChanged() + SortFilterBottomSheet.ACTION_DISPLAY -> reattachAdapter() + SortFilterBottomSheet.ACTION_DOWNLOAD_BADGE -> presenter.requestDownloadBadgesUpdate() - FilterBottomSheet.ACTION_UNREAD_BADGE -> presenter.requestUnreadBadgesUpdate() - FilterBottomSheet.ACTION_CAT_SORT -> onCatSortChanged() + SortFilterBottomSheet.ACTION_UNREAD_BADGE -> presenter.requestUnreadBadgesUpdate() + SortFilterBottomSheet.ACTION_CAT_SORT -> onCatSortChanged() } } @@ -528,15 +525,19 @@ class LibraryController( // Mutate the filter icon because it needs to be tinted and the resource is shared. menu.findItem(R.id.action_library_filter).icon.mutate() - searchViewSubscription?.unsubscribe() - searchViewSubscription = searchView.queryTextChanges() - // Ignore events if this controller isn't at the top - .filter { router.backstack.lastOrNull()?.controller() == this } - .subscribeUntilDestroy { - query = it.toString() + searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + override fun onQueryTextChange(newText: String?): Boolean { + if (router.backstack.lastOrNull()?.controller() == this@LibraryController) { + query = newText ?: "" searchRelay.call(query) } + return true + } + override fun onQueryTextSubmit(query: String?): Boolean { + return true + } + }) searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() }) } @@ -712,9 +713,6 @@ class LibraryController( } fun openManga(manga: Manga, startY: Float?) { - // Notify the presenter a manga is being opened. - presenter.onOpenManga() - router.pushController(MangaController(manga, startY).withFadeTransaction()) } 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 60d077d820..63c68d754e 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 @@ -55,12 +55,13 @@ private typealias LibraryMap = Map> * Presenter of [LibraryController]. */ class LibraryPresenter( + private val view: LibraryController, private val db: DatabaseHelper = Injekt.get(), private val preferences: PreferencesHelper = Injekt.get(), private val coverCache: CoverCache = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get() -) : BasePresenter() { +) { private val context = preferences.context @@ -80,33 +81,6 @@ class LibraryPresenter( private var currentMangaMap:LibraryMap? = null - override fun onCreate(savedState: Bundle?) { - super.onCreate(savedState) - getLibrary() - } - - /** - * Subscribes to library if needed. - */ - /* fun subscribeLibrary() { - if (librarySubscription.isNullOrUnsubscribed()) { - librarySubscription = getLibraryObservable() - .combineLatest(downloadTriggerRelay.observeOn(Schedulers.io())) { - lib, _ -> lib.apply { setDownloadCount(mangaMap) } - } - .combineLatest(filterTriggerRelay.observeOn(Schedulers.io())) { - lib, _ -> lib.copy(mangaMap = applyFilters(lib.mangaMap)) - } - .combineLatest(sortTriggerRelay.observeOn(Schedulers.io())) { - lib, _ -> lib.copy(mangaMap = applySort(lib.mangaMap)) - } - .observeOn(AndroidSchedulers.mainThread()) - .subscribeLatestCache({ view, (categories, mangaMap) -> - view.onNextLibraryUpdate(categories, mangaMap) - }) - } - }*/ - fun getLibrary() { launchUI { val mangaMap = withContext(Dispatchers.IO) { @@ -119,7 +93,7 @@ class LibraryPresenter( mangaMap } currentMangaMap = mangaMap - view?.onNextLibraryUpdate(categories, mangaMap) + view.onNextLibraryUpdate(categories, mangaMap) } } @@ -428,25 +402,6 @@ class LibraryPresenter( return Library(this.categories, libraryMap) } - /** - * Get the categories and all its manga from the database. - * - * @return an observable of the categories and its manga. - */ - /*private fun getLibraryObservable(): Observable { - return Observable.combineLatest(getCategoriesObservable(), getLibraryMangasObservable()) { dbCategories, libraryManga -> - val categories = if (libraryManga.containsKey(0)) - arrayListOf(createDefaultCategory()) + dbCategories - else dbCategories - - this.allCategories = categories - this.categories = if (preferences.hideCategories().getOrDefault()) - arrayListOf(createDefaultCategory()) - else categories - Library(this.categories, libraryManga) - } - }*/ - private fun createDefaultCategory(): Category { val default = Category.createDefault(context) val defOrder = preferences.defaultMangaOrder().getOrDefault() @@ -454,36 +409,7 @@ class LibraryPresenter( else default.mangaOrder = defOrder.split("/").mapNotNull { it.toLongOrNull() } return default } -/* - /** - * Get the categories from the database. - * - * @return an observable of the categories. - */ - private fun getCategoriesObservable(): Observable> { - return db.getCategories().asRxObservable() - } - /** - * Get the manga grouped by categories. - * - * @return an observable containing a map with the category id as key and a list of manga as the - * value. - */ - private fun getLibraryMangasObservable(): Observable { - val libraryAsList = preferences.libraryAsList() - return db.getLibraryMangas().asRxObservable() - .map { list -> - if (!preferences.hideCategories().getOrDefault()) { - list.map { LibraryItem(it, libraryAsList) }.groupBy { it.manga.category } - } - else { - list.distinctBy { it.id }.map { LibraryItem(it, libraryAsList)}.groupBy { - 0 } - } - } - } -*/ /** * Requests the library to be filtered. */ @@ -493,7 +419,7 @@ class LibraryPresenter( mangaMap = withContext(Dispatchers.IO) { applyFilters(mangaMap) } mangaMap = withContext(Dispatchers.IO) { applySort(mangaMap) } currentMangaMap = mangaMap - view?.onNextLibraryUpdate(categories, mangaMap) + view.onNextLibraryUpdate(categories, mangaMap) } } @@ -501,7 +427,6 @@ class LibraryPresenter( * Requests the library to have download badges added/removed. */ fun requestDownloadBadgesUpdate() { - //getLibrary() launchUI { val mangaMap = rawMangaMap ?: return@launchUI withContext(Dispatchers.IO) { setDownloadCount(mangaMap) } @@ -509,7 +434,7 @@ class LibraryPresenter( val current = currentMangaMap ?: return@launchUI withContext(Dispatchers.IO) { setDownloadCount(current) } currentMangaMap = current - view?.onNextLibraryUpdate(categories, current) + view.onNextLibraryUpdate(categories, current) } } @@ -525,7 +450,7 @@ class LibraryPresenter( val current = currentMangaMap ?: return@launchUI withContext(Dispatchers.IO) { setUnreadBadge(current) } currentMangaMap = current - view?.onNextLibraryUpdate(categories, current) + view.onNextLibraryUpdate(categories, current) } } @@ -537,7 +462,7 @@ class LibraryPresenter( var mangaMap = currentMangaMap ?: return@launchUI mangaMap = withContext(Dispatchers.IO) { applySort(mangaMap) } currentMangaMap = mangaMap - view?.onNextLibraryUpdate(categories, mangaMap) + view.onNextLibraryUpdate(categories, mangaMap) } } @@ -546,23 +471,14 @@ class LibraryPresenter( var mangaMap = currentMangaMap ?: return@launchUI mangaMap = withContext(Dispatchers.IO) { applyCatSort(mangaMap, catId) } currentMangaMap = mangaMap - view?.onNextLibraryUpdate(categories, mangaMap) + view.onNextLibraryUpdate(categories, mangaMap) } } fun requestFullUpdate() { - //librarySubscription?.unsubscribe() getLibrary() } - /** - * Called when a manga is opened. - */ - fun onOpenManga() { - // Avoid further db updates for the library when it's not needed - //librarySubscription?.let { remove(it) } - } - /** * Returns the common categories for the given list of manga. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortBottomSheet.kt deleted file mode 100644 index 2bd78e22cd..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortBottomSheet.kt +++ /dev/null @@ -1,168 +0,0 @@ -package eu.kanade.tachiyomi.ui.library.filter - -import android.app.Activity -import android.content.res.Configuration -import android.graphics.Color -import android.graphics.drawable.GradientDrawable -import android.os.Build -import android.os.Bundle -import android.view.View -import android.view.ViewGroup -import android.view.WindowManager -import android.widget.CompoundButton -import android.widget.LinearLayout -import android.widget.RadioButton -import android.widget.RadioGroup -import android.widget.Toast -import androidx.constraintlayout.widget.ConstraintLayout -import androidx.core.graphics.ColorUtils -import com.bluelinelabs.conductor.Controller -import com.f2prateek.rx.preferences.Preference -import com.google.android.material.bottomsheet.BottomSheetDialog -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault -import eu.kanade.tachiyomi.ui.migration.MigrationFlags -import eu.kanade.tachiyomi.util.view.gone -import eu.kanade.tachiyomi.util.system.toast -import eu.kanade.tachiyomi.util.view.marginBottom -import eu.kanade.tachiyomi.util.view.updateLayoutParams -import eu.kanade.tachiyomi.util.view.visible -import kotlinx.android.synthetic.main.migration_bottom_sheet.* -import kotlinx.android.synthetic.main.migration_bottom_sheet.extra_search_param -import kotlinx.android.synthetic.main.migration_bottom_sheet.extra_search_param_text -import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_categories -import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_chapters -import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_tracking -import uy.kohesive.injekt.injectLazy - -class SortBottomSheet(private val activity: Activity, theme: Int, private val listener: -SortBottomSheetListener) : - BottomSheetDialog(activity, - theme) { - /** - * Preferences helper. - */ - private val preferences by injectLazy() - - init { - // Use activity theme for this layout - val view = activity.layoutInflater.inflate(R.layout.migration_bottom_sheet, null) - //val scroll = NestedScrollView(context) - // scroll.addView(view) - - setContentView(view) - if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) - sourceGroup.orientation = LinearLayout.HORIZONTAL - window?.setBackgroundDrawable(null) - val currentNightMode = activity.resources.configuration.uiMode and Configuration - .UI_MODE_NIGHT_MASK - if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - val nView = View(context) - val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom - val params = ConstraintLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, height - ) - params.bottomToBottom = constraintLayout.id - params.startToStart = constraintLayout.id - params.endToEnd = constraintLayout.id - nView.layoutParams = params - nView.background = GradientDrawable( - GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf( - ColorUtils.setAlphaComponent(Color.BLACK, 179), Color.TRANSPARENT - ) - ) - constraintLayout.addView(nView) - } - } - - /** - * Called when the sheet is created. It initializes the listeners and values of the preferences. - */ - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - initPreferences() - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) - val marginB = skip_step.marginBottom - skip_step.updateLayoutParams { - bottomMargin = marginB + - activity.window.decorView.rootWindowInsets.systemWindowInsetBottom - } - } - - } - - /** - * Init general reader preferences. - */ - private fun initPreferences() { - val flags = preferences.migrateFlags().getOrDefault() - - mig_chapters.isChecked = MigrationFlags.hasChapters(flags) - mig_categories.isChecked = MigrationFlags.hasCategories(flags) - mig_tracking.isChecked = MigrationFlags.hasTracks(flags) - - mig_chapters.setOnCheckedChangeListener { _, _ -> setFlags() } - mig_categories.setOnCheckedChangeListener { _, _ -> setFlags() } - mig_tracking.setOnCheckedChangeListener { _, _ -> setFlags() } - - extra_search_param_text.gone() - extra_search_param.setOnCheckedChangeListener { _, isChecked -> - if (isChecked) { - extra_search_param_text.visible() - } else { - extra_search_param_text.gone() - } - } - sourceGroup.bindToPreference(preferences.useSourceWithMost()) - - skip_step.isChecked = preferences.skipPreMigration().getOrDefault() - skip_step.setOnCheckedChangeListener { _, isChecked -> - if (isChecked) - (listener as? Controller)?.activity?.toast(R.string.pre_migration_skip_toast, - Toast.LENGTH_LONG) - } - } - - private fun setFlags() { - var flags = 0 - if(mig_chapters.isChecked) flags = flags or MigrationFlags.CHAPTERS - if(mig_categories.isChecked) flags = flags or MigrationFlags.CATEGORIES - if(mig_tracking.isChecked) flags = flags or MigrationFlags.TRACK - preferences.migrateFlags().set(flags) - } - - /** - * Binds a checkbox or switch view with a boolean preference. - */ - private fun CompoundButton.bindToPreference(pref: Preference) { - isChecked = pref.getOrDefault() - setOnCheckedChangeListener { _, isChecked -> pref.set(isChecked) } - } - - /** - * Binds a radio group with a boolean preference. - */ - private fun RadioGroup.bindToPreference(pref: Preference) { - (getChildAt(pref.getOrDefault().toInt()) as RadioButton).isChecked = true - setOnCheckedChangeListener { _, value -> - val index = indexOfChild(findViewById(value)) - pref.set(index == 1) - } - } - - private fun Boolean.toInt() = if (this) 1 else 0 - - - -} - -interface SortBottomSheetListener { - fun onApplySort() -} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt similarity index 90% rename from app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt index 94b4bcb863..ccfbe3833b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt @@ -44,7 +44,7 @@ import uy.kohesive.injekt.injectLazy import kotlin.math.min import kotlin.math.roundToInt -class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) +class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs), FilterTagGroupListener { @@ -88,8 +88,8 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri fun onCreate(pagerView:View) { if (isLandscape() || isTablet()) { - sideLayout.orientation = HORIZONTAL - sortingLayout.updateLayoutParams { + side_layout.orientation = HORIZONTAL + sorting_layout.updateLayoutParams { bottomMargin = 0 topMargin = 0 } @@ -98,10 +98,10 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri top = 0 ) } - clearButton = pendingClearButton - filterLayout.removeView(clearButton) + clearButton = clear_button + filter_layout.removeView(clearButton) sheetBehavior = BottomSheetBehavior.from(this) - topbar.setOnClickListener { + top_bar.setOnClickListener { if (sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED) { sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED //topbar.animate().alpha(0f).setDuration(100).start() @@ -117,7 +117,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri val coordLayout:View = (pagerView.parent as ViewGroup).findViewById(R.id.snackbar_layout) sheetBehavior?.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { override fun onSlide(bottomSheet: View, progress: Float) { - topbar.alpha = 1 - progress + top_bar.alpha = 1 - progress shadow2.alpha = (1 - progress) * 0.25f updateRootPadding(progress) } @@ -126,12 +126,12 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri if (state == BottomSheetBehavior.STATE_COLLAPSED) reSortViews() else setMainSortText() if (state == BottomSheetBehavior.STATE_EXPANDED) - topbar.alpha = 0f - topbar.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED - topbar.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED + top_bar.alpha = 0f + top_bar.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED + top_bar.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED } }) - topbar.viewTreeObserver.addOnGlobalLayoutListener { + top_bar.viewTreeObserver.addOnGlobalLayoutListener { val phoneLandscape = (isLandscape() && !isTablet()) sheetBehavior?.peekHeight = if (phoneLandscape) { if (shadow2.visibility != View.GONE) { @@ -140,15 +140,15 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } 0 } - else if (!sortText.text.isNullOrBlank()) { - topbar.height + else if (!title.text.isNullOrBlank()) { + top_bar.height } else 0 if (sheetBehavior?.state == BottomSheetBehavior.STATE_COLLAPSED) { val height = context.resources.getDimensionPixelSize(R.dimen.rounder_radius) pager?.setPadding(0, 0, 0, if (phoneLandscape) 0 else - (topbar.height - height)) - coordLayout.setPadding(0, 0, 0, topbar.height) + (top_bar.height - height)) + coordLayout.setPadding(0, 0, 0, top_bar.height) } else { updateRootPadding() @@ -156,11 +156,11 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } createTags() - mainSortTextView.setOnClickListener { showMainSortOptions() } - catSortTextView.setOnClickListener { showCatSortOptions() } + library_sort_text.setOnClickListener { showMainSortOptions() } + category_sort_text.setOnClickListener { showCatSortOptions() } clearButton.setOnClickListener { clearFilters() } - downloadCheckbox.isChecked = preferences.downloadBadge().getOrDefault() - downloadCheckbox.setOnCheckedChangeListener { _, isChecked -> + download_checkbox.isChecked = preferences.downloadBadge().getOrDefault() + download_checkbox.setOnCheckedChangeListener { _, isChecked -> preferences.downloadBadge().set(isChecked) onGroupClicked(ACTION_DOWNLOAD_BADGE) } @@ -169,7 +169,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri showUnreadMenu() } - displayGroup.bindToPreference(preferences.libraryAsList()) + display_group.bindToPreference(preferences.libraryAsList()) } private fun isLandscape(): Boolean { @@ -212,17 +212,17 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri filters.joinToString(", ") { context.getString(it) } } } - sortText.text = text + title.text = text setMainSortText() } } fun adjustTitleMargin(downloading: Boolean) { - val params = sortText.layoutParams as? MarginLayoutParams ?: return + val params = title.layoutParams as? MarginLayoutParams ?: return params.rightMargin = (if (downloading) 80 else 8).dpToPx - sortText.layoutParams = params + title.layoutParams = params - filterScrollView.updatePaddingRelative(end = (if (downloading) 80 else 20).dpToPx) + filter_scroll.updatePaddingRelative(end = (if (downloading) 80 else 20).dpToPx) } fun updateRootPadding(progress: Float? = null) { @@ -309,7 +309,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri tracked.setup(this, R.string.action_filter_tracked, R.string.action_filter_not_tracked) filterItems.forEach { - filterLayout.addView(it) + filter_layout.addView(it) } checkForManwha() @@ -323,12 +323,12 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri launchUI { val mangaType = inflate(R.layout.filter_buttons) as FilterTagGroup mangaType.setup( - this@FilterBottomSheet, + this@SortFilterBottomSheet, R.string.manga, R.string.manwha ) - this@FilterBottomSheet.mangaType = mangaType - filterLayout.addView(mangaType) + this@SortFilterBottomSheet.mangaType = mangaType + filter_layout.addView(mangaType) filterItems.add(mangaType) } } @@ -347,7 +347,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri private fun showMainSortOptions() { // Create a PopupMenu, giving it the clicked view for an anchor - val popup = PopupMenu(context, mainSortTextView) + val popup = PopupMenu(context, library_sort_text) // Inflate our menu resource into the PopupMenu's Menu popup.menuInflater.inflate(R.menu.main_sort, popup.menu) @@ -390,7 +390,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri private fun showCatSortOptions() { val category = lastCategory ?: return // Create a PopupMenu, giving it the clicked view for an anchor - val popup = PopupMenu(context, catSortTextView) + val popup = PopupMenu(context, category_sort_text) // Inflate our menu resource into the PopupMenu's Menu popup.menuInflater.inflate(R.menu.cat_sort, popup.menu) @@ -504,7 +504,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } ) } - mainSortTextView.text = withContext(Dispatchers.IO) { + library_sort_text.text = withContext(Dispatchers.IO) { context.getString( if (sortId == LibrarySort.DRAG_AND_DROP) R.string.sort_library_by_ else R.string.sort_by_, context.getString( @@ -519,7 +519,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri ) ) } - mainSortTextView.setCompoundDrawablesRelativeWithIntrinsicBounds( + library_sort_text.setCompoundDrawablesRelativeWithIntrinsicBounds( drawableL, null, null, null ) setCatSortText() @@ -540,7 +540,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } ) } - catSortTextView.text = withContext(Dispatchers.IO) { + category_sort_text.text = withContext(Dispatchers.IO) { context.getString( R.string.sort_category_by_, context.getString( when (sortId) { @@ -554,11 +554,11 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri ) ) } - catSortTextView.setCompoundDrawablesRelativeWithIntrinsicBounds( + category_sort_text.setCompoundDrawablesRelativeWithIntrinsicBounds( drawableL, null, null, null ) - if (catSortTextView.visibility != View.VISIBLE) catSortTextView.visible() - } else if (catSortTextView.visibility == View.VISIBLE) catSortTextView.gone() + if (category_sort_text.visibility != View.VISIBLE) category_sort_text.visible() + } else if (category_sort_text.visibility == View.VISIBLE) category_sort_text.gone() } } @@ -603,9 +603,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } val filters = getFilters().size if (filters > 0 && clearButton.parent == null) - filterLayout.addView(clearButton, 0) + filter_layout.addView(clearButton, 0) else if (filters == 0 && clearButton.parent != null) - filterLayout.removeView(clearButton) + filter_layout.removeView(clearButton) } private fun clearFilters() { @@ -621,7 +621,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri val transition = androidx.transition.AutoTransition() transition.duration = 150 - androidx.transition.TransitionManager.beginDelayedTransition(filterLayout, transition) + androidx.transition.TransitionManager.beginDelayedTransition(filter_layout, transition) filterItems.forEach { it.reset() } @@ -630,16 +630,16 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } fun reSortViews() { - filterLayout.removeAllViews() + filter_layout.removeAllViews() if (filterItems.any { it.isActivated }) - filterLayout.addView(clearButton) + filter_layout.addView(clearButton) filterItems.filter { it.isActivated }.forEach { - filterLayout.addView(it) + filter_layout.addView(it) } filterItems.filterNot { it.isActivated }.forEach { - filterLayout.addView(it) + filter_layout.addView(it) } - filterScrollView.scrollTo(0, 0) + filter_scroll.scrollTo(0, 0) } private fun showUnreadMenu() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 507d9c569f..6f19fb6b21 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -111,13 +111,15 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { lateinit var tabAnimator: TabsAnimator override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) + // Create a webview before extensions do or else they will break night mode theme + // https://stackoverflow.com/questions/54191883 Timber.d("Manually instantiating WebView to avoid night mode issue.") try { WebView(applicationContext) } catch (e: Exception) { Timber.e(e, "Exception when creating webview at start") } + super.onCreate(savedInstanceState) if (trulyGoBack) return // Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079 @@ -480,7 +482,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { } else if (!bottomNav && backstackSize == 1 && router.getControllerWithTag ("$startScreenId") == null) { setSelectedDrawerItem(startScreenId) - } else if (!router.handleBack()) { + } else if (!router.handleBack()) { unlocked = false super.onBackPressed() } @@ -488,7 +490,10 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { private fun setSelectedDrawerItem(itemId: Int) { if (!isFinishing) { - if (bottomNav) navigationView.selectedItemId = itemId + if (bottomNav) { + if (itemId == R.id.nav_drawer_library || itemId == R.id.nav_drawer_settings) + navigationView.selectedItemId = itemId + } else nav_view.setCheckedItem(itemId) jumpToController(itemId) } @@ -499,21 +504,17 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { val currentRoot = router.backstack.firstOrNull() if (currentRoot?.tag()?.toIntOrNull() != id) { when (id) { - R.id.nav_drawer_library -> setRoot(LibraryController(), id) + R.id.nav_drawer_library -> if (!bottomNav) setRoot(LibraryController(), id) R.id.nav_drawer_recent_updates -> { - if (bottomNav) - navigationView.selectedItemId = R.id.nav_drawer_recents - setRoot(RecentChaptersController(), if (bottomNav) R.id.nav_drawer_recents - else id) preferences.showRecentUpdates().set(true) + if (bottomNav) navigationView.selectedItemId = R.id.nav_drawer_recents + else setRoot(RecentChaptersController(), id) updateRecentsIcon() } R.id.nav_drawer_recently_read -> { - if (bottomNav) - navigationView.selectedItemId = R.id.nav_drawer_recents - setRoot(RecentlyReadController(), if (bottomNav) R.id.nav_drawer_recents - else id) preferences.showRecentUpdates().set(false) + if (bottomNav) navigationView.selectedItemId = R.id.nav_drawer_recents + else setRoot(RecentlyReadController(), id) updateRecentsIcon() } R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id) @@ -549,7 +550,8 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { } R.id.nav_drawer_settings -> { - setRoot(SettingsMainController(), id) + if (!bottomNav) + setRoot(SettingsMainController(), id) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index cdfd8e0bcb..1f8febd120 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -131,7 +131,7 @@ class RecentlyReadController(bundle: Bundle? = null) : BaseController(bundle), if (size > 0) { empty_view?.hide() } else { - empty_view.show(R.drawable.ic_glasses_black_128dp, R.string.information_no_recent_manga) + empty_view.show(R.drawable.ic_history_white_128dp, R.string.information_no_recent_manga) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index a50f0b2605..4454295a8c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.setting +import androidx.appcompat.app.AppCompatDelegate import androidx.biometric.BiometricManager import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.BuildConfig diff --git a/app/src/main/res/drawable/ic_history_white_128dp.xml b/app/src/main/res/drawable/ic_history_white_128dp.xml new file mode 100644 index 0000000000..46514a1a00 --- /dev/null +++ b/app/src/main/res/drawable/ic_history_white_128dp.xml @@ -0,0 +1,6 @@ + + + diff --git a/app/src/main/res/layout-land/filter_bottom_sheet.xml b/app/src/main/res/layout-land/filter_bottom_sheet.xml index 30e8c0bcd2..7a670bdccb 100644 --- a/app/src/main/res/layout-land/filter_bottom_sheet.xml +++ b/app/src/main/res/layout-land/filter_bottom_sheet.xml @@ -1,5 +1,5 @@ - @@ -175,7 +175,7 @@ > + app:layout_constraintTop_toTopOf="@+id/title" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml b/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml index 30e8c0bcd2..7a670bdccb 100644 --- a/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml +++ b/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml @@ -1,5 +1,5 @@ - @@ -175,7 +175,7 @@ > + app:layout_constraintTop_toTopOf="@+id/title" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/filter_bottom_sheet.xml b/app/src/main/res/layout/filter_bottom_sheet.xml index d9f5008fd6..0a002974cd 100644 --- a/app/src/main/res/layout/filter_bottom_sheet.xml +++ b/app/src/main/res/layout/filter_bottom_sheet.xml @@ -1,5 +1,5 @@ - @@ -171,7 +171,7 @@ > + app:layout_constraintTop_toTopOf="@+id/title" /> - \ No newline at end of file + \ No newline at end of file From c48252b61c482ed8cc647954d4d0c1c9e84c3bac Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 8 Feb 2020 19:19:40 -0800 Subject: [PATCH 033/259] More fixes to D&D sorting with new presenter --- .../kanade/tachiyomi/ui/library/LibraryCategoryView.kt | 10 ++++------ .../kanade/tachiyomi/ui/library/LibraryGridHolder.kt | 6 +++--- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 6 +++++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 9abba0c86f..f543fe1e0e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -81,8 +81,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att private var lastClickPosition = -1 - private var justDraggedAndDropped = false - fun onCreate(controller: LibraryController) { this.controller = controller @@ -239,10 +237,10 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att val mangaForCategory = event.getMangaForCategory(category).orEmpty() // Update the category with its manga. - if (!justDraggedAndDropped) + // if (!justDraggedAndDropped) adapter.setItems(mangaForCategory) - else - justDraggedAndDropped = false + // else + // justDraggedAndDropped = false swipe_refresh.isEnabled = !preferences.hideCategories().getOrDefault() @@ -366,7 +364,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att preferences.defaultMangaOrder().set(mangaIds.joinToString("/")) else db.insertCategory(category).asRxObservable().subscribe() - justDraggedAndDropped = true + //justDraggedAndDropped = true controller.onCatSortChanged(category.id) controller.enableReorderItems(category) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 36ba87f93c..8132eefc93 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -60,9 +60,9 @@ class LibraryGridHolder( local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE // Update the cover. - GlideApp.with(view.context).clear(thumbnail) - GlideApp.with(view.context) - .load(item.manga) + if (item.manga.thumbnail_url == null) + GlideApp.with(view.context).clear(thumbnail) + else GlideApp.with(view.context).load(item.manga) .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) .signature(ObjectKey(MangaImpl.getLastCoverFetch(item.manga.id!!).toString())) .centerCrop().into(thumbnail) 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 63c68d754e..44e5cbdb6a 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 @@ -211,7 +211,11 @@ class LibraryPresenter( private fun applySort(map: LibraryMap, catId: Int?): LibraryMap { if (catId == null) return map - val category = allCategories.find { it.id == catId } ?: return map + val category = db.getCategories().executeAsBlocking().find { it.id == catId } ?: return map + allCategories.find { it.id == catId }?.apply { + mangaOrder = category.mangaOrder + mangaSort = category.mangaSort + } val lastReadManga by lazy { var counter = 0 From 1bb2edc4bba4c1cc2b039cd709e8c73524d3888e Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 8 Feb 2020 20:57:02 -0800 Subject: [PATCH 034/259] Removed unread badge from catelouge items + warning for nav drawer Side nav is painful to maintain so sooner or later it's going bye bye --- .../ui/catalogue/browse/CatalogueItem.kt | 7 ++--- .../ui/setting/SettingsGeneralController.kt | 28 +++++++++++++++---- .../main/res/layout/catalogue_grid_item.xml | 4 ++- .../main/res/layout/catalogue_list_item.xml | 2 ++ .../main/res/layout/filter_bottom_sheet.xml | 6 ++-- app/src/main/res/layout/filter_buttons.xml | 7 +++-- app/src/main/res/values/strings.xml | 5 ++++ 7 files changed, 43 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt index a31b5fbf86..781ca75c82 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt @@ -30,11 +30,8 @@ class CatalogueItem(val manga: Manga, private val catalogueAsList: Preference + bottomNav as Boolean + if (!bottomNav) { + MaterialDialog(activity!!).title(R.string.switch_to_sidebar) + .message(R.string.switch_to_sidebar_summary) + .positiveButton(R.string.action_switch) { + preferences.useBottonNav().set(bottomNav) + switchNavType(bottomNav) + }.negativeButton(android.R.string.no).show() + false } - true + else { + switchNavType(bottomNav) + true + } + } } @@ -148,4 +159,11 @@ class SettingsGeneralController : SettingsController() { } } } + + fun switchNavType(bottomNav: Boolean) { + activity?.recreate() + if (bottomNav) { + (activity as MainActivity).navigationView.selectedItemId = R.id.nav_drawer_settings + } + } } diff --git a/app/src/main/res/layout/catalogue_grid_item.xml b/app/src/main/res/layout/catalogue_grid_item.xml index 818ad16e42..e59629051f 100644 --- a/app/src/main/res/layout/catalogue_grid_item.xml +++ b/app/src/main/res/layout/catalogue_grid_item.xml @@ -45,8 +45,8 @@ android:paddingStart="3dp" android:paddingEnd="3dp" android:paddingTop="1dp" - android:visibility="gone" android:textColor="@color/md_white_1000" + android:visibility="gone" tools:visibility="visible" tools:text="120" app:layout_constraintStart_toEndOf="@+id/download_text" @@ -124,6 +124,8 @@ android:id="@+id/unread_badge" android:layout_width="20dp" android:layout_height="20dp" + android:visibility="gone" + tools:visibility="visible" android:layout_gravity="end" android:src="@drawable/unread_circle_badge"/> diff --git a/app/src/main/res/layout/catalogue_list_item.xml b/app/src/main/res/layout/catalogue_list_item.xml index 4a8c1374b9..8cf6ecf2a9 100644 --- a/app/src/main/res/layout/catalogue_list_item.xml +++ b/app/src/main/res/layout/catalogue_list_item.xml @@ -120,6 +120,8 @@ android:id="@+id/unread_badge" android:layout_width="10dp" android:layout_height="10dp" + android:visibility="gone" + tools:visibility="visible" android:layout_gravity="end" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout/filter_bottom_sheet.xml b/app/src/main/res/layout/filter_bottom_sheet.xml index 0a002974cd..884064ae5d 100644 --- a/app/src/main/res/layout/filter_bottom_sheet.xml +++ b/app/src/main/res/layout/filter_bottom_sheet.xml @@ -1,6 +1,7 @@ @@ -39,7 +40,7 @@ android:clickable="true" android:focusable="true" android:textStyle="normal" - android:text="112" + tools:text="Item 2" android:paddingStart="20dp" android:paddingEnd="20dp"/> @@ -61,7 +62,7 @@ android:clickable="true" android:focusable="true" android:textStyle="normal" - android:text="112" + tools:text="Item 3" android:paddingStart="20dp" android:paddingEnd="20dp"/> \ 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 519ef79208..7e0bade948 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -168,6 +168,11 @@ Check for updates Automatically check for new app versions Use bottom navigation + Switch to navigation drawer? + Navigation drawer is no longer supported by this + version of Tachiyomi and will later be removed. Non-critical bugs and features + relating to it will be ignored. + Switch Display From dc103acea2f056f2dfc5e3e6e986a01caa433320 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 8 Feb 2020 21:01:13 -0800 Subject: [PATCH 035/259] Moved bottom navigation setting to bottom of the general list In case you can't tell this is going to go away someday --- .../ui/setting/SettingsGeneralController.kt | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index cf376ebd81..b03e7f9fda 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -61,29 +61,6 @@ class SettingsGeneralController : SettingsController() { } } - switchPreference { - key = Keys.useBottomNav - titleRes = R.string.use_bottom_nav - defaultValue = true - onChange { bottomNav -> - bottomNav as Boolean - if (!bottomNav) { - MaterialDialog(activity!!).title(R.string.switch_to_sidebar) - .message(R.string.switch_to_sidebar_summary) - .positiveButton(R.string.action_switch) { - preferences.useBottonNav().set(bottomNav) - switchNavType(bottomNav) - }.negativeButton(android.R.string.no).show() - false - } - else { - switchNavType(bottomNav) - true - } - - } - } - listPreference(activity) { key= Keys.dateFormat titleRes = R.string.pref_date_format @@ -158,6 +135,29 @@ class SettingsGeneralController : SettingsController() { defaultValue = 0 } } + + switchPreference { + key = Keys.useBottomNav + titleRes = R.string.use_bottom_nav + defaultValue = true + onChange { bottomNav -> + bottomNav as Boolean + if (!bottomNav) { + MaterialDialog(activity!!).title(R.string.switch_to_sidebar) + .message(R.string.switch_to_sidebar_summary) + .positiveButton(R.string.action_switch) { + preferences.useBottonNav().set(bottomNav) + switchNavType(bottomNav) + }.negativeButton(android.R.string.no).show() + false + } + else { + switchNavType(bottomNav) + true + } + + } + } } fun switchNavType(bottomNav: Boolean) { From 08dcd06d27b27f672f94cfe346fbdbb89d695638 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 8 Feb 2020 21:49:44 -0800 Subject: [PATCH 036/259] More design fixes Enabled filters now have white text Using A10's back gesture to close the snackbar works properly now --- .../ui/library/LibraryCategoryView.kt | 1 - .../tachiyomi/ui/library/LibraryController.kt | 8 ++--- .../ui/library/filter/FilterTagGroup.kt | 11 ++++++- .../library/filter/SortFilterBottomSheet.kt | 32 +++++++++++-------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index f543fe1e0e..35f907aacc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -101,7 +101,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att swipe_refresh.addView(recycler) adapter.fastScroller = fast_scroller - if (!MainActivity.bottomNav) { fast_scroller.addOnScrollStateChangeListener { controller.lockFilterBar(it) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 63cff94a1d..3850d53828 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -547,7 +547,7 @@ class LibraryController( override fun handleBack(): Boolean { val sheetBehavior = BottomSheetBehavior.from(bottom_sheet) - if (sheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) { + if (sheetBehavior.state != BottomSheetBehavior.STATE_COLLAPSED) { sheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED return true } @@ -570,12 +570,12 @@ class LibraryController( R.id.action_search -> expandActionViewFromInteraction = true R.id.action_library_filter -> { if (MainActivity.bottomNav) { - if (bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED) + if (bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_COLLAPSED) bottom_sheet.sheetBehavior?.state = - BottomSheetBehavior.STATE_EXPANDED + BottomSheetBehavior.STATE_COLLAPSED else bottom_sheet.sheetBehavior?.state = - BottomSheetBehavior.STATE_COLLAPSED + BottomSheetBehavior.STATE_EXPANDED } else navView?.let { activity?.drawer?.openDrawer(GravityCompat.END) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt index 711c83a934..49393c5656 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterTagGroup.kt @@ -1,12 +1,14 @@ package eu.kanade.tachiyomi.ui.library.filter import android.content.Context +import android.graphics.Color import android.util.AttributeSet import android.view.ViewGroup import android.widget.LinearLayout import com.f2prateek.rx.preferences.Preference import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.system.dpToPx +import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.visible import kotlinx.android.synthetic.main.filter_buttons.view.* @@ -81,7 +83,10 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute buttons.forEach { it.isActivated = false } - for (i in 0 until itemCount) buttons[i].visible() + for (i in 0 until itemCount) { + buttons[i].visible() + buttons[i].setTextColor(context.getResourceColor(android.R.attr.textColorPrimary)) + } for (i in 0 until (itemCount - 1)) separators[i].visible() } @@ -96,6 +101,8 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute } if (itemCount == 1) { firstButton.isActivated = !firstButton.isActivated + firstButton.setTextColor(if (firstButton.isActivated) Color.WHITE else context + .getResourceColor(android.R.attr.textColorPrimary)) listener?.onFilterClicked(this, if (firstButton.isActivated) index else -1, callBack) return } @@ -122,6 +129,8 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute separator2.gone() } } + mainButton.setTextColor(if (mainButton.isActivated) Color.WHITE else context + .getResourceColor(android.R.attr.textColorPrimary)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt index ccfbe3833b..ad0f52fbdd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt @@ -115,34 +115,40 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A val shadow2:View = (pagerView.parent as ViewGroup).findViewById(R.id.shadow2) val shadow:View = (pagerView.parent as ViewGroup).findViewById(R.id.shadow) val coordLayout:View = (pagerView.parent as ViewGroup).findViewById(R.id.snackbar_layout) + val phoneLandscape = (isLandscape() && !isTablet()) + if (phoneLandscape) + shadow.alpha = 0f sheetBehavior?.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { override fun onSlide(bottomSheet: View, progress: Float) { top_bar.alpha = 1 - progress shadow2.alpha = (1 - progress) * 0.25f + if (phoneLandscape) + shadow.alpha = progress updateRootPadding(progress) } override fun onStateChanged(p0: View, state: Int) { - if (state == BottomSheetBehavior.STATE_COLLAPSED) reSortViews() + if (state == BottomSheetBehavior.STATE_COLLAPSED) { + reSortViews() + if (phoneLandscape) + shadow.alpha = 0f + } else setMainSortText() - if (state == BottomSheetBehavior.STATE_EXPANDED) + if (state == BottomSheetBehavior.STATE_EXPANDED) { top_bar.alpha = 0f + if (phoneLandscape) + shadow.alpha = 1f + } top_bar.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED top_bar.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED } }) + if (phoneLandscape && shadow2.visibility != View.GONE) { + shadow2.gone() + } top_bar.viewTreeObserver.addOnGlobalLayoutListener { - val phoneLandscape = (isLandscape() && !isTablet()) - sheetBehavior?.peekHeight = if (phoneLandscape) { - if (shadow2.visibility != View.GONE) { - shadow.gone() - shadow2.gone() - } - 0 - } - else if (!title.text.isNullOrBlank()) { - top_bar.height - } + sheetBehavior?.peekHeight = if (phoneLandscape) 0 + else if (!title.text.isNullOrBlank()) top_bar.height else 0 if (sheetBehavior?.state == BottomSheetBehavior.STATE_COLLAPSED) { val height = context.resources.getDimensionPixelSize(R.dimen.rounder_radius) From d4e839f555dccb515da0668f15fc0a7b465174da Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 9 Feb 2020 02:35:00 -0800 Subject: [PATCH 037/259] Edge to edge bottom sheets for reader Added collaspe button to reader sheet Made other reader themes material --- .../design/MigrationBottomSheetDialog.kt | 79 ++++++++----------- .../manga/design/PreMigrationController.kt | 3 +- .../ui/reader/ReaderColorFilterSheet.kt | 23 +++++- .../tachiyomi/ui/reader/ReaderPageSheet.kt | 19 ++++- .../ui/reader/ReaderSettingsSheet.kt | 59 +++++++++++++- .../tachiyomi/util/view/ViewExtensions.kt | 63 ++++++++++++++- app/src/main/res/drawable/round_ripple.xml | 9 +++ .../layout-land/reader_color_filter_sheet.xml | 18 ++--- .../res/layout/migration_bottom_sheet.xml | 21 +++-- .../main/res/layout/reader_color_filter.xml | 4 +- .../res/layout/reader_color_filter_sheet.xml | 9 ++- app/src/main/res/layout/reader_page_sheet.xml | 3 +- .../main/res/layout/reader_settings_sheet.xml | 44 +++++++---- app/src/main/res/values/themes.xml | 4 +- 14 files changed, 262 insertions(+), 96 deletions(-) create mode 100644 app/src/main/res/drawable/round_ripple.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt index d0bd508a14..d6ad69e583 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt @@ -2,13 +2,8 @@ package eu.kanade.tachiyomi.ui.migration.manga.design import android.app.Activity import android.content.res.Configuration -import android.graphics.Color -import android.graphics.drawable.ColorDrawable -import android.graphics.drawable.GradientDrawable import android.os.Build import android.os.Bundle -import android.view.Gravity -import android.view.View import android.view.ViewGroup import android.view.WindowManager import android.widget.CompoundButton @@ -17,7 +12,6 @@ import android.widget.RadioButton import android.widget.RadioGroup import android.widget.Toast import androidx.constraintlayout.widget.ConstraintLayout -import androidx.core.graphics.ColorUtils import com.bluelinelabs.conductor.Controller import com.f2prateek.rx.preferences.Preference import com.google.android.material.bottomsheet.BottomSheetDialog @@ -25,24 +19,18 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.migration.MigrationFlags -import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.toast -import eu.kanade.tachiyomi.util.view.marginBottom -import eu.kanade.tachiyomi.util.view.updateLayoutParams +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.setBottomEdge +import eu.kanade.tachiyomi.util.view.setEdgeToEdge import eu.kanade.tachiyomi.util.view.visible import kotlinx.android.synthetic.main.migration_bottom_sheet.* -import kotlinx.android.synthetic.main.migration_bottom_sheet.extra_search_param -import kotlinx.android.synthetic.main.migration_bottom_sheet.extra_search_param_text -import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_categories -import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_chapters -import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_tracking -import kotlinx.android.synthetic.main.migration_bottom_sheet.view.* import uy.kohesive.injekt.injectLazy -class MigrationBottomSheetDialog(private val activity: Activity, theme: Int, private val listener: +class MigrationBottomSheetDialog(activity: Activity, private val listener: StartMigrationListener) : - BottomSheetDialog(activity, - theme) { + BottomSheetDialog(activity, R.style.BottomSheetDialogTheme) { /** * Preferences helper. */ @@ -55,31 +43,35 @@ StartMigrationListener) : // scroll.addView(view) setContentView(view) - if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) + if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) { sourceGroup.orientation = LinearLayout.HORIZONTAL - window?.setBackgroundDrawable(null) - val currentNightMode = activity.resources.configuration.uiMode and Configuration - .UI_MODE_NIGHT_MASK - if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - val nView = View(context) - val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom - val params = ConstraintLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, height - ) - params.bottomToBottom = constraintLayout.id - params.startToStart = constraintLayout.id - params.endToEnd = constraintLayout.id - nView.layoutParams = params - nView.background = GradientDrawable( - GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf( - ColorUtils.setAlphaComponent(Color.BLACK, 179), Color.TRANSPARENT - ) - ) - constraintLayout.addView(nView) + val params = skip_step.layoutParams as ConstraintLayout.LayoutParams + params.apply { + topToBottom = -1 + startToStart = -1 + bottomToBottom = extra_search_param.id + startToEnd = extra_search_param.id + endToEnd = sourceGroup.id + topToTop = extra_search_param.id + marginStart = 16.dpToPx + } + skip_step.layoutParams = params + + + val params2 = extra_search_param_text.layoutParams as ConstraintLayout.LayoutParams + params2.bottomToBottom = options_layout.id + extra_search_param_text.layoutParams = params2 + + + val params3 = extra_search_param.layoutParams as ConstraintLayout.LayoutParams + params3.endToEnd = -1 + extra_search_param.layoutParams = params3 + } + setEdgeToEdge(activity, constraint_layout, view, false) + setBottomEdge( + if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) extra_search_param_text + else skip_step, activity) } /** @@ -92,11 +84,6 @@ StartMigrationListener) : if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) - val marginB = skip_step.marginBottom - skip_step.updateLayoutParams { - bottomMargin = marginB + - activity.window.decorView.rootWindowInsets.systemWindowInsetBottom - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt index 8cbfc5b5fe..e909fe7c33 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt @@ -72,8 +72,7 @@ class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), F fab.setOnClickListener { if (dialog?.isShowing != true) { - dialog = MigrationBottomSheetDialog(activity!!, R.style.BottomSheetDialogTheme, - this) + dialog = MigrationBottomSheetDialog(activity!!, this) dialog?.show() val bottomSheet = dialog?.findViewById( com.google.android.material.R.id.design_bottom_sheet diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt index 57f88346dc..eaeb398cd6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.reader import android.graphics.Color +import android.os.Build import android.view.View import android.view.ViewGroup import android.widget.SeekBar @@ -11,11 +12,12 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.lang.plusAssign +import eu.kanade.tachiyomi.util.view.setBottomEdge +import eu.kanade.tachiyomi.util.view.setEdgeToEdge import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import kotlinx.android.synthetic.main.reader_color_filter.* -import kotlinx.android.synthetic.main.reader_color_filter_sheet.brightness_overlay -import kotlinx.android.synthetic.main.reader_color_filter_sheet.color_overlay +import kotlinx.android.synthetic.main.reader_color_filter_sheet.* import rx.Subscription import rx.android.schedulers.AndroidSchedulers import rx.subscriptions.CompositeSubscription @@ -26,7 +28,8 @@ import kotlin.math.abs /** * Color filter sheet to toggle custom filter and brightness overlay. */ -class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activity) { +class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog + (activity, R.style.BottomSheetDialogTheme) { private val preferences by injectLazy() @@ -51,6 +54,14 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ val view = activity.layoutInflater.inflate(R.layout.reader_color_filter_sheet, null) setContentView(view) + setEdgeToEdge(activity, constraint_layout, view, true) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && + preferences.readerTheme().getOrDefault() == 0 && + activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && + activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0) + window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + setBottomEdge(brightness_seekbar, activity) + sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup) // Initialize subscriptions. @@ -90,6 +101,12 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ preferences.customBrightness().set(isChecked) } + /*color_filter_mode.setOnClickListener { + val popupMenu = PopupMenu(context, color_filter_mode) + + popupMenu.menuInflater.inflate(R.menu.download_single, popupMenu.menu) + popupMenu.show() + }*/ color_filter_mode.onItemSelectedListener = IgnoreFirstSpinnerListener { position -> preferences.colorFilterMode().set(position) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt index da1acb6a0c..a74e825cf6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt @@ -1,13 +1,21 @@ package eu.kanade.tachiyomi.ui.reader +import android.os.Build import android.os.Bundle +import android.view.View import com.google.android.material.bottomsheet.BottomSheetDialog import android.view.ViewGroup import com.afollestad.materialdialogs.MaterialDialog import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.ui.reader.model.ReaderPage +import eu.kanade.tachiyomi.util.view.setBottomEdge +import eu.kanade.tachiyomi.util.view.setEdgeToEdge import kotlinx.android.synthetic.main.reader_page_sheet.* +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get /** * Sheet to show when a page is long clicked. @@ -15,7 +23,7 @@ import kotlinx.android.synthetic.main.reader_page_sheet.* class ReaderPageSheet( private val activity: ReaderActivity, private val page: ReaderPage -) : BottomSheetDialog(activity) { +) : BottomSheetDialog(activity, R.style.BottomSheetDialogTheme) { /** * View used on this sheet. @@ -24,6 +32,15 @@ class ReaderPageSheet( init { setContentView(view) + setEdgeToEdge(activity, view, view, false) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && + Injekt.get().readerTheme().getOrDefault() == 0 && + activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && + activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0) + window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + + setBottomEdge(save_layout, activity) + set_as_cover_layout.setOnClickListener { setAsCover() } share_layout.setOnClickListener { share() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt index 3b48be03a6..a1ff69ea07 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt @@ -1,16 +1,25 @@ package eu.kanade.tachiyomi.ui.reader +import android.content.res.Configuration +import android.os.Build import android.os.Bundle +import android.view.View +import android.view.ViewGroup import com.google.android.material.bottomsheet.BottomSheetDialog import androidx.core.widget.NestedScrollView import android.widget.CompoundButton import android.widget.Spinner import com.f2prateek.rx.preferences.Preference +import com.google.android.material.bottomsheet.BottomSheetBehavior import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer +import eu.kanade.tachiyomi.util.system.dpToPx +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.setBottomEdge +import eu.kanade.tachiyomi.util.view.setEdgeToEdge import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener import kotlinx.android.synthetic.main.reader_settings_sheet.* @@ -19,19 +28,48 @@ import uy.kohesive.injekt.injectLazy /** * Sheet to show reader and viewer preferences. */ -class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDialog(activity) { +class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDialog + (activity, R.style.BottomSheetDialogTheme) { /** * Preferences helper. */ private val preferences by injectLazy() + private var sheetBehavior: BottomSheetBehavior<*> + + val scroll:NestedScrollView + init { // Use activity theme for this layout val view = activity.layoutInflater.inflate(R.layout.reader_settings_sheet, null) - val scroll = NestedScrollView(activity) + scroll = NestedScrollView(activity) scroll.addView(view) setContentView(scroll) + + sheetBehavior = BottomSheetBehavior.from(scroll.parent as ViewGroup) + setEdgeToEdge(activity, constraint_layout, scroll, + context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && + preferences.readerTheme().getOrDefault() == 0 && + activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && + activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0) + window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + val height = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + activity.window.decorView.rootWindowInsets.systemWindowInsetBottom + } else 0 + sheetBehavior.peekHeight = 200.dpToPx + height + + sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { + override fun onSlide(bottomSheet: View, progress: Float) { } + + override fun onStateChanged(p0: View, state: Int) { + if (state == BottomSheetBehavior.STATE_EXPANDED) { + sheetBehavior.skipCollapsed = true + } + } + }) + } /** @@ -46,6 +84,21 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia is PagerViewer -> initPagerPreferences() is WebtoonViewer -> initWebtoonPreferences() } + + setBottomEdge( + if (activity.viewer is PagerViewer) page_transitions else crop_borders_webtoon, activity + ) + + close_button.setOnClickListener { + dismiss() + } + + } + + override fun onStart() { + super.onStart() + sheetBehavior.skipCollapsed = true + sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED } /** @@ -70,6 +123,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia */ private fun initPagerPreferences() { pager_prefs_group.visible() + webtoon_prefs_group.gone() scale_type.bindToPreference(preferences.imageScaleType(), 1) zoom_start.bindToPreference(preferences.zoomStart(), 1) crop_borders.bindToPreference(preferences.cropBorders()) @@ -81,6 +135,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia */ private fun initWebtoonPreferences() { webtoon_prefs_group.visible() + pager_prefs_group.gone() crop_borders_webtoon.bindToPreference(preferences.cropBordersWebtoon()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 7edb46bd3e..4b363b1eea 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -2,31 +2,35 @@ package eu.kanade.tachiyomi.util.view +import android.app.Activity import android.content.Context +import android.content.res.Configuration import android.graphics.Color import android.graphics.Point import android.graphics.Typeface +import android.graphics.drawable.GradientDrawable +import android.os.Build import android.view.View import android.view.ViewGroup import android.view.WindowInsets import android.widget.TextView import androidx.annotation.Px import androidx.annotation.RequiresApi -import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.appcompat.widget.SearchView +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.graphics.ColorUtils import androidx.core.view.ViewCompat import com.amulyakhare.textdrawable.TextDrawable import com.amulyakhare.textdrawable.util.ColorGenerator import com.bluelinelabs.conductor.Controller +import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.snackbar.Snackbar import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.util.system.getResourceColor -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.main.MainActivity +import eu.kanade.tachiyomi.util.system.getResourceColor import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import uy.kohesive.injekt.injectLazy import kotlin.math.min /** @@ -233,4 +237,55 @@ inline fun View.updatePaddingRelative( @Px bottom: Int = paddingBottom ) { setPaddingRelative(start, top, end, bottom) +} + +fun BottomSheetDialog.setEdgeToEdge(activity: Activity, layout: View, contentView: View, + setTopMargin: Boolean) { + window?.setBackgroundDrawable(null) + val currentNightMode = activity.resources.configuration.uiMode and Configuration + .UI_MODE_NIGHT_MASK + if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && + activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0) + window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + } + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && layout is ConstraintLayout) { + val nView = View(context) + val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom + val params = ConstraintLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, height + ) + params.bottomToBottom = layout.id + params.startToStart = layout.id + params.endToEnd = layout.id + nView.layoutParams = params + nView.background = GradientDrawable( + GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf( + ColorUtils.setAlphaComponent(Color.BLACK, 179), Color.TRANSPARENT + ) + ) + layout.addView(nView) + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + //window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) + window?.findViewById(com.google.android.material.R.id.container)?.fitsSystemWindows = + false + contentView.updateLayoutParams { + if (setTopMargin) + topMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetTop + leftMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetLeft + rightMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetRight + } + } +} + +fun setBottomEdge(view: View, activity: Activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + val marginB = view.marginBottom + view.updateLayoutParams { + bottomMargin = marginB + + activity.window.decorView.rootWindowInsets.systemWindowInsetBottom + } + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/round_ripple.xml b/app/src/main/res/drawable/round_ripple.xml new file mode 100644 index 0000000000..bec0a84b4c --- /dev/null +++ b/app/src/main/res/drawable/round_ripple.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/reader_color_filter_sheet.xml b/app/src/main/res/layout-land/reader_color_filter_sheet.xml index 75c1f8424c..4dc4bd9b0d 100644 --- a/app/src/main/res/layout-land/reader_color_filter_sheet.xml +++ b/app/src/main/res/layout-land/reader_color_filter_sheet.xml @@ -4,18 +4,18 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" + android:background="?android:colorBackground" android:baselineAligned="false" - android:background="?android:colorBackground"> + android:orientation="horizontal"> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@id/scroll"> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toEndOf="@id/frame"> - + - + \ No newline at end of file diff --git a/app/src/main/res/layout/migration_bottom_sheet.xml b/app/src/main/res/layout/migration_bottom_sheet.xml index ba3024d5e0..f235d9a29e 100644 --- a/app/src/main/res/layout/migration_bottom_sheet.xml +++ b/app/src/main/res/layout/migration_bottom_sheet.xml @@ -2,8 +2,10 @@ + app:layout_constraintTop_toBottomOf="@+id/extra_search_param_text"/> + + diff --git a/app/src/main/res/layout/reader_color_filter.xml b/app/src/main/res/layout/reader_color_filter.xml index 74940f2cd3..6ce11e2668 100644 --- a/app/src/main/res/layout/reader_color_filter.xml +++ b/app/src/main/res/layout/reader_color_filter.xml @@ -2,8 +2,9 @@ diff --git a/app/src/main/res/layout/reader_color_filter_sheet.xml b/app/src/main/res/layout/reader_color_filter_sheet.xml index c4d4da941b..23e7ce23d4 100644 --- a/app/src/main/res/layout/reader_color_filter_sheet.xml +++ b/app/src/main/res/layout/reader_color_filter_sheet.xml @@ -1,10 +1,11 @@ + android:background="@drawable/bg_bottom_sheet_dialog_fragment" + android:clipToPadding="false" + android:orientation="vertical"> - + diff --git a/app/src/main/res/layout/reader_page_sheet.xml b/app/src/main/res/layout/reader_page_sheet.xml index 2cd9b7d96a..955a01e19f 100644 --- a/app/src/main/res/layout/reader_page_sheet.xml +++ b/app/src/main/res/layout/reader_page_sheet.xml @@ -2,7 +2,8 @@ diff --git a/app/src/main/res/layout/reader_settings_sheet.xml b/app/src/main/res/layout/reader_settings_sheet.xml index 3725094d1a..5dbe384c5b 100644 --- a/app/src/main/res/layout/reader_settings_sheet.xml +++ b/app/src/main/res/layout/reader_settings_sheet.xml @@ -3,12 +3,16 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/constraint_layout" android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="?android:colorBackground" + style="@style/BottomSheetDialogTheme" + android:background="@drawable/bg_bottom_sheet_dialog_fragment" + android:layout_height="wrap_content" android:clipToPadding="false" android:orientation="vertical" - android:padding="@dimen/material_component_dialogs_padding_around_content_area" + android:paddingStart="@dimen/material_component_dialogs_padding_around_content_area" + android:paddingEnd="@dimen/material_component_dialogs_padding_around_content_area" + android:paddingTop="16dp" android:forceDarkAllowed="false"> @@ -20,18 +24,22 @@ android:text="@string/pref_category_general" android:textColor="?attr/colorAccent" android:textStyle="bold" + app:layout_constraintEnd_toStartOf="@id/close_button" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - + @@ -163,6 +171,7 @@ + app:layout_constraintTop_toBottomOf="@id/crop_borders" + app:layout_constraintBottom_toBottomOf="parent"/> @@ -234,7 +245,8 @@ android:layout_marginTop="16dp" android:text="@string/pref_crop_borders" android:textColor="?android:attr/textColorSecondary" - app:layout_constraintTop_toBottomOf="@id/webtoon_prefs" /> + app:layout_constraintTop_toBottomOf="@id/webtoon_prefs" + app:layout_constraintBottom_toBottomOf="parent" /> @@ -243,7 +255,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" - app:constraint_referenced_ids="pager_prefs,scale_type_text,scale_type,zoom_start_text,zoom_start,crop_borders,page_transitions" + app:constraint_referenced_ids="pager_prefs,scale_type,scale_type_text,zoom_start_text,zoom_start,crop_borders,page_transitions" tools:visibility="visible" /> ?colorPrimaryDark - - From a07de130a9775c0b2b0588a2b2d8f8b9cf95842b Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 12 Feb 2020 22:03:28 -0800 Subject: [PATCH 051/259] Added material library grid Like the old grid but using a card view + play button Increased memory size of glide + remove cross fade being on by default --- .../tachiyomi/data/glide/TachiGlideModule.kt | 9 +- .../browse/BrowseCatalogueController.kt | 10 +- .../ui/catalogue/browse/CatalogueItem.kt | 14 +- .../browse/CatalogueMatGridHolder.kt | 63 ++++++ .../ui/library/LibraryCategoryAdapter.kt | 17 +- .../ui/library/LibraryCategoryView.kt | 7 + .../tachiyomi/ui/library/LibraryController.kt | 37 ++-- .../tachiyomi/ui/library/LibraryGridHolder.kt | 2 +- .../tachiyomi/ui/library/LibraryHolder.kt | 2 +- .../tachiyomi/ui/library/LibraryItem.kt | 22 +-- .../tachiyomi/ui/library/LibraryListHolder.kt | 2 +- .../ui/library/LibraryMatGridHolder.kt | 99 ++++++++++ .../tachiyomi/ui/library/LibraryPresenter.kt | 14 ++ .../ui/manga/info/MangaInfoController.kt | 3 + .../tachiyomi/ui/reader/ReaderPresenter.kt | 25 +-- .../tachiyomi/widget/AutofitRecyclerView.kt | 2 +- .../res/drawable/library_item_selector.xml | 35 ++++ .../res/drawable/round_play_background.xml | 24 +++ .../drawable/shape_gradient_top_shadow.xml | 2 +- .../res/layout/catalogue_mat_grid_item.xml | 187 ++++++++++++++++++ .../res/layout/catalogue_recycler_autofit.xml | 3 +- .../main/res/layout/library_controller.xml | 2 +- app/src/main/res/values/colors.xml | 4 + app/src/main/res/values/strings.xml | 7 + 24 files changed, 527 insertions(+), 65 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueMatGridHolder.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt create mode 100644 app/src/main/res/drawable/library_item_selector.xml create mode 100644 app/src/main/res/drawable/round_play_background.xml create mode 100644 app/src/main/res/layout/catalogue_mat_grid_item.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt b/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt index 1eecf3eedb..77faee50a0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt @@ -9,6 +9,7 @@ import com.bumptech.glide.annotation.GlideModule import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory +import com.bumptech.glide.load.engine.cache.LruResourceCache import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.module.AppGlideModule @@ -28,8 +29,12 @@ class TachiGlideModule : AppGlideModule() { override fun applyOptions(context: Context, builder: GlideBuilder) { builder.setDiskCache(InternalCacheDiskCacheFactory(context, 50 * 1024 * 1024)) builder.setDefaultRequestOptions(RequestOptions().format(DecodeFormat.PREFER_RGB_565)) - builder.setDefaultTransitionOptions(Drawable::class.java, - DrawableTransitionOptions.withCrossFade()) + val memoryCacheSizeBytes = 1024 * 1024 * 100 // 1000mb + builder.setMemoryCache(LruResourceCache(memoryCacheSizeBytes.toLong())) + + /* builder.setDefaultTransitionOptions( + Drawable::class.java, + DrawableTransitionOptions.withCrossFade())*/ } override fun registerComponents(context: Context, glide: Glide, registry: Registry) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index c71cb6d533..2354601929 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -106,7 +106,7 @@ open class BrowseCatalogueController(bundle: Bundle) : /** * Recycler view with the list of results. */ - private var recycler: androidx.recyclerview.widget.RecyclerView? = null + private var recycler: RecyclerView? = null /** * Subscription for the search view. @@ -212,9 +212,9 @@ open class BrowseCatalogueController(bundle: Bundle) : private fun setupRecycler(view: View) { numColumnsSubscription?.unsubscribe() - var oldPosition = androidx.recyclerview.widget.RecyclerView.NO_POSITION + var oldPosition = RecyclerView.NO_POSITION val oldRecycler = catalogue_view?.getChildAt(1) - if (oldRecycler is androidx.recyclerview.widget.RecyclerView) { + if (oldRecycler is RecyclerView) { oldPosition = (oldRecycler.layoutManager as androidx.recyclerview.widget.LinearLayoutManager).findFirstVisibleItemPosition() oldRecycler.adapter = null @@ -239,7 +239,7 @@ open class BrowseCatalogueController(bundle: Bundle) : (layoutManager as androidx.recyclerview.widget.GridLayoutManager).spanSizeLookup = object : androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup() { override fun getSpanSize(position: Int): Int { return when (adapter?.getItemViewType(position)) { - R.layout.catalogue_grid_item, null -> 1 + R.layout.catalogue_mat_grid_item, null -> 1 else -> spanCount } } @@ -251,7 +251,7 @@ open class BrowseCatalogueController(bundle: Bundle) : catalogue_view.addView(recycler, 1) recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) - if (oldPosition != androidx.recyclerview.widget.RecyclerView.NO_POSITION) { + if (oldPosition != RecyclerView.NO_POSITION) { recycler.layoutManager?.scrollToPosition(oldPosition) } this.recycler = recycler diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt index 781ca75c82..a7c2944387 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.catalogue.browse import android.view.Gravity import android.view.View import android.view.ViewGroup.LayoutParams.MATCH_PARENT +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.FrameLayout import androidx.recyclerview.widget.RecyclerView import com.f2prateek.rx.preferences.Preference @@ -15,6 +16,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.catalogue_grid_item.view.* +import kotlinx.android.synthetic.main.catalogue_mat_grid_item.view.* class CatalogueItem(val manga: Manga, private val catalogueAsList: Preference) : AbstractFlexibleItem() { @@ -23,19 +25,19 @@ class CatalogueItem(val manga: Manga, private val catalogueAsList: Preference>): CatalogueHolder { val parent = adapter.recyclerView return if (parent is AutofitRecyclerView) { view.apply { - card.layoutParams = FrameLayout.LayoutParams( - MATCH_PARENT, parent.itemWidth / 3 * 4) - gradient.layoutParams = FrameLayout.LayoutParams( - MATCH_PARENT, parent.itemWidth / 3 * 4 / 2, Gravity.BOTTOM) + val coverHeight = (parent.itemWidth / 3 * 4f).toInt() + constraint_layout.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) + cover_thumbnail.adjustViewBounds = false + cover_thumbnail.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight) } - CatalogueGridHolder(view, adapter) + CatalogueMatGridHolder(view, adapter) } else { CatalogueListHolder(view, adapter) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueMatGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueMatGridHolder.kt new file mode 100644 index 0000000000..6ad671ec24 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueMatGridHolder.kt @@ -0,0 +1,63 @@ +package eu.kanade.tachiyomi.ui.catalogue.browse + +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions +import com.bumptech.glide.signature.ObjectKey +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.flexibleadapter.items.IFlexible +import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.models.MangaImpl +import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.ui.library.LibraryCategoryAdapter +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.widget.StateImageViewTarget +import kotlinx.android.synthetic.main.catalogue_mat_grid_item.* + +/** + * Class used to hold the displayed data of a manga in the library, like the cover or the title. + * All the elements from the layout file "item_catalogue_grid" are available in this class. + * + * @param view the inflated view for this holder. + * @param adapter the adapter handling this holder. + * @param listener a listener to react to single tap and long tap events. + * @constructor creates a new library holder. + */ +class CatalogueMatGridHolder( + private val view: View, + private val adapter: FlexibleAdapter>) : + CatalogueHolder(view, adapter) { + + /** + * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this + * holder with the given manga. + * + * @param manga the manga item to bind. + */ + override fun onSetValues(manga: Manga) { + // Update the title of the manga. + title.text = manga.currentTitle() + subtitle.gone() + + bookmark_text.visibility = if (manga.favorite) View.VISIBLE else View.GONE + + // Update the cover. + setImage(manga) + } + + override fun setImage(manga: Manga) { + if (manga.thumbnail_url == null) + Glide.with(view.context).clear(cover_thumbnail) + else { + GlideApp.with(view.context) + .load(manga) + .diskCacheStrategy(DiskCacheStrategy.DATA) + .centerCrop() + .placeholder(android.R.color.transparent) + .transition(DrawableTransitionOptions.withCrossFade()) + .into(StateImageViewTarget(cover_thumbnail, progress)) + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index 174e3512f8..811b69ad49 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -11,8 +11,9 @@ import eu.kanade.tachiyomi.util.lang.chop import eu.kanade.tachiyomi.util.lang.removeArticles import uy.kohesive.injekt.injectLazy import java.text.SimpleDateFormat -import java.util.* - +import java.util.Calendar +import java.util.Date +import java.util.Locale /** * Adapter storing a list of manga in a certain category. @@ -29,6 +30,12 @@ class LibraryCategoryAdapter(val view: LibraryCategoryView) : val onItemReleaseListener: CategoryAdapter.OnItemReleaseListener = view + + /** + * Listener called when an item of the list press start reading. + */ + val libraryListener: LibraryListener = view + /** * Sets a list of manga in the adapter. * @@ -133,4 +140,10 @@ class LibraryCategoryAdapter(val view: LibraryCategoryView) : SimpleDateFormat("yyyy", Locale.getDefault()).format(date) } + interface LibraryListener { + /** + * Called when an item of the list is released. + */ + fun startReading(position: Int) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 4727afa939..07831f2f1d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -39,6 +39,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, FlexibleAdapter.OnItemMoveListener, + LibraryCategoryAdapter.LibraryListener, CategoryAdapter.OnItemReleaseListener { /** @@ -96,6 +97,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att recycler.adapter = adapter swipe_refresh.addView(recycler) adapter.fastScroller = fast_scroller + // recycler.addOnScrollListener(adapter.preloader()) if (::category.isInitialized) { val mangaForCategory = controller.presenter.getMangaInCategory(category.id) @@ -332,6 +334,11 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att if (adapter.selectedItemCount == 0) saveDragSort() } + override fun startReading(position: Int) { + val manga = adapter.getItem(position)?.manga ?: return + controller.startReading(manga) + } + private fun saveDragSort() { val mangaIds = adapter.currentItems.mapNotNull { it.manga.id } category.mangaSort = null diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index ce5365f9eb..5839728d38 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.ui.library +import android.app.Activity import android.content.Context +import android.content.Intent import android.content.res.Configuration import android.graphics.Color import android.os.Bundle @@ -50,6 +52,7 @@ import eu.kanade.tachiyomi.ui.migration.MigrationInterface import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcedureConfig +import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener @@ -141,6 +144,8 @@ class LibraryController( private var tabsVisibilitySubscription: Subscription? = null + private var observeLater:Boolean = false + var snack: Snackbar? = null var presenter = LibraryPresenter(this) @@ -165,22 +170,11 @@ class LibraryController( adapter = LibraryAdapter(this) library_pager.adapter = adapter + library_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { override fun onPageSelected(position: Int) { preferences.lastUsedCategory().set(position) activeCategory = position - } - - override fun onPageScrollStateChanged(state: Int) {} - - override fun onPageScrolled( - position: Int, positionOffset: Float, positionOffsetPixels: Int - ) { - } - }) - - library_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { - override fun onPageSelected(position: Int) { bottom_sheet.lastCategory = adapter?.categories?.getOrNull(position) if (preferences.librarySortingMode().getOrDefault() == LibrarySort.DRAG_AND_DROP) bottom_sheet.updateTitle() } @@ -227,6 +221,7 @@ class LibraryController( val library = presenter.getAllManga() if (library != null) onNextLibraryUpdate(presenter.categories, library) else { + library_pager.alpha = 0f presenter.getLibraryBlocking() } } @@ -242,6 +237,14 @@ class LibraryController( } } + override fun onActivityResumed(activity: Activity) { + super.onActivityResumed(activity) + if (observeLater) { + presenter.getLibrary() + observeLater = false + } + } + override fun onDestroy() { presenter.onDestroy() super.onDestroy() @@ -345,6 +348,8 @@ class LibraryController( } else if (!freshStart) { justStarted = false + if (library_pager.alpha == 0f) + library_pager.animate().alpha(1f).setDuration(500).start() } } @@ -666,6 +671,14 @@ class LibraryController( presenter.moveMangasToCategories(categories, mangas) destroyActionModeIfNeeded() } + + fun startReading(manga: Manga) { + val activity = activity ?: return + val chapter = presenter.getFirstUnread(manga) ?: return + val intent = ReaderActivity.newIntent(activity, manga, chapter) + observeLater = true + startActivity(intent) + } } object HeightTopWindowInsetsListener : View.OnApplyWindowInsetsListener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 8132eefc93..c4537e2c34 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -25,7 +25,7 @@ import kotlinx.android.synthetic.main.catalogue_grid_item.* */ class LibraryGridHolder( private val view: View, - adapter: FlexibleAdapter> + adapter: LibraryCategoryAdapter ) : LibraryHolder(view, adapter) { 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 1cc6144314..f08fd847df 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 @@ -15,7 +15,7 @@ import eu.davidea.flexibleadapter.items.IFlexible abstract class LibraryHolder( view: View, - val adapter: FlexibleAdapter> + val adapter: LibraryCategoryAdapter ) : BaseFlexibleViewHolder(view, adapter) { /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index b2843a439a..3427b01ef3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -1,10 +1,7 @@ package eu.kanade.tachiyomi.ui.library import android.annotation.SuppressLint -import android.view.Gravity import android.view.View -import android.view.ViewGroup.LayoutParams.MATCH_PARENT -import android.widget.FrameLayout import androidx.recyclerview.widget.RecyclerView import com.f2prateek.rx.preferences.Preference import eu.davidea.flexibleadapter.FlexibleAdapter @@ -15,10 +12,10 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.SourceManager +import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.widget.AutofitRecyclerView -import kotlinx.android.synthetic.main.catalogue_grid_item.view.* +import kotlinx.android.synthetic.main.catalogue_mat_grid_item.view.* import uy.kohesive.injekt.injectLazy -import java.io.Serializable class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference) : AbstractFlexibleItem(), IFilterable { @@ -30,21 +27,21 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference return if (libraryAsList.getOrDefault()) R.layout.catalogue_list_item else - R.layout.catalogue_grid_item + R.layout.catalogue_mat_grid_item } override fun createViewHolder(view: View, adapter: FlexibleAdapter>): LibraryHolder { val parent = adapter.recyclerView return if (parent is AutofitRecyclerView) { view.apply { - val coverHeight = parent.itemWidth / 3 * 4 - card.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight) - gradient.layoutParams = FrameLayout.LayoutParams( - MATCH_PARENT, coverHeight / 2, Gravity.BOTTOM) + val coverHeight = (parent.itemWidth / 3 * 4f).toInt() + constraint_layout.minHeight = coverHeight } - LibraryGridHolder(view, adapter) + LibraryMatGridHolder(view, adapter as LibraryCategoryAdapter, parent.itemWidth - 22.dpToPx, parent + .spanCount) + } else { - LibraryListHolder(view, adapter) + LibraryListHolder(view, adapter as LibraryCategoryAdapter) } } @@ -52,7 +49,6 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference holder: LibraryHolder, position: Int, payloads: MutableList?) { - holder.onSetValues(this) } 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 5e8e6862cf..df8fba1fe8 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,7 +30,7 @@ import kotlinx.android.synthetic.main.catalogue_list_item.unread_text class LibraryListHolder( private val view: View, - adapter: FlexibleAdapter> + adapter: LibraryCategoryAdapter ) : LibraryHolder(view, adapter) { /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt new file mode 100644 index 0000000000..947dc2a24d --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt @@ -0,0 +1,99 @@ +package eu.kanade.tachiyomi.ui.library + +import android.view.View +import com.bumptech.glide.Glide +import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.signature.ObjectKey +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.database.models.MangaImpl +import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.source.LocalSource +import eu.kanade.tachiyomi.util.system.getResourceColor +import kotlinx.android.synthetic.main.catalogue_mat_grid_item.* +import kotlinx.android.synthetic.main.catalogue_mat_grid_item.view.* + +/** + * Class used to hold the displayed data of a manga in the library, like the cover or the title. + * All the elements from the layout file "item_catalogue_grid" are available in this class. + * + * @param view the inflated view for this holder. + * @param adapter the adapter handling this holder. + * @param listener a listener to react to single tap and long tap events. + * @constructor creates a new library holder. + */ +class LibraryMatGridHolder( + private val view: View, + adapter: LibraryCategoryAdapter, + var width:Int, + var rowCount: Int +) : LibraryHolder(view, adapter) { + + /** + * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this + * holder with the given manga. + * + * @param item the manga item to bind. + */ + override fun onSetValues(item: LibraryItem) { + // Update the title of the manga. + title.text = item.manga.currentTitle() + + // Update the unread count and its visibility. + val unread = item.manga.unread + + // Update the subtitle of the manga with artist or the unread count + with(subtitle) { + text = when { + item.manga.unread > 0 -> when (item.unreadType) { + 1 -> view.resources.getQuantityString(R.plurals.unread_count, unread, unread) + 0 -> view.resources.getString(R.string.new_chapter) + else -> item.manga.originalAuthor() + } + else -> item.manga.originalAuthor() + } + setTextColor( + view.context.getResourceColor( + if (item.manga.unread > 0 && item.unreadType > -1) android.R.attr.colorAccent + else android.R.attr.textColorSecondary + ) + ) + } + play_button.visibility = if (unread > 0) View.VISIBLE else View.GONE + play_button.setOnClickListener { playButtonClicked() } + + // Update the download count and its visibility. + with(download_text) { + visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE + text = item.downloadCount.toString() + } + // Set local visibility if its local manga + local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE + + // Update the cover. + if (item.manga.thumbnail_url == null) Glide.with(view.context).clear(cover_thumbnail) + else { + val id = item.manga.id ?: return + GlideApp.with(view.context).load(item.manga) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .signature(ObjectKey(MangaImpl.getLastCoverFetch(id).toString())) + .into(cover_thumbnail) + } + } + + private fun playButtonClicked() { + adapter.libraryListener.startReading(adapterPosition) + } + + override fun onActionStateChanged(position: Int, actionState: Int) { + super.onActionStateChanged(position, actionState) + if (actionState == 2) { + view.card.isDragged = true + } + } + + override fun onItemReleased(position: Int) { + super.onItemReleased(position) + view.card.isDragged = false + } + +} 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 8d375a407a..579b45258c 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 @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.library import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category +import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory @@ -16,6 +17,7 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource +import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem import eu.kanade.tachiyomi.ui.migration.MigrationFlags import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.lang.removeArticles @@ -27,16 +29,20 @@ import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Comp import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import rx.Observable +import rx.Subscription import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.ArrayList +import java.util.Calendar import java.util.Collections import java.util.Comparator +import java.util.Date /** * Class containing library information. @@ -78,6 +84,8 @@ class LibraryPresenter( private var currentMangaMap:LibraryMap? = null + private var readerSubscription: Subscription? = null + fun isDownloading() = downloadManager.hasQueue() fun onDestroy() { @@ -684,6 +692,12 @@ class LibraryPresenter( } } + fun getFirstUnread(manga: Manga): Chapter? { + val chapters = db.getChapters(manga).executeAsBlocking() + return chapters.sortedByDescending { it.source_order }.find { !it.read } + + } + private companion object { var currentLibrary:Library? = null } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index 17b24e42a6..7ef2fec77d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -34,6 +34,7 @@ import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.resource.bitmap.RoundedCorners +import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition import com.bumptech.glide.signature.ObjectKey @@ -333,6 +334,7 @@ class MangaInfoController : NucleusController(), .load(manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())) + .transition(DrawableTransitionOptions.withCrossFade()) //.centerCrop() .into(manga_cover) if (manga_cover_full != null) { @@ -356,6 +358,7 @@ class MangaInfoController : NucleusController(), .load(manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())) + .transition(DrawableTransitionOptions.withCrossFade()) .centerCrop() .into(backdrop) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 79f5877839..a696b0d9e0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -119,20 +119,6 @@ class ReaderPresenter( } } - /** - * Called when the presenter is destroyed. It saves the current progress and cleans up - * references on the currently active chapters. - */ - override fun onDestroy() { - super.onDestroy() - val currentChapters = viewerChaptersRelay.value - if (currentChapters != null) { - currentChapters.unref() - saveChapterProgress(currentChapters.currChapter) - saveChapterHistory(currentChapters.currChapter) - } - } - /** * Called when the presenter instance is being saved. It saves the currently active chapter * id and the last page read. @@ -152,6 +138,12 @@ class ReaderPresenter( */ fun onBackPressed() { deletePendingChapters() + val currentChapters = viewerChaptersRelay.value + if (currentChapters != null) { + currentChapters.unref() + saveChapterProgress(currentChapters.currChapter) + saveChapterHistory(currentChapters.currChapter) + } } /** @@ -364,10 +356,7 @@ class ReaderPresenter( */ private fun saveChapterHistory(chapter: ReaderChapter) { val history = History.create(chapter.chapter).apply { last_read = Date().time } - db.updateHistoryLastRead(history).asRxCompletable() - .onErrorComplete() - .subscribeOn(Schedulers.io()) - .subscribe() + db.updateHistoryLastRead(history).executeAsBlocking() } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt index 738e2e70f9..53b062b6af 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt @@ -9,7 +9,7 @@ import kotlin.math.max class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : androidx.recyclerview.widget.RecyclerView(context, attrs) { - private val manager = androidx.recyclerview.widget.GridLayoutManager(context, 1) + private val manager = GridLayoutManager(context, 1) private var columnWidth = -1 diff --git a/app/src/main/res/drawable/library_item_selector.xml b/app/src/main/res/drawable/library_item_selector.xml new file mode 100644 index 0000000000..07a4041479 --- /dev/null +++ b/app/src/main/res/drawable/library_item_selector.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/round_play_background.xml b/app/src/main/res/drawable/round_play_background.xml new file mode 100644 index 0000000000..9452dd735c --- /dev/null +++ b/app/src/main/res/drawable/round_play_background.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_gradient_top_shadow.xml b/app/src/main/res/drawable/shape_gradient_top_shadow.xml index 8b67330a76..e709d2332a 100644 --- a/app/src/main/res/drawable/shape_gradient_top_shadow.xml +++ b/app/src/main/res/drawable/shape_gradient_top_shadow.xml @@ -3,5 +3,5 @@ + android:startColor="@color/md_black_1000_54"/> \ No newline at end of file diff --git a/app/src/main/res/layout/catalogue_mat_grid_item.xml b/app/src/main/res/layout/catalogue_mat_grid_item.xml new file mode 100644 index 0000000000..dc289c5e27 --- /dev/null +++ b/app/src/main/res/layout/catalogue_mat_grid_item.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/catalogue_recycler_autofit.xml b/app/src/main/res/layout/catalogue_recycler_autofit.xml index 50ff838a71..8003036795 100644 --- a/app/src/main/res/layout/catalogue_recycler_autofit.xml +++ b/app/src/main/res/layout/catalogue_recycler_autofit.xml @@ -1,5 +1,6 @@ \ No newline at end of file + tools:listitem="@layout/catalogue_mat_grid_item" /> \ No newline at end of file diff --git a/app/src/main/res/layout/library_controller.xml b/app/src/main/res/layout/library_controller.xml index 538a037856..b74570b268 100644 --- a/app/src/main/res/layout/library_controller.xml +++ b/app/src/main/res/layout/library_controller.xml @@ -33,10 +33,10 @@ android:layout_width="match_parent" android:layout_height="20dp" android:background="@drawable/shape_gradient_top_shadow" - android:backgroundTint="@color/md_black_1000_54" android:paddingBottom="10dp" app:layout_anchorGravity="top" app:layout_anchor="@id/bottom_sheet" /> + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 1101531eda..ef8c665b41 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -49,6 +49,7 @@ #DE000000 + #B3000000 #8A000000 #61000000 #1F000000 @@ -71,10 +72,13 @@ #80448AFF #2979FF + #DE2979FF #612979FF #F44336 + #DEF44336 + #009688 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 25713775c9..4391dc3010 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -409,6 +409,12 @@ %1$s is already in queue Local Remove from library? + + New chapter + %d Unread + + New + Start Reading Search filters @@ -419,6 +425,7 @@ Global search… Latest Browse + In Library This manga has been removed from the database. From f124dbdd58102df88b7deada43cb6992f5a10adb Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 13 Feb 2020 19:46:02 -0800 Subject: [PATCH 052/259] Added Option to make grid fixed size, removed rx logic from recent reads Cleanup of old filter sidebar --- .../data/preference/PreferenceKeys.kt | 2 + .../data/preference/PreferencesHelper.kt | 2 + .../tachiyomi/ui/library/LibraryController.kt | 18 +- .../tachiyomi/ui/library/LibraryItem.kt | 25 +- .../ui/library/LibraryMatGridHolder.kt | 11 +- .../ui/library/LibraryNavigationView.kt | 277 ------------------ .../tachiyomi/ui/library/LibraryPresenter.kt | 3 +- .../recently_read/RecentlyReadController.kt | 6 +- .../ui/recently_read/RecentlyReadPresenter.kt | 21 -- .../ui/setting/SettingsLibraryController.kt | 7 + .../res/layout/catalogue_mat_grid_item.xml | 34 ++- app/src/main/res/layout/library_drawer.xml | 14 - app/src/main/res/menu/library_selection.xml | 5 - app/src/main/res/values/strings.xml | 3 + 14 files changed, 71 insertions(+), 357 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt delete mode 100644 app/src/main/res/layout/library_drawer.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 5c080bcf2b..17d860f941 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -113,6 +113,8 @@ object PreferenceKeys { const val libraryAsList = "pref_display_library_as_list" + const val libraryGridFixed = "library_grid_fixes" + const val lang = "app_language" const val dateFormat = "app_date_format" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 5f6feb0668..8fff8b56e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -173,6 +173,8 @@ class PreferencesHelper(val context: Context) { fun libraryAsList() = rxPrefs.getBoolean(Keys.libraryAsList, false) + fun libraryGridFixedSize() = rxPrefs.getBoolean(Keys.libraryGridFixed, false) + fun downloadBadge() = rxPrefs.getBoolean(Keys.downloadBadge, false) fun filterDownloaded() = rxPrefs.getInteger(Keys.filterDownloaded, 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 5839728d38..69d8472033 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -264,10 +264,11 @@ class LibraryController( override fun downloadStatusChanged(downloading: Boolean) { launchUI { val scale = if (downloading) 1f else 0f + val fab = fab ?: return@launchUI fab.animate().scaleX(scale).scaleY(scale).setDuration(200).start() fab.isClickable = downloading fab.isFocusable = downloading - bottom_sheet.adjustTitleMargin(downloading) + bottom_sheet?.adjustTitleMargin(downloading) } } @@ -520,14 +521,6 @@ class LibraryController( destroyActionModeIfNeeded() } else { mode.title = resources?.getString(R.string.label_selected, count) - menu.findItem(R.id.action_hide_title)?.isVisible = - !preferences.libraryAsList().getOrDefault() - if (!preferences.libraryAsList().getOrDefault()) { - val showAll = (selectedMangas.all { (it as? LibraryManga)?.hide_title == true }) - menu.findItem(R.id.action_hide_title)?.title = activity?.getString( - if (showAll) R.string.action_show_title else R.string.action_hide_title - ) - } if (preferences.librarySortingMode().getOrDefault() == LibrarySort.DRAG_AND_DROP) { val catId = (selectedMangas.first() as? LibraryManga)?.category val sameCat = (adapter?.categories?.getOrNull(library_pager.currentItem)?.id @@ -570,12 +563,6 @@ class LibraryController( .withFadeTransaction()) destroyActionModeIfNeeded() } - R.id.action_hide_title -> { - val showAll = (selectedMangas.filter { (it as? LibraryManga)?.hide_title == true } - ).size == selectedMangas.size - presenter.hideShowTitle(selectedMangas.toList(), !showAll) - destroyActionModeIfNeeded() - } R.id.action_to_top, R.id.action_to_bottom -> { adapter?.categories?.getOrNull(library_pager.currentItem)?.id?.let { reorganizeRelay.call(it to if (item.itemId == R.id.action_to_top) -1 else -2) @@ -676,6 +663,7 @@ class LibraryController( val activity = activity ?: return val chapter = presenter.getFirstUnread(manga) ?: return val intent = ReaderActivity.newIntent(activity, manga, chapter) + destroyActionModeIfNeeded() observeLater = true startActivity(intent) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 3427b01ef3..396f38d8fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.ui.library import android.annotation.SuppressLint import android.view.View +import android.view.ViewGroup +import android.widget.FrameLayout import androidx.recyclerview.widget.RecyclerView import com.f2prateek.rx.preferences.Preference import eu.davidea.flexibleadapter.FlexibleAdapter @@ -12,12 +14,12 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.SourceManager -import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.catalogue_mat_grid_item.view.* import uy.kohesive.injekt.injectLazy -class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference) : +class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference, + private val fixedGrid: Preference) : AbstractFlexibleItem(), IFilterable { var downloadCount = -1 @@ -33,12 +35,23 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference override fun createViewHolder(view: View, adapter: FlexibleAdapter>): LibraryHolder { val parent = adapter.recyclerView return if (parent is AutofitRecyclerView) { + val fixedSize = fixedGrid.getOrDefault() view.apply { - val coverHeight = (parent.itemWidth / 3 * 4f).toInt() - constraint_layout.minHeight = coverHeight + val coverHeight = (parent.itemWidth / 3f * 4f).toInt() + if (fixedSize) { + constraint_layout.layoutParams = FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + cover_thumbnail.adjustViewBounds = false + cover_thumbnail.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, coverHeight) + } + else { + constraint_layout.minHeight = coverHeight + cover_thumbnail.maxHeight = (parent.itemWidth / 3f * 6f).toInt() + } } - LibraryMatGridHolder(view, adapter as LibraryCategoryAdapter, parent.itemWidth - 22.dpToPx, parent - .spanCount) + LibraryMatGridHolder(view, adapter as LibraryCategoryAdapter, parent.itemWidth, fixedSize) } else { LibraryListHolder(view, adapter as LibraryCategoryAdapter) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt index 947dc2a24d..406b6e78dd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt @@ -25,7 +25,7 @@ class LibraryMatGridHolder( private val view: View, adapter: LibraryCategoryAdapter, var width:Int, - var rowCount: Int + var fixedSize: Boolean ) : LibraryHolder(view, adapter) { /** @@ -58,8 +58,8 @@ class LibraryMatGridHolder( ) ) } - play_button.visibility = if (unread > 0) View.VISIBLE else View.GONE - play_button.setOnClickListener { playButtonClicked() } + play_layout.visibility = if (unread > 0) View.VISIBLE else View.GONE + play_layout.setOnClickListener { playButtonClicked() } // Update the download count and its visibility. with(download_text) { @@ -73,10 +73,11 @@ class LibraryMatGridHolder( if (item.manga.thumbnail_url == null) Glide.with(view.context).clear(cover_thumbnail) else { val id = item.manga.id ?: return - GlideApp.with(view.context).load(item.manga) + var glide = GlideApp.with(view.context).load(item.manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .signature(ObjectKey(MangaImpl.getLastCoverFetch(id).toString())) - .into(cover_thumbnail) + glide = if (fixedSize) glide.centerCrop() else glide.override(width) + glide.into(cover_thumbnail) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt deleted file mode 100644 index 372b21daec..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt +++ /dev/null @@ -1,277 +0,0 @@ -package eu.kanade.tachiyomi.ui.library - -import android.content.Context -import android.util.AttributeSet -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.database.DatabaseHelper -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault -import eu.kanade.tachiyomi.data.track.TrackManager -import eu.kanade.tachiyomi.widget.ExtendedNavigationView -import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.MultiSort.Companion.SORT_ASC -import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.MultiSort.Companion.SORT_DESC -import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.MultiSort.Companion.SORT_NONE -import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_EXCLUDE -import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_IGNORE -import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_INCLUDE -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get -import uy.kohesive.injekt.injectLazy -import kotlin.math.min - -/** - * The navigation view shown in a drawer with the different options to show the library. - */ -class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) - : ExtendedNavigationView(context, attrs) { - - /** - * Preferences helper. - */ - private val preferences: PreferencesHelper by injectLazy() - - /** - * List of groups shown in the view. - */ - private val groups = listOf(FilterGroup(), SortGroup(), DisplayGroup(), BadgeGroup()) - - /** - * Adapter instance. - */ - private val adapter = Adapter(groups.map { it.createItems() }.flatten()) - - /** - * Click listener to notify the parent fragment when an item from a group is clicked. - */ - var onGroupClicked: (Group, Item) -> Unit = { _, _ -> } - - init { - recycler.adapter = adapter - addView(recycler) - - groups.forEach { it.initModels() } - } - - /** - * Returns true if there's at least one filter from [FilterGroup] active. - */ - fun hasActiveFilters(): Boolean { - return (groups[0] as FilterGroup).items.any { - when (it) { - is Item.TriStateGroup -> - if (it.resTitle == R.string.categories) it.state == STATE_IGNORE - else it.state != STATE_IGNORE - is Item.CheckboxGroup -> it.checked - else -> false - } - } - } - - /** - * Adapter of the recycler view. - */ - inner class Adapter(items: List) : ExtendedNavigationView.Adapter(items) { - - override fun onItemClicked(item: Item) { - if (item is GroupedItem) { - item.group.onItemClicked(item) - onGroupClicked(item.group, item) - } - } - } - - /** - * Filters group (unread, downloaded, ...). - */ - inner class FilterGroup : Group { - - private val downloaded = Item.TriStateGroup(R.string.action_filter_downloaded, this) - - private val unread = Item.TriStateGroup(R.string.action_filter_unread, this) - - private val completed = Item.TriStateGroup(R.string.completed, this) - - private val tracked = Item.TriStateGroup(R.string.action_filter_tracked, this) - - private val categories = Item.TriStateGroup(R.string.action_hide_categories, this) - - override val items:List = { - val list = mutableListOf() - if (Injekt.get().getCategories().executeAsBlocking().isNotEmpty()) - list.add(categories) - list.add(downloaded) - list.add(unread) - list.add(completed) - if (Injekt.get().hasLoggedServices()) - list.add(tracked) - list - }() - - override val header = Item.Header(R.string.action_filter) - - override val footer = Item.Separator() - - override fun initModels() { - try { - categories.state = - if (preferences.hideCategories().getOrDefault()) STATE_INCLUDE - else STATE_IGNORE - downloaded.state = min(2, preferences.filterDownloaded().getOrDefault()) - unread.state = min(2, preferences.filterUnread().getOrDefault()) - completed.state = min(2, preferences.filterCompleted().getOrDefault()) - tracked.state = min(2, preferences.filterTracked().getOrDefault()) - } - catch (e: Exception) { - preferences.upgradeFilters() - } - } - - override fun onItemClicked(item: Item) { - if (item == categories) { - item as Item.TriStateGroup - val newState = when (item.state) { - STATE_IGNORE -> STATE_INCLUDE - else -> STATE_IGNORE - } - item.state = newState - when (item) { - categories -> preferences.hideCategories().set(item.state == STATE_INCLUDE) - } - } - else if (item is Item.TriStateGroup) { - val newState = when (item.state) { - STATE_IGNORE -> STATE_INCLUDE - STATE_INCLUDE -> STATE_EXCLUDE - else -> STATE_IGNORE - } - item.state = newState - when (item) { - downloaded -> preferences.filterDownloaded().set(item.state) - unread -> preferences.filterUnread().set(item.state) - completed -> preferences.filterCompleted().set(item.state) - tracked -> preferences.filterTracked().set(item.state) - } - } - adapter.notifyItemChanged(item) - } - } - - /** - * Sorting group (alphabetically, by last read, ...) and ascending or descending. - */ - inner class SortGroup : Group { - - private val alphabetically = Item.MultiSort(R.string.action_sort_alpha, this) - - private val total = Item.MultiSort(R.string.action_sort_total, this) - - private val lastRead = Item.MultiSort(R.string.action_sort_last_read, this) - - private val lastUpdated = Item.MultiSort(R.string.action_sort_last_updated, this) - - private val unread = Item.MultiSort(R.string.action_filter_unread, this) - - private val dragAndDrop = Item.MultiSort(R.string.action_sort_drag_and_drop, this) - - override val items = listOf(alphabetically, lastRead, lastUpdated, unread, total, - dragAndDrop) - - override val header = Item.Header(R.string.action_sort) - - override val footer = Item.Separator() - - override fun initModels() { - val sorting = preferences.librarySortingMode().getOrDefault() - val order = if (preferences.librarySortingAscending().getOrDefault()) - SORT_ASC else SORT_DESC - - alphabetically.state = if (sorting == LibrarySort.ALPHA) order else SORT_NONE - lastRead.state = if (sorting == LibrarySort.LAST_READ) order else SORT_NONE - lastUpdated.state = if (sorting == LibrarySort.LAST_UPDATED) order else SORT_NONE - unread.state = if (sorting == LibrarySort.UNREAD) order else SORT_NONE - total.state = if (sorting == LibrarySort.TOTAL) order else SORT_NONE - dragAndDrop.state = if (sorting == LibrarySort.DRAG_AND_DROP) order else SORT_NONE - } - - override fun onItemClicked(item: Item) { - item as Item.MultiStateGroup - val prevState = item.state - - item.group.items.forEach { (it as Item.MultiStateGroup).state = SORT_NONE } - if (item == dragAndDrop) - item.state = SORT_ASC - else - item.state = when (prevState) { - SORT_NONE -> SORT_ASC - SORT_ASC -> SORT_DESC - SORT_DESC -> SORT_ASC - else -> throw Exception("Unknown state") - } - - preferences.librarySortingMode().set(when (item) { - alphabetically -> LibrarySort.ALPHA - lastRead -> LibrarySort.LAST_READ - lastUpdated -> LibrarySort.LAST_UPDATED - unread -> LibrarySort.UNREAD - total -> LibrarySort.TOTAL - dragAndDrop -> LibrarySort.DRAG_AND_DROP - else -> LibrarySort.ALPHA - }) - preferences.librarySortingAscending().set(item.state == SORT_ASC) - - item.group.items.forEach { adapter.notifyItemChanged(it) } - } - - } - - inner class BadgeGroup : Group { - private val downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge, this) - override val header = null - override val footer = null - override val items = listOf(downloadBadge) - override fun initModels() { - downloadBadge.checked = preferences.downloadBadge().getOrDefault() - } - - override fun onItemClicked(item: Item) { - item as Item.CheckboxGroup - item.checked = !item.checked - preferences.downloadBadge().set((item.checked)) - adapter.notifyItemChanged(item) - } - } - - /** - * Display group, to show the library as a list or a grid. - */ - inner class DisplayGroup : Group { - - private val grid = Item.Radio(R.string.action_display_grid, this) - - private val list = Item.Radio(R.string.action_display_list, this) - - override val items = listOf(grid, list) - - override val header = Item.Header(R.string.action_display) - - override val footer = null - - override fun initModels() { - val asList = preferences.libraryAsList().getOrDefault() - grid.checked = !asList - list.checked = asList - } - - override fun onItemClicked(item: Item) { - item as Item.Radio - if (item.checked) return - - item.group.items.forEach { (it as Item.Radio).checked = false } - item.checked = true - - preferences.libraryAsList().set(item == list) - - item.group.items.forEach { adapter.notifyItemChanged(it) } - } - } -} 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 579b45258c..d717442774 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 @@ -420,13 +420,14 @@ class LibraryPresenter( private fun getLibraryFromDB(): Library { val categories = db.getCategories().executeAsBlocking().toMutableList() val libraryAsList = preferences.libraryAsList() + val fixedGrid = preferences.libraryGridFixedSize() val showCategories = !preferences.hideCategories().getOrDefault() val unreadBadgeType = preferences.unreadBadgeType().getOrDefault() var libraryManga = db.getLibraryMangas().executeAsBlocking() if (!showCategories) libraryManga = libraryManga.distinctBy { it.id } val libraryMap = libraryManga.map { manga -> - LibraryItem(manga, libraryAsList).apply { unreadType = unreadBadgeType } + LibraryItem(manga, libraryAsList, fixedGrid).apply { unreadType = unreadBadgeType } }.groupBy { if (showCategories) it.manga.category else 0 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index de39c8a6e2..99c8c1db60 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -101,7 +101,11 @@ class RecentlyReadController(bundle: Bundle? = null) : BaseController(bundle), override fun onActivityResumed(activity: Activity) { super.onActivityResumed(activity) if (observeLater) { - presenter.observe() + launchUI { + val manga = presenter.refresh(query) + recentItems = manga.toMutableList() + adapter?.updateDataSet(manga) + } observeLater = false } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt index bcf73ba09b..aaebfd5032 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt @@ -1,19 +1,12 @@ package eu.kanade.tachiyomi.ui.recently_read -import android.os.Bundle import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.system.launchUI import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import okhttp3.Dispatcher -import rx.Observable -import rx.Subscription -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers import uy.kohesive.injekt.injectLazy import java.util.Calendar import java.util.Comparator @@ -30,7 +23,6 @@ class RecentlyReadPresenter(private val view: RecentlyReadController) { * Used to connect to database */ val db: DatabaseHelper by injectLazy() - private var readerSubscription:Subscription? = null var lastCount = 25 var lastSearch = "" @@ -54,19 +46,6 @@ class RecentlyReadPresenter(private val view: RecentlyReadController) { .map(::RecentlyReadItem) } - fun observe() { - readerSubscription?.unsubscribe() - val cal = Calendar.getInstance() - cal.time = Date() - cal.add(Calendar.YEAR, -50) - readerSubscription = db.getRecentMangaLimit(cal.time, lastCount, "").asRxObservable().map { - val items = it.map(::RecentlyReadItem) - launchUI { - view.onNextManga(items) - } - }.observeOn(Schedulers.io()).skip(1).take(1).subscribe() - } - /** * Reset last read of chapter to 0L * @param history history belonging to chapter diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index e5129bbee0..97bb37d382 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -58,6 +58,13 @@ class SettingsLibraryController : SettingsController() { summaryRes = R.string.pref_remove_articles_summary defaultValue = false } + + switchPreference { + key = Keys.libraryGridFixed + titleRes = R.string.pref_fixed_grid + summaryRes = R.string.pref_fixed_grid_summary + defaultValue = false + } } val dbCategories = db.getCategories().executeAsBlocking() diff --git a/app/src/main/res/layout/catalogue_mat_grid_item.xml b/app/src/main/res/layout/catalogue_mat_grid_item.xml index dc289c5e27..25a08faded 100644 --- a/app/src/main/res/layout/catalogue_mat_grid_item.xml +++ b/app/src/main/res/layout/catalogue_mat_grid_item.xml @@ -108,29 +108,39 @@ android:paddingTop="10dp" android:paddingEnd="5dp" android:paddingBottom="3dp" + android:text="@string/in_library" android:textColor="@color/md_white_1000" android:textSize="13sp" android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toEndOf="@+id/local_text" app:layout_constraintTop_toTopOf="parent" - android:text="@string/in_library" tools:visibility="visible" /> - + tools:visibility="visible"> + + + - - - \ No newline at end of file diff --git a/app/src/main/res/menu/library_selection.xml b/app/src/main/res/menu/library_selection.xml index 6706833e2b..eee4c7a5ee 100644 --- a/app/src/main/res/menu/library_selection.xml +++ b/app/src/main/res/menu/library_selection.xml @@ -40,9 +40,4 @@ - - \ 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 4391dc3010..5875db43d6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -196,6 +196,9 @@ Only update ongoing manga Sync chapters after reading Sort by ignoring articles + Fixed grid size in library + Show all covers as the same height by cropping (improves + fast scrolling performance) When sorting alphabetically, sort ignoring articles (a, an, the) at the start of manga titles Skip pre-migration From dc1fe311f89d43f27ff1acf6200256b56b0f7d43 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 13 Feb 2020 22:49:32 -0800 Subject: [PATCH 053/259] Added Material List view, removed old grid And more layout fixes of course --- .../browse/BrowseCatalogueController.kt | 3 +- .../catalogue/browse/CatalogueGridHolder.kt | 50 ++-- .../ui/catalogue/browse/CatalogueItem.kt | 7 +- .../catalogue/browse/CatalogueListHolder.kt | 33 +-- .../browse/CatalogueMatGridHolder.kt | 63 ----- .../tachiyomi/ui/library/LibraryController.kt | 5 + .../tachiyomi/ui/library/LibraryGridHolder.kt | 97 ++++--- .../tachiyomi/ui/library/LibraryItem.kt | 6 +- .../tachiyomi/ui/library/LibraryListHolder.kt | 123 ++++++--- .../ui/library/LibraryMatGridHolder.kt | 100 ------- .../tachiyomi/ui/library/LibraryPresenter.kt | 2 - .../tachiyomi/ui/migration/MangaHolder.kt | 10 +- .../ui/setting/SettingsLibraryController.kt | 13 +- .../res/drawable-night/list_item_selector.xml | 20 -- .../res/drawable/library_item_selector.xml | 8 +- .../main/res/drawable/list_item_selector.xml | 13 +- .../drawable/list_item_selector_amoled.xml | 19 -- .../res/drawable/list_item_selector_dark.xml | 16 +- .../res/layout-land/filter_bottom_sheet.xml | 2 +- .../layout-sw600dp/filter_bottom_sheet.xml | 2 +- .../main/res/layout/catalogue_grid_item.xml | 227 +++++++++------- .../main/res/layout/catalogue_list_item.xml | 245 +++++++++--------- .../res/layout/catalogue_mat_grid_item.xml | 197 -------------- .../res/layout/catalogue_recycler_autofit.xml | 2 +- .../main/res/layout/filter_bottom_sheet.xml | 2 +- .../main/res/layout/library_controller.xml | 2 +- .../main/res/layout/reader_color_filter.xml | 4 +- .../main/res/layout/reader_settings_sheet.xml | 20 +- app/src/main/res/values-night/colors.xml | 2 + app/src/main/res/values-night/themes.xml | 2 +- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 11 +- app/src/main/res/values/styles.xml | 4 + 33 files changed, 539 insertions(+), 772 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueMatGridHolder.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt delete mode 100644 app/src/main/res/drawable-night/list_item_selector.xml delete mode 100644 app/src/main/res/drawable/list_item_selector_amoled.xml delete mode 100644 app/src/main/res/layout/catalogue_mat_grid_item.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index 2354601929..c361cc9f41 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -17,7 +17,6 @@ import com.f2prateek.rx.preferences.Preference import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar import com.jakewharton.rxbinding.support.v7.widget.queryTextChangeEvents -import com.jakewharton.rxbinding.view.visible import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R @@ -239,7 +238,7 @@ open class BrowseCatalogueController(bundle: Bundle) : (layoutManager as androidx.recyclerview.widget.GridLayoutManager).spanSizeLookup = object : androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup() { override fun getSpanSize(position: Int): Int { return when (adapter?.getItemViewType(position)) { - R.layout.catalogue_mat_grid_item, null -> 1 + R.layout.catalogue_grid_item, null -> 1 else -> spanCount } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueGridHolder.kt index 0fb957f2cc..97fc021bb5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueGridHolder.kt @@ -1,51 +1,63 @@ package eu.kanade.tachiyomi.ui.catalogue.browse import android.view.View +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions +import com.bumptech.glide.signature.ObjectKey import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.ui.library.LibraryCategoryAdapter +import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.widget.StateImageViewTarget import kotlinx.android.synthetic.main.catalogue_grid_item.* -import androidx.recyclerview.widget.RecyclerView -import eu.davidea.flexibleadapter.items.IFlexible /** - * Class used to hold the displayed data of a manga in the catalogue, like the cover or the title. + * Class used to hold the displayed data of a manga in the library, like the cover or the title. * All the elements from the layout file "item_catalogue_grid" are available in this class. * * @param view the inflated view for this holder. * @param adapter the adapter handling this holder. - * @constructor creates a new catalogue holder. + * @param listener a listener to react to single tap and long tap events. + * @constructor creates a new library holder. */ -class CatalogueGridHolder(private val view: View, private val adapter: FlexibleAdapter>) : - CatalogueHolder(view, adapter) { +class CatalogueGridHolder( + private val view: View, + private val adapter: FlexibleAdapter>) : + CatalogueHolder(view, adapter) { /** - * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this + * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * holder with the given manga. * - * @param manga the manga to bind. + * @param manga the manga item to bind. */ override fun onSetValues(manga: Manga) { - // Set manga title - title.text = manga.originalTitle() + // Update the title of the manga. + title.text = manga.currentTitle() + subtitle.gone() - // Set alpha of thumbnail. - thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f + bookmark_text.visibility = if (manga.favorite) View.VISIBLE else View.GONE + // Update the cover. setImage(manga) } override fun setImage(manga: Manga) { - GlideApp.with(view.context).clear(thumbnail) - if (!manga.thumbnail_url.isNullOrEmpty()) { + if (manga.thumbnail_url == null) + Glide.with(view.context).clear(cover_thumbnail) + else { GlideApp.with(view.context) - .load(manga) - .diskCacheStrategy(DiskCacheStrategy.DATA) - .centerCrop() - .placeholder(android.R.color.transparent) - .into(StateImageViewTarget(thumbnail, progress)) + .load(manga) + .diskCacheStrategy(DiskCacheStrategy.DATA) + .centerCrop() + .placeholder(android.R.color.transparent) + .transition(DrawableTransitionOptions.withCrossFade()) + .into(StateImageViewTarget(cover_thumbnail, progress)) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt index a7c2944387..071dfb2540 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueItem.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.catalogue.browse -import android.view.Gravity import android.view.View import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT @@ -13,10 +12,8 @@ import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.getOrDefault -import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.catalogue_grid_item.view.* -import kotlinx.android.synthetic.main.catalogue_mat_grid_item.view.* class CatalogueItem(val manga: Manga, private val catalogueAsList: Preference) : AbstractFlexibleItem() { @@ -25,7 +22,7 @@ class CatalogueItem(val manga: Manga, private val catalogueAsList: Preference>): CatalogueHolder { @@ -37,7 +34,7 @@ class CatalogueItem(val manga: Manga, private val catalogueAsList: Preference>) : CatalogueHolder(view, adapter) { - private val favoriteColor = view.context.getResourceColor(android.R.attr.textColorHint) - private val unfavoriteColor = view.context.getResourceColor(android.R.attr.textColorPrimary) - /** * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this * holder with the given manga. @@ -33,22 +32,26 @@ class CatalogueListHolder(private val view: View, adapter: FlexibleAdapter>) : - CatalogueHolder(view, adapter) { - - /** - * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this - * holder with the given manga. - * - * @param manga the manga item to bind. - */ - override fun onSetValues(manga: Manga) { - // Update the title of the manga. - title.text = manga.currentTitle() - subtitle.gone() - - bookmark_text.visibility = if (manga.favorite) View.VISIBLE else View.GONE - - // Update the cover. - setImage(manga) - } - - override fun setImage(manga: Manga) { - if (manga.thumbnail_url == null) - Glide.with(view.context).clear(cover_thumbnail) - else { - GlideApp.with(view.context) - .load(manga) - .diskCacheStrategy(DiskCacheStrategy.DATA) - .centerCrop() - .placeholder(android.R.color.transparent) - .transition(DrawableTransitionOptions.withCrossFade()) - .into(StateImageViewTarget(cover_thumbnail, progress)) - } - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 69d8472033..4aa2a1f4a3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -245,6 +245,11 @@ class LibraryController( } } + override fun onActivityPaused(activity: Activity) { + super.onActivityPaused(activity) + presenter.onDestroy() + } + override fun onDestroy() { presenter.onDestroy() super.onDestroy() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index c4537e2c34..43bb338244 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -1,18 +1,17 @@ package eu.kanade.tachiyomi.ui.library import android.view.View -import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView +import androidx.core.content.ContextCompat +import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.signature.ObjectKey -import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.flexibleadapter.items.IFlexible +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource -import eu.kanade.tachiyomi.util.system.dpToPx -import eu.kanade.tachiyomi.util.view.updateLayoutParams +import eu.kanade.tachiyomi.util.system.getResourceColor import kotlinx.android.synthetic.main.catalogue_grid_item.* +import kotlinx.android.synthetic.main.catalogue_grid_item.view.* /** * Class used to hold the displayed data of a manga in the library, like the cover or the title. @@ -24,9 +23,10 @@ import kotlinx.android.synthetic.main.catalogue_grid_item.* * @constructor creates a new library holder. */ class LibraryGridHolder( - private val view: View, - adapter: LibraryCategoryAdapter - + private val view: View, + adapter: LibraryCategoryAdapter, + var width:Int, + var fixedSize: Boolean ) : LibraryHolder(view, adapter) { /** @@ -37,35 +37,70 @@ class LibraryGridHolder( */ override fun onSetValues(item: LibraryItem) { // Update the title of the manga. - with(title) { - visibility = if (item.manga.hide_title) View.GONE else View.VISIBLE - text = item.manga.currentTitle() - } - gradient.visibility = if (item.manga.hide_title) View.GONE else View.VISIBLE + title.text = item.manga.currentTitle() // Update the unread count and its visibility. - with(unread_text) { - visibility = - if (item.manga.unread > 0 && item.unreadType == 1) View.VISIBLE else View.GONE - text = item.manga.unread.toString() + val unread = item.manga.unread + + // Update the subtitle of the manga with artist or the unread count + with(subtitle) { + text = when { + item.manga.unread > 0 -> when (item.unreadType) { + 1 -> view.resources.getQuantityString(R.plurals.unread_count, unread, unread) + 0 -> view.resources.getString(R.string.new_chapter) + else -> item.manga.originalAuthor() + } + else -> item.manga.originalAuthor() + } + setTextColor( + view.context.getResourceColor( + if (item.manga.unread > 0 && item.unreadType > -1) android.R.attr.colorAccent + else android.R.attr.textColorSecondary + ) + ) } - // Update the download count and its visibility. - unread_badge.visibility = - if (item.manga.unread > 0 && item.unreadType == 0) View.VISIBLE else View.GONE + play_layout.visibility = if (unread > 0) View.VISIBLE else View.GONE + play_layout.setOnClickListener { playButtonClicked() } + + // Update the download count or local status and its visibility. with(download_text) { - visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE - text = item.downloadCount.toString() + visibility = if (item.downloadCount > -1 && (item.downloadCount > 0 || item.manga + .source == LocalSource.ID)) + View.VISIBLE else View.GONE + text = if (item.manga.source == LocalSource.ID) + itemView.resources.getString(R.string.local_source_badge) + else item.downloadCount.toString() + backgroundTintList = ContextCompat.getColorStateList(itemView.context, + if (item.manga.source == LocalSource.ID) R.color.md_teal_500 + else R.color.md_red_500) } - //set local visibility if its local manga - local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE // Update the cover. - if (item.manga.thumbnail_url == null) - GlideApp.with(view.context).clear(thumbnail) - else GlideApp.with(view.context).load(item.manga) - .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) - .signature(ObjectKey(MangaImpl.getLastCoverFetch(item.manga.id!!).toString())) - .centerCrop().into(thumbnail) + if (item.manga.thumbnail_url == null) Glide.with(view.context).clear(cover_thumbnail) + else { + val id = item.manga.id ?: return + var glide = GlideApp.with(view.context).load(item.manga) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .signature(ObjectKey(MangaImpl.getLastCoverFetch(id).toString())) + glide = if (fixedSize) glide.centerCrop() else glide.override(width) + glide.into(cover_thumbnail) + } + } + + private fun playButtonClicked() { + adapter.libraryListener.startReading(adapterPosition) + } + + override fun onActionStateChanged(position: Int, actionState: Int) { + super.onActionStateChanged(position, actionState) + if (actionState == 2) { + view.card.isDragged = true + } + } + + override fun onItemReleased(position: Int) { + super.onItemReleased(position) + view.card.isDragged = false } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 396f38d8fe..381e1b7ba9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -15,7 +15,7 @@ import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.widget.AutofitRecyclerView -import kotlinx.android.synthetic.main.catalogue_mat_grid_item.view.* +import kotlinx.android.synthetic.main.catalogue_grid_item.view.* import uy.kohesive.injekt.injectLazy class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference, @@ -29,7 +29,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference return if (libraryAsList.getOrDefault()) R.layout.catalogue_list_item else - R.layout.catalogue_mat_grid_item + R.layout.catalogue_grid_item } override fun createViewHolder(view: View, adapter: FlexibleAdapter>): LibraryHolder { @@ -51,7 +51,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference cover_thumbnail.maxHeight = (parent.itemWidth / 3f * 6f).toInt() } } - LibraryMatGridHolder(view, adapter as LibraryCategoryAdapter, parent.itemWidth, fixedSize) + LibraryGridHolder(view, adapter as LibraryCategoryAdapter, parent.itemWidth, fixedSize) } else { LibraryListHolder(view, adapter as LibraryCategoryAdapter) 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 df8fba1fe8..7a80328bc8 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 @@ -1,22 +1,21 @@ package eu.kanade.tachiyomi.ui.library +import android.text.Html import android.view.View +import androidx.core.content.ContextCompat +import androidx.core.text.HtmlCompat +import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy -import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource import kotlinx.android.synthetic.main.catalogue_list_item.* -import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.signature.ObjectKey -import eu.davidea.flexibleadapter.items.IFlexible +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.MangaImpl -import kotlinx.android.synthetic.main.catalogue_grid_item.* -import kotlinx.android.synthetic.main.catalogue_list_item.download_text -import kotlinx.android.synthetic.main.catalogue_list_item.local_text -import kotlinx.android.synthetic.main.catalogue_list_item.thumbnail +import eu.kanade.tachiyomi.util.system.getResourceColor +import kotlinx.android.synthetic.main.catalogue_list_item.subtitle import kotlinx.android.synthetic.main.catalogue_list_item.title -import kotlinx.android.synthetic.main.catalogue_list_item.unread_badge -import kotlinx.android.synthetic.main.catalogue_list_item.unread_text +import kotlinx.android.synthetic.main.catalogue_list_item.view.* /** * Class used to hold the displayed data of a manga in the library, like the cover or the title. @@ -44,37 +43,89 @@ class LibraryListHolder( title.text = item.manga.currentTitle() // Update the unread count and its visibility. - with(unread_text) { - visibility = if (item.manga.unread > 0 && item.unreadType == 1) View.VISIBLE else - View.GONE - text = item.manga.unread.toString() - } - unread_badge.visibility = - if (item.manga.unread > 0 && item.unreadType == 0) View.VISIBLE else View.GONE - // Update the download count and its visibility. - with(download_text) { - visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE - text = "${item.downloadCount}" - } - //show local text badge if local manga - local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE + val unread = item.manga.unread - // Create thumbnail onclick to simulate long click - thumbnail.setOnClickListener { - // Simulate long click on this view to enter selection mode - onLongClick(itemView) + // Update the subtitle of the manga with artist or the unread count and download count + "First Color" + val subtitleText = when { + unread > 0 -> when (item.unreadType) { + 1 -> view.resources.getQuantityString(R.plurals.unread_count, unread, unread) + 0 -> view.resources.getString(R.string.new_chapter) + else -> item.manga.originalAuthor() + } + else -> item.manga.originalAuthor() } + // Update the download count or local status and its visibility. + val downloadText = + if (item.manga.source == LocalSource.ID) + itemView.resources.getString(R.string.local_source_badge) + else view.resources.getQuantityString(R.plurals.download_count, + item.downloadCount, item.downloadCount) + + // Combine the 2 above using html + val subText = if (item.downloadCount > 0 || item.manga.source == LocalSource.ID) { + val downloadColor = convertColor(ContextCompat.getColor(itemView.context, + if (item.manga.source == LocalSource.ID) R.color.md_teal_500 + else R.color.md_red_500)) + val unreadColor = convertColor(itemView.context.getResourceColor(R.attr.colorAccent)) + when { + unread > 0 && item.unreadType > -1 -> "$downloadText | " + + "$subtitleText" + subtitleText != null -> "$downloadText | " + + subtitleText + else -> "$downloadText" + } + } + else { + subtitleText + } + with(subtitle) { + text = HtmlCompat.fromHtml(subText ?: "", HtmlCompat.FROM_HTML_MODE_LEGACY) + setTextColor( + view.context.getResourceColor( + if (item.manga.unread > 0 && item.unreadType > -1 && item.downloadCount <= 0 + && item.manga.source != LocalSource.ID) + android.R.attr.colorAccent + else android.R.attr.textColorSecondary + ) + ) + } + play_layout.visibility = if (unread > 0) View.VISIBLE else View.GONE + play_layout.setOnClickListener { playButtonClicked() } // Update the cover. - GlideApp.with(itemView.context).clear(thumbnail) - GlideApp.with(itemView.context) - .load(item.manga) - .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) - .signature(ObjectKey(MangaImpl.getLastCoverFetch(item.manga.id!!).toString())) - .centerCrop() - .circleCrop() - .dontAnimate() - .into(thumbnail) + if (item.manga.thumbnail_url == null) Glide.with(view.context).clear(cover_thumbnail) + else { + val id = item.manga.id ?: return + val height = itemView.context.resources.getDimensionPixelSize(R.dimen + .material_component_lists_single_line_with_avatar_height) + GlideApp.with(view.context).load(item.manga) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .signature(ObjectKey(MangaImpl.getLastCoverFetch(id).toString())) + .override(height) + .into(cover_thumbnail) + } + } + + private fun convertColor(color: Int):String { + return Integer.toHexString(color and 0x00ffffff) + } + + private fun playButtonClicked() { + adapter.libraryListener.startReading(adapterPosition) + } + + override fun onActionStateChanged(position: Int, actionState: Int) { + super.onActionStateChanged(position, actionState) + if (actionState == 2) { + view.card.isDragged = true + } + } + + override fun onItemReleased(position: Int) { + super.onItemReleased(position) + view.card.isDragged = false } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt deleted file mode 100644 index 406b6e78dd..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMatGridHolder.kt +++ /dev/null @@ -1,100 +0,0 @@ -package eu.kanade.tachiyomi.ui.library - -import android.view.View -import com.bumptech.glide.Glide -import com.bumptech.glide.load.engine.DiskCacheStrategy -import com.bumptech.glide.signature.ObjectKey -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.database.models.MangaImpl -import eu.kanade.tachiyomi.data.glide.GlideApp -import eu.kanade.tachiyomi.source.LocalSource -import eu.kanade.tachiyomi.util.system.getResourceColor -import kotlinx.android.synthetic.main.catalogue_mat_grid_item.* -import kotlinx.android.synthetic.main.catalogue_mat_grid_item.view.* - -/** - * Class used to hold the displayed data of a manga in the library, like the cover or the title. - * All the elements from the layout file "item_catalogue_grid" are available in this class. - * - * @param view the inflated view for this holder. - * @param adapter the adapter handling this holder. - * @param listener a listener to react to single tap and long tap events. - * @constructor creates a new library holder. - */ -class LibraryMatGridHolder( - private val view: View, - adapter: LibraryCategoryAdapter, - var width:Int, - var fixedSize: Boolean -) : LibraryHolder(view, adapter) { - - /** - * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this - * holder with the given manga. - * - * @param item the manga item to bind. - */ - override fun onSetValues(item: LibraryItem) { - // Update the title of the manga. - title.text = item.manga.currentTitle() - - // Update the unread count and its visibility. - val unread = item.manga.unread - - // Update the subtitle of the manga with artist or the unread count - with(subtitle) { - text = when { - item.manga.unread > 0 -> when (item.unreadType) { - 1 -> view.resources.getQuantityString(R.plurals.unread_count, unread, unread) - 0 -> view.resources.getString(R.string.new_chapter) - else -> item.manga.originalAuthor() - } - else -> item.manga.originalAuthor() - } - setTextColor( - view.context.getResourceColor( - if (item.manga.unread > 0 && item.unreadType > -1) android.R.attr.colorAccent - else android.R.attr.textColorSecondary - ) - ) - } - play_layout.visibility = if (unread > 0) View.VISIBLE else View.GONE - play_layout.setOnClickListener { playButtonClicked() } - - // Update the download count and its visibility. - with(download_text) { - visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE - text = item.downloadCount.toString() - } - // Set local visibility if its local manga - local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE - - // Update the cover. - if (item.manga.thumbnail_url == null) Glide.with(view.context).clear(cover_thumbnail) - else { - val id = item.manga.id ?: return - var glide = GlideApp.with(view.context).load(item.manga) - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) - .signature(ObjectKey(MangaImpl.getLastCoverFetch(id).toString())) - glide = if (fixedSize) glide.centerCrop() else glide.override(width) - glide.into(cover_thumbnail) - } - } - - private fun playButtonClicked() { - adapter.libraryListener.startReading(adapterPosition) - } - - override fun onActionStateChanged(position: Int, actionState: Int) { - super.onActionStateChanged(position, actionState) - if (actionState == 2) { - view.card.isDragged = true - } - } - - override fun onItemReleased(position: Int) { - super.onItemReleased(position) - view.card.isDragged = false - } - -} 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 d717442774..83d268221c 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 @@ -84,8 +84,6 @@ class LibraryPresenter( private var currentMangaMap:LibraryMap? = null - private var readerSubscription: Subscription? = null - fun isDownloading() = downloadManager.hasQueue() fun onDestroy() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaHolder.kt index 61a9a14199..82ac9a4967 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaHolder.kt @@ -19,20 +19,20 @@ class MangaHolder( title.text = item.manga.currentTitle() // Create thumbnail onclick to simulate long click - thumbnail.setOnClickListener { + cover_thumbnail.setOnClickListener { // Simulate long click on this view to enter selection mode onLongClick(itemView) } // Update the cover. - GlideApp.with(itemView.context).clear(thumbnail) + GlideApp.with(itemView.context).clear(cover_thumbnail) GlideApp.with(itemView.context) .load(item.manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) - .centerCrop() - .circleCrop() +// .centerCrop() +// .circleCrop() .dontAnimate() - .into(thumbnail) + .into(cover_thumbnail) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 97bb37d382..d7fec0040e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -52,6 +52,13 @@ class SettingsLibraryController : SettingsController() { } } + switchPreference { + key = Keys.libraryGridFixed + titleRes = R.string.pref_fixed_grid + summaryRes = R.string.pref_fixed_grid_summary + defaultValue = false + } + switchPreference { key = Keys.removeArticles titleRes = R.string.pref_remove_articles @@ -59,12 +66,6 @@ class SettingsLibraryController : SettingsController() { defaultValue = false } - switchPreference { - key = Keys.libraryGridFixed - titleRes = R.string.pref_fixed_grid - summaryRes = R.string.pref_fixed_grid_summary - defaultValue = false - } } val dbCategories = db.getCategories().executeAsBlocking() diff --git a/app/src/main/res/drawable-night/list_item_selector.xml b/app/src/main/res/drawable-night/list_item_selector.xml deleted file mode 100644 index ff1236a28c..0000000000 --- a/app/src/main/res/drawable-night/list_item_selector.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/drawable/library_item_selector.xml b/app/src/main/res/drawable/library_item_selector.xml index 07a4041479..658066ad8e 100644 --- a/app/src/main/res/drawable/library_item_selector.xml +++ b/app/src/main/res/drawable/library_item_selector.xml @@ -1,6 +1,6 @@ + android:color="@color/fullRippleColor"> - + - + - + diff --git a/app/src/main/res/drawable/list_item_selector.xml b/app/src/main/res/drawable/list_item_selector.xml index d219df8b1c..8f92da27e8 100644 --- a/app/src/main/res/drawable/list_item_selector.xml +++ b/app/src/main/res/drawable/list_item_selector.xml @@ -1,18 +1,21 @@ + android:color="@color/fullRippleColor"> + + + - + - + - - + + diff --git a/app/src/main/res/drawable/list_item_selector_amoled.xml b/app/src/main/res/drawable/list_item_selector_amoled.xml deleted file mode 100644 index e11e4e9e53..0000000000 --- a/app/src/main/res/drawable/list_item_selector_amoled.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/drawable/list_item_selector_dark.xml b/app/src/main/res/drawable/list_item_selector_dark.xml index fea6891057..48af7d3484 100644 --- a/app/src/main/res/drawable/list_item_selector_dark.xml +++ b/app/src/main/res/drawable/list_item_selector_dark.xml @@ -7,14 +7,16 @@ - - - - + + + - - - diff --git a/app/src/main/res/layout-land/filter_bottom_sheet.xml b/app/src/main/res/layout-land/filter_bottom_sheet.xml index 7a670bdccb..67aaa40f14 100644 --- a/app/src/main/res/layout-land/filter_bottom_sheet.xml +++ b/app/src/main/res/layout-land/filter_bottom_sheet.xml @@ -193,7 +193,7 @@ android:focusable="true" android:gravity="start|center" android:padding="5dp" - android:text="@string/action_display_unread_badge" + android:text="@string/action_display_unread_text" android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" android:textColor="?android:attr/textColorPrimary" android:textSize="15sp" diff --git a/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml b/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml index 70c07ccabf..5c6fec5897 100644 --- a/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml +++ b/app/src/main/res/layout-sw600dp/filter_bottom_sheet.xml @@ -193,7 +193,7 @@ android:focusable="true" android:gravity="start|center" android:padding="5dp" - android:text="@string/action_display_unread_badge" + android:text="@string/action_display_unread_text" android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" android:textColor="?android:attr/textColorPrimary" android:textSize="15sp" diff --git a/app/src/main/res/layout/catalogue_grid_item.xml b/app/src/main/res/layout/catalogue_grid_item.xml index e59629051f..83b13098e1 100644 --- a/app/src/main/res/layout/catalogue_grid_item.xml +++ b/app/src/main/res/layout/catalogue_grid_item.xml @@ -1,132 +1,169 @@ - + android:layout_gravity="bottom"> - + - - - + android:layout_marginTop="2dp" + android:layout_marginStart="6dp" + android:layout_marginEnd="6dp" + app:layout_constraintBottom_toTopOf="@+id/title" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="1.0"> - - + tools:background="?android:attr/colorBackground" + tools:ignore="ContentDescription" + tools:src="@mipmap/ic_launcher" /> + tools:text="1" /> + - + tools:visibility="visible" /> - + + + + + + + + + + + + android:singleLine="true" + android:textColor="?android:attr/textColorPrimary" + android:textSize="12sp" + app:layout_constraintBottom_toTopOf="@+id/subtitle" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + tools:text="Sample name" /> - + android:layout_marginBottom="14dp" + android:ellipsize="end" + android:lineSpacingExtra="-4dp" + android:layout_marginStart="6dp" + android:paddingEnd="6dp" + android:singleLine="true" + android:textColor="?android:attr/textColorSecondary" + android:textSize="12sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + tools:text="Sample artist" /> - - - - - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/catalogue_list_item.xml b/app/src/main/res/layout/catalogue_list_item.xml index 8cf6ecf2a9..40234a206d 100644 --- a/app/src/main/res/layout/catalogue_list_item.xml +++ b/app/src/main/res/layout/catalogue_list_item.xml @@ -1,132 +1,145 @@ - + android:minHeight="@dimen/material_component_lists_single_line_with_avatar_height" + tools:layout_editor_absoluteX="0dp" + tools:layout_editor_absoluteY="25dp"> - - - + + + + + + + + + + + + android:singleLine="true" + android:textColor="?android:attr/textColorSecondary" + android:textSize="14sp" + app:layout_constrainedWidth="true" + app:layout_constraintEnd_toStartOf="@+id/extras_layout" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="@+id/title" + app:layout_constraintTop_toBottomOf="@+id/title" + app:layout_constraintVertical_bias="0.0" + tools:text="Manga artist" /> - - - - - - - - - + app:layout_constraintTop_toTopOf="parent"> + + + + + + + + + + + diff --git a/app/src/main/res/layout/catalogue_mat_grid_item.xml b/app/src/main/res/layout/catalogue_mat_grid_item.xml deleted file mode 100644 index 25a08faded..0000000000 --- a/app/src/main/res/layout/catalogue_mat_grid_item.xml +++ /dev/null @@ -1,197 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/catalogue_recycler_autofit.xml b/app/src/main/res/layout/catalogue_recycler_autofit.xml index 8003036795..7df2aaf743 100644 --- a/app/src/main/res/layout/catalogue_recycler_autofit.xml +++ b/app/src/main/res/layout/catalogue_recycler_autofit.xml @@ -8,4 +8,4 @@ android:layout_height="match_parent" android:columnWidth="140dp" android:clipToPadding="false" - tools:listitem="@layout/catalogue_mat_grid_item" /> \ No newline at end of file + tools:listitem="@layout/catalogue_grid_item" /> \ No newline at end of file diff --git a/app/src/main/res/layout/filter_bottom_sheet.xml b/app/src/main/res/layout/filter_bottom_sheet.xml index aa56f1a873..0cd2664dd7 100644 --- a/app/src/main/res/layout/filter_bottom_sheet.xml +++ b/app/src/main/res/layout/filter_bottom_sheet.xml @@ -190,7 +190,7 @@ android:focusable="true" android:gravity="start|center" android:padding="5dp" - android:text="@string/action_display_unread_badge" + android:text="@string/action_display_unread_text" android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" android:textColor="?android:attr/textColorPrimary" android:textSize="15sp" diff --git a/app/src/main/res/layout/library_controller.xml b/app/src/main/res/layout/library_controller.xml index b74570b268..10389c4a66 100644 --- a/app/src/main/res/layout/library_controller.xml +++ b/app/src/main/res/layout/library_controller.xml @@ -31,7 +31,7 @@ @@ -228,7 +228,7 @@ app:layout_constraintEnd_toEndOf="parent"/> @@ -193,7 +193,7 @@ android:layout_height="wrap_content" android:text="@string/pref_zoom_start" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintEnd_toStartOf="@id/verticalcenter" + app:layout_constraintEnd_toStartOf="@id/bottom_line" app:layout_constraintBaseline_toBaselineOf="@id/zoom_start"/> #212121 #212121 + @color/md_white_1000_12 #3399FF #B3000000 #FFFFFF #212121 @color/md_white_1000_20 + #707070 @color/md_grey_800 #3399FF #212121 diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index b6ee4ed8f3..82788cb292 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -31,7 +31,7 @@ @color/textColorPrimary - @drawable/list_item_selector_amoled + @drawable/list_item_selector @drawable/library_item_selector_amoled @color/dialog_amoled diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ef8c665b41..8faae86f5d 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -13,6 +13,7 @@ #323232 #323232 @color/md_white_1000 + #C2C2C2 @color/md_black_1000_12 @color/md_blue_A400 @color/md_black_1000_38 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5875db43d6..289638ab53 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -97,7 +97,7 @@ Grid List Download badges - Unread badges + Unread text All unread Any unread Hide unread @@ -197,8 +197,7 @@ Sync chapters after reading Sort by ignoring articles Fixed grid size in library - Show all covers as the same height by cropping (improves - fast scrolling performance) + Show all covers as the same height by cropping When sorting alphabetically, sort ignoring articles (a, an, the) at the start of manga titles Skip pre-migration @@ -414,10 +413,14 @@ Remove from library? New chapter - %d Unread + %d unread New Start Reading + + 1 downloaded + %d downloaded + Search filters diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c3089f614f..11721c49c5 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -56,6 +56,10 @@ bold + + From dea8e18edaff4ab89b68b0e2ea605360c46ed7e0 Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 14 Feb 2020 00:27:55 -0800 Subject: [PATCH 054/259] Increase Glide cache size, Fixed extension/broswe catalogue filter buttons --- .../eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt | 4 ++-- .../ui/catalogue/browse/CatalogueNavigationView.kt | 6 ++++++ .../eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt | 3 +-- app/src/main/res/drawable/button_bg_transparent.xml | 7 +------ app/src/main/res/layout/catalogue_drawer_content.xml | 9 +++++++-- app/src/main/res/layout/extension_card_item.xml | 3 +-- app/src/main/res/layout/extension_detail_controller.xml | 1 + app/src/main/res/layout/navigation_view_text.xml | 6 +++--- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt b/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt index 77faee50a0..4b57d19347 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt @@ -27,9 +27,9 @@ import java.io.InputStream class TachiGlideModule : AppGlideModule() { override fun applyOptions(context: Context, builder: GlideBuilder) { - builder.setDiskCache(InternalCacheDiskCacheFactory(context, 50 * 1024 * 1024)) + builder.setDiskCache(InternalCacheDiskCacheFactory(context, 100 * 1024 * 1024)) builder.setDefaultRequestOptions(RequestOptions().format(DecodeFormat.PREFER_RGB_565)) - val memoryCacheSizeBytes = 1024 * 1024 * 100 // 1000mb + val memoryCacheSizeBytes = 1024 * 1024 * 100 // 100mb builder.setMemoryCache(LruResourceCache(memoryCacheSizeBytes.toLong())) /* builder.setDefaultTransitionOptions( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt index b467213418..6a62e0792b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt @@ -6,7 +6,9 @@ import android.view.ViewGroup import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.util.view.inflate +import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.widget.SimpleNavigationView import kotlinx.android.synthetic.main.catalogue_drawer_content.view.* @@ -31,6 +33,10 @@ class CatalogueNavigationView @JvmOverloads constructor(context: Context, attrs: title.text = context.getString(R.string.source_search_options) search_btn.setOnClickListener { onSearchClicked() } reset_btn.setOnClickListener { onResetClicked() } + view.search_layout.setOnApplyWindowInsetsListener { v, insets -> + view.updatePaddingRelative(bottom = insets.systemWindowInsetBottom) + insets + } } fun setFilters(items: List>) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt index 99ad2f5794..d3b5aea23c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt @@ -61,9 +61,8 @@ class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) : isClickable = true isActivated = false - //background = VectorDrawableCompat.create(resources!!, R.drawable.button_bg_transparent, null) setTextColor(ContextCompat.getColorStateList(context, R.drawable.button_text_state)) - backgroundTintList = ContextCompat.getColorStateList(context, R.color.button_bg) + backgroundTintList = ContextCompat.getColorStateList(context, android.R.color.transparent) val extension = item.extension diff --git a/app/src/main/res/drawable/button_bg_transparent.xml b/app/src/main/res/drawable/button_bg_transparent.xml index 8fc57a2aee..a9e82645b7 100644 --- a/app/src/main/res/drawable/button_bg_transparent.xml +++ b/app/src/main/res/drawable/button_bg_transparent.xml @@ -1,11 +1,6 @@ - - - - - - + diff --git a/app/src/main/res/layout/catalogue_drawer_content.xml b/app/src/main/res/layout/catalogue_drawer_content.xml index 450078cab4..9c1b558f55 100644 --- a/app/src/main/res/layout/catalogue_drawer_content.xml +++ b/app/src/main/res/layout/catalogue_drawer_content.xml @@ -27,7 +27,7 @@ android:maxLines="1" tools:text="Title" android:textAppearance="@style/TextAppearance.AppCompat.Body2" - android:textColor="@color/md_white_1000"/> + android:textColor="?attr/actionBarTintColor"/> @@ -44,10 +44,14 @@ android:background="?android:attr/divider"/> + android:paddingStart="8dp" + android:paddingEnd="8dp" + android:paddingTop="8dp" + tools:paddingBottom="20dp">