Merge branch 'master' into h11128pull

pull/365/head
Jason Yao 4 years ago committed by GitHub
commit 752fb4fd6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/src/main/assets/themeConfig.json
  2. 2
      app/src/main/java/io/legado/app/App.kt
  3. 17
      app/src/main/java/io/legado/app/help/CrashHandler.kt
  4. 28
      app/src/main/java/io/legado/app/help/ThemeConfig.kt
  5. 8
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  8. 2
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  9. 2
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  10. 2
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  11. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  12. 21
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  13. 11
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt
  14. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  15. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  16. 27
      app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt
  17. 2
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  18. 2
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt
  19. 23
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  20. 11
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt
  21. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  22. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt
  23. 4
      app/src/main/java/io/legado/app/ui/widget/recycler/HeaderAdapterDataObserver.kt
  24. 2
      app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt
  25. 7
      app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt
  26. 10
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  27. 10
      app/src/main/res/menu/theme_list.xml

@ -9,7 +9,7 @@
}, },
{ {
"themeName": "黑白", "themeName": "黑白",
"isNightTheme": false, "isNightTheme": true,
"primaryColor": "#303030", "primaryColor": "#303030",
"accentColor": "#E0E0E0", "accentColor": "#E0E0E0",
"backgroundColor": "#424242", "backgroundColor": "#424242",
@ -17,7 +17,7 @@
}, },
{ {
"themeName": "A屏黑", "themeName": "A屏黑",
"isNightTheme": false, "isNightTheme": true,
"primaryColor": "#000000", "primaryColor": "#000000",
"accentColor": "#FFFFFF", "accentColor": "#FFFFFF",
"backgroundColor": "#000000", "backgroundColor": "#000000",

@ -45,7 +45,7 @@ class App : MultiDexApplication() {
super.onCreate() super.onCreate()
INSTANCE = this INSTANCE = this
androidId = Settings.System.getString(contentResolver, Settings.Secure.ANDROID_ID) androidId = Settings.System.getString(contentResolver, Settings.Secure.ANDROID_ID)
CrashHandler().init(this) CrashHandler(this)
LanguageUtils.setConfigurationOld(this) LanguageUtils.setConfigurationOld(this)
db = AppDatabase.createDatabase(INSTANCE) db = AppDatabase.createDatabase(INSTANCE)
packageManager.getPackageInfo(packageName, 0)?.let { packageManager.getPackageInfo(packageName, 0)?.let {

@ -20,18 +20,14 @@ import java.util.concurrent.TimeUnit
* 异常管理类 * 异常管理类
*/ */
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
class CrashHandler : Thread.UncaughtExceptionHandler { class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
private val tag = this.javaClass.simpleName private val tag = this.javaClass.simpleName
/** /**
* 系统默认UncaughtExceptionHandler * 系统默认UncaughtExceptionHandler
*/ */
private var mDefaultHandler: Thread.UncaughtExceptionHandler? = null private var mDefaultHandler: Thread.UncaughtExceptionHandler? = null
/**
* context
*/
private var mContext: Context? = null
/** /**
* 存储异常和参数信息 * 存储异常和参数信息
*/ */
@ -43,8 +39,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler {
@SuppressLint("SimpleDateFormat") @SuppressLint("SimpleDateFormat")
private val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") private val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss")
fun init(context: Context) { init {
mContext = context
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler() mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler()
//设置该CrashHandler为系统默认的 //设置该CrashHandler为系统默认的
Thread.setDefaultUncaughtExceptionHandler(this) Thread.setDefaultUncaughtExceptionHandler(this)
@ -65,14 +60,14 @@ class CrashHandler : Thread.UncaughtExceptionHandler {
private fun handleException(ex: Throwable?) { private fun handleException(ex: Throwable?) {
if (ex == null) return if (ex == null) return
//收集设备参数信息 //收集设备参数信息
collectDeviceInfo(mContext!!) collectDeviceInfo(context)
//添加自定义信息 //添加自定义信息
addCustomInfo() addCustomInfo()
kotlin.runCatching { kotlin.runCatching {
//使用Toast来显示异常信息 //使用Toast来显示异常信息
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
Toast.makeText( Toast.makeText(
mContext, context,
ex.message, ex.message,
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show() ).show()
@ -141,7 +136,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler {
val timestamp = System.currentTimeMillis() val timestamp = System.currentTimeMillis()
val time = format.format(Date()) val time = format.format(Date())
val fileName = "crash-$time-$timestamp.log" val fileName = "crash-$time-$timestamp.log"
mContext?.externalCacheDir?.let { rootFile -> context.externalCacheDir?.let { rootFile ->
FileUtils.getFile(rootFile, "crash").listFiles()?.forEach { FileUtils.getFile(rootFile, "crash").listFiles()?.forEach {
if (it.lastModified() < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)) { if (it.lastModified() < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)) {
it.delete() it.delete()

@ -2,6 +2,7 @@ package io.legado.app.help
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import androidx.annotation.Keep
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
@ -40,7 +41,14 @@ object ThemeConfig {
} }
} }
fun addConfig(newConfig: Config) { fun addConfig(json: String) {
GSON.fromJsonObject<Config>(json)?.let {
addConfig(it)
save()
}
}
private fun addConfig(newConfig: Config) {
configList.forEachIndexed { index, config -> configList.forEachIndexed { index, config ->
if (newConfig.themeName == config.themeName) { if (newConfig.themeName == config.themeName) {
configList[index] = newConfig configList[index] = newConfig
@ -66,10 +74,7 @@ object ThemeConfig {
fun applyConfig(context: Context, config: Config) { fun applyConfig(context: Context, config: Config) {
val primary = Color.parseColor(config.primaryColor) val primary = Color.parseColor(config.primaryColor)
val accent = Color.parseColor(config.accentColor) val accent = Color.parseColor(config.accentColor)
var background = Color.parseColor(config.backgroundColor) val background = Color.parseColor(config.backgroundColor)
if (!ColorUtils.isColorLight(background)) {
background = context.getCompatColor(R.color.md_grey_100)
}
val bBackground = Color.parseColor(config.bottomBackground) val bBackground = Color.parseColor(config.bottomBackground)
if (config.isNightTheme) { if (config.isNightTheme) {
context.putPrefInt(PreferKey.cNPrimary, primary) context.putPrefInt(PreferKey.cNPrimary, primary)
@ -127,13 +132,14 @@ object ThemeConfig {
addConfig(config) addConfig(config)
} }
@Keep
class Config( class Config(
var themeName: String = "典雅蓝", var themeName: String,
var isNightTheme: Boolean = false, var isNightTheme: Boolean,
var primaryColor: String = "#03A9F4", var primaryColor: String,
var accentColor: String = "#AD1457", var accentColor: String,
var backgroundColor: String = "#F5F5F5", var backgroundColor: String,
var bottomBackground: String = "#EEEEEE" var bottomBackground: String
) )
} }

@ -6,6 +6,7 @@ import androidx.documentfile.provider.DocumentFile
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ThemeConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -34,6 +35,7 @@ object Backup {
"readRecord.json", "readRecord.json",
"httpTTS.json", "httpTTS.json",
ReadBookConfig.configFileName, ReadBookConfig.configFileName,
ThemeConfig.configFileName,
"config.xml" "config.xml"
) )
} }
@ -61,10 +63,14 @@ object Backup {
writeListToJson(App.db.txtTocRule().all, "txtTocRule.json", backupPath) writeListToJson(App.db.txtTocRule().all, "txtTocRule.json", backupPath)
writeListToJson(App.db.readRecordDao().all, "readRecord.json", backupPath) writeListToJson(App.db.readRecordDao().all, "readRecord.json", backupPath)
writeListToJson(App.db.httpTTSDao().all, "httpTTS.json", backupPath) writeListToJson(App.db.httpTTSDao().all, "httpTTS.json", backupPath)
GSON.toJson(ReadBookConfig.configList)?.let { GSON.toJson(ReadBookConfig.configList).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName) FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName)
.writeText(it) .writeText(it)
} }
GSON.toJson(ThemeConfig.configList).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName)
.writeText(it)
}
Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp ->
val edit = sp.edit() val edit = sp.edit()
App.INSTANCE.defaultSharedPreferences.all.map { App.INSTANCE.defaultSharedPreferences.all.map {

@ -14,7 +14,6 @@ import io.legado.app.constant.AppConst
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup 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.alert
import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.dialogs.okButton
@ -22,6 +21,7 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.ui.book.group.GroupManageDialog import io.legado.app.ui.book.group.GroupManageDialog
import io.legado.app.ui.book.group.GroupSelectDialog import io.legado.app.ui.book.group.GroupSelectDialog
import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt

@ -8,8 +8,8 @@ import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import kotlinx.android.synthetic.main.item_arrange_book.view.* import kotlinx.android.synthetic.main.item_arrange_book.view.*
import org.jetbrains.anko.backgroundColor import org.jetbrains.anko.backgroundColor
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick

@ -21,11 +21,11 @@ import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.* import io.legado.app.lib.dialogs.*
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel

@ -20,7 +20,6 @@ import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.BookGroup 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.alert
import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.noButton
@ -28,6 +27,7 @@ import io.legado.app.lib.dialogs.yesButton
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel

@ -21,13 +21,13 @@ import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.TxtTocRule import io.legado.app.data.entities.TxtTocRule
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.cancelButton
import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.dialogs.okButton
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.* import io.legado.app.utils.*

@ -32,7 +32,9 @@ class ContentView(context: Context) : FrameLayout(context) {
private var tvPageAndTotal: BatteryView? = null private var tvPageAndTotal: BatteryView? = null
val headerHeight: Int val headerHeight: Int
get() = if (ReadBookConfig.hideStatusBar) ll_header.height else context.statusBarHeight get() = if (ReadBookConfig.hideStatusBar) {
if (ll_header.isGone) 0 else ll_header.height
} else context.statusBarHeight
init { init {
//设置背景防止切换背景时文字重叠 //设置背景防止切换背景时文字重叠

@ -1,9 +1,6 @@
package io.legado.app.ui.book.source.edit package io.legado.app.ui.book.source.edit
import android.app.Activity import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Rect import android.graphics.Rect
import android.net.Uri import android.net.Uri
@ -28,10 +25,7 @@ import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
import io.legado.app.ui.login.SourceLogin import io.legado.app.ui.login.SourceLogin
import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.utils.GSON import io.legado.app.utils.*
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel
import io.legado.app.utils.shareWithQr
import kotlinx.android.synthetic.main.activity_book_source_edit.* import kotlinx.android.synthetic.main.activity_book_source_edit.*
import org.jetbrains.anko.* import org.jetbrains.anko.*
import kotlin.math.abs import kotlin.math.abs
@ -80,18 +74,11 @@ class BookSourceEditActivity :
} }
} }
} }
R.id.menu_copy_source -> getSource().let { source -> R.id.menu_copy_source -> sendToClip(GSON.toJson(getSource()))
GSON.toJson(source)?.let { sourceStr ->
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
clipboard?.setPrimaryClip(ClipData.newPlainText(null, sourceStr))
}
}
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) }
R.id.menu_qr_code_camera -> startActivityForResult<QrCodeActivity>(qrRequestCode) R.id.menu_qr_code_camera -> startActivityForResult<QrCodeActivity>(qrRequestCode)
R.id.menu_share_str -> GSON.toJson(getSource())?.let { share(it) } R.id.menu_share_str -> share(GSON.toJson(getSource()))
R.id.menu_share_qr -> GSON.toJson(getSource())?.let { sourceStr -> R.id.menu_share_qr -> shareWithQr(getString(R.string.share_book_source), GSON.toJson(getSource()))
shareWithQr(getString(R.string.share_book_source), sourceStr)
}
R.id.menu_rule_summary -> { R.id.menu_rule_summary -> {
try { try {
val intent = Intent(Intent.ACTION_VIEW) val intent = Intent(Intent.ACTION_VIEW)

@ -1,8 +1,6 @@
package io.legado.app.ui.book.source.edit package io.legado.app.ui.book.source.edit
import android.app.Application import android.app.Application
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent import android.content.Intent
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
@ -10,6 +8,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.help.storage.OldRule import io.legado.app.help.storage.OldRule
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getClipText
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { class BookSourceEditViewModel(application: Application) : BaseViewModel(application) {
@ -54,12 +53,8 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
fun pasteSource(onSuccess: (source: BookSource) -> Unit) { fun pasteSource(onSuccess: (source: BookSource) -> Unit) {
execute(context = Dispatchers.Main) { execute(context = Dispatchers.Main) {
var source: BookSource? = null var source: BookSource? = null
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? context.getClipText()?.let { json ->
clipboard?.primaryClip?.let { source = OldRule.jsonToBookSource(json)
if (it.itemCount > 0) {
val json = it.getItemAt(0).text.toString()
source = OldRule.jsonToBookSource(json)
}
} }
source source
}.onError { }.onError {

@ -20,7 +20,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.* import io.legado.app.lib.dialogs.*
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
@ -32,6 +31,7 @@ import io.legado.app.ui.filechooser.FilePicker
import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.* import io.legado.app.utils.*

@ -12,9 +12,9 @@ import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.ItemTouchCallback.OnItemTouchCallbackListener
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback.OnItemTouchCallbackListener
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_book_source.view.* import kotlinx.android.synthetic.main.item_book_source.view.*

@ -3,8 +3,10 @@ package io.legado.app.ui.config
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
@ -18,12 +20,13 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getClipText
import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.dialog_recycler_view.*
import kotlinx.android.synthetic.main.item_theme_config.view.* import kotlinx.android.synthetic.main.item_theme_config.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.share import org.jetbrains.anko.share
class ThemeListDialog : BaseDialogFragment() { class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var adapter: Adapter private lateinit var adapter: Adapter
@ -46,6 +49,7 @@ class ThemeListDialog : BaseDialogFragment() {
tool_bar.setBackgroundColor(primaryColor) tool_bar.setBackgroundColor(primaryColor)
tool_bar.setTitle(R.string.theme_list) tool_bar.setTitle(R.string.theme_list)
initView() initView()
initMenu()
initData() initData()
} }
@ -56,10 +60,28 @@ class ThemeListDialog : BaseDialogFragment() {
recycler_view.adapter = adapter recycler_view.adapter = adapter
} }
private fun initMenu() {
tool_bar.setOnMenuItemClickListener(this)
tool_bar.inflateMenu(R.menu.theme_list)
tool_bar.menu.applyTint(requireContext())
}
fun initData() { fun initData() {
adapter.setItems(ThemeConfig.configList) adapter.setItems(ThemeConfig.configList)
} }
override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.menu_import -> {
requireContext().getClipText()?.let {
ThemeConfig.addConfig(it)
initData()
}
}
}
return true
}
fun delete(index: Int) { fun delete(index: Int) {
alert(R.string.delete, R.string.sure_del) { alert(R.string.delete, R.string.sure_del) {
okButton { okButton {
@ -85,6 +107,9 @@ class ThemeListDialog : BaseDialogFragment() {
override fun registerListener(holder: ItemViewHolder) { override fun registerListener(holder: ItemViewHolder) {
holder.itemView.apply { holder.itemView.apply {
onClick {
ThemeConfig.applyConfig(context, ThemeConfig.configList[holder.layoutPosition])
}
iv_share.onClick { iv_share.onClick {
share(holder.layoutPosition) share(holder.layoutPosition)
} }

@ -21,7 +21,6 @@ import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.help.ItemTouchCallback
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.* import io.legado.app.lib.dialogs.*
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
@ -32,6 +31,7 @@ import io.legado.app.ui.filechooser.FilePicker
import io.legado.app.ui.replacerule.edit.ReplaceEditDialog import io.legado.app.ui.replacerule.edit.ReplaceEditDialog
import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.* import io.legado.app.utils.*

@ -10,9 +10,9 @@ import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import kotlinx.android.synthetic.main.item_replace_rule.view.* import kotlinx.android.synthetic.main.item_replace_rule.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.* import java.util.*

@ -1,9 +1,6 @@
package io.legado.app.ui.rss.source.edit package io.legado.app.ui.rss.source.edit
import android.app.Activity import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Rect import android.graphics.Rect
import android.os.Bundle import android.os.Bundle
@ -23,10 +20,7 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity
import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.utils.GSON import io.legado.app.utils.*
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel
import io.legado.app.utils.shareWithQr
import kotlinx.android.synthetic.main.activity_rss_source_edit.* import kotlinx.android.synthetic.main.activity_rss_source_edit.*
import org.jetbrains.anko.* import org.jetbrains.anko.*
import kotlin.math.abs import kotlin.math.abs
@ -97,20 +91,11 @@ class RssSourceEditActivity :
} }
} }
} }
R.id.menu_copy_source -> { R.id.menu_copy_source -> sendToClip(GSON.toJson(getRssSource()))
GSON.toJson(getRssSource())?.let { sourceStr ->
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
clipboard?.setPrimaryClip(ClipData.newPlainText(null, sourceStr))
}
}
R.id.menu_qr_code_camera -> startActivityForResult<QrCodeActivity>(qrRequestCode) R.id.menu_qr_code_camera -> startActivityForResult<QrCodeActivity>(qrRequestCode)
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) }
R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr -> R.id.menu_share_str -> share(GSON.toJson(getRssSource()))
share(sourceStr) R.id.menu_share_qr -> shareWithQr(getString(R.string.share_rss_source), GSON.toJson(getRssSource()))
}
R.id.menu_share_qr -> GSON.toJson(getRssSource())?.let { sourceStr ->
shareWithQr(getString(R.string.share_rss_source), sourceStr)
}
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }

@ -1,14 +1,13 @@
package io.legado.app.ui.rss.source.edit package io.legado.app.ui.rss.source.edit
import android.app.Application import android.app.Application
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent import android.content.Intent
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getClipText
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { class RssSourceEditViewModel(application: Application) : BaseViewModel(application) {
@ -53,12 +52,8 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
fun pasteSource(onSuccess: (source: RssSource) -> Unit) { fun pasteSource(onSuccess: (source: RssSource) -> Unit) {
execute(context = Dispatchers.Main) { execute(context = Dispatchers.Main) {
var source: RssSource? = null var source: RssSource? = null
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? context.getClipText()?.let { json ->
clipboard?.primaryClip?.let { source = GSON.fromJsonObject<RssSource>(json)
if (it.itemCount > 0) {
val json = it.getItemAt(0).text.toString().trim()
source = GSON.fromJsonObject<RssSource>(json)
}
} }
source source
}.onError { }.onError {

@ -20,7 +20,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.* import io.legado.app.lib.dialogs.*
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
@ -31,6 +30,7 @@ import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.* import io.legado.app.utils.*

@ -10,9 +10,9 @@ import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import kotlinx.android.synthetic.main.item_rss_source.view.* import kotlinx.android.synthetic.main.item_rss_source.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.* import java.util.*

@ -1,8 +1,8 @@
package io.legado.app.help package io.legado.app.ui.widget.recycler
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
internal class AdapterDataObserverHeader( internal class HeaderAdapterDataObserver(
private var adapterDataObserver: RecyclerView.AdapterDataObserver, private var adapterDataObserver: RecyclerView.AdapterDataObserver,
private var headerCount: Int private var headerCount: Int
) : RecyclerView.AdapterDataObserver() { ) : RecyclerView.AdapterDataObserver() {

@ -1,4 +1,4 @@
package io.legado.app.help package io.legado.app.ui.widget.recycler
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager

@ -4,12 +4,7 @@ import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSmoothScroller import androidx.recyclerview.widget.LinearSmoothScroller
class UpLinearLayoutManager: LinearLayoutManager { class UpLinearLayoutManager(val context: Context) : LinearLayoutManager(context) {
val context: Context
constructor(context: Context) : super(context) {
this.context = context
}
fun smoothScrollToPosition(position: Int) { fun smoothScrollToPosition(position: Int) {
smoothScrollToPosition(position, 0) smoothScrollToPosition(position, 0)

@ -146,6 +146,16 @@ fun Context.sendToClip(text: String) {
} }
} }
fun Context.getClipText(): String? {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?
clipboard?.primaryClip?.let {
if (it.itemCount > 0) {
return it.getItemAt(0).text.toString().trim()
}
}
return null
}
/** /**
* 系统是否暗色主题 * 系统是否暗色主题
*/ */

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_import"
android:title="剪贴板导入"
app:showAsAction="always" />
</menu>
Loading…
Cancel
Save