From 57f3220fb6827f9ed8208b7029a6c2a97287c1b7 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 19 Oct 2020 21:07:53 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/config/BgTextConfigDialog.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 69070e27b..a41bf4003 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -119,7 +119,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { headerView.iv_bg.setImageResource(R.drawable.ic_image) headerView.iv_bg.setColorFilter(primaryTextColor) headerView.onClick { selectImage() } - requireContext().assets.list("bg/")?.let { + requireContext().assets.list("bg${File.separator}")?.let { adapter.setItems(it.toList()) } } @@ -194,7 +194,10 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { with(holder.itemView) { - ImageLoader.load(context, context.assets.open("bg/$item").readBytes()) + ImageLoader.load( + context, + context.assets.open("bg${File.separator}$item").readBytes() + ) .centerCrop() .into(iv_bg) tv_name.setTextColor(secondaryTextColor) From 3cfbd0d0711938e50ca0038163d7a5088587d039 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 19 Oct 2020 21:32:33 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/AnalyzeByJSoup.kt | 16 +++---- .../app/ui/book/read/config/BgAdapter.kt | 42 +++++++++++++++++++ .../ui/book/read/config/BgTextConfigDialog.kt | 39 ++--------------- 3 files changed, 53 insertions(+), 44 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt index cdfa03d7b..59fc6952b 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt @@ -196,20 +196,20 @@ class AnalyzeByJSoup { private fun filterElements(elements: Elements, rules: Array?): Elements { if (rules == null || rules.size < 2) return elements - val selectedEls = Elements() - for (ele in elements) { + val result = Elements() + for (element in elements) { var isOk = false when (rules[0]) { - "class" -> isOk = ele.getElementsByClass(rules[1]).size > 0 - "id" -> isOk = ele.getElementById(rules[1]) != null - "tag" -> isOk = ele.getElementsByTag(rules[1]).size > 0 - "text" -> isOk = ele.getElementsContainingOwnText(rules[1]).size > 0 + "class" -> isOk = element.getElementsByClass(rules[1]).size > 0 + "id" -> isOk = element.getElementById(rules[1]) != null + "tag" -> isOk = element.getElementsByTag(rules[1]).size > 0 + "text" -> isOk = element.getElementsContainingOwnText(rules[1]).size > 0 } if (isOk) { - selectedEls.add(ele) + result.add(element) } } - return selectedEls + return result } /** diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt new file mode 100644 index 000000000..335ff8520 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt @@ -0,0 +1,42 @@ +package io.legado.app.ui.book.read.config + +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.constant.EventBus +import io.legado.app.help.ImageLoader +import io.legado.app.help.ReadBookConfig +import io.legado.app.utils.postEvent +import kotlinx.android.synthetic.main.item_bg_image.view.* +import org.jetbrains.anko.sdk27.listeners.onClick +import java.io.File + +class BgAdapter(context: Context, val textColor: Int) : + SimpleRecyclerAdapter(context, R.layout.item_bg_image) { + + override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { + with(holder.itemView) { + ImageLoader.load( + context, + context.assets.open("bg${File.separator}$item").readBytes() + ) + .centerCrop() + .into(iv_bg) + tv_name.setTextColor(textColor) + tv_name.text = item.substringBeforeLast(".") + } + } + + override fun registerListener(holder: ItemViewHolder) { + holder.itemView.apply { + this.onClick { + getItemByLayoutPosition(holder.layoutPosition)?.let { + ReadBookConfig.durConfig.setCurBg(1, it) + ReadBookConfig.upBg() + postEvent(EventBus.UP_CONFIG, false) + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index a41bf4003..bd7f3d32d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -2,7 +2,6 @@ package io.legado.app.ui.book.read.config import android.annotation.SuppressLint import android.app.Activity.RESULT_OK -import android.content.Context import android.content.DialogInterface import android.content.Intent import android.graphics.Color @@ -14,10 +13,7 @@ import androidx.documentfile.provider.DocumentFile import com.jaredrummler.android.colorpicker.ColorPickerDialog import io.legado.app.R import io.legado.app.base.BaseDialogFragment -import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.EventBus -import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig import io.legado.app.help.http.HttpHelper import io.legado.app.help.permission.Permissions @@ -53,8 +49,8 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { private val requestCodeImport = 132 private val configFileName = "readConfig.zip" private lateinit var adapter: BgAdapter - var primaryTextColor = 0 - var secondaryTextColor = 0 + private var primaryTextColor = 0 + private var secondaryTextColor = 0 override fun onStart() { super.onStart() @@ -109,7 +105,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { @SuppressLint("InflateParams") private fun initData() = with(ReadBookConfig.durConfig) { sw_dark_status_icon.isChecked = curStatusIconDark() - adapter = BgAdapter(requireContext()) + adapter = BgAdapter(requireContext(), secondaryTextColor) recycler_view.adapter = adapter val headerView = LayoutInflater.from(requireContext()) .inflate(R.layout.item_bg_image, recycler_view, false) @@ -189,35 +185,6 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { startActivityForResult(intent, requestCodeBg) } - inner class BgAdapter(context: Context) : - SimpleRecyclerAdapter(context, R.layout.item_bg_image) { - - override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { - with(holder.itemView) { - ImageLoader.load( - context, - context.assets.open("bg${File.separator}$item").readBytes() - ) - .centerCrop() - .into(iv_bg) - tv_name.setTextColor(secondaryTextColor) - tv_name.text = item.substringBeforeLast(".") - } - } - - override fun registerListener(holder: ItemViewHolder) { - holder.itemView.apply { - this.onClick { - getItemByLayoutPosition(holder.layoutPosition)?.let { - ReadBookConfig.durConfig.setCurBg(1, it) - ReadBookConfig.upBg() - postEvent(EventBus.UP_CONFIG, false) - } - } - } - } - } - @Suppress("BlockingMethodInNonBlockingContext") private fun exportConfig(uri: Uri) { execute { From 9378bde46e56b7831b096d9168158042fa0f997f Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 19 Oct 2020 21:37:34 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/my/MyFragment.kt | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) 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 e8eddefae..75f840986 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 @@ -29,12 +29,8 @@ import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.prefs.NameListPreference import io.legado.app.ui.widget.prefs.PreferenceCategory import io.legado.app.ui.widget.prefs.SwitchPreference -import io.legado.app.utils.LogUtils -import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.observeEventSticky -import io.legado.app.utils.putPrefBoolean +import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_title_bar.* -import org.jetbrains.anko.startActivity class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog.CallBack { @@ -138,20 +134,20 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog. override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - "bookSourceManage" -> context?.startActivity() - "replaceManage" -> context?.startActivity() - "setting" -> context?.startActivity( + "bookSourceManage" -> startActivity() + "replaceManage" -> startActivity() + "setting" -> startActivity( Pair("configType", ConfigViewModel.TYPE_CONFIG) ) - "web_dav_setting" -> context?.startActivity( + "web_dav_setting" -> startActivity( Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG) ) - "theme_setting" -> context?.startActivity( + "theme_setting" -> startActivity( Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG) ) - "readRecord" -> context?.startActivity() - "donate" -> context?.startActivity() - "about" -> context?.startActivity() + "readRecord" -> startActivity() + "donate" -> startActivity() + "about" -> startActivity() } return super.onPreferenceTreeClick(preference) } From 56ba339f23b41386337ae173818409b5210d1216 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 19 Oct 2020 21:46:48 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/main/MainActivity.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index db221bede..e14f0035a 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -191,10 +191,10 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun getItem(position: Int): Fragment { return when (getId(position)) { - 0 -> BookshelfFragment() - 1 -> ExploreFragment() - 2 -> RssFragment() - else -> MyFragment() + 0 -> fragmentMap[0] ?: BookshelfFragment() + 1 -> fragmentMap[1] ?: ExploreFragment() + 2 -> fragmentMap[2] ?: RssFragment() + else -> fragmentMap[3] ?: MyFragment() } } From 4cd36aa6e676c404bf615910b49d33341cc54eba Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 19 Oct 2020 22:11:46 +0800 Subject: [PATCH 05/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/utils/EncodingDetect.java | 42 ++++++------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/EncodingDetect.java b/app/src/main/java/io/legado/app/utils/EncodingDetect.java index b5bd4cf66..b026eff34 100644 --- a/app/src/main/java/io/legado/app/utils/EncodingDetect.java +++ b/app/src/main/java/io/legado/app/utils/EncodingDetect.java @@ -35,6 +35,7 @@ import static android.text.TextUtils.isEmpty; * @version 1.0 * @since Create on 2010-01-27 11:19:00 */ +@SuppressWarnings("ALL") public class EncodingDetect { public static String getHtmlEncode(@NonNull byte[] bytes) { @@ -117,6 +118,7 @@ public class EncodingDetect { } +@SuppressWarnings("ALL") class BytesEncodingDetect extends Encoding { // Frequency tables to hold the GB, Big5, and EUC-TW character // frequencies @@ -271,9 +273,7 @@ class BytesEncodingDetect extends Encoding { rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { // System.err.println(rawtext[i]); - if (rawtext[i] >= 0) { - // asciichars++; - } else { + if (rawtext[i] < 0) { dbchars++; if ((byte) 0xA1 <= rawtext[i] && rawtext[i] <= (byte) 0xF7 && (byte) 0xA1 <= rawtext[i + 1] @@ -312,9 +312,7 @@ class BytesEncodingDetect extends Encoding { rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { // System.err.println(rawtext[i]); - if (rawtext[i] >= 0) { - // asciichars++; - } else { + if (rawtext[i] < 0) { dbchars++; if ((byte) 0xA1 <= rawtext[i] && rawtext[i] <= (byte) 0xF7 && // Original GB range @@ -373,9 +371,7 @@ class BytesEncodingDetect extends Encoding { rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { // System.err.println(rawtext[i]); - if (rawtext[i] >= 0) { - // asciichars++; - } else { + if (rawtext[i] < 0) { dbchars++; if ((byte) 0xA1 <= rawtext[i] && rawtext[i] <= (byte) 0xF7 && // Original GB range @@ -516,9 +512,7 @@ class BytesEncodingDetect extends Encoding { // Check to see if characters fit into acceptable ranges rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { - if (rawtext[i] >= 0) { - // asciichars++; - } else { + if (rawtext[i] < 0) { dbchars++; if ((byte) 0xA1 <= rawtext[i] && rawtext[i] <= (byte) 0xF9 @@ -560,9 +554,7 @@ class BytesEncodingDetect extends Encoding { rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { // System.err.println(rawtext[i]); - if (rawtext[i] >= 128) { - // asciichars++; - } else { + if (rawtext[i] < 128) { dbchars++; if (0xA1 <= rawtext[i] && rawtext[i] <= 0xF9 @@ -626,9 +618,7 @@ class BytesEncodingDetect extends Encoding { // and have expected frequency of use rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { - if (rawtext[i] >= 0) { // in ASCII range - // asciichars++; - } else { // high bit set + if (rawtext[i] < 0) { // high bit set dbchars++; if (i + 3 < rawtextlen && (byte) 0x8E == rawtext[i] && (byte) 0xA1 <= rawtext[i + 1] @@ -846,9 +836,7 @@ class BytesEncodingDetect extends Encoding { rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { // System.err.println(rawtext[i]); - if (rawtext[i] >= 0) { - // asciichars++; - } else { + if (rawtext[i] < 0) { dbchars++; if ((byte) 0xA1 <= rawtext[i] && rawtext[i] <= (byte) 0xFE && (byte) 0xA1 <= rawtext[i + 1] @@ -886,9 +874,7 @@ class BytesEncodingDetect extends Encoding { rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { // System.err.println(rawtext[i]); - if (rawtext[i] >= 0) { - // asciichars++; - } else { + if (rawtext[i] < 0) { dbchars++; if ((byte) 0x81 <= rawtext[i] && rawtext[i] <= (byte) 0xFE @@ -945,9 +931,7 @@ class BytesEncodingDetect extends Encoding { rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { // System.err.println(rawtext[i]); - if (rawtext[i] >= 0) { - // asciichars++; - } else { + if (rawtext[i] < 0) { dbchars++; if ((byte) 0xA1 <= rawtext[i] && rawtext[i] <= (byte) 0xFE && (byte) 0xA1 <= rawtext[i + 1] @@ -997,9 +981,7 @@ class BytesEncodingDetect extends Encoding { rawtextlen = rawtext.length; for (i = 0; i < rawtextlen - 1; i++) { // System.err.println(rawtext[i]); - if (rawtext[i] >= 0) { - // asciichars++; - } else { + if (rawtext[i] < 0) { dbchars++; if (i + 1 < rawtext.length && (((byte) 0x81 <= rawtext[i] && rawtext[i] <= (byte) 0x9F) || ((byte) 0xE0 <= rawtext[i] && rawtext[i] <= (byte) 0xEF)) From 2419c718ab1649fc318a68f79495fc49e3f54c23 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 07:54:19 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/utils/EncodingDetect.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/utils/EncodingDetect.java b/app/src/main/java/io/legado/app/utils/EncodingDetect.java index b026eff34..8447ed238 100644 --- a/app/src/main/java/io/legado/app/utils/EncodingDetect.java +++ b/app/src/main/java/io/legado/app/utils/EncodingDetect.java @@ -4365,6 +4365,7 @@ class BytesEncodingDetect extends Encoding { } } +@SuppressWarnings("ALL") class Encoding { // Supported Encoding Types static int GB2312 = 0; From da44ea6e0c7f9f8877c785cd05b1f61023bf47be Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 08:00:12 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/utils/Toasts.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/utils/Toasts.kt b/app/src/main/java/io/legado/app/utils/Toasts.kt index 4348b4daf..9038c2231 100644 --- a/app/src/main/java/io/legado/app/utils/Toasts.kt +++ b/app/src/main/java/io/legado/app/utils/Toasts.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package io.legado.app.utils import android.widget.Toast From 1a8e45b8b401024092f83b10697366ef8ea2442f Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 09:50:35 +0800 Subject: [PATCH 08/19] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=88=86=E7=BB=84?= =?UTF-8?q?=E6=97=A0=E4=B9=A6=E7=B1=8D=E6=97=B6=E8=87=AA=E5=8A=A8=E9=9A=90?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/dao/BookGroupDao.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 9c362151e..eb3395a91 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 @@ -2,6 +2,7 @@ package io.legado.app.data.dao import androidx.lifecycle.LiveData import androidx.room.* +import io.legado.app.constant.BookType import io.legado.app.data.entities.BookGroup @Dao @@ -16,7 +17,16 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> - @Query("SELECT * FROM book_groups where show > 0 or groupId >= 0 ORDER BY `order`") + @Query( + """ + SELECT * FROM book_groups where groupId >= 0 + or (groupId = -4 and show > 0 and (select count(bookUrl) from books where ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 and type != ${BookType.audio} and origin != '${BookType.local}') > 0) + or (groupId = -3 and show > 0 and (select count(bookUrl) from books where type = ${BookType.audio}) > 0) + or (groupId = -2 and show > 0 and (select count(bookUrl) from books where origin = '${BookType.local}') > 0) + or (groupId = -1 and show > 0) + ORDER BY `order` + """ + ) fun liveDataShow(): LiveData> @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") From 9466956ae0042a01e86190802c02b36e8086b401 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 09:56:58 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E5=8F=96=E6=B6=88=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=88=86=E7=BB=84=E6=97=A0=E4=B9=A6=E7=B1=8D=E6=97=B6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/dao/BookGroupDao.kt | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) 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 eb3395a91..e23aa9eb5 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 @@ -2,7 +2,6 @@ package io.legado.app.data.dao import androidx.lifecycle.LiveData import androidx.room.* -import io.legado.app.constant.BookType import io.legado.app.data.entities.BookGroup @Dao @@ -17,16 +16,7 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> - @Query( - """ - SELECT * FROM book_groups where groupId >= 0 - or (groupId = -4 and show > 0 and (select count(bookUrl) from books where ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 and type != ${BookType.audio} and origin != '${BookType.local}') > 0) - or (groupId = -3 and show > 0 and (select count(bookUrl) from books where type = ${BookType.audio}) > 0) - or (groupId = -2 and show > 0 and (select count(bookUrl) from books where origin = '${BookType.local}') > 0) - or (groupId = -1 and show > 0) - ORDER BY `order` - """ - ) + @Query("SELECT * FROM book_groups where groupId >= 0 or (groupId < 0 and show > 0) ORDER BY `order`") fun liveDataShow(): LiveData> @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") From 49508c2204fd4edf4379ab6bfb5b207974a850ef Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 10:15:07 +0800 Subject: [PATCH 10/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/BookGroup.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt index 5663f2e13..c2669cc65 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt @@ -28,4 +28,18 @@ data class BookGroup( } } + override fun hashCode(): Int { + return groupId.hashCode() + } + + override fun equals(other: Any?): Boolean { + if (other is BookGroup) { + return other.groupId == groupId + && other.groupName == groupName + && other.order == order + && other.show == show + } + return false + } + } \ No newline at end of file From a2f194182018dfb43ac6562dabdc4db86bbae096 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 10:45:28 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=88=86=E7=BB=84?= =?UTF-8?q?=E6=97=A0=E4=B9=A6=E7=B1=8D=E6=97=B6=E8=87=AA=E5=8A=A8=E9=9A=90?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/dao/BookDao.kt | 9 +------ .../io/legado/app/data/dao/BookGroupDao.kt | 12 ++++++++- .../ui/main/bookshelf/BookshelfFragment.kt | 21 +++++++++------- .../ui/main/bookshelf/books/BooksFragment.kt | 25 ++++++++++--------- 4 files changed, 37 insertions(+), 30 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 b421c3ffa..3623792a0 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 @@ -18,16 +18,9 @@ interface BookDao { @Query("SELECT * FROM books WHERE origin = '${BookType.local}'") fun observeLocal(): LiveData> - @Query( - """ - select * from books where ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 and type != ${BookType.audio} and origin != '${BookType.local}' - """ - ) + @Query("select * from books where ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 and type != ${BookType.audio} and origin != '${BookType.local}'") fun observeNoGroup(): LiveData> - @Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups where groupId > 0) & `group` = 0") - fun observeNoGroupSize(): LiveData - @Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'") fun observeLocalUri(): LiveData> 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 e23aa9eb5..eb3395a91 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 @@ -2,6 +2,7 @@ package io.legado.app.data.dao import androidx.lifecycle.LiveData import androidx.room.* +import io.legado.app.constant.BookType import io.legado.app.data.entities.BookGroup @Dao @@ -16,7 +17,16 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> - @Query("SELECT * FROM book_groups where groupId >= 0 or (groupId < 0 and show > 0) ORDER BY `order`") + @Query( + """ + SELECT * FROM book_groups where groupId >= 0 + or (groupId = -4 and show > 0 and (select count(bookUrl) from books where ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 and type != ${BookType.audio} and origin != '${BookType.local}') > 0) + or (groupId = -3 and show > 0 and (select count(bookUrl) from books where type = ${BookType.audio}) > 0) + or (groupId = -2 and show > 0 and (select count(bookUrl) from books where origin = '${BookType.local}') > 0) + or (groupId = -1 and show > 0) + ORDER BY `order` + """ + ) fun liveDataShow(): LiveData> @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") 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 861e1025c..218bc004a 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 @@ -105,11 +105,12 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b private fun initBookGroupData() { bookGroupLiveData?.removeObservers(viewLifecycleOwner) - bookGroupLiveData = App.db.bookGroupDao().liveDataShow() - bookGroupLiveData?.observe(viewLifecycleOwner, { - viewModel.checkGroup(it) - upGroup(it) - }) + bookGroupLiveData = App.db.bookGroupDao().liveDataShow().apply { + observe(viewLifecycleOwner) { + viewModel.checkGroup(it) + upGroup(it) + } + } } override fun onQueryTextSubmit(query: String?): Boolean { @@ -126,10 +127,12 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b if (data.isEmpty()) { App.db.bookGroupDao().enableGroup(AppConst.bookGroupAllId) } else { - bookGroups.clear() - bookGroups.addAll(data) - adapter.notifyDataSetChanged() - selectLastTab() + if (data != bookGroups) { + bookGroups.clear() + bookGroups.addAll(data) + adapter.notifyDataSetChanged() + selectLastTab() + } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index ebd3e8cad..a52856d33 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -107,19 +107,20 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio() AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) - } - bookshelfLiveData?.observe(this, { list -> - tv_empty_msg.isGone = list.isNotEmpty() - val books = when (getPrefInt(PreferKey.bookshelfSort)) { - 1 -> list.sortedByDescending { it.latestChapterTime } - 2 -> list.sortedBy { it.name } - 3 -> list.sortedBy { it.order } - else -> list.sortedByDescending { it.durChapterTime } + }.apply { + observe(viewLifecycleOwner) { list -> + tv_empty_msg.isGone = list.isNotEmpty() + val books = when (getPrefInt(PreferKey.bookshelfSort)) { + 1 -> list.sortedByDescending { it.latestChapterTime } + 2 -> list.sortedBy { it.name } + 3 -> list.sortedBy { it.order } + else -> list.sortedByDescending { it.durChapterTime } + } + val diffResult = DiffUtil + .calculateDiff(BooksDiffCallBack(booksAdapter.getItems(), books)) + booksAdapter.setItems(books, diffResult) } - val diffResult = DiffUtil - .calculateDiff(BooksDiffCallBack(booksAdapter.getItems(), books)) - booksAdapter.setItems(books, diffResult) - }) + } } fun getBooks(): List { From 7da127c280c0493f690f16875284f59b839f71a8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 10:46:40 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=88=86=E7=BB=84?= =?UTF-8?q?=E6=97=A0=E4=B9=A6=E7=B1=8D=E6=97=B6=E8=87=AA=E5=8A=A8=E9=9A=90?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 70e2b98ae..5ad10ab4f 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/10/20** +* 默认分组无书籍时自动隐藏 + **2020/10/19** * 优化分组管理 * 修复预下载没有保存的bug From 72b7864600d0b43129ccda6b8587e646ebeb2a7e Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 11:10:05 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=88=86=E7=BB=84?= =?UTF-8?q?=E6=97=A0=E4=B9=A6=E7=B1=8D=E6=97=B6=E8=87=AA=E5=8A=A8=E9=9A=90?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 2 +- app/src/main/java/io/legado/app/data/dao/BookGroupDao.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 3623792a0..8794296f6 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 @@ -18,7 +18,7 @@ interface BookDao { @Query("SELECT * FROM books WHERE origin = '${BookType.local}'") fun observeLocal(): LiveData> - @Query("select * from books where ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 and type != ${BookType.audio} and origin != '${BookType.local}'") + @Query("select * from books where type != ${BookType.audio} and origin != '${BookType.local}' and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0") fun observeNoGroup(): LiveData> @Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'") 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 eb3395a91..6bf596905 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 @@ -20,7 +20,7 @@ interface BookGroupDao { @Query( """ SELECT * FROM book_groups where groupId >= 0 - or (groupId = -4 and show > 0 and (select count(bookUrl) from books where ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 and type != ${BookType.audio} and origin != '${BookType.local}') > 0) + or (groupId = -4 and show > 0 and (select count(bookUrl) from books where type != ${BookType.audio} and origin != '${BookType.local}' and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0) > 0) or (groupId = -3 and show > 0 and (select count(bookUrl) from books where type = ${BookType.audio}) > 0) or (groupId = -2 and show > 0 and (select count(bookUrl) from books where origin = '${BookType.local}') > 0) or (groupId = -1 and show > 0) From 17121a460470205f11de68e759d14f1cec760b45 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 14:08:24 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BookChapter.kt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 607704e6a..34a822f3f 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -36,19 +36,15 @@ data class BookChapter( var variable: String? = null //变量 ) : Parcelable { - @Ignore + @delegate:Transient + @delegate:Ignore @IgnoredOnParcel - var variableMap: HashMap? = null - private set - get() { - if (field == null) { - field = GSON.fromJsonObject>(variable) ?: HashMap() - } - return field - } + val variableMap by lazy { + GSON.fromJsonObject>(variable) ?: HashMap() + } fun putVariable(key: String, value: String) { - variableMap?.put(key, value) + variableMap[key] = value variable = GSON.toJson(variableMap) } From 7792765e1bfa0e76ea0c08b51fe1a59f7c1719b5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 14:11:18 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/entities/BookChapter.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 34a822f3f..4c120c0c9 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -50,7 +50,12 @@ data class BookChapter( override fun hashCode() = url.hashCode() - override fun equals(other: Any?) = if (other is BookChapter) other.url == url else false + override fun equals(other: Any?): Boolean { + if (other is BookChapter) { + return other.url == url + } + return false + } } From 570df8913597c2a5d35037f46e0fd7b6a1aabafe Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 14:17:08 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/RssSource.kt | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 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 300049f82..90418f0c0 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 @@ -39,14 +39,19 @@ data class RssSource( var header: String? = null, var enableJs: Boolean = false, var loadWithBaseUrl: Boolean = false, - + var customOrder: Int = 0 -): Parcelable, JsExtensions { - - override fun equals(other: Any?) = if (other is RssSource) other.sourceUrl == sourceUrl else false - +) : Parcelable, JsExtensions { + + override fun equals(other: Any?): Boolean { + if (other is RssSource) { + return other.sourceUrl == sourceUrl + } + return false + } + override fun hashCode() = sourceUrl.hashCode() - + @Throws(Exception::class) fun getHeaderMap() = HashMap().apply { this[AppConst.UA_NAME] = App.INSTANCE.getPrefString("user_agent") ?: AppConst.userAgent @@ -64,33 +69,37 @@ data class RssSource( } } } - + /** * 执行JS */ @Throws(Exception::class) - private fun evalJS(jsStr: String): Any = AppConst.SCRIPT_ENGINE.eval(jsStr, SimpleBindings().apply { this["java"] = this@RssSource }) - + private fun evalJS(jsStr: String): Any? { + val bindings = SimpleBindings() + bindings["java"] = this + return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings) + } + fun equal(source: RssSource): Boolean { return equal(sourceUrl, source.sourceUrl) - && equal(sourceIcon, source.sourceIcon) - && enabled == source.enabled - && equal(sourceGroup, source.sourceGroup) - && equal(ruleArticles, source.ruleArticles) - && equal(ruleNextPage, source.ruleNextPage) - && equal(ruleTitle, source.ruleTitle) - && equal(rulePubDate, source.rulePubDate) - && equal(ruleDescription, source.ruleDescription) - && equal(ruleLink, source.ruleLink) - && equal(ruleContent, source.ruleContent) - && enableJs == source.enableJs - && loadWithBaseUrl == source.loadWithBaseUrl + && equal(sourceIcon, source.sourceIcon) + && enabled == source.enabled + && equal(sourceGroup, source.sourceGroup) + && equal(ruleArticles, source.ruleArticles) + && equal(ruleNextPage, source.ruleNextPage) + && equal(ruleTitle, source.ruleTitle) + && equal(rulePubDate, source.rulePubDate) + && equal(ruleDescription, source.ruleDescription) + && equal(ruleLink, source.ruleLink) + && equal(ruleContent, source.ruleContent) + && enableJs == source.enableJs + && loadWithBaseUrl == source.loadWithBaseUrl } - + private fun equal(a: String?, b: String?): Boolean { return a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) } - + fun sortUrls(): LinkedHashMap = linkedMapOf().apply { sortUrl?.split("(&&|\n)+".toRegex())?.forEach { c -> From b55d511ce01ad9daa5e03e8a4e9b4f1e00ef0c9d Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 14:26:45 +0800 Subject: [PATCH 17/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/about/AboutFragment.kt | 14 ++------------ .../java/io/legado/app/utils/ContextExtensions.kt | 10 ++++++++++ 2 files changed, 12 insertions(+), 12 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 8744f8f92..eea2feba4 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 @@ -13,8 +13,8 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.applyTint import io.legado.app.utils.openUrl +import io.legado.app.utils.sendMail import io.legado.app.utils.sendToClip -import io.legado.app.utils.toast class AboutFragment : PreferenceFragmentCompat() { @@ -48,7 +48,7 @@ class AboutFragment : PreferenceFragmentCompat() { "contributors" -> openUrl(R.string.contributors_url) "update_log" -> showUpdateLog() "check_update" -> openUrl(R.string.latest_release_url) - "mail" -> sendMail() + "mail" -> requireContext().sendMail("kunfei.ge@gmail.com") "sourceRuleSummary" -> openUrl(R.string.source_rule_url) "git" -> openUrl(R.string.this_github_url) "home_page" -> openUrl(R.string.home_page_url) @@ -66,16 +66,6 @@ class AboutFragment : PreferenceFragmentCompat() { requireContext().openUrl(getString(addressID)) } - private fun sendMail() { - try { - val intent = Intent(Intent.ACTION_SENDTO) - intent.data = Uri.parse("mailto:kunfei.ge@gmail.com") - startActivity(intent) - } catch (e: Exception) { - toast(e.localizedMessage ?: "Error") - } - } - private fun showUpdateLog() { val log = String(requireContext().assets.open("updateLog.md").readBytes()) TextDialog.show(childFragmentManager, log, TextDialog.MD) diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index 489f5d508..b99f935eb 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -156,6 +156,16 @@ fun Context.getClipText(): String? { return null } +fun Context.sendMail(mail: String) { + try { + val intent = Intent(Intent.ACTION_SENDTO) + intent.data = Uri.parse("mailto:$mail") + startActivity(intent) + } catch (e: Exception) { + toast(e.localizedMessage ?: "Error") + } +} + /** * 系统是否暗色主题 */ From 027fc778ac4ac4356463faea8faf60c02d46d6fe Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 14:35:36 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/BookHelp.kt | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 4f1a2ba9f..537737c3f 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -11,7 +11,6 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.* -import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.delay import kotlinx.coroutines.withContext @@ -307,17 +306,13 @@ object BookHelp { private var replaceRules: List = arrayListOf() @Synchronized - suspend fun upReplaceRules() { - withContext(IO) { - synchronized(this) { - val o = bookOrigin - bookName?.let { - replaceRules = if (o.isNullOrEmpty()) { - App.db.replaceRuleDao().findEnabledByScope(it) - } else { - App.db.replaceRuleDao().findEnabledByScope(it, o) - } - } + fun upReplaceRules() { + val o = bookOrigin + bookName?.let { + replaceRules = if (o.isNullOrEmpty()) { + App.db.replaceRuleDao().findEnabledByScope(it) + } else { + App.db.replaceRuleDao().findEnabledByScope(it, o) } } } From 04a76a284998f349365d6cc59541c70f6f960690 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 16:53:40 +0800 Subject: [PATCH 19/19] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadMenu.kt | 45 +- .../io/legado/app/ui/widget/SearchView.kt | 17 +- .../app/ui/widget/image/CircleImageView.kt | 5 +- .../app/ui/widget/image/CoverImageView.kt | 20 +- .../app/ui/widget/image/FilletImageView.kt | 42 +- .../legado/app/ui/widget/image/PhotoView.kt | 408 +++++++++--------- .../app/ui/widget/text/AccentBgTextView.kt | 2 +- .../ui/widget/text/AutoCompleteTextView.kt | 13 +- 8 files changed, 261 insertions(+), 291 deletions(-) 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 277cde943..40af2c32d 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 @@ -21,37 +21,30 @@ import kotlinx.android.synthetic.main.view_read_menu.view.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick -class ReadMenu : FrameLayout { +/** + * 阅读界面菜单 + */ +class ReadMenu @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : FrameLayout(context, attrs, defStyleAttr) { var cnaShowMenu: Boolean = false - private var callBack: CallBack? = null + private val callBack: CallBack? get() = activity as? CallBack private lateinit var menuTopIn: Animation private lateinit var menuTopOut: Animation private lateinit var menuBottomIn: Animation private lateinit var menuBottomOut: Animation - private val bgColor: Int - private val textColor: Int - private var bottomBackgroundList: ColorStateList + private val bgColor: Int = context.bottomBackground + private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor)) + private val bottomBackgroundList: ColorStateList = Selector.colorBuild() + .setDefaultColor(bgColor) + .setPressedColor(ColorUtils.darkenColor(bgColor)) + .create() private var onMenuOutEnd: (() -> Unit)? = null val showBrightnessView get() = context.getPrefBoolean(PreferKey.showBrightnessView, true) - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( - context, - attrs, - defStyleAttr - ) - init { - callBack = activity as? CallBack - bgColor = context.bottomBackground - textColor = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor)) - bottomBackgroundList = Selector.colorBuild() - .setDefaultColor(bgColor) - .setPressedColor(ColorUtils.darkenColor(bgColor)) - .create() inflate(context, R.layout.view_read_menu, this) if (AppConfig.isNightTheme) { fabNightTheme.setImageResource(R.drawable.ic_daytime) @@ -254,9 +247,7 @@ class ReadMenu : FrameLayout { } } - override fun onAnimationRepeat(animation: Animation) { - - } + override fun onAnimationRepeat(animation: Animation) = Unit }) //隐藏菜单 @@ -277,9 +268,7 @@ class ReadMenu : FrameLayout { callBack?.upSystemUiVisibility() } - override fun onAnimationRepeat(animation: Animation) { - - } + override fun onAnimationRepeat(animation: Animation) = Unit }) } diff --git a/app/src/main/java/io/legado/app/ui/widget/SearchView.kt b/app/src/main/java/io/legado/app/ui/widget/SearchView.kt index 2f83c8594..82d24c671 100644 --- a/app/src/main/java/io/legado/app/ui/widget/SearchView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/SearchView.kt @@ -16,21 +16,14 @@ import android.widget.TextView import androidx.appcompat.widget.SearchView import io.legado.app.R -class SearchView : SearchView { +class SearchView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : SearchView(context, attrs, defStyleAttr) { private var mSearchHintIcon: Drawable? = null private var textView: TextView? = null - constructor( - context: Context, - attrs: AttributeSet? = null - ) : super(context, attrs) - - constructor( - context: Context, - attrs: AttributeSet?, - defStyleAttr: Int - ) : super(context, attrs, defStyleAttr) - @SuppressLint("UseCompatLoadingForDrawables") override fun onLayout( changed: Boolean, diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt index b1d1a5376..2364deab7 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt @@ -26,10 +26,7 @@ import kotlin.math.pow @Suppress("unused", "MemberVisibilityCanBePrivate") class CircleImageView(context: Context, attrs: AttributeSet) : - AppCompatImageView( - context, - attrs - ) { + AppCompatImageView(context, attrs) { private val mDrawableRect = RectF() private val mBorderRect = RectF() diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 52b0517c2..5a85a0573 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -20,7 +20,15 @@ import io.legado.app.utils.getPrefString * 封面 */ @Suppress("unused") -class CoverImageView : androidx.appcompat.widget.AppCompatImageView { +class CoverImageView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : androidx.appcompat.widget.AppCompatImageView( + context, + attrs, + defStyleAttr +) { internal var width: Float = 0.toFloat() internal var height: Float = 0.toFloat() private var nameHeight = 0f @@ -45,16 +53,6 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { private var author: String? = null private var loadFailed = false - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( - context, - attrs, - defStyleAttr - ) - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) val measuredHeight = measuredWidth * 7 / 5 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 bcb449329..57428fe47 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 @@ -10,7 +10,11 @@ import io.legado.app.R import io.legado.app.utils.dp import kotlin.math.max -class FilletImageView : AppCompatImageView { +class FilletImageView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : AppCompatImageView(context, attrs, defStyleAttr) { internal var width: Float = 0.toFloat() internal var height: Float = 0.toFloat() private var leftTopRadius: Int = 0 @@ -18,26 +22,29 @@ class FilletImageView : AppCompatImageView { private var rightBottomRadius: Int = 0 private var leftBottomRadius: Int = 0 - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { - init(context, attrs) - } - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { - init(context, attrs) - } - - private fun init(context: Context, attrs: AttributeSet) { + init { // 读取配置 val array = context.obtainStyledAttributes(attrs, R.styleable.FilletImageView) 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) + 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 + ) rightBottomRadius = - array.getDimensionPixelOffset(R.styleable.FilletImageView_right_bottom_radius, defaultRadius) - leftBottomRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_left_bottom_radius, defaultRadius) + array.getDimensionPixelOffset( + R.styleable.FilletImageView_right_bottom_radius, + defaultRadius + ) + leftBottomRadius = array.getDimensionPixelOffset( + R.styleable.FilletImageView_left_bottom_radius, + defaultRadius + ) //如果四个角的值没有设置,那么就使用通用的radius的值。 if (defaultRadius == leftTopRadius) { @@ -53,7 +60,6 @@ class FilletImageView : AppCompatImageView { leftBottomRadius = radius } array.recycle() - } override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { diff --git a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt index 5a2c7588f..08cc63e3a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt @@ -16,6 +16,7 @@ import android.view.animation.Interpolator import android.widget.ImageView import android.widget.OverScroller import android.widget.Scroller +import androidx.appcompat.widget.AppCompatImageView import io.legado.app.R import io.legado.app.ui.widget.image.photo.Info import io.legado.app.ui.widget.image.photo.OnRotateListener @@ -23,10 +24,12 @@ import io.legado.app.ui.widget.image.photo.RotateGestureDetector import kotlin.math.abs import kotlin.math.roundToInt - -@Suppress("UNUSED_PARAMETER", "unused", "MemberVisibilityCanBePrivate") -@SuppressLint("AppCompatCustomView") -class PhotoView : ImageView { +@Suppress("UNUSED_PARAMETER", "unused", "MemberVisibilityCanBePrivate", "PropertyName") +class PhotoView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : AppCompatImageView(context, attrs, defStyleAttr) { val MIN_ROTATE = 35 val ANIMA_DURING = 340 val MAX_SCALE = 2.5f @@ -45,9 +48,9 @@ class PhotoView : ImageView { private val mSynthesisMatrix: Matrix = Matrix() private val mTmpMatrix: Matrix = Matrix() - private var mRotateDetector: RotateGestureDetector? = null - private var mDetector: GestureDetector? = null - private var mScaleDetector: ScaleGestureDetector? = null + private val mRotateDetector: RotateGestureDetector + private val mDetector: GestureDetector + private val mScaleDetector: ScaleGestureDetector private var mClickListener: OnClickListener? = null private var mScaleType: ScaleType? = null @@ -100,23 +103,11 @@ class PhotoView : ImageView { private var mLongClick: OnLongClickListener? = null - constructor(context: Context) : super(context) { - init() - } + private val mRotateListener = RotateListener() + private val mGestureListener = GestureListener() + private val mScaleListener = ScaleGestureListener() - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { - init() - } - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( - context, - attrs, - defStyleAttr - ) { - init() - } - - private fun init() { + init { super.setScaleType(ScaleType.MATRIX) if (mScaleType == null) mScaleType = ScaleType.CENTER_INSIDE mRotateDetector = RotateGestureDetector(mRotateListener) @@ -484,11 +475,11 @@ class PhotoView : ImageView { return if (isEnable) { val action = event.actionMasked if (event.pointerCount >= 2) hasMultiTouch = true - mDetector!!.onTouchEvent(event) + mDetector.onTouchEvent(event) if (isRotateEnable) { - mRotateDetector!!.onTouchEvent(event) + mRotateDetector.onTouchEvent(event) } - mScaleDetector!!.onTouchEvent(event) + mScaleDetector.onTouchEvent(event) if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) onUp() true } else { @@ -566,49 +557,6 @@ class PhotoView : ImageView { return abs(rect.left.roundToInt() - (mWidgetRect.width() - rect.width()) / 2) < 1 } - private val mRotateListener: OnRotateListener = object : - OnRotateListener { - override fun onRotate( - degrees: Float, - focusX: Float, - focusY: Float - ) { - mRotateFlag += degrees - if (canRotate) { - mDegrees += degrees - mAnimMatrix.postRotate(degrees, focusX, focusY) - } else { - if (abs(mRotateFlag) >= mMinRotate) { - canRotate = true - mRotateFlag = 0f - } - } - } - } - - private val mScaleListener: OnScaleGestureListener = object : OnScaleGestureListener { - override fun onScale(detector: ScaleGestureDetector): Boolean { - val scaleFactor = detector.scaleFactor - if (java.lang.Float.isNaN(scaleFactor) || java.lang.Float.isInfinite(scaleFactor)) return false - mScale *= scaleFactor - //mScaleCenter.set(detector.getFocusX(), detector.getFocusY()); - mAnimMatrix.postScale( - scaleFactor, - scaleFactor, - detector.focusX, - detector.focusY - ) - executeTranslate() - return true - } - - override fun onScaleBegin(detector: ScaleGestureDetector): Boolean { - return true - } - - override fun onScaleEnd(detector: ScaleGestureDetector) {} - } - private fun resistanceScrollByX( overScroll: Float, detalX: Float @@ -652,147 +600,6 @@ class PhotoView : ImageView { mClickListener?.onClick(this) } - private val mGestureListener: GestureDetector.OnGestureListener = - object : SimpleOnGestureListener() { - override fun onLongPress(e: MotionEvent) { - mLongClick?.onLongClick(this@PhotoView) - } - - override fun onDown(e: MotionEvent): Boolean { - hasOverTranslate = false - hasMultiTouch = false - canRotate = false - removeCallbacks(mClickRunnable) - return false - } - - override fun onFling( - e1: MotionEvent, - e2: MotionEvent, - velocityX: Float, - velocityY: Float - ): Boolean { - if (hasMultiTouch) return false - if (!imgLargeWidth && !imgLargeHeight) return false - if (mTranslate.isRunning) return false - var vx = velocityX - var vy = velocityY - if (mImgRect.left.roundToInt() >= mWidgetRect.left - || mImgRect.right.roundToInt() <= mWidgetRect.right - ) { - vx = 0f - } - if (mImgRect.top.roundToInt() >= mWidgetRect.top - || mImgRect.bottom.roundToInt() <= mWidgetRect.bottom - ) { - vy = 0f - } - if (canRotate || mDegrees % 90 != 0f) { - var toDegrees = (mDegrees / 90).toInt() * 90.toFloat() - val remainder = mDegrees % 90 - if (remainder > 45) toDegrees += 90f else if (remainder < -45) toDegrees -= 90f - mTranslate.withRotate(mDegrees.toInt(), toDegrees.toInt()) - mDegrees = toDegrees - } - doTranslateReset(mImgRect) - mTranslate.withFling(vx, vy) - mTranslate.start() - // onUp(e2); - return super.onFling(e1, e2, velocityX, velocityY) - } - - override fun onScroll( - e1: MotionEvent, - e2: MotionEvent, - distanceX: Float, - distanceY: Float - ): Boolean { - var x = distanceX - var y = distanceY - if (mTranslate.isRunning) { - mTranslate.stop() - } - if (canScrollHorizontallySelf(x)) { - if (x < 0 && mImgRect.left - x > mWidgetRect.left) - x = mImgRect.left - if (x > 0 && mImgRect.right - x < mWidgetRect.right) - x = mImgRect.right - mWidgetRect.right - mAnimMatrix.postTranslate(-x, 0f) - mTranslateX -= x.toInt() - } else if (imgLargeWidth || hasMultiTouch || hasOverTranslate) { - checkRect() - if (!hasMultiTouch) { - if (x < 0 && mImgRect.left - x > mCommonRect.left) x = - resistanceScrollByX(mImgRect.left - mCommonRect.left, x) - if (x > 0 && mImgRect.right - x < mCommonRect.right) x = - resistanceScrollByX(mImgRect.right - mCommonRect.right, x) - } - mTranslateX -= x.toInt() - mAnimMatrix.postTranslate(-x, 0f) - hasOverTranslate = true - } - if (canScrollVerticallySelf(y)) { - if (y < 0 && mImgRect.top - y > mWidgetRect.top) y = - mImgRect.top - if (y > 0 && mImgRect.bottom - y < mWidgetRect.bottom) y = - mImgRect.bottom - mWidgetRect.bottom - mAnimMatrix.postTranslate(0f, -y) - mTranslateY -= y.toInt() - } else if (imgLargeHeight || hasOverTranslate || hasMultiTouch) { - checkRect() - if (!hasMultiTouch) { - if (y < 0 && mImgRect.top - y > mCommonRect.top) y = - resistanceScrollByY(mImgRect.top - mCommonRect.top, y) - if (y > 0 && mImgRect.bottom - y < mCommonRect.bottom) y = - resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, y) - } - mAnimMatrix.postTranslate(0f, -y) - mTranslateY -= y.toInt() - hasOverTranslate = true - } - executeTranslate() - return true - } - - override fun onSingleTapUp(e: MotionEvent): Boolean { - postDelayed(mClickRunnable, 250) - return false - } - - override fun onDoubleTap(e: MotionEvent): Boolean { - mTranslate.stop() - val from: Float - val to: Float - val imgCx = mImgRect.left + mImgRect.width() / 2 - val imgCy = mImgRect.top + mImgRect.height() / 2 - mScaleCenter[imgCx] = imgCy - mRotateCenter[imgCx] = imgCy - mTranslateX = 0 - mTranslateY = 0 - if (isZoonUp) { - from = mScale - to = 1f - } else { - from = mScale - to = mMaxScale - mScaleCenter[e.x] = e.y - } - mTmpMatrix.reset() - mTmpMatrix.postTranslate(-mBaseRect.left, -mBaseRect.top) - mTmpMatrix.postTranslate(mRotateCenter.x, mRotateCenter.y) - mTmpMatrix.postTranslate(-mHalfBaseRectWidth, -mHalfBaseRectHeight) - mTmpMatrix.postRotate(mDegrees, mRotateCenter.x, mRotateCenter.y) - mTmpMatrix.postScale(to, to, mScaleCenter.x, mScaleCenter.y) - mTmpMatrix.postTranslate(mTranslateX.toFloat(), mTranslateY.toFloat()) - mTmpMatrix.mapRect(mTmpRect, mBaseRect) - doTranslateReset(mTmpRect) - isZoonUp = !isZoonUp - mTranslate.withScale(from, to) - mTranslate.start() - return false - } - } - fun canScrollHorizontallySelf(direction: Float): Boolean { if (mImgRect.width() <= mWidgetRect.width()) return false @@ -1268,4 +1075,185 @@ class PhotoView : ImageView { executeTranslate() } + inner class RotateListener : OnRotateListener { + override fun onRotate( + degrees: Float, + focusX: Float, + focusY: Float + ) { + mRotateFlag += degrees + if (canRotate) { + mDegrees += degrees + mAnimMatrix.postRotate(degrees, focusX, focusY) + } else { + if (abs(mRotateFlag) >= mMinRotate) { + canRotate = true + mRotateFlag = 0f + } + } + } + } + + inner class GestureListener : SimpleOnGestureListener() { + override fun onLongPress(e: MotionEvent) { + mLongClick?.onLongClick(this@PhotoView) + } + + override fun onDown(e: MotionEvent): Boolean { + hasOverTranslate = false + hasMultiTouch = false + canRotate = false + removeCallbacks(mClickRunnable) + return false + } + + override fun onFling( + e1: MotionEvent, + e2: MotionEvent, + velocityX: Float, + velocityY: Float + ): Boolean { + if (hasMultiTouch) return false + if (!imgLargeWidth && !imgLargeHeight) return false + if (mTranslate.isRunning) return false + var vx = velocityX + var vy = velocityY + if (mImgRect.left.roundToInt() >= mWidgetRect.left + || mImgRect.right.roundToInt() <= mWidgetRect.right + ) { + vx = 0f + } + if (mImgRect.top.roundToInt() >= mWidgetRect.top + || mImgRect.bottom.roundToInt() <= mWidgetRect.bottom + ) { + vy = 0f + } + if (canRotate || mDegrees % 90 != 0f) { + var toDegrees = (mDegrees / 90).toInt() * 90.toFloat() + val remainder = mDegrees % 90 + if (remainder > 45) toDegrees += 90f else if (remainder < -45) toDegrees -= 90f + mTranslate.withRotate(mDegrees.toInt(), toDegrees.toInt()) + mDegrees = toDegrees + } + doTranslateReset(mImgRect) + mTranslate.withFling(vx, vy) + mTranslate.start() + // onUp(e2); + return super.onFling(e1, e2, velocityX, velocityY) + } + + override fun onScroll( + e1: MotionEvent, + e2: MotionEvent, + distanceX: Float, + distanceY: Float + ): Boolean { + var x = distanceX + var y = distanceY + if (mTranslate.isRunning) { + mTranslate.stop() + } + if (canScrollHorizontallySelf(x)) { + if (x < 0 && mImgRect.left - x > mWidgetRect.left) + x = mImgRect.left + if (x > 0 && mImgRect.right - x < mWidgetRect.right) + x = mImgRect.right - mWidgetRect.right + mAnimMatrix.postTranslate(-x, 0f) + mTranslateX -= x.toInt() + } else if (imgLargeWidth || hasMultiTouch || hasOverTranslate) { + checkRect() + if (!hasMultiTouch) { + if (x < 0 && mImgRect.left - x > mCommonRect.left) x = + resistanceScrollByX(mImgRect.left - mCommonRect.left, x) + if (x > 0 && mImgRect.right - x < mCommonRect.right) x = + resistanceScrollByX(mImgRect.right - mCommonRect.right, x) + } + mTranslateX -= x.toInt() + mAnimMatrix.postTranslate(-x, 0f) + hasOverTranslate = true + } + if (canScrollVerticallySelf(y)) { + if (y < 0 && mImgRect.top - y > mWidgetRect.top) y = + mImgRect.top + if (y > 0 && mImgRect.bottom - y < mWidgetRect.bottom) y = + mImgRect.bottom - mWidgetRect.bottom + mAnimMatrix.postTranslate(0f, -y) + mTranslateY -= y.toInt() + } else if (imgLargeHeight || hasOverTranslate || hasMultiTouch) { + checkRect() + if (!hasMultiTouch) { + if (y < 0 && mImgRect.top - y > mCommonRect.top) y = + resistanceScrollByY(mImgRect.top - mCommonRect.top, y) + if (y > 0 && mImgRect.bottom - y < mCommonRect.bottom) y = + resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, y) + } + mAnimMatrix.postTranslate(0f, -y) + mTranslateY -= y.toInt() + hasOverTranslate = true + } + executeTranslate() + return true + } + + override fun onSingleTapUp(e: MotionEvent): Boolean { + postDelayed(mClickRunnable, 250) + return false + } + + override fun onDoubleTap(e: MotionEvent): Boolean { + mTranslate.stop() + val from: Float + val to: Float + val imgCx = mImgRect.left + mImgRect.width() / 2 + val imgCy = mImgRect.top + mImgRect.height() / 2 + mScaleCenter[imgCx] = imgCy + mRotateCenter[imgCx] = imgCy + mTranslateX = 0 + mTranslateY = 0 + if (isZoonUp) { + from = mScale + to = 1f + } else { + from = mScale + to = mMaxScale + mScaleCenter[e.x] = e.y + } + mTmpMatrix.reset() + mTmpMatrix.postTranslate(-mBaseRect.left, -mBaseRect.top) + mTmpMatrix.postTranslate(mRotateCenter.x, mRotateCenter.y) + mTmpMatrix.postTranslate(-mHalfBaseRectWidth, -mHalfBaseRectHeight) + mTmpMatrix.postRotate(mDegrees, mRotateCenter.x, mRotateCenter.y) + mTmpMatrix.postScale(to, to, mScaleCenter.x, mScaleCenter.y) + mTmpMatrix.postTranslate(mTranslateX.toFloat(), mTranslateY.toFloat()) + mTmpMatrix.mapRect(mTmpRect, mBaseRect) + doTranslateReset(mTmpRect) + isZoonUp = !isZoonUp + mTranslate.withScale(from, to) + mTranslate.start() + return false + } + } + + inner class ScaleGestureListener : OnScaleGestureListener { + override fun onScale(detector: ScaleGestureDetector): Boolean { + val scaleFactor = detector.scaleFactor + if (java.lang.Float.isNaN(scaleFactor) || java.lang.Float.isInfinite(scaleFactor)) return false + mScale *= scaleFactor + //mScaleCenter.set(detector.getFocusX(), detector.getFocusY()); + mAnimMatrix.postScale( + scaleFactor, + scaleFactor, + detector.focusX, + detector.focusY + ) + executeTranslate() + return true + } + + override fun onScaleBegin(detector: ScaleGestureDetector): Boolean { + return true + } + + override fun onScaleEnd(detector: ScaleGestureDetector) {} + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt b/app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt index f6fc05cd4..3d9df36f0 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt @@ -11,7 +11,7 @@ import io.legado.app.utils.ColorUtils import io.legado.app.utils.dp import io.legado.app.utils.getCompatColor -class AccentBgTextView(context: Context, attrs: AttributeSet?) : +class AccentBgTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : AppCompatTextView(context, attrs) { private var radius = 0 diff --git a/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt b/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt index 1319aac5e..c7eb18ee4 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt @@ -16,12 +16,12 @@ import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_1line_text_and_del.view.* import org.jetbrains.anko.sdk27.listeners.onClick - -class AutoCompleteTextView : AppCompatAutoCompleteTextView { - - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) +@Suppress("unused") +class AutoCompleteTextView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : AppCompatAutoCompleteTextView(context, attrs, defStyleAttr) { var delCallBack: ((value: String) -> Unit)? = null @@ -33,7 +33,6 @@ class AutoCompleteTextView : AppCompatAutoCompleteTextView { return true } - @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent?): Boolean { if (event?.action == MotionEvent.ACTION_DOWN) {