From b2ac302c45e987379b46b0ddecd82fd8efcb6b1f Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 27 Sep 2019 14:38:49 +0800 Subject: [PATCH 001/140] up --- .../java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt | 2 +- .../java/io/legado/app/ui/main/bookshelf/BooksFragment.kt | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt index 603684163..d6df919e0 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt @@ -35,7 +35,7 @@ class BooksAdapter(private val callBack: CallBack) : } fun notification(bookUrl: String) { - for (i in 0..itemCount) { + for (i in 0 until itemCount) { getItem(i)?.let { if (it.bookUrl == bookUrl) { notifyItemChanged(i) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt index 4819d288f..47d168562 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment +import io.legado.app.constant.Bus import io.legado.app.data.entities.Book import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor @@ -20,6 +21,7 @@ import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.main.MainViewModel import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModelOfActivity +import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.fragment_books.* import org.jetbrains.anko.startActivity @@ -52,6 +54,9 @@ class BooksFragment : VMBaseFragment(R.layout.fragment_books), } initRecyclerView() upRecyclerData() + observeEvent(Bus.UP_BOOK) { + booksAdapter.notification(it) + } } private fun initRecyclerView() { @@ -70,7 +75,6 @@ class BooksFragment : VMBaseFragment(R.layout.fragment_books), }) booksAdapter = BooksAdapter(this) rv_bookshelf.adapter = booksAdapter - } private fun upRecyclerData() { From bced8f38377f7e5374951d621ed162024dab4449 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 27 Sep 2019 17:51:58 +0800 Subject: [PATCH 002/140] up --- .../java/io/legado/app/help/ReadBookConfig.kt | 37 ++- .../ui/book/read/config/ReadStyleDialog.kt | 2 +- .../legado/app/ui/widget/page/ContentView.kt | 6 +- .../java/io/legado/app/utils/BitmapUtil.kt | 252 ++++++++++++++++++ 4 files changed, 280 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/BitmapUtil.kt diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 915ea9f5a..9238c1341 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -1,6 +1,7 @@ package io.legado.app.help import android.graphics.Color +import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable import io.legado.app.App @@ -52,7 +53,11 @@ object ReadBookConfig { } fun upBg() { - bg = getConfig().bgDrawable() + val resources = App.INSTANCE.resources + val dm = resources.displayMetrics + val width = dm.widthPixels + val height = dm.heightPixels + bg = getConfig().bgDrawable(width, height) } fun save() { @@ -162,20 +167,30 @@ object ReadBookConfig { else bgType } - fun bgDrawable(): Drawable { + fun bgDrawable(width: Int, height: Int): Drawable { var bgDrawable: Drawable? = null - kotlin.runCatching { - when (bgType()) { - 0 -> bgDrawable = ColorDrawable(Color.parseColor(bgStr())) - 1 -> bgDrawable = - Drawable.createFromStream( - App.INSTANCE.assets.open("bg" + File.separator + bgStr()), - "bg" + val resources = App.INSTANCE.resources + try { + bgDrawable = when (bgType()) { + 0 -> ColorDrawable(Color.parseColor(bgStr())) + 1 -> { + BitmapDrawable( + resources, + BitmapUtil.decodeBitmap( + App.INSTANCE, + "bg" + File.separator + bgStr(), + width, + height + ) ) - else -> runCatching { - bgDrawable = Drawable.createFromPath(bgStr()) } + else -> BitmapDrawable( + resources, + BitmapUtil.decodeBitmap(bgStr(), width, height) + ) } + } catch (e: Exception) { + e.printStackTrace() } return bgDrawable ?: ColorDrawable(App.INSTANCE.getCompatColor(R.color.background)) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index ea80392c8..114552bf6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -249,7 +249,7 @@ class ReadStyleDialog : DialogFragment() { ReadBookConfig.getConfig(i).apply { when (bgType()) { 2 -> ImageLoader.load(requireContext(), bgStr()).centerCrop().setAsDrawable(iv) - else -> iv.setImageDrawable(bgDrawable()) + else -> iv.setImageDrawable(bgDrawable(100, 150)) } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt index 719129a03..228e6f2e9 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt @@ -10,7 +10,6 @@ import android.widget.ImageView import androidx.appcompat.widget.AppCompatImageView import io.legado.app.R import io.legado.app.constant.AppConst.TIME_FORMAT -import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_book_page.view.* @@ -90,10 +89,7 @@ class ContentView : FrameLayout { } fun setBg(bg: Drawable?) { - //all supported - ImageLoader.load(context, bg) - .centerCrop() - .setAsDrawable(bgImage) + bgImage.background = bg } fun upTime() { diff --git a/app/src/main/java/io/legado/app/utils/BitmapUtil.kt b/app/src/main/java/io/legado/app/utils/BitmapUtil.kt new file mode 100644 index 000000000..a5c7b776f --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/BitmapUtil.kt @@ -0,0 +1,252 @@ +package io.legado.app.utils + +import android.content.Context +import android.graphics.Bitmap +import android.graphics.Bitmap.Config +import android.graphics.BitmapFactory +import android.graphics.Canvas +import android.renderscript.Allocation +import android.renderscript.Element +import android.renderscript.RenderScript +import android.renderscript.ScriptIntrinsicBlur +import android.view.View +import io.legado.app.App +import java.io.IOException +import kotlin.math.ceil + + +@SuppressWarnings("unused", "WeakerAccess") +object BitmapUtil { + /** + * 从path中获取图片信息,在通过BitmapFactory.decodeFile(String path)方法将突破转成Bitmap时, + * 遇到大一些的图片,我们经常会遇到OOM(Out Of Memory)的问题。所以用到了我们上面提到的BitmapFactory.Options这个类。 + * + * @param path 文件路径 + * @param width 想要显示的图片的宽度 + * @param height 想要显示的图片的高度 + * @return + */ + fun decodeBitmap(path: String, width: Int, height: Int): Bitmap { + val op = BitmapFactory.Options() + // inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight; + op.inJustDecodeBounds = true + BitmapFactory.decodeFile(path, op) //获取尺寸信息 + //获取比例大小 + val wRatio = ceil((op.outWidth / width).toDouble()).toInt() + val hRatio = ceil((op.outHeight / height).toDouble()).toInt() + //如果超出指定大小,则缩小相应的比例 + if (wRatio > 1 && hRatio > 1) { + if (wRatio > hRatio) { + op.inSampleSize = wRatio + } else { + op.inSampleSize = hRatio + } + } + op.inJustDecodeBounds = false + return BitmapFactory.decodeFile(path, op) + } + + /** 从path中获取Bitmap图片 + * @param path 图片路径 + * @return + */ + + fun decodeBitmap(path: String): Bitmap { + val opts = BitmapFactory.Options() + + opts.inJustDecodeBounds = true + BitmapFactory.decodeFile(path, opts) + + opts.inSampleSize = computeSampleSize(opts, -1, 128 * 128) + + opts.inJustDecodeBounds = false + + return BitmapFactory.decodeFile(path, opts) + } + + /** + * 以最省内存的方式读取本地资源的图片 + * @param context 设备上下文 + * @param resId 资源ID + * @return + */ + fun decodeBitmap(context: Context, resId: Int): Bitmap? { + val opt = BitmapFactory.Options() + opt.inPreferredConfig = Config.RGB_565 + //获取资源图片 + val `is` = context.resources.openRawResource(resId) + return BitmapFactory.decodeStream(`is`, null, opt) + } + + /** + * @param context 设备上下文 + * @param resId 资源ID + * @param width + * @param height + * @return + */ + fun decodeBitmap(context: Context, resId: Int, width: Int, height: Int): Bitmap? { + + var inputStream = context.resources.openRawResource(resId) + + val op = BitmapFactory.Options() + // inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight; + op.inJustDecodeBounds = true + BitmapFactory.decodeStream(inputStream, null, op) //获取尺寸信息 + //获取比例大小 + val wRatio = ceil((op.outWidth / width).toDouble()).toInt() + val hRatio = ceil((op.outHeight / height).toDouble()).toInt() + //如果超出指定大小,则缩小相应的比例 + if (wRatio > 1 && hRatio > 1) { + if (wRatio > hRatio) { + op.inSampleSize = wRatio + } else { + op.inSampleSize = hRatio + } + } + inputStream = context.resources.openRawResource(resId) + op.inJustDecodeBounds = false + return BitmapFactory.decodeStream(inputStream, null, op) + } + + /** + * @param context 设备上下文 + * @param fileNameInAssets Assets里面文件的名称 + * @param width 图片的宽度 + * @param height 图片的高度 + * @return Bitmap + * @throws IOException + */ + @Throws(IOException::class) + fun decodeBitmap(context: Context, fileNameInAssets: String, width: Int, height: Int): Bitmap? { + + var inputStream = context.assets.open(fileNameInAssets) + val op = BitmapFactory.Options() + // inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight; + op.inJustDecodeBounds = true + BitmapFactory.decodeStream(inputStream, null, op) //获取尺寸信息 + //获取比例大小 + val wRatio = ceil((op.outWidth / width).toDouble()).toInt() + val hRatio = ceil((op.outHeight / height).toDouble()).toInt() + //如果超出指定大小,则缩小相应的比例 + if (wRatio > 1 && hRatio > 1) { + if (wRatio > hRatio) { + op.inSampleSize = wRatio + } else { + op.inSampleSize = hRatio + } + } + inputStream = context.assets.open(fileNameInAssets) + op.inJustDecodeBounds = false + return BitmapFactory.decodeStream(inputStream, null, op) + } + + + //图片不被压缩 + fun convertViewToBitmap(view: View, bitmapWidth: Int, bitmapHeight: Int): Bitmap { + val bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888) + view.draw(Canvas(bitmap)) + return bitmap + } + + + /** + * @param options + * @param minSideLength + * @param maxNumOfPixels + * @return + * 设置恰当的inSampleSize是解决该问题的关键之一。BitmapFactory.Options提供了另一个成员inJustDecodeBounds。 + * 设置inJustDecodeBounds为true后,decodeFile并不分配空间,但可计算出原始图片的长度和宽度,即opts.width和opts.height。 + * 有了这两个参数,再通过一定的算法,即可得到一个恰当的inSampleSize。 + * 查看Android源码,Android提供了下面这种动态计算的方法。 + */ + fun computeSampleSize( + options: BitmapFactory.Options, + minSideLength: Int, + maxNumOfPixels: Int + ): Int { + + val initialSize = computeInitialSampleSize(options, minSideLength, maxNumOfPixels) + + var roundedSize: Int + + if (initialSize <= 8) { + roundedSize = 1 + while (roundedSize < initialSize) { + roundedSize = roundedSize shl 1 + } + } else { + roundedSize = (initialSize + 7) / 8 * 8 + } + + return roundedSize + } + + + private fun computeInitialSampleSize( + options: BitmapFactory.Options, + minSideLength: Int, + maxNumOfPixels: Int + ): Int { + + val w = options.outWidth.toDouble() + val h = options.outHeight.toDouble() + + val lowerBound = if (maxNumOfPixels == -1) + 1 + else + Math.ceil(Math.sqrt(w * h / maxNumOfPixels)).toInt() + + val upperBound = if (minSideLength == -1) 128 else Math.min( + Math.floor(w / minSideLength), + Math.floor(h / minSideLength) + ).toInt() + + if (upperBound < lowerBound) { + // return the larger one when there is no overlapping zone. + return lowerBound + } + + return if (maxNumOfPixels == -1 && minSideLength == -1) { + 1 + } else if (minSideLength == -1) { + lowerBound + } else { + upperBound + } + } + + /** + * 高斯模糊 + */ + fun stackBlur(srcBitmap: Bitmap?): Bitmap? { + if (srcBitmap == null) return null + val rs = RenderScript.create(App.INSTANCE) + val blurredBitmap = srcBitmap.copy(Config.ARGB_8888, true) + + //分配用于渲染脚本的内存 + val input = Allocation.createFromBitmap( + rs, + blurredBitmap, + Allocation.MipmapControl.MIPMAP_FULL, + Allocation.USAGE_SHARED + ) + val output = Allocation.createTyped(rs, input.type) + + //加载我们想要使用的特定脚本的实例。 + val script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)) + script.setInput(input) + + //设置模糊半径 + script.setRadius(8f) + + //启动 ScriptIntrinsicBlur + script.forEach(output) + + //将输出复制到模糊的位图 + output.copyTo(blurredBitmap) + + return blurredBitmap + } + +} From 0a26d404b05bca83df5b5436599552650df93fbc Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 27 Sep 2019 18:01:11 +0800 Subject: [PATCH 003/140] up --- app/src/main/java/io/legado/app/utils/BitmapUtil.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/BitmapUtil.kt b/app/src/main/java/io/legado/app/utils/BitmapUtil.kt index a5c7b776f..2b72e17db 100644 --- a/app/src/main/java/io/legado/app/utils/BitmapUtil.kt +++ b/app/src/main/java/io/legado/app/utils/BitmapUtil.kt @@ -13,9 +13,12 @@ import android.view.View import io.legado.app.App import java.io.IOException import kotlin.math.ceil +import kotlin.math.floor +import kotlin.math.min +import kotlin.math.sqrt -@SuppressWarnings("unused", "WeakerAccess") +@Suppress("unused", "WeakerAccess") object BitmapUtil { /** * 从path中获取图片信息,在通过BitmapFactory.decodeFile(String path)方法将突破转成Bitmap时, @@ -195,11 +198,11 @@ object BitmapUtil { val lowerBound = if (maxNumOfPixels == -1) 1 else - Math.ceil(Math.sqrt(w * h / maxNumOfPixels)).toInt() + ceil(sqrt(w * h / maxNumOfPixels)).toInt() - val upperBound = if (minSideLength == -1) 128 else Math.min( - Math.floor(w / minSideLength), - Math.floor(h / minSideLength) + val upperBound = if (minSideLength == -1) 128 else min( + floor(w / minSideLength), + floor(h / minSideLength) ).toInt() if (upperBound < lowerBound) { From 8b22086d54596788a1061d4070815c2ee00a0d21 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 27 Sep 2019 22:03:20 +0800 Subject: [PATCH 004/140] up --- app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index dbcc05184..a44cab248 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -312,6 +312,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } private fun curPageChanged() { + seek_read_page.progress = viewModel.durPageIndex when (readAloudStatus) { Status.PLAY -> readAloud() Status.PAUSE -> { From 85cbe43e240f1561f12d05e998d1796d6c2d3ea8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 27 Sep 2019 22:10:32 +0800 Subject: [PATCH 005/140] up --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 2 +- app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index a44cab248..b8bb11427 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -304,7 +304,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea tv_chapter_url.text = it.url tv_chapter_url.visible() } - read_menu.upReadProgress(it.pageSize().minus(1), viewModel.durPageIndex) + seek_read_page.max = it.pageSize().minus(1) tv_pre.isEnabled = viewModel.durChapterIndex != 0 tv_next.isEnabled = viewModel.durChapterIndex != viewModel.chapterSize - 1 curPageChanged() diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index bb321fd65..0aa08497c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -95,11 +95,6 @@ class ReadMenu : FrameLayout { } } - fun upReadProgress(max: Int, dur: Int) { - seek_read_page.max = max - seek_read_page.progress = dur - } - private fun brightnessAuto(): Boolean { return context.getPrefBoolean("brightnessAuto", true) } From 565de5db0744c173801d8f08062852ba459ddb8e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 28 Sep 2019 11:55:10 +0800 Subject: [PATCH 006/140] up --- .../book/source/manage/GroupManageDialog.kt | 1 - .../ui/main/bookshelf/BookshelfViewModel.kt | 11 ++ .../ui/main/bookshelf/GroupManageDialog.kt | 136 ++++++++++++++++++ .../app/ui/replacerule/GroupManageDialog.kt | 1 - app/src/main/res/layout/item_book_group.xml | 8 -- 5 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt delete mode 100644 app/src/main/res/layout/item_book_group.xml diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index 1cdcccd45..59f5e73af 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -29,7 +29,6 @@ import io.legado.app.utils.requestInputMethod import io.legado.app.utils.splitNotBlank import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* -import kotlinx.android.synthetic.main.item_book_group.view.tv_group import kotlinx.android.synthetic.main.item_group_manage.view.* import org.jetbrains.anko.sdk27.listeners.onClick diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 1bb9a3b64..a56a08871 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -20,4 +20,15 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } } + fun addGroup(groupName: String) { + + } + + fun upGroup(bookGroup: BookGroup) { + + } + + fun delGroup(bookGroup: BookGroup) { + + } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt new file mode 100644 index 000000000..d33a62476 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt @@ -0,0 +1,136 @@ +package io.legado.app.ui.main.bookshelf + +import android.annotation.SuppressLint +import android.content.Context +import android.os.Bundle +import android.util.DisplayMetrics +import android.view.LayoutInflater +import android.view.MenuItem +import android.view.View +import android.view.ViewGroup +import android.widget.EditText +import androidx.appcompat.widget.Toolbar +import androidx.fragment.app.DialogFragment +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import io.legado.app.App +import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.data.entities.BookGroup +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.customView +import io.legado.app.lib.dialogs.noButton +import io.legado.app.lib.dialogs.yesButton +import io.legado.app.utils.applyTint +import io.legado.app.utils.getViewModel +import io.legado.app.utils.requestInputMethod +import kotlinx.android.synthetic.main.dialog_edit_text.view.* +import kotlinx.android.synthetic.main.dialog_recycler_view.* +import kotlinx.android.synthetic.main.item_group_manage.view.* +import org.jetbrains.anko.sdk27.listeners.onClick + +class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { + private lateinit var viewModel: BookshelfViewModel + private lateinit var adapter: GroupAdapter + + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.windowManager?.defaultDisplay?.getMetrics(dm) + dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt()) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + viewModel = getViewModel(BookshelfViewModel::class.java) + return inflater.inflate(R.layout.dialog_recycler_view, container) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + initData() + } + + private fun initData() { + tool_bar.title = getString(R.string.group_manage) + tool_bar.inflateMenu(R.menu.group_manage) + tool_bar.menu.applyTint(requireContext(), false) + tool_bar.setOnMenuItemClickListener(this) + adapter = GroupAdapter(requireContext()) + recycler_view.layoutManager = LinearLayoutManager(requireContext()) + recycler_view.addItemDecoration( + DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) + ) + recycler_view.adapter = adapter + App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { + adapter.setItems(it) + }) + } + + override fun onMenuItemClick(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.menu_add -> addGroup() + } + return true + } + + @SuppressLint("InflateParams") + private fun addGroup() { + alert(title = getString(R.string.add_group)) { + var editText: EditText? = null + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view.apply { + hint = "分组名称" + } + } + } + yesButton { + editText?.text?.toString()?.let { + if (it.isNotBlank()) { + viewModel.addGroup(it) + } + } + } + noButton() + }.show().applyTint().requestInputMethod() + } + + @SuppressLint("InflateParams") + private fun editGroup(bookGroup: BookGroup) { + alert(title = getString(R.string.group_edit)) { + var editText: EditText? = null + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view.apply { + hint = "分组名称" + setText(bookGroup.groupName) + } + } + } + yesButton { + viewModel.upGroup(bookGroup.copy(groupName = editText?.text?.toString() ?: "")) + } + noButton() + }.show().applyTint().requestInputMethod() + } + + private inner class GroupAdapter(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_group_manage) { + + override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList) { + with(holder.itemView) { + tv_group.text = item.groupName + tv_edit.onClick { editGroup(item) } + tv_del.onClick { viewModel.delGroup(item) } + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt index 49fb8c3e6..2b2a84835 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt @@ -29,7 +29,6 @@ import io.legado.app.utils.requestInputMethod import io.legado.app.utils.splitNotBlank import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* -import kotlinx.android.synthetic.main.item_book_group.view.tv_group import kotlinx.android.synthetic.main.item_group_manage.view.* import org.jetbrains.anko.sdk27.listeners.onClick diff --git a/app/src/main/res/layout/item_book_group.xml b/app/src/main/res/layout/item_book_group.xml deleted file mode 100644 index 04536bac4..000000000 --- a/app/src/main/res/layout/item_book_group.xml +++ /dev/null @@ -1,8 +0,0 @@ - - \ No newline at end of file From 6fb960f6de5d45c2dbc0639da3bceaca87f0c2b1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 28 Sep 2019 16:13:11 +0800 Subject: [PATCH 007/140] up --- .../ui/main/bookshelf/BookshelfFragment.kt | 36 +++++++------------ app/src/main/res/menu/main_bookshelf.xml | 6 ++++ 2 files changed, 19 insertions(+), 23 deletions(-) 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 b7f91a0af..008ff6131 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 @@ -1,11 +1,9 @@ package io.legado.app.ui.main.bookshelf -import android.annotation.SuppressLint import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View -import android.widget.EditText import androidx.appcompat.widget.SearchView import androidx.lifecycle.LiveData import androidx.lifecycle.Observer @@ -16,11 +14,12 @@ import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.constant.AppConst import io.legado.app.data.entities.BookGroup -import io.legado.app.lib.dialogs.* +import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.search.SearchActivity -import io.legado.app.utils.* -import kotlinx.android.synthetic.main.dialog_edit_text.view.* +import io.legado.app.utils.getViewModel +import io.legado.app.utils.putPrefInt +import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_tab_layout.* import kotlinx.android.synthetic.main.view_title_bar.* @@ -51,6 +50,15 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b when (item.itemId) { R.id.menu_search -> startActivity() R.id.menu_bookshelf_layout -> selectBookshelfLayout() + R.id.menu_group_manage -> fragmentManager?.let { + GroupManageDialog().show(it, "groupManageDialog") + } + R.id.menu_add_local -> { + } + R.id.menu_add_url -> { + } + R.id.menu_arrange_bookshelf -> { + } } } @@ -92,24 +100,6 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b return false } - @SuppressLint("InflateParams") - private fun showGroupInputDialog() { - alert(title = "新建分组") { - var editText: EditText? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = edit_view.apply { - hint = "分组名称" - } - } - } - yesButton { - viewModel.saveBookGroup(editText?.text?.toString()) - } - noButton() - }.show().applyTint().requestInputMethod() - } - private fun selectBookshelfLayout() { selector( title = "选择书架布局", diff --git a/app/src/main/res/menu/main_bookshelf.xml b/app/src/main/res/menu/main_bookshelf.xml index 19bbbdb7f..45b586ca8 100644 --- a/app/src/main/res/menu/main_bookshelf.xml +++ b/app/src/main/res/menu/main_bookshelf.xml @@ -26,6 +26,12 @@ android:title="@string/download_all" app:showAsAction="never" /> + + Date: Sat, 28 Sep 2019 17:00:53 +0800 Subject: [PATCH 008/140] up --- .../io/legado/app/data/dao/BookGroupDao.kt | 13 ++++---- .../ui/main/bookshelf/BookshelfViewModel.kt | 30 +++++++++---------- .../ui/main/bookshelf/GroupManageDialog.kt | 2 +- app/src/main/res/menu/book_group_manage.xml | 27 +++++++++++++++++ 4 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/menu/book_group_manage.xml diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index 51068b149..6162ffc5a 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -1,10 +1,7 @@ package io.legado.app.data.dao import androidx.lifecycle.LiveData -import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy -import androidx.room.Query +import androidx.room.* import io.legado.app.data.entities.BookGroup @Dao @@ -17,5 +14,11 @@ interface BookGroupDao { val maxId: Int @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(bookGroup: BookGroup) + fun insert(vararg bookGroup: BookGroup) + + @Update + fun update(vararg bookGroup: BookGroup) + + @Delete + fun delete(vararg bookGroup: BookGroup) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index a56a08871..f4664fa22 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -7,28 +7,28 @@ import io.legado.app.data.entities.BookGroup class BookshelfViewModel(application: Application) : BaseViewModel(application) { - fun saveBookGroup(group: String?) { - if (!group.isNullOrBlank()) { - execute { - App.db.bookGroupDao().insert( - BookGroup( - App.db.bookGroupDao().maxId + 1, - group - ) - ) - } - } - } fun addGroup(groupName: String) { - + execute { + val maxId = App.db.bookGroupDao().maxId + val bookGroup = BookGroup( + groupId = maxId.plus(1), + groupName = groupName, + order = maxId.plus(1) + ) + App.db.bookGroupDao().insert(bookGroup) + } } fun upGroup(bookGroup: BookGroup) { - + execute { + App.db.bookGroupDao().update(bookGroup) + } } fun delGroup(bookGroup: BookGroup) { - + execute { + App.db.bookGroupDao().delete(bookGroup) + } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt index d33a62476..7db85906e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt @@ -59,7 +59,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private fun initData() { tool_bar.title = getString(R.string.group_manage) - tool_bar.inflateMenu(R.menu.group_manage) + tool_bar.inflateMenu(R.menu.book_group_manage) tool_bar.menu.applyTint(requireContext(), false) tool_bar.setOnMenuItemClickListener(this) adapter = GroupAdapter(requireContext()) diff --git a/app/src/main/res/menu/book_group_manage.xml b/app/src/main/res/menu/book_group_manage.xml new file mode 100644 index 000000000..4c887905d --- /dev/null +++ b/app/src/main/res/menu/book_group_manage.xml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file From 6bed8c39c2a67b2c0a0b27a02b9d2b225047678d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 28 Sep 2019 22:00:35 +0800 Subject: [PATCH 009/140] up --- .../java/io/legado/app/constant/AppConst.kt | 10 ++--- .../ui/main/bookshelf/BookshelfFragment.kt | 38 +++++++++++++++---- .../ui/main/bookshelf/GroupManageDialog.kt | 23 +++++++++-- app/src/main/res/values/strings.xml | 1 + 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index f9fe5b942..99dcb17cb 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -38,11 +38,7 @@ object AppConst { ) } - val defaultBookGroups by lazy { - listOf( - BookGroup(-1, "全部"), - BookGroup(-2, "本地"), - BookGroup(-3, "音频") - ) - } + val bookGroupAll = BookGroup(-1, App.INSTANCE.getString(R.string.all)) + val bookGroupLocal = BookGroup(-2, App.INSTANCE.getString(R.string.local)) + val bookGroupAudio = BookGroup(-3, App.INSTANCE.getString(R.string.audio)) } \ No newline at end of file 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 008ff6131..797ef096d 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 @@ -17,6 +17,7 @@ import io.legado.app.data.entities.BookGroup import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.search.SearchActivity +import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getViewModel import io.legado.app.utils.putPrefInt import io.legado.app.utils.startActivity @@ -27,13 +28,14 @@ import org.jetbrains.anko.startActivity class BookshelfFragment : VMBaseFragment(R.layout.fragment_bookshelf), SearchView.OnQueryTextListener, + GroupManageDialog.CallBack, BookshelfAdapter.CallBack { override val viewModel: BookshelfViewModel get() = getViewModel(BookshelfViewModel::class.java) private var bookGroupLiveData: LiveData>? = null - private val bookGroups = mutableListOf().apply { addAll(AppConst.defaultBookGroups) } + private val bookGroups = mutableListOf() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) @@ -50,9 +52,8 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b when (item.itemId) { R.id.menu_search -> startActivity() R.id.menu_bookshelf_layout -> selectBookshelfLayout() - R.id.menu_group_manage -> fragmentManager?.let { - GroupManageDialog().show(it, "groupManageDialog") - } + R.id.menu_group_manage -> GroupManageDialog() + .show(childFragmentManager, "groupManageDialog") R.id.menu_add_local -> { } R.id.menu_add_url -> { @@ -83,11 +84,18 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b bookGroupLiveData?.removeObservers(viewLifecycleOwner) bookGroupLiveData = App.db.bookGroupDao().liveDataAll() bookGroupLiveData?.observe(viewLifecycleOwner, Observer { - for (index in AppConst.defaultBookGroups.size until bookGroups.size) { - bookGroups.removeAt(AppConst.defaultBookGroups.size) + synchronized(this) { + bookGroups.clear() + bookGroups.add(AppConst.bookGroupAll) + if (getPrefBoolean("bookGroupLocal", true)) { + bookGroups.add(AppConst.bookGroupLocal) + } + if (getPrefBoolean("bookGroupAudio", true)) { + bookGroups.add(AppConst.bookGroupAudio) + } + bookGroups.addAll(it) + view_pager_bookshelf.adapter?.notifyDataSetChanged() } - bookGroups.addAll(it) - view_pager_bookshelf.adapter?.notifyDataSetChanged() }) } @@ -100,6 +108,20 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b return false } + override fun upGroup() { + synchronized(this) { + bookGroups.remove(AppConst.bookGroupLocal) + bookGroups.remove(AppConst.bookGroupAudio) + if (getPrefBoolean("bookGroupAudio", true)) { + bookGroups.add(1, AppConst.bookGroupAudio) + } + if (getPrefBoolean("bookGroupLocal", true)) { + bookGroups.add(1, AppConst.bookGroupLocal) + } + view_pager_bookshelf.adapter?.notifyDataSetChanged() + } + } + private fun selectBookshelfLayout() { selector( title = "选择书架布局", diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt index 7db85906e..87d43bc1b 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt @@ -24,9 +24,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModel -import io.legado.app.utils.requestInputMethod +import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_group_manage.view.* @@ -35,6 +33,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var viewModel: BookshelfViewModel private lateinit var adapter: GroupAdapter + private var callBack: CallBack? = null override fun onStart() { super.onStart() @@ -54,6 +53,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + callBack = parentFragment as? CallBack initData() } @@ -62,6 +62,10 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.inflateMenu(R.menu.book_group_manage) tool_bar.menu.applyTint(requireContext(), false) tool_bar.setOnMenuItemClickListener(this) + tool_bar.menu.findItem(R.id.menu_group_local) + .isChecked = getPrefBoolean("bookGroupLocal", true) + tool_bar.menu.findItem(R.id.menu_group_audio) + .isChecked = getPrefBoolean("bookGroupAudio", true) adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration( @@ -76,6 +80,16 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_add -> addGroup() + R.id.menu_group_local -> { + item.isChecked = !item.isChecked + putPrefBoolean("bookGroupLocal", item.isChecked) + callBack?.upGroup() + } + R.id.menu_group_audio -> { + item.isChecked = !item.isChecked + putPrefBoolean("bookGroupAudio", item.isChecked) + callBack?.upGroup() + } } return true } @@ -133,4 +147,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } } + interface CallBack { + fun upGroup() + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 72667cbab..af7b4e933 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -35,6 +35,7 @@ 替换净化-搜索 书架 订阅 + 全部 最近阅读 最后阅读 让阅读成为一种习惯。 From cca3920c76a0f01987d0815f56439e09f977c6a2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 28 Sep 2019 22:19:58 +0800 Subject: [PATCH 010/140] up --- .../ui/main/bookshelf/BookshelfViewModel.kt | 8 +++--- .../ui/main/bookshelf/GroupManageDialog.kt | 25 ++++++++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index f4664fa22..0499e5e5e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -20,15 +20,15 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } } - fun upGroup(bookGroup: BookGroup) { + fun upGroup(vararg bookGroup: BookGroup) { execute { - App.db.bookGroupDao().update(bookGroup) + App.db.bookGroupDao().update(*bookGroup) } } - fun delGroup(bookGroup: BookGroup) { + fun delGroup(vararg bookGroup: BookGroup) { execute { - App.db.bookGroupDao().delete(bookGroup) + App.db.bookGroupDao().delete(*bookGroup) } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt index 87d43bc1b..f6151edaf 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt @@ -13,6 +13,7 @@ import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.App @@ -20,6 +21,7 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookGroup +import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton @@ -75,6 +77,10 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { adapter.setItems(it) }) + val itemTouchCallback = ItemTouchCallback() + itemTouchCallback.onItemTouchCallbackListener = adapter + itemTouchCallback.isCanDrag = true + ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) } override fun onMenuItemClick(item: MenuItem?): Boolean { @@ -136,7 +142,8 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } private inner class GroupAdapter(context: Context) : - SimpleRecyclerAdapter(context, R.layout.item_group_manage) { + SimpleRecyclerAdapter(context, R.layout.item_group_manage), + ItemTouchCallback.OnItemTouchCallbackListener { override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList) { with(holder.itemView) { @@ -145,6 +152,22 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tv_del.onClick { viewModel.delGroup(item) } } } + + override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + val srcItem = getItem(srcPosition) + val targetItem = getItem(targetPosition) + if (srcItem != null && targetItem != null) { + val order = srcItem.order + srcItem.order = targetItem.order + targetItem.order = order + viewModel.upGroup(srcItem, targetItem) + } + return true + } + + override fun onSwiped(adapterPosition: Int) { + + } } interface CallBack { From 69960cefbd82a045f8d77fb86c1eaceed47de9f0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 28 Sep 2019 22:23:02 +0800 Subject: [PATCH 011/140] up --- app/src/main/res/layout/item_group_manage.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/item_group_manage.xml b/app/src/main/res/layout/item_group_manage.xml index 493bf7998..d7d85630a 100644 --- a/app/src/main/res/layout/item_group_manage.xml +++ b/app/src/main/res/layout/item_group_manage.xml @@ -2,6 +2,7 @@ From fa933273d9e63f85a450e3e792d95c822d8bbf91 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 28 Sep 2019 22:26:26 +0800 Subject: [PATCH 012/140] up --- app/src/main/res/values-zh/strings.xml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/src/main/res/values-zh/strings.xml diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml new file mode 100644 index 000000000..78554f9eb --- /dev/null +++ b/app/src/main/res/values-zh/strings.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file From 0104a541e021e208f638aaccc58dd58930967745 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 09:47:44 +0800 Subject: [PATCH 013/140] up --- .../io/legado/app/ui/book/info/BookInfoActivity.kt | 6 ++++-- .../main/res/layout-land/activity_book_info.xml | 14 ++++++++++++-- app/src/main/res/layout/activity_book_info.xml | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 62bc33ca9..8905a248c 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -204,8 +204,10 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } } iv_chapter_top.onClick { - adapter.reorder = !adapter.reorder - adapter.notifyDataSetChanged() + rv_chapter_list.scrollToPosition(0) + } + iv_chapter_bottom.onClick { + rv_chapter_list.scrollToPosition(adapter.itemCount - 1) } } diff --git a/app/src/main/res/layout-land/activity_book_info.xml b/app/src/main/res/layout-land/activity_book_info.xml index a5419f1e6..efc24a7a4 100644 --- a/app/src/main/res/layout-land/activity_book_info.xml +++ b/app/src/main/res/layout-land/activity_book_info.xml @@ -245,11 +245,21 @@ android:layout_height="match_parent" android:background="?android:attr/selectableItemBackgroundBorderless" android:contentDescription="@string/go_to_top" - android:padding="10dp" - android:src="@drawable/ic_exchange_order" + android:src="@drawable/ic_arrow_drop_up" android:tooltipText="@string/go_to_top" app:tint="@color/tv_text_default" tools:ignore="UnusedAttribute" /> + + diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index 2ccef7e17..b5981556c 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -237,11 +237,21 @@ android:layout_height="match_parent" android:background="?android:attr/selectableItemBackgroundBorderless" android:contentDescription="@string/go_to_top" - android:padding="10dp" - android:src="@drawable/ic_exchange_order" + android:src="@drawable/ic_arrow_drop_up" android:tooltipText="@string/go_to_top" app:tint="@color/tv_text_default" tools:ignore="UnusedAttribute" /> + + From adc7867306e42de2eda4fe3e9bbb6d094c0d5be4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 16:04:55 +0800 Subject: [PATCH 014/140] up --- .../io/legado/app/ui/config/ConfigFragment.kt | 2 + .../io/legado/app/ui/main/my/MyFragment.kt | 8 ++- .../main/java/io/legado/app/utils/LogUtils.kt | 70 ++++++------------- 3 files changed, 27 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt index c3b0ae799..fd957e433 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt @@ -10,6 +10,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.help.BookHelp import io.legado.app.lib.theme.ATH +import io.legado.app.utils.LogUtils import io.legado.app.utils.getPrefString @@ -39,6 +40,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { "downloadPath" -> BookHelp.upDownloadPath() + "recordLog" -> LogUtils.upLevel() } } 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 36f2db63b..af839204e 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 @@ -10,6 +10,7 @@ import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment +import io.legado.app.help.BookHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup @@ -21,6 +22,7 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.replacerule.ReplaceRuleActivity +import io.legado.app.utils.LogUtils import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity @@ -82,9 +84,9 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { key: String? ) { when (key) { - "isNightTheme" -> { - App.INSTANCE.applyDayNight() - } + "isNightTheme" -> App.INSTANCE.applyDayNight() + "recordLog" -> LogUtils.upLevel() + "downloadPath" -> BookHelp.upDownloadPath() } } diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index 571c4e4cf..b271cbda0 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -11,66 +11,36 @@ import java.util.logging.Formatter object LogUtils { + const val TIME_PATTERN = "yyyy-MM-dd HH:mm:ss" - private val logger: Logger by lazy { + val logger: Logger by lazy { Logger.getGlobal().apply { - addFileHandler( - this, - Level.INFO, - FileHelp.getCachePath() - ) + addHandler(fileHandler) } } - fun log(msg: String) { - if (App.INSTANCE.getPrefBoolean("recordLog")) { - logger.log(Level.INFO, msg) - } - } - - private const val DATE_PATTERN = "yyyy-MM-dd" - const val TIME_PATTERN = "HH:mm:ss" - - /** - * 为log添加控制台handler - * - * @param log 要添加handler的log - * @param level 控制台的输出等级 - */ - fun addConsoleHandler(log: Logger, level: Level) { - // 控制台输出的handler - val consoleHandler = ConsoleHandler() - // 设置控制台输出的等级(如果ConsoleHandler的等级高于或者等于log的level,则按照FileHandler的level输出到控制台,如果低于,则按照Log等级输出) - consoleHandler.level = level - // 添加控制台的handler - log.addHandler(consoleHandler) - } - - /** - * 为log添加文件输出Handler - * - * @param log 要添加文件输出handler的log - * @param level log输出等级 - * @param filePath 指定文件全路径 - */ - fun addFileHandler(log: Logger, level: Level, filePath: String) { - var fileHandler: FileHandler? = null - try { - fileHandler = - FileHandler(filePath + File.separator + getCurrentDateStr(DATE_PATTERN) + ".log") - // 设置输出文件的等级(如果FileHandler的等级高于或者等于log的level,则按照FileHandler的level输出到文件,如果低于,则按照Log等级输出) - fileHandler.level = level - fileHandler.formatter = object : Formatter() { + private val fileHandler by lazy { + FileHandler(FileHelp.getCachePath() + File.separator + "app.log", 1024, 2).apply { + formatter = object : Formatter() { override fun format(record: LogRecord): String { // 设置文件输出格式 - return (getCurrentDateStr(TIME_PATTERN) + ":" + record.message + "\n") + return (getCurrentDateStr(TIME_PATTERN) + ": " + record.message + "\n") } } - } catch (e: Exception) { - e.printStackTrace() + level = if (App.INSTANCE.getPrefBoolean("recordLog")) { + Level.INFO + } else { + Level.OFF + } + } + } + + fun upLevel() { + fileHandler.level = if (App.INSTANCE.getPrefBoolean("recordLog")) { + Level.INFO + } else { + Level.OFF } - // 添加输出文件handler - log.addHandler(fileHandler) } /** From b4894d43d32d6a11b416565c114bff85621188c1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 16:15:23 +0800 Subject: [PATCH 015/140] up --- .../main/java/io/legado/app/receiver/MediaButtonReceiver.kt | 4 +++- app/src/main/java/io/legado/app/utils/LogUtils.kt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 17eba6b18..1dfa59fcc 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -7,7 +7,9 @@ import android.view.KeyEvent import io.legado.app.constant.Bus import io.legado.app.help.ActivityHelp import io.legado.app.ui.book.read.ReadBookActivity +import io.legado.app.utils.LogUtils.MyLogger import io.legado.app.utils.postEvent +import java.util.logging.Level /** @@ -22,7 +24,7 @@ class MediaButtonReceiver : BroadcastReceiver() { fun handleIntent(context: Context, intent: Intent): Boolean { val intentAction = intent.action val keyEventAction = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT)?.action -// LogUtils.log("耳机按键: $intentAction $keyEventAction") + MyLogger.log(Level.INFO, "耳机按键: $intentAction $keyEventAction") if (Intent.ACTION_MEDIA_BUTTON == intentAction) { if (keyEventAction == KeyEvent.ACTION_DOWN) { readAloud(context) diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index b271cbda0..82b2c8cc4 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -13,7 +13,7 @@ import java.util.logging.Formatter object LogUtils { const val TIME_PATTERN = "yyyy-MM-dd HH:mm:ss" - val logger: Logger by lazy { + val MyLogger: Logger by lazy { Logger.getGlobal().apply { addHandler(fileHandler) } From 016e98f4855ca322c38090c5d6002cc311f66622 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 18:02:33 +0800 Subject: [PATCH 016/140] up --- app/build.gradle | 3 + app/src/main/java/io/legado/app/App.kt | 10 ++++ .../app/receiver/MediaButtonReceiver.kt | 5 +- .../io/legado/app/ui/config/ConfigFragment.kt | 5 +- .../io/legado/app/ui/main/my/MyFragment.kt | 5 +- .../main/java/io/legado/app/utils/LogUtils.kt | 55 ------------------- 6 files changed, 21 insertions(+), 62 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/utils/LogUtils.kt diff --git a/app/build.gradle b/app/build.gradle index 22922cbbe..97a5a9dc0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -148,4 +148,7 @@ dependencies { //颜色选择 implementation 'com.jaredrummler:colorpicker:1.1.0' + //日志记录 + implementation 'com.apkfuns.logutils:library:1.7.5' + implementation 'com.apkfuns.log2file:log2file:1.3.1' } diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 54238a6ad..ea8a30f66 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -9,6 +9,8 @@ import android.os.Build import android.os.Bundle import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatDelegate +import com.apkfuns.log2file.LogFileEngineFactory +import com.apkfuns.logutils.LogUtils import com.jeremyliao.liveeventbus.LiveEventBus import io.legado.app.constant.AppConst.channelIdDownload import io.legado.app.constant.AppConst.channelIdReadAloud @@ -16,12 +18,15 @@ import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.data.AppDatabase import io.legado.app.help.ActivityHelp import io.legado.app.help.CrashHandler +import io.legado.app.help.FileHelp import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.ThemeStore import io.legado.app.ui.widget.page.ChapterProvider import io.legado.app.utils.getCompatColor +import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefInt import io.legado.app.utils.isNightTheme +import java.io.File @Suppress("DEPRECATION") class App : Application() { @@ -43,6 +48,11 @@ class App : Application() { super.onCreate() INSTANCE = this CrashHandler().init(this) + LogUtils.getLog2FileConfig() + .configLog2FileEnable(getPrefBoolean("recordLog")) + .configLog2FilePath(FileHelp.getCachePath() + File.separator + "logs" + File.separator) + .configLog2FileNameFormat("%d{yyyyMMdd}.log") + .configLogFileEngine(LogFileEngineFactory(this)) db = AppDatabase.createDatabase(INSTANCE) packageManager.getPackageInfo(packageName, 0)?.let { versionCode = it.versionCode diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 1dfa59fcc..45565c31c 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -4,12 +4,11 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.view.KeyEvent +import com.apkfuns.logutils.LogUtils import io.legado.app.constant.Bus import io.legado.app.help.ActivityHelp import io.legado.app.ui.book.read.ReadBookActivity -import io.legado.app.utils.LogUtils.MyLogger import io.legado.app.utils.postEvent -import java.util.logging.Level /** @@ -24,7 +23,7 @@ class MediaButtonReceiver : BroadcastReceiver() { fun handleIntent(context: Context, intent: Intent): Boolean { val intentAction = intent.action val keyEventAction = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT)?.action - MyLogger.log(Level.INFO, "耳机按键: $intentAction $keyEventAction") + LogUtils.d("耳机按键", "$intentAction $keyEventAction") if (Intent.ACTION_MEDIA_BUTTON == intentAction) { if (keyEventAction == KeyEvent.ACTION_DOWN) { readAloud(context) diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt index fd957e433..c111b9401 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt @@ -6,11 +6,12 @@ import android.view.View import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import com.apkfuns.logutils.LogUtils import io.legado.app.App import io.legado.app.R import io.legado.app.help.BookHelp import io.legado.app.lib.theme.ATH -import io.legado.app.utils.LogUtils +import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefString @@ -40,7 +41,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { "downloadPath" -> BookHelp.upDownloadPath() - "recordLog" -> LogUtils.upLevel() + "recordLog" -> LogUtils.getLog2FileConfig().configLog2FileEnable(getPrefBoolean("recordLog")) } } 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 af839204e..350737281 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 @@ -7,6 +7,7 @@ import android.view.MenuItem import android.view.View import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import com.apkfuns.logutils.LogUtils import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment @@ -22,7 +23,7 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.replacerule.ReplaceRuleActivity -import io.legado.app.utils.LogUtils +import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity @@ -85,7 +86,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { ) { when (key) { "isNightTheme" -> App.INSTANCE.applyDayNight() - "recordLog" -> LogUtils.upLevel() + "recordLog" -> LogUtils.getLog2FileConfig().configLog2FileEnable(getPrefBoolean("recordLog")) "downloadPath" -> BookHelp.upDownloadPath() } } diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt deleted file mode 100644 index 82b2c8cc4..000000000 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ /dev/null @@ -1,55 +0,0 @@ -package io.legado.app.utils - -import android.annotation.SuppressLint -import io.legado.app.App -import io.legado.app.help.FileHelp -import java.io.File -import java.text.SimpleDateFormat -import java.util.* -import java.util.logging.* -import java.util.logging.Formatter - - -object LogUtils { - const val TIME_PATTERN = "yyyy-MM-dd HH:mm:ss" - - val MyLogger: Logger by lazy { - Logger.getGlobal().apply { - addHandler(fileHandler) - } - } - - private val fileHandler by lazy { - FileHandler(FileHelp.getCachePath() + File.separator + "app.log", 1024, 2).apply { - formatter = object : Formatter() { - override fun format(record: LogRecord): String { - // 设置文件输出格式 - return (getCurrentDateStr(TIME_PATTERN) + ": " + record.message + "\n") - } - } - level = if (App.INSTANCE.getPrefBoolean("recordLog")) { - Level.INFO - } else { - Level.OFF - } - } - } - - fun upLevel() { - fileHandler.level = if (App.INSTANCE.getPrefBoolean("recordLog")) { - Level.INFO - } else { - Level.OFF - } - } - - /** - * 获取当前时间 - */ - @SuppressLint("SimpleDateFormat") - fun getCurrentDateStr(pattern: String): String { - val date = Date() - val sdf = SimpleDateFormat(pattern) - return sdf.format(date) - } -} \ No newline at end of file From 1ce32423a90367c3a9f50f2f4dda1f2545264762 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 18:45:43 +0800 Subject: [PATCH 017/140] up --- app/build.gradle | 3 - app/src/main/java/io/legado/app/App.kt | 10 --- .../app/receiver/MediaButtonReceiver.kt | 2 +- .../io/legado/app/ui/config/ConfigFragment.kt | 5 +- .../io/legado/app/ui/main/my/MyFragment.kt | 5 +- .../main/java/io/legado/app/utils/LogUtils.kt | 63 +++++++++++++++++++ 6 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/LogUtils.kt diff --git a/app/build.gradle b/app/build.gradle index 97a5a9dc0..22922cbbe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -148,7 +148,4 @@ dependencies { //颜色选择 implementation 'com.jaredrummler:colorpicker:1.1.0' - //日志记录 - implementation 'com.apkfuns.logutils:library:1.7.5' - implementation 'com.apkfuns.log2file:log2file:1.3.1' } diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index ea8a30f66..54238a6ad 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -9,8 +9,6 @@ import android.os.Build import android.os.Bundle import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatDelegate -import com.apkfuns.log2file.LogFileEngineFactory -import com.apkfuns.logutils.LogUtils import com.jeremyliao.liveeventbus.LiveEventBus import io.legado.app.constant.AppConst.channelIdDownload import io.legado.app.constant.AppConst.channelIdReadAloud @@ -18,15 +16,12 @@ import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.data.AppDatabase import io.legado.app.help.ActivityHelp import io.legado.app.help.CrashHandler -import io.legado.app.help.FileHelp import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.ThemeStore import io.legado.app.ui.widget.page.ChapterProvider import io.legado.app.utils.getCompatColor -import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefInt import io.legado.app.utils.isNightTheme -import java.io.File @Suppress("DEPRECATION") class App : Application() { @@ -48,11 +43,6 @@ class App : Application() { super.onCreate() INSTANCE = this CrashHandler().init(this) - LogUtils.getLog2FileConfig() - .configLog2FileEnable(getPrefBoolean("recordLog")) - .configLog2FilePath(FileHelp.getCachePath() + File.separator + "logs" + File.separator) - .configLog2FileNameFormat("%d{yyyyMMdd}.log") - .configLogFileEngine(LogFileEngineFactory(this)) db = AppDatabase.createDatabase(INSTANCE) packageManager.getPackageInfo(packageName, 0)?.let { versionCode = it.versionCode diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 45565c31c..ce3908021 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -4,10 +4,10 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.view.KeyEvent -import com.apkfuns.logutils.LogUtils import io.legado.app.constant.Bus import io.legado.app.help.ActivityHelp import io.legado.app.ui.book.read.ReadBookActivity +import io.legado.app.utils.LogUtils import io.legado.app.utils.postEvent diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt index c111b9401..fd957e433 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt @@ -6,12 +6,11 @@ import android.view.View import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import com.apkfuns.logutils.LogUtils import io.legado.app.App import io.legado.app.R import io.legado.app.help.BookHelp import io.legado.app.lib.theme.ATH -import io.legado.app.utils.getPrefBoolean +import io.legado.app.utils.LogUtils import io.legado.app.utils.getPrefString @@ -41,7 +40,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { "downloadPath" -> BookHelp.upDownloadPath() - "recordLog" -> LogUtils.getLog2FileConfig().configLog2FileEnable(getPrefBoolean("recordLog")) + "recordLog" -> LogUtils.upLevel() } } 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 350737281..af839204e 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 @@ -7,7 +7,6 @@ import android.view.MenuItem import android.view.View import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import com.apkfuns.logutils.LogUtils import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment @@ -23,7 +22,7 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.replacerule.ReplaceRuleActivity -import io.legado.app.utils.getPrefBoolean +import io.legado.app.utils.LogUtils import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity @@ -86,7 +85,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { ) { when (key) { "isNightTheme" -> App.INSTANCE.applyDayNight() - "recordLog" -> LogUtils.getLog2FileConfig().configLog2FileEnable(getPrefBoolean("recordLog")) + "recordLog" -> LogUtils.upLevel() "downloadPath" -> BookHelp.upDownloadPath() } } diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt new file mode 100644 index 000000000..27c3015fe --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -0,0 +1,63 @@ +package io.legado.app.utils + +import android.annotation.SuppressLint +import io.legado.app.App +import io.legado.app.help.FileHelp +import java.io.File +import java.text.SimpleDateFormat +import java.util.* +import java.util.logging.* +import java.util.logging.Formatter + + +object LogUtils { + const val TIME_PATTERN = "yyyy-MM-dd HH:mm:ss" + + fun d(tag: String, msg: String) { + logger.log(Level.INFO, "$tag $msg") + } + + fun e(tag: String, msg: String) { + logger.log(Level.WARNING, "$tag $msg") + } + + private val logger: Logger by lazy { + Logger.getGlobal().apply { + addHandler(fileHandler) + } + } + + private val fileHandler by lazy { + FileHandler(FileHelp.getCachePath() + File.separator + "app.log", 1024, 2).apply { + formatter = object : Formatter() { + override fun format(record: LogRecord): String { + // 设置文件输出格式 + return (getCurrentDateStr(TIME_PATTERN) + ": " + record.message + "\n") + } + } + level = if (App.INSTANCE.getPrefBoolean("recordLog")) { + Level.INFO + } else { + Level.OFF + } + } + } + + fun upLevel() { + fileHandler.level = if (App.INSTANCE.getPrefBoolean("recordLog")) { + Level.INFO + } else { + Level.OFF + } + } + + /** + * 获取当前时间 + */ + @SuppressLint("SimpleDateFormat") + fun getCurrentDateStr(pattern: String): String { + val date = Date() + val sdf = SimpleDateFormat(pattern) + return sdf.format(date) + } +} \ No newline at end of file From f6685e5dd29b396c1d269337fe6543fa358918da Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 18:49:58 +0800 Subject: [PATCH 018/140] up --- app/src/main/java/io/legado/app/utils/LogUtils.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index 27c3015fe..1ae855b6b 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -28,7 +28,11 @@ object LogUtils { } private val fileHandler by lazy { - FileHandler(FileHelp.getCachePath() + File.separator + "app.log", 1024, 2).apply { + FileHandler( + FileHelp.getCachePath() + File.separator + "logs" + File.separator + "app.log", + 2048, + 10 + ).apply { formatter = object : Formatter() { override fun format(record: LogRecord): String { // 设置文件输出格式 From fe8c4e02e55a35422b4bd5e63eefba26adc4b9a6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 19:33:19 +0800 Subject: [PATCH 019/140] up --- app/src/main/java/io/legado/app/utils/LogUtils.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index 1ae855b6b..f8b8b6bb6 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -13,10 +13,12 @@ import java.util.logging.Formatter object LogUtils { const val TIME_PATTERN = "yyyy-MM-dd HH:mm:ss" + @JvmStatic fun d(tag: String, msg: String) { logger.log(Level.INFO, "$tag $msg") } + @JvmStatic fun e(tag: String, msg: String) { logger.log(Level.WARNING, "$tag $msg") } From 4227b8ccc78e2ff77cf650ef33eeffe58bc66ba6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 19:46:00 +0800 Subject: [PATCH 020/140] up --- .../main/java/io/legado/app/utils/ACache.kt | 196 +++++++++--------- 1 file changed, 103 insertions(+), 93 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/ACache.kt b/app/src/main/java/io/legado/app/utils/ACache.kt index 5ac75f875..7549813e8 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -23,7 +23,49 @@ import kotlin.math.min * 本地缓存 */ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) { - private lateinit var mCache: ACacheManager + + + companion object { + const val TIME_HOUR = 60 * 60 + const val TIME_DAY = TIME_HOUR * 24 + private const val MAX_SIZE = 1000 * 1000 * 50 // 50 mb + private const val MAX_COUNT = Integer.MAX_VALUE // 不限制存放数据的数量 + private val mInstanceMap = HashMap() + + @JvmOverloads + fun get( + ctx: Context, + cacheName: String = "ACache", + maxSize: Long = MAX_SIZE.toLong(), + maxCount: Int = MAX_COUNT, + cacheDir: Boolean = true + ): ACache { + val f = if (cacheDir) File(ctx.cacheDir, cacheName) else File(ctx.filesDir, cacheName) + return get(f, maxSize, maxCount) + } + + @JvmOverloads + fun get( + cacheDir: File, + maxSize: Long = MAX_SIZE.toLong(), + maxCount: Int = MAX_COUNT + ): ACache { + synchronized(this) { + var manager = mInstanceMap[cacheDir.absoluteFile.toString() + myPid()] + if (manager == null) { + manager = ACache(cacheDir, maxSize, maxCount) + mInstanceMap[cacheDir.absolutePath + myPid()] = manager + } + return manager + } + } + + private fun myPid(): String { + return "_" + android.os.Process.myPid() + } + } + + private var mCache: ACacheManager? = null init { try { @@ -48,12 +90,14 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) * @param value 保存的String数据 */ fun put(key: String, value: String) { - try { - val file = mCache.newFile(key) - file.writeText(value) - mCache.put(file) - } catch (e: Exception) { - e.printStackTrace() + mCache?.let { mCache -> + try { + val file = mCache.newFile(key) + file.writeText(value) + mCache.put(file) + } catch (e: Exception) { + e.printStackTrace() + } } } @@ -74,24 +118,26 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) * @return String 数据 */ fun getAsString(key: String): String? { - val file = mCache[key] - if (!file.exists()) - return null - var removeFile = false - return try { - val text = file.readText() - if (!Utils.isDue(text)) { - Utils.clearDateInfo(text) - } else { - removeFile = true - null + mCache?.let { mCache -> + val file = mCache[key] + if (!file.exists()) + return null + var removeFile = false + try { + val text = file.readText() + if (!Utils.isDue(text)) { + return Utils.clearDateInfo(text) + } else { + removeFile = true + } + } catch (e: IOException) { + e.printStackTrace() + } finally { + if (removeFile) + remove(key) } - } catch (e: IOException) { - null - } finally { - if (removeFile) - remove(key) } + return null } // ======================================= @@ -184,9 +230,11 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) * @param value 保存的数据 */ fun put(key: String, value: ByteArray) { - val file = mCache.newFile(key) - file.writeBytes(value) - mCache.put(file) + mCache?.let { mCache -> + val file = mCache.newFile(key) + file.writeBytes(value) + mCache.put(file) + } } /** @@ -206,26 +254,28 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) * @return byte 数据 */ fun getAsBinary(key: String): ByteArray? { - var removeFile = false - try { - val file = mCache[key] - if (!file.exists()) - return null + mCache?.let { mCache -> + var removeFile = false + try { + val file = mCache[key] + if (!file.exists()) + return null - val byteArray = file.readBytes() - return if (!Utils.isDue(byteArray)) { - Utils.clearDateInfo(byteArray) - } else { - removeFile = true - null + val byteArray = file.readBytes() + return if (!Utils.isDue(byteArray)) { + Utils.clearDateInfo(byteArray) + } else { + removeFile = true + null + } + } catch (e: Exception) { + e.printStackTrace() + } finally { + if (removeFile) + remove(key) } - } catch (e: Exception) { - e.printStackTrace() - return null - } finally { - if (removeFile) - remove(key) } + return null } /** @@ -269,7 +319,6 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) return ois.readObject() } catch (e: Exception) { e.printStackTrace() - return null } finally { try { bais?.close() @@ -371,15 +420,16 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) * @return value 缓存的文件 */ fun file(key: String): File? { - try { - val f = mCache.newFile(key) - if (f.exists()) { - return f + mCache?.let { mCache -> + try { + val f = mCache.newFile(key) + if (f.exists()) { + return f + } + } catch (e: Exception) { + e.printStackTrace() } - } catch (e: Exception) { - e.printStackTrace() } - return null } @@ -389,14 +439,14 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) * @return 是否移除成功 */ fun remove(key: String): Boolean { - return mCache.remove(key) + return mCache?.remove(key) == true } /** * 清除所有数据 */ fun clear() { - mCache.clear() + mCache?.clear() } /** @@ -726,44 +776,4 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } } - companion object { - const val TIME_HOUR = 60 * 60 - const val TIME_DAY = TIME_HOUR * 24 - private const val MAX_SIZE = 1000 * 1000 * 50 // 50 mb - private const val MAX_COUNT = Integer.MAX_VALUE // 不限制存放数据的数量 - private val mInstanceMap = HashMap() - - @JvmOverloads - fun get( - ctx: Context, - cacheName: String = "ACache", - maxSize: Long = MAX_SIZE.toLong(), - maxCount: Int = MAX_COUNT, - cacheDir: Boolean = true - ): ACache { - val f = if (cacheDir) File(ctx.cacheDir, cacheName) else File(ctx.filesDir, cacheName) - return get(f, maxSize, maxCount) - } - - @JvmOverloads - fun get( - cacheDir: File, - maxSize: Long = MAX_SIZE.toLong(), - maxCount: Int = MAX_COUNT - ): ACache { - synchronized(this) { - var manager = mInstanceMap[cacheDir.absoluteFile.toString() + myPid()] - if (manager == null) { - manager = ACache(cacheDir, maxSize, maxCount) - mInstanceMap[cacheDir.absolutePath + myPid()] = manager - } - return manager - } - } - - private fun myPid(): String { - return "_" + android.os.Process.myPid() - } - } - } \ No newline at end of file From 0f1c604ba33bd6a743a77bffa51d95f0e900cf2f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 20:02:02 +0800 Subject: [PATCH 021/140] up --- .../app/ui/book/search/SearchActivity.kt | 5 ++-- ...ty_search.xml => activity_book_search.xml} | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) rename app/src/main/res/layout/{activity_search.xml => activity_book_search.xml} (68%) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 64d5d76f8..5e01ac820 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -17,12 +17,13 @@ import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.utils.getViewModel import io.legado.app.utils.invisible import io.legado.app.utils.visible -import kotlinx.android.synthetic.main.activity_search.* +import kotlinx.android.synthetic.main.activity_book_search.* import kotlinx.android.synthetic.main.view_search.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity -class SearchActivity : VMBaseActivity(R.layout.activity_search), SearchAdapter.CallBack { +class SearchActivity : VMBaseActivity(R.layout.activity_book_search), + SearchAdapter.CallBack { override val viewModel: SearchViewModel get() = getViewModel(SearchViewModel::class.java) diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_book_search.xml similarity index 68% rename from app/src/main/res/layout/activity_search.xml rename to app/src/main/res/layout/activity_book_search.xml index 3fd29e772..e4588e73c 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_book_search.xml @@ -36,6 +36,35 @@ + + + + + + + + + + + + Date: Sun, 29 Sep 2019 20:09:07 +0800 Subject: [PATCH 022/140] up --- app/src/main/res/layout/activity_book_search.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/activity_book_search.xml b/app/src/main/res/layout/activity_book_search.xml index e4588e73c..15e895b18 100644 --- a/app/src/main/res/layout/activity_book_search.xml +++ b/app/src/main/res/layout/activity_book_search.xml @@ -41,6 +41,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" + android:visibility="gone" app:layout_constraintTop_toBottomOf="@id/title_bar"> From abc9c2f196314e62641e2fd5eefd0be217406922 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 20:28:30 +0800 Subject: [PATCH 023/140] up --- .../legado/app/ui/book/search/BookAdapter.kt | 15 +++++++++++++ .../app/ui/book/search/HistoryKeyAdapter.kt | 16 ++++++++++++++ .../app/ui/book/search/SearchActivity.kt | 21 ++++++++++++++++++- .../main/res/layout/activity_book_search.xml | 4 ++-- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt create mode 100644 app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt diff --git a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt new file mode 100644 index 000000000..7b018db40 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt @@ -0,0 +1,15 @@ +package io.legado.app.ui.book.search + +import android.content.Context +import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter + +class BookAdapter(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_text) { + + override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt new file mode 100644 index 000000000..7ceb93993 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -0,0 +1,16 @@ +package io.legado.app.ui.book.search + +import android.content.Context +import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter + + +class HistoryKeyAdapter(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_text) { + + override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 5e01ac820..5d3299611 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.Observer import androidx.paging.LivePagedListBuilder import androidx.paging.PagedList import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity @@ -29,6 +30,8 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se get() = getViewModel(SearchViewModel::class.java) private lateinit var adapter: SearchAdapter + private lateinit var bookAdapter: BookAdapter + private lateinit var historyKeyAdapter: HistoryKeyAdapter private var searchBookData: LiveData>? = null override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -67,14 +70,30 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se return false } }) - fb_stop.onClick { viewModel.stop() } + search_view.setOnQueryTextFocusChangeListener { v, hasFocus -> + if (hasFocus) { + ll_history.visible() + } else { + ll_history.invisible() + } + } } private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) + ATH.applyEdgeEffectColor(rv_bookshelf_search) + ATH.applyEdgeEffectColor(rv_history_key) + bookAdapter = BookAdapter(this) + rv_bookshelf_search.layoutManager = + LinearLayoutManager(this, RecyclerView.HORIZONTAL, false) + rv_bookshelf_search.adapter = bookAdapter + historyKeyAdapter = HistoryKeyAdapter(this) + rv_history_key.layoutManager = LinearLayoutManager(this, RecyclerView.HORIZONTAL, false) + rv_history_key.adapter = historyKeyAdapter adapter = SearchAdapter(this) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter + fb_stop.onClick { viewModel.stop() } } private fun initData() { diff --git a/app/src/main/res/layout/activity_book_search.xml b/app/src/main/res/layout/activity_book_search.xml index 15e895b18..f231b65cb 100644 --- a/app/src/main/res/layout/activity_book_search.xml +++ b/app/src/main/res/layout/activity_book_search.xml @@ -50,7 +50,7 @@ android:text="@string/bookshelf" /> @@ -61,7 +61,7 @@ android:text="@string/searchHistory" /> From 5c41348cb58c725f6d72d7df142e9567418ff6de Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 22:03:08 +0800 Subject: [PATCH 024/140] up --- .../java/io/legado/app/data/dao/BookDao.kt | 3 ++ .../legado/app/data/dao/SearchKeywordDao.kt | 12 ++++---- .../legado/app/ui/book/search/BookAdapter.kt | 10 +++++-- .../app/ui/book/search/HistoryKeyAdapter.kt | 10 +++++-- .../app/ui/book/search/SearchActivity.kt | 29 ++++++++++++++++++- .../main/res/layout/activity_book_search.xml | 3 ++ 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index bae53c8f2..a174e0829 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -24,6 +24,9 @@ interface BookDao { @Query("SELECT bookUrl FROM books WHERE `group` = :group") fun observeUrlsByGroup(group: Int): LiveData> + @Query("SELECT bookUrl FROM books WHERE name like '%' | :key | '%' or author like '%' | :key | '%'") + fun liveDataSearch(key: String): LiveData> + @Query("SELECT * FROM books WHERE `name` in (:names)") fun findByName(vararg names: String): List diff --git a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt index b2370ceb6..fcd7130ef 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt @@ -1,6 +1,6 @@ package io.legado.app.data.dao -import androidx.paging.DataSource +import androidx.lifecycle.LiveData import androidx.room.* import io.legado.app.data.entities.SearchKeyword @@ -9,16 +9,16 @@ import io.legado.app.data.entities.SearchKeyword interface SearchKeywordDao { @Query("SELECT * FROM search_keywords ORDER BY usage DESC") - fun observeByUsage(): DataSource.Factory + fun liveDataByUsage(): LiveData> @Query("SELECT * FROM search_keywords ORDER BY lastUseTime DESC") - fun observeByTime(): DataSource.Factory + fun liveDataByTime(): LiveData> - @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(vararg keywords: SearchKeyword) + @Query("SELECT * FROM search_keywords where word like '%' | :key | '%' ORDER BY usage DESC") + fun liveDataSearch(key: String): LiveData> @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(keyword: SearchKeyword): Long + fun insert(vararg keywords: SearchKeyword) @Update fun update(vararg keywords: SearchKeyword) diff --git a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt index 7b018db40..9c8f2735c 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt @@ -4,12 +4,16 @@ import android.content.Context import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.data.entities.Book +import kotlinx.android.synthetic.main.item_text.view.* class BookAdapter(context: Context) : - SimpleRecyclerAdapter(context, R.layout.item_text) { - - override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { + SimpleRecyclerAdapter(context, R.layout.item_text) { + override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { + with(holder.itemView) { + text_view.text = item.name + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index 7ceb93993..752c1f705 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -4,13 +4,17 @@ import android.content.Context import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.data.entities.SearchKeyword +import kotlinx.android.synthetic.main.item_text.view.* class HistoryKeyAdapter(context: Context) : - SimpleRecyclerAdapter(context, R.layout.item_text) { - - override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { + SimpleRecyclerAdapter(context, R.layout.item_text) { + override fun convert(holder: ItemViewHolder, item: SearchKeyword, payloads: MutableList) { + with(holder.itemView) { + text_view.text = item.word + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 5d3299611..eae5a9ec2 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -11,11 +11,14 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.data.entities.Book +import io.legado.app.data.entities.SearchKeyword import io.legado.app.data.entities.SearchShow import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.utils.getViewModel +import io.legado.app.utils.gone import io.legado.app.utils.invisible import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_book_search.* @@ -33,6 +36,8 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se private lateinit var bookAdapter: BookAdapter private lateinit var historyKeyAdapter: HistoryKeyAdapter private var searchBookData: LiveData>? = null + private var historyData: LiveData>? = null + private var bookData: LiveData>? = null override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() @@ -67,10 +72,11 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se override fun onQueryTextChange(newText: String?): Boolean { if (newText.isNullOrBlank()) viewModel.stop() + upHistory(newText) return false } }) - search_view.setOnQueryTextFocusChangeListener { v, hasFocus -> + search_view.setOnQueryTextFocusChangeListener { _, hasFocus -> if (hasFocus) { ll_history.visible() } else { @@ -107,6 +113,27 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se searchBookData?.observe(this, Observer { adapter.submitList(it) }) } + private fun upHistory(key: String?) { + bookData?.removeObservers(this) + if (key.isNullOrBlank()) { + tv_book_show.gone() + rv_bookshelf_search.gone() + } else { + tv_book_show.visible() + rv_bookshelf_search.visible() + bookData = App.db.bookDao().liveDataSearch(key) + bookData?.observe(this, Observer { bookAdapter.setItems(it) }) + } + historyData?.removeObservers(this) + historyData = + if (key.isNullOrBlank()) { + App.db.searchKeywordDao().liveDataByUsage() + } else { + App.db.searchKeywordDao().liveDataSearch(key) + } + historyData?.observe(this, Observer { historyKeyAdapter.setItems(it) }) + } + override fun showBookInfo(name: String, author: String) { viewModel.getSearchBook(name, author) { searchBook -> searchBook?.let { diff --git a/app/src/main/res/layout/activity_book_search.xml b/app/src/main/res/layout/activity_book_search.xml index f231b65cb..246341e4c 100644 --- a/app/src/main/res/layout/activity_book_search.xml +++ b/app/src/main/res/layout/activity_book_search.xml @@ -45,8 +45,10 @@ app:layout_constraintTop_toBottomOf="@id/title_bar"> Date: Sun, 29 Sep 2019 22:06:48 +0800 Subject: [PATCH 025/140] up --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 2 +- app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index a174e0829..ccbf8e3c9 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -24,7 +24,7 @@ interface BookDao { @Query("SELECT bookUrl FROM books WHERE `group` = :group") fun observeUrlsByGroup(group: Int): LiveData> - @Query("SELECT bookUrl FROM books WHERE name like '%' | :key | '%' or author like '%' | :key | '%'") + @Query("SELECT bookUrl FROM books WHERE name like '%' || :key || '%' or author like '%' || :key || '%'") fun liveDataSearch(key: String): LiveData> @Query("SELECT * FROM books WHERE `name` in (:names)") diff --git a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt index fcd7130ef..81badc15e 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt @@ -14,7 +14,7 @@ interface SearchKeywordDao { @Query("SELECT * FROM search_keywords ORDER BY lastUseTime DESC") fun liveDataByTime(): LiveData> - @Query("SELECT * FROM search_keywords where word like '%' | :key | '%' ORDER BY usage DESC") + @Query("SELECT * FROM search_keywords where word like '%' || :key || '%' ORDER BY usage DESC") fun liveDataSearch(key: String): LiveData> @Insert(onConflict = OnConflictStrategy.REPLACE) From 39c8a1d06bc8eb31a2285b67b7af4f4750cf5aa4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 29 Sep 2019 22:12:22 +0800 Subject: [PATCH 026/140] up --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 2 +- .../main/java/io/legado/app/data/dao/SearchKeywordDao.kt | 2 +- app/src/main/res/layout/activity_book_search.xml | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index ccbf8e3c9..c74172c37 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -24,7 +24,7 @@ interface BookDao { @Query("SELECT bookUrl FROM books WHERE `group` = :group") fun observeUrlsByGroup(group: Int): LiveData> - @Query("SELECT bookUrl FROM books WHERE name like '%' || :key || '%' or author like '%' || :key || '%'") + @Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'") fun liveDataSearch(key: String): LiveData> @Query("SELECT * FROM books WHERE `name` in (:names)") diff --git a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt index 81badc15e..704f37287 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt @@ -14,7 +14,7 @@ interface SearchKeywordDao { @Query("SELECT * FROM search_keywords ORDER BY lastUseTime DESC") fun liveDataByTime(): LiveData> - @Query("SELECT * FROM search_keywords where word like '%' || :key || '%' ORDER BY usage DESC") + @Query("SELECT * FROM search_keywords where word like '%'||:key||'%' ORDER BY usage DESC") fun liveDataSearch(key: String): LiveData> @Insert(onConflict = OnConflictStrategy.REPLACE) diff --git a/app/src/main/res/layout/activity_book_search.xml b/app/src/main/res/layout/activity_book_search.xml index 246341e4c..8064c107d 100644 --- a/app/src/main/res/layout/activity_book_search.xml +++ b/app/src/main/res/layout/activity_book_search.xml @@ -49,12 +49,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="6dp" - android:text="@string/bookshelf" /> + android:text="@string/bookshelf" + android:visibility="gone" /> + android:layout_height="wrap_content" + android:visibility="gone" /> Date: Sun, 29 Sep 2019 22:20:21 +0800 Subject: [PATCH 027/140] up --- .../java/io/legado/app/data/dao/SearchKeywordDao.kt | 3 +++ .../java/io/legado/app/data/entities/SearchKeyword.kt | 2 +- .../io/legado/app/ui/book/search/SearchActivity.kt | 1 + .../io/legado/app/ui/book/search/SearchViewModel.kt | 10 ++++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt index 704f37287..be7ad75c5 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt @@ -17,6 +17,9 @@ interface SearchKeywordDao { @Query("SELECT * FROM search_keywords where word like '%'||:key||'%' ORDER BY usage DESC") fun liveDataSearch(key: String): LiveData> + @Query("select * from search_keywords where word = :key") + fun get(key: String): SearchKeyword? + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg keywords: SearchKeyword) diff --git a/app/src/main/java/io/legado/app/data/entities/SearchKeyword.kt b/app/src/main/java/io/legado/app/data/entities/SearchKeyword.kt index 1c1c5015b..89d1c3baf 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchKeyword.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchKeyword.kt @@ -13,5 +13,5 @@ data class SearchKeyword( @PrimaryKey var word: String = "", // 搜索关键词 var usage: Int = 1, // 使用次数 - var lastUseTime: Long = 0 // 最后一次使用时间 + var lastUseTime: Long = System.currentTimeMillis() // 最后一次使用时间 ) : Parcelable diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index eae5a9ec2..ed51e45df 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -58,6 +58,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se override fun onQueryTextSubmit(query: String?): Boolean { search_view.clearFocus() query?.let { + viewModel.saveSearchKey(query) viewModel.search(it, { refresh_progress_bar.isAutoLoading = true initData() diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index f8550229f..85b3694db 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -4,6 +4,7 @@ import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.SearchBook +import io.legado.app.data.entities.SearchKeyword import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers @@ -61,4 +62,13 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { success?.invoke(searchBook) } } + + fun saveSearchKey(key: String) { + execute { + App.db.searchKeywordDao().get(key)?.let { + it.usage = it.usage + 1 + App.db.searchKeywordDao().update(it) + } ?: App.db.searchKeywordDao().insert(SearchKeyword(key, 1)) + } + } } From 1743dfc1f92d63d989c42bbeac46e0567f3ff946 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 08:16:10 +0800 Subject: [PATCH 028/140] up --- app/src/main/java/io/legado/app/ui/about/DonateActivity.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt index 313a6bec6..6d0671029 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt @@ -8,11 +8,10 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import android.widget.Toast -import androidx.lifecycle.AndroidViewModel import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.lib.theme.ATH -import io.legado.app.utils.getViewModel +import io.legado.app.utils.ACache import kotlinx.android.synthetic.main.activity_donate.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.toast @@ -60,7 +59,7 @@ class DonateActivity : BaseActivity(R.layout.activity_donate) { } catch (e: Exception) { e.printStackTrace() } finally { - + ACache.get(this, cacheDir = false).put("proTime", System.currentTimeMillis()) } } From 02b27a5c5a64eaf6c6276aa228d369b5bc1cefbf Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 09:11:11 +0800 Subject: [PATCH 029/140] up --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index b8bb11427..eb72a47f4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -36,6 +36,7 @@ import io.legado.app.ui.book.source.edit.SourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity +import io.legado.app.ui.replacerule.edit.ReplaceEditDialog import io.legado.app.ui.widget.page.ChapterProvider import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.TextChapter @@ -609,7 +610,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } observeEvent(Bus.REPLACE) { - toast(it) + ReplaceEditDialog().show(supportFragmentManager, "replaceEditDialog") } } From 9a4ef149a6bedd1c94daa956911346dbfbfb9fd9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 15:52:46 +0800 Subject: [PATCH 030/140] up --- .../main/res/layout/activity_book_search.xml | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/app/src/main/res/layout/activity_book_search.xml b/app/src/main/res/layout/activity_book_search.xml index 8064c107d..4e5789b55 100644 --- a/app/src/main/res/layout/activity_book_search.xml +++ b/app/src/main/res/layout/activity_book_search.xml @@ -39,10 +39,12 @@ + app:layout_constraintTop_toBottomOf="@id/title_bar" + app:layout_constraintBottom_toBottomOf="parent"> - + android:orientation="horizontal"> + + + + + + Date: Mon, 30 Sep 2019 15:55:18 +0800 Subject: [PATCH 031/140] up --- .../io/legado/app/ui/book/search/SearchActivity.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index ed51e45df..6d5ca5563 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -120,10 +120,17 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se tv_book_show.gone() rv_bookshelf_search.gone() } else { - tv_book_show.visible() - rv_bookshelf_search.visible() bookData = App.db.bookDao().liveDataSearch(key) - bookData?.observe(this, Observer { bookAdapter.setItems(it) }) + bookData?.observe(this, Observer { + if (it.isEmpty()) { + tv_book_show.gone() + rv_bookshelf_search.gone() + } else { + tv_book_show.visible() + rv_bookshelf_search.visible() + } + bookAdapter.setItems(it) + }) } historyData?.removeObservers(this) historyData = From 1c0335b2f1ea2c4779b52488014f5bb855ba9a14 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 17:12:23 +0800 Subject: [PATCH 032/140] up --- .../legado/app/ui/book/search/BookAdapter.kt | 7 ++++++- .../app/ui/book/search/HistoryKeyAdapter.kt | 18 +++++++++++++++++- .../app/ui/book/search/SearchActivity.kt | 17 ++++++++++++++--- .../main/res/layout/activity_book_search.xml | 4 +++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt index 9c8f2735c..3a08418e1 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt @@ -6,14 +6,19 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.Book import kotlinx.android.synthetic.main.item_text.view.* +import org.jetbrains.anko.sdk27.listeners.onClick -class BookAdapter(context: Context) : +class BookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_text) { override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) { text_view.text = item.name + onClick { callBack.showBookInfo(item.bookUrl) } } } + interface CallBack { + fun showBookInfo(url: String) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index 752c1f705..48b60e9b0 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -5,16 +5,32 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SearchKeyword +import io.legado.app.ui.widget.anima.explosion_field.ExplosionField import kotlinx.android.synthetic.main.item_text.view.* +import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.sdk27.listeners.onLongClick -class HistoryKeyAdapter(context: Context) : +class HistoryKeyAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_text) { override fun convert(holder: ItemViewHolder, item: SearchKeyword, payloads: MutableList) { with(holder.itemView) { text_view.text = item.word + onClick { + callBack.searchHistory(item.word) + } + onLongClick { + it?.let { + ExplosionField(context).explode(it, true) + } + + true + } } } + interface CallBack { + fun searchHistory(key: String) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 6d5ca5563..bdf2525f0 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -27,6 +27,8 @@ import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity class SearchActivity : VMBaseActivity(R.layout.activity_book_search), + BookAdapter.CallBack, + HistoryKeyAdapter.CallBack, SearchAdapter.CallBack { override val viewModel: SearchViewModel @@ -90,11 +92,11 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se ATH.applyEdgeEffectColor(recycler_view) ATH.applyEdgeEffectColor(rv_bookshelf_search) ATH.applyEdgeEffectColor(rv_history_key) - bookAdapter = BookAdapter(this) + bookAdapter = BookAdapter(this, this) rv_bookshelf_search.layoutManager = LinearLayoutManager(this, RecyclerView.HORIZONTAL, false) rv_bookshelf_search.adapter = bookAdapter - historyKeyAdapter = HistoryKeyAdapter(this) + historyKeyAdapter = HistoryKeyAdapter(this, this) rv_history_key.layoutManager = LinearLayoutManager(this, RecyclerView.HORIZONTAL, false) rv_history_key.adapter = historyKeyAdapter adapter = SearchAdapter(this) @@ -112,9 +114,10 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se ), 30 ).build() searchBookData?.observe(this, Observer { adapter.submitList(it) }) + upHistory() } - private fun upHistory(key: String?) { + private fun upHistory(key: String? = null) { bookData?.removeObservers(this) if (key.isNullOrBlank()) { tv_book_show.gone() @@ -149,4 +152,12 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } } } + + override fun showBookInfo(url: String) { + startActivity(Pair("bookUrl", url)) + } + + override fun searchHistory(key: String) { + search_view.setQuery(key, false) + } } diff --git a/app/src/main/res/layout/activity_book_search.xml b/app/src/main/res/layout/activity_book_search.xml index 4e5789b55..ebb7a3186 100644 --- a/app/src/main/res/layout/activity_book_search.xml +++ b/app/src/main/res/layout/activity_book_search.xml @@ -43,6 +43,8 @@ android:background="@color/background" android:orientation="vertical" android:visibility="gone" + android:clickable="true" + android:focusable="true" app:layout_constraintTop_toBottomOf="@id/title_bar" app:layout_constraintBottom_toBottomOf="parent"> @@ -84,7 +86,7 @@ From 4877bad39720e5c4d5259c807a63f95a032c754f Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 18:13:11 +0800 Subject: [PATCH 033/140] up --- .../java/io/legado/app/ui/book/info/BookInfoActivity.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 8905a248c..3d170cc6e 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -183,7 +183,11 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } } } - tv_loading.onClick { } + tv_loading.onClick { + viewModel.bookData.value?.let { + viewModel.loadBookInfo(it) + } + } tv_origin.onClick { viewModel.bookData.value?.let { startActivity(Pair("data", it.origin)) From 27d076847099e1503c89a595e1b25d475e75f25b Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 18:19:56 +0800 Subject: [PATCH 034/140] up --- .../res/layout-land/activity_book_info.xml | 25 +++++++---------- .../main/res/layout/activity_book_info.xml | 27 +++++++------------ app/src/main/res/values/strings.xml | 1 + 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/app/src/main/res/layout-land/activity_book_info.xml b/app/src/main/res/layout-land/activity_book_info.xml index efc24a7a4..d043d23f7 100644 --- a/app/src/main/res/layout-land/activity_book_info.xml +++ b/app/src/main/res/layout-land/activity_book_info.xml @@ -165,7 +165,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="8dp" - android:text="简介" + android:text="@string/book_intro" android:textColor="@color/tv_text_default" android:textSize="16sp" /> @@ -192,22 +192,15 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintLeft_toRightOf="@+id/fg"> - - - - - + android:paddingLeft="8dp" + android:paddingRight="8dp" + android:paddingTop="8dp" + android:text="@string/chapter_list" + android:textColor="@color/tv_text_default" + android:textSize="16sp" /> + android:text="@string/dur_pos" /> @@ -184,22 +184,15 @@ android:layout_height="5dp" android:background="@color/bg_divider_line" /> - - - - - + android:paddingLeft="8dp" + android:paddingRight="8dp" + android:paddingTop="8dp" + android:text="@string/chapter_list" + android:textColor="@color/tv_text_default" + android:textSize="16sp" /> + android:text="@string/dur_pos" /> 编辑订阅源 筛选 筛选发现 + 当前位置: From c77c257556c41ac90dadce7b7f75aae9bd11802a Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 19:42:10 +0800 Subject: [PATCH 035/140] up --- .../io/legado/app/ui/book/search/HistoryKeyAdapter.kt | 8 +++++++- .../java/io/legado/app/ui/book/search/SearchActivity.kt | 7 +++++++ .../java/io/legado/app/ui/book/search/SearchViewModel.kt | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index 48b60e9b0..213157e90 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -1,12 +1,16 @@ package io.legado.app.ui.book.search import android.content.Context +import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SearchKeyword import io.legado.app.ui.widget.anima.explosion_field.ExplosionField import kotlinx.android.synthetic.main.item_text.view.* +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick @@ -24,7 +28,9 @@ class HistoryKeyAdapter(context: Context, val callBack: CallBack) : it?.let { ExplosionField(context).explode(it, true) } - + GlobalScope.launch(IO) { + App.db.searchKeywordDao().delete(item) + } true } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index bdf2525f0..098fe7983 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -44,6 +44,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() initSearchView() + initOtherView() initData() intent.getStringExtra("key")?.let { search_view.setQuery(it, true) @@ -105,6 +106,12 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se fb_stop.onClick { viewModel.stop() } } + private fun initOtherView() { + tv_clear_history.onClick { + viewModel.clearHistory() + } + } + private fun initData() { searchBookData?.removeObservers(this) searchBookData = LivePagedListBuilder( diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 85b3694db..011a13d8a 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -71,4 +71,10 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } ?: App.db.searchKeywordDao().insert(SearchKeyword(key, 1)) } } + + fun clearHistory() { + execute { + App.db.searchKeywordDao().deleteAll() + } + } } From e9279fd1035598916aa2e37e6d07b20d28fc01ae Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 19:43:07 +0800 Subject: [PATCH 036/140] up --- .../java/io/legado/app/ui/book/search/SearchActivity.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 098fe7983..1ed4fae13 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -103,13 +103,11 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se adapter = SearchAdapter(this) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter - fb_stop.onClick { viewModel.stop() } } private fun initOtherView() { - tv_clear_history.onClick { - viewModel.clearHistory() - } + tv_clear_history.onClick { viewModel.clearHistory() } + fb_stop.onClick { viewModel.stop() } } private fun initData() { From 5c594ffbd55de6d53700c9d602ad660a55f9dcb1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 20:25:29 +0800 Subject: [PATCH 037/140] up --- .../java/io/legado/app/base/BaseViewModel.kt | 15 ++++++++-- .../io/legado/app/help/coroutine/Coroutine.kt | 29 +++++++++++++------ .../app/ui/book/search/SearchActivity.kt | 5 +++- .../app/ui/book/search/SearchViewModel.kt | 12 +++++++- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/BaseViewModel.kt b/app/src/main/java/io/legado/app/base/BaseViewModel.kt index 1aa8452c9..d59bb15f7 100644 --- a/app/src/main/java/io/legado/app/base/BaseViewModel.kt +++ b/app/src/main/java/io/legado/app/base/BaseViewModel.kt @@ -8,17 +8,26 @@ import io.legado.app.help.coroutine.Coroutine import kotlinx.coroutines.* import org.jetbrains.anko.AnkoLogger import org.jetbrains.anko.toast +import kotlin.coroutines.CoroutineContext -open class BaseViewModel(application: Application) : AndroidViewModel(application), CoroutineScope by MainScope(), +open class BaseViewModel(application: Application) : AndroidViewModel(application), + CoroutineScope by MainScope(), AnkoLogger { val context: Context by lazy { this.getApplication() } - fun execute(scope: CoroutineScope = this, block: suspend CoroutineScope.() -> T): Coroutine { + fun execute( + scope: CoroutineScope = this, + context: CoroutineContext = scope.coroutineContext.plus(Dispatchers.IO), + block: suspend CoroutineScope.() -> T + ): Coroutine { return Coroutine.async(scope) { block() } } - fun submit(scope: CoroutineScope = this, block: suspend CoroutineScope.() -> Deferred): Coroutine { + fun submit( + scope: CoroutineScope = this, + block: suspend CoroutineScope.() -> Deferred + ): Coroutine { return Coroutine.async(scope) { block().await() } } diff --git a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt index 5b8c3d2c0..e72a3df22 100644 --- a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt +++ b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt @@ -1,18 +1,25 @@ package io.legado.app.help.coroutine -import android.util.Log import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext -class Coroutine(scope: CoroutineScope, block: suspend CoroutineScope.() -> T) { +class Coroutine( + scope: CoroutineScope, + context: CoroutineContext = scope.coroutineContext.plus(Dispatchers.IO), + block: suspend CoroutineScope.() -> T +) { companion object { val DEFAULT = MainScope() - fun async(scope: CoroutineScope = DEFAULT, block: suspend CoroutineScope.() -> T): Coroutine { - return Coroutine(scope, block) + fun async( + scope: CoroutineScope = DEFAULT, + context: CoroutineContext = scope.coroutineContext.plus(Dispatchers.IO), + block: suspend CoroutineScope.() -> T + ): Coroutine { + return Coroutine(scope, context, block) } } @@ -37,7 +44,7 @@ class Coroutine(scope: CoroutineScope, block: suspend CoroutineScope.() -> T) get() = job.isCompleted init { - this.job = executeInternal(scope, block) + this.job = executeInternal(scope, context, block) } fun timeout(timeMillis: () -> Long): Coroutine { @@ -101,11 +108,15 @@ class Coroutine(scope: CoroutineScope, block: suspend CoroutineScope.() -> T) return job.invokeOnCompletion(handler) } - private fun executeInternal(scope: CoroutineScope, block: suspend CoroutineScope.() -> T): Job { + private fun executeInternal( + scope: CoroutineScope, + context: CoroutineContext, + block: suspend CoroutineScope.() -> T + ): Job { return scope.plus(Dispatchers.Main).launch { try { start?.let { dispatchVoidCallback(this, it) } - val value = executeBlock(scope, timeMillis ?: 0L, block) + val value = executeBlock(context, timeMillis ?: 0L, block) success?.let { dispatchCallback(this, value, it) } } catch (e: Throwable) { val consume: Boolean = errorReturn?.value?.let { value -> @@ -147,11 +158,11 @@ class Coroutine(scope: CoroutineScope, block: suspend CoroutineScope.() -> T) } private suspend inline fun executeBlock( - scope: CoroutineScope, + context: CoroutineContext, timeMillis: Long, noinline block: suspend CoroutineScope.() -> T ): T? { - return withContext(scope.coroutineContext.plus(Dispatchers.IO)) { + return withContext(context) { if (timeMillis > 0L) withTimeout(timeMillis) { block() } else block() diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 1ed4fae13..bc25fa64f 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -107,7 +107,10 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se private fun initOtherView() { tv_clear_history.onClick { viewModel.clearHistory() } - fb_stop.onClick { viewModel.stop() } + fb_stop.onClick { + viewModel.stop() + refresh_progress_bar.isAutoLoading = false + } } private fun initData() { diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 011a13d8a..0890ef013 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -8,9 +8,13 @@ import io.legado.app.data.entities.SearchKeyword import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.asCoroutineDispatcher +import kotlinx.coroutines.cancel import kotlinx.coroutines.delay +import java.util.concurrent.Executors class SearchViewModel(application: Application) : BaseViewModel(application) { + private var searchPool = Executors.newFixedThreadPool(99).asCoroutineDispatcher() private var task: Coroutine<*>? = null var searchKey: String = "" var startTime: Long = 0 @@ -26,7 +30,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { searchKey = key startTime = System.currentTimeMillis() start?.invoke() - task = execute { + task = execute(context = searchPool) { //onCleared时自动取消 val bookSourceList = App.db.bookSourceDao().allEnabled for (item in bookSourceList) { @@ -53,6 +57,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } fun stop() { + searchPool.cancel() task?.cancel() } @@ -77,4 +82,9 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { App.db.searchKeywordDao().deleteAll() } } + + override fun onCleared() { + searchPool.close() + super.onCleared() + } } From a73dd8a20d96b70e5e2ee29d0ddfb90ca3f3cd45 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 20:48:54 +0800 Subject: [PATCH 038/140] up --- .../app/ui/book/info/BookInfoActivity.kt | 10 ++--- .../app/ui/book/read/ReadBookActivity.kt | 10 ++--- .../app/ui/changesource/ChangeSourceDialog.kt | 37 ++++++++----------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 3d170cc6e..74d3b4495 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -232,13 +232,11 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } } - override fun curOrigin(): String? { - return viewModel.bookData.value?.origin - } + override val curOrigin: String? + get() = viewModel.bookData.value?.origin - override fun oldBook(): Book? { - return viewModel.bookData.value - } + override val oldBook: Book? + get() = viewModel.bookData.value override fun changeTo(book: Book) { upLoading(true) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index eb72a47f4..2a3bf10a6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -330,13 +330,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea return viewModel.chapterSize } - override fun curOrigin(): String? { - return viewModel.bookData.value?.origin - } + override val curOrigin: String? + get() = viewModel.bookData.value?.origin - override fun oldBook(): Book? { - return viewModel.bookData.value - } + override val oldBook: Book? + get() = viewModel.bookData.value override fun changeTo(book: Book) { viewModel.changeTo(book) diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index 8f02698b9..674db46c1 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -35,6 +35,7 @@ class ChangeSourceDialog : DialogFragment(), } } + private var callBack: CallBack? = null private lateinit var viewModel: ChangeSourceViewModel private lateinit var changeSourceAdapter: ChangeSourceAdapter @@ -49,6 +50,7 @@ class ChangeSourceDialog : DialogFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + callBack = activity as? CallBack viewModel.searchStateData.observe(viewLifecycleOwner, Observer { refresh_progress_bar.isAutoLoading = it }) @@ -114,31 +116,24 @@ class ChangeSourceDialog : DialogFragment(), } override fun changeTo(searchBook: SearchBook) { - val activity = activity - if (activity is CallBack) { - val book = searchBook.toBook() - activity.oldBook()?.let { oldBook -> - book.durChapterIndex = oldBook.durChapterIndex - book.durChapterPos = oldBook.durChapterPos - book.durChapterTitle = oldBook.durChapterTitle - book.customCoverUrl = oldBook.customCoverUrl - book.customIntro = oldBook.customIntro - book.order = oldBook.order - if (book.coverUrl.isNullOrEmpty()) { - book.coverUrl = oldBook.getDisplayCover() - } - activity.changeTo(book) + val book = searchBook.toBook() + callBack?.oldBook?.let { oldBook -> + book.durChapterIndex = oldBook.durChapterIndex + book.durChapterPos = oldBook.durChapterPos + book.durChapterTitle = oldBook.durChapterTitle + book.customCoverUrl = oldBook.customCoverUrl + book.customIntro = oldBook.customIntro + book.order = oldBook.order + if (book.coverUrl.isNullOrEmpty()) { + book.coverUrl = oldBook.getDisplayCover() } + callBack?.changeTo(book) } dismiss() } override fun curOrigin(): String { - val activity = activity - if (activity is CallBack) { - return activity.curOrigin() ?: "" - } - return "" + return callBack?.curOrigin ?: "" } override fun adapter(): ChangeSourceAdapter { @@ -146,8 +141,8 @@ class ChangeSourceDialog : DialogFragment(), } interface CallBack { - fun curOrigin(): String? - fun oldBook(): Book? + val curOrigin: String? + val oldBook: Book? fun changeTo(book: Book) } From ddb55cfc52cc545ff1b19a15f22efd7060e60339 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 20:55:55 +0800 Subject: [PATCH 039/140] up --- app/src/main/java/io/legado/app/base/BaseViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/base/BaseViewModel.kt b/app/src/main/java/io/legado/app/base/BaseViewModel.kt index d59bb15f7..e9bae2236 100644 --- a/app/src/main/java/io/legado/app/base/BaseViewModel.kt +++ b/app/src/main/java/io/legado/app/base/BaseViewModel.kt @@ -21,7 +21,7 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio context: CoroutineContext = scope.coroutineContext.plus(Dispatchers.IO), block: suspend CoroutineScope.() -> T ): Coroutine { - return Coroutine.async(scope) { block() } + return Coroutine.async(scope, context) { block() } } fun submit( From a083bf31b468d93e528eecd44947aefe91f73682 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 21:00:12 +0800 Subject: [PATCH 040/140] up --- .../main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index cb54f4df1..8c00a19d4 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -134,6 +134,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { App.db.bookChapterDao().insert(*chapters.toTypedArray()) bookData.postValue(book) chapterListData.postValue(chapters) + }.onError { + it.printStackTrace() } } From d6832a91ecdac1ad45eb28d2a500295a861a7ebf Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 21:49:40 +0800 Subject: [PATCH 041/140] up --- app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt | 4 ++++ .../main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt index e72a3df22..c61efdd23 100644 --- a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt +++ b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt @@ -1,5 +1,6 @@ package io.legado.app.help.coroutine +import io.legado.app.BuildConfig import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext @@ -119,6 +120,9 @@ class Coroutine( val value = executeBlock(context, timeMillis ?: 0L, block) success?.let { dispatchCallback(this, value, it) } } catch (e: Throwable) { + if (BuildConfig.DEBUG) { + e.printStackTrace() + } val consume: Boolean = errorReturn?.value?.let { value -> success?.let { dispatchCallback(this, value, it) } true diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 8c00a19d4..cb54f4df1 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -134,8 +134,6 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { App.db.bookChapterDao().insert(*chapters.toTypedArray()) bookData.postValue(book) chapterListData.postValue(chapters) - }.onError { - it.printStackTrace() } } From 0b2007870f99eefc9b3bd788113ec83bb6b8a1cd Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 21:53:23 +0800 Subject: [PATCH 042/140] up --- .../main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 1 - .../main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt | 3 +-- .../main/java/io/legado/app/ui/book/search/SearchViewModel.kt | 2 -- .../main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt | 2 -- app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 3 --- 5 files changed, 1 insertion(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index cb54f4df1..7b9ee2118 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -99,7 +99,6 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } }.onError { toast(R.string.error_get_chapter_list) - it.printStackTrace() } } ?: toast(R.string.error_no_source) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index a0b02a402..d6d6ae004 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -68,7 +68,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } saveRead(book) - }.onError { it.printStackTrace() } + } } private fun loadBookInfo( @@ -103,7 +103,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } }?.onError { toast(R.string.error_load_toc) - it.printStackTrace() } ?: autoChangeSource() } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 0890ef013..c70078a45 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -47,8 +47,6 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } delay(100)//每隔100毫秒搜索一个书源 } - }.onError { - it.printStackTrace() } task?.invokeOnCompletion { diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt index f36a5fc69..a9514c8e4 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt @@ -39,8 +39,6 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application App.db.searchBookDao().insert(*searchBooks.toTypedArray()) page++ } - }.onError { - it.printStackTrace() } } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 3a9c1db32..992ed6a16 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -38,9 +38,6 @@ class MainViewModel(application: Application) : BaseViewModel(application) { App.db.bookChapterDao().insert(*it.toTypedArray()) } } - .onError { - it.printStackTrace() - } .onFinally { synchronized(this) { updateList.remove(book.bookUrl) From e362ab2ad955bef4ea114c257271089e4eb3282f Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 22:21:36 +0800 Subject: [PATCH 043/140] up --- .../main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt | 2 +- .../io/legado/app/ui/widget/anima/explosion_field/Utils.kt | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index bc38b8571..c04981cdd 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -445,7 +445,7 @@ class AnalyzeRule(private var book: BaseBook? = null) { } //分离正则表达式 val ruleStrS = - rule.trim { it <= ' ' }.splitNotBlank("##") + rule.trim { it <= ' ' }.split("##") rule = ruleStrS[0] if (ruleStrS.size > 1) { replaceRegex = ruleStrS[1] diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/Utils.kt b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/Utils.kt index 2f99191d2..6e33941fb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/Utils.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/Utils.kt @@ -22,6 +22,7 @@ import android.graphics.Canvas import android.graphics.drawable.BitmapDrawable import android.view.View import android.widget.ImageView +import kotlin.math.roundToInt object Utils { @@ -29,7 +30,7 @@ object Utils { private val sCanvas = Canvas() fun dp2Px(dp: Int): Int { - return Math.round(dp * DENSITY) + return (dp * DENSITY).roundToInt() } fun createBitmapFromView(view: View): Bitmap? { @@ -55,7 +56,7 @@ object Utils { return bitmap } - fun createBitmapSafely( + private fun createBitmapSafely( width: Int, height: Int, config: Bitmap.Config, From 11d7133f93042f6c64c32c8806ea4c9e40ceb527 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 22:38:46 +0800 Subject: [PATCH 044/140] up --- .../main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 7b9ee2118..dc96b4c0c 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -129,7 +129,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { chapters ) book.durChapterTitle = chapters[book.durChapterIndex].title - App.db.bookDao().update(book) + App.db.bookDao().insert(book) App.db.bookChapterDao().insert(*chapters.toTypedArray()) bookData.postValue(book) chapterListData.postValue(chapters) From cde3bcf0cb2829cf2cc77fa09134763f9bf7b4c6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 22:57:32 +0800 Subject: [PATCH 045/140] up --- app/src/main/java/io/legado/app/base/BaseViewModel.kt | 2 ++ .../app/ui/changesource/ChangeSourceViewModel.kt | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/base/BaseViewModel.kt b/app/src/main/java/io/legado/app/base/BaseViewModel.kt index e9bae2236..98e09354b 100644 --- a/app/src/main/java/io/legado/app/base/BaseViewModel.kt +++ b/app/src/main/java/io/legado/app/base/BaseViewModel.kt @@ -2,6 +2,7 @@ package io.legado.app.base import android.app.Application import android.content.Context +import androidx.annotation.CallSuper import androidx.lifecycle.AndroidViewModel import io.legado.app.App import io.legado.app.help.coroutine.Coroutine @@ -31,6 +32,7 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio return Coroutine.async(scope) { block().await() } } + @CallSuper override fun onCleared() { super.onCleared() cancel() diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index db4a5e889..cd67d50ec 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -12,11 +12,14 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.delay import kotlinx.coroutines.withContext import org.jetbrains.anko.debug +import java.util.concurrent.Executors class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { + private var searchPool = Executors.newFixedThreadPool(99).asCoroutineDispatcher() var callBack: CallBack? = null val searchStateData = MutableLiveData() var name: String = "" @@ -51,7 +54,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } fun search() { - task = execute { + task = execute(context = searchPool) { searchStateData.postValue(true) val bookSourceList = App.db.bookSourceDao().allEnabled for (item in bookSourceList) { @@ -130,4 +133,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio interface CallBack { fun adapter(): ChangeSourceAdapter } + + override fun onCleared() { + searchPool.close() + super.onCleared() + } } \ No newline at end of file From 86a99da671fa7a75475d9eeddcfc6c3b2cefec6f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 11:51:15 +0800 Subject: [PATCH 046/140] up --- app/src/main/java/io/legado/app/base/BaseViewModel.kt | 5 +++-- .../main/java/io/legado/app/help/coroutine/Coroutine.kt | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/BaseViewModel.kt b/app/src/main/java/io/legado/app/base/BaseViewModel.kt index 98e09354b..3610a00a5 100644 --- a/app/src/main/java/io/legado/app/base/BaseViewModel.kt +++ b/app/src/main/java/io/legado/app/base/BaseViewModel.kt @@ -19,7 +19,7 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio fun execute( scope: CoroutineScope = this, - context: CoroutineContext = scope.coroutineContext.plus(Dispatchers.IO), + context: CoroutineContext = Dispatchers.IO, block: suspend CoroutineScope.() -> T ): Coroutine { return Coroutine.async(scope, context) { block() } @@ -27,9 +27,10 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio fun submit( scope: CoroutineScope = this, + context: CoroutineContext = Dispatchers.IO, block: suspend CoroutineScope.() -> Deferred ): Coroutine { - return Coroutine.async(scope) { block().await() } + return Coroutine.async(scope, context) { block().await() } } @CallSuper diff --git a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt index c61efdd23..e9fd0df86 100644 --- a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt +++ b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt @@ -7,7 +7,7 @@ import kotlin.coroutines.CoroutineContext class Coroutine( scope: CoroutineScope, - context: CoroutineContext = scope.coroutineContext.plus(Dispatchers.IO), + context: CoroutineContext = Dispatchers.IO, block: suspend CoroutineScope.() -> T ) { @@ -17,7 +17,7 @@ class Coroutine( fun async( scope: CoroutineScope = DEFAULT, - context: CoroutineContext = scope.coroutineContext.plus(Dispatchers.IO), + context: CoroutineContext = Dispatchers.IO, block: suspend CoroutineScope.() -> T ): Coroutine { return Coroutine(scope, context, block) @@ -117,7 +117,7 @@ class Coroutine( return scope.plus(Dispatchers.Main).launch { try { start?.let { dispatchVoidCallback(this, it) } - val value = executeBlock(context, timeMillis ?: 0L, block) + val value = executeBlock(scope, context, timeMillis ?: 0L, block) success?.let { dispatchCallback(this, value, it) } } catch (e: Throwable) { if (BuildConfig.DEBUG) { @@ -162,11 +162,12 @@ class Coroutine( } private suspend inline fun executeBlock( + scope: CoroutineScope, context: CoroutineContext, timeMillis: Long, noinline block: suspend CoroutineScope.() -> T ): T? { - return withContext(context) { + return withContext(scope.coroutineContext.plus(context)) { if (timeMillis > 0L) withTimeout(timeMillis) { block() } else block() From 8d7bdb3ad10525674483febf8816b2af6455c2bf Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 11:58:54 +0800 Subject: [PATCH 047/140] up --- .../main/java/io/legado/app/ui/book/search/SearchViewModel.kt | 4 +--- .../io/legado/app/ui/changesource/ChangeSourceViewModel.kt | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index c70078a45..de1131371 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -9,7 +9,6 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.asCoroutineDispatcher -import kotlinx.coroutines.cancel import kotlinx.coroutines.delay import java.util.concurrent.Executors @@ -55,7 +54,6 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } fun stop() { - searchPool.cancel() task?.cancel() } @@ -82,7 +80,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } override fun onCleared() { - searchPool.close() super.onCleared() + searchPool.close() } } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index cd67d50ec..f3a468da1 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -135,7 +135,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } override fun onCleared() { - searchPool.close() super.onCleared() + searchPool.close() } } \ No newline at end of file From 423cff9d9576e89deefdc72101ae5731c5f23458 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 12:51:27 +0800 Subject: [PATCH 048/140] up --- .../main/java/io/legado/app/ui/book/search/SearchViewModel.kt | 2 +- .../java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index de1131371..b754f91f1 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -13,7 +13,7 @@ import kotlinx.coroutines.delay import java.util.concurrent.Executors class SearchViewModel(application: Application) : BaseViewModel(application) { - private var searchPool = Executors.newFixedThreadPool(99).asCoroutineDispatcher() + private var searchPool = Executors.newFixedThreadPool(16).asCoroutineDispatcher() private var task: Coroutine<*>? = null var searchKey: String = "" var startTime: Long = 0 diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index f3a468da1..265dcc227 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -19,7 +19,7 @@ import org.jetbrains.anko.debug import java.util.concurrent.Executors class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { - private var searchPool = Executors.newFixedThreadPool(99).asCoroutineDispatcher() + private var searchPool = Executors.newFixedThreadPool(16).asCoroutineDispatcher() var callBack: CallBack? = null val searchStateData = MutableLiveData() var name: String = "" From 3e808b12dc7aeb3c8ce6f0f35a41c6d4feaf2507 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 12:57:17 +0800 Subject: [PATCH 049/140] up --- .../main/java/io/legado/app/model/WebBook.kt | 40 +++++++++++++------ .../app/ui/book/search/SearchViewModel.kt | 9 ++++- .../ui/changesource/ChangeSourceViewModel.kt | 4 +- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index a09e9f326..9201fd542 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -11,6 +11,8 @@ import io.legado.app.model.webbook.BookContent import io.legado.app.model.webbook.BookInfo import io.legado.app.model.webbook.BookList import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlin.coroutines.CoroutineContext class WebBook(val bookSource: BookSource) { @@ -20,9 +22,13 @@ class WebBook(val bookSource: BookSource) { /** * 搜索 */ - fun searchBook(key: String, page: Int? = 1, scope: CoroutineScope = Coroutine.DEFAULT) - : Coroutine> { - return Coroutine.async(scope) { + fun searchBook( + key: String, + page: Int? = 1, + scope: CoroutineScope = Coroutine.DEFAULT, + context: CoroutineContext = Dispatchers.IO + ): Coroutine> { + return Coroutine.async(scope, context) { bookSource.searchUrl?.let { searchUrl -> val analyzeUrl = AnalyzeUrl( ruleUrl = searchUrl, @@ -40,9 +46,13 @@ class WebBook(val bookSource: BookSource) { /** * 发现 */ - fun exploreBook(url: String, page: Int? = 1, scope: CoroutineScope = Coroutine.DEFAULT) - : Coroutine> { - return Coroutine.async(scope) { + fun exploreBook( + url: String, + page: Int? = 1, + scope: CoroutineScope = Coroutine.DEFAULT, + context: CoroutineContext = Dispatchers.IO + ): Coroutine> { + return Coroutine.async(scope, context) { val analyzeUrl = AnalyzeUrl( ruleUrl = url, page = page, @@ -57,8 +67,12 @@ class WebBook(val bookSource: BookSource) { /** * 书籍信息 */ - fun getBookInfo(book: Book, scope: CoroutineScope = Coroutine.DEFAULT): Coroutine { - return Coroutine.async(scope) { + fun getBookInfo( + book: Book, + scope: CoroutineScope = Coroutine.DEFAULT, + context: CoroutineContext = Dispatchers.IO + ): Coroutine { + return Coroutine.async(scope, context) { val analyzeUrl = AnalyzeUrl( book = book, ruleUrl = book.bookUrl, @@ -76,9 +90,10 @@ class WebBook(val bookSource: BookSource) { */ fun getChapterList( book: Book, - scope: CoroutineScope = Coroutine.DEFAULT + scope: CoroutineScope = Coroutine.DEFAULT, + context: CoroutineContext = Dispatchers.IO ): Coroutine> { - return Coroutine.async(scope) { + return Coroutine.async(scope, context) { val analyzeUrl = AnalyzeUrl( book = book, ruleUrl = book.tocUrl, @@ -97,9 +112,10 @@ class WebBook(val bookSource: BookSource) { book: Book, bookChapter: BookChapter, nextChapterUrl: String? = null, - scope: CoroutineScope = Coroutine.DEFAULT + scope: CoroutineScope = Coroutine.DEFAULT, + context: CoroutineContext = Dispatchers.IO ): Coroutine { - return Coroutine.async(scope) { + return Coroutine.async(scope, context) { val analyzeUrl = AnalyzeUrl( book = book, diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index b754f91f1..a9e84bf0d 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -29,12 +29,17 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { searchKey = key startTime = System.currentTimeMillis() start?.invoke() - task = execute(context = searchPool) { + task = execute { //onCleared时自动取消 val bookSourceList = App.db.bookSourceDao().allEnabled for (item in bookSourceList) { //task取消时自动取消 by (scope = this@execute) - WebBook(item).searchBook(key, searchPage, scope = this@execute) + WebBook(item).searchBook( + key, + searchPage, + scope = this@execute, + context = searchPool + ) .timeout(30000L) .onSuccess(Dispatchers.IO) { it?.let { list -> diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 265dcc227..9843ec994 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -54,12 +54,12 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } fun search() { - task = execute(context = searchPool) { + task = execute { searchStateData.postValue(true) val bookSourceList = App.db.bookSourceDao().allEnabled for (item in bookSourceList) { //task取消时自动取消 by (scope = this@execute) - WebBook(item).searchBook(name, scope = this@execute) + WebBook(item).searchBook(name, scope = this@execute, context = searchPool) .timeout(30000L) .onSuccess(IO) { it?.forEach { searchBook -> From 97c8fa5953d700bede7a315cc47dfa9a33018a62 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 17:29:54 +0800 Subject: [PATCH 050/140] up --- .../main/java/io/legado/app/ui/book/search/SearchViewModel.kt | 2 -- .../java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index a9e84bf0d..0c21d1820 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -9,7 +9,6 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.asCoroutineDispatcher -import kotlinx.coroutines.delay import java.util.concurrent.Executors class SearchViewModel(application: Application) : BaseViewModel(application) { @@ -49,7 +48,6 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } } } - delay(100)//每隔100毫秒搜索一个书源 } } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 9843ec994..44483aa07 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -13,7 +13,6 @@ import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.asCoroutineDispatcher -import kotlinx.coroutines.delay import kotlinx.coroutines.withContext import org.jetbrains.anko.debug import java.util.concurrent.Executors @@ -73,7 +72,6 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } } } - delay(100) } } From 91e3ae3c5d0e60b20f14f2bfb30c12f0637cee1d Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 17:54:35 +0800 Subject: [PATCH 051/140] up --- app/src/main/java/io/legado/app/utils/LogUtils.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index f8b8b6bb6..3dd8f3dfe 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -30,8 +30,10 @@ object LogUtils { } private val fileHandler by lazy { + val logFolder = FileHelp.getCachePath() + File.separator + "logs" + FileHelp.getFolder(logFolder) FileHandler( - FileHelp.getCachePath() + File.separator + "logs" + File.separator + "app.log", + logFolder + File.separator + "app.log", 2048, 10 ).apply { From 5c3d50657ab8eb879d8366c4868b24e3473565a4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 18:54:45 +0800 Subject: [PATCH 052/140] up --- .../io/legado/app/data/entities/EditEntity.kt | 3 + .../ui/book/source/edit/SourceEditActivity.kt | 2 +- .../ui/book/source/edit/SourceEditAdapter.kt | 5 +- .../rss/source/edit/RssSourceEditActivity.kt | 1 + .../rss/source/edit/RssSourceEditAdapter.kt | 85 +++++++++++++++++++ .../res/layout/activity_rss_source_edit.xml | 4 + 6 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/io/legado/app/data/entities/EditEntity.kt create mode 100644 app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt diff --git a/app/src/main/java/io/legado/app/data/entities/EditEntity.kt b/app/src/main/java/io/legado/app/data/entities/EditEntity.kt new file mode 100644 index 000000000..d4c1ecc1a --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/EditEntity.kt @@ -0,0 +1,3 @@ +package io.legado.app.data.entities + +data class EditEntity(var key: String, var value: String?, var hint: Int) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt index 8a2db83d6..3abcbcacf 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt @@ -19,6 +19,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppConst import io.legado.app.data.entities.BookSource +import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.rule.* import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.source.debug.SourceDebugActivity @@ -618,5 +619,4 @@ class SourceEditActivity : } } - class EditEntity(var key: String, var value: String?, var hint: Int) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt index 3ac5fc3d1..434f2071a 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt @@ -7,11 +7,12 @@ import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import io.legado.app.R +import io.legado.app.data.entities.EditEntity import kotlinx.android.synthetic.main.item_source_edit.view.* class SourceEditAdapter : RecyclerView.Adapter() { - var editEntities: ArrayList = ArrayList() + var editEntities: ArrayList = ArrayList() set(value) { field = value notifyDataSetChanged() @@ -34,7 +35,7 @@ class SourceEditAdapter : RecyclerView.Adapter() } class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { - fun bind(editEntity: SourceEditActivity.EditEntity) = with(itemView) { + fun bind(editEntity: EditEntity) = with(itemView) { if (editText.getTag(R.id.tag1) == null) { val listener = object : View.OnAttachStateChangeListener { override fun onViewAttachedToWindow(v: View) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index e58ba568c..40ce0ba97 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -16,4 +16,5 @@ class RssSourceEditActivity : } + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt new file mode 100644 index 000000000..78e0740ef --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt @@ -0,0 +1,85 @@ +package io.legado.app.ui.rss.source.edit + +import android.text.Editable +import android.text.TextWatcher +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import io.legado.app.R +import io.legado.app.data.entities.EditEntity +import kotlinx.android.synthetic.main.item_source_edit.view.* + +class RssSourceEditAdapter : RecyclerView.Adapter() { + + var editEntities: ArrayList = ArrayList() + set(value) { + field = value + notifyDataSetChanged() + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { + return MyViewHolder( + LayoutInflater.from( + parent.context + ).inflate(R.layout.item_source_edit, parent, false) + ) + } + + override fun onBindViewHolder(holder: MyViewHolder, position: Int) { + holder.bind(editEntities[position]) + } + + override fun getItemCount(): Int { + return editEntities.size + } + + class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { + fun bind(editEntity: EditEntity) = with(itemView) { + if (editText.getTag(R.id.tag1) == null) { + val listener = object : View.OnAttachStateChangeListener { + override fun onViewAttachedToWindow(v: View) { + editText.isCursorVisible = false + editText.isCursorVisible = true + editText.isFocusable = true + editText.isFocusableInTouchMode = true + } + + override fun onViewDetachedFromWindow(v: View) { + + } + } + editText.addOnAttachStateChangeListener(listener) + editText.setTag(R.id.tag1, listener) + } + editText.getTag(R.id.tag2)?.let { + if (it is TextWatcher) { + editText.removeTextChangedListener(it) + } + } + editText.setText(editEntity.value) + textInputLayout.hint = context.getString(editEntity.hint) + val textWatcher = object : TextWatcher { + override fun beforeTextChanged( + s: CharSequence, + start: Int, + count: Int, + after: Int + ) { + + } + + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + + } + + override fun afterTextChanged(s: Editable?) { + editEntity.value = (s?.toString()) + } + } + editText.addTextChangedListener(textWatcher) + editText.setTag(R.id.tag2, textWatcher) + } + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_rss_source_edit.xml b/app/src/main/res/layout/activity_rss_source_edit.xml index 437330f50..5579d3de5 100644 --- a/app/src/main/res/layout/activity_rss_source_edit.xml +++ b/app/src/main/res/layout/activity_rss_source_edit.xml @@ -13,5 +13,9 @@ app:displayHomeAsUp="true" app:title="@string/rss_source_edit" /> + \ No newline at end of file From 358f955071eae78be7a6d7ee7d91c79b136307ea Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 19:44:52 +0800 Subject: [PATCH 053/140] up --- .../ui/book/source/edit/SourceEditActivity.kt | 6 +- .../rss/source/edit/RssSourceEditActivity.kt | 90 ++++++++++++++++++- .../legado/app/ui/widget/KeyboardToolPop.kt | 8 +- 3 files changed, 96 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt index 3abcbcacf..4a9cc535f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt @@ -34,7 +34,7 @@ import kotlin.math.abs class SourceEditActivity : VMBaseActivity(R.layout.activity_book_source_edit, false), - KeyboardToolPop.OnClickListener { + KeyboardToolPop.CallBack { override val viewModel: SourceEditViewModel get() = getViewModel(SourceEditViewModel::class.java) @@ -92,7 +92,7 @@ class SourceEditActivity : toast("书源名称和URL不能为空") } else { viewModel.save(bookSource) { - startActivity("key" to bookSource.bookSourceUrl) + startActivity(Pair("key", bookSource.bookSourceUrl)) } } } @@ -567,7 +567,7 @@ class SourceEditActivity : return source } - override fun click(text: String) { + override fun sendText(text: String) { if (text.isBlank()) return val view = window.decorView.findFocus() if (view is EditText) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 40ce0ba97..effc75a44 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -1,20 +1,108 @@ package io.legado.app.ui.rss.source.edit +import android.graphics.Rect import android.os.Bundle +import android.view.Gravity +import android.view.Menu +import android.view.ViewTreeObserver +import android.widget.EditText +import android.widget.PopupWindow +import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.AppConst +import io.legado.app.lib.theme.ATH +import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.utils.getViewModel +import kotlinx.android.synthetic.main.activity_book_source_edit.* +import org.jetbrains.anko.displayMetrics +import kotlin.math.abs class RssSourceEditActivity : - VMBaseActivity(R.layout.activity_rss_source_edit, false) { + VMBaseActivity(R.layout.activity_rss_source_edit, false), + KeyboardToolPop.CallBack { + + private var mSoftKeyboardTool: PopupWindow? = null + private var mIsSoftKeyBoardShowing = false + + private lateinit var adapter: RssSourceEditAdapter override val viewModel: RssSourceEditViewModel get() = getViewModel(RssSourceEditViewModel::class.java) override fun onActivityCreated(savedInstanceState: Bundle?) { + initView() + } + + override fun onDestroy() { + super.onDestroy() + mSoftKeyboardTool?.dismiss() + } + + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.source_edit, menu) + return super.onCompatCreateOptionsMenu(menu) + } + private fun initView() { + ATH.applyEdgeEffectColor(recycler_view) + mSoftKeyboardTool = KeyboardToolPop(this, AppConst.keyboardToolChars, this) + window.decorView.viewTreeObserver.addOnGlobalLayoutListener(KeyboardOnGlobalChangeListener()) + recycler_view.layoutManager = LinearLayoutManager(this) + recycler_view.adapter = adapter } + override fun sendText(text: String) { + if (text.isBlank()) return + val view = window.decorView.findFocus() + if (view is EditText) { + val start = view.selectionStart + val end = view.selectionEnd + val edit = view.editableText//获取EditText的文字 + if (start < 0 || start >= edit.length) { + edit.append(text) + } else { + edit.replace(start, end, text)//光标所在位置插入文字 + } + } + } + + private fun showKeyboardTopPopupWindow() { + mSoftKeyboardTool?.isShowing?.let { if (it) return } + if (!isFinishing) { + mSoftKeyboardTool?.showAtLocation(ll_content, Gravity.BOTTOM, 0, 0) + } + } + + private fun closePopupWindow() { + mSoftKeyboardTool?.let { + if (it.isShowing) { + it.dismiss() + } + } + } + + private inner class KeyboardOnGlobalChangeListener : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + val rect = Rect() + // 获取当前页面窗口的显示范围 + window.decorView.getWindowVisibleDisplayFrame(rect) + val screenHeight = this@RssSourceEditActivity.displayMetrics.heightPixels + val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 + val preShowing = mIsSoftKeyBoardShowing + if (abs(keyboardHeight) > screenHeight / 5) { + mIsSoftKeyBoardShowing = true // 超过屏幕五分之一则表示弹出了输入法 + recycler_view.setPadding(0, 0, 0, 100) + showKeyboardTopPopupWindow() + } else { + mIsSoftKeyBoardShowing = false + recycler_view.setPadding(0, 0, 0, 0) + if (preShowing) { + closePopupWindow() + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt index 57f40c039..40e321b87 100644 --- a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt +++ b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt @@ -18,7 +18,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class KeyboardToolPop( context: Context, private val chars: List, - val onClickListener: OnClickListener? + val callBack: CallBack? ) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) { init { @@ -45,13 +45,13 @@ class KeyboardToolPop( override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { with(holder.itemView) { text_view.text = item - onClick { onClickListener?.click(item) } + onClick { callBack?.sendText(item) } } } } - interface OnClickListener { - fun click(text: String) + interface CallBack { + fun sendText(text: String) } } From 498cbf99a5299663b50cf5b1a7d765ffbf3989b7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 19:55:31 +0800 Subject: [PATCH 054/140] up --- .../io/legado/app/data/dao/RssSourceDao.kt | 3 +++ .../io/legado/app/data/entities/RssSource.kt | 6 +++--- .../rss/source/edit/RssSourceEditActivity.kt | 18 ++++++++++++++++++ .../rss/source/edit/RssSourceEditViewModel.kt | 13 +++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index 999898598..d6b2d7767 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -7,6 +7,9 @@ import io.legado.app.data.entities.RssSource @Dao interface RssSourceDao { + @Query("select * from rssSources where sourceUrl = :key") + fun getByKey(key: String): RssSource? + @get:Query("SELECT * FROM rssSources") val all: List diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index 17a7064e9..7a1d8d045 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -8,10 +8,10 @@ import kotlinx.android.parcel.Parcelize @Parcelize @Entity(tableName = "rssSources") data class RssSource( - var sourceName: String, + var sourceName: String = "", @PrimaryKey - var sourceUrl: String, - var iconUrl: String, + var sourceUrl: String = "", + var iconUrl: String = "", var enabled: Boolean = true, var ruleGuid: String? = null, var ruleTitle: String? = null, diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index effc75a44..afffb7b97 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -7,10 +7,12 @@ import android.view.Menu import android.view.ViewTreeObserver import android.widget.EditText import android.widget.PopupWindow +import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppConst +import io.legado.app.data.entities.RssSource import io.legado.app.lib.theme.ATH import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.utils.getViewModel @@ -33,6 +35,19 @@ class RssSourceEditActivity : override fun onActivityCreated(savedInstanceState: Bundle?) { initView() + viewModel.sourceLiveData.observe(this, Observer { + upRecyclerView(it) + }) + if (viewModel.sourceLiveData.value == null) { + val sourceID = intent.getStringExtra("data") + if (sourceID == null) { + upRecyclerView(null) + } else { + sourceID.let { viewModel.setSource(sourceID) } + } + } else { + upRecyclerView(viewModel.sourceLiveData.value) + } } override fun onDestroy() { @@ -53,6 +68,9 @@ class RssSourceEditActivity : recycler_view.adapter = adapter } + private fun upRecyclerView(rssSource: RssSource?) { + + } override fun sendText(text: String) { if (text.isBlank()) return diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index fdb353c69..53f7d01de 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -1,9 +1,22 @@ package io.legado.app.ui.rss.source.edit import android.app.Application +import androidx.lifecycle.MutableLiveData +import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.data.entities.RssSource class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { + val sourceLiveData: MutableLiveData = MutableLiveData() + + fun setSource(key: String) { + execute { + App.db.rssSourceDao().getByKey(key)?.let { + sourceLiveData.postValue(it) + } ?: sourceLiveData.postValue(RssSource()) + } + } + } \ No newline at end of file From 4ff6ea6653dd6cc4e0ebb4ee6c7d1006bd386ee0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 22:09:52 +0800 Subject: [PATCH 055/140] up --- .../io/legado/app/data/entities/RssSource.kt | 8 +- .../ui/book/source/edit/SourceEditActivity.kt | 358 ++++-------------- .../rss/source/edit/RssSourceEditActivity.kt | 29 ++ app/src/main/res/values/strings.xml | 15 + 4 files changed, 113 insertions(+), 297 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index 7a1d8d045..d17ab598d 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -16,11 +16,13 @@ data class RssSource( var ruleGuid: String? = null, var ruleTitle: String? = null, var ruleAuthor: String? = null, - var ruleLink: String? = null, var rulePubDate: String? = null, + //类别 + var ruleCategories: String? = null, + //描述 var ruleDescription: String? = null, - var ruleContent: String? = null, var ruleImage: String? = null, - var ruleCategories: String? = null, + var ruleContent: String? = null, + var ruleLink: String? = null, var customOrder: Int = 0 ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt index 4a9cc535f..c7e6dbbf5 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt @@ -146,322 +146,92 @@ class SourceEditActivity : cb_is_enable_find.isChecked = it.enabledExplore } //基本信息 - with(bookSource) { - sourceEntities.clear() - sourceEntities - .add( - EditEntity( - "bookSourceUrl", - this?.bookSourceUrl, - R.string.book_source_url - ) - ) - sourceEntities - .add( - EditEntity( - "bookSourceName", - this?.bookSourceName, - R.string.book_source_name - ) - ) - sourceEntities.add( + sourceEntities.clear() + searchEntities.apply { + add(EditEntity("bookSourceUrl", bookSource?.bookSourceUrl, R.string.book_source_url)) + add(EditEntity("bookSourceName", bookSource?.bookSourceName, R.string.book_source_name)) + add( EditEntity( "bookSourceGroup", - this?.bookSourceGroup, + bookSource?.bookSourceGroup, R.string.book_source_group ) ) - sourceEntities - .add( - EditEntity( - "loginUrl", - this?.loginUrl, - R.string.book_source_login_url - ) - ) - sourceEntities - .add( - EditEntity( - "bookUrlPattern", - this?.bookUrlPattern, - R.string.book_url_pattern - ) - ) - sourceEntities.add( - EditEntity( - "header", - this?.header, - R.string.source_http_header - ) - ) + add(EditEntity("loginUrl", bookSource?.loginUrl, R.string.book_source_login_url)) + add(EditEntity("bookUrlPattern", bookSource?.bookUrlPattern, R.string.book_url_pattern)) + add(EditEntity("header", bookSource?.header, R.string.source_http_header)) } //搜索 - with(bookSource?.getSearchRule()) { + (bookSource?.getSearchRule()).let { searchRule -> searchEntities.clear() - searchEntities - .add( - EditEntity( - "searchUrl", - bookSource?.searchUrl, - R.string.rule_search_url - ) - ) - searchEntities.add( - EditEntity( - "bookList", - this?.bookList, - R.string.rule_book_list - ) - ) - searchEntities.add( - EditEntity( - "name", - this?.name, - R.string.rule_book_name - ) - ) - searchEntities.add( - EditEntity( - "author", - this?.author, - R.string.rule_book_author - ) - ) - searchEntities.add( - EditEntity( - "kind", - this?.kind, - R.string.rule_book_kind - ) - ) - searchEntities.add( - EditEntity( - "wordCount", - this?.wordCount, - R.string.rule_word_count - ) - ) - searchEntities - .add( - EditEntity( - "lastChapter", - this?.lastChapter, - R.string.rule_last_chapter - ) - ) - searchEntities.add( - EditEntity( - "intro", - this?.intro, - R.string.rule_book_intro - ) - ) - searchEntities.add( - EditEntity( - "coverUrl", - this?.coverUrl, - R.string.rule_cover_url - ) - ) - searchEntities.add( - EditEntity( - "bookUrl", - this?.bookUrl, - R.string.rule_book_url - ) - ) + searchEntities.apply { + add(EditEntity("searchUrl", bookSource?.searchUrl, R.string.rule_search_url)) + add(EditEntity("bookList", searchRule?.bookList, R.string.rule_book_list)) + add(EditEntity("name", searchRule?.name, R.string.rule_book_name)) + add(EditEntity("author", searchRule?.author, R.string.rule_book_author)) + add(EditEntity("kind", searchRule?.kind, R.string.rule_book_kind)) + add(EditEntity("wordCount", searchRule?.wordCount, R.string.rule_word_count)) + add(EditEntity("lastChapter", searchRule?.lastChapter, R.string.rule_last_chapter)) + add(EditEntity("intro", searchRule?.intro, R.string.rule_book_intro)) + add(EditEntity("coverUrl", searchRule?.coverUrl, R.string.rule_cover_url)) + add(EditEntity("bookUrl", searchRule?.bookUrl, R.string.rule_book_url)) + } } //详情页 - with(bookSource?.getBookInfoRule()) { + (bookSource?.getBookInfoRule()).let { infoRule -> infoEntities.clear() - infoEntities.add( - EditEntity( - "init", - this?.init, - R.string.rule_book_info_init - ) - ) - infoEntities.add( - EditEntity( - "name", - this?.name, - R.string.rule_book_name - ) - ) - infoEntities.add( - EditEntity( - "author", - this?.author, - R.string.rule_book_author - ) - ) - infoEntities.add( - EditEntity( - "coverUrl", - this?.coverUrl, - R.string.rule_cover_url - ) - ) - infoEntities.add( - EditEntity( - "intro", - this?.intro, - R.string.rule_book_intro - ) - ) - infoEntities.add( - EditEntity( - "kind", - this?.kind, - R.string.rule_book_kind - ) - ) - infoEntities.add( - EditEntity( - "wordCount", - this?.wordCount, - R.string.rule_word_count - ) - ) - infoEntities.add( - EditEntity( - "lastChapter", - this?.lastChapter, - R.string.rule_last_chapter - ) - ) - infoEntities.add( - EditEntity( - "tocUrl", - this?.tocUrl, - R.string.rule_toc_url - ) - ) + infoEntities.apply { + add(EditEntity("init", infoRule?.init, R.string.rule_book_info_init)) + add(EditEntity("name", infoRule?.name, R.string.rule_book_name)) + add(EditEntity("author", infoRule?.author, R.string.rule_book_author)) + add(EditEntity("coverUrl", infoRule?.coverUrl, R.string.rule_cover_url)) + add(EditEntity("intro", infoRule?.intro, R.string.rule_book_intro)) + add(EditEntity("kind", infoRule?.kind, R.string.rule_book_kind)) + add(EditEntity("wordCount", infoRule?.wordCount, R.string.rule_word_count)) + add(EditEntity("lastChapter", infoRule?.lastChapter, R.string.rule_last_chapter)) + add(EditEntity("tocUrl", infoRule?.tocUrl, R.string.rule_toc_url)) + } } //目录页 - with(bookSource?.getTocRule()) { + (bookSource?.getTocRule()).let { tocRule -> tocEntities.clear() - tocEntities.add( - EditEntity( - "chapterList", - this?.chapterList, - R.string.rule_chapter_list - ) - ) - tocEntities.add( - EditEntity( - "chapterName", - this?.chapterName, - R.string.rule_chapter_name - ) - ) - tocEntities.add( - EditEntity( - "chapterUrl", - this?.chapterUrl, - R.string.rule_chapter_url - ) - ) - tocEntities.add( - EditEntity( - "nextTocUrl", - this?.nextTocUrl, - R.string.rule_next_toc_url - ) - ) + tocEntities.apply { + add(EditEntity("chapterList", tocRule?.chapterList, R.string.rule_chapter_list)) + add(EditEntity("chapterName", tocRule?.chapterName, R.string.rule_chapter_name)) + add(EditEntity("chapterUrl", tocRule?.chapterUrl, R.string.rule_chapter_url)) + add(EditEntity("nextTocUrl", tocRule?.nextTocUrl, R.string.rule_next_toc_url)) + } } //正文页 - with(bookSource?.getContentRule()) { + (bookSource?.getContentRule()).let { contentRule -> contentEntities.clear() - contentEntities.add( - EditEntity( - "content", - this?.content, - R.string.rule_book_content - ) - ) - contentEntities.add( - EditEntity( - "nextContentUrl", - this?.nextContentUrl, - R.string.rule_content_url_next + contentEntities.apply { + add(EditEntity("content", contentRule?.content, R.string.rule_book_content)) + add( + EditEntity( + "nextContentUrl", + contentRule?.nextContentUrl, + R.string.rule_content_url_next + ) ) - ) + } } //发现 - with(bookSource?.getExploreRule()) { + (bookSource?.getExploreRule()).let { exploreRule -> findEntities.clear() - findEntities.add( - EditEntity( - "exploreUrl", - bookSource?.exploreUrl, - R.string.rule_find_url - ) - ) - findEntities.add( - EditEntity( - "bookList", - this?.bookList, - R.string.rule_book_list - ) - ) - findEntities.add( - EditEntity( - "name", - this?.name, - R.string.rule_book_name - ) - ) - findEntities.add( - EditEntity( - "author", - this?.author, - R.string.rule_book_author - ) - ) - findEntities.add( - EditEntity( - "kind", - this?.kind, - R.string.rule_book_kind - ) - ) - findEntities.add( - EditEntity( - "wordCount", - this?.wordCount, - R.string.rule_word_count - ) - ) - findEntities.add( - EditEntity( - "intro", - this?.intro, - R.string.rule_book_intro - ) - ) - findEntities.add( - EditEntity( - "lastChapter", - this?.lastChapter, - R.string.rule_last_chapter - ) - ) - findEntities.add( - EditEntity( - "coverUrl", - this?.coverUrl, - R.string.rule_cover_url - ) - ) - findEntities.add( - EditEntity( - "bookUrl", - this?.bookUrl, - R.string.rule_book_url - ) - ) + findEntities.apply { + add(EditEntity("exploreUrl", bookSource?.exploreUrl, R.string.rule_find_url)) + add(EditEntity("bookList", exploreRule?.bookList, R.string.rule_book_list)) + add(EditEntity("name", exploreRule?.name, R.string.rule_book_name)) + add(EditEntity("author", exploreRule?.author, R.string.rule_book_author)) + add(EditEntity("kind", exploreRule?.kind, R.string.rule_book_kind)) + add(EditEntity("wordCount", exploreRule?.wordCount, R.string.rule_word_count)) + add(EditEntity("intro", exploreRule?.intro, R.string.rule_book_intro)) + add(EditEntity("lastChapter", exploreRule?.lastChapter, R.string.rule_last_chapter)) + add(EditEntity("coverUrl", exploreRule?.coverUrl, R.string.rule_cover_url)) + add(EditEntity("bookUrl", exploreRule?.bookUrl, R.string.rule_book_url)) + } } setEditEntities(0) } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index afffb7b97..e623420f4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppConst +import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.RssSource import io.legado.app.lib.theme.ATH import io.legado.app.ui.widget.KeyboardToolPop @@ -28,6 +29,7 @@ class RssSourceEditActivity : private var mIsSoftKeyBoardShowing = false private lateinit var adapter: RssSourceEditAdapter + private val sourceEntities: ArrayList = ArrayList() override val viewModel: RssSourceEditViewModel get() = getViewModel(RssSourceEditViewModel::class.java) @@ -69,6 +71,33 @@ class RssSourceEditActivity : } private fun upRecyclerView(rssSource: RssSource?) { + sourceEntities.clear() + sourceEntities.apply { + add(EditEntity("sourceName", rssSource?.sourceName, R.string.rss_source_name)) + add(EditEntity("sourceUrl", rssSource?.sourceUrl, R.string.rss_source_url)) + add(EditEntity("iconUrl", rssSource?.iconUrl, R.string.rss_source_icon)) + add(EditEntity("ruleTitle", rssSource?.ruleTitle, R.string.rss_rule_title)) + add(EditEntity("ruleAuthor", rssSource?.ruleAuthor, R.string.rss_rule_author)) + add(EditEntity("ruleGuid", rssSource?.ruleGuid, R.string.rss_rule_guid)) + add(EditEntity("rulePubDate", rssSource?.rulePubDate, R.string.rss_rule_date)) + add( + EditEntity( + "ruleCategories", + rssSource?.ruleCategories, + R.string.rss_rule_categories + ) + ) + add( + EditEntity( + "ruleDescription", + rssSource?.ruleDescription, + R.string.rss_rule_description + ) + ) + add(EditEntity("ruleImage", rssSource?.ruleImage, R.string.rss_rule_image)) + add(EditEntity("ruleContent", rssSource?.ruleContent, R.string.rss_rule_content)) + add(EditEntity("ruleLink", rssSource?.ruleLink, R.string.rss_rule_link)) + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2b3bceac2..990597367 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -375,6 +375,21 @@ 正文下一页URL规则(nextContentUrl) + + 名称 + url + 图标 + 标题 + 作者 + guid + 时间 + 类别 + 描述 + 图片url + 内容 + 链接 + + 没有书源 书籍信息获取失败 From 2dc2d6728b89d35faff01a2af9956d8ffdac9be0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 22:39:30 +0800 Subject: [PATCH 056/140] up --- .../ui/book/source/edit/SourceEditActivity.kt | 144 ++++++++---------- .../rss/source/edit/RssSourceEditActivity.kt | 39 +++++ .../rss/source/edit/RssSourceEditViewModel.kt | 8 +- 3 files changed, 111 insertions(+), 80 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt index c7e6dbbf5..8e3f1c940 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt @@ -79,20 +79,14 @@ class SourceEditActivity : override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_save -> { - val bookSource = getSource() - if (bookSource == null) { - toast("书源名称和URL不能为空") - } else { - viewModel.save(bookSource) { setResult(Activity.RESULT_OK); finish() } + getSource()?.let { + viewModel.save(it) { setResult(Activity.RESULT_OK); finish() } } } R.id.menu_debug_source -> { - val bookSource = getSource() - if (bookSource == null) { - toast("书源名称和URL不能为空") - } else { - viewModel.save(bookSource) { - startActivity(Pair("key", bookSource.bookSourceUrl)) + getSource()?.let { + viewModel.save(it) { + startActivity(Pair("key", it.bookSourceUrl)) } } } @@ -249,84 +243,76 @@ class SourceEditActivity : val bookInfoRule = BookInfoRule() val tocRule = TocRule() val contentRule = ContentRule() - for (entity in sourceEntities) { - with(entity) { - when (key) { - "bookSourceUrl" -> value?.let { source.bookSourceUrl = it } ?: return null - "bookSourceName" -> value?.let { source.bookSourceName = it } ?: return null - "bookSourceGroup" -> source.bookSourceGroup = value - "loginUrl" -> source.loginUrl = value - "bookUrlPattern" -> source.bookUrlPattern = value - "header" -> source.header = value - } + sourceEntities.forEach { + when (it.key) { + "bookSourceUrl" -> source.bookSourceUrl = it.value ?: "" + "bookSourceName" -> source.bookSourceName = it.value ?: "" + "bookSourceGroup" -> source.bookSourceGroup = it.value + "loginUrl" -> source.loginUrl = it.value + "bookUrlPattern" -> source.bookUrlPattern = it.value + "header" -> source.header = it.value } } - for (entity in searchEntities) { - with(entity) { - when (key) { - "searchUrl" -> source.searchUrl = value - "bookList" -> searchRule.bookList = value - "name" -> searchRule.name = value - "author" -> searchRule.author = value - "kind" -> searchRule.kind = value - "intro" -> searchRule.intro = value - "updateTime" -> searchRule.updateTime = value - "wordCount" -> searchRule.wordCount = value - "lastChapter" -> searchRule.lastChapter = value - "coverUrl" -> searchRule.coverUrl = value - "bookUrl" -> searchRule.bookUrl = value - } + if (source.bookSourceUrl.isBlank() || source.bookSourceName.isBlank()) { + toast("书源名称和URL不能为空") + return null + } + searchEntities.forEach { + when (it.key) { + "searchUrl" -> source.searchUrl = it.value + "bookList" -> searchRule.bookList = it.value + "name" -> searchRule.name = it.value + "author" -> searchRule.author = it.value + "kind" -> searchRule.kind = it.value + "intro" -> searchRule.intro = it.value + "updateTime" -> searchRule.updateTime = it.value + "wordCount" -> searchRule.wordCount = it.value + "lastChapter" -> searchRule.lastChapter = it.value + "coverUrl" -> searchRule.coverUrl = it.value + "bookUrl" -> searchRule.bookUrl = it.value } } - for (entity in findEntities) { - with(entity) { - when (key) { - "exploreUrl" -> source.exploreUrl = value - "bookList" -> exploreRule.bookList = value - "name" -> exploreRule.name = value - "author" -> exploreRule.author = value - "kind" -> exploreRule.kind = value - "intro" -> exploreRule.intro = value - "updateTime" -> exploreRule.updateTime = value - "wordCount" -> exploreRule.wordCount = value - "lastChapter" -> exploreRule.lastChapter = value - "coverUrl" -> exploreRule.coverUrl = value - "bookUrl" -> exploreRule.bookUrl = value - } + findEntities.forEach { + when (it.key) { + "exploreUrl" -> source.exploreUrl = it.value + "bookList" -> exploreRule.bookList = it.value + "name" -> exploreRule.name = it.value + "author" -> exploreRule.author = it.value + "kind" -> exploreRule.kind = it.value + "intro" -> exploreRule.intro = it.value + "updateTime" -> exploreRule.updateTime = it.value + "wordCount" -> exploreRule.wordCount = it.value + "lastChapter" -> exploreRule.lastChapter = it.value + "coverUrl" -> exploreRule.coverUrl = it.value + "bookUrl" -> exploreRule.bookUrl = it.value } } - for (entity in infoEntities) { - with(entity) { - when (key) { - "init" -> bookInfoRule.init = value - "name" -> bookInfoRule.name = value - "author" -> bookInfoRule.author = value - "kind" -> bookInfoRule.kind = value - "intro" -> bookInfoRule.intro = value - "updateTime" -> bookInfoRule.updateTime = value - "wordCount" -> bookInfoRule.wordCount = value - "lastChapter" -> bookInfoRule.lastChapter = value - "coverUrl" -> bookInfoRule.coverUrl = value - "tocUrl" -> bookInfoRule.tocUrl = value - } + infoEntities.forEach { + when (it.key) { + "init" -> bookInfoRule.init = it.value + "name" -> bookInfoRule.name = it.value + "author" -> bookInfoRule.author = it.value + "kind" -> bookInfoRule.kind = it.value + "intro" -> bookInfoRule.intro = it.value + "updateTime" -> bookInfoRule.updateTime = it.value + "wordCount" -> bookInfoRule.wordCount = it.value + "lastChapter" -> bookInfoRule.lastChapter = it.value + "coverUrl" -> bookInfoRule.coverUrl = it.value + "tocUrl" -> bookInfoRule.tocUrl = it.value } } - for (entity in tocEntities) { - with(entity) { - when (key) { - "chapterList" -> tocRule.chapterList = value - "chapterName" -> tocRule.chapterName = value - "chapterUrl" -> tocRule.chapterUrl = value - "nextTocUrl" -> tocRule.nextTocUrl = value - } + tocEntities.forEach { + when (it.key) { + "chapterList" -> tocRule.chapterList = it.value + "chapterName" -> tocRule.chapterName = it.value + "chapterUrl" -> tocRule.chapterUrl = it.value + "nextTocUrl" -> tocRule.nextTocUrl = it.value } } - for (entity in contentEntities) { - with(entity) { - when (key) { - "content" -> contentRule.content = value - "nextContentUrl" -> contentRule.nextContentUrl = value - } + contentEntities.forEach { + when (it.key) { + "content" -> contentRule.content = it.value + "nextContentUrl" -> contentRule.nextContentUrl = it.value } } source.ruleSearch = GSON.toJson(searchRule) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index e623420f4..cfee144db 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -1,9 +1,11 @@ package io.legado.app.ui.rss.source.edit +import android.app.Activity import android.graphics.Rect import android.os.Bundle import android.view.Gravity import android.view.Menu +import android.view.MenuItem import android.view.ViewTreeObserver import android.widget.EditText import android.widget.PopupWindow @@ -62,6 +64,20 @@ class RssSourceEditActivity : return super.onCompatCreateOptionsMenu(menu) } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_save -> { + getRssSource()?.let { + viewModel.save(it) { + setResult(Activity.RESULT_OK) + finish() + } + } + } + } + return super.onCompatOptionsItemSelected(item) + } + private fun initView() { ATH.applyEdgeEffectColor(recycler_view) mSoftKeyboardTool = KeyboardToolPop(this, AppConst.keyboardToolChars, this) @@ -98,7 +114,30 @@ class RssSourceEditActivity : add(EditEntity("ruleContent", rssSource?.ruleContent, R.string.rss_rule_content)) add(EditEntity("ruleLink", rssSource?.ruleLink, R.string.rss_rule_link)) } + } + private fun getRssSource(): RssSource? { + val source = viewModel.sourceLiveData.value ?: RssSource() + sourceEntities.forEach { + when (it.key) { + "sourceName" -> source.sourceName = it.value ?: "" + "sourceUrl" -> source.sourceName = it.value ?: "" + "iconUrl" -> source.sourceName = it.value ?: "" + "ruleTitle" -> source.sourceName = it.value ?: "" + "ruleAuthor" -> source.sourceName = it.value ?: "" + "ruleGuid" -> source.sourceName = it.value ?: "" + "rulePubDate" -> source.sourceName = it.value ?: "" + "ruleCategories" -> source.sourceName = it.value ?: "" + "ruleDescription" -> source.sourceName = it.value ?: "" + "ruleImage" -> source.sourceName = it.value ?: "" + "ruleContent" -> source.sourceName = it.value ?: "" + "ruleLink" -> source.sourceName = it.value ?: "" + } + } + if (source.sourceName.isBlank() || source.sourceName.isBlank()) { + return null + } + return source } override fun sendText(text: String) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 53f7d01de..6d089a865 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -18,5 +18,11 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati } } - + fun save(rssSource: RssSource, success: (() -> Unit)) { + execute { + App.db.rssSourceDao().insert(rssSource) + }.onSuccess { + success() + } + } } \ No newline at end of file From 54320528ddc6ce9935a68d44ce5d053f07606deb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 22:44:42 +0800 Subject: [PATCH 057/140] up --- .../rss/source/edit/RssSourceEditActivity.kt | 20 +++++++++++++++++++ .../rss/source/edit/RssSourceEditViewModel.kt | 18 +++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index cfee144db..023aee11c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -1,6 +1,9 @@ package io.legado.app.ui.rss.source.edit import android.app.Activity +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context import android.graphics.Rect import android.os.Bundle import android.view.Gravity @@ -17,10 +20,13 @@ import io.legado.app.constant.AppConst import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.RssSource import io.legado.app.lib.theme.ATH +import io.legado.app.ui.book.source.debug.SourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop +import io.legado.app.utils.GSON import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_book_source_edit.* import org.jetbrains.anko.displayMetrics +import org.jetbrains.anko.startActivity import kotlin.math.abs class RssSourceEditActivity : @@ -74,6 +80,20 @@ class RssSourceEditActivity : } } } + R.id.menu_debug_source -> { + getRssSource()?.let { + viewModel.save(it) { + startActivity(Pair("key", it.sourceUrl)) + } + } + } + R.id.menu_copy_source -> { + GSON.toJson(getRssSource())?.let { sourceStr -> + val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? + clipboard?.primaryClip = ClipData.newPlainText(null, sourceStr) + } + } + R.id.menu_paste_source -> viewModel.pasteSource() } return super.onCompatOptionsItemSelected(item) } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 6d089a865..b4c0133a8 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -1,10 +1,14 @@ package io.legado.app.ui.rss.source.edit import android.app.Application +import android.content.ClipboardManager +import android.content.Context import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssSource +import io.legado.app.utils.GSON +import io.legado.app.utils.fromJsonObject class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { @@ -25,4 +29,18 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati success() } } + + fun pasteSource() { + execute { + val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? + clipboard?.primaryClip?.let { + if (it.itemCount > 0) { + val json = it.getItemAt(0).text.toString() + GSON.fromJsonObject(json)?.let { source -> + sourceLiveData.postValue(source) + } ?: toast("格式不对") + } + } + } + } } \ No newline at end of file From ecd264bac724157dbf178ae15fb9488292db25c0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 22:47:53 +0800 Subject: [PATCH 058/140] up --- app/src/main/AndroidManifest.xml | 1 + .../ui/rss/source/debug/RssSourceDebugActivity.kt | 14 ++++++++++++++ .../ui/rss/source/edit/RssSourceEditActivity.kt | 4 ++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 96e2b7ea2..928c4d99d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -70,6 +70,7 @@ + diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt index de8bf27dc..0c55e2270 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt @@ -1,2 +1,16 @@ package io.legado.app.ui.rss.source.debug +import android.os.Bundle +import io.legado.app.R +import io.legado.app.base.BaseActivity + + +class RssSourceDebugActivity : BaseActivity(R.layout.activity_book_source_debug, false) { + + + override fun onActivityCreated(savedInstanceState: Bundle?) { + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 023aee11c..9fd580e9c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -20,7 +20,7 @@ import io.legado.app.constant.AppConst import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.RssSource import io.legado.app.lib.theme.ATH -import io.legado.app.ui.book.source.debug.SourceDebugActivity +import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.utils.GSON import io.legado.app.utils.getViewModel @@ -83,7 +83,7 @@ class RssSourceEditActivity : R.id.menu_debug_source -> { getRssSource()?.let { viewModel.save(it) { - startActivity(Pair("key", it.sourceUrl)) + startActivity(Pair("key", it.sourceUrl)) } } } From 3fe9d763c9b864aca507fa6c393604b3f4e9dd12 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 22:49:29 +0800 Subject: [PATCH 059/140] up --- .../io/legado/app/ui/book/source/debug/SourceDebugActivity.kt | 4 ++-- .../legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt | 2 +- ...tivity_book_source_debug.xml => activity_source_debug.xml} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename app/src/main/res/layout/{activity_book_source_debug.xml => activity_source_debug.xml} (100%) diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt index b180f6b17..de2ef20e7 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt @@ -12,13 +12,13 @@ import io.legado.app.lib.theme.ATH 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_book_source_debug.* +import kotlinx.android.synthetic.main.activity_source_debug.* import kotlinx.android.synthetic.main.view_search.* import kotlinx.coroutines.launch import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast -class SourceDebugActivity : VMBaseActivity(R.layout.activity_book_source_debug) { +class SourceDebugActivity : VMBaseActivity(R.layout.activity_source_debug) { override val viewModel: SourceDebugModel get() = getViewModel(SourceDebugModel::class.java) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt index 0c55e2270..3018a1f1e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt @@ -5,7 +5,7 @@ import io.legado.app.R import io.legado.app.base.BaseActivity -class RssSourceDebugActivity : BaseActivity(R.layout.activity_book_source_debug, false) { +class RssSourceDebugActivity : BaseActivity(R.layout.activity_source_debug, false) { override fun onActivityCreated(savedInstanceState: Bundle?) { diff --git a/app/src/main/res/layout/activity_book_source_debug.xml b/app/src/main/res/layout/activity_source_debug.xml similarity index 100% rename from app/src/main/res/layout/activity_book_source_debug.xml rename to app/src/main/res/layout/activity_source_debug.xml From 9634cfac60fbb6aa463afd941f86d13ce2f15e4d Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 22:58:50 +0800 Subject: [PATCH 060/140] up --- .../io/legado/app/ui/book/source/edit/SourceEditActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt index 8e3f1c940..4eb28dcea 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt @@ -141,7 +141,7 @@ class SourceEditActivity : } //基本信息 sourceEntities.clear() - searchEntities.apply { + sourceEntities.apply { add(EditEntity("bookSourceUrl", bookSource?.bookSourceUrl, R.string.book_source_url)) add(EditEntity("bookSourceName", bookSource?.bookSourceName, R.string.book_source_name)) add( From 0b76f7b967d7cc87e1b5901d8a07e7c689d0a212 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 23:00:55 +0800 Subject: [PATCH 061/140] up --- .../io/legado/app/ui/rss/source/manage/RssSourceActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 047a342d4..f0052917e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -43,7 +43,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_add_book_source -> startActivity() + R.id.menu_add -> startActivity() } return super.onCompatOptionsItemSelected(item) } From b3da0df8a55e61e679a6897efeb3189d54199d1b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 23:05:22 +0800 Subject: [PATCH 062/140] up --- .../io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 9fd580e9c..4113261fb 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -36,7 +36,7 @@ class RssSourceEditActivity : private var mSoftKeyboardTool: PopupWindow? = null private var mIsSoftKeyBoardShowing = false - private lateinit var adapter: RssSourceEditAdapter + private val adapter = RssSourceEditAdapter() private val sourceEntities: ArrayList = ArrayList() override val viewModel: RssSourceEditViewModel From 699b715f3d785cf9d2f5b86514a7e5cb68bb56fb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 23:06:25 +0800 Subject: [PATCH 063/140] up --- .../io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 4113261fb..79eb9552d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -134,6 +134,7 @@ class RssSourceEditActivity : add(EditEntity("ruleContent", rssSource?.ruleContent, R.string.rss_rule_content)) add(EditEntity("ruleLink", rssSource?.ruleLink, R.string.rss_rule_link)) } + adapter.editEntities = sourceEntities } private fun getRssSource(): RssSource? { From 54bad44495afc75ff8405c408256ad48dc2b41c3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 23:11:23 +0800 Subject: [PATCH 064/140] up --- app/src/main/res/layout/activity_rss_source_edit.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/activity_rss_source_edit.xml b/app/src/main/res/layout/activity_rss_source_edit.xml index 5579d3de5..d47a244de 100644 --- a/app/src/main/res/layout/activity_rss_source_edit.xml +++ b/app/src/main/res/layout/activity_rss_source_edit.xml @@ -1,6 +1,7 @@ From 0b3199e204b8178ba9260dcd49e3dc2d3d734c08 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 1 Oct 2019 23:13:48 +0800 Subject: [PATCH 065/140] up --- app/src/main/res/layout/activity_rss_source_edit.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/activity_rss_source_edit.xml b/app/src/main/res/layout/activity_rss_source_edit.xml index d47a244de..dd2545faf 100644 --- a/app/src/main/res/layout/activity_rss_source_edit.xml +++ b/app/src/main/res/layout/activity_rss_source_edit.xml @@ -12,6 +12,7 @@ android:layout_height="wrap_content" app:contentInsetStartWithNavigation="0dp" app:displayHomeAsUp="true" + app:fitStatusBar="false" app:title="@string/rss_source_edit" /> Date: Wed, 2 Oct 2019 03:24:38 +0800 Subject: [PATCH 066/140] =?UTF-8?q?=E6=B5=8B=E8=AF=95RSS=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../io/legado/app/constant/RSSKeywords.kt | 2 +- .../io/legado/app/ui/main/rss/RssFragment.kt | 4 + .../app/ui/rss/article/RssArticlesActivity.kt | 93 ++++++++++++++++++- .../legado/app/ui/rss/read/ReadRssActivity.kt | 18 ++-- app/src/main/res/layout/activity_read_rss.xml | 5 +- app/src/main/res/layout/fragment_rss.xml | 1 - app/src/main/res/layout/item_rss.xml | 41 +++++++- app/src/main/res/menu/main_rss.xml | 5 + 9 files changed, 153 insertions(+), 18 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 96e2b7ea2..98701bba5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -70,7 +70,7 @@ - + diff --git a/app/src/main/java/io/legado/app/constant/RSSKeywords.kt b/app/src/main/java/io/legado/app/constant/RSSKeywords.kt index 5a4119e05..bb8d4207a 100644 --- a/app/src/main/java/io/legado/app/constant/RSSKeywords.kt +++ b/app/src/main/java/io/legado/app/constant/RSSKeywords.kt @@ -5,7 +5,7 @@ object RSSKeywords { const val RSS_ITEM = "item" const val RSS_ITEM_TITLE = "title" const val RSS_ITEM_LINK = "link" - const val RSS_ITEM_AUTHOR = "dc:creator" + const val RSS_ITEM_AUTHOR = "author" const val RSS_ITEM_CATEGORY = "category" const val RSS_ITEM_THUMBNAIL = "media:thumbnail" const val RSS_ITEM_ENCLOSURE = "enclosure" diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 79c82bf1d..347b95a23 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -10,6 +10,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.lib.theme.ATH +import io.legado.app.ui.rss.article.RssArticlesActivity import io.legado.app.ui.rss.source.manage.RssSourceActivity import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_rss.* @@ -34,6 +35,9 @@ class RssFragment : BaseFragment(R.layout.fragment_rss), super.onCompatOptionsItemSelected(item) when (item.itemId) { R.id.menu_rss_config -> startActivity() + R.id.menu_rss_add -> { + startActivity() + } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index a69c70fb5..6a52df7b3 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -1,3 +1,94 @@ package io.legado.app.ui.rss.article -class RssArticlesActivity \ No newline at end of file +import android.content.Context +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.BaseAdapter +import androidx.appcompat.app.AppCompatActivity +import io.legado.app.R +import io.legado.app.data.entities.RssArticle +import io.legado.app.model.rss.RssParser +import io.legado.app.ui.rss.read.ReadRssActivity +import kotlinx.android.synthetic.main.item_rss.view.* +import org.jetbrains.anko.* +import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.sdk27.listeners.onItemClick +import java.net.URL + +class RssArticlesActivity : AppCompatActivity() { + val zhihu_dayli = "https://rsshub.app/zhihu/daily" + val nytimes = "https://rsshub.app/nytimes/dual" + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + var articles = mutableListOf() + val adapter = ArticleAdapter(articles, this) + verticalLayout { + val url = editText { + hint = "请输入RSS地址" + } + fun loadRss(urlString:String){ + Thread { + val xml = URL(urlString).readText() + articles = RssParser.parseXML(xml) + runOnUiThread { + adapter.articles = articles + adapter.notifyDataSetChanged() + } + }.start() + } + button("解析") { + onClick { + val urlString = url.text.toString().trim() + if(urlString != ""){ + loadRss(urlString) + } + } + } + button("知乎日报") { + onClick { + loadRss(zhihu_dayli) + } + } + button("纽约时报") { + onClick { + loadRss(nytimes) + } + } + listView { + this.adapter = adapter + onItemClick { p0, p1, p2, p3 -> + startActivity("description" to articles[p2].description) + } + } + } + } +} + +class ArticleAdapter(var articles: List, var context: Context) : BaseAdapter() { + override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { + val item_rss= LayoutInflater.from(context).inflate(R.layout.item_rss, null) + val article = articles[position] + item_rss.title.text = article.title + item_rss.pub_date.text = article.pubDate + if(article.author != null && article.author != ""){ + item_rss.author.text = article.author + } else{ + item_rss.author.text = article.link + } + return item_rss + } + + override fun getItem(position: Int): Any { + return articles[position] + } + + override fun getItemId(position: Int): Long { + return 1 + } + + override fun getCount(): Int { + return articles.size + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 5e7972c6d..984cc0ea4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -1,15 +1,15 @@ package io.legado.app.ui.rss.read import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity import io.legado.app.R -import io.legado.app.base.BaseActivity - - -class ReadRssActivity : BaseActivity(R.layout.activity_read_rss) { - - override fun onActivityCreated(savedInstanceState: Bundle?) { - +import kotlinx.android.synthetic.main.activity_read_rss.* + +class ReadRssActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_read_rss) + val s = intent.getStringExtra("description") + webView.loadData(""+s,"text/html","utf-8") } - - } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_read_rss.xml b/app/src/main/res/layout/activity_read_rss.xml index d829e291c..0650007cf 100644 --- a/app/src/main/res/layout/activity_read_rss.xml +++ b/app/src/main/res/layout/activity_read_rss.xml @@ -3,5 +3,8 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_rss.xml b/app/src/main/res/layout/fragment_rss.xml index 3d9e9a4b5..f5a3b374c 100644 --- a/app/src/main/res/layout/fragment_rss.xml +++ b/app/src/main/res/layout/fragment_rss.xml @@ -11,7 +11,6 @@ android:layout_height="wrap_content" app:attachToActivity="false" app:title="@string/rss" /> - - + android:layout_height="wrap_content" + app:cardCornerRadius="2dp" + app:cardElevation="8dp"> - \ No newline at end of file + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/main_rss.xml b/app/src/main/res/menu/main_rss.xml index 9c051a1d2..f1e39cae2 100644 --- a/app/src/main/res/menu/main_rss.xml +++ b/app/src/main/res/menu/main_rss.xml @@ -2,6 +2,11 @@ + Date: Wed, 2 Oct 2019 10:20:33 +0800 Subject: [PATCH 067/140] up --- .../app/ui/rss/source/edit/RssSourceEditViewModel.kt | 2 ++ app/src/main/res/values/strings.xml | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index b4c0133a8..0f002d627 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -27,6 +27,8 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati App.db.rssSourceDao().insert(rssSource) }.onSuccess { success() + }.onError { + toast(it.localizedMessage) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 990597367..a0bb5a060 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -150,9 +150,9 @@ 新建订阅源 添加书籍 扫描 - 拷贝书源 - 粘贴书源 - 书源规则说明 + 拷贝源 + 粘贴源 + 源规则说明 检查更新 扫描二维码 扫描本地图片 @@ -406,7 +406,7 @@ header - 调试书源 + 调试源 二维码导入 扫描二维码 选中时点击可弹出菜单 From 98317208317ed4dcedd1eb0c1716de570da13643 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 10:49:36 +0800 Subject: [PATCH 068/140] up --- .../io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 79eb9552d..2f0d601ff 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -27,6 +27,7 @@ import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_book_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity +import org.jetbrains.anko.toast import kotlin.math.abs class RssSourceEditActivity : @@ -156,6 +157,7 @@ class RssSourceEditActivity : } } if (source.sourceName.isBlank() || source.sourceName.isBlank()) { + toast("名称或url不能为空") return null } return source From 6953feef0d920a3d095088e2541e739e749e2d0a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 10:51:24 +0800 Subject: [PATCH 069/140] up --- .../rss/source/edit/RssSourceEditActivity.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 2f0d601ff..bb3e493ec 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -143,17 +143,17 @@ class RssSourceEditActivity : sourceEntities.forEach { when (it.key) { "sourceName" -> source.sourceName = it.value ?: "" - "sourceUrl" -> source.sourceName = it.value ?: "" - "iconUrl" -> source.sourceName = it.value ?: "" - "ruleTitle" -> source.sourceName = it.value ?: "" - "ruleAuthor" -> source.sourceName = it.value ?: "" - "ruleGuid" -> source.sourceName = it.value ?: "" - "rulePubDate" -> source.sourceName = it.value ?: "" - "ruleCategories" -> source.sourceName = it.value ?: "" - "ruleDescription" -> source.sourceName = it.value ?: "" - "ruleImage" -> source.sourceName = it.value ?: "" - "ruleContent" -> source.sourceName = it.value ?: "" - "ruleLink" -> source.sourceName = it.value ?: "" + "sourceUrl" -> source.sourceUrl = it.value ?: "" + "iconUrl" -> source.iconUrl = it.value ?: "" + "ruleTitle" -> source.ruleTitle = it.value ?: "" + "ruleAuthor" -> source.ruleAuthor = it.value ?: "" + "ruleGuid" -> source.ruleGuid = it.value ?: "" + "rulePubDate" -> source.rulePubDate = it.value ?: "" + "ruleCategories" -> source.ruleCategories = it.value ?: "" + "ruleDescription" -> source.ruleDescription = it.value ?: "" + "ruleImage" -> source.ruleImage = it.value ?: "" + "ruleContent" -> source.ruleContent = it.value ?: "" + "ruleLink" -> source.ruleLink = it.value ?: "" } } if (source.sourceName.isBlank() || source.sourceName.isBlank()) { From f1e9345c47e18ce89c8abea861b9e5ba089de04d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 11:08:01 +0800 Subject: [PATCH 070/140] up --- .../book/source/manage/BookSourceActivity.kt | 5 +-- .../app/ui/rss/source/manage/DiffCallBack.kt | 41 +++++++++++++++++++ .../ui/rss/source/manage/RssSourceActivity.kt | 18 ++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/rss/source/manage/DiffCallBack.kt diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 6dfc8f3a2..81364c11e 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -136,10 +136,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity bookSourceLiveDate?.observe(this, Observer { search_view.queryHint = getString(R.string.search_book_source_num, it.size) val diffResult = DiffUtil.calculateDiff( - DiffCallBack( - adapter.getItems(), - it - ) + DiffCallBack(adapter.getItems(), it) ) adapter.setItemsNoNotify(it) diffResult.dispatchUpdatesTo(adapter) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/DiffCallBack.kt new file mode 100644 index 000000000..4260febe4 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/DiffCallBack.kt @@ -0,0 +1,41 @@ +package io.legado.app.ui.rss.source.manage + +import androidx.recyclerview.widget.DiffUtil +import io.legado.app.data.entities.RssSource + +class DiffCallBack( + private val oldItems: List, + private val newItems: List +) : DiffUtil.Callback() { + + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + return oldItem.sourceUrl == newItem.sourceUrl + } + + override fun getOldListSize(): Int { + return oldItems.size + } + + override fun getNewListSize(): Int { + return newItems.size + } + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + return oldItem.sourceName == newItem.sourceName + && oldItem.enabled == newItem.enabled + } + + override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + return when { + oldItem.sourceName == newItem.sourceName + && oldItem.enabled != newItem.enabled -> 2 + else -> null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index f0052917e..09eb27e39 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -5,9 +5,13 @@ import android.view.Menu import android.view.MenuItem import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat +import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.RssSource @@ -29,11 +33,13 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r get() = getViewModel(RssSourceViewModel::class.java) private lateinit var adapter: RssSourceAdapter + private var sourceLiveData: LiveData>? = null override fun onActivityCreated(savedInstanceState: Bundle?) { setSupportActionBar(toolbar) initRecyclerView() initSearchView() + initData() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -81,6 +87,18 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r }) } + private fun initData() { + sourceLiveData?.removeObservers(this) + sourceLiveData = App.db.rssSourceDao().liveAll() + sourceLiveData?.observe(this, Observer { + val diffResult = DiffUtil.calculateDiff( + DiffCallBack(adapter.getItems(), it) + ) + adapter.setItemsNoNotify(it) + diffResult.dispatchUpdatesTo(adapter) + }) + } + override fun del(source: RssSource) { } From 89512c0db8a77debf26e7608e87078ac0742875d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 11:08:58 +0800 Subject: [PATCH 071/140] up --- .../legado/app/ui/book/source/manage/BookSourceActivity.kt | 5 ++--- .../io/legado/app/ui/rss/source/manage/RssSourceActivity.kt | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 81364c11e..258e8b52d 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -135,9 +135,8 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } bookSourceLiveDate?.observe(this, Observer { search_view.queryHint = getString(R.string.search_book_source_num, it.size) - val diffResult = DiffUtil.calculateDiff( - DiffCallBack(adapter.getItems(), it) - ) + val diffResult = DiffUtil + .calculateDiff(DiffCallBack(adapter.getItems(), it)) adapter.setItemsNoNotify(it) diffResult.dispatchUpdatesTo(adapter) }) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 09eb27e39..0a2c2f0bd 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -91,9 +91,8 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r sourceLiveData?.removeObservers(this) sourceLiveData = App.db.rssSourceDao().liveAll() sourceLiveData?.observe(this, Observer { - val diffResult = DiffUtil.calculateDiff( - DiffCallBack(adapter.getItems(), it) - ) + val diffResult = DiffUtil + .calculateDiff(DiffCallBack(adapter.getItems(), it)) adapter.setItemsNoNotify(it) diffResult.dispatchUpdatesTo(adapter) }) From 0d127074c954da1d5a4048c01270efd6972d52a7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 11:12:03 +0800 Subject: [PATCH 072/140] up --- .../io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt | 4 ++++ app/src/main/res/layout/item_rss_source.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index 85aebdb18..35492aa48 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -6,13 +6,17 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.RssSource import io.legado.app.help.ItemTouchCallback +import kotlinx.android.synthetic.main.item_rss_source.view.* class RssSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_rss_source), ItemTouchCallback.OnItemTouchCallbackListener { override fun convert(holder: ItemViewHolder, item: RssSource, payloads: MutableList) { + with(holder.itemView) { + cb_source.text = item.sourceName + } } diff --git a/app/src/main/res/layout/item_rss_source.xml b/app/src/main/res/layout/item_rss_source.xml index 7d9513d98..d0ecd8788 100644 --- a/app/src/main/res/layout/item_rss_source.xml +++ b/app/src/main/res/layout/item_rss_source.xml @@ -9,7 +9,7 @@ android:padding="16dp"> Date: Wed, 2 Oct 2019 11:48:20 +0800 Subject: [PATCH 073/140] up --- .../io/legado/app/data/dao/RssSourceDao.kt | 9 +++ .../io/legado/app/data/entities/RssSource.kt | 5 +- .../rss/source/edit/RssSourceEditActivity.kt | 24 +++--- .../ui/rss/source/manage/RssSourceActivity.kt | 7 +- .../ui/rss/source/manage/RssSourceAdapter.kt | 77 ++++++++++++++++++- .../rss/source/manage/RssSourceViewModel.kt | 18 +++++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 125 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index d6b2d7767..e931f25d7 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -22,6 +22,15 @@ interface RssSourceDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg rssSource: RssSource) + @Query("update rssSources set enabled = 1 where sourceUrl in (:sourceUrls)") + fun enableSection(vararg sourceUrls: String) + + @Query("update rssSources set enabled = 0 where sourceUrl in (:sourceUrls)") + fun disableSection(vararg sourceUrls: String) + + @Query("delete from rssSources where sourceUrl in (:sourceUrls)") + fun delSection(vararg sourceUrls: String) + @Update fun update(vararg rssSource: RssSource) diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index d17ab598d..f15a14696 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -8,10 +8,11 @@ import kotlinx.android.parcel.Parcelize @Parcelize @Entity(tableName = "rssSources") data class RssSource( - var sourceName: String = "", @PrimaryKey var sourceUrl: String = "", - var iconUrl: String = "", + var sourceName: String = "", + var sourceIcon: String = "", + var sourceGroup: String? = null, var enabled: Boolean = true, var ruleGuid: String? = null, var ruleTitle: String? = null, diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index bb3e493ec..0636afda6 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -112,7 +112,8 @@ class RssSourceEditActivity : sourceEntities.apply { add(EditEntity("sourceName", rssSource?.sourceName, R.string.rss_source_name)) add(EditEntity("sourceUrl", rssSource?.sourceUrl, R.string.rss_source_url)) - add(EditEntity("iconUrl", rssSource?.iconUrl, R.string.rss_source_icon)) + add(EditEntity("sourceIcon", rssSource?.sourceIcon, R.string.rss_source_icon)) + add(EditEntity("sourceGroup", rssSource?.sourceGroup, R.string.rss_source_group)) add(EditEntity("ruleTitle", rssSource?.ruleTitle, R.string.rss_rule_title)) add(EditEntity("ruleAuthor", rssSource?.ruleAuthor, R.string.rss_rule_author)) add(EditEntity("ruleGuid", rssSource?.ruleGuid, R.string.rss_rule_guid)) @@ -144,16 +145,17 @@ class RssSourceEditActivity : when (it.key) { "sourceName" -> source.sourceName = it.value ?: "" "sourceUrl" -> source.sourceUrl = it.value ?: "" - "iconUrl" -> source.iconUrl = it.value ?: "" - "ruleTitle" -> source.ruleTitle = it.value ?: "" - "ruleAuthor" -> source.ruleAuthor = it.value ?: "" - "ruleGuid" -> source.ruleGuid = it.value ?: "" - "rulePubDate" -> source.rulePubDate = it.value ?: "" - "ruleCategories" -> source.ruleCategories = it.value ?: "" - "ruleDescription" -> source.ruleDescription = it.value ?: "" - "ruleImage" -> source.ruleImage = it.value ?: "" - "ruleContent" -> source.ruleContent = it.value ?: "" - "ruleLink" -> source.ruleLink = it.value ?: "" + "sourceIcon" -> source.sourceIcon = it.value ?: "" + "sourceGroup" -> source.sourceGroup = it.value + "ruleTitle" -> source.ruleTitle = it.value + "ruleAuthor" -> source.ruleAuthor = it.value + "ruleGuid" -> source.ruleGuid = it.value + "rulePubDate" -> source.rulePubDate = it.value + "ruleCategories" -> source.ruleCategories = it.value + "ruleDescription" -> source.ruleDescription = it.value + "ruleImage" -> source.ruleImage = it.value + "ruleContent" -> source.ruleContent = it.value + "ruleLink" -> source.ruleLink = it.value } } if (source.sourceName.isBlank() || source.sourceName.isBlank()) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 0a2c2f0bd..b2d996fb2 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -50,6 +50,11 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_add -> startActivity() + R.id.menu_select_all -> adapter.selectAll() + R.id.menu_revert_selection -> adapter.revertSelection() + R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds()) + R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) + R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) } return super.onCompatOptionsItemSelected(item) } @@ -103,7 +108,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } override fun edit(source: RssSource) { - + startActivity(Pair("data", source.sourceUrl)) } override fun update(vararg source: RssSource) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index 35492aa48..8dee3c485 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -1,21 +1,94 @@ package io.legado.app.ui.rss.source.manage import android.content.Context +import android.view.Menu +import android.widget.PopupMenu import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.RssSource import io.legado.app.help.ItemTouchCallback +import io.legado.app.lib.theme.backgroundColor import kotlinx.android.synthetic.main.item_rss_source.view.* +import org.jetbrains.anko.sdk27.listeners.onClick class RssSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_rss_source), ItemTouchCallback.OnItemTouchCallbackListener { + private val selectedIds = linkedSetOf() + + fun selectAll() { + getItems().forEach { + selectedIds.add(it.sourceUrl) + } + notifyItemRangeChanged(0, itemCount, 1) + } + + fun revertSelection() { + getItems().forEach { + if (selectedIds.contains(it.sourceUrl)) { + selectedIds.remove(it.sourceUrl) + } else { + selectedIds.add(it.sourceUrl) + } + } + notifyItemRangeChanged(0, itemCount, 1) + } + + fun getSelectionIds(): LinkedHashSet { + val selection = linkedSetOf() + getItems().map { + if (selectedIds.contains(it.sourceUrl)) { + selection.add(it.sourceUrl) + } + } + return selection + } + override fun convert(holder: ItemViewHolder, item: RssSource, payloads: MutableList) { with(holder.itemView) { - cb_source.text = item.sourceName - + if (payloads.isEmpty()) { + this.setBackgroundColor(context.backgroundColor) + if (item.sourceGroup.isNullOrEmpty()) { + cb_source.text = item.sourceName + } else { + cb_source.text = + String.format("%s (%s)", item.sourceName, item.sourceGroup) + } + swt_enabled.isChecked = item.enabled + swt_enabled.onClick { + item.enabled = swt_enabled.isChecked + callBack.update(item) + } + cb_source.isChecked = selectedIds.contains(item.sourceUrl) + cb_source.setOnClickListener { + if (cb_source.isChecked) { + selectedIds.add(item.sourceUrl) + } else { + selectedIds.remove(item.sourceUrl) + } + } + iv_edit.onClick { callBack.edit(item) } + iv_menu_more.onClick { + val popupMenu = PopupMenu(context, it) + popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top) + popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete) + popupMenu.setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.menu_top -> callBack.toTop(item) + R.id.menu_del -> callBack.del(item) + } + true + } + popupMenu.show() + } + } else { + when (payloads[0]) { + 1 -> cb_source.isChecked = selectedIds.contains(item.sourceUrl) + 2 -> swt_enabled.isChecked = item.enabled + } + } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index c91f73ef7..199532d72 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -1,8 +1,26 @@ package io.legado.app.ui.rss.source.manage import android.app.Application +import io.legado.app.App import io.legado.app.base.BaseViewModel class RssSourceViewModel(application: Application) : BaseViewModel(application) { + fun enableSelection(ids: LinkedHashSet) { + execute { + App.db.rssSourceDao().enableSection(*ids.toTypedArray()) + } + } + + fun disableSelection(ids: LinkedHashSet) { + execute { + App.db.rssSourceDao().disableSection(*ids.toTypedArray()) + } + } + + fun delSelection(ids: LinkedHashSet) { + execute { + App.db.rssSourceDao().delSection(*ids.toTypedArray()) + } + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a0bb5a060..bfe21f7a4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -379,6 +379,7 @@ 名称 url 图标 + 分组 标题 作者 guid From 34536c91c0d5d463522d309f67c1ba73343edf88 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 12:00:56 +0800 Subject: [PATCH 074/140] up --- app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 128fb6078..3d82b5320 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -39,8 +39,8 @@ object WebDavHelp { val url = getWebDavUrl() val names = arrayListOf() if (!url.isNullOrBlank() && initWebDav()) { - val files = WebDav(url + "legado/").listFiles() - files.reversed() + var files = WebDav(url + "legado/").listFiles() + files = files.reversed() for (index: Int in 0 until min(10, files.size)) { files[index].displayName?.let { names.add(it) From 1188b7089d487c5aeba47bb423c67ff7fa6807ef Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 12:15:06 +0800 Subject: [PATCH 075/140] up --- .../io/legado/app/data/dao/BookSourceDao.kt | 4 +- .../io/legado/app/data/dao/RssSourceDao.kt | 10 ++++- .../ui/rss/source/manage/RssSourceActivity.kt | 39 +++++++++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 39dc91264..334bb7a82 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -11,7 +11,7 @@ interface BookSourceDao { @Query("select * from book_sources order by customOrder asc") fun liveDataAll(): LiveData> - @Query("select * from book_sources where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceUrl like :searchKey order by customOrder asc") + @Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey order by customOrder asc") fun liveDataSearch(searchKey: String = ""): LiveData> @Query("select * from book_sources where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' order by customOrder asc") @@ -23,7 +23,7 @@ interface BookSourceDao { @Query("select bookSourceGroup from book_sources where bookSourceGroup is not null and bookSourceGroup <> ''") fun liveGroup(): LiveData> - @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceUrl like :searchKey") + @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey") fun searchIsEnable(searchKey: String = ""): List @Query("update book_sources set enabled = 1 where bookSourceUrl in (:sourceUrls)") diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index e931f25d7..9390b04ac 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -16,11 +16,14 @@ interface RssSourceDao { @Query("SELECT * FROM rssSources") fun liveAll(): LiveData> + @Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key") + fun liveSearch(key: String): LiveData> + @Query("SELECT * FROM rssSources where enabled = 1") fun liveEnabled(): LiveData> - @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(vararg rssSource: RssSource) + @Query("select sourceGroup from rssSources where sourceGroup is not null and sourceGroup <> ''") + fun liveGroup(): LiveData> @Query("update rssSources set enabled = 1 where sourceUrl in (:sourceUrls)") fun enableSection(vararg sourceUrls: String) @@ -31,6 +34,9 @@ interface RssSourceDao { @Query("delete from rssSources where sourceUrl in (:sourceUrls)") fun delSection(vararg sourceUrls: String) + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(vararg rssSource: RssSource) + @Update fun update(vararg rssSource: RssSource) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index b2d996fb2..4ef9c9a0f 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.rss.source.manage import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.view.SubMenu import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat import androidx.lifecycle.LiveData @@ -20,6 +21,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.utils.getViewModel +import io.legado.app.utils.splitNotBlank import kotlinx.android.synthetic.main.activity_rss_source.* import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* @@ -34,12 +36,15 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r private lateinit var adapter: RssSourceAdapter private var sourceLiveData: LiveData>? = null + private var groups = hashSetOf() + private var groupMenu: SubMenu? = null override fun onActivityCreated(savedInstanceState: Bundle?) { setSupportActionBar(toolbar) initRecyclerView() initSearchView() - initData() + initLiveDataGroup() + initLiveDataSource() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -47,6 +52,12 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r return super.onCompatCreateOptionsMenu(menu) } + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { + groupMenu = menu?.findItem(R.id.menu_group)?.subMenu + upGroupMenu() + return super.onPrepareOptionsMenu(menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_add -> startActivity() @@ -92,9 +103,31 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r }) } - private fun initData() { + private fun initLiveDataGroup() { + App.db.rssSourceDao().liveGroup().observe(this, Observer { + groups.clear() + it.map { group -> + groups.addAll(group.splitNotBlank(",", ";")) + } + upGroupMenu() + }) + } + + private fun upGroupMenu() { + groupMenu?.removeGroup(R.id.source_group) + groups.map { + groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) + } + } + + private fun initLiveDataSource(key: String? = null) { sourceLiveData?.removeObservers(this) - sourceLiveData = App.db.rssSourceDao().liveAll() + sourceLiveData = + if (key.isNullOrBlank()) { + App.db.rssSourceDao().liveAll() + } else { + App.db.rssSourceDao().liveSearch("%$key%") + } sourceLiveData?.observe(this, Observer { val diffResult = DiffUtil .calculateDiff(DiffCallBack(adapter.getItems(), it)) From 95b763104829d299addce01fb9e72315000224c3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 12:23:11 +0800 Subject: [PATCH 076/140] up --- .../java/io/legado/app/help/storage/Backup.kt | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 92333d1d3..97497a854 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -45,27 +45,43 @@ object Backup { } private fun backupBookshelf(path: String) { - val json = GSON.toJson(App.db.bookDao().allBooks) - val file = FileHelp.getFile(path + File.separator + "bookshelf.json") - file.writeText(json) + App.db.bookDao().allBooks.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + val file = FileHelp.getFile(path + File.separator + "bookshelf.json") + file.writeText(json) + } + } } private fun backupBookSource(path: String) { - val json = GSON.toJson(App.db.bookSourceDao().all) - val file = FileHelp.getFile(path + File.separator + "bookSource.json") - file.writeText(json) + App.db.bookSourceDao().all.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + val file = FileHelp.getFile(path + File.separator + "bookSource.json") + file.writeText(json) + } + } } private fun backupRssSource(path: String) { - val json = GSON.toJson(App.db.rssSourceDao().all) - val file = FileHelp.getFile(path + File.separator + "rssSource.json") - file.writeText(json) + App.db.rssSourceDao().all.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + val file = FileHelp.getFile(path + File.separator + "rssSource.json") + file.writeText(json) + } + } } private fun backupReplaceRule(path: String) { - val json = GSON.toJson(App.db.replaceRuleDao().all) - val file = FileHelp.getFile(path + File.separator + "replaceRule.json") - file.writeText(json) + App.db.replaceRuleDao().all.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + val file = FileHelp.getFile(path + File.separator + "replaceRule.json") + file.writeText(json) + } + } } private fun backupPreference(path: String) { From e034bb55a5d25d38b64f6a32e89477ce633bc60c Mon Sep 17 00:00:00 2001 From: mabdc <747455334@qq.com> Date: Wed, 2 Oct 2019 12:34:00 +0800 Subject: [PATCH 077/140] up --- app/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 98701bba5..8c0318cae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -70,6 +70,7 @@ + From c5c5aa0213adb0e6c72353c130749370e33dddb3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 12:58:16 +0800 Subject: [PATCH 078/140] up --- .../app/ui/rss/article/RssArticlesActivity.kt | 5 ++- app/src/main/res/layout/item_rss_article.xml | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/layout/item_rss_article.xml diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 3686dacdf..8e1e9ac6b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -13,8 +13,9 @@ import io.legado.app.data.entities.RssArticle import io.legado.app.model.rss.RssParser import io.legado.app.ui.rss.read.ReadRssActivity import kotlinx.android.synthetic.main.item_rss.view.* -import org.jetbrains.anko.* +import org.jetbrains.anko.listView import org.jetbrains.anko.sdk27.listeners.onItemClick +import org.jetbrains.anko.startActivity import java.net.URL class RssArticlesActivity : AppCompatActivity() { @@ -48,7 +49,7 @@ class RssArticlesActivity : AppCompatActivity() { class ArticleAdapter(var articles: MutableList, var context: Context) : BaseAdapter() { override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { - val item_rss = LayoutInflater.from(context).inflate(R.layout.item_rss, null) + val item_rss = LayoutInflater.from(context).inflate(R.layout.item_rss_article, null) val article = articles[position] item_rss.title.text = article.title item_rss.pub_date.text = article.pubDate diff --git a/app/src/main/res/layout/item_rss_article.xml b/app/src/main/res/layout/item_rss_article.xml new file mode 100644 index 000000000..d406fc228 --- /dev/null +++ b/app/src/main/res/layout/item_rss_article.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + \ No newline at end of file From dee7495f8fbaed3fbb355b335e497cd169d7d4af Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 15:48:44 +0800 Subject: [PATCH 079/140] up --- app/src/main/res/layout/item_rss.xml | 54 +++++++++------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/app/src/main/res/layout/item_rss.xml b/app/src/main/res/layout/item_rss.xml index da5b52d42..532f166b7 100644 --- a/app/src/main/res/layout/item_rss.xml +++ b/app/src/main/res/layout/item_rss.xml @@ -1,44 +1,24 @@ - + android:layout_height="wrap_content"> - - + - + - - - - \ No newline at end of file + \ No newline at end of file From b37141cbf9be50efce0017381603d65db9a3c2d8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 16:10:03 +0800 Subject: [PATCH 080/140] up --- .../java/io/legado/app/ui/main/rss/RssAdapter.kt | 13 +++++++++++-- app/src/main/res/layout/item_rss.xml | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt index 6bef664c6..a5efbf379 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt @@ -5,15 +5,24 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.RssSource +import io.legado.app.help.ImageLoader +import kotlinx.android.synthetic.main.item_rss.view.* +import org.jetbrains.anko.sdk27.listeners.onClick class RssAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_rss) { override fun convert(holder: ItemViewHolder, item: RssSource, payloads: MutableList) { - + with(holder.itemView) { + tv_name.text = item.sourceName + ImageLoader.load(context, item.sourceIcon) + .centerCrop() + .setAsBitmap(iv_icon) + onClick { callBack.openRss(item) } + } } interface CallBack { - fun openRss() + fun openRss(rssSource: RssSource) } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_rss.xml b/app/src/main/res/layout/item_rss.xml index 532f166b7..1b55a8ed1 100644 --- a/app/src/main/res/layout/item_rss.xml +++ b/app/src/main/res/layout/item_rss.xml @@ -9,6 +9,8 @@ android:id="@+id/iv_icon" android:layout_width="60dp" android:layout_height="60dp" + android:src="@drawable/ic_image" + android:scaleType="centerCrop" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" /> @@ -17,6 +19,7 @@ android:id="@+id/tv_name" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="16dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/iv_icon" /> From f41c2a7073d75d85e9dce26055c39b7d95b6251a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 16:12:43 +0800 Subject: [PATCH 081/140] up --- .../java/io/legado/app/ui/rss/article/RssArticlesActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 8e1e9ac6b..3ab686c7f 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -12,7 +12,7 @@ import io.legado.app.R import io.legado.app.data.entities.RssArticle import io.legado.app.model.rss.RssParser import io.legado.app.ui.rss.read.ReadRssActivity -import kotlinx.android.synthetic.main.item_rss.view.* +import kotlinx.android.synthetic.main.item_rss_article.view.* import org.jetbrains.anko.listView import org.jetbrains.anko.sdk27.listeners.onItemClick import org.jetbrains.anko.startActivity From 186e6c865501f39c9c221dc9d8f559fbf4f5464d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 16:14:05 +0800 Subject: [PATCH 082/140] up --- app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 0e0819ce5..aa3419b72 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.GridLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment +import io.legado.app.data.entities.RssSource import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.yesButton @@ -22,7 +23,6 @@ import io.legado.app.ui.rss.source.manage.RssSourceActivity import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_rss.* import kotlinx.android.synthetic.main.view_title_bar.* -import org.jetbrains.anko.padding class RssFragment : BaseFragment(R.layout.fragment_rss), RssAdapter.CallBack { @@ -78,7 +78,7 @@ class RssFragment : BaseFragment(R.layout.fragment_rss), }) } - override fun openRss() { + override fun openRss(rssSource: RssSource) { } } \ No newline at end of file From d6fc96ca19260b5dc0bf99d3f3adf18d94076dc6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 16:21:41 +0800 Subject: [PATCH 083/140] up --- app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt | 4 ++-- .../java/io/legado/app/ui/rss/article/RssArticlesActivity.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index aa3419b72..0dddd4426 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -58,7 +58,7 @@ class RssFragment : BaseFragment(R.layout.fragment_rss), } yesButton{ Log.i("RSS","Quick Add URL: ${urlEdit.text}") - startActivity("QuickAddURL" to urlEdit.text.toString().trim()) + startActivity("url" to urlEdit.text.toString().trim()) } }.show() } @@ -79,6 +79,6 @@ class RssFragment : BaseFragment(R.layout.fragment_rss), } override fun openRss(rssSource: RssSource) { - + startActivity(Pair("url", rssSource.sourceUrl)) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 3ab686c7f..3590627a1 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -21,9 +21,9 @@ import java.net.URL class RssArticlesActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (intent.hasExtra("QuickAddURL")) { + if (intent.hasExtra("url")) { // 处理从 快速添加并预览 跳转到这个页面 - val urlString = intent.getStringExtra("QuickAddURL") + val urlString = intent.getStringExtra("url") val adapter = ArticleAdapter(mutableListOf(), this) listView { this.adapter = adapter From 8a284c2b04a34bc106f2485dffcdc2831e7cfbd1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 16:50:09 +0800 Subject: [PATCH 084/140] up --- .../java/io/legado/app/data/AppDatabase.kt | 3 +- .../io/legado/app/data/dao/RssArticleDao.kt | 14 +++ .../app/ui/rss/article/RssArticlesActivity.kt | 91 ++++++------------- .../app/ui/rss/article/RssArticlesAdapter.kt | 27 ++++++ .../ui/rss/article/RssArticlesViewModel.kt | 10 ++ .../main/res/layout/activity_rss_artivles.xml | 26 ++++++ 6 files changed, 109 insertions(+), 62 deletions(-) create mode 100644 app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt create mode 100644 app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt create mode 100644 app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt create mode 100644 app/src/main/res/layout/activity_rss_artivles.xml diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index d58a5ccb7..3b17435d5 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -12,7 +12,7 @@ import io.legado.app.data.entities.* @Database( entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, - SearchKeyword::class, SourceCookie::class, RssSource::class, Bookmark::class], + SearchKeyword::class, SourceCookie::class, RssSource::class, Bookmark::class, RssArticle::class], version = 1, exportSchema = true ) @@ -58,4 +58,5 @@ abstract class AppDatabase : RoomDatabase() { abstract fun sourceCookieDao(): SourceCookieDao abstract fun rssSourceDao(): RssSourceDao abstract fun bookmarkDao(): BookmarkDao + abstract fun rssArtivleDao(): RssArticleDao } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt new file mode 100644 index 000000000..5935d76ce --- /dev/null +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -0,0 +1,14 @@ +package io.legado.app.data.dao + +import androidx.lifecycle.LiveData +import androidx.room.Query +import io.legado.app.data.entities.RssArticle + +interface RssArticleDao { + + + @Query("select * from rssArticles where origin = :origin") + fun liveByOrigin(origin: String): LiveData> + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 3590627a1..9df7a3aeb 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -1,75 +1,44 @@ package io.legado.app.ui.rss.article -import android.app.ProgressDialog -import android.content.Context import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.BaseAdapter -import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App import io.legado.app.R +import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.RssArticle -import io.legado.app.model.rss.RssParser -import io.legado.app.ui.rss.read.ReadRssActivity -import kotlinx.android.synthetic.main.item_rss_article.view.* -import org.jetbrains.anko.listView -import org.jetbrains.anko.sdk27.listeners.onItemClick -import org.jetbrains.anko.startActivity -import java.net.URL +import io.legado.app.lib.theme.ATH +import io.legado.app.utils.getViewModel +import kotlinx.android.synthetic.main.activity_rss_artivles.* -class RssArticlesActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - if (intent.hasExtra("url")) { - // 处理从 快速添加并预览 跳转到这个页面 - val urlString = intent.getStringExtra("url") - val adapter = ArticleAdapter(mutableListOf(), this) - listView { - this.adapter = adapter - onItemClick { p0, p1, p2, p3 -> - startActivity("description" to adapter.articles[p2].description) - } - } - val loading = ProgressDialog(this@RssArticlesActivity) - loading.setMessage("加载中...") - loading.show() - Thread { - val xml = URL(urlString).readText() - val articles = RssParser.parseXML(xml) - runOnUiThread { - adapter.articles = articles - adapter.notifyDataSetChanged() - loading.dismiss() - } - }.start() - } - } -} +class RssArticlesActivity : VMBaseActivity(R.layout.activity_rss_artivles) { -class ArticleAdapter(var articles: MutableList, var context: Context) : BaseAdapter() { - override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { - val item_rss = LayoutInflater.from(context).inflate(R.layout.item_rss_article, null) - val article = articles[position] - item_rss.title.text = article.title - item_rss.pub_date.text = article.pubDate - if (article.author != null && article.author != "") { - item_rss.author.text = article.author - } else { - item_rss.author.text = article.link - } - return item_rss - } + override val viewModel: RssArticlesViewModel + get() = getViewModel(RssArticlesViewModel::class.java) + + private var adapter: RssArticlesAdapter? = null + private var rssArticlesData: LiveData>? = null - override fun getItem(position: Int): Any { - return articles[position] + override fun onActivityCreated(savedInstanceState: Bundle?) { + initView() + intent.getStringExtra("url")?.let { + initData(it) + } } - override fun getItemId(position: Int): Long { - return 1 + private fun initView() { + ATH.applyEdgeEffectColor(recycler_view) + recycler_view.layoutManager = LinearLayoutManager(this) + adapter = RssArticlesAdapter(this) + recycler_view.adapter = adapter } - override fun getCount(): Int { - return articles.size + private fun initData(origin: String) { + rssArticlesData?.removeObservers(this) + rssArticlesData = App.db.rssArtivleDao().liveByOrigin(origin) + rssArticlesData?.observe(this, Observer { + adapter?.setItems(it) + }) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt new file mode 100644 index 000000000..0e185ab22 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -0,0 +1,27 @@ +package io.legado.app.ui.rss.article + +import android.content.Context +import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.data.entities.RssArticle +import kotlinx.android.synthetic.main.item_rss_article.view.* + + +class RssArticlesAdapter(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_rss_article) { + + override fun convert(holder: ItemViewHolder, item: RssArticle, payloads: MutableList) { + with(holder.itemView) { + title.text = item.title + pub_date.text = item.pubDate + if (item.author.isNullOrBlank()) { + author.text = item.link + } else { + author.text = item.author + } + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt new file mode 100644 index 000000000..344b1d098 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -0,0 +1,10 @@ +package io.legado.app.ui.rss.article + +import android.app.Application +import io.legado.app.base.BaseViewModel + + +class RssArticlesViewModel(application: Application) : BaseViewModel(application) { + + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_rss_artivles.xml b/app/src/main/res/layout/activity_rss_artivles.xml new file mode 100644 index 000000000..5665c8a24 --- /dev/null +++ b/app/src/main/res/layout/activity_rss_artivles.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + \ No newline at end of file From f40c386ed29ca1e704ba3d00c46fc7bb6b388a3d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 16:52:45 +0800 Subject: [PATCH 085/140] up --- .../legado/app/ui/book/read/ReadBookActivity.kt | 4 ++-- .../app/ui/book/read/config/ReadStyleDialog.kt | 2 +- .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 4 ++-- ...vity_read_book.xml => activity_book_read.xml} | 0 app/src/main/res/layout/activity_read_rss.xml | 10 ---------- app/src/main/res/layout/activity_rss_read.xml | 16 ++++++++++++++++ 6 files changed, 21 insertions(+), 15 deletions(-) rename app/src/main/res/layout/{activity_read_book.xml => activity_book_read.xml} (100%) delete mode 100644 app/src/main/res/layout/activity_read_rss.xml create mode 100644 app/src/main/res/layout/activity_rss_read.xml diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 2a3bf10a6..3b2400e56 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -42,7 +42,7 @@ import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.TextChapter import io.legado.app.ui.widget.page.delegate.PageDelegate import io.legado.app.utils.* -import kotlinx.android.synthetic.main.activity_read_book.* +import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.view_book_page.* import kotlinx.android.synthetic.main.view_read_menu.* import kotlinx.android.synthetic.main.view_title_bar.* @@ -55,7 +55,7 @@ import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast -class ReadBookActivity : VMBaseActivity(R.layout.activity_read_book), +class ReadBookActivity : VMBaseActivity(R.layout.activity_book_read), PageView.CallBack, ReadMenu.CallBack, ReadAloudDialog.CallBack, diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 114552bf6..d64fc4db9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -20,7 +20,7 @@ import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.widget.font.FontSelectDialog import io.legado.app.utils.* -import kotlinx.android.synthetic.main.activity_read_book.* +import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.dialog_read_book_style.* import org.jetbrains.anko.sdk27.listeners.onCheckedChange import org.jetbrains.anko.sdk27.listeners.onClick diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index e93f1e982..84d36c5eb 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -3,12 +3,12 @@ package io.legado.app.ui.rss.read import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import io.legado.app.R -import kotlinx.android.synthetic.main.activity_read_rss.* +import kotlinx.android.synthetic.main.activity_rss_read.* class ReadRssActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_read_rss) + setContentView(R.layout.activity_rss_read) val description = intent.getStringExtra("description") webView.loadData("$description","text/html", "utf-8") } diff --git a/app/src/main/res/layout/activity_read_book.xml b/app/src/main/res/layout/activity_book_read.xml similarity index 100% rename from app/src/main/res/layout/activity_read_book.xml rename to app/src/main/res/layout/activity_book_read.xml diff --git a/app/src/main/res/layout/activity_read_rss.xml b/app/src/main/res/layout/activity_read_rss.xml deleted file mode 100644 index 0650007cf..000000000 --- a/app/src/main/res/layout/activity_read_rss.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_rss_read.xml b/app/src/main/res/layout/activity_rss_read.xml new file mode 100644 index 000000000..5d403f5fe --- /dev/null +++ b/app/src/main/res/layout/activity_rss_read.xml @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file From 4356e9e30eb0f312d94f186e67deacfef66200e1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 16:54:05 +0800 Subject: [PATCH 086/140] up --- .../java/io/legado/app/ui/rss/article/RssArticlesActivity.kt | 1 + .../java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 9df7a3aeb..a7c09b1a8 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -24,6 +24,7 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi initView() intent.getStringExtra("url")?.let { initData(it) + viewModel.loadContent(it) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 344b1d098..86894d3a4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -6,5 +6,7 @@ import io.legado.app.base.BaseViewModel class RssArticlesViewModel(application: Application) : BaseViewModel(application) { + fun loadContent(url: String) { + } } \ No newline at end of file From 26d040c39b788c73c1fcb59be7775d97097b5066 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 17:05:31 +0800 Subject: [PATCH 087/140] up --- .../main/java/io/legado/app/data/dao/RssArticleDao.kt | 7 +++++-- .../java/io/legado/app/data/entities/RssArticle.kt | 1 + .../legado/app/ui/rss/article/RssArticlesViewModel.kt | 10 +++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index 5935d76ce..c90766948 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -1,14 +1,17 @@ package io.legado.app.data.dao import androidx.lifecycle.LiveData +import androidx.room.Insert +import androidx.room.OnConflictStrategy import androidx.room.Query import io.legado.app.data.entities.RssArticle interface RssArticleDao { - @Query("select * from rssArticles where origin = :origin") + @Query("select * from rssArticles where origin = :origin order by time desc") fun liveByOrigin(origin: String): LiveData> - + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(vararg rssArticle: RssArticle) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt index 6f8773ba3..4f24761e3 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt @@ -7,6 +7,7 @@ import androidx.room.PrimaryKey @Entity(tableName = "rssArticles") data class RssArticle( var origin: String = "", + var time: Long = System.currentTimeMillis(), @PrimaryKey var guid: String? = null, var title: String? = null, diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 86894d3a4..9a1b904f0 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -1,12 +1,20 @@ package io.legado.app.ui.rss.article import android.app.Application +import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.model.rss.RssParser +import java.net.URL class RssArticlesViewModel(application: Application) : BaseViewModel(application) { fun loadContent(url: String) { - + execute { + val xml = URL(url).readText() + RssParser.parseXML(xml).let { + App.db.rssArtivleDao().insert(*it.toTypedArray()) + } + } } } \ No newline at end of file From 9dffaf39b4cd6c784f7fbbb476ed518889e674b9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 17:07:08 +0800 Subject: [PATCH 088/140] up --- app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index c90766948..caa2fb293 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -1,14 +1,15 @@ package io.legado.app.data.dao import androidx.lifecycle.LiveData +import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import io.legado.app.data.entities.RssArticle +@Dao interface RssArticleDao { - @Query("select * from rssArticles where origin = :origin order by time desc") fun liveByOrigin(origin: String): LiveData> From 18e6d179a7f6173ad10ffcc99f8771159a60b8b8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 17:14:40 +0800 Subject: [PATCH 089/140] up --- .../java/io/legado/app/data/entities/RssArticle.kt | 12 +++++++++--- .../main/java/io/legado/app/model/rss/RssParser.kt | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt index 4f24761e3..1c89ff8ca 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt @@ -1,6 +1,7 @@ package io.legado.app.data.entities import androidx.room.Entity +import androidx.room.Ignore import androidx.room.PrimaryKey @@ -9,7 +10,7 @@ data class RssArticle( var origin: String = "", var time: Long = System.currentTimeMillis(), @PrimaryKey - var guid: String? = null, + var guid: String = "", var title: String? = null, var author: String? = null, var link: String? = null, @@ -17,5 +18,10 @@ data class RssArticle( var description: String? = null, var content: String? = null, var image: String? = null, - var categories: MutableList = mutableListOf() -) \ No newline at end of file + var categories: String? = null +) { + + @Ignore + var categoryList: MutableList = mutableListOf() + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/rss/RssParser.kt b/app/src/main/java/io/legado/app/model/rss/RssParser.kt index 2696fb26a..accd22de0 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParser.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParser.kt @@ -42,7 +42,7 @@ object RssParser { xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_AUTHOR, true) -> if (insideItem) currentArticle.author = xmlPullParser.nextText().trim() xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_CATEGORY, true) -> - if (insideItem) currentArticle.categories.add(xmlPullParser.nextText().trim()) + if (insideItem) currentArticle.categoryList.add(xmlPullParser.nextText().trim()) xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_THUMBNAIL, true) -> if (insideItem) currentArticle.image = xmlPullParser.getAttributeValue(null, RSSKeywords.RSS_ITEM_URL) @@ -92,6 +92,7 @@ object RssParser { ) { // The item is correctly parsed insideItem = false + currentArticle.categories = currentArticle.categoryList.joinToString(",") articleList.add(currentArticle) currentArticle = RssArticle() } From 1c44a4f6e40a958e3437c9e4485132374ad37ed8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 17:24:43 +0800 Subject: [PATCH 090/140] up --- .../java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 9a1b904f0..b1f8d70cb 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -13,6 +13,9 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application execute { val xml = URL(url).readText() RssParser.parseXML(xml).let { + it.forEach { rssArticle -> + rssArticle.origin = url + } App.db.rssArtivleDao().insert(*it.toTypedArray()) } } From fa01c3781c2e9c47974ba069b819c47b647397ec Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 17:30:52 +0800 Subject: [PATCH 091/140] up --- .../app/ui/rss/article/RssArticlesActivity.kt | 5 ++++- .../app/ui/rss/article/RssArticlesViewModel.kt | 4 +++- .../main/res/layout/activity_rss_artivles.xml | 17 +++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index a7c09b1a8..0a0168bf5 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -24,7 +24,9 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi initView() intent.getStringExtra("url")?.let { initData(it) - viewModel.loadContent(it) + viewModel.loadContent(it) { + refresh_progress_bar.isAutoLoading = false + } } } @@ -33,6 +35,7 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi recycler_view.layoutManager = LinearLayoutManager(this) adapter = RssArticlesAdapter(this) recycler_view.adapter = adapter + refresh_progress_bar.isAutoLoading = true } private fun initData(origin: String) { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index b1f8d70cb..f96478bf6 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -9,7 +9,7 @@ import java.net.URL class RssArticlesViewModel(application: Application) : BaseViewModel(application) { - fun loadContent(url: String) { + fun loadContent(url: String, onFinally: () -> Unit) { execute { val xml = URL(url).readText() RssParser.parseXML(xml).let { @@ -18,6 +18,8 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application } App.db.rssArtivleDao().insert(*it.toTypedArray()) } + }.onFinally { + onFinally() } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_rss_artivles.xml b/app/src/main/res/layout/activity_rss_artivles.xml index 5665c8a24..43c2e25f8 100644 --- a/app/src/main/res/layout/activity_rss_artivles.xml +++ b/app/src/main/res/layout/activity_rss_artivles.xml @@ -12,15 +12,24 @@ app:contentInsetStartWithNavigation="0dp" app:displayHomeAsUp="true" /> - + android:layout_height="2dp" + app:layout_constraintTop_toBottomOf="@id/title_bar" /> - + + - + \ No newline at end of file From e8f438e84e300f7d773662b4c872afc1f3681312 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 17:40:42 +0800 Subject: [PATCH 092/140] up --- .../app/ui/rss/article/RssArticlesActivity.kt | 9 +++++++-- .../app/ui/rss/article/RssArticlesAdapter.kt | 18 ++++++++++++------ app/src/main/res/layout/item_rss_article.xml | 6 +++--- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 0a0168bf5..cd0756c35 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -12,7 +12,8 @@ import io.legado.app.lib.theme.ATH import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_rss_artivles.* -class RssArticlesActivity : VMBaseActivity(R.layout.activity_rss_artivles) { +class RssArticlesActivity : VMBaseActivity(R.layout.activity_rss_artivles), + RssArticlesAdapter.CallBack { override val viewModel: RssArticlesViewModel get() = getViewModel(RssArticlesViewModel::class.java) @@ -33,7 +34,7 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - adapter = RssArticlesAdapter(this) + adapter = RssArticlesAdapter(this, this) recycler_view.adapter = adapter refresh_progress_bar.isAutoLoading = true } @@ -45,4 +46,8 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi adapter?.setItems(it) }) } + + override fun readRss(rssArticle: RssArticle) { + + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index 0e185ab22..cb209dc37 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -6,22 +6,28 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.RssArticle import kotlinx.android.synthetic.main.item_rss_article.view.* +import org.jetbrains.anko.sdk27.listeners.onClick -class RssArticlesAdapter(context: Context) : +class RssArticlesAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_rss_article) { override fun convert(holder: ItemViewHolder, item: RssArticle, payloads: MutableList) { with(holder.itemView) { - title.text = item.title - pub_date.text = item.pubDate + tv_title.text = item.title + tv_pub_date.text = item.pubDate if (item.author.isNullOrBlank()) { - author.text = item.link + tv_author.text = item.link } else { - author.text = item.author + tv_author.text = item.author + } + onClick { + callBack.readRss(item) } } } - + interface CallBack { + fun readRss(rssArticle: RssArticle) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_rss_article.xml b/app/src/main/res/layout/item_rss_article.xml index d406fc228..8f9c1d03b 100644 --- a/app/src/main/res/layout/item_rss_article.xml +++ b/app/src/main/res/layout/item_rss_article.xml @@ -14,7 +14,7 @@ android:layout_height="wrap_content"> Date: Wed, 2 Oct 2019 17:42:11 +0800 Subject: [PATCH 093/140] up --- .../java/io/legado/app/ui/rss/article/RssArticlesActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index cd0756c35..b332ecc0e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -9,8 +9,10 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.RssArticle import io.legado.app.lib.theme.ATH +import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_rss_artivles.* +import org.jetbrains.anko.startActivity class RssArticlesActivity : VMBaseActivity(R.layout.activity_rss_artivles), RssArticlesAdapter.CallBack { @@ -48,6 +50,6 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi } override fun readRss(rssArticle: RssArticle) { - + startActivity(Pair("description", rssArticle.description)) } } \ No newline at end of file From 8928f4ef2391f26ce439ddc9b31df8cd924d653a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 17:45:20 +0800 Subject: [PATCH 094/140] up --- app/src/main/res/layout/activity_rss_artivles.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/layout/activity_rss_artivles.xml b/app/src/main/res/layout/activity_rss_artivles.xml index 43c2e25f8..5eceec843 100644 --- a/app/src/main/res/layout/activity_rss_artivles.xml +++ b/app/src/main/res/layout/activity_rss_artivles.xml @@ -1,5 +1,5 @@ - + app:layout_constraintTop_toTopOf="parent" /> - \ No newline at end of file + \ No newline at end of file From ae7b937cd24932656c75c91188d50f43dbbb6b5a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 17:46:16 +0800 Subject: [PATCH 095/140] up --- .../java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 84d36c5eb..f13f41b61 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -1,15 +1,15 @@ package io.legado.app.ui.rss.read import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import io.legado.app.R +import io.legado.app.base.BaseActivity import kotlinx.android.synthetic.main.activity_rss_read.* -class ReadRssActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_rss_read) +class ReadRssActivity : BaseActivity(R.layout.activity_rss_read) { + + override fun onActivityCreated(savedInstanceState: Bundle?) { val description = intent.getStringExtra("description") webView.loadData("$description","text/html", "utf-8") } + } \ No newline at end of file From 8a05d8dde90554d8c0c75c6edfb013bddfe4b16b Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 18:18:34 +0800 Subject: [PATCH 096/140] up --- .../io/legado/app/ui/widget/image/FilletImageView.kt | 9 +++++---- app/src/main/res/layout/item_rss.xml | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt index bb6a4461e..d1c50fb31 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt @@ -7,6 +7,7 @@ import android.graphics.Path import android.util.AttributeSet import androidx.appcompat.widget.AppCompatImageView import io.legado.app.R +import kotlin.math.max class FilletImageView : AppCompatImageView { internal var width: Float = 0.toFloat() @@ -62,11 +63,11 @@ class FilletImageView : AppCompatImageView { override fun onDraw(canvas: Canvas) { //这里做下判断,只有图片的宽高大于设置的圆角距离的时候才进行裁剪 - val maxLeft = Math.max(leftTopRadius, leftBottomRadius) - val maxRight = Math.max(rightTopRadius, rightBottomRadius) + val maxLeft = max(leftTopRadius, leftBottomRadius) + val maxRight = max(rightTopRadius, rightBottomRadius) val minWidth = maxLeft + maxRight - val maxTop = Math.max(leftTopRadius, rightTopRadius) - val maxBottom = Math.max(leftBottomRadius, rightBottomRadius) + val maxTop = max(leftTopRadius, rightTopRadius) + val maxBottom = max(leftBottomRadius, rightBottomRadius) val minHeight = maxTop + maxBottom if (width >= minWidth && height > minHeight) { @SuppressLint("DrawAllocation") val path = Path() diff --git a/app/src/main/res/layout/item_rss.xml b/app/src/main/res/layout/item_rss.xml index 1b55a8ed1..6cff479c7 100644 --- a/app/src/main/res/layout/item_rss.xml +++ b/app/src/main/res/layout/item_rss.xml @@ -9,6 +9,7 @@ android:id="@+id/iv_icon" android:layout_width="60dp" android:layout_height="60dp" + android:background="@color/colorPrimary" android:src="@drawable/ic_image" android:scaleType="centerCrop" app:layout_constraintTop_toTopOf="parent" From 9dddc17d5e0cf8b7446f4c2a1428625742d78690 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 18:37:59 +0800 Subject: [PATCH 097/140] up --- .../legado/app/ui/book/info/BookInfoActivity.kt | 4 ++-- .../legado/app/ui/book/search/SearchAdapter.kt | 8 ++++---- .../legado/app/ui/explore/ExploreShowAdapter.kt | 4 ++-- .../legado/app/ui/main/bookshelf/BooksAdapter.kt | 4 ++-- .../java/io/legado/app/ui/main/rss/RssAdapter.kt | 2 ++ .../app/ui/widget/anima/RefreshProgressBar.kt | 8 ++++---- ...cover_default.jpg => image_cover_default.jpg} | Bin .../{img_cover_gs.jpg => image_cover_gs.jpg} | Bin app/src/main/res/drawable/image_rss.jpg | Bin 0 -> 9125 bytes .../main/res/layout-land/activity_book_info.xml | 2 +- app/src/main/res/layout/activity_audio_play.xml | 2 +- app/src/main/res/layout/activity_book_info.xml | 2 +- .../main/res/layout/activity_book_info_edit.xml | 2 +- app/src/main/res/layout/item_bookshelf_list.xml | 2 +- app/src/main/res/layout/item_rss.xml | 2 -- app/src/main/res/layout/item_search.xml | 2 +- 16 files changed, 22 insertions(+), 22 deletions(-) rename app/src/main/res/drawable/{img_cover_default.jpg => image_cover_default.jpg} (100%) rename app/src/main/res/drawable/{img_cover_gs.jpg => image_cover_gs.jpg} (100%) create mode 100644 app/src/main/res/drawable/image_rss.jpg diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 74d3b4495..3f78488de 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -88,8 +88,8 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo book.getDisplayIntro() // getString(R.string.intro_show, book.getDisplayIntro()) book.getDisplayCover()?.let { ImageLoader.load(this, it) - .placeholder(R.drawable.img_cover_default) - .error(R.drawable.img_cover_default) + .placeholder(R.drawable.image_cover_default) + .error(R.drawable.image_cover_default) .centerCrop() .setAsDrawable(iv_cover) } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index a2cb9ad08..38974157d 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -84,8 +84,8 @@ class SearchAdapter(val callBack: CallBack) : } searchBook.coverUrl.let { ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.img_cover_default) - .error(R.drawable.img_cover_default) + .placeholder(R.drawable.image_cover_default) + .error(R.drawable.image_cover_default) .centerCrop() .setAsDrawable(iv_cover) } @@ -100,8 +100,8 @@ class SearchAdapter(val callBack: CallBack) : 1 -> bv_originCount.setBadgeCount(searchBook.originCount) 2 -> searchBook.coverUrl.let { ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.img_cover_default) - .error(R.drawable.img_cover_default) + .placeholder(R.drawable.image_cover_default) + .error(R.drawable.image_cover_default) .centerCrop() .setAsDrawable(iv_cover) } diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt index 6510735f5..1a248e736 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt @@ -59,8 +59,8 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : } item.coverUrl.let { ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.img_cover_default) - .error(R.drawable.img_cover_default) + .placeholder(R.drawable.image_cover_default) + .error(R.drawable.image_cover_default) .centerCrop() .setAsDrawable(iv_cover) } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt index d6df919e0..5152278ca 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt @@ -72,8 +72,8 @@ class BooksAdapter(private val callBack: CallBack) : tv_last.text = book.latestChapterTitle book.getDisplayCover()?.let { ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.img_cover_default) - .error(R.drawable.img_cover_default) + .placeholder(R.drawable.image_cover_default) + .error(R.drawable.image_cover_default) .centerCrop() .setAsDrawable(iv_cover) } diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt index a5efbf379..b490c8ec8 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt @@ -17,6 +17,8 @@ class RssAdapter(context: Context, val callBack: CallBack) : tv_name.text = item.sourceName ImageLoader.load(context, item.sourceIcon) .centerCrop() + .placeholder(R.drawable.image_rss) + .error(R.drawable.image_rss) .setAsBitmap(iv_icon) onClick { callBack.openRss(item) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt b/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt index 3eee366be..1095d5889 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt @@ -16,15 +16,15 @@ class RefreshProgressBar @JvmOverloads constructor( attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : View(context, attrs, defStyleAttr) { - internal var a = 1 - var maxProgress = 100 + private var a = 1 private var durProgress = 0 - var secondMaxProgress = 100 private var secondDurProgress = 0 + var maxProgress = 100 + var secondMaxProgress = 100 var bgColor = 0x00000000 var secondColor = -0x3e3e3f var fontColor = -0xc9c9ca - var speed = 1 + var speed = 2 var secondFinalProgress = 0 private set private var paint: Paint = Paint() diff --git a/app/src/main/res/drawable/img_cover_default.jpg b/app/src/main/res/drawable/image_cover_default.jpg similarity index 100% rename from app/src/main/res/drawable/img_cover_default.jpg rename to app/src/main/res/drawable/image_cover_default.jpg diff --git a/app/src/main/res/drawable/img_cover_gs.jpg b/app/src/main/res/drawable/image_cover_gs.jpg similarity index 100% rename from app/src/main/res/drawable/img_cover_gs.jpg rename to app/src/main/res/drawable/image_cover_gs.jpg diff --git a/app/src/main/res/drawable/image_rss.jpg b/app/src/main/res/drawable/image_rss.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a152df50636b1ba8398bdc90679fc56480a6b1ec GIT binary patch literal 9125 zcmeHsd0bQ1_HPhHYehvsltC(720=h%k|Ck33~eFA7-Gs8nPm!+kRV~Iw<_J#mg0a6DKNgX;UC3Q&Z@L{PVM^7F-`pG9p z<&K{?c2Ys^%ozo_)29_xG*lIp)Rj-4{_Nss>Y7>?bS|7#)w`speMv+6g7$tV5{C~T zK6>P+?9rpL+KQ(Ywg0z|y;lI4BN8GBk)(tg;DC&Tq>RKK6QB%`0349q7x!Ps0V#=t zhYv{}5x3f$lmJLb9*~eaA}x79N^<`Zi35@{2M?W>I%W6;)Js-QE&T42vhKsD)h`== zc^!_%r2qKZ#CuF0_BW%eeP00116Iv{!I@V)>hGW$bF9F#h8 z_@7ezK7@Dx+4IowAG@XGFJJe1QubO-&FJpf;*$E8-g|?9W0K-NWh7+))_@(m|IqRO zQ-51va!gjInuTx9t2Y}P?6mcg_^o@So#Lr_n?1m=bU2>3NCkz}SG?Oi(h|{S3k3y! zo#zNS{Oa(p|9zNZumv^^8#-&CuGEUDtj0s0t+YKr5hCIxr&aEK>fMRpPtA$F(+#+S zTy*V&F`+aw*)A1Lnvu`s2 z&E}V1or%@+pmW`4v0R%qW`myTI(|fL)euJnJm6gpVRuzG171Sa;8>%foMCE;;_#Vvsucj!T)sLg%S*ZpzyNN9K z09lAK>KKBZW9u~}KOfQyDRLIu#>=I@A z$OVnBr@e@Z$=ez{j@xy(#qAFMIar%beL-ggkd+*;v`SC1ZjE^&CWsuE_m!m2`+qmn z6Ax;pBKH9Lr9Sf;!EyH~+l+=sh&_N4ecI2y>gZJ~%WECxSx+w(-xglM73LUymUWzy z5M-Wy`IG;H8~O5FR4p}$OeiFIErbs7;D%u?hO%6=1yEK_5B_B=)NLa9y&9( zTD$&CaXi_Zk|;i=vi+QfA{_=TNT66cLyN|$y0v%x|ZNv$oQ@9 zP7SB`w_Q;oir>8S_4Hhr6$p-{u_Cc=bNjm-XP(``h-H{jYv<`-*yw(fNC|AchB+ZSt})38%~KHU0Wq8Od^qm7y59UNW=5Bq^nt2F2ufr*V)c|j zOHM_nv9fX_Gel}*`$D3-@RR$7iPwqqVFu4R_1-y{OtLZEha#|J55&8pl{v{n5EJ(|* zBx-O9$J`+gll?Z6{B6Mg@8f2x@w`^Y2WJJ!lb3xjbzKn{rk{Th#cKIBJ3EJ^o__v* zf$xa-f*FKL>zE?fZ4Prr)_DS5{nzy?9~q%=Po%AU7czowsSvv011ToHgsl~rsk@Nc zcJ$g}E`Fv*|MowHPV(4y|7bI`^1LxtHeF?C;+iHIS)Dxwx`S`FD|85kIq?TE$Amm8 zZ!)ndp>$}~Lh+?*nmUznhgrEi#pQq_*d|Q4qlo!Jx+}dGkxNj9A{>W^i7PlA%d6e( z!pR2X1^WQ&p{jn4P%&t`2LDp0)v*H4#p#3Vd*Qa>oKp|Hz9snQFx%XU&SbNG^LWkU z^QYcsV5Dwd%5*HuHj=nk?x*}Z`ZzI*Z;tX8%&SZ= zK}p3qiTk9|cRN0#QGVc+_f}re;G;(QeM;Nr6xbakA8#2C&i&ib5XSH z;E66w`v-o+Vvd`cT9g@O*rYdR7(NPiS*tEVe~+~Jh|n%wf~hvQb%hfrl1v73pH7-rtE2bs0kBrqe!9Tc==@JDxS8gcMt2$F3i=nZ8J9Gzn&t} zL_Xsxw<1m9(0*GNuBF41=d~)K_menCEv~(FF}MU125SX{LODlqvsI%*vutQr1yDi#;~Y|^&elwu znlznMoXupmIiy$OZ1W?+ZkN_{RT+S3bmn*p&YbSpAYAaGwpr{ZY0^AQ+-8f|Lq~U= zfu5=JPX+ck!}a-ZFOHB_EqlLlxttoEvaU8(^NDY}`MeSDX4CI?&g_$dI1X$*rjgat zvN`8T5>o4`IOd5l7+yf#S`NWqCvi66ZINMOgbEF5H}*U^!&^61o-?4=4;sX-3OA{! z?i|t`1SG_uTE9Dvtq=;AhdTRfOhu~(+Ew@Iu8pU)eV_*$S9rf@`y>{CJNfDl%=qn6 z>gAY78p4OqWi}(jcMFQQsSQuL@uHdeOy}rplOHdqM4ZrZ7n9ij^~D^UgXMlFPqpL1 zcx7na3N%$Wl@V~_al2+Q88e5%Kos^vr25sc0Ev+OHc6CBqN0y|`r#y&eW_&ES!CQQ;_sZ!Jl z$B=2^-H4dTpS|@=dh(PQjL#i3p%TC0vHnqy zap%*K3;4KiCO#Tj-zZ%!Rf+nhCy3VLkz9#h+A#5~0MBS9<$rZ&JCFAw+MZQ!Z4i9l zV~K0vHI0uJ1?jCm>#INCCG&B3pvF5Zb72lsp%)Ub(- zbg+!;HP3S}x9Molx+r!y6K}jO=Gbdq-6xuOxzmKceZ0>#u|w{N4<5!UVOfK;d=x&E z+YJ&Fr0Z4F`~4|&-UqKoxam5jDm$<4>Jkp5c92c2t5FxY(a69>k#aeEHd7ylW@BvI z@3dU2o3q?e>Ck#n z_`@-0T${UvNpdB!!gdJONvdTzWb%V1P~$6=W;(mGQ9I)wU4ZBMMF{H??yKpw;5H<<)3p z+_+tu8viK>t~auYcc5?VJ4sm?Lqo&tYjxl%r%}pc zwa>2N#NzJ29I`+fMHs07dnETxCXLGuj|f761x}34h26q?dw}TcB76>qH^OIkl>4po zDkF^*I|$Kbt;EDFC|57!#e6*mRZOBVoBG9hfjq3~x)^D{2WS7+iL~RRSEm<-8c^XL zvYm-B<$h~o570cp$!0QAhpB~bg;kWAZg+p5a{O318LfMJF>VP4IXWW(+u!N@u>SH%9Y$fV`AH`zMn~>uE+~d+C7QPr+oulsMkfAyb&l)n>)% z5pgW)=lH?fJxkL=za%S^n6FY`dnE>i#)Opa0ZQa{70K4mE|=P^$}~}ymcR80aTPdj znD;rBD%7cyN_XKyeS$986K1eCJGN)@O-aL@Go-)*{;B!qKDXK7u85zYm7>*^Hhe|8 z-mpK1-aQ#MO}8~%El!QVkNuc+nNJlu3BwJolyL2watuk|vW#RLwwY4$Cou$nk7xGfmKwn#qP z3P_xN0i=d|ZwnIO9=ECZt3S+a!(~R-3M%T#u^zF9kTvN|`^tqyF8&8Y`d#!@&M3WQ zD>AfGmqejzy;QOPqPWmyU#lx9Sbzj;3pbvj`SOGGTlHXPgo-iuOg45hRZul;rW7*_rVtpkRC)X7 zo_%;r)C+D=9>jMMD;n}-#OqD5a4Trmdd@<$+o)ERWtatDW~_1)l|2q2o>ME1hhQL{ z{CCXyHF`Hbe@5$4XEba57vpNLJnEnhg zDLbx=2Gn;VaBj(?(CpGYECgRr($h(p<8(Zh{NbT-O{}!igTK!cU-(nlMgs`v8ao9& z4myWKKh>T@7SrTT^WzZ`%`CVEtx1^5AybIOSAnzE`lfpTNwL}4L@C4&wy0?_(ejbG z!N%OcFnACh>Eu8rh>%qZ>bd3%MkBA1M*lS*@l>VGc12?X`<~SaE6-`Qc-L=(aO7BNywj%YkaffXslSF+;#-w~M{|82irKh;*Ik8$Ytdm~&PeiF zaXsWp`x6{btRv#*((If6iRzCz+O%pK9nI2?G627!L901(ylE;c0zNrM!O$};Ncn`q_l<}%#q#Vxr++b-kPO%;zPCEJ=Lqd6`Y z6kjgY)3d9_8c)GCQ;yjPk_|qGy^?tTVyc*DIy4y78kE8@;yOo|gTk8M5)$Uw*_7oBiC6s%6V_j9HNmc4QW^0$wbTuGVMgX7Ez4kGne=kgHoyle?4lM27>)UdI{RS@DwRQ|&Jd_XBcoQoduYGwF1N+R%~o~5_M;fVHE?Hy!C*w;@IuwcpZglgC zwHUjK$jS{!nYz&DmiCOZJ%{by1xIt>DN+d)oavu{B;2+oI+{u`RyZbfeQEwd-s?P{rxlLc-0VD(6{aQxiFn zJ4t5+;`WID>&p{WM5U1WA}R)+v=LR5R-=2Ouz%fvT|DM|r)?=q7UeP`cE=eT-}D`r zpaCRvmlqt~o0Wd*7-cq<)L_^Y`GiAFr8$aS+S|Jt36BTUBpabNoocJ{(Ct0I(Mh*l;2z-g za70$cLz2)46teVnH*YGe8|m9@M;-mzpK9stanJiK{`$Q?azgS{2l6&O^p=U4Iyo5* zpGjyh!f7G{Q&?A@g>4S>&u`|g7#Xu+VCx50u6DhD5I}eAV4)CZx`df=VAz*6D7|hu z`y-IMuaCXWx!Lu};+6CJWws6FldPP_&F?0vt0OEY2`@e*Kf9yzg3~;dh)p<2E+#XA z5}C|Nm2z&(Rs>>=q!B7Y&9UW&h%nieJ%Ie9h9EVDK5jLpvG_U?aZwCHllJ^Hp$U|hL*WE#r^>f|Pmdl?i3dG5 zy1bGfm%BKaRMK{YNawHE#xI?|P}fy}k2!wC-?3fshV1*>SNBVV|CIe=-d*k;>G@E{ zk7iSZSi@G})1Up_azUhsdiv9~a5)ch0GnuC?v%7}H7+?n{m5p$haO={nBaTHZ(8RF z!0IJzdON_Y&#moDjY%8v${ygj!|TEMZUsHAEz*>doh9FBGuVh8_ArJUcah)*U+Z~` z=gMsB*m0>o#Nv3UaCSb53!7reDu3CpY#NCxn+1}8KP#?mLcTxSc4m6NoO!(ahx##* zMfB*r8@bfo^qlqIP#Y+xDRFq&qTJ=oia+5sO~7wDIQI|97=Rk>`0bRr8~`fl54u;C zj;*UF^}3}Jgj@(+6{oRG8A(idm*?aT!YFI~)WPAKCgFBwVF71IL4xj$fRt#W8;d@a z3unuRrxyJM33KgMQ98`UJr#A>WQ&Ka}NM)9*W#!jOh>OI+p}W=s!;pr5Z?ic*SfMu*v( ze=IZJq-IA$95{#`7t+gjiHlMEO$*B^=)h$Fuh;zW1-%WGJpj_iPQ8f@ogUw2Y-KLb zj~ZoU38;))w6(Uy(oI{t2oZO{Ixx~y`rAf0uxvfyZu-Te=y&3MA4&0+&oMDb7GbY< zI^$l;?Ic&h<_h?Juw7|d=Mc4UZn%rC&Z`A}>c?&PsmA({>@7|`l@9vslc~@Dpfx}V zddN@gCKW^?0o+^DTYVPRf849}3dEtVm`9x`c+~G%8v2mDy+jwsb-=O#oyma#xF?aw z!mgzD$NLI(LhZl65~(23thtjBq{4eS~2I3VtOiFr|ZpMm(()t~k+<>{2)fEYqsD#kaJrn4i^c zk>PempR6Lx;=jQl&Rye8;Mlv*YA~g+NANi~a;*)n3oz)r$noa672dm`PzuM_)gjLU zLW2MjZRWPYuND}a>V?g4P+iyZ917CmYM%F;yS@^z2RMV+Q7baNKr4^ynV&n_xB$04 z@xsa~=aQF`+p(NWH~)F6n7v;xD3F3jDcuK(AXRs+y*yUL$1d$uLaJhsxQhZ?`-RnK>cOoh z*xk{u09fTeZ@Nllj#o|9D4H|aKm|+9JC0FB&t198vR`|^EJES49$Xu^YSV-o^4IBA z+1w19c5uGmmdcHp?E8m5NVE0;*9ujif!5a2A2TemHZxTUrIE0t^S5QD-fdb07}}@& z1h1;X+G#c(3A$w})Eo`VDJ-+4%x0$=35YqN-xq@Ax|J$h&mW+Yi`lRofG<q%=&Rf6Nb<<3mvP>CKKHH;9kyc=E_R=uN~K`thpDR=^vlbDcYV4slnFk20qV_H zB!sju{PVzPI|Dk)rOiZZt8(D_C)ud7xO(}P4ou=-47()xyI`D#|68JGoOo#VaW6!Vg0^p5omQA_;umBRRHTB_(eW_L98nq?uC1ja=USAS70eVz}b^p@5=0m4{K0{ gC-27XM9$`BX&HSc&Hj_8_@n3e|JT1Eus85O0E22~1poj5 literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout-land/activity_book_info.xml b/app/src/main/res/layout-land/activity_book_info.xml index d043d23f7..a284835eb 100644 --- a/app/src/main/res/layout-land/activity_book_info.xml +++ b/app/src/main/res/layout-land/activity_book_info.xml @@ -28,7 +28,7 @@ android:layout_width="86dp" android:layout_height="120dp" android:layout_margin="10dp" - android:src="@drawable/img_cover_default" + android:src="@drawable/image_cover_default" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/title_bar" /> diff --git a/app/src/main/res/layout/activity_audio_play.xml b/app/src/main/res/layout/activity_audio_play.xml index 2a392be02..ec6bbd556 100644 --- a/app/src/main/res/layout/activity_audio_play.xml +++ b/app/src/main/res/layout/activity_audio_play.xml @@ -25,7 +25,7 @@ android:layout_height="260dp" android:layout_gravity="center" android:contentDescription="@string/img_cover" - android:src="@drawable/img_cover_default" + android:src="@drawable/image_cover_default" app:layout_constraintTop_toBottomOf="@+id/title_bar" app:layout_constraintBottom_toTopOf="@+id/ll_player_progress" app:layout_constraintLeft_toLeftOf="parent" diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index 0f4028383..9c2887c68 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -19,7 +19,7 @@ android:layout_height="120dp" android:layout_margin="10dp" android:scaleType="centerCrop" - android:src="@drawable/img_cover_default" + android:src="@drawable/image_cover_default" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/title_bar" /> diff --git a/app/src/main/res/layout/activity_book_info_edit.xml b/app/src/main/res/layout/activity_book_info_edit.xml index 4244c2b89..12328a069 100644 --- a/app/src/main/res/layout/activity_book_info_edit.xml +++ b/app/src/main/res/layout/activity_book_info_edit.xml @@ -34,7 +34,7 @@ android:layout_height="126dp" android:contentDescription="@string/img_cover" android:scaleType="centerCrop" - android:src="@drawable/img_cover_default" /> + android:src="@drawable/image_cover_default" /> Date: Wed, 2 Oct 2019 18:40:52 +0800 Subject: [PATCH 098/140] up --- .../main/java/io/legado/app/ui/widget/image/FilletImageView.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt index d1c50fb31..bcb449329 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt @@ -7,6 +7,7 @@ import android.graphics.Path import android.util.AttributeSet import androidx.appcompat.widget.AppCompatImageView import io.legado.app.R +import io.legado.app.utils.dp import kotlin.math.max class FilletImageView : AppCompatImageView { @@ -30,7 +31,7 @@ class FilletImageView : AppCompatImageView { private fun init(context: Context, attrs: AttributeSet) { // 读取配置 val array = context.obtainStyledAttributes(attrs, R.styleable.FilletImageView) - val defaultRadius = 5 + val defaultRadius = 5.dp val radius = array.getDimensionPixelOffset(R.styleable.FilletImageView_radius, defaultRadius) leftTopRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_left_top_radius, defaultRadius) rightTopRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_right_top_radius, defaultRadius) From f3b2e296e767f60081dafa7ae0401fd77344a788 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 22:57:03 +0800 Subject: [PATCH 099/140] up --- .../app/ui/rss/article/RssArticlesAdapter.kt | 5 -- app/src/main/res/layout/item_rss_article.xml | 74 +++++++++---------- 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index cb209dc37..f75ad0f21 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -16,11 +16,6 @@ class RssArticlesAdapter(context: Context, val callBack: CallBack) : with(holder.itemView) { tv_title.text = item.title tv_pub_date.text = item.pubDate - if (item.author.isNullOrBlank()) { - tv_author.text = item.link - } else { - tv_author.text = item.author - } onClick { callBack.readRss(item) } diff --git a/app/src/main/res/layout/item_rss_article.xml b/app/src/main/res/layout/item_rss_article.xml index 8f9c1d03b..6a9e5aba1 100644 --- a/app/src/main/res/layout/item_rss_article.xml +++ b/app/src/main/res/layout/item_rss_article.xml @@ -1,45 +1,43 @@ - + android:layout_height="100dp" + android:padding="16dp"> - + - + - + - - - - \ No newline at end of file + \ No newline at end of file From b5565a96c5926a70cdf3c7dc97a86ced12346117 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 23:04:37 +0800 Subject: [PATCH 100/140] up --- .../io/legado/app/ui/rss/article/RssArticlesAdapter.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index f75ad0f21..55e45bfc8 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -5,6 +5,9 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.RssArticle +import io.legado.app.help.ImageLoader +import io.legado.app.utils.gone +import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_rss_article.view.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -19,6 +22,13 @@ class RssArticlesAdapter(context: Context, val callBack: CallBack) : onClick { callBack.readRss(item) } + if (item.image.isNullOrBlank()) { + image_view.gone() + } else { + image_view.visible() + ImageLoader.load(context, item.image) + .setAsBitmap(image_view) + } } } From cbb2ef24aecd0f458ddd9d310915d7be5c953b0d Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 09:40:25 +0800 Subject: [PATCH 101/140] up --- .../io/legado/app/data/entities/RssSource.kt | 2 + .../java/io/legado/app/model/rss/RssParser.kt | 3 +- .../legado/app/model/rss/RssParserByRule.kt | 79 +++++++++++++++++++ .../ui/rss/article/RssArticlesViewModel.kt | 14 +++- 4 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index f15a14696..4537747a1 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -14,6 +14,8 @@ data class RssSource( var sourceIcon: String = "", var sourceGroup: String? = null, var enabled: Boolean = true, + //列表规则 + var ruleArticles: String? = null, var ruleGuid: String? = null, var ruleTitle: String? = null, var ruleAuthor: String? = null, diff --git a/app/src/main/java/io/legado/app/model/rss/RssParser.kt b/app/src/main/java/io/legado/app/model/rss/RssParser.kt index accd22de0..7363a349e 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParser.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParser.kt @@ -11,7 +11,7 @@ import java.io.StringReader object RssParser { @Throws(XmlPullParserException::class, IOException::class) - fun parseXML(xml: String): MutableList { + fun parseXML(xml: String, sourceUrl: String): MutableList { val articleList = mutableListOf() var currentArticle = RssArticle() @@ -93,6 +93,7 @@ object RssParser { // The item is correctly parsed insideItem = false currentArticle.categories = currentArticle.categoryList.joinToString(",") + currentArticle.origin = sourceUrl articleList.add(currentArticle) currentArticle = RssArticle() } diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt new file mode 100644 index 000000000..6880976ab --- /dev/null +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -0,0 +1,79 @@ +package io.legado.app.model.rss + +import io.legado.app.data.entities.RssArticle +import io.legado.app.data.entities.RssSource +import io.legado.app.model.analyzeRule.AnalyzeRule +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +object RssParserByRule { + + @Throws(XmlPullParserException::class, IOException::class) + fun parseXML(xml: String, rssSource: RssSource): MutableList { + + val articleList = mutableListOf() + + val analyzeRule = AnalyzeRule() + analyzeRule.setContent(xml) + + rssSource.ruleArticles?.let { ruleArticles -> + val collections = analyzeRule.getElements(ruleArticles) + val ruleGuid = analyzeRule.splitSourceRule(rssSource.ruleGuid ?: "") + val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle ?: "") + val ruleAuthor = analyzeRule.splitSourceRule(rssSource.ruleAuthor ?: "") + val rulePubDate = analyzeRule.splitSourceRule(rssSource.rulePubDate ?: "") + val ruleCategories = analyzeRule.splitSourceRule(rssSource.ruleCategories ?: "") + val ruleDescription = analyzeRule.splitSourceRule(rssSource.ruleDescription ?: "") + val ruleImage = analyzeRule.splitSourceRule(rssSource.ruleImage ?: "") + val ruleContent = analyzeRule.splitSourceRule(rssSource.ruleContent ?: "") + val ruleLink = analyzeRule.splitSourceRule(rssSource.ruleLink ?: "") + for ((index, item) in collections.withIndex()) { + getItem( + item, + analyzeRule, + index == 0, + ruleGuid, + ruleTitle, + ruleAuthor, + rulePubDate, + ruleCategories, + ruleDescription, + ruleImage, + ruleContent, + ruleLink + ) + } + } ?: let { + return RssParser.parseXML(xml, rssSource.sourceUrl) + } + return articleList + } + + private fun getItem( + item: Any, + analyzeRule: AnalyzeRule, + printLog: Boolean, + ruleGuid: List, + ruleTitle: List, + ruleAuthor: List, + rulePubDate: List, + ruleCategories: List, + ruleDescription: List, + ruleImage: List, + ruleContent: List, + ruleLink: List + ): RssArticle? { + val rssArticle = RssArticle() + analyzeRule.setContent(item) + rssArticle.guid = analyzeRule.getString(ruleGuid) + rssArticle.title = analyzeRule.getString(ruleTitle) + rssArticle.author = analyzeRule.getString(ruleAuthor) + rssArticle.pubDate = analyzeRule.getString(rulePubDate) + rssArticle.categories = analyzeRule.getString(ruleCategories) + rssArticle.description = analyzeRule.getString(ruleDescription) + rssArticle.image = analyzeRule.getString(ruleImage) + rssArticle.content = analyzeRule.getString(ruleContent) + rssArticle.link = analyzeRule.getString(ruleLink) + return rssArticle + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index f96478bf6..39f0f22e2 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -4,6 +4,7 @@ import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.model.rss.RssParser +import io.legado.app.model.rss.RssParserByRule import java.net.URL @@ -11,15 +12,20 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application fun loadContent(url: String, onFinally: () -> Unit) { execute { + val rssSource = App.db.rssSourceDao().getByKey(url) val xml = URL(url).readText() - RssParser.parseXML(xml).let { - it.forEach { rssArticle -> - rssArticle.origin = url + if (rssSource == null || rssSource.ruleArticles.isNullOrBlank()) { + RssParser.parseXML(xml, url).let { + App.db.rssArtivleDao().insert(*it.toTypedArray()) + } + } else { + RssParserByRule.parseXML(xml, rssSource).let { + App.db.rssArtivleDao().insert(*it.toTypedArray()) } - App.db.rssArtivleDao().insert(*it.toTypedArray()) } }.onFinally { onFinally() } } + } \ No newline at end of file From 439b78c6ca4649b4c1a035a8ac6897e20ecb3ac7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 09:52:23 +0800 Subject: [PATCH 102/140] up --- .../io/legado/app/ui/rss/article/RssArticlesActivity.kt | 3 +++ .../io/legado/app/ui/rss/article/RssArticlesViewModel.kt | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index b332ecc0e..f72a98048 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -25,6 +25,9 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi override fun onActivityCreated(savedInstanceState: Bundle?) { initView() + viewModel.titleLiveData.observe(this, Observer { + title_bar.title = it + }) intent.getStringExtra("url")?.let { initData(it) viewModel.loadContent(it) { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 39f0f22e2..a4ddecf4d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.rss.article import android.app.Application +import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.model.rss.RssParser @@ -10,9 +11,14 @@ import java.net.URL class RssArticlesViewModel(application: Application) : BaseViewModel(application) { + val titleLiveData = MutableLiveData() + fun loadContent(url: String, onFinally: () -> Unit) { execute { val rssSource = App.db.rssSourceDao().getByKey(url) + rssSource?.let { + titleLiveData.postValue(rssSource.sourceName) + } val xml = URL(url).readText() if (rssSource == null || rssSource.ruleArticles.isNullOrBlank()) { RssParser.parseXML(xml, url).let { From f79f999152b2183566beef7aef4868d95add43af Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 09:56:36 +0800 Subject: [PATCH 103/140] up --- app/src/main/java/io/legado/app/help/storage/Backup.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 97497a854..fa3ad14f9 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -35,7 +35,7 @@ object Backup { fun autoBackup() { doAsync { - val path = defaultPath + File.separator + "autoBackup" + val path = defaultPath backupBookshelf(path) backupBookSource(path) backupRssSource(path) From 5346d3a7217788dbbdb785a471942029eed9fb0e Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 10:14:57 +0800 Subject: [PATCH 104/140] up --- app/src/main/res/layout/item_rss_article.xml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/item_rss_article.xml b/app/src/main/res/layout/item_rss_article.xml index 6a9e5aba1..f9ead8598 100644 --- a/app/src/main/res/layout/item_rss_article.xml +++ b/app/src/main/res/layout/item_rss_article.xml @@ -1,6 +1,7 @@ @@ -33,11 +34,13 @@ + android:contentDescription="@string/img_cover" + tools:ignore="RtlHardcoded,RtlSymmetry" /> \ No newline at end of file From 1c4672af7df120488a49f604d7af263dbaf7d1e6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 10:19:01 +0800 Subject: [PATCH 105/140] up --- .../io/legado/app/ui/rss/article/RssArticlesActivity.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index f72a98048..7962e6bfd 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -1,8 +1,10 @@ package io.legado.app.ui.rss.article import android.os.Bundle +import androidx.core.content.ContextCompat import androidx.lifecycle.LiveData import androidx.lifecycle.Observer +import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R @@ -39,6 +41,12 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) + recycler_view.addItemDecoration( + DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply { + ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let { + this.setDrawable(it) + } + }) adapter = RssArticlesAdapter(this, this) recycler_view.adapter = adapter refresh_progress_bar.isAutoLoading = true From 2fc65b1bff6c6836c8bc781602ec03b9df18062b Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 10:32:03 +0800 Subject: [PATCH 106/140] up --- .../io/legado/app/data/dao/RssSourceDao.kt | 6 +++++ .../ui/rss/source/manage/RssSourceActivity.kt | 8 +++--- .../rss/source/manage/RssSourceViewModel.kt | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index 9390b04ac..b33f82b60 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -31,6 +31,9 @@ interface RssSourceDao { @Query("update rssSources set enabled = 0 where sourceUrl in (:sourceUrls)") fun disableSection(vararg sourceUrls: String) + @get:Query("select min(customOrder) from rssSources") + val minOrder: Int + @Query("delete from rssSources where sourceUrl in (:sourceUrls)") fun delSection(vararg sourceUrls: String) @@ -40,6 +43,9 @@ interface RssSourceDao { @Update fun update(vararg rssSource: RssSource) + @Delete + fun delete(vararg rssSource: RssSource) + @Query("delete from rssSources where sourceUrl = :sourceUrl") fun delete(sourceUrl: String) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 4ef9c9a0f..5515e4cf1 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -137,7 +137,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } override fun del(source: RssSource) { - + viewModel.del(source) } override fun edit(source: RssSource) { @@ -145,15 +145,15 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } override fun update(vararg source: RssSource) { - + viewModel.update(*source) } override fun toTop(source: RssSource) { - + viewModel.topSource(source) } override fun upOrder() { - + viewModel.upOrder() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 199532d72..8915a6cd8 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -3,9 +3,36 @@ package io.legado.app.ui.rss.source.manage import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.data.entities.RssSource class RssSourceViewModel(application: Application) : BaseViewModel(application) { + fun topSource(rssSource: RssSource) { + execute { + val minXh = App.db.rssSourceDao().minOrder + rssSource.customOrder = minXh - 1 + App.db.rssSourceDao().insert(rssSource) + } + } + + fun del(rssSource: RssSource) { + execute { App.db.rssSourceDao().delete(rssSource) } + } + + fun update(vararg rssSource: RssSource) { + execute { App.db.rssSourceDao().update(*rssSource) } + } + + fun upOrder() { + execute { + val sources = App.db.rssSourceDao().all + for ((index: Int, source: RssSource) in sources.withIndex()) { + source.customOrder = index + 1 + } + App.db.rssSourceDao().update(*sources.toTypedArray()) + } + } + fun enableSelection(ids: LinkedHashSet) { execute { App.db.rssSourceDao().enableSection(*ids.toTypedArray()) From a583d471a0893383ffd3f51e406f8a438157cca6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 10:40:17 +0800 Subject: [PATCH 107/140] up --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3c95124c7..bfcb4cc7a 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { maven { url 'https://plugins.gradle.org/m2/' } } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:3.5.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.3' } From fa1137617411f32ff33d9267170ac33617d28e23 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 11:02:09 +0800 Subject: [PATCH 108/140] up --- app/src/main/AndroidManifest.xml | 4 ++-- .../io/legado/app/data/dao/BookSourceDao.kt | 3 +++ .../io/legado/app/data/dao/RssSourceDao.kt | 3 +++ .../app/ui/book/info/BookInfoActivity.kt | 4 ++-- .../app/ui/book/read/ReadBookActivity.kt | 4 ++-- ...Activity.kt => BookSourceDebugActivity.kt} | 11 +++++---- ...ugAdapter.kt => BookSourceDebugAdapter.kt} | 2 +- ...eDebugModel.kt => BookSourceDebugModel.kt} | 3 ++- ...tActivity.kt => BookSourceEditActivity.kt} | 24 +++++++++---------- ...ditAdapter.kt => BookSourceEditAdapter.kt} | 2 +- ...iewModel.kt => BookSourceEditViewModel.kt} | 11 +++++---- .../book/source/manage/BookSourceActivity.kt | 6 ++--- .../book/source/manage/BookSourceViewModel.kt | 3 +-- .../app/ui/main/explore/ExploreFragment.kt | 4 ++-- .../rss/source/edit/RssSourceEditActivity.kt | 8 +++---- .../rss/source/edit/RssSourceEditViewModel.kt | 8 ++++++- .../rss/source/manage/RssSourceViewModel.kt | 3 +-- 17 files changed, 57 insertions(+), 46 deletions(-) rename app/src/main/java/io/legado/app/ui/book/source/debug/{SourceDebugActivity.kt => BookSourceDebugActivity.kt} (90%) rename app/src/main/java/io/legado/app/ui/book/source/debug/{SourceDebugAdapter.kt => BookSourceDebugAdapter.kt} (90%) rename app/src/main/java/io/legado/app/ui/book/source/debug/{SourceDebugModel.kt => BookSourceDebugModel.kt} (91%) rename app/src/main/java/io/legado/app/ui/book/source/edit/{SourceEditActivity.kt => BookSourceEditActivity.kt} (95%) rename app/src/main/java/io/legado/app/ui/book/source/edit/{SourceEditAdapter.kt => BookSourceEditAdapter.kt} (96%) rename app/src/main/java/io/legado/app/ui/book/source/edit/{SourceEditViewModel.kt => BookSourceEditViewModel.kt} (83%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8c0318cae..39ddc4987 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,7 +46,7 @@ android:name=".help.permission.PermissionActivity" android:theme="@style/Activity.Permission" /> @@ -63,7 +63,7 @@ - + diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 334bb7a82..0c8e4d65e 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -67,4 +67,7 @@ interface BookSourceDao { @get:Query("select min(customOrder) from book_sources") val minOrder: Int + + @get:Query("select max(customOrder) from book_sources") + val maxOrder: Int } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index b33f82b60..d30b861da 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -34,6 +34,9 @@ interface RssSourceDao { @get:Query("select min(customOrder) from rssSources") val minOrder: Int + @get:Query("select max(customOrder) from rssSources") + val maxOrder: Int + @Query("delete from rssSources where sourceUrl in (:sourceUrls)") fun delSection(vararg sourceUrls: String) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 3f78488de..b9bb67838 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -14,7 +14,7 @@ import io.legado.app.help.ImageLoader import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.info.edit.BookInfoEditActivity import io.legado.app.ui.book.read.ReadBookActivity -import io.legado.app.ui.book.source.edit.SourceEditActivity +import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.utils.getCompatDrawable import io.legado.app.utils.getViewModel @@ -190,7 +190,7 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } tv_origin.onClick { viewModel.bookData.value?.let { - startActivity(Pair("data", it.origin)) + startActivity(Pair("data", it.origin)) } } tv_change_source.onClick { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 3b2400e56..c763ae746 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -32,7 +32,7 @@ import io.legado.app.service.BaseReadAloudService import io.legado.app.ui.book.read.config.* import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR -import io.legado.app.ui.book.source.edit.SourceEditActivity +import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity @@ -114,7 +114,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo private fun initView() { tv_chapter_name.onClick { viewModel.webBook?.let { - startActivityForResult( + startActivityForResult( requestCodeEditSource, Pair("data", it.bookSource.bookSourceUrl) ) diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt similarity index 90% rename from app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt rename to app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index de2ef20e7..dafeaa218 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -18,12 +18,13 @@ import kotlinx.coroutines.launch import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast -class SourceDebugActivity : VMBaseActivity(R.layout.activity_source_debug) { +class BookSourceDebugActivity : + VMBaseActivity(R.layout.activity_source_debug) { - override val viewModel: SourceDebugModel - get() = getViewModel(SourceDebugModel::class.java) + override val viewModel: BookSourceDebugModel + get() = getViewModel(BookSourceDebugModel::class.java) - private lateinit var adapter: SourceDebugAdapter + private lateinit var adapter: BookSourceDebugAdapter private val qrRequestCode = 101 override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -42,7 +43,7 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) - adapter = SourceDebugAdapter(this) + adapter = BookSourceDebugAdapter(this) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter rotate_loading.loadingColor = accentColor diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt similarity index 90% rename from app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugAdapter.kt rename to app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt index 94147a5f1..2ec4e9518 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt @@ -6,7 +6,7 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import kotlinx.android.synthetic.main.item_log.view.* -class SourceDebugAdapter(context: Context) : +class BookSourceDebugAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_log) { override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { holder.itemView.apply { diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt similarity index 91% rename from app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugModel.kt rename to app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt index a17565820..ced985aa9 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt @@ -6,7 +6,8 @@ import io.legado.app.base.BaseViewModel import io.legado.app.model.WebBook import io.legado.app.model.webbook.SourceDebug -class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback { +class BookSourceDebugModel(application: Application) : BaseViewModel(application), + SourceDebug.Callback { private var webBook: WebBook? = null diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt similarity index 95% rename from app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt rename to app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 4eb28dcea..e2fdd270f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -22,7 +22,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.rule.* import io.legado.app.lib.theme.ATH -import io.legado.app.ui.book.source.debug.SourceDebugActivity +import io.legado.app.ui.book.source.debug.BookSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.utils.GSON import io.legado.app.utils.getViewModel @@ -32,13 +32,13 @@ import org.jetbrains.anko.startActivity import org.jetbrains.anko.toast import kotlin.math.abs -class SourceEditActivity : - VMBaseActivity(R.layout.activity_book_source_edit, false), +class BookSourceEditActivity : + VMBaseActivity(R.layout.activity_book_source_edit, false), KeyboardToolPop.CallBack { - override val viewModel: SourceEditViewModel - get() = getViewModel(SourceEditViewModel::class.java) + override val viewModel: BookSourceEditViewModel + get() = getViewModel(BookSourceEditViewModel::class.java) - private val adapter = SourceEditAdapter() + private val adapter = BookSourceEditAdapter() private val sourceEntities: ArrayList = ArrayList() private val searchEntities: ArrayList = ArrayList() private val findEntities: ArrayList = ArrayList() @@ -55,11 +55,8 @@ class SourceEditActivity : upRecyclerView(it) }) if (viewModel.sourceLiveData.value == null) { - val sourceID = intent.getStringExtra("data") - if (sourceID == null) { - upRecyclerView(null) - } else { - sourceID.let { viewModel.setBookSource(sourceID) } + intent.getStringExtra("data")?.let { + viewModel.setBookSource(it) } } else { upRecyclerView(viewModel.sourceLiveData.value) @@ -86,7 +83,7 @@ class SourceEditActivity : R.id.menu_debug_source -> { getSource()?.let { viewModel.save(it) { - startActivity(Pair("key", it.bookSourceUrl)) + startActivity(Pair("key", it.bookSourceUrl)) } } } @@ -120,6 +117,7 @@ class SourceEditActivity : setEditEntities(tab?.position) } }) + upRecyclerView(null) } private fun setEditEntities(tabPosition: Int?) { @@ -358,7 +356,7 @@ class SourceEditActivity : val rect = Rect() // 获取当前页面窗口的显示范围 window.decorView.getWindowVisibleDisplayFrame(rect) - val screenHeight = this@SourceEditActivity.displayMetrics.heightPixels + val screenHeight = this@BookSourceEditActivity.displayMetrics.heightPixels val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 val preShowing = mIsSoftKeyBoardShowing if (abs(keyboardHeight) > screenHeight / 5) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt similarity index 96% rename from app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt rename to app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt index 434f2071a..37939e803 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt @@ -10,7 +10,7 @@ import io.legado.app.R import io.legado.app.data.entities.EditEntity import kotlinx.android.synthetic.main.item_source_edit.view.* -class SourceEditAdapter : RecyclerView.Adapter() { +class BookSourceEditAdapter : RecyclerView.Adapter() { var editEntities: ArrayList = ArrayList() set(value) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt similarity index 83% rename from app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditViewModel.kt rename to app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index c3af29a6a..8bff89145 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -9,7 +9,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.BookSource import io.legado.app.help.storage.OldRule -class SourceEditViewModel(application: Application) : BaseViewModel(application) { +class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { val sourceLiveData: MutableLiveData = MutableLiveData() @@ -17,14 +17,17 @@ class SourceEditViewModel(application: Application) : BaseViewModel(application) execute { App.db.bookSourceDao().getBookSource(key)?.let { sourceLiveData.postValue(it) - } ?: sourceLiveData.postValue(BookSource()) + } } } fun save(bookSource: BookSource, finally: (() -> Unit)? = null) { execute { - if (bookSource.customOrder == 0) { - bookSource.customOrder = App.db.bookSourceDao().allCount() + sourceLiveData.value?.let { + bookSource.customOrder = it.customOrder + App.db.bookSourceDao().delete(it) + } ?: let { + bookSource.customOrder = App.db.bookSourceDao().maxOrder + 1 } App.db.bookSourceDao().insert(bookSource) }.onFinally { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 258e8b52d..ecdb0ad7b 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -28,7 +28,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.view.ATEAutoCompleteTextView import io.legado.app.service.CheckSourceService -import io.legado.app.ui.book.source.edit.SourceEditActivity +import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.utils.ACache import io.legado.app.utils.applyTint @@ -76,7 +76,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_add_book_source -> { - this.startActivity() + this.startActivity() } R.id.menu_import_book_source_qr -> { this.startActivityForResult(qrRequestCode) @@ -212,7 +212,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } override fun edit(bookSource: BookSource) { - startActivity(Pair("data", bookSource.bookSourceUrl)) + startActivity(Pair("data", bookSource.bookSourceUrl)) } override fun upOrder() { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 31accc240..a51b589b3 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -16,8 +16,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun topSource(bookSource: BookSource) { execute { - val minXh = App.db.bookSourceDao().minOrder - bookSource.customOrder = minXh - 1 + bookSource.customOrder = App.db.bookSourceDao().minOrder - 1 App.db.bookSourceDao().insert(bookSource) } } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 6889124f3..ea23c0909 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -12,7 +12,7 @@ import io.legado.app.base.VMBaseFragment import io.legado.app.data.entities.BookSource import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor -import io.legado.app.ui.book.source.edit.SourceEditActivity +import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.explore.ExploreShowActivity import io.legado.app.utils.getViewModel import io.legado.app.utils.startActivity @@ -88,7 +88,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ } override fun editSource(sourceUrl: String) { - startActivity(Pair("data", sourceUrl)) + startActivity(Pair("data", sourceUrl)) } override fun toTop(source: BookSource) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 0636afda6..81ff0b823 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -50,11 +50,8 @@ class RssSourceEditActivity : upRecyclerView(it) }) if (viewModel.sourceLiveData.value == null) { - val sourceID = intent.getStringExtra("data") - if (sourceID == null) { - upRecyclerView(null) - } else { - sourceID.let { viewModel.setSource(sourceID) } + intent.getStringExtra("data")?.let { + viewModel.setSource(it) } } else { upRecyclerView(viewModel.sourceLiveData.value) @@ -105,6 +102,7 @@ class RssSourceEditActivity : window.decorView.viewTreeObserver.addOnGlobalLayoutListener(KeyboardOnGlobalChangeListener()) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter + upRecyclerView(null) } private fun upRecyclerView(rssSource: RssSource?) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 0f002d627..aec9924ea 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -18,12 +18,18 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati execute { App.db.rssSourceDao().getByKey(key)?.let { sourceLiveData.postValue(it) - } ?: sourceLiveData.postValue(RssSource()) + } } } fun save(rssSource: RssSource, success: (() -> Unit)) { execute { + sourceLiveData.value?.let { + rssSource.customOrder = it.customOrder + App.db.rssSourceDao().delete(it) + } ?: let { + rssSource.customOrder = App.db.rssSourceDao().maxOrder + 1 + } App.db.rssSourceDao().insert(rssSource) }.onSuccess { success() diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 8915a6cd8..b0ad309d6 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -9,8 +9,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) fun topSource(rssSource: RssSource) { execute { - val minXh = App.db.rssSourceDao().minOrder - rssSource.customOrder = minXh - 1 + rssSource.customOrder = App.db.rssSourceDao().minOrder - 1 App.db.rssSourceDao().insert(rssSource) } } From d4164d89e1f588f4853ef019693892058b0207c0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 11:38:42 +0800 Subject: [PATCH 109/140] up --- .../rss/source/edit/RssSourceEditActivity.kt | 2 ++ app/src/main/res/values/strings.xml | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 81ff0b823..002818d82 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -112,6 +112,7 @@ class RssSourceEditActivity : add(EditEntity("sourceUrl", rssSource?.sourceUrl, R.string.rss_source_url)) add(EditEntity("sourceIcon", rssSource?.sourceIcon, R.string.rss_source_icon)) add(EditEntity("sourceGroup", rssSource?.sourceGroup, R.string.rss_source_group)) + add(EditEntity("ruleArticles", rssSource?.ruleArticles, R.string.rss_rule_articles)) add(EditEntity("ruleTitle", rssSource?.ruleTitle, R.string.rss_rule_title)) add(EditEntity("ruleAuthor", rssSource?.ruleAuthor, R.string.rss_rule_author)) add(EditEntity("ruleGuid", rssSource?.ruleGuid, R.string.rss_rule_guid)) @@ -145,6 +146,7 @@ class RssSourceEditActivity : "sourceUrl" -> source.sourceUrl = it.value ?: "" "sourceIcon" -> source.sourceIcon = it.value ?: "" "sourceGroup" -> source.sourceGroup = it.value + "ruleArticles" -> source.ruleArticles = it.value "ruleTitle" -> source.ruleTitle = it.value "ruleAuthor" -> source.ruleAuthor = it.value "ruleGuid" -> source.ruleGuid = it.value diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bfe21f7a4..52525e7cb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -376,19 +376,20 @@ - 名称 - url - 图标 - 分组 - 标题 - 作者 - guid - 时间 - 类别 - 描述 - 图片url - 内容 - 链接 + 名称(sourceName) + url(sourceUrl) + 图标(sourceIcon) + 分组(sourceGroup) + 列表规则(ruleArticles) + 标题规则(ruleTitle) + 作者规则(ruleAuthor) + guid规则(ruleGuid) + 时间规则(rulePubDate) + 类别规则(ruleCategories) + 描述规则(ruleDescription) + 图片url规则(ruleImage) + 内容规则(ruleContent) + 链接规则(ruleLink) From 63c1b8914ef24318208ca3ad87ab835463bbe3ea Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 11:52:24 +0800 Subject: [PATCH 110/140] up --- app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt | 4 ++-- app/src/main/java/io/legado/app/data/entities/RssSource.kt | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index d30b861da..8081068ed 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -13,10 +13,10 @@ interface RssSourceDao { @get:Query("SELECT * FROM rssSources") val all: List - @Query("SELECT * FROM rssSources") + @Query("SELECT * FROM rssSources order by customOrder") fun liveAll(): LiveData> - @Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key") + @Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key order by customOrder") fun liveSearch(key: String): LiveData> @Query("SELECT * FROM rssSources where enabled = 1") diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index 4537747a1..82f0d4863 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -2,11 +2,12 @@ package io.legado.app.data.entities import android.os.Parcelable import androidx.room.Entity +import androidx.room.Index import androidx.room.PrimaryKey import kotlinx.android.parcel.Parcelize @Parcelize -@Entity(tableName = "rssSources") +@Entity(tableName = "rssSources", indices = [(Index(value = ["sourceUrl"], unique = false))]) data class RssSource( @PrimaryKey var sourceUrl: String = "", From 8a543ef3b716c751839b4e96674e4c68355c7ea9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 12:35:29 +0800 Subject: [PATCH 111/140] up --- .../java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt | 2 +- .../io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt index 3fa28cd69..4b11ab39c 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt @@ -25,7 +25,7 @@ class ReplaceEditDialog : DialogFragment(), val dialog = ReplaceEditDialog() id?.let { val bundle = Bundle() - bundle.putLong("data", id) + bundle.putLong("id", id) dialog.arguments = bundle } return dialog diff --git a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt index ae8ba8025..281a0ac2d 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt @@ -14,7 +14,7 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application fun initData(bundle: Bundle) { execute { replaceRuleData.value ?: let { - val id = bundle.getLong("data") + val id = bundle.getLong("id") if (id > 0) { App.db.replaceRuleDao().findById(id)?.let { replaceRuleData.postValue(it) From 21449396585eea61d96d5a41ddbf91c6e7b8fab0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 13:49:14 +0800 Subject: [PATCH 112/140] up --- .../ui/rss/article/RssArticlesViewModel.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index a4ddecf4d..b2d052c29 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -4,9 +4,9 @@ import android.app.Application import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.rss.RssParser import io.legado.app.model.rss.RssParserByRule -import java.net.URL class RssArticlesViewModel(application: Application) : BaseViewModel(application) { @@ -19,14 +19,15 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application rssSource?.let { titleLiveData.postValue(rssSource.sourceName) } - val xml = URL(url).readText() - if (rssSource == null || rssSource.ruleArticles.isNullOrBlank()) { - RssParser.parseXML(xml, url).let { - App.db.rssArtivleDao().insert(*it.toTypedArray()) - } - } else { - RssParserByRule.parseXML(xml, rssSource).let { - App.db.rssArtivleDao().insert(*it.toTypedArray()) + AnalyzeUrl(url).getResponseAsync().await().body()?.let { xml -> + if (rssSource == null || rssSource.ruleArticles.isNullOrBlank()) { + RssParser.parseXML(xml, url).let { + App.db.rssArtivleDao().insert(*it.toTypedArray()) + } + } else { + RssParserByRule.parseXML(xml, rssSource).let { + App.db.rssArtivleDao().insert(*it.toTypedArray()) + } } } }.onFinally { From 08dcf5de24746ce02bf136b3077353fa00f9b05d Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 14:37:35 +0800 Subject: [PATCH 113/140] up --- .../io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt | 1 + .../io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 8bff89145..2289ea4b1 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -29,6 +29,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat } ?: let { bookSource.customOrder = App.db.bookSourceDao().maxOrder + 1 } + sourceLiveData.postValue(bookSource) App.db.bookSourceDao().insert(bookSource) }.onFinally { finally?.let { it() } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index aec9924ea..2b8f5e242 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -30,6 +30,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati } ?: let { rssSource.customOrder = App.db.rssSourceDao().maxOrder + 1 } + sourceLiveData.postValue(rssSource) App.db.rssSourceDao().insert(rssSource) }.onSuccess { success() From be95698ea748e944054088b82cd7a70829c73f69 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 14:40:42 +0800 Subject: [PATCH 114/140] up --- app/src/main/java/io/legado/app/ui/about/AboutFragment.kt | 2 +- app/src/main/res/values/pref_key_value.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index e98523051..093c5a9ec 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -24,7 +24,7 @@ class AboutFragment : PreferenceFragmentCompat() { override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { "mail" -> openIntent(Intent.ACTION_SENDTO, "mailto:kunfei.ge@gmail.com") - "gitHub" -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url)) + "git" -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url)) } return super.onPreferenceTreeClick(preference) } diff --git a/app/src/main/res/values/pref_key_value.xml b/app/src/main/res/values/pref_key_value.xml index dd706603a..091d276ad 100644 --- a/app/src/main/res/values/pref_key_value.xml +++ b/app/src/main/res/values/pref_key_value.xml @@ -19,7 +19,7 @@ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.2357.134 Safari/537.36 https://gedoor.github.io/MyBookshelf/sourcerule.html - https://github.com/gedoor/MyBookshelf + https://github.com/gedoor/legado https://gedoor.github.io/MyBookshelf/disclaimer.html https://gedoor.github.io/MyBookshelf/ https://github.com/gedoor/MyBookshelf/releases/latest From f6352d4e9756354ea821f697d9dc4df42eecc583 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 14:48:23 +0800 Subject: [PATCH 115/140] up --- .../app/ui/book/source/edit/BookSourceEditActivity.kt | 8 ++------ .../app/ui/rss/source/edit/RssSourceEditActivity.kt | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index e2fdd270f..6362c947f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -54,12 +54,8 @@ class BookSourceEditActivity : viewModel.sourceLiveData.observe(this, Observer { upRecyclerView(it) }) - if (viewModel.sourceLiveData.value == null) { - intent.getStringExtra("data")?.let { - viewModel.setBookSource(it) - } - } else { - upRecyclerView(viewModel.sourceLiveData.value) + intent.getStringExtra("data")?.let { + viewModel.setBookSource(it) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 002818d82..5eed4540c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -49,12 +49,8 @@ class RssSourceEditActivity : viewModel.sourceLiveData.observe(this, Observer { upRecyclerView(it) }) - if (viewModel.sourceLiveData.value == null) { - intent.getStringExtra("data")?.let { - viewModel.setSource(it) - } - } else { - upRecyclerView(viewModel.sourceLiveData.value) + intent.getStringExtra("data")?.let { + viewModel.setSource(it) } } From 5c15dfa5b5de50d35c8568c26ae4b4b734b63060 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 14:49:44 +0800 Subject: [PATCH 116/140] up --- .../legado/app/ui/book/source/edit/BookSourceEditViewModel.kt | 2 +- .../io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 2289ea4b1..8dcfe81ed 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -29,8 +29,8 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat } ?: let { bookSource.customOrder = App.db.bookSourceDao().maxOrder + 1 } - sourceLiveData.postValue(bookSource) App.db.bookSourceDao().insert(bookSource) + sourceLiveData.postValue(bookSource) }.onFinally { finally?.let { it() } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 2b8f5e242..72f0637b9 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -30,8 +30,8 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati } ?: let { rssSource.customOrder = App.db.rssSourceDao().maxOrder + 1 } - sourceLiveData.postValue(rssSource) App.db.rssSourceDao().insert(rssSource) + sourceLiveData.postValue(rssSource) }.onSuccess { success() }.onError { From c028e643e3fe2afbea3dd98c373383f75d9c3b15 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 14:55:56 +0800 Subject: [PATCH 117/140] up --- .../io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt | 1 - .../io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 8dcfe81ed..9c8a1d8ca 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -24,7 +24,6 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat fun save(bookSource: BookSource, finally: (() -> Unit)? = null) { execute { sourceLiveData.value?.let { - bookSource.customOrder = it.customOrder App.db.bookSourceDao().delete(it) } ?: let { bookSource.customOrder = App.db.bookSourceDao().maxOrder + 1 diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 72f0637b9..b6dd3af87 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -25,7 +25,6 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati fun save(rssSource: RssSource, success: (() -> Unit)) { execute { sourceLiveData.value?.let { - rssSource.customOrder = it.customOrder App.db.rssSourceDao().delete(it) } ?: let { rssSource.customOrder = App.db.rssSourceDao().maxOrder + 1 From f25a36b8eac94abc0ef44f19d46e72c695e86edd Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 15:06:05 +0800 Subject: [PATCH 118/140] up --- .../io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt | 2 +- .../io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 6362c947f..b1c659b9b 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -225,7 +225,7 @@ class BookSourceEditActivity : } private fun getSource(): BookSource? { - val source = viewModel.sourceLiveData.value ?: BookSource() + val source = viewModel.sourceLiveData.value?.copy() ?: BookSource() source.enabled = cb_is_enable.isChecked source.enabledExplore = cb_is_enable_find.isChecked viewModel.sourceLiveData.value?.let { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 5eed4540c..c30e8b9ff 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -135,7 +135,7 @@ class RssSourceEditActivity : } private fun getRssSource(): RssSource? { - val source = viewModel.sourceLiveData.value ?: RssSource() + val source = viewModel.sourceLiveData.value?.copy() ?: RssSource() sourceEntities.forEach { when (it.key) { "sourceName" -> source.sourceName = it.value ?: "" From 9b6a37e07a83fa1c96ee130aed695a7259d2586d Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 15:08:56 +0800 Subject: [PATCH 119/140] up --- .../legado/app/ui/book/source/edit/BookSourceEditViewModel.kt | 4 +++- .../legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 9c8a1d8ca..910c461a7 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -24,7 +24,9 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat fun save(bookSource: BookSource, finally: (() -> Unit)? = null) { execute { sourceLiveData.value?.let { - App.db.bookSourceDao().delete(it) + if (it.bookSourceUrl != bookSource.bookSourceUrl) { + App.db.bookSourceDao().delete(it) + } } ?: let { bookSource.customOrder = App.db.bookSourceDao().maxOrder + 1 } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index b6dd3af87..f87438b9c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -25,7 +25,9 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati fun save(rssSource: RssSource, success: (() -> Unit)) { execute { sourceLiveData.value?.let { - App.db.rssSourceDao().delete(it) + if (it.sourceUrl != rssSource.sourceUrl) { + App.db.rssSourceDao().delete(it) + } } ?: let { rssSource.customOrder = App.db.rssSourceDao().maxOrder + 1 } From 8de1ff85abca226b1fb4812851d8e4edad340a40 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 15:09:38 +0800 Subject: [PATCH 120/140] up --- .../io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt index 3018a1f1e..3c476c921 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt @@ -5,7 +5,7 @@ import io.legado.app.R import io.legado.app.base.BaseActivity -class RssSourceDebugActivity : BaseActivity(R.layout.activity_source_debug, false) { +class RssSourceDebugActivity : BaseActivity(R.layout.activity_source_debug) { override fun onActivityCreated(savedInstanceState: Bundle?) { From fa1c8ce18e5a899dfc9bb4707f3d9c5663f89b3f Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 15:29:15 +0800 Subject: [PATCH 121/140] up --- app/src/main/java/io/legado/app/model/Rss.kt | 24 +++++++++++++++++++ .../legado/app/model/rss/RssParserByRule.kt | 20 ++++++++++++---- .../ui/rss/article/RssArticlesViewModel.kt | 23 +++++++----------- 3 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/io/legado/app/model/Rss.kt diff --git a/app/src/main/java/io/legado/app/model/Rss.kt b/app/src/main/java/io/legado/app/model/Rss.kt new file mode 100644 index 000000000..cd76e24fe --- /dev/null +++ b/app/src/main/java/io/legado/app/model/Rss.kt @@ -0,0 +1,24 @@ +package io.legado.app.model + +import io.legado.app.data.entities.RssArticle +import io.legado.app.data.entities.RssSource +import io.legado.app.help.coroutine.Coroutine +import io.legado.app.model.analyzeRule.AnalyzeUrl +import io.legado.app.model.rss.RssParserByRule +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlin.coroutines.CoroutineContext + +object Rss { + + fun getArticles( + rssSource: RssSource, + scope: CoroutineScope = Coroutine.DEFAULT, + context: CoroutineContext = Dispatchers.IO + ): Coroutine> { + return Coroutine.async(scope, context) { + val response = AnalyzeUrl(rssSource.sourceUrl).getResponseAsync().await() + RssParserByRule.parseXML(response, rssSource) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index 6880976ab..c1609c852 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -1,18 +1,28 @@ package io.legado.app.model.rss +import io.legado.app.App +import io.legado.app.R import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.model.analyzeRule.AnalyzeRule -import org.xmlpull.v1.XmlPullParserException -import java.io.IOException +import retrofit2.Response object RssParserByRule { - @Throws(XmlPullParserException::class, IOException::class) - fun parseXML(xml: String, rssSource: RssSource): MutableList { - + @Throws(Exception::class) + fun parseXML(response: Response, rssSource: RssSource): MutableList { val articleList = mutableListOf() + val xml = response.body() + if (xml.isNullOrBlank()) { + throw Exception( + App.INSTANCE.getString( + R.string.error_get_web_content, + rssSource.sourceUrl + ) + ) + } + val analyzeRule = AnalyzeRule() analyzeRule.setContent(xml) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index b2d052c29..5d9470f71 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -4,9 +4,8 @@ import android.app.Application import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel -import io.legado.app.model.analyzeRule.AnalyzeUrl -import io.legado.app.model.rss.RssParser -import io.legado.app.model.rss.RssParserByRule +import io.legado.app.data.entities.RssSource +import io.legado.app.model.Rss class RssArticlesViewModel(application: Application) : BaseViewModel(application) { @@ -15,19 +14,15 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application fun loadContent(url: String, onFinally: () -> Unit) { execute { - val rssSource = App.db.rssSourceDao().getByKey(url) - rssSource?.let { + var rssSource = App.db.rssSourceDao().getByKey(url) + if (rssSource == null) { + rssSource = RssSource(sourceUrl = url) + } else { titleLiveData.postValue(rssSource.sourceName) } - AnalyzeUrl(url).getResponseAsync().await().body()?.let { xml -> - if (rssSource == null || rssSource.ruleArticles.isNullOrBlank()) { - RssParser.parseXML(xml, url).let { - App.db.rssArtivleDao().insert(*it.toTypedArray()) - } - } else { - RssParserByRule.parseXML(xml, rssSource).let { - App.db.rssArtivleDao().insert(*it.toTypedArray()) - } + Rss.getArticles(rssSource, this).onSuccess { + it?.let { + App.db.rssArtivleDao().insert(*it.toTypedArray()) } } }.onFinally { From a6d2165887c6c96db16c9a67eea07e3f6c01daeb Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 15:33:02 +0800 Subject: [PATCH 122/140] up --- .../java/io/legado/app/model/rss/RssParserByRule.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index c1609c852..1bd629a50 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -23,10 +23,9 @@ object RssParserByRule { ) } - val analyzeRule = AnalyzeRule() - analyzeRule.setContent(xml) - rssSource.ruleArticles?.let { ruleArticles -> + val analyzeRule = AnalyzeRule() + analyzeRule.setContent(xml) val collections = analyzeRule.getElements(ruleArticles) val ruleGuid = analyzeRule.splitSourceRule(rssSource.ruleGuid ?: "") val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle ?: "") @@ -51,7 +50,9 @@ object RssParserByRule { ruleImage, ruleContent, ruleLink - ) + )?.let { + articleList.add(it) + } } } ?: let { return RssParser.parseXML(xml, rssSource.sourceUrl) @@ -84,6 +85,9 @@ object RssParserByRule { rssArticle.image = analyzeRule.getString(ruleImage) rssArticle.content = analyzeRule.getString(ruleContent) rssArticle.link = analyzeRule.getString(ruleLink) + if (rssArticle.title.isNullOrBlank()) { + return null + } return rssArticle } } \ No newline at end of file From d29a46c8efe66ac9c591ac9b9c61ce294e72f372 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 15:36:25 +0800 Subject: [PATCH 123/140] up --- .../io/legado/app/ui/rss/article/RssArticlesViewModel.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 5d9470f71..bd82bdda4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -24,9 +24,11 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application it?.let { App.db.rssArtivleDao().insert(*it.toTypedArray()) } + }.onError { + toast(it.localizedMessage) + }.onFinally { + onFinally() } - }.onFinally { - onFinally() } } From 0dfd83f30fe6d59352d1500eb37d79365c12b7be Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 15:55:52 +0800 Subject: [PATCH 124/140] up --- .../io/legado/app/data/dao/BookSourceDao.kt | 3 +++ .../source/edit/BookSourceEditActivity.kt | 2 +- .../source/edit/BookSourceEditViewModel.kt | 22 +++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 0c8e4d65e..e1864eb5b 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -65,6 +65,9 @@ interface BookSourceDao { @Delete fun delete(vararg bookSource: BookSource) + @Query("delete from book_sources where bookSourceUrl = :key") + fun delete(key: String) + @get:Query("select min(customOrder) from book_sources") val minOrder: Int diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index b1c659b9b..6362c947f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -225,7 +225,7 @@ class BookSourceEditActivity : } private fun getSource(): BookSource? { - val source = viewModel.sourceLiveData.value?.copy() ?: BookSource() + val source = viewModel.sourceLiveData.value ?: BookSource() source.enabled = cb_is_enable.isChecked source.enabledExplore = cb_is_enable_find.isChecked viewModel.sourceLiveData.value?.let { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 910c461a7..1202f74f2 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -12,26 +12,34 @@ import io.legado.app.help.storage.OldRule class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { val sourceLiveData: MutableLiveData = MutableLiveData() + var oldSourceUrl: String? = null - fun setBookSource(key: String) { + fun setBookSource(key: String?) { execute { - App.db.bookSourceDao().getBookSource(key)?.let { + var source: BookSource? = null + if (key != null) { + source = App.db.bookSourceDao().getBookSource(key) + } + source?.let { + oldSourceUrl = it.bookSourceUrl sourceLiveData.postValue(it) + } ?: let { + sourceLiveData.postValue(BookSource().apply { + customOrder = App.db.bookSourceDao().maxOrder + 1 + }) } } } fun save(bookSource: BookSource, finally: (() -> Unit)? = null) { execute { - sourceLiveData.value?.let { - if (it.bookSourceUrl != bookSource.bookSourceUrl) { + oldSourceUrl?.let { + if (oldSourceUrl != bookSource.bookSourceUrl) { App.db.bookSourceDao().delete(it) } - } ?: let { - bookSource.customOrder = App.db.bookSourceDao().maxOrder + 1 } + oldSourceUrl = bookSource.bookSourceUrl App.db.bookSourceDao().insert(bookSource) - sourceLiveData.postValue(bookSource) }.onFinally { finally?.let { it() } } From b5be12b231f0d7ed4b020bb72b84ade2ef707de1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 15:56:53 +0800 Subject: [PATCH 125/140] up --- .../legado/app/ui/book/source/edit/BookSourceEditActivity.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 6362c947f..153e3fcb8 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -54,9 +54,7 @@ class BookSourceEditActivity : viewModel.sourceLiveData.observe(this, Observer { upRecyclerView(it) }) - intent.getStringExtra("data")?.let { - viewModel.setBookSource(it) - } + viewModel.setBookSource(intent.getStringExtra("data")) } override fun onDestroy() { @@ -113,7 +111,6 @@ class BookSourceEditActivity : setEditEntities(tab?.position) } }) - upRecyclerView(null) } private fun setEditEntities(tabPosition: Int?) { From a62b75832b552962f1bd1a83a7fe542e0f1609fb Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 15:58:09 +0800 Subject: [PATCH 126/140] up --- .../legado/app/ui/book/source/edit/BookSourceEditActivity.kt | 2 +- .../legado/app/ui/book/source/edit/BookSourceEditViewModel.kt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 153e3fcb8..267890628 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -54,7 +54,7 @@ class BookSourceEditActivity : viewModel.sourceLiveData.observe(this, Observer { upRecyclerView(it) }) - viewModel.setBookSource(intent.getStringExtra("data")) + viewModel.initData(intent) } override fun onDestroy() { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 1202f74f2..61cc49858 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.book.source.edit import android.app.Application import android.content.ClipboardManager import android.content.Context +import android.content.Intent import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel @@ -14,8 +15,9 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat val sourceLiveData: MutableLiveData = MutableLiveData() var oldSourceUrl: String? = null - fun setBookSource(key: String?) { + fun initData(intent: Intent) { execute { + val key = intent.getStringExtra("data") var source: BookSource? = null if (key != null) { source = App.db.bookSourceDao().getBookSource(key) From 9fb795206d4a31d3c10b9c0c0b9dcc118bba1dfc Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 16:01:57 +0800 Subject: [PATCH 127/140] up --- .../rss/source/edit/RssSourceEditActivity.kt | 5 +--- .../rss/source/edit/RssSourceEditViewModel.kt | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index c30e8b9ff..45374b1ea 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -49,9 +49,7 @@ class RssSourceEditActivity : viewModel.sourceLiveData.observe(this, Observer { upRecyclerView(it) }) - intent.getStringExtra("data")?.let { - viewModel.setSource(it) - } + viewModel.initData(intent) } override fun onDestroy() { @@ -98,7 +96,6 @@ class RssSourceEditActivity : window.decorView.viewTreeObserver.addOnGlobalLayoutListener(KeyboardOnGlobalChangeListener()) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter - upRecyclerView(null) } private fun upRecyclerView(rssSource: RssSource?) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index f87438b9c..8b0f2cd11 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.rss.source.edit import android.app.Application import android.content.ClipboardManager import android.content.Context +import android.content.Intent import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel @@ -13,26 +14,35 @@ import io.legado.app.utils.fromJsonObject class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { val sourceLiveData: MutableLiveData = MutableLiveData() + var oldSourceUrl: String? = null - fun setSource(key: String) { + fun initData(intent: Intent) { execute { - App.db.rssSourceDao().getByKey(key)?.let { + val key = intent.getStringExtra("data") + var source: RssSource? = null + if (key != null) { + source = App.db.rssSourceDao().getByKey(key) + } + source?.let { + oldSourceUrl = it.sourceUrl sourceLiveData.postValue(it) + } ?: let { + sourceLiveData.postValue(RssSource().apply { + customOrder = App.db.rssSourceDao().maxOrder + 1 + }) } } } fun save(rssSource: RssSource, success: (() -> Unit)) { execute { - sourceLiveData.value?.let { - if (it.sourceUrl != rssSource.sourceUrl) { + oldSourceUrl?.let { + if (oldSourceUrl != rssSource.sourceUrl) { App.db.rssSourceDao().delete(it) } - } ?: let { - rssSource.customOrder = App.db.rssSourceDao().maxOrder + 1 } + oldSourceUrl = rssSource.sourceUrl App.db.rssSourceDao().insert(rssSource) - sourceLiveData.postValue(rssSource) }.onSuccess { success() }.onError { From ff2800ce0a5de6bd574c46e51364e4d34efb79a8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 16:03:29 +0800 Subject: [PATCH 128/140] up --- .../io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 45374b1ea..9283744b4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -132,7 +132,7 @@ class RssSourceEditActivity : } private fun getRssSource(): RssSource? { - val source = viewModel.sourceLiveData.value?.copy() ?: RssSource() + val source = viewModel.sourceLiveData.value ?: RssSource() sourceEntities.forEach { when (it.key) { "sourceName" -> source.sourceName = it.value ?: "" From 1c74f48d5398997e78a4caa861239b889886df88 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 16:15:12 +0800 Subject: [PATCH 129/140] up --- .../app/ui/rss/article/RssArticlesViewModel.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index bd82bdda4..b24445785 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -6,6 +6,7 @@ import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssSource import io.legado.app.model.Rss +import kotlinx.coroutines.Dispatchers.IO class RssArticlesViewModel(application: Application) : BaseViewModel(application) { @@ -20,15 +21,16 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application } else { titleLiveData.postValue(rssSource.sourceName) } - Rss.getArticles(rssSource, this).onSuccess { - it?.let { - App.db.rssArtivleDao().insert(*it.toTypedArray()) + Rss.getArticles(rssSource, this) + .onSuccess(IO) { + it?.let { + App.db.rssArtivleDao().insert(*it.toTypedArray()) + } + }.onError { + toast(it.localizedMessage) + }.onFinally { + onFinally() } - }.onError { - toast(it.localizedMessage) - }.onFinally { - onFinally() - } } } From 48eac4955e4593fe13a51d9da08fc78a375fa215 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 16:26:38 +0800 Subject: [PATCH 130/140] up --- app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index 8081068ed..f280c0fb9 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -19,7 +19,7 @@ interface RssSourceDao { @Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key order by customOrder") fun liveSearch(key: String): LiveData> - @Query("SELECT * FROM rssSources where enabled = 1") + @Query("SELECT * FROM rssSources where enabled = 1 order by customOrder") fun liveEnabled(): LiveData> @Query("select sourceGroup from rssSources where sourceGroup is not null and sourceGroup <> ''") From f0dbf97c961d23a86590dff450876792ea256796 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 18:24:08 +0800 Subject: [PATCH 131/140] up --- app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index 1bd629a50..f2a40bc01 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -51,6 +51,7 @@ object RssParserByRule { ruleContent, ruleLink )?.let { + it.origin = rssSource.sourceUrl articleList.add(it) } } From cc990cd6138c6cf37589f2a86632d094d8f124f4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 18:39:17 +0800 Subject: [PATCH 132/140] up --- .../io/legado/app/ui/rss/article/RssArticlesActivity.kt | 5 ++++- .../main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 7962e6bfd..40e943756 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -61,6 +61,9 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi } override fun readRss(rssArticle: RssArticle) { - startActivity(Pair("description", rssArticle.description)) + startActivity( + Pair("description", rssArticle.description), + Pair("url", rssArticle.link) + ) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index f13f41b61..eb8fa6451 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -9,7 +9,12 @@ class ReadRssActivity : BaseActivity(R.layout.activity_rss_read) { override fun onActivityCreated(savedInstanceState: Bundle?) { val description = intent.getStringExtra("description") - webView.loadData("$description","text/html", "utf-8") + val url = intent.getStringExtra("url") + if (description.isNullOrBlank()) { + webView.loadUrl(url) + } else { + webView.loadData("$description", "text/html", "utf-8") + } } } \ No newline at end of file From 35c01961e5cb23465bb9dc11ea3f701c470e3801 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 19:12:23 +0800 Subject: [PATCH 133/140] up --- app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt | 2 +- .../io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index f2a40bc01..45bbaf637 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -84,8 +84,8 @@ object RssParserByRule { rssArticle.categories = analyzeRule.getString(ruleCategories) rssArticle.description = analyzeRule.getString(ruleDescription) rssArticle.image = analyzeRule.getString(ruleImage) - rssArticle.content = analyzeRule.getString(ruleContent) rssArticle.link = analyzeRule.getString(ruleLink) + rssArticle.content = analyzeRule.getString(ruleContent) if (rssArticle.title.isNullOrBlank()) { return null } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 9283744b4..10e783e15 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -125,8 +125,8 @@ class RssSourceEditActivity : ) ) add(EditEntity("ruleImage", rssSource?.ruleImage, R.string.rss_rule_image)) - add(EditEntity("ruleContent", rssSource?.ruleContent, R.string.rss_rule_content)) add(EditEntity("ruleLink", rssSource?.ruleLink, R.string.rss_rule_link)) + add(EditEntity("ruleContent", rssSource?.ruleContent, R.string.rss_rule_content)) } adapter.editEntities = sourceEntities } @@ -147,8 +147,8 @@ class RssSourceEditActivity : "ruleCategories" -> source.ruleCategories = it.value "ruleDescription" -> source.ruleDescription = it.value "ruleImage" -> source.ruleImage = it.value - "ruleContent" -> source.ruleContent = it.value "ruleLink" -> source.ruleLink = it.value + "ruleContent" -> source.ruleContent = it.value } } if (source.sourceName.isBlank() || source.sourceName.isBlank()) { From 1c0bc20cc3e33cebad2870eca0d64933d195f785 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 19:19:10 +0800 Subject: [PATCH 134/140] up --- app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt | 2 ++ app/src/main/res/layout/item_rss_article.xml | 1 + 2 files changed, 3 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt new file mode 100644 index 000000000..6d43baf9a --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -0,0 +1,2 @@ +package io.legado.app.ui.rss.read + diff --git a/app/src/main/res/layout/item_rss_article.xml b/app/src/main/res/layout/item_rss_article.xml index f9ead8598..7a28bc6b1 100644 --- a/app/src/main/res/layout/item_rss_article.xml +++ b/app/src/main/res/layout/item_rss_article.xml @@ -13,6 +13,7 @@ android:text="@string/app_name" android:textSize="16sp" android:textStyle="bold" + android:textColor="@color/tv_text_default" android:layout_marginBottom="10dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" From bb3b689c06a5fdd517b674213981257e22da9ff0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 19:33:34 +0800 Subject: [PATCH 135/140] up --- app/src/main/res/layout/item_rss_article.xml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/res/layout/item_rss_article.xml b/app/src/main/res/layout/item_rss_article.xml index 7a28bc6b1..293ae0ce3 100644 --- a/app/src/main/res/layout/item_rss_article.xml +++ b/app/src/main/res/layout/item_rss_article.xml @@ -10,15 +10,15 @@ android:id="@+id/tv_title" android:layout_width="0dp" android:layout_height="0dp" + android:layout_marginBottom="10dp" android:text="@string/app_name" + android:textColor="@color/tv_text_default" android:textSize="16sp" android:textStyle="bold" - android:textColor="@color/tv_text_default" - android:layout_marginBottom="10dp" - app:layout_constraintLeft_toLeftOf="parent" - app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@+id/tv_pub_date" - app:layout_constraintRight_toLeftOf="@+id/image_view" /> + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toLeftOf="@+id/image_view" + app:layout_constraintTop_toTopOf="parent" /> \ No newline at end of file From e8bab32b7b88407740323c3904418ba1268e50c8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 19:38:21 +0800 Subject: [PATCH 136/140] up --- app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index caa2fb293..c4ee3467d 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -13,6 +13,6 @@ interface RssArticleDao { @Query("select * from rssArticles where origin = :origin order by time desc") fun liveByOrigin(origin: String): LiveData> - @Insert(onConflict = OnConflictStrategy.REPLACE) + @Insert(onConflict = OnConflictStrategy.IGNORE) fun insert(vararg rssArticle: RssArticle) } \ No newline at end of file From 4b42d172fe9b0ea99bc693410ea96839ef01e83c Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 20:06:56 +0800 Subject: [PATCH 137/140] up --- app/src/main/java/io/legado/app/data/entities/RssArticle.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt index 1c89ff8ca..f2deefb1e 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt @@ -18,7 +18,9 @@ data class RssArticle( var description: String? = null, var content: String? = null, var image: String? = null, - var categories: String? = null + var categories: String? = null, + var read: Boolean = false, + var star: Boolean = false ) { @Ignore From 7bd457626e8ef641c9681183d98694a299cfedc7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 20:12:06 +0800 Subject: [PATCH 138/140] up --- app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt | 8 ++++---- .../io/legado/app/ui/rss/article/RssArticlesViewModel.kt | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index c4ee3467d..0c6290965 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -1,10 +1,7 @@ package io.legado.app.data.dao import androidx.lifecycle.LiveData -import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy -import androidx.room.Query +import androidx.room.* import io.legado.app.data.entities.RssArticle @Dao @@ -15,4 +12,7 @@ interface RssArticleDao { @Insert(onConflict = OnConflictStrategy.IGNORE) fun insert(vararg rssArticle: RssArticle) + + @Update + fun update(vararg rssArticle: RssArticle) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index b24445785..a75e7ae07 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -4,6 +4,7 @@ import android.app.Application import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.model.Rss import kotlinx.coroutines.Dispatchers.IO @@ -34,4 +35,11 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application } } + fun read(rssArticle: RssArticle) { + execute { + rssArticle.read = true + App.db.rssArtivleDao().update(rssArticle) + } + } + } \ No newline at end of file From 223564a8666ec8baddb8dc900af4be1ba2b13c13 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 20:23:17 +0800 Subject: [PATCH 139/140] up --- .../io/legado/app/ui/rss/article/RssArticlesActivity.kt | 1 + .../java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 40e943756..70137fa22 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -65,5 +65,6 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi Pair("description", rssArticle.description), Pair("url", rssArticle.link) ) + viewModel.read(rssArticle) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index 55e45bfc8..a89af62ba 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -10,6 +10,7 @@ import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_rss_article.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.textColorResource class RssArticlesAdapter(context: Context, val callBack: CallBack) : @@ -29,6 +30,11 @@ class RssArticlesAdapter(context: Context, val callBack: CallBack) : ImageLoader.load(context, item.image) .setAsBitmap(image_view) } + if (item.read) { + tv_title.textColorResource = R.color.tv_text_secondary + } else { + tv_title.textColorResource = R.color.tv_text_default + } } } From 70cc4d308eb5f0a9b6697c4191c1eccc365aa4b8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 20:28:48 +0800 Subject: [PATCH 140/140] up --- .../java/io/legado/app/ui/rss/article/RssArticlesActivity.kt | 2 +- .../java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 70137fa22..8ec14de5b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -61,10 +61,10 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi } override fun readRss(rssArticle: RssArticle) { + viewModel.read(rssArticle) startActivity( Pair("description", rssArticle.description), Pair("url", rssArticle.link) ) - viewModel.read(rssArticle) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index a89af62ba..03546d957 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -31,7 +31,7 @@ class RssArticlesAdapter(context: Context, val callBack: CallBack) : .setAsBitmap(image_view) } if (item.read) { - tv_title.textColorResource = R.color.tv_text_secondary + tv_title.textColorResource = R.color.tv_text_summary } else { tv_title.textColorResource = R.color.tv_text_default }