diff --git a/app/src/main/assets/themeConfig.json b/app/src/main/assets/themeConfig.json index d785fd22e..a8826cf98 100644 --- a/app/src/main/assets/themeConfig.json +++ b/app/src/main/assets/themeConfig.json @@ -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", diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index a96db68fb..4fac6f22e 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/help/CrashHandler.kt b/app/src/main/java/io/legado/app/help/CrashHandler.kt index 223d8f29e..e842707d3 100644 --- a/app/src/main/java/io/legado/app/help/CrashHandler.kt +++ b/app/src/main/java/io/legado/app/help/CrashHandler.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index 6a2402485..412b6b8bf 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -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(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 ) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 7efc5a723..b52688846 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index ab37c5fe1..f23a2008c 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index 4917ea6cb..84e070259 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index b3fb5674d..0782c7c39 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 7a83ab140..bee66bcc6 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 4603a0d33..c0bed1512 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -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.* diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 3537fade5..66333c901 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -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 { //设置背景防止切换背景时文字重叠 diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 457a2b0ba..57421991d 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -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(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) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 81f3d22f0..7e1f70089 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index c7139fd01..a7d58dba5 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -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.* diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index afacfa0a2..a5177f443 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -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.* diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index 16d6d68b9..87cb180dd 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 3c33d008b..1f65877f8 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -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.* diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt index a62c62ac6..bcb29e87d 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt @@ -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.* diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index bd070639a..34b795a2b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -1,9 +1,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(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) } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index eb9c4e034..88a9a78dd 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -1,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(json) - } + context.getClipText()?.let { json -> + source = GSON.fromJsonObject(json) } source }.onError { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index b53c31b50..05885d183 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -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.* diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index 5693af3d4..2652503b3 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -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.* diff --git a/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/HeaderAdapterDataObserver.kt similarity index 93% rename from app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt rename to app/src/main/java/io/legado/app/ui/widget/recycler/HeaderAdapterDataObserver.kt index 1aeddeb95..f8e2a0c8c 100644 --- a/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/HeaderAdapterDataObserver.kt @@ -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() { diff --git a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt similarity index 99% rename from app/src/main/java/io/legado/app/help/ItemTouchCallback.kt rename to app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt index 9c1a0bbf2..b015a0086 100644 --- a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt @@ -1,4 +1,4 @@ -package io.legado.app.help +package io.legado.app.ui.widget.recycler import androidx.recyclerview.widget.GridLayoutManager diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt index 0df53aba7..0af559c45 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt @@ -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) 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 272c8d02d..489f5d508 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -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 +} + /** * 系统是否暗色主题 */ diff --git a/app/src/main/res/menu/theme_list.xml b/app/src/main/res/menu/theme_list.xml new file mode 100644 index 000000000..bd7f6194d --- /dev/null +++ b/app/src/main/res/menu/theme_list.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file