pull/49/head
kunfei 5 years ago
parent 6ee4b417cb
commit b2caeedafa
  1. 33
      app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt
  2. 33
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -7,12 +7,23 @@ import androidx.preference.EditTextPreference
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Backup
import io.legado.app.help.storage.Restore
import io.legado.app.help.storage.WebDavHelp import io.legado.app.help.storage.WebDavHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.applyTint
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
@ -86,8 +97,30 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
when (preference?.key) { when (preference?.key) {
"web_dav_backup" -> Backup.backup() "web_dav_backup" -> Backup.backup()
"web_dav_restore" -> WebDavHelp.showRestoreDialog(requireContext()) "web_dav_restore" -> WebDavHelp.showRestoreDialog(requireContext())
"import_old" -> importOld()
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }
private fun importOld() {
Coroutine.async {
if (withContext(Dispatchers.IO) { App.db.bookDao().allBookCount == 0 }) {
alert(title = "导入") {
message = "是否导入旧版本数据"
yesButton {
PermissionsCompat.Builder(this@WebDavConfigFragment)
.addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage)
.onGranted {
Restore.importYueDuData(requireContext())
}
.request()
}
noButton {
}
}.show().applyTint()
}
}
}
} }

@ -14,22 +14,17 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.help.ActivityHelp import io.legado.app.help.ActivityHelp
import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Backup
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.main.bookshelf.BookshelfFragment import io.legado.app.ui.main.bookshelf.BookshelfFragment
import io.legado.app.ui.main.explore.ExploreFragment import io.legado.app.ui.main.explore.ExploreFragment
import io.legado.app.ui.main.my.MyFragment import io.legado.app.ui.main.my.MyFragment
import io.legado.app.ui.main.rss.RssFragment import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.utils.* import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getViewModel
import io.legado.app.utils.observeEvent
import io.legado.app.utils.putPrefInt
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
BottomNavigationView.OnNavigationItemSelectedListener, BottomNavigationView.OnNavigationItemSelectedListener,
@ -60,26 +55,6 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
return false return false
} }
private fun restore() {
launch {
if (withContext(IO) { App.db.bookDao().allBookCount == 0 }) {
alert(title = "导入") {
message = "是否导入旧版本数据"
yesButton {
PermissionsCompat.Builder(this@MainActivity)
.addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage)
.onGranted { viewModel.importYueDuData() }
.request()
}
noButton {
}
}.show().applyTint()
}
}
}
private fun upVersion() { private fun upVersion() {
if (getPrefInt("versionCode") != App.INSTANCE.versionCode) { if (getPrefInt("versionCode") != App.INSTANCE.versionCode) {
putPrefInt("versionCode", App.INSTANCE.versionCode) putPrefInt("versionCode", App.INSTANCE.versionCode)

Loading…
Cancel
Save