Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jan 6, 2025
1 parent 9093dac commit 9bf7db4
Show file tree
Hide file tree
Showing 37 changed files with 168 additions and 84 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@
android:foregroundServiceType="dataSync"
android:icon="@drawable/ic_web_service_noti"
android:label="legado Web Service"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
tools:targetApi="24">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/io/legado/app/data/entities/Book.kt
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,6 @@ data class Book(
}
}

fun update() {
appDb.bookDao.update(this)
}

fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/io/legado/app/help/book/BookExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ fun Book.sync(oldBook: Book) {
canUpdate = curBook.canUpdate
}

fun Book.update() {
appDb.bookDao.update(this)
}

fun Book.getBookSource(): BookSource? {
return appDb.bookSourceDao.getBookSource(origin)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package io.legado.app.lib.prefs.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.fragment.app.DialogFragment
import androidx.preference.*
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.lib.prefs.EditTextPreferenceDialog
import io.legado.app.lib.prefs.ListPreferenceDialog
import io.legado.app.lib.prefs.MultiSelectListPreferenceDialog
import io.legado.app.utils.applyNavigationBarPadding

abstract class PreferenceFragment : PreferenceFragmentCompat() {

private val dialogFragmentTag = "androidx.preference.PreferenceFragment.DIALOG"

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
listView.clipToPadding = false
listView.applyNavigationBarPadding()
}

@SuppressLint("RestrictedApi")
override fun onDisplayPreferenceDialog(preference: Preference) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.graphics.drawable.ColorDrawable
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.ViewCompat
import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.databinding.ViewNavigationBadgeBinding
import io.legado.app.help.config.AppConfig
Expand Down Expand Up @@ -34,6 +35,8 @@ class ThemeBottomNavigationVIew(context: Context, attrs: AttributeSet) :
isItemHorizontalTranslationEnabled = false
itemBackground = ColorDrawable(Color.TRANSPARENT)
}

ViewCompat.setOnApplyWindowInsetsListener(this, null)
}

fun addBadgeView(index: Int): BadgeView {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/io/legado/app/model/AudioPlay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.legado.app.help.book.ContentProcessor
import io.legado.app.help.book.getBookSource
import io.legado.app.help.book.readSimulating
import io.legado.app.help.book.simulatedTotalChapterNum
import io.legado.app.help.book.update
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook
import io.legado.app.service.AudioPlayService
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/io/legado/app/model/ReadBook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.legado.app.help.book.isImage
import io.legado.app.help.book.isLocal
import io.legado.app.help.book.readSimulating
import io.legado.app.help.book.simulatedTotalChapterNum
import io.legado.app.help.book.update
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.coroutine.Coroutine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.legado.app.constant.AppPattern.bookFileRegex
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.book.update
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.webdav.Authorization
import io.legado.app.lib.webdav.WebDav
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction
import io.legado.app.constant.NotificationId
import io.legado.app.data.appDb
import io.legado.app.help.book.update
import io.legado.app.help.config.AppConfig
import io.legado.app.model.CacheBook
import io.legado.app.model.webBook.WebBook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.applyTint
import io.legado.app.utils.cnCompare
import io.legado.app.utils.getInt
Expand Down Expand Up @@ -105,6 +106,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
}
}
binding.recyclerView.adapter = adapter
binding.recyclerView.applyNavigationBarPadding()
}

private fun initSearchView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ActivityAllBookmarkBinding
import io.legado.app.ui.file.HandleFileContract
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
Expand Down Expand Up @@ -53,6 +54,7 @@ class AllBookmarkActivity : VMBaseActivity<ActivityAllBookmarkBinding, AllBookma
private fun initView() {
binding.recyclerView.addItemDecoration(BookmarkDecoration(adapter))
binding.recyclerView.adapter = adapter
binding.recyclerView.applyNavigationBarPadding()
}

override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.file.HandleFileContract
import io.legado.app.utils.ACache
import io.legado.app.utils.FileDoc
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.applyTint
import io.legado.app.utils.checkWrite
import io.legado.app.utils.cnCompare
Expand Down Expand Up @@ -200,6 +201,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private fun initRecyclerView() {
binding.recyclerView.layoutManager = layoutManager
binding.recyclerView.adapter = adapter
binding.recyclerView.applyNavigationBarPadding()
}

private fun initBookData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.legado.app.databinding.ViewLoadMoreBinding
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.widget.recycler.LoadMoreView
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding

Expand Down Expand Up @@ -43,6 +44,7 @@ class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreSh
private fun initRecyclerView() {
binding.recyclerView.addItemDecoration(VerticalDivider(this))
binding.recyclerView.adapter = adapter
binding.recyclerView.applyNavigationBarPadding()
adapter.addFooterView {
ViewLoadMoreBinding.bind(loadMoreView)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import io.legado.app.help.book.isLocal
import io.legado.app.help.book.isLocalTxt
import io.legado.app.help.book.isMobi
import io.legado.app.help.book.removeType
import io.legado.app.help.book.update
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.config.ReadTipConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.applyNavigationBarMargin
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.applyTint
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.gone
Expand Down Expand Up @@ -211,11 +213,14 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
binding.rvHistoryKey.setEdgeEffectColor(primaryColor)
binding.rvBookshelfSearch.layoutManager = FlexboxLayoutManager(this)
binding.rvBookshelfSearch.adapter = bookAdapter
binding.rvBookshelfSearch.applyNavigationBarMargin()
binding.rvHistoryKey.layoutManager = FlexboxLayoutManager(this)
binding.rvHistoryKey.adapter = historyKeyAdapter
binding.rvHistoryKey.applyNavigationBarMargin()
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.adapter = adapter
binding.recyclerView.itemAnimator = null
binding.recyclerView.applyNavigationBarPadding()
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
super.onItemRangeInserted(positionStart, itemCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.applyNavigationBarMargin
import io.legado.app.utils.applyTint
import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.invisible
Expand Down Expand Up @@ -65,6 +66,7 @@ class SearchContentActivity :
val bbg = bottomBackground
val btc = getPrimaryTextColor(ColorUtils.isColorLight(bbg))
binding.llSearchBaseInfo.setBackgroundColor(bbg)
binding.llSearchBaseInfo.applyNavigationBarMargin()
binding.tvCurrentSearchInfo.setTextColor(btc)
binding.ivSearchContentTop.setColorFilter(btc)
binding.ivSearchContentBottom.setColorFilter(btc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.launch
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.showDialogFragment
Expand Down Expand Up @@ -61,6 +62,7 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
private fun initRecyclerView() {
binding.recyclerView.setEdgeEffectColor(primaryColor)
binding.recyclerView.adapter = adapter
binding.recyclerView.applyNavigationBarPadding()
binding.rotateLoading.loadingColor = accentColor
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.book.bookmark.BookmarkDialog
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.viewbindingdelegate.viewBinding
Expand Down Expand Up @@ -50,6 +51,7 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark
binding.recyclerView.layoutManager = mLayoutManager
binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
binding.recyclerView.adapter = adapter
binding.recyclerView.applyNavigationBarPadding()
}

override fun upBookmark(searchKey: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.applyNavigationBarMargin
import io.legado.app.utils.observeEvent
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -74,6 +75,7 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
tvCurrentChapterInfo.setOnClickListener {
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
}
binding.llChapterBaseInfo.applyNavigationBarMargin()
}

@SuppressLint("SetTextI18n")
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/io/legado/app/ui/file/FileManageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.file.utils.FilePickerIcon
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ConvertUtils
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.applyTint
import io.legado.app.utils.openFileUri
import io.legado.app.utils.viewbindingdelegate.viewBinding
Expand Down Expand Up @@ -56,6 +57,7 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.addItemDecoration(VerticalDivider(this))
binding.recyclerView.adapter = fileAdapter
binding.recyclerView.applyNavigationBarPadding()
onBackPressedDispatcher.addCallback(this) {
if (viewModel.lastDir != viewModel.rootDoc) {
gotoLastDir()
Expand Down
34 changes: 22 additions & 12 deletions app/src/main/java/io/legado/app/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.EditText
import androidx.activity.addCallback
import androidx.activity.viewModels
import androidx.core.view.ViewCompat
import androidx.core.view.postDelayed
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
Expand Down Expand Up @@ -45,6 +46,7 @@ import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.isCreated
import io.legado.app.utils.navigationBarHeight
import io.legado.app.utils.observeEvent
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.showDialogFragment
Expand All @@ -53,6 +55,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import splitties.views.bottomPadding
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

Expand Down Expand Up @@ -87,18 +90,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),

override fun onActivityCreated(savedInstanceState: Bundle?) {
upBottomMenu()
binding.run {
viewPagerMain.setEdgeEffectColor(primaryColor)
viewPagerMain.offscreenPageLimit = 3
viewPagerMain.adapter = adapter
viewPagerMain.addOnPageChangeListener(PageChangeCallback())
bottomNavigationView.elevation = elevation
bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity)
bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity)
if (AppConfig.isEInkMode) {
bottomNavigationView.setBackgroundResource(R.drawable.bg_eink_border_top)
}
}
initView()
upHomePage()
viewModel.deleteNotShelfBook()
onBackPressedDispatcher.addCallback(this) {
Expand Down Expand Up @@ -198,6 +190,24 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
}
}

private fun initView() = binding.run {
viewPagerMain.setEdgeEffectColor(primaryColor)
viewPagerMain.offscreenPageLimit = 3
viewPagerMain.adapter = adapter
viewPagerMain.addOnPageChangeListener(PageChangeCallback())
bottomNavigationView.elevation = elevation
bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity)
bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity)
if (AppConfig.isEInkMode) {
bottomNavigationView.setBackgroundResource(R.drawable.bg_eink_border_top)
}
ViewCompat.setOnApplyWindowInsetsListener(root) { _, windowInsets ->
val height = windowInsets.navigationBarHeight
bottomNavigationView.bottomPadding = height
windowInsets.inset(0, 0, 0, height)
}
}

/**
* 用户隐私与协议
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.rss.read.ReadRssActivity
import io.legado.app.ui.widget.recycler.LoadMoreView
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding
Expand Down Expand Up @@ -66,6 +67,7 @@ class RssArticlesFragment() : VMBaseFragment<RssArticlesViewModel>(R.layout.frag
private fun initView() = binding.run {
refreshLayout.setColorSchemeColors(accentColor)
recyclerView.setEdgeEffectColor(primaryColor)
recyclerView.applyNavigationBarPadding()
loadMoreView.setOnClickListener {
if (!loadMoreView.isLoading) {
scrollToBottom(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.legado.app.databinding.FragmentRssArticlesBinding
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.rss.read.ReadRssActivity
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding
Expand Down Expand Up @@ -51,6 +52,7 @@ class RssFavoritesFragment() : VMBaseFragment<RssFavoritesViewModel>(R.layout.fr
LinearLayoutManager(requireContext())
}
recyclerView.adapter = adapter
recyclerView.applyNavigationBarPadding()
}

private fun loadArticles() {
Expand Down
Loading

0 comments on commit 9bf7db4

Please sign in to comment.