From d6a83ed3e09a52e2fe1fb9c0d5b20ed80d2d701e Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Fri, 2 Aug 2019 16:35:36 +0800 Subject: [PATCH 1/3] update --- .../app/ui/sourcedebug/SourceDebugActivity.kt | 15 ++++++--------- .../legado/app/ui/sourcedebug/SourceDebugModel.kt | 8 +++++++- 2 files changed, 13 insertions(+), 10 deletions(-) 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 609689873..a70924bed 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 @@ -28,6 +28,12 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s viewModel.init(intent.getStringExtra("key")) initRecyclerView() initSearchView() + viewModel.observe{state, msg-> + adapter.addItem(msg) + if (state == -1 || state == 1000) { + rotate_loading.hide() + } + } } private fun initRecyclerView() { @@ -64,13 +70,4 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s toast("未获取到书源") }) } - - override fun observeLiveBus() { - observeEvent(Bus.SOURCE_DEBUG_LOG) { - adapter.addItem(it.obj as String) - if (it.what == -1 || it.what == 1000) { - rotate_loading.hide() - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt index df76cda3b..e5c800b20 100644 --- a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt @@ -13,6 +13,8 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S private var webBook: WebBook? = null + private var callback: ((Int, String)-> Unit)? = null + fun init(sourceUrl: String?) { sourceUrl?.let { //优先使用这个,不会抛出异常 @@ -23,6 +25,10 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S } } + fun observe(callback: (Int, String)-> Unit){ + this.callback = callback + } + fun startDebug(key: String, start: (() -> Unit)? = null, error: (() -> Unit)? = null) { webBook?.let { start?.invoke() @@ -31,7 +37,7 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S } override fun printLog(state: Int, msg: String) { - postEvent(Bus.SOURCE_DEBUG_LOG, EventMessage.obtain(state, msg)) + callback?.invoke(state, msg) } override fun onCleared() { From d6b249f823e6c6c5113b37a20362829ef4f185db Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Fri, 2 Aug 2019 16:38:25 +0800 Subject: [PATCH 2/3] update --- .../io/legado/app/ui/main/my/MyFragment.kt | 6 +- .../java/io/legado/app/ui/widget/PageView.kt | 77 +++++++++++++++++++ .../io/legado/app/utils/FragmentExtensions.kt | 23 +++++- .../io/legado/app/utils/ViewExtensions.kt | 2 +- app/src/main/res/layout/activity_read.xml | 16 +++- 5 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/PageView.kt diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 92b27f3ed..5c23674e2 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -6,9 +6,9 @@ import android.view.MenuItem import android.view.View import io.legado.app.R import io.legado.app.base.BaseFragment -import io.legado.app.ui.search.SearchActivity +import io.legado.app.ui.read.ReadActivity +import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.view_title_bar.* -import org.jetbrains.anko.startActivity class MyFragment : BaseFragment(R.layout.fragment_my_config) { @@ -26,7 +26,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onCompatOptionsItemSelected(item: MenuItem) { when (item.itemId) { - R.id.action_settings -> requireContext().startActivity() + R.id.action_settings -> startActivity() } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/PageView.kt new file mode 100644 index 000000000..7844f7e3f --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/PageView.kt @@ -0,0 +1,77 @@ +package io.legado.app.ui.widget + +import android.content.Context +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Rect +import android.graphics.drawable.GradientDrawable +import android.util.AttributeSet +import android.util.Log +import android.view.MotionEvent +import androidx.appcompat.widget.AppCompatTextView +import io.legado.app.utils.screenshot +import kotlin.math.abs + +class PageView(context: Context, attrs: AttributeSet) : AppCompatTextView(context, attrs) { + + private var bitmap: Bitmap? = null + + 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 + + init { + val shadowColors = intArrayOf(0x66111111, 0x00000000) + shadowDrawable = GradientDrawable( + GradientDrawable.Orientation.LEFT_RIGHT, shadowColors + ) + shadowDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT + } + + override fun onDraw(canvas: Canvas?) { + canvas?.save() + super.onDraw(canvas) + canvas?.restore() + + + bitmap?.let { + srcRect.set(0, 0, width, height) + destRect.set(-width + offset.toInt(), 0, offset.toInt(), height) + canvas?.drawBitmap(it, srcRect, destRect, null) + addShadow(offset.toInt(), canvas) + } + } + + //添加阴影 + private fun addShadow(left: Int, canvas: Canvas?) { + canvas?.let { + shadowDrawable.setBounds(left, 0, left + 30, height) + shadowDrawable.draw(it) + } + } + + override fun onTouchEvent(event: MotionEvent?): Boolean { + when (event?.action) { + MotionEvent.ACTION_DOWN -> { + bitmap = screenshot() + Log.e("TAG", "bitmap == null: " + (bitmap == null)) + downX = event.x + offset = 0.toFloat() + invalidate() + } + MotionEvent.ACTION_MOVE -> { + offset = abs(event.x - downX) + invalidate() + } + MotionEvent.ACTION_UP -> { + bitmap = null + invalidate() + } + } + + return true + } +} diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index c81c734ad..f233929fb 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -1,5 +1,8 @@ package io.legado.app.utils +import android.app.Activity +import android.app.Service +import android.content.Intent import android.content.res.ColorStateList import android.graphics.drawable.Drawable import androidx.annotation.ColorRes @@ -8,6 +11,7 @@ import androidx.core.content.edit import androidx.fragment.app.Fragment import org.jetbrains.anko.connectivityManager import org.jetbrains.anko.defaultSharedPreferences +import org.jetbrains.anko.internals.AnkoInternals fun Fragment.isOnline() = requireContext().connectivityManager.activeNetworkInfo?.isConnected == true @@ -54,4 +58,21 @@ val Fragment.isNightTheme: Boolean get() = getPrefBoolean("isNightTheme") val Fragment.isTransparentStatusBar: Boolean - get() = getPrefBoolean("transparentStatusBar") \ No newline at end of file + get() = getPrefBoolean("transparentStatusBar") + + +inline fun Fragment.startActivity(vararg params: Pair) = + AnkoInternals.internalStartActivity(requireActivity(), T::class.java, params) + + +inline fun Fragment.startActivityForResult(requestCode: Int, vararg params: Pair) = + startActivityForResult(AnkoInternals.createIntent(requireActivity(), T::class.java, params), requestCode) + +inline fun Fragment.startService(vararg params: Pair) = + AnkoInternals.internalStartService(requireActivity(), T::class.java, params) + +inline fun Fragment.stopService(vararg params: Pair) = + AnkoInternals.internalStopService(requireActivity(), T::class.java, params) + +inline fun Fragment.intentFor(vararg params: Pair): Intent = + AnkoInternals.createIntent(requireActivity(), T::class.java, params) \ No newline at end of file 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 50944d224..cbde9e3f1 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -55,7 +55,7 @@ fun View.visible() { fun View.screenshot(): Bitmap? { return runCatching { - val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565) + val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) val c = Canvas(screenshot) c.translate(-scrollX.toFloat(), -scrollY.toFloat()) draw(c) diff --git a/app/src/main/res/layout/activity_read.xml b/app/src/main/res/layout/activity_read.xml index d829e291c..fc9704d8b 100644 --- a/app/src/main/res/layout/activity_read.xml +++ b/app/src/main/res/layout/activity_read.xml @@ -1,7 +1,17 @@ + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + \ No newline at end of file From 461f5ec6d652a990ea6c90227edf8b933758713c Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Fri, 2 Aug 2019 16:39:24 +0800 Subject: [PATCH 3/3] update --- .../io/legado/app/ui/sourcedebug/SourceDebugActivity.kt | 6 ++++++ 1 file changed, 6 insertions(+) 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 1e0cd7fef..0dda06020 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 @@ -31,6 +31,12 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s viewModel.init(intent.getStringExtra("key")) initRecyclerView() initSearchView() + viewModel.observe{state, msg-> + adapter.addItem(msg) + if (state == -1 || state == 1000) { + rotate_loading.hide() + } + } } private fun initRecyclerView() {