主题导入导出

pull/366/head
gedoor 4 years ago
parent f31870819e
commit fb860c2349
  1. 20
      app/src/main/java/io/legado/app/help/ThemeConfig.kt
  2. 11
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  3. 21
      app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt
  4. 11
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  5. 10
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  6. 10
      app/src/main/res/menu/theme_list.xml

@ -40,7 +40,13 @@ object ThemeConfig {
} }
} }
fun addConfig(newConfig: Config) { fun addConfig(json: String) {
GSON.fromJsonObject<Config>(json)?.let {
addConfig(it)
}
}
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
@ -125,12 +131,12 @@ object ThemeConfig {
} }
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
) )
} }

@ -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
@ -82,8 +76,7 @@ class BookSourceEditActivity :
} }
R.id.menu_copy_source -> getSource().let { source -> R.id.menu_copy_source -> getSource().let { source ->
GSON.toJson(source)?.let { sourceStr -> GSON.toJson(source)?.let { sourceStr ->
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager sendToClip(sourceStr)
clipboard?.setPrimaryClip(ClipData.newPlainText(null, sourceStr))
} }
} }
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) }

@ -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,25 @@ class ThemeListDialog : BaseDialogFragment() {
recycler_view.adapter = adapter recycler_view.adapter = adapter
} }
private fun initMenu() {
tool_bar.setOnMenuItemClickListener(this)
}
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)
}
}
}
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 {

@ -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
@ -99,8 +93,7 @@ class RssSourceEditActivity :
} }
R.id.menu_copy_source -> { R.id.menu_copy_source -> {
GSON.toJson(getRssSource())?.let { sourceStr -> GSON.toJson(getRssSource())?.let { sourceStr ->
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager sendToClip(sourceStr)
clipboard?.setPrimaryClip(ClipData.newPlainText(null, sourceStr))
} }
} }
R.id.menu_qr_code_camera -> startActivityForResult<QrCodeActivity>(qrRequestCode) R.id.menu_qr_code_camera -> startActivityForResult<QrCodeActivity>(qrRequestCode)

@ -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