From 5fc1808f292102dc444444f5a6b81dd4683a077b Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Thu, 8 Aug 2019 14:15:04 +0800 Subject: [PATCH] update --- .../app/ui/booksource/BookSourceActivity.kt | 2 +- .../app/ui/chapterlist/ChapterListActivity.kt | 1 + .../ui/main/bookshelf/BookshelfFragment.kt | 12 +-- .../io/legado/app/ui/search/SearchActivity.kt | 3 +- .../app/ui/sourcedebug/SourceDebugActivity.kt | 2 +- .../java/io/legado/app/ui/widget/TitleBar.kt | 8 +- .../io/legado/app/ui/widget/page/PageView.kt | 99 +++++++++++++++---- .../io/legado/app/utils/ViewExtensions.kt | 2 +- .../main/res/layout/activity_book_source.xml | 13 +-- .../main/res/layout/activity_chapter_list.xml | 20 ++-- app/src/main/res/layout/activity_search.xml | 1 + .../main/res/layout/activity_source_debug.xml | 1 + .../{page_view.xml => view_book_page.xml} | 3 +- app/src/main/res/layout/view_search.xml | 10 ++ app/src/main/res/layout/view_tab_layout.xml | 7 ++ app/src/main/res/layout/view_title_bar.xml | 18 +--- app/src/main/res/values/attrs.xml | 1 + 17 files changed, 138 insertions(+), 65 deletions(-) rename app/src/main/res/layout/{page_view.xml => view_book_page.xml} (63%) create mode 100644 app/src/main/res/layout/view_search.xml create mode 100644 app/src/main/res/layout/view_tab_layout.xml diff --git a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt index fd849ad63..36305d870 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt @@ -23,6 +23,7 @@ import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.sourceedit.SourceEditActivity import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_book_source.* +import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch @@ -93,7 +94,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } private fun initSearchView() { - search_view.visibility = View.VISIBLE search_view.onActionViewExpanded() search_view.queryHint = getString(R.string.search_book_source) search_view.clearFocus() diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index 3d379ac41..b253d5c72 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -12,6 +12,7 @@ import io.legado.app.base.BaseActivity import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_chapter_list.* +import kotlinx.android.synthetic.main.view_tab_layout.* import kotlinx.android.synthetic.main.view_title_bar.* class ChapterListActivity : BaseActivity(R.layout.activity_chapter_list) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 814947fe2..5ff3135a8 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -29,6 +29,7 @@ import io.legado.app.ui.search.SearchActivity import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_edittext.view.* import kotlinx.android.synthetic.main.fragment_bookshelf.* +import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.textColor @@ -66,12 +67,11 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b } private fun initSearchView() { - search_view.visible() - search_view.onActionViewExpanded() - search_view.isSubmitButtonEnabled = true - search_view.queryHint = getString(R.string.search_book_key) - search_view.clearFocus() - search_view.setOnQueryTextListener(this) +// search_view.onActionViewExpanded() +// search_view.isSubmitButtonEnabled = true +// search_view.queryHint = getString(R.string.search_book_key) +// search_view.clearFocus() +// search_view.setOnQueryTextListener(this) } private fun initRecyclerView() { diff --git a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt index 74a51d172..1730b9d34 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt @@ -15,7 +15,7 @@ import io.legado.app.data.entities.SearchShow import io.legado.app.lib.theme.ATH import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_search.* -import kotlinx.android.synthetic.main.view_title_bar.* +import kotlinx.android.synthetic.main.view_search.* class SearchActivity : VMBaseActivity(R.layout.activity_search) { @@ -32,7 +32,6 @@ class SearchActivity : VMBaseActivity(R.layout.activity_search) } private fun initSearchView() { - search_view.visibility = View.VISIBLE search_view.onActionViewExpanded() search_view.isSubmitButtonEnabled = true search_view.queryHint = getString(R.string.search_book_key) diff --git a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt index 80f7df36d..2290654e4 100644 --- a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt @@ -14,6 +14,7 @@ import io.legado.app.lib.theme.accentColor import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_source_debug.* +import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.coroutines.launch import org.jetbrains.anko.startActivityForResult @@ -50,7 +51,6 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s } private fun initSearchView() { - search_view.visibility = View.VISIBLE search_view.onActionViewExpanded() search_view.isSubmitButtonEnabled = true search_view.queryHint = getString(R.string.search_book_key) diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 631356af0..7e57837b4 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -10,7 +10,6 @@ import android.view.Menu import android.view.View import androidx.annotation.ColorInt import androidx.annotation.StyleRes -import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.core.graphics.drawable.DrawableCompat import com.google.android.material.appbar.AppBarLayout @@ -126,6 +125,9 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a this.subtitle = subtitleText } + if (a.hasValue(R.styleable.TitleBar_contentLayout)) { + inflate(context, a.getResourceId(R.styleable.TitleBar_contentLayout, 0), this) + } } if (a.getBoolean(R.styleable.TitleBar_fitStatusBar, true)) { @@ -146,7 +148,7 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a if (attachToActivity) { attachToActivity() } - wrapAppTheme() + wrapTheme() } fun setNavigationOnClickListener(clickListener: ((View) -> Unit)) { @@ -177,7 +179,7 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a toolbar.setSubtitleTextAppearance(context, resId) } - private fun wrapAppTheme() { + private fun wrapTheme() { val primaryTextColor = if (isInEditMode) Color.BLACK else context.primaryTextColor DrawableUtils.setTint(toolbar.overflowIcon, primaryTextColor) toolbar.setTitleTextColor(primaryTextColor) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 2ff709124..353087726 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -1,19 +1,17 @@ package io.legado.app.ui.widget.page import android.content.Context -import android.graphics.Bitmap -import android.graphics.Canvas -import android.graphics.Rect +import android.graphics.* import android.graphics.drawable.GradientDrawable import android.util.AttributeSet -import android.util.Log import android.view.MotionEvent -import android.view.View import android.widget.FrameLayout -import androidx.appcompat.widget.AppCompatTextView import io.legado.app.R +import io.legado.app.utils.dp import io.legado.app.utils.screenshot -import kotlin.math.abs +import kotlinx.android.synthetic.main.view_book_page.view.* +import org.jetbrains.anko.backgroundColor +import org.jetbrains.anko.horizontalPadding class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) { @@ -22,34 +20,99 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att private var downX: Float = 0.toFloat() private var offset: Float = 0.toFloat() - private val srcRect: Rect = Rect() - private val destRect: Rect = Rect() - private val shadowDrawable: GradientDrawable + private val shadowDrawableR: GradientDrawable + private val shadowDrawableL: GradientDrawable + + private val bitmapMatrix = Matrix() + + private var cover: Boolean = true init { val shadowColors = intArrayOf(0x66111111, 0x00000000) - shadowDrawable = GradientDrawable( + shadowDrawableR = GradientDrawable( GradientDrawable.Orientation.LEFT_RIGHT, shadowColors ) - shadowDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT + shadowDrawableR.gradientType = GradientDrawable.LINEAR_GRADIENT + + shadowDrawableL = GradientDrawable( + GradientDrawable.Orientation.RIGHT_LEFT, shadowColors + ) + shadowDrawableL.gradientType = GradientDrawable.LINEAR_GRADIENT + + inflate(context, R.layout.view_book_page, this) + + setWillNotDraw(false) + + page_panel.backgroundColor = Color.WHITE + + page_panel.horizontalPadding = 16.dp - inflate(context, R.layout.page_view, this) } - override fun onDraw(canvas: Canvas?) { - canvas?.save() - super.onDraw(canvas) - canvas?.restore() + override fun dispatchDraw(canvas: Canvas?) { + super.dispatchDraw(canvas) + + bitmap?.let { + val dx = if (offset > 0) offset - width else offset + width + bitmapMatrix.setTranslate(dx, 0.toFloat()) + canvas?.drawBitmap(it, bitmapMatrix, null) + + if (cover) { + addShadow(dx.toInt(), canvas) + } + } + } + private fun addShadow(left: Int, canvas: Canvas?) { + canvas?.let { + if (left < 0) { + shadowDrawableR.setBounds(left + width, 0, left+ width + 30, height) + shadowDrawableR.draw(it) + } else { + shadowDrawableL.setBounds(left - 30, 0, left, height) + shadowDrawableL.draw(it) + } + } } override fun onTouchEvent(event: MotionEvent?): Boolean { + when (event?.action) { + MotionEvent.ACTION_DOWN -> { + bitmap = page_panel.screenshot() + downX = event.x + offset = 0.toFloat() + if (!cover) { + page_panel.translationX = 0.toFloat() + } + invalidate() + } + MotionEvent.ACTION_MOVE -> { + offset = event.x - downX + if (!cover) { + page_panel.translationX = offset + } + invalidate() + } + + MotionEvent.ACTION_UP -> { + bitmap = null + if (!cover) { + page_panel.translationX = 0.toFloat() + } + invalidate() + } + } return true } - fun setPageFactory(factory: PageFactory<*>){ + fun setTranslate(translationX: Float, translationY: Float) { + page_panel.translationX = translationX + page_panel.translationY = translationY + } + + fun setPageFactory(factory: PageFactory<*>) { } } diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index cbde9e3f1..1c7fb29c3 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -28,7 +28,7 @@ private tailrec fun getCompatActivity(context: Context?): AppCompatActivity? { val View.activity: AppCompatActivity? get() = getCompatActivity(context) -fun View.hideSoftInput() = run { +inline fun View.hideSoftInput() = run { val imm = App.INSTANCE.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager imm?.let { imm.hideSoftInputFromWindow(this.windowToken, 0) diff --git a/app/src/main/res/layout/activity_book_source.xml b/app/src/main/res/layout/activity_book_source.xml index 8297c7268..e884787c0 100644 --- a/app/src/main/res/layout/activity_book_source.xml +++ b/app/src/main/res/layout/activity_book_source.xml @@ -11,16 +11,17 @@ android:layout_height="wrap_content" app:contentInsetStartWithNavigation="0dp" app:displayHomeAsUp="true" - app:title="@string/book_source"/> + app:title="@string/book_source" + app:contentLayout="@layout/view_search"/> + android:layout_width="match_parent" + android:layout_height="match_parent"> + android:id="@+id/recycler_view" + android:layout_width="match_parent" + android:layout_height="match_parent"/> diff --git a/app/src/main/res/layout/activity_chapter_list.xml b/app/src/main/res/layout/activity_chapter_list.xml index 94bb27054..159f77324 100644 --- a/app/src/main/res/layout/activity_chapter_list.xml +++ b/app/src/main/res/layout/activity_chapter_list.xml @@ -1,17 +1,19 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + android:id="@+id/title_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + app:contentLayout="@layout/view_tab_layout"/> + android:id="@+id/view_pager" + android:layout_width="match_parent" + android:layout_height="match_parent"/> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index e330e1565..6f4f88662 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -11,6 +11,7 @@ android:id="@+id/title_bar" android:layout_width="match_parent" android:layout_height="wrap_content" + app:contentLayout="@layout/view_search" app:contentInsetStartWithNavigation="0dp" app:layout_constraintTop_toTopOf="parent" app:title="搜索"/> diff --git a/app/src/main/res/layout/activity_source_debug.xml b/app/src/main/res/layout/activity_source_debug.xml index 4a98208bd..1b79a6058 100644 --- a/app/src/main/res/layout/activity_source_debug.xml +++ b/app/src/main/res/layout/activity_source_debug.xml @@ -10,6 +10,7 @@ android:id="@+id/title_bar" android:layout_width="match_parent" android:layout_height="wrap_content" + app:contentLayout="@layout/view_search" app:layout_constraintTop_toTopOf="parent" app:title="@string/debug_source" /> diff --git a/app/src/main/res/layout/page_view.xml b/app/src/main/res/layout/view_book_page.xml similarity index 63% rename from app/src/main/res/layout/page_view.xml rename to app/src/main/res/layout/view_book_page.xml index fa67d4f81..ec9423495 100644 --- a/app/src/main/res/layout/page_view.xml +++ b/app/src/main/res/layout/view_book_page.xml @@ -24,7 +24,8 @@ + android:layout_height="match_parent" + android:text="233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333"/> + \ No newline at end of file diff --git a/app/src/main/res/layout/view_tab_layout.xml b/app/src/main/res/layout/view_tab_layout.xml new file mode 100644 index 000000000..80cfe13e4 --- /dev/null +++ b/app/src/main/res/layout/view_tab_layout.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_title_bar.xml b/app/src/main/res/layout/view_title_bar.xml index 5200ed5e8..3b7641388 100644 --- a/app/src/main/res/layout/view_title_bar.xml +++ b/app/src/main/res/layout/view_title_bar.xml @@ -5,20 +5,4 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="?attr/actionBarStyle" - app:popupTheme="@style/AppTheme.PopupOverlay"> - - - - - - + app:popupTheme="@style/AppTheme.PopupOverlay"/> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index c782a6e9a..67c52d7c9 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -14,6 +14,7 @@ +