From 1f01d3ced4aa558c4f096c1a82cc8b626049595b Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 15 Sep 2021 11:41:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/about/AppLogDialog.kt | 7 ------- .../io/legado/app/ui/book/cache/CacheActivity.kt | 2 +- .../io/legado/app/ui/book/info/BookInfoActivity.kt | 2 ++ .../io/legado/app/ui/book/info/BookInfoViewModel.kt | 2 +- .../app/ui/main/bookshelf/BaseBookshelfFragment.kt | 2 +- .../java/io/legado/app/utils/FragmentExtensions.kt | 13 +++++++++++++ app/src/main/res/menu/book_info.xml | 5 +++++ 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt b/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt index 3a332b49f..831f1e740 100644 --- a/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt +++ b/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -24,12 +23,6 @@ import java.util.* class AppLogDialog : BaseDialogFragment() { - companion object { - fun show(fragmentManager: FragmentManager) { - AppLogDialog().show(fragmentManager, "appLogDialog") - } - } - private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val adapter by lazy { LogAdapter(requireContext()) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index d58bad1c6..04b46b771 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -135,7 +135,7 @@ class CacheActivity : VMBaseActivity() R.id.menu_export_file_name -> alertExportFileName() R.id.menu_export_type -> showExportTypeConfig() R.id.menu_export_charset -> showCharsetConfig() - R.id.menu_log -> AppLogDialog.show(supportFragmentManager) + R.id.menu_log -> supportFragmentManager.showDialog() else -> if (item.groupId == R.id.menu_group) { binding.titleBar.subtitle = item.title groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0 diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index d41f78aa0..4ee294511 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -29,6 +29,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor +import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.book.audio.AudioPlayActivity import io.legado.app.ui.book.changecover.ChangeCoverDialog import io.legado.app.ui.book.changesource.ChangeSourceDialog @@ -182,6 +183,7 @@ class BookInfoActivity : } } R.id.menu_clear_cache -> viewModel.clearCache() + R.id.menu_log -> supportFragmentManager.showDialog() } return super.onCompatOptionsItemSelected(item) } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 4a6daad01..1fc705d02 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -270,7 +270,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { }.onSuccess { context.toastOnUi(R.string.clear_cache_success) }.onError { - context.toastOnUi(it.stackTraceToString()) + context.toastOnUi("清理缓存出错\n${it.localizedMessage}") } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt index 9090cd5b3..cc7bfe948 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt @@ -90,7 +90,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment importBookshelfAlert(groupId) - R.id.menu_log -> AppLogDialog.show(childFragmentManager) + R.id.menu_log -> childFragmentManager.showDialog() } } diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index 1883dd7e0..5d6265a50 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -6,10 +6,23 @@ import android.app.Activity import android.content.Intent import android.content.res.ColorStateList import android.graphics.drawable.Drawable +import android.os.Bundle import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.edit +import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager + +inline fun FragmentManager.showDialog( + arguments: Bundle.() -> Unit = {} +) { + val dialog = T::class.java.newInstance() + val bundle = Bundle() + bundle.apply(arguments) + dialog.arguments = bundle + dialog.show(this, T::class.simpleName) +} fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = requireContext().defaultSharedPreferences.getBoolean(key, defValue) diff --git a/app/src/main/res/menu/book_info.xml b/app/src/main/res/menu/book_info.xml index b2d1657ce..99b8c39ca 100644 --- a/app/src/main/res/menu/book_info.xml +++ b/app/src/main/res/menu/book_info.xml @@ -60,4 +60,9 @@ android:title="@string/clear_cache" app:showAsAction="never" /> + + \ No newline at end of file