From e3751011324da031384621e09ebd03d9f39d6a04 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 22 Oct 2016 21:42:48 +0200 Subject: [PATCH] Revert "Support API 25. Use new DividerItemDecoration." This reverts commit 05b14bae7be1df4ddfe457a86fc40f6f0ec5191a. --- app/build.gradle | 8 +- .../ui/catalogue/CatalogueFragment.kt | 11 ++- .../ui/manga/chapter/ChaptersFragment.kt | 6 +- .../recent_updates/RecentChaptersFragment.kt | 5 +- .../tachiyomi/widget/DividerItemDecoration.kt | 83 +++++++++++++++++++ app/src/main/res/values/attrs.xml | 5 +- app/src/main/res/values/themes.xml | 4 +- build.gradle | 2 +- 8 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/DividerItemDecoration.kt diff --git a/app/build.gradle b/app/build.gradle index c8837dc5da..5355e7f6af 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,14 +33,14 @@ def includeUpdater() { } android { - compileSdkVersion 25 - buildToolsVersion "25.0.0" + compileSdkVersion 24 + buildToolsVersion "24.0.2" publishNonDefault true defaultConfig { applicationId "eu.kanade.tachiyomi" minSdkVersion 16 - targetSdkVersion 25 + targetSdkVersion 24 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" versionCode 12 versionName "0.3.1" @@ -97,7 +97,7 @@ dependencies { compile 'com.github.inorichi:ReactiveNetwork:69092ed' // Android support library - final support_library_version = '25.0.0' + final support_library_version = '24.2.1' compile "com.android.support:support-v4:$support_library_version" compile "com.android.support:appcompat-v7:$support_library_version" compile "com.android.support:cardview-v7:$support_library_version" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt index 5fc11962c9..f9c37e2b78 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt @@ -3,7 +3,10 @@ package eu.kanade.tachiyomi.ui.catalogue import android.content.res.Configuration import android.os.Bundle import android.support.design.widget.Snackbar -import android.support.v7.widget.* +import android.support.v7.widget.GridLayoutManager +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.SearchView +import android.support.v7.widget.Toolbar import android.view.* import android.view.animation.AnimationUtils import android.widget.ArrayAdapter @@ -18,8 +21,10 @@ import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaActivity +import eu.kanade.tachiyomi.util.getResourceDrawable import eu.kanade.tachiyomi.util.snack import eu.kanade.tachiyomi.util.toast +import eu.kanade.tachiyomi.widget.DividerItemDecoration import eu.kanade.tachiyomi.widget.EndlessScrollListener import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener import kotlinx.android.synthetic.main.fragment_catalogue.* @@ -144,7 +149,9 @@ open class CatalogueFragment : BaseRxFragment(), FlexibleVie catalogue_list.adapter = adapter catalogue_list.layoutManager = llm catalogue_list.addOnScrollListener(listScrollListener) - catalogue_list.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL)) + catalogue_list.addItemDecoration( + DividerItemDecoration(context.theme.getResourceDrawable(R.attr.divider_drawable))) + if (presenter.isListMode) { switcher.showNext() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt index fdf5a0747f..318beec435 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt @@ -6,7 +6,6 @@ import android.content.Intent import android.os.Bundle import android.support.v4.app.DialogFragment import android.support.v7.view.ActionMode -import android.support.v7.widget.DividerItemDecoration import android.support.v7.widget.LinearLayoutManager import android.view.* import com.afollestad.materialdialogs.MaterialDialog @@ -20,8 +19,10 @@ import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment import eu.kanade.tachiyomi.ui.manga.MangaActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.getCoordinates +import eu.kanade.tachiyomi.util.getResourceDrawable import eu.kanade.tachiyomi.util.toast import eu.kanade.tachiyomi.widget.DeletingChaptersDialog +import eu.kanade.tachiyomi.widget.DividerItemDecoration import kotlinx.android.synthetic.main.fragment_manga_chapters.* import nucleus.factory.RequiresPresenter import timber.log.Timber @@ -66,7 +67,8 @@ class ChaptersFragment : BaseRxFragment(), ActionMode.Callbac recycler.adapter = adapter recycler.layoutManager = LinearLayoutManager(activity) - recycler.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL)) + recycler.addItemDecoration(DividerItemDecoration( + context.theme.getResourceDrawable(R.attr.divider_drawable))) recycler.setHasFixedSize(true) swipe_refresh.setOnRefreshListener { fetchChapters() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt index d3a6a325cc..c59cd7f71d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.recent_updates import android.os.Bundle import android.support.v4.app.DialogFragment import android.support.v7.view.ActionMode -import android.support.v7.widget.DividerItemDecoration import android.support.v7.widget.LinearLayoutManager import android.view.* import com.afollestad.materialdialogs.MaterialDialog @@ -14,7 +13,9 @@ import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity +import eu.kanade.tachiyomi.util.getResourceDrawable import eu.kanade.tachiyomi.widget.DeletingChaptersDialog +import eu.kanade.tachiyomi.widget.DividerItemDecoration import kotlinx.android.synthetic.main.fragment_recent_chapters.* import nucleus.factory.RequiresPresenter import timber.log.Timber @@ -68,7 +69,7 @@ class RecentChaptersFragment override fun onViewCreated(view: View, savedState: Bundle?) { // Init RecyclerView and adapter recycler.layoutManager = LinearLayoutManager(activity) - recycler.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL)) + recycler.addItemDecoration(DividerItemDecoration(context.theme.getResourceDrawable(R.attr.divider_drawable))) recycler.setHasFixedSize(true) adapter = RecentChaptersAdapter(this) recycler.adapter = adapter diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/DividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/DividerItemDecoration.kt new file mode 100644 index 0000000000..d752ac6fb4 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/DividerItemDecoration.kt @@ -0,0 +1,83 @@ +package eu.kanade.tachiyomi.widget + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Rect +import android.graphics.drawable.Drawable +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.util.AttributeSet +import android.view.View + +class DividerItemDecoration : RecyclerView.ItemDecoration { + + private val divider: Drawable? + + constructor(context: Context, attrs: AttributeSet) { + val a = context.obtainStyledAttributes(attrs, intArrayOf(android.R.attr.listDivider)) + divider = a.getDrawable(0) + a.recycle() + } + + constructor(divider: Drawable) { + this.divider = divider + } + + override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) { + super.getItemOffsets(outRect, view, parent, state) + if (divider == null) return + if (parent.getChildPosition(view) < 1) return + + if (getOrientation(parent) == LinearLayoutManager.VERTICAL) + outRect.top = divider.intrinsicHeight + else + outRect.left = divider.intrinsicWidth + } + + override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State?) { + if (divider == null) { + super.onDrawOver(c, parent, state) + return + } + + if (getOrientation(parent) == LinearLayoutManager.VERTICAL) { + val left = parent.paddingLeft + val right = parent.width - parent.paddingRight + val childCount = parent.childCount + val dividerHeight = divider.intrinsicHeight + + for (i in 1..childCount - 1) { + val child = parent.getChildAt(i) + val params = child.layoutParams as RecyclerView.LayoutParams + val ty = (child.translationY + 0.5f).toInt() + val top = child.top - params.topMargin + ty + val bottom = top + dividerHeight + divider.setBounds(left, top, right, bottom) + divider.draw(c) + } + } else { //horizontal + val top = parent.paddingTop + val bottom = parent.height - parent.paddingBottom + val childCount = parent.childCount + + for (i in 1..childCount - 1) { + val child = parent.getChildAt(i) + val params = child.layoutParams as RecyclerView.LayoutParams + val size = divider.intrinsicWidth + val left = child.left - params.leftMargin + val right = left + size + divider.setBounds(left, top, right, bottom) + divider.draw(c) + } + } + } + + private fun getOrientation(parent: RecyclerView): Int { + if (parent.layoutManager is LinearLayoutManager) { + val layoutManager = parent.layoutManager as LinearLayoutManager + return layoutManager.orientation + } else + throw IllegalStateException("DividerItemDecoration can only be used with a LinearLayoutManager.") + } + +} \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 3d4b09c757..0d37df9c39 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -1,11 +1,13 @@ - + + @@ -23,6 +25,7 @@ + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 3039d40b8c..bbf56979d1 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -22,7 +22,6 @@ @color/backgroundLight ?colorAccent @color/dividerLight - @drawable/line_divider_light true @@ -34,6 +33,7 @@ @drawable/list_item_selector_light @drawable/library_item_selector_light + @drawable/line_divider_light @color/textColorPrimaryLight @color/dialogLight ?colorAccent @@ -60,7 +60,6 @@ @color/backgroundDark ?colorAccent @color/dividerDark - @drawable/line_divider_dark true @@ -74,6 +73,7 @@ @style/Theme.Widget.NavigationView.Dark @drawable/list_item_selector_dark @drawable/library_item_selector_dark + @drawable/line_divider_dark @color/textColorPrimaryDark @color/dialogDark ?colorAccent diff --git a/build.gradle b/build.gradle index 5995e49e83..8cdddff216 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' + classpath 'com.android.tools.build:gradle:2.2.1' classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files