From 40e4adc23b6d3671ebf27ea7fc499cce9e7b9dd7 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 6 Feb 2020 05:52:00 -0800 Subject: [PATCH] More work to the bottom sheet + fixed white theme in webview for dark mode --- .../tachiyomi/ui/library/FilterBottomSheet.kt | 80 +++++++++++++++++-- .../tachiyomi/ui/library/FilterTagGroup.kt | 2 +- .../tachiyomi/ui/library/LibraryPresenter.kt | 11 ++- .../kanade/tachiyomi/ui/main/MainActivity.kt | 14 ++-- .../tachiyomi/ui/webview/WebViewActivity.kt | 8 +- .../drawable/shape_gradient_top_shadow.xml | 7 ++ .../main/res/layout/filter_bottom_sheet.xml | 51 ++++++++---- .../main/res/layout/library_controller.xml | 15 ++++ app/src/main/res/values/strings.xml | 1 + 9 files changed, 154 insertions(+), 35 deletions(-) create mode 100644 app/src/main/res/drawable/shape_gradient_top_shadow.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterBottomSheet.kt index c3fd18ad20..706de172f4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterBottomSheet.kt @@ -38,7 +38,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri private lateinit var categories:FilterTagGroup - val items:List by lazy { + val filterItems:List by lazy { val list = mutableListOf() if (Injekt.get().getCategories().executeAsBlocking().isNotEmpty()) list.add(categories) @@ -53,7 +53,6 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri var onGroupClicked: (Int) -> Unit = { _ -> } val recycler = androidx.recyclerview.widget.RecyclerView(context) var pager:View? = null - var filters = listOf() init { @@ -68,8 +67,16 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri sheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED } } + line.alpha = 0f + + + + sortText.alpha = if (sheetBehavior.state != BottomSheetBehavior.STATE_EXPANDED) 1f else 0f + title.alpha = if (sheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) 1f else 0f + pager = pagerView pager?.setPadding(0, 0, 0, topbar.height) + updateTitle() sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { override fun onSlide(bottomSheet: View, progress: Float) { val minHeight = sheetBehavior.peekHeight @@ -77,7 +84,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri val percent = (progress * 100).roundToInt() val value = (percent * (maxHeight - minHeight) / 100) + minHeight pager?.setPadding(0, 0, 0, value) - line.alpha = 1 - progress + sortText.alpha = 1 - progress + title.alpha = progress + //line.alpha = 1 - progress } override fun onStateChanged(p0: View, p1: Int) { @@ -93,6 +102,64 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri createTags() } + fun updateTitle() { + val filters = getFilters().toMutableList() + if (filters.isEmpty()) { + sortText.text = context.getString( + R.string.sorting_by_, context.getString( + when (preferences.librarySortingMode().getOrDefault()) { + LibrarySort.LAST_UPDATED -> R.string.action_sort_last_updated + LibrarySort.DRAG_AND_DROP -> R.string.action_sort_drag_and_drop + LibrarySort.TOTAL -> R.string.action_sort_total + LibrarySort.UNREAD -> R.string.action_filter_unread + LibrarySort.LAST_READ -> R.string.action_sort_last_read + else -> R.string.title + } + ) + ) + } + else { + filters.add(0, when (preferences.librarySortingMode().getOrDefault()) { + LibrarySort.LAST_UPDATED -> R.string.action_sort_last_updated + LibrarySort.DRAG_AND_DROP -> R.string.action_sort_drag_and_drop + LibrarySort.TOTAL -> R.string.action_sort_total + LibrarySort.UNREAD -> R.string.action_filter_unread + LibrarySort.LAST_READ -> R.string.action_sort_last_read + else -> R.string.action_sort_alpha + }) + sortText.text = filters.joinToString(", ") { context.getString(it) } + } + } + + fun getFilters(): List { + val filters = mutableListOf() + var filter = preferences.filterDownloaded().getOrDefault() + if (filter > 0) { + filters.add(if (filter == 1) R.string.action_filter_downloaded else R.string + .action_filter_not_downloaded) + } + filter = preferences.filterCompleted().getOrDefault() + if (filter > 0) { + filters.add(if (filter == 1) R.string.completed else R.string + .ongoing) + } + filter = preferences.filterUnread().getOrDefault() + if (filter > 0) { + filters.add(when (filter) { + 3 -> R.string.action_filter_read + 2 -> R.string.action_filter_in_progress + else -> R.string.action_filter_not_started + }) + } + filter = preferences.filterTracked().getOrDefault() + if (filter > 0) { + filters.add(if (filter == 1) R.string.action_filter_tracked else R.string + .action_filter_not_tracked) + } + return filters + } + + fun createTags() { categories = inflate(R.layout.filter_buttons) as FilterTagGroup categories.setup(this, R.string.categories) @@ -120,15 +187,15 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri tracked.onItemClicked = { view, index -> onFilterClicked(view, index) } tracked.setState(preferences.filterTracked()) - items.forEach { + filterItems.forEach { filterLayout.addView(it) } } private fun onFilterClicked(view: View, index: Int) { - val transition = AutoTransition() + /*val transition = AutoTransition() transition.duration = 150 - TransitionManager.beginDelayedTransition(this, transition) + TransitionManager.beginDelayedTransition(this, transition)*/ /*f (index > -1) { filterScrollView.scrollX = 0 filterLayout.removeView(view) @@ -160,6 +227,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri onGroupClicked(ACTION_FILTER) } } + updateTitle() } companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterTagGroup.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterTagGroup.kt index 2a7a273769..0203e52aef 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterTagGroup.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/FilterTagGroup.kt @@ -61,7 +61,7 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute fun setState(preference: Preference) { val index = preference.getOrDefault() - 1 - if (index > 1) + if (index > -1) toggleButton(index) } 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 cc9bc9c424..d5fe4078c8 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 @@ -139,14 +139,19 @@ class LibraryPresenter( val filterTracked = preferences.filterTracked().getOrDefault() + val lastReadManga by lazy { + db.getLastReadManga().executeAsBlocking() + } + val filterFn: (LibraryItem) -> Boolean = f@ { item -> // Filter when there isn't unread chapters. if (MainActivity.bottomNav) { if (filterUnread == STATE_INCLUDE && - (item.manga.unread == 0 || db.getChapters(item.manga).executeAsBlocking() - .size != item.manga.unread)) return@f false + (item.manga.unread == 0 || lastReadManga.find { it.id == item.manga.id } == + null)) return@f false if (filterUnread == STATE_EXCLUDE && - (item.manga.unread == 0 || db.getChapters(item.manga).executeAsBlocking().size == item.manga.unread)) return@f false + (item.manga.unread == 0 || lastReadManga.find { it.id == item.manga.id } != + null)) return@f false if (filterUnread == STATE_REALLY_EXCLUDE && item.manga.unread > 0) return@f false } else { 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 66a86b2b49..cd08a95505 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 @@ -112,15 +112,13 @@ open class MainActivity : BaseActivity() { lateinit var tabAnimator: TabsAnimator override fun onCreate(savedInstanceState: Bundle?) { - if (preferences.theme() in 1..4) { - 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) + 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") + } if (trulyGoBack) return // Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079 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 f4e41301e4..f1fb4b9aaa 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 @@ -14,6 +14,7 @@ import android.view.ViewGroup import android.webkit.WebChromeClient import android.webkit.WebView import android.widget.LinearLayout +import androidx.appcompat.app.AppCompatDelegate import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils import eu.kanade.tachiyomi.R @@ -55,6 +56,11 @@ class WebViewActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + delegate.localNightMode = when (preferences.theme()) { + 1, 8 -> AppCompatDelegate.MODE_NIGHT_NO + 2, 3, 4 -> AppCompatDelegate.MODE_NIGHT_YES + else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + } setContentView(R.layout.webview_activity) title = intent.extras?.getString(TITLE_KEY) setSupportActionBar(toolbar) @@ -188,7 +194,7 @@ class WebViewActivity : BaseActivity() { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) - val currentNightMode = newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK + val currentNightMode = resources.configuration.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)) diff --git a/app/src/main/res/drawable/shape_gradient_top_shadow.xml b/app/src/main/res/drawable/shape_gradient_top_shadow.xml new file mode 100644 index 0000000000..8b67330a76 --- /dev/null +++ b/app/src/main/res/drawable/shape_gradient_top_shadow.xml @@ -0,0 +1,7 @@ + + + + \ 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 5a817ffed2..0e2c1f8f73 100644 --- a/app/src/main/res/layout/filter_bottom_sheet.xml +++ b/app/src/main/res/layout/filter_bottom_sheet.xml @@ -17,27 +17,43 @@ android:id="@+id/topbar" android:background="?android:attr/colorPrimary"> - + app:layout_constraintBottom_toBottomOf="@+id/sortText" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@+id/sortText" /> + + + + + app:layout_constraintTop_toBottomOf="@+id/sortText" /> @@ -67,6 +83,9 @@ android:id="@+id/filterScrollView" android:layout_width="fill_parent" android:scrollbars="none" + android:paddingStart="20dp" + android:paddingEnd="20dp" + android:clipToPadding="false" android:layout_height="wrap_content"> + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 935ae32b48..9fbdfd9873 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -44,6 +44,7 @@ Tracked Not tracked + Sorting by %1$s Remove filter Alphabetically Enabled