修复UI的bug,修改添加网址的order

pull/2001/head
821938089 2 years ago
parent b5afa7f8ed
commit 0ab76a176f
  1. 1
      app/src/main/AndroidManifest.xml
  2. 11
      app/src/main/java/io/legado/app/App.kt
  3. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
  4. 38
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt

@ -147,6 +147,7 @@
<!-- 主界面 --> <!-- 主界面 -->
<activity <activity
android:name=".ui.main.MainActivity" android:name=".ui.main.MainActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|uiMode"
android:alwaysRetainTaskState="true" android:alwaysRetainTaskState="true"
android:launchMode="singleTask" /> android:launchMode="singleTask" />
<!-- 阅读界面 --> <!-- 阅读界面 -->

@ -3,6 +3,7 @@ package io.legado.app
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.content.pm.ActivityInfo
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Build import android.os.Build
import androidx.multidex.MultiDexApplication import androidx.multidex.MultiDexApplication
@ -28,8 +29,11 @@ import java.util.concurrent.TimeUnit
class App : MultiDexApplication() { class App : MultiDexApplication() {
private lateinit var oldConfig: Configuration
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
oldConfig = Configuration(resources.configuration)
CrashHandler(this) CrashHandler(this)
//预下载Cronet so //预下载Cronet so
CronetLoader.preDownload() CronetLoader.preDownload()
@ -69,10 +73,11 @@ class App : MultiDexApplication() {
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
when (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) { val diff = newConfig.diff(oldConfig)
Configuration.UI_MODE_NIGHT_YES, if ((diff and ActivityInfo.CONFIG_UI_MODE) != 0) {
Configuration.UI_MODE_NIGHT_NO -> applyDayNight(this) applyDayNight(this)
} }
oldConfig = Configuration(newConfig)
} }
/** /**

@ -50,7 +50,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
) )
WebBook.getBookInfo(this, bookSource, book) WebBook.getBookInfo(this, bookSource, book)
.onSuccess(IO) { .onSuccess(IO) {
it.order = appDb.bookDao.maxOrder + 1 it.order = appDb.bookDao.minOrder - 1
it.save() it.save()
successCount++ successCount++
}.onError { }.onError {

@ -59,10 +59,12 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
} }
} }
private var booksFlowJob: Job? = null private var booksFlowJob: Job? = null
private var savedInstanceState: Bundle? = null
private var position = 0 private var position = 0
private var groupId = -1L private var groupId = -1L
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
this.savedInstanceState = savedInstanceState
arguments?.let { arguments?.let {
position = it.getInt("position", 0) position = it.getInt("position", 0)
groupId = it.getLong("groupId", -1) groupId = it.getLong("groupId", -1)
@ -126,11 +128,25 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
}.conflate().collect { list -> }.conflate().collect { list ->
binding.tvEmptyMsg.isGone = list.isNotEmpty() binding.tvEmptyMsg.isGone = list.isNotEmpty()
booksAdapter.setItems(list) booksAdapter.setItems(list)
recoverPositionState()
delay(100) delay(100)
} }
} }
} }
private fun recoverPositionState() {
// 恢复书架位置状态
if (savedInstanceState?.getBoolean("needRecoverState") == true) {
val layoutManager = binding.rvBookshelf.layoutManager
if (layoutManager is LinearLayoutManager) {
val leavePosition = savedInstanceState!!.getInt("leavePosition")
val leaveOffset = savedInstanceState!!.getInt("leaveOffset")
layoutManager.scrollToPositionWithOffset(leavePosition, leaveOffset)
}
savedInstanceState!!.putBoolean("needRecoverState", false)
}
}
fun getBooks(): List<Book> { fun getBooks(): List<Book> {
return booksAdapter.getItems() return booksAdapter.getItems()
} }
@ -147,6 +163,28 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
return booksAdapter.itemCount return booksAdapter.itemCount
} }
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
// 保存书架位置状态
val layoutManager = binding.rvBookshelf.layoutManager
if (layoutManager is LinearLayoutManager) {
val itemPosition = layoutManager.findFirstVisibleItemPosition()
val currentView = layoutManager.findViewByPosition(itemPosition)
val viewOffset = currentView?.top
if (viewOffset != null) {
outState.putInt("leavePosition", itemPosition)
outState.putInt("leaveOffset", viewOffset)
outState.putBoolean("needRecoverState", true)
} else if (savedInstanceState != null) {
val leavePosition = savedInstanceState!!.getInt("leavePosition")
val leaveOffset = savedInstanceState!!.getInt("leaveOffset")
outState.putInt("leavePosition", leavePosition)
outState.putInt("leaveOffset", leaveOffset)
outState.putBoolean("needRecoverState", true)
}
}
}
override fun open(book: Book) { override fun open(book: Book) {
when (book.type) { when (book.type) {
BookType.audio -> BookType.audio ->

Loading…
Cancel
Save