From a7793f1a342db2b24fb961dc7d19c61a2461b391 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Dec 2019 09:40:22 +0800 Subject: [PATCH 01/26] up --- .../app/ui/changecover/ChangeCoverDialog.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt new file mode 100644 index 000000000..ad94edb17 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -0,0 +1,18 @@ +package io.legado.app.ui.changecover + +import android.util.DisplayMetrics +import androidx.fragment.app.DialogFragment + + +class ChangeCoverDialog : DialogFragment() { + + + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.windowManager?.defaultDisplay?.getMetrics(dm) + dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt()) + } + + +} \ No newline at end of file From e6776a4c2a604c02a09527a8fc38373116a5f317 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Dec 2019 09:44:27 +0800 Subject: [PATCH 02/26] up --- .../app/ui/changecover/ChangeCoverDialog.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index ad94edb17..4a283e463 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -1,11 +1,18 @@ package io.legado.app.ui.changecover +import android.os.Bundle import android.util.DisplayMetrics +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import androidx.fragment.app.DialogFragment +import io.legado.app.R +import io.legado.app.utils.getViewModel class ChangeCoverDialog : DialogFragment() { + private lateinit var viewModel: ChangeCoverViewModel override fun onStart() { super.onStart() @@ -14,5 +21,14 @@ class ChangeCoverDialog : DialogFragment() { dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt()) } + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + viewModel = getViewModel(ChangeCoverViewModel::class.java) + return inflater.inflate(R.layout.dialog_change_source, container) + } + } \ No newline at end of file From 182e1fd11588843fe3ca20c7811d49420016fd89 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Dec 2019 09:44:46 +0800 Subject: [PATCH 03/26] up --- .../io/legado/app/ui/changecover/ChangeCoverViewModel.kt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt new file mode 100644 index 000000000..efb0212f9 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -0,0 +1,9 @@ +package io.legado.app.ui.changecover + +import android.app.Application +import io.legado.app.base.BaseViewModel + +class ChangeCoverViewModel(application: Application) : BaseViewModel(application) { + + +} \ No newline at end of file From 997b9a994a121f2e71bae42873d29b2324b6f45e Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Dec 2019 15:32:43 +0800 Subject: [PATCH 04/26] up --- .../legado/app/ui/changecover/CoverAdapter.kt | 16 ++++++++ app/src/main/res/layout/item_cover.xml | 40 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt create mode 100644 app/src/main/res/layout/item_cover.xml diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt new file mode 100644 index 000000000..93dc6252b --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -0,0 +1,16 @@ +package io.legado.app.ui.changecover + +import android.content.Context +import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.data.entities.Book + + +class CoverAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_cover) { + + override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { + + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/item_cover.xml b/app/src/main/res/layout/item_cover.xml new file mode 100644 index 000000000..018b5f2f8 --- /dev/null +++ b/app/src/main/res/layout/item_cover.xml @@ -0,0 +1,40 @@ + + + + + + + + \ No newline at end of file From 592b25d7deae7b2cf0b053b3f4e3efca34ec71d3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Dec 2019 15:57:03 +0800 Subject: [PATCH 05/26] up --- .../legado/app/ui/changecover/CoverAdapter.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt index 93dc6252b..408acbeb4 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -4,13 +4,22 @@ import android.content.Context import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter -import io.legado.app.data.entities.Book +import io.legado.app.data.entities.SearchBook +import io.legado.app.help.ImageLoader +import kotlinx.android.synthetic.main.item_cover.view.* +class CoverAdapter(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_cover) { -class CoverAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_cover) { - - override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { - + override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList) { + with(holder.itemView) { + item.coverUrl?.let { + ImageLoader.load(context, it) + .centerCrop() + .into(iv_cover) + } + tv_source.text = item.originName + } } } \ No newline at end of file From ef9310fd88a27cb1f24efbd7acad17c2623b11ce Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Dec 2019 16:00:16 +0800 Subject: [PATCH 06/26] up --- .../main/java/io/legado/app/help/storage/Restore.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 0b8e66db5..7d4c8191d 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -149,7 +149,9 @@ object Restore { context.toast("成功导入书籍${books.size}") } } catch (e: Exception) { - context.toast("导入书籍失败\n${e.localizedMessage}") + withContext(Main) { + context.toast("导入书籍失败\n${e.localizedMessage}") + } } try {// Book source @@ -168,7 +170,9 @@ object Restore { context.toast("成功导入书源${bookSources.size}") } } catch (e: Exception) { - context.toast("导入源失败\n${e.localizedMessage}") + withContext(Main) { + context.toast("导入源失败\n${e.localizedMessage}") + } } try {// Replace rules @@ -196,7 +200,9 @@ object Restore { context.toast("成功导入替换规则${replaceRules.size}") } } catch (e: Exception) { - context.toast("导入替换规则失败\n${e.localizedMessage}") + withContext(Main) { + context.toast("导入替换规则失败\n${e.localizedMessage}") + } } } } From acc4449bc80b5ff868af99f711dee3430be10144 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Dec 2019 17:17:54 +0800 Subject: [PATCH 07/26] up --- .../java/io/legado/app/ui/changecover/ChangeCoverDialog.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index 4a283e463..03db768f4 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -6,8 +6,10 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment +import androidx.recyclerview.widget.GridLayoutManager import io.legado.app.R import io.legado.app.utils.getViewModel +import kotlinx.android.synthetic.main.dialog_change_source.* class ChangeCoverDialog : DialogFragment() { @@ -30,5 +32,10 @@ class ChangeCoverDialog : DialogFragment() { return inflater.inflate(R.layout.dialog_change_source, container) } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + tool_bar.setTitle(R.string.change_cover_source) + recycler_view.layoutManager = GridLayoutManager(requireContext(), 3) + } } \ No newline at end of file From 3019e5510acafbfa48b20b4231e0f0bc3211a79f Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 09:59:59 +0800 Subject: [PATCH 08/26] up --- .../java/io/legado/app/ui/changecover/ChangeCoverDialog.kt | 3 +++ build.gradle | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index 03db768f4..a0488160f 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -15,6 +15,7 @@ import kotlinx.android.synthetic.main.dialog_change_source.* class ChangeCoverDialog : DialogFragment() { private lateinit var viewModel: ChangeCoverViewModel + private lateinit var adapter: CoverAdapter override fun onStart() { super.onStart() @@ -36,6 +37,8 @@ class ChangeCoverDialog : DialogFragment() { super.onViewCreated(view, savedInstanceState) tool_bar.setTitle(R.string.change_cover_source) recycler_view.layoutManager = GridLayoutManager(requireContext(), 3) + adapter = CoverAdapter(requireContext()) + recycler_view.adapter = adapter } } \ No newline at end of file diff --git a/build.gradle b/build.gradle index cb1547a01..be4632b0d 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { maven { url 'https://plugins.gradle.org/m2/' } } dependencies { - classpath 'com.android.tools.build:gradle:3.5.2' + classpath 'com.android.tools.build:gradle:3.5.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.3' classpath 'com.google.gms:google-services:4.3.3' From 24f473286763fe517fe34b50ff5838f9e68cf81d Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 10:10:39 +0800 Subject: [PATCH 09/26] up --- .../legado/app/ui/book/info/edit/BookInfoEditActivity.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 9b44da8bc..bd851d77f 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -8,8 +8,10 @@ import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book +import io.legado.app.ui.changecover.ChangeCoverDialog import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_book_info_edit.* +import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.toast class BookInfoEditActivity : @@ -24,6 +26,7 @@ class BookInfoEditActivity : viewModel.loadBook(it) } } + initEvent() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -38,6 +41,12 @@ class BookInfoEditActivity : return super.onCompatOptionsItemSelected(item) } + private fun initEvent() { + tv_change_cover.onClick { + ChangeCoverDialog().show(supportFragmentManager, "changeCoverDialog") + } + } + private fun upView(book: Book) { tie_book_name.setText(book.name) tie_book_author.setText(book.author) From 92d40f733677358d7176502c52075ba15a4daa19 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 10:18:10 +0800 Subject: [PATCH 10/26] up --- .../ui/book/info/edit/BookInfoEditActivity.kt | 4 +++- .../app/ui/changecover/ChangeCoverDialog.kt | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index bd851d77f..9ae95e166 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -43,7 +43,9 @@ class BookInfoEditActivity : private fun initEvent() { tv_change_cover.onClick { - ChangeCoverDialog().show(supportFragmentManager, "changeCoverDialog") + viewModel.bookData.value?.let { + ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) + } } } diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index a0488160f..325e49b8c 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -6,6 +6,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.GridLayoutManager import io.legado.app.R import io.legado.app.utils.getViewModel @@ -14,6 +15,21 @@ import kotlinx.android.synthetic.main.dialog_change_source.* class ChangeCoverDialog : DialogFragment() { + companion object { + const val tag = "changeCoverDialog" + + fun show(manager: FragmentManager, name: String, author: String) { + val fragment = (manager.findFragmentByTag(tag) as? ChangeCoverDialog) + ?: ChangeCoverDialog().apply { + val bundle = Bundle() + bundle.putString("name", name) + bundle.putString("author", author) + arguments = bundle + } + fragment.show(manager, tag) + } + } + private lateinit var viewModel: ChangeCoverViewModel private lateinit var adapter: CoverAdapter From e3eb5195c249e528084c5c7efd90ca0d5f6a578e Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 10:22:19 +0800 Subject: [PATCH 11/26] up --- .../app/ui/book/info/edit/BookInfoEditActivity.kt | 3 ++- .../legado/app/ui/changecover/ChangeCoverDialog.kt | 13 +++++++++++++ .../app/ui/changecover/ChangeCoverViewModel.kt | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 9ae95e166..ecb8c9592 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -15,7 +15,8 @@ import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.toast class BookInfoEditActivity : - VMBaseActivity(R.layout.activity_book_info_edit) { + VMBaseActivity(R.layout.activity_book_info_edit), + ChangeCoverDialog.CallBack { override val viewModel: BookInfoEditViewModel get() = getViewModel(BookInfoEditViewModel::class.java) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index 325e49b8c..0deebf906 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -30,6 +30,7 @@ class ChangeCoverDialog : DialogFragment() { } } + private var callBack: CallBack? = null private lateinit var viewModel: ChangeCoverViewModel private lateinit var adapter: CoverAdapter @@ -51,10 +52,22 @@ class ChangeCoverDialog : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + callBack = activity as? CallBack tool_bar.setTitle(R.string.change_cover_source) + arguments?.let { bundle -> + bundle.getString("name")?.let { + viewModel.name = it + } + bundle.getString("author")?.let { + viewModel.author = it + } + } recycler_view.layoutManager = GridLayoutManager(requireContext(), 3) adapter = CoverAdapter(requireContext()) recycler_view.adapter = adapter } + interface CallBack { + + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index efb0212f9..5f12c56b2 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -5,5 +5,8 @@ import io.legado.app.base.BaseViewModel class ChangeCoverViewModel(application: Application) : BaseViewModel(application) { + var name: String = "" + var author: String = "" + } \ No newline at end of file From f929aa9833bbc1adc1876551cb7824bc426f0ff0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 10:34:31 +0800 Subject: [PATCH 12/26] up --- .../io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt | 4 ++++ .../java/io/legado/app/ui/changecover/ChangeCoverDialog.kt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index ecb8c9592..0361c462d 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -74,4 +74,8 @@ class BookInfoEditActivity : }) } } + + override fun coverChangeTo(coverUrl: String) { + + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index 0deebf906..f566cbbbb 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -68,6 +68,6 @@ class ChangeCoverDialog : DialogFragment() { } interface CallBack { - + fun coverChangeTo(coverUrl: String) } } \ No newline at end of file From 3651422291bb1036610f794ccf52de5960b5f1bd Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 11:49:40 +0800 Subject: [PATCH 13/26] up --- .../ui/book/info/edit/BookInfoEditActivity.kt | 27 ++++++++++++------- .../book/info/edit/BookInfoEditViewModel.kt | 10 +++---- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 0361c462d..297951b40 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -8,11 +8,11 @@ import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book +import io.legado.app.help.ImageLoader import io.legado.app.ui.changecover.ChangeCoverDialog import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_book_info_edit.* import org.jetbrains.anko.sdk27.listeners.onClick -import org.jetbrains.anko.toast class BookInfoEditActivity : VMBaseActivity(R.layout.activity_book_info_edit), @@ -55,6 +55,15 @@ class BookInfoEditActivity : tie_book_author.setText(book.author) tie_cover_url.setText(book.getDisplayCover()) tie_book_intro.setText(book.getDisplayIntro()) + upCover() + } + + private fun upCover() { + viewModel.book?.getDisplayCover()?.let { + ImageLoader.load(this, it) + .centerCrop() + .into(iv_cover) + } } private fun saveData() { @@ -64,18 +73,16 @@ class BookInfoEditActivity : val customCoverUrl = tie_cover_url.text?.toString() book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl book.customIntro = tie_book_intro.text?.toString() - viewModel.saveBook(book, - success = { - setResult(Activity.RESULT_OK) - finish() - }, - error = { - toast(it) - }) + viewModel.saveBook(book) { + setResult(Activity.RESULT_OK) + finish() + } } } override fun coverChangeTo(coverUrl: String) { - + viewModel.book?.customCoverUrl = coverUrl + tie_cover_url.setText(coverUrl) + upCover() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt index a947719cd..66602c1d7 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt @@ -7,25 +7,23 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book class BookInfoEditViewModel(application: Application) : BaseViewModel(application) { - + var book: Book? = null val bookData = MutableLiveData() - fun loadBook(bookUrl: String) { execute { - App.db.bookDao().getBook(bookUrl)?.let { + book = App.db.bookDao().getBook(bookUrl) + book?.let { bookData.postValue(it) } } } - fun saveBook(book: Book, success: (() -> Unit)?, error: ((msg: String) -> Unit)?) { + fun saveBook(book: Book, success: (() -> Unit)?) { execute { App.db.bookDao().insert(book) }.onSuccess { success?.invoke() - }.onError { - error?.invoke(it.localizedMessage) } } } \ No newline at end of file From f41663e53a1fb68e995eddd80a2730ba50a09788 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 11:50:06 +0800 Subject: [PATCH 14/26] up --- .../io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 297951b40..a4e420af1 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -67,7 +67,7 @@ class BookInfoEditActivity : } private fun saveData() { - viewModel.bookData.value?.let { book -> + viewModel.book?.let { book -> book.name = tie_book_name.text?.toString() ?: "" book.author = tie_book_author.text?.toString() ?: "" val customCoverUrl = tie_cover_url.text?.toString() From cbe09c1f0b3a82681c0427267ae5ebc1c20763e7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 16:41:46 +0800 Subject: [PATCH 15/26] up --- app/src/main/java/io/legado/app/help/CrashHandler.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 a8fe0d05f..9a5c7131a 100644 --- a/app/src/main/java/io/legado/app/help/CrashHandler.kt +++ b/app/src/main/java/io/legado/app/help/CrashHandler.kt @@ -103,7 +103,9 @@ class CrashHandler : Thread.UncaughtExceptionHandler { kotlin.runCatching { for (field in fields) { field.isAccessible = true - paramsMap[field.name] = field.get(null).toString() + field.get(null)?.toString()?.let { + paramsMap[field.name] = it + } } } } From 341ddaaf62b1fdfba51c7f75ecd01702edaca3c1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 16:45:51 +0800 Subject: [PATCH 16/26] up --- app/src/main/java/io/legado/app/help/FileHelp.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/FileHelp.kt b/app/src/main/java/io/legado/app/help/FileHelp.kt index a208a74a2..5a7678563 100644 --- a/app/src/main/java/io/legado/app/help/FileHelp.kt +++ b/app/src/main/java/io/legado/app/help/FileHelp.kt @@ -47,7 +47,7 @@ object FileHelp { if (file.isDirectory) { val files = file.listFiles() - for (subFile in files) { + files?.forEach { subFile -> val path = subFile.path deleteFile(path) } From f4ff991e1d3f0da665e37f1fcb331924453d1523 Mon Sep 17 00:00:00 2001 From: ca1e Date: Sat, 7 Dec 2019 14:44:06 +0800 Subject: [PATCH 17/26] commit clean caches --- app/src/main/java/io/legado/app/constant/PreferKey.kt | 3 +++ .../java/io/legado/app/ui/config/ConfigFragment.kt | 10 ++++++++-- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_config.xml | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 24ac981e9..446efc0bf 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -10,4 +10,7 @@ object PreferKey { const val nextKey = "nextKeyCode" const val showRss = "showRss" const val bookshelfLayout = "bookshelfLayout" + const val recordLog = "recordLog" + const val processText = "process_text" + const val cleanCache = "cleanCache" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt index cee764420..a4a7bd62d 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt @@ -12,6 +12,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.BookHelp +import io.legado.app.help.FileHelp import io.legado.app.lib.theme.ATH import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.ui.filechooser.FileChooserDialog @@ -59,6 +60,11 @@ class ConfigFragment : PreferenceFragmentCompat(), mode = FileChooserDialog.DIRECTORY, initPath = getPreferenceString(PreferKey.downloadPath) ) + PreferKey.cleanCache -> { + LogUtils.d("xxx","cleancaches") + FileHelp.deleteFile(getPreferenceString(PreferKey.downloadPath)) + toast("成功清理缓存") + } } return super.onPreferenceTreeClick(preference) } @@ -69,8 +75,8 @@ class ConfigFragment : PreferenceFragmentCompat(), BookHelp.upDownloadPath() findPreference(key)?.summary = getPreferenceString(key) } - "recordLog" -> LogUtils.upLevel() - "process_text" -> sharedPreferences?.let { + PreferKey.recordLog -> LogUtils.upLevel() + PreferKey.processText -> sharedPreferences?.let { setProcessTextEnable(it.getBoolean("process_text", true)) } PreferKey.showRss -> postEvent(PreferKey.showRss, PreferKey.showRss) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9e6327377..f4786808e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -313,6 +313,7 @@ 替换范围,选填书名或者源名 分组 内容缓存路径 + 清理缓存 系统文件选择器 新版本 下载更新 diff --git a/app/src/main/res/xml/pref_config.xml b/app/src/main/res/xml/pref_config.xml index 3e9a873b6..bc421509b 100644 --- a/app/src/main/res/xml/pref_config.xml +++ b/app/src/main/res/xml/pref_config.xml @@ -39,4 +39,8 @@ android:key="recordLog" android:title="记录日志" app:iconSpaceReserved="false" /> + \ No newline at end of file From 6bf160ed816b32b3a71c83a5014eab8b9f8281de Mon Sep 17 00:00:00 2001 From: ca1e Date: Sat, 7 Dec 2019 20:03:17 +0800 Subject: [PATCH 18/26] =?UTF-8?q?commit=20=E8=B0=83=E6=95=B4=E9=85=8D?= =?UTF-8?q?=E8=89=B2=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/readConfig.json | 14 +++++++------- app/src/main/res/xml/about.xml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/assets/readConfig.json b/app/src/main/assets/readConfig.json index 21cea9f69..ee546dc37 100644 --- a/app/src/main/assets/readConfig.json +++ b/app/src/main/assets/readConfig.json @@ -4,7 +4,7 @@ "bgType": 1, "darkStatusIcon": true, "textColor": "#5E432E", - "textSize": 22, + "textSize": 24, "letterSpacing": 0, "lineSpacingExtra": 10, "lineSpacingMultiplier": 1.2, @@ -14,11 +14,11 @@ "paddingBottom": 0 }, { - "bgStr": "新羊皮纸.jpg", - "bgType": 1, + "bgStr": "#C6BAA1", + "bgType": 0, "darkStatusIcon": true, "textColor": "#5E432E", - "textSize": 22, + "textSize": 24, "letterSpacing": 0, "lineSpacingExtra": 10, "lineSpacingMultiplier": 1.2, @@ -32,7 +32,7 @@ "bgType": 0, "darkStatusIcon": false, "textColor": "#FFFFFF", - "textSize": 22, + "textSize": 24, "letterSpacing": 0, "lineSpacingExtra": 10, "lineSpacingMultiplier": 1.2, @@ -46,7 +46,7 @@ "bgType": 1, "darkStatusIcon": false, "textColor": "#adadad", - "textSize": 22, + "textSize": 24, "letterSpacing": 0, "lineSpacingExtra": 10, "lineSpacingMultiplier": 1.2, @@ -60,7 +60,7 @@ "bgType": 0, "darkStatusIcon": false, "textColor": "#adadad", - "textSize": 22, + "textSize": 24, "letterSpacing": 0, "lineSpacingExtra": 10, "lineSpacingMultiplier": 1.2, diff --git a/app/src/main/res/xml/about.xml b/app/src/main/res/xml/about.xml index 0391f9d86..9bf6b7b71 100644 --- a/app/src/main/res/xml/about.xml +++ b/app/src/main/res/xml/about.xml @@ -5,7 +5,7 @@ Date: Tue, 10 Dec 2019 00:15:09 +0800 Subject: [PATCH 19/26] commit mod webServer --- app/build.gradle | 2 +- app/src/main/assets/updateLog.md | 7 +- app/src/main/java/io/legado/app/App.kt | 6 +- .../java/io/legado/app/help/IntentHelp.kt | 11 +++ .../legado/app/help/permission/Permissions.kt | 7 +- .../java/io/legado/app/service/WebService.kt | 1 - .../io/legado/app/ui/config/ConfigActivity.kt | 2 +- .../app/ui/config/ThemeConfigFragment.kt | 14 ++-- .../app/ui/config/WebDavConfigFragment.kt | 77 +++++++++++-------- .../io/legado/app/ui/main/my/MyFragment.kt | 17 +++- .../io/legado/app/utils/ContextExtensions.kt | 4 +- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/pref_config_theme.xml | 4 +- 13 files changed, 90 insertions(+), 64 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 43c822e3b..c2bc779e2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ static def releaseTime() { } def name = "legado" -def version = "0." + releaseTime() +def version = "3." + releaseTime() def gitCommits = Integer.parseInt('git rev-list --count HEAD'.execute([], project.rootDir).text.trim()) android { diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index e08399579..94535e6d4 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -1,9 +1,14 @@ ## 更新日志 * 旧版数据导入教程: -* 先在旧版阅读2.19.xxxxxx进行备份,再在新版阅读3.0的【我的】中,点击【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 +* 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 * 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。 +**2019/12/09** +* [add]其他设置->清理缓存 +* [mod]调整深色模式配色,预适配Android10 +* [mod]启用web服务 + **2019/12/03** * from Celeter1、调试log修改 2、增加书源字符串分享(RSS未包含) 3、增加导出选中的源(包含书源、RSS、替换规则) * 一键缓存 diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index a9fbf72d4..37dd40e25 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -70,13 +70,13 @@ class App : Application() { if (isNightTheme) { ThemeStore.editTheme(this) .primaryColor( - getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_blue_grey_600)) + getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900)) ) .accentColor( getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) ) .backgroundColor( - getPrefInt("colorBackgroundNight", getCompatColor(R.color.md_grey_800)) + getPrefInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000)) ) .apply() } else { @@ -101,7 +101,6 @@ class App : Application() { initNightTheme() } - private fun initNightTheme() { val targetMode = if (isNightTheme) { AppCompatDelegate.MODE_NIGHT_YES @@ -111,7 +110,6 @@ class App : Application() { AppCompatDelegate.setDefaultNightMode(targetMode) } - /** * 创建通知ID */ diff --git a/app/src/main/java/io/legado/app/help/IntentHelp.kt b/app/src/main/java/io/legado/app/help/IntentHelp.kt index 815867694..d02e13392 100644 --- a/app/src/main/java/io/legado/app/help/IntentHelp.kt +++ b/app/src/main/java/io/legado/app/help/IntentHelp.kt @@ -21,6 +21,17 @@ object IntentHelp { } } + fun toInstallUnknown(context: Context) { + try { + val intent = Intent() + intent.action = "android.settings.MANAGE_UNKNOWN_APP_SOURCES" + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + context.startActivity(intent) + } catch (ignored: Exception) { + context.toast("无法打开设置") + } + } + inline fun servicePendingIntent(context: Context, action: String): PendingIntent? { return PendingIntent.getService( context, diff --git a/app/src/main/java/io/legado/app/help/permission/Permissions.kt b/app/src/main/java/io/legado/app/help/permission/Permissions.kt index e1c0893e3..236691f7f 100644 --- a/app/src/main/java/io/legado/app/help/permission/Permissions.kt +++ b/app/src/main/java/io/legado/app/help/permission/Permissions.kt @@ -36,10 +36,12 @@ object Permissions { const val WRITE_EXTERNAL_STORAGE = "android.permission.WRITE_EXTERNAL_STORAGE" object Group { - val CALENDAR = arrayOf(READ_CALENDAR, WRITE_CALENDAR) + val STORAGE = arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE) val CAMERA = arrayOf(Permissions.CAMERA) + val CALENDAR = arrayOf(READ_CALENDAR, WRITE_CALENDAR) + val CONTACTS = arrayOf(READ_CONTACTS, WRITE_CONTACTS, GET_ACCOUNTS) val LOCATION = arrayOf(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION) @@ -65,8 +67,5 @@ object Permissions { RECEIVE_WAP_PUSH, RECEIVE_MMS ) - - val STORAGE = arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE) } - } diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 012623865..60ce40004 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -34,7 +34,6 @@ class WebService : BaseService() { context.startService(intent) } } - } private var httpServer: HttpServer? = null diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt index 52d197a08..a926a8ae2 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt @@ -19,7 +19,7 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) when (viewModel.configType) { ConfigViewModel.TYPE_CONFIG -> { - title_bar.title = getString(R.string.setting) + title_bar.title = getString(R.string.other_setting) val fTag = "configFragment" var configFragment = supportFragmentManager.findFragmentByTag(fTag) if (configFragment == null) configFragment = ConfigFragment() diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 642a57578..a47fb4360 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -100,18 +100,14 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar .setMessage("是否确认恢复?") .setPositiveButton(R.string.ok) { _, _ -> preferenceManager.sharedPreferences.edit() + // light mode .putInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) .putInt("colorAccent", getCompatColor(R.color.md_pink_800)) .putInt("colorBackground", getCompatColor(R.color.md_grey_100)) - .putInt( - "colorPrimaryNight", - getCompatColor(R.color.md_blue_grey_600) - ) - .putInt( - "colorAccentNight", - getCompatColor(R.color.md_deep_orange_800) - ) - .putInt("colorBackgroundNight", getCompatColor(R.color.md_grey_800)) + // dark mode + .putInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900)) + .putInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) + .putInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000)) .apply() App.INSTANCE.applyTheme() recreateActivities() diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index a29c34057..1e4d34a73 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -1,9 +1,8 @@ package io.legado.app.ui.config -import android.content.Intent +import android.content.Context import android.os.Build import android.os.Bundle -import android.provider.Settings import android.text.InputType import android.view.View import androidx.preference.EditTextPreference @@ -11,6 +10,7 @@ import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R +import io.legado.app.help.IntentHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup @@ -21,12 +21,22 @@ import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.LogUtils import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + fun bindPreferenceSummaryToValue(preference: Preference?) { + preference?.apply { + onPreferenceChangeListener = this@WebDavConfigFragment + onPreferenceChange( + this, + context.getPrefString(key) + ) + } + } addPreferencesFromResource(R.xml.pref_config_web_dav) findPreference("web_dav_url")?.let { it.setOnBindEditTextListener { editText -> @@ -82,47 +92,49 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference return true } - private fun bindPreferenceSummaryToValue(preference: Preference?) { - preference?.apply { - onPreferenceChangeListener = this@WebDavConfigFragment - onPreferenceChange( - this, - context.getPrefString(key) - ) - } - } - override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - "web_dav_backup" -> Backup.backup() - "web_dav_restore" -> WebDavHelp.showRestoreDialog(requireContext()) - "import_old" -> importOld() + "web_dav_backup" -> PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { Backup.backup() } + .request() + "web_dav_restore" -> PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + WebDavHelp.showRestoreDialog(requireContext()) + } + .request() + "import_old" -> needInstallApps { importOld() } } return super.onPreferenceTreeClick(preference) } - private fun importOld() { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { - val haveInstallPermission = context!!.packageManager.canRequestPackageInstalls() - if (haveInstallPermission) { - startImport() - } else { //没有安装外部来源应用的权限 - alert(title = "开启权限提示") { - message = "需要打开「安装外部来源应用」权限才能导入旧版数据,请去设置中开启" - yesButton { - val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES) - startActivityForResult(intent, 666) - } - noButton { - } - }.show().applyTint() + private fun needInstallApps(callback: () -> Unit) { + + fun canRequestPackageInstalls() :Boolean { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { + return requireContext().packageManager.canRequestPackageInstalls() } + return true + } + if (!canRequestPackageInstalls()) { + alert(title = "开启权限提示") { + message = "需要打开「安装外部来源应用」权限才能导入旧版数据,请去设置中开启" + yesButton { + IntentHelp.toInstallUnknown(requireContext()) + } + noButton { + } + }.show().applyTint() } else { - startImport() + LogUtils.d("xxx","import old") + callback() } } - private fun startImport() { + private fun importOld() { alert(title = "导入") { message = "是否导入旧版本数据" yesButton { @@ -138,5 +150,4 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference } }.show().applyTint() } - } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index b2747f97e..b84538aa1 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -16,6 +16,7 @@ import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH +import io.legado.app.service.WebService import io.legado.app.ui.about.AboutActivity import io.legado.app.ui.about.DonateActivity import io.legado.app.ui.book.source.manage.BookSourceActivity @@ -23,7 +24,9 @@ import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.utils.LogUtils +import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.startActivity +import io.legado.app.utils.toast import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity @@ -79,12 +82,18 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { super.onPause() } - override fun onSharedPreferenceChanged( - sharedPreferences: SharedPreferences?, - key: String? - ) { + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { "isNightTheme" -> App.INSTANCE.applyDayNight() + "webService" -> { + if (requireContext().getPrefBoolean("webService")) { + WebService.start(requireContext()) + toast("正在启动服务\n具体信息查看通知栏") + }else{ + WebService.stop(requireContext()) + toast("服务已停止") + } + } "recordLog" -> LogUtils.upLevel() "downloadPath" -> BookHelp.upDownloadPath() } 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 c51be0b80..f9541edaf 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -7,10 +7,8 @@ import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.core.content.edit -import org.jetbrains.anko.connectivityManager import org.jetbrains.anko.defaultSharedPreferences - -fun Context.isOnline() = connectivityManager.activeNetworkInfo?.isConnected == true +import java.util.function.BinaryOperator fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4786808e..123967b0a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -202,7 +202,7 @@ 替换规则名称 选择操作 全选 - 暗色主题 + 深色模式 启动页 开始下载 取消下载 diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 607359962..e96124472 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -57,7 +57,7 @@ app:iconSpaceReserved="false"> Date: Tue, 10 Dec 2019 00:24:10 +0800 Subject: [PATCH 20/26] commit opt import --- app/src/main/java/io/legado/app/utils/ContextExtensions.kt | 1 - 1 file changed, 1 deletion(-) 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 f9541edaf..9642814de 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -8,7 +8,6 @@ import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.core.content.edit import org.jetbrains.anko.defaultSharedPreferences -import java.util.function.BinaryOperator fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) From 4a1257833953d5ab484c5e06e259c57ae8fee3e8 Mon Sep 17 00:00:00 2001 From: ca1e Date: Wed, 11 Dec 2019 22:28:47 +0800 Subject: [PATCH 21/26] commit backup restore --- .../java/io/legado/app/help/storage/Backup.kt | 30 +++++++--------- .../io/legado/app/help/storage/Restore.kt | 13 ++++--- .../io/legado/app/help/storage/WebDavHelp.kt | 7 ++-- .../io/legado/app/ui/config/ConfigFragment.kt | 6 ++-- .../app/ui/config/WebDavConfigFragment.kt | 35 +++++++++---------- app/src/main/res/values/arrays.xml | 2 +- app/src/main/res/xml/pref_config_web_dav.xml | 28 ++++++++------- 7 files changed, 61 insertions(+), 60 deletions(-) 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 2f0b040a4..7062d1951 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 @@ -20,23 +20,26 @@ object Backup { } val legadoPath by lazy { - defaultPath + File.separator + "legadoBackUp" + FileUtils.getSdCardPath() + File.separator + "YueDu3.0" } val exportPath by lazy { legadoPath + File.separator + "Export" } + private fun pbackup(path :String = legadoPath){ + backupBookshelf(path) + backupBookSource(path) + backupRssSource(path) + backupReplaceRule(path) + backupReadConfig(path) + backupPreference(path) + WebDavHelp.backUpWebDav(path) + } + fun backup() { doAsync { - val path = legadoPath - backupBookshelf(path) - backupBookSource(path) - backupRssSource(path) - backupReplaceRule(path) - backupReadConfig(path) - backupPreference(path) - WebDavHelp.backUpWebDav(path) + pbackup() uiThread { App.INSTANCE.toast(R.string.backup_success) } @@ -45,14 +48,7 @@ object Backup { fun autoBackup() { doAsync { - val path = legadoPath - backupBookshelf(path) - backupBookSource(path) - backupRssSource(path) - backupReplaceRule(path) - backupReadConfig(path) - backupPreference(path) - WebDavHelp.backUpWebDav(path) + pbackup() } } diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 7d4c8191d..53b040f28 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -7,6 +7,7 @@ import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.Option import com.jayway.jsonpath.ParseContext import io.legado.app.App +import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookSource @@ -14,8 +15,6 @@ import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.RssSource import io.legado.app.help.FileHelp import io.legado.app.help.ReadBookConfig -import io.legado.app.help.storage.Backup.defaultPath -import io.legado.app.help.storage.Backup.legadoPath import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -37,7 +36,7 @@ object Restore { ) } - fun restore(path: String = legadoPath) { + fun restore(path: String = Backup.legadoPath) { doAsync { try { val file = FileHelp.getFile(path + File.separator + "bookshelf.json") @@ -99,14 +98,14 @@ object Restore { } edit.commit() } - uiThread { App.INSTANCE.toast("恢复完成") } + uiThread { App.INSTANCE.toast(R.string.restore_success) } } } fun importYueDuData(context: Context) { GlobalScope.launch(IO) { try {// 导入书架 - val shelfFile = FileHelp.getFile(defaultPath + File.separator + "myBookShelf.json") + val shelfFile = FileHelp.getFile(Backup.defaultPath + File.separator + "myBookShelf.json") val books = mutableListOf() val items: List> = jsonPath.parse(shelfFile.readText()).read("$") val existingBooks = App.db.bookDao().allBookUrls.toSet() @@ -156,7 +155,7 @@ object Restore { try {// Book source val sourceFile = - FileHelp.getFile(defaultPath + File.separator + "myBookSource.json") + FileHelp.getFile(Backup.defaultPath + File.separator + "myBookSource.json") val bookSources = mutableListOf() val items: List> = jsonPath.parse(sourceFile.readText()).read("$") for (item in items) { @@ -177,7 +176,7 @@ object Restore { try {// Replace rules val ruleFile = - FileHelp.getFile(defaultPath + File.separator + "myBookReplaceRule.json") + FileHelp.getFile(Backup.defaultPath + File.separator + "myBookReplaceRule.json") val replaceRules = mutableListOf() val items: List> = jsonPath.parse(ruleFile.readText()).read("$") val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet() diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 7d2022b5b..a4ac7fbcc 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -18,6 +18,9 @@ import kotlin.math.min object WebDavHelp { private val zipFilePath = FileHelp.getCachePath() + "/backup" + ".zip" + private val unzipFilesPath by lazy { + FileHelp.getCachePath() + } private fun getWebDavUrl(): String? { var url = App.INSTANCE.getPrefString("web_dav_url") @@ -73,8 +76,8 @@ object WebDavHelp { getWebDavUrl()?.let { val file = WebDav(it + "legado/" + name) file.downloadTo(zipFilePath, true) - ZipUtils.unzipFile(zipFilePath, Backup.legadoPath) - Restore.restore() + ZipUtils.unzipFile(zipFilePath, unzipFilesPath) + Restore.restore(unzipFilesPath) } } } diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt index a4a7bd62d..927804039 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt @@ -61,8 +61,10 @@ class ConfigFragment : PreferenceFragmentCompat(), initPath = getPreferenceString(PreferKey.downloadPath) ) PreferKey.cleanCache -> { - LogUtils.d("xxx","cleancaches") - FileHelp.deleteFile(getPreferenceString(PreferKey.downloadPath)) + getPreferenceString(PreferKey.downloadPath).let { + FileHelp.deleteFile(it) + FileHelp.getFolder(it) + } toast("成功清理缓存") } } diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 1e4d34a73..9eb761712 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.config -import android.content.Context import android.os.Build import android.os.Bundle import android.text.InputType @@ -106,7 +105,22 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference WebDavHelp.showRestoreDialog(requireContext()) } .request() - "import_old" -> needInstallApps { importOld() } + "import_old" -> needInstallApps { + alert(title = "导入") { + message = "是否导入旧版本数据" + yesButton { + PermissionsCompat.Builder(this@WebDavConfigFragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + Restore.importYueDuData(requireContext()) + } + .request() + } + noButton { + } + }.show().applyTint() + } } return super.onPreferenceTreeClick(preference) } @@ -133,21 +147,4 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference callback() } } - - private fun importOld() { - alert(title = "导入") { - message = "是否导入旧版本数据" - yesButton { - PermissionsCompat.Builder(this@WebDavConfigFragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - Restore.importYueDuData(requireContext()) - } - .request() - } - noButton { - } - }.show().applyTint() - } } \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 7534dcab1..8d6d53a10 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -40,7 +40,7 @@ @string/layout_grid3 @string/layout_grid4 @string/layout_grid5 - @string/layout_grid6 + diff --git a/app/src/main/res/xml/pref_config_web_dav.xml b/app/src/main/res/xml/pref_config_web_dav.xml index 51234ec1a..42733f458 100644 --- a/app/src/main/res/xml/pref_config_web_dav.xml +++ b/app/src/main/res/xml/pref_config_web_dav.xml @@ -20,19 +20,23 @@ android:summary="@string/web_dav_pw_s" app:iconSpaceReserved="false" /> - + - + - + + + + + \ No newline at end of file From e2c6975a29a7e3f1ba407e2512dca1d77707822c Mon Sep 17 00:00:00 2001 From: ca1e Date: Wed, 11 Dec 2019 22:30:24 +0800 Subject: [PATCH 22/26] commit revert comment --- app/src/main/res/values/arrays.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 8d6d53a10..7534dcab1 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -40,7 +40,7 @@ @string/layout_grid3 @string/layout_grid4 @string/layout_grid5 - + @string/layout_grid6 From d635edd8a88ee3db1ae3895afec0d5b83769dfb0 Mon Sep 17 00:00:00 2001 From: NPC-C83H Date: Thu, 12 Dec 2019 11:03:10 +0800 Subject: [PATCH 23/26] Update WebService.kt --- app/src/main/java/io/legado/app/service/WebService.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 60ce40004..b32e6d6bc 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -48,6 +48,12 @@ class WebService : BaseService() { override fun onDestroy() { super.onDestroy() isRun = false + if (httpServer?.isAlive == true) { + httpServer?.stop() + } + if (webSocketServer?.isAlive == true) { + webSocketServer?.stop() + } } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -112,4 +118,4 @@ class WebService : BaseService() { val notification = builder.build() startForeground(AppConst.notificationIdWeb, notification) } -} \ No newline at end of file +} From db800b9884182b81161824c3ca9fa4e501014023 Mon Sep 17 00:00:00 2001 From: ca1e Date: Thu, 12 Dec 2019 20:55:54 +0800 Subject: [PATCH 24/26] =?UTF-8?q?commit=20=E8=A1=A5=E5=85=85=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=8A=B6=E6=80=81=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 8 ++++++-- .../main/java/io/legado/app/utils/ContextExtensions.kt | 2 +- app/src/main/res/xml/pref_config_theme.xml | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 94535e6d4..a669fb6a6 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,13 +4,17 @@ * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 * 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。 +**2019/12/12** +* [fix]web服务停止问题 +* 默认显示沉浸式状态栏 + **2019/12/09** * [add]其他设置->清理缓存 * [mod]调整深色模式配色,预适配Android10 * [mod]启用web服务 **2019/12/03** -* from Celeter1、调试log修改 2、增加书源字符串分享(RSS未包含) 3、增加导出选中的源(包含书源、RSS、替换规则) +* [by Celeter]1、调试log修改 2、增加书源字符串分享(RSS未包含) 3、增加导出选中的源(包含书源、RSS、替换规则) * 一键缓存 * 修复bug @@ -20,4 +24,4 @@ * 音频添加速度调整 * 后台朗读,长按返回,或点击按钮 * 订阅可以隐藏 -* 优化老版本规则导入from Celeter \ No newline at end of file +* [by Celeter]优化老版本规则导入 \ No newline at end of file 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 9642814de..bbdd84e6e 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -64,4 +64,4 @@ val Context.isNightTheme: Boolean get() = getPrefBoolean("isNightTheme") val Context.isTransparentStatusBar: Boolean - get() = getPrefBoolean("transparentStatusBar") \ No newline at end of file + get() = getPrefBoolean("transparentStatusBar", true) \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index e96124472..4e5bc46d8 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -4,7 +4,7 @@ From 58004601698ac1b533ace64a4cc433e85341c3db Mon Sep 17 00:00:00 2001 From: ca1e Date: Thu, 12 Dec 2019 22:46:09 +0800 Subject: [PATCH 25/26] =?UTF-8?q?commit=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/constant/Bus.kt | 1 + .../ui/book/read/config/ReadStyleDialog.kt | 2 +- .../io/legado/app/ui/config/ConfigFragment.kt | 5 +++-- .../io/legado/app/ui/main/MainActivity.kt | 21 +++++++------------ .../io/legado/app/ui/widget/page/PageView.kt | 5 ++--- .../io/legado/app/utils/ContextExtensions.kt | 5 ++++- app/src/main/res/values/strings.xml | 1 + 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 517bafc93..395d51ec4 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -17,4 +17,5 @@ object Bus { const val AUDIO_PROGRESS = "audioProgress" const val AUDIO_SIZE = "audioSize" const val AUDIO_SPEED = "audioSpeed" + const val SHOW_RSS = "showRss" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 822ca033c..a816677f0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -182,7 +182,7 @@ class ReadStyleDialog : DialogFragment() { requireContext().putPrefInt("pageAnim", i) val activity = activity if (activity is ReadBookActivity) { - activity.page_view.upPageAnim() + activity.page_view.upPageAnim(i) } break } diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt index 927804039..0410b34a6 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt @@ -10,6 +10,7 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R +import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey import io.legado.app.help.BookHelp import io.legado.app.help.FileHelp @@ -65,7 +66,7 @@ class ConfigFragment : PreferenceFragmentCompat(), FileHelp.deleteFile(it) FileHelp.getFolder(it) } - toast("成功清理缓存") + toast(R.string.clear_cache_success) } } return super.onPreferenceTreeClick(preference) @@ -81,7 +82,7 @@ class ConfigFragment : PreferenceFragmentCompat(), PreferKey.processText -> sharedPreferences?.let { setProcessTextEnable(it.getBoolean("process_text", true)) } - PreferKey.showRss -> postEvent(PreferKey.showRss, PreferKey.showRss) + PreferKey.showRss -> postEvent(Bus.SHOW_RSS, "unused") } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 83f515a0c..1b5966efb 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -13,7 +13,6 @@ import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus -import io.legado.app.constant.PreferKey import io.legado.app.help.ActivityHelp import io.legado.app.help.storage.Backup import io.legado.app.lib.theme.ATH @@ -45,7 +44,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager) view_pager_main.addOnPageChangeListener(this) bottom_navigation_view.setOnNavigationItemSelectedListener(this) - bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = showRss() + bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = isShowRSS upVersion() } @@ -66,10 +65,10 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), fragmentList.add(RssFragment()) fragmentList.add(MyFragment()) } - if (showRss() && fragmentList.size < 4) { + if (isShowRSS && fragmentList.size < 4) { fragmentList.add(2, RssFragment()) } - if (!showRss() && fragmentList.size == 4) { + if (!isShowRSS && fragmentList.size == 4) { fragmentList.removeAt(2) } } @@ -87,7 +86,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), pagePosition = position when (position) { 0, 1, 3 -> bottom_navigation_view.menu.getItem(position).isChecked = true - 2 -> if (showRss()) { + 2 -> if (isShowRSS) { bottom_navigation_view.menu.getItem(position).isChecked = true } else { bottom_navigation_view.menu.getItem(3).isChecked = true @@ -133,20 +132,16 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), observeEvent(Bus.RECREATE) { recreate() } - observeEvent(PreferKey.showRss) { - bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = showRss() + observeEvent(Bus.SHOW_RSS) { + bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = isShowRSS upFragmentList() view_pager_main.adapter?.notifyDataSetChanged() - if (showRss()) { + if (isShowRSS) { view_pager_main.setCurrentItem(3, false) } } } - private fun showRss(): Boolean { - return getPrefBoolean("showRss", true) - } - private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { @@ -159,7 +154,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } override fun getCount(): Int { - return if (showRss()) 4 else 3 + return if (isShowRSS) 4 else 3 } } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 2a05969f7..ec4693ffb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -11,7 +11,6 @@ import io.legado.app.service.help.ReadBook import io.legado.app.ui.widget.page.curl.CurlView import io.legado.app.ui.widget.page.delegate.* import io.legado.app.utils.activity -import io.legado.app.utils.getPrefInt class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), @@ -89,13 +88,13 @@ class PageView(context: Context, attrs: AttributeSet) : } } - fun upPageAnim() { + fun upPageAnim(pageAnim: Int = 0) { if (curlView != null) { removeView(curlView) curlView = null } pageDelegate = null - pageDelegate = when (context.getPrefInt("pageAnim")) { + pageDelegate = when (pageAnim) { 0 -> CoverPageDelegate(this) 1 -> SlidePageDelegate(this) 2 -> SimulationPageDelegate(this) 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 bbdd84e6e..f47a0a2a8 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -64,4 +64,7 @@ val Context.isNightTheme: Boolean get() = getPrefBoolean("isNightTheme") val Context.isTransparentStatusBar: Boolean - get() = getPrefBoolean("transparentStatusBar", true) \ No newline at end of file + get() = getPrefBoolean("transparentStatusBar", true) + +val Context.isShowRSS: Boolean + get() = getPrefBoolean("showRss", true) \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 123967b0a..602c75ca4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -160,6 +160,7 @@ 作者:%s 朗读停止 清除缓存 + 成功清理缓存 保存 编辑源 编辑书源 From 811230970a58ebd641fb3039b76597ace3d88dbf Mon Sep 17 00:00:00 2001 From: ca1e Date: Fri, 13 Dec 2019 01:12:00 +0800 Subject: [PATCH 26/26] =?UTF-8?q?commit=20=E6=96=87=E6=A1=88=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/xml/pref_config_theme.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 4e5bc46d8..f9f3df963 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -6,7 +6,8 @@