pull/32/head
Administrator 5 years ago
parent e344fe9fb6
commit 5fc1808f29
  1. 2
      app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt
  2. 1
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt
  3. 12
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  4. 3
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  5. 2
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt
  6. 8
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  7. 99
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt
  8. 2
      app/src/main/java/io/legado/app/utils/ViewExtensions.kt
  9. 3
      app/src/main/res/layout/activity_book_source.xml
  10. 6
      app/src/main/res/layout/activity_chapter_list.xml
  11. 1
      app/src/main/res/layout/activity_search.xml
  12. 1
      app/src/main/res/layout/activity_source_debug.xml
  13. 3
      app/src/main/res/layout/view_book_page.xml
  14. 10
      app/src/main/res/layout/view_search.xml
  15. 7
      app/src/main/res/layout/view_tab_layout.xml
  16. 18
      app/src/main/res/layout/view_title_bar.xml
  17. 1
      app/src/main/res/values/attrs.xml

@ -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<BookSourceViewModel>(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()

@ -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) {

@ -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<BookshelfViewModel>(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() {

@ -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<SearchViewModel>(R.layout.activity_search) {
@ -32,7 +32,6 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(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)

@ -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<SourceDebugModel>(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)

@ -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)

@ -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<*>) {
}
}

@ -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)

@ -11,7 +11,8 @@
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"/>
<FrameLayout
android:layout_width="match_parent"

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -7,11 +8,12 @@
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
app:contentLayout="@layout/view_tab_layout"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"/>
</LinearLayout>

@ -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="搜索"/>

@ -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" />

@ -24,7 +24,8 @@
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:text="233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333233333333333333333333333333333333333333333333333333"/>
<androidx.recyclerview.widget.RecyclerView

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.SearchView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/search_view"
android:layout_width="match_parent"
android:theme="?attr/actionBarStyle"
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
app:defaultQueryHint="搜索"/>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.tabs.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="?attr/actionBarStyle"/>

@ -5,20 +5,4 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?attr/actionBarStyle"
app:popupTheme="@style/AppTheme.PopupOverlay">
<androidx.appcompat.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:imeOptions="actionSearch"
app:defaultQueryHint="搜索" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</androidx.appcompat.widget.Toolbar>
app:popupTheme="@style/AppTheme.PopupOverlay"/>

@ -14,6 +14,7 @@
<attr name="contentInsetStartWithNavigation"/>
<attr name="contentInsetLeft"/>
<attr name="contentInsetRight"/>
<attr name="contentLayout" format="reference"/>
<attr name="attachToActivity" format="boolean"/>
<attr name="displayHomeAsUp" format="boolean"/>
<attr name="navigationIcon" format="reference"/>

Loading…
Cancel
Save