Merge branch 'h11128pull' of github.com:h11128/legado into h11128pull

pull/365/head
Jason Yao 4 years ago
commit 1417b1d16f
  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": "黑白",
"isNightTheme": false,
"isNightTheme": true,
"primaryColor": "#303030",
"accentColor": "#E0E0E0",
"backgroundColor": "#424242",
@ -17,7 +17,7 @@
},
{
"themeName": "A屏黑",
"isNightTheme": false,
"isNightTheme": true,
"primaryColor": "#000000",
"accentColor": "#FFFFFF",
"backgroundColor": "#000000",

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

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

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

@ -6,6 +6,7 @@ import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.constant.PreferKey
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ThemeConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
@ -34,6 +35,7 @@ object Backup {
"readRecord.json",
"httpTTS.json",
ReadBookConfig.configFileName,
ThemeConfig.configFileName,
"config.xml"
)
}
@ -61,10 +63,14 @@ object Backup {
writeListToJson(App.db.txtTocRule().all, "txtTocRule.json", backupPath)
writeListToJson(App.db.readRecordDao().all, "readRecord.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)
.writeText(it)
}
GSON.toJson(ThemeConfig.configList).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName)
.writeText(it)
}
Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp ->
val edit = sp.edit()
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.data.entities.Book
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.noButton
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.GroupSelectDialog
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.utils.applyTint
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.data.entities.Book
import io.legado.app.data.entities.BookGroup
import io.legado.app.help.ItemTouchCallback
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 org.jetbrains.anko.backgroundColor
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.data.entities.BookGroup
import io.legado.app.help.AppConfig
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.*
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor
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.utils.applyTint
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.SimpleRecyclerAdapter
import io.legado.app.data.entities.BookGroup
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
@ -28,6 +27,7 @@ import io.legado.app.lib.dialogs.yesButton
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor
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.utils.applyTint
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.SimpleRecyclerAdapter
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.cancelButton
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.okButton
import io.legado.app.lib.theme.backgroundColor
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.text.AutoCompleteTextView
import io.legado.app.utils.*

@ -32,7 +32,9 @@ class ContentView(context: Context) : FrameLayout(context) {
private var tvPageAndTotal: BatteryView? = null
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 {
//设置背景防止切换背景时文字重叠

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

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

@ -20,7 +20,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.BookSource
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.*
import io.legado.app.lib.theme.ATH
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.widget.SelectActionBar
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.text.AutoCompleteTextView
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.SimpleRecyclerAdapter
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.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback.OnItemTouchCallbackListener
import io.legado.app.utils.invisible
import io.legado.app.utils.visible
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.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
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.utils.GSON
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.item_theme_config.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.share
class ThemeListDialog : BaseDialogFragment() {
class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var adapter: Adapter
@ -46,6 +49,7 @@ class ThemeListDialog : BaseDialogFragment() {
tool_bar.setBackgroundColor(primaryColor)
tool_bar.setTitle(R.string.theme_list)
initView()
initMenu()
initData()
}
@ -56,10 +60,28 @@ class ThemeListDialog : BaseDialogFragment() {
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() {
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) {
alert(R.string.delete, R.string.sure_del) {
okButton {
@ -85,6 +107,9 @@ class ThemeListDialog : BaseDialogFragment() {
override fun registerListener(holder: ItemViewHolder) {
holder.itemView.apply {
onClick {
ThemeConfig.applyConfig(context, ThemeConfig.configList[holder.layoutPosition])
}
iv_share.onClick {
share(holder.layoutPosition)
}

@ -21,7 +21,6 @@ import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.BookHelp
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.ItemTouchCallback
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.*
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.widget.SelectActionBar
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.text.AutoCompleteTextView
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.SimpleRecyclerAdapter
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.theme.backgroundColor
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 org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*

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

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

@ -20,7 +20,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.RssSource
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.*
import io.legado.app.lib.theme.ATH
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.widget.SelectActionBar
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.text.AutoCompleteTextView
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.SimpleRecyclerAdapter
import io.legado.app.data.entities.RssSource
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.theme.backgroundColor
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 org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*

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

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

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