pull/1693/head
kunfei 3 years ago
parent 536577b869
commit a0860ca956
  1. 2
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 20
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt

@ -95,6 +95,7 @@ object PreferKey {
const val uploadRule = "uploadRule" const val uploadRule = "uploadRule"
const val tocUiUseReplace = "tocUiUseReplace" const val tocUiUseReplace = "tocUiUseReplace"
const val enableReadRecord = "enableReadRecord" const val enableReadRecord = "enableReadRecord"
const val localBookImportSort = "localBookImportSort"
const val customWelcome = "customWelcome" const val customWelcome = "customWelcome"
const val welcomeImage = "welcomeImagePath" const val welcomeImage = "welcomeImagePath"
const val welcomeImageDark = "welcomeImagePathDark" const val welcomeImageDark = "welcomeImagePathDark"
@ -103,6 +104,7 @@ object PreferKey {
const val welcomeShowIcon = "welcomeShowIcon" const val welcomeShowIcon = "welcomeShowIcon"
const val welcomeShowIconDark = "welcomeShowIconDark" const val welcomeShowIconDark = "welcomeShowIconDark"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"
const val cBackground = "colorBackground" const val cBackground = "colorBackground"

@ -12,6 +12,7 @@ import androidx.documentfile.provider.DocumentFile
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.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.databinding.ActivityImportBookBinding import io.legado.app.databinding.ActivityImportBookBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
@ -80,18 +81,9 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
R.id.menu_select_folder -> selectFolder.launch() R.id.menu_select_folder -> selectFolder.launch()
R.id.menu_scan_folder -> scanFolder() R.id.menu_scan_folder -> scanFolder()
R.id.menu_import_file_name -> alertImportFileName() R.id.menu_import_file_name -> alertImportFileName()
R.id.menu_sort_name -> { R.id.menu_sort_name -> upSort(0)
viewModel.sort = 0 R.id.menu_sort_size -> upSort(1)
upSort() R.id.menu_sort_time -> upSort(2)
}
R.id.menu_sort_size -> {
viewModel.sort = 1
upSort()
}
R.id.menu_sort_time -> {
viewModel.sort = 2
upSort()
}
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
@ -203,7 +195,9 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
.request() .request()
} }
private fun upSort() { private fun upSort(sort: Int) {
viewModel.sort = sort
putPrefInt(PreferKey.localBookImportSort, sort)
if (scanDocJob?.isCancelled == true || scanDocJob?.isCompleted == true) { if (scanDocJob?.isCancelled == true || scanDocJob?.isCompleted == true) {
viewModel.dataCallback?.setItems(adapter.getItems()) viewModel.dataCallback?.setItems(adapter.getItems())
} }

@ -4,11 +4,9 @@ import android.app.Application
import android.net.Uri import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.PreferKey
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.DocumentUtils import io.legado.app.utils.*
import io.legado.app.utils.FileDoc
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
@ -24,7 +22,7 @@ import java.util.*
class ImportBookViewModel(application: Application) : BaseViewModel(application) { class ImportBookViewModel(application: Application) : BaseViewModel(application) {
private val bookFileRegex = Regex("(?i).*\\.(txt|epub|umd)") private val bookFileRegex = Regex("(?i).*\\.(txt|epub|umd)")
var sort = 0 var sort = context.getPrefInt(PreferKey.localBookImportSort)
var dataCallback: DataCallback? = null var dataCallback: DataCallback? = null
var dataFlowStart: (() -> Unit)? = null var dataFlowStart: (() -> Unit)? = null
val dataFlow = callbackFlow<List<FileDoc>> { val dataFlow = callbackFlow<List<FileDoc>> {

Loading…
Cancel
Save