pull/1319/head
gedoor 3 years ago
parent f42045f1e1
commit 1f01d3ced4
  1. 7
      app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
  6. 13
      app/src/main/java/io/legado/app/utils/FragmentExtensions.kt
  7. 5
      app/src/main/res/menu/book_info.xml

@ -5,7 +5,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
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
@ -24,12 +23,6 @@ import java.util.*
class AppLogDialog : BaseDialogFragment() { class AppLogDialog : BaseDialogFragment() {
companion object {
fun show(fragmentManager: FragmentManager) {
AppLogDialog().show(fragmentManager, "appLogDialog")
}
}
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private val adapter by lazy { private val adapter by lazy {
LogAdapter(requireContext()) LogAdapter(requireContext())

@ -135,7 +135,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
R.id.menu_export_file_name -> alertExportFileName() R.id.menu_export_file_name -> alertExportFileName()
R.id.menu_export_type -> showExportTypeConfig() R.id.menu_export_type -> showExportTypeConfig()
R.id.menu_export_charset -> showCharsetConfig() R.id.menu_export_charset -> showCharsetConfig()
R.id.menu_log -> AppLogDialog.show(supportFragmentManager) R.id.menu_log -> supportFragmentManager.showDialog<AppLogDialog>()
else -> if (item.groupId == R.id.menu_group) { else -> if (item.groupId == R.id.menu_group) {
binding.titleBar.subtitle = item.title binding.titleBar.subtitle = item.title
groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0 groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0

@ -29,6 +29,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor 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.audio.AudioPlayActivity
import io.legado.app.ui.book.changecover.ChangeCoverDialog import io.legado.app.ui.book.changecover.ChangeCoverDialog
import io.legado.app.ui.book.changesource.ChangeSourceDialog import io.legado.app.ui.book.changesource.ChangeSourceDialog
@ -182,6 +183,7 @@ class BookInfoActivity :
} }
} }
R.id.menu_clear_cache -> viewModel.clearCache() R.id.menu_clear_cache -> viewModel.clearCache()
R.id.menu_log -> supportFragmentManager.showDialog<AppLogDialog>()
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }

@ -270,7 +270,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}.onSuccess { }.onSuccess {
context.toastOnUi(R.string.clear_cache_success) context.toastOnUi(R.string.clear_cache_success)
}.onError { }.onError {
context.toastOnUi(it.stackTraceToString()) context.toastOnUi("清理缓存出错\n${it.localizedMessage}")
} }
} }

@ -90,7 +90,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
} }
} }
R.id.menu_import_bookshelf -> importBookshelfAlert(groupId) R.id.menu_import_bookshelf -> importBookshelfAlert(groupId)
R.id.menu_log -> AppLogDialog.show(childFragmentManager) R.id.menu_log -> childFragmentManager.showDialog<AppLogDialog>()
} }
} }

@ -6,10 +6,23 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Bundle
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.content.edit import androidx.core.content.edit
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
inline fun <reified T : DialogFragment> 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) = fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) =
requireContext().defaultSharedPreferences.getBoolean(key, defValue) requireContext().defaultSharedPreferences.getBoolean(key, defValue)

@ -60,4 +60,9 @@
android:title="@string/clear_cache" android:title="@string/clear_cache"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_log"
android:title="@string/log"
app:showAsAction="never" />
</menu> </menu>
Loading…
Cancel
Save