|
|
@ -36,6 +36,7 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow |
|
|
|
FileChooserDialog.CallBack, |
|
|
|
FileChooserDialog.CallBack, |
|
|
|
DownloadAdapter.CallBack { |
|
|
|
DownloadAdapter.CallBack { |
|
|
|
private val exportRequestCode = 32 |
|
|
|
private val exportRequestCode = 32 |
|
|
|
|
|
|
|
private val exportBookPathKey = "exportBookPath" |
|
|
|
lateinit var adapter: DownloadAdapter |
|
|
|
lateinit var adapter: DownloadAdapter |
|
|
|
private var bookshelfLiveData: LiveData<List<Book>>? = null |
|
|
|
private var bookshelfLiveData: LiveData<List<Book>>? = null |
|
|
|
private var menu: Menu? = null |
|
|
|
private var menu: Menu? = null |
|
|
@ -132,7 +133,7 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow |
|
|
|
items(resources.getStringArray(R.array.select_folder).toList()) { _, index -> |
|
|
|
items(resources.getStringArray(R.array.select_folder).toList()) { _, index -> |
|
|
|
when (index) { |
|
|
|
when (index) { |
|
|
|
0 -> { |
|
|
|
0 -> { |
|
|
|
val path = ACache.get(this@DownloadActivity).getAsString("exportBookPath") |
|
|
|
val path = ACache.get(this@DownloadActivity).getAsString(exportBookPathKey) |
|
|
|
if (path.isNullOrEmpty()) { |
|
|
|
if (path.isNullOrEmpty()) { |
|
|
|
toast("没有默认路径") |
|
|
|
toast("没有默认路径") |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -172,6 +173,7 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow |
|
|
|
override fun onFilePicked(requestCode: Int, currentPath: String) { |
|
|
|
override fun onFilePicked(requestCode: Int, currentPath: String) { |
|
|
|
when (requestCode) { |
|
|
|
when (requestCode) { |
|
|
|
exportRequestCode -> { |
|
|
|
exportRequestCode -> { |
|
|
|
|
|
|
|
ACache.get(this@DownloadActivity).put(exportBookPathKey, currentPath) |
|
|
|
adapter.getItem(exportPosition)?.let { |
|
|
|
adapter.getItem(exportPosition)?.let { |
|
|
|
viewModel.export(currentPath, it) |
|
|
|
viewModel.export(currentPath, it) |
|
|
|
} |
|
|
|
} |
|
|
@ -184,6 +186,11 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow |
|
|
|
when (requestCode) { |
|
|
|
when (requestCode) { |
|
|
|
exportRequestCode -> if (resultCode == Activity.RESULT_OK) { |
|
|
|
exportRequestCode -> if (resultCode == Activity.RESULT_OK) { |
|
|
|
data?.data?.let { uri -> |
|
|
|
data?.data?.let { uri -> |
|
|
|
|
|
|
|
contentResolver.takePersistableUriPermission( |
|
|
|
|
|
|
|
uri, |
|
|
|
|
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
ACache.get(this@DownloadActivity).put(exportBookPathKey, uri.toString()) |
|
|
|
adapter.getItem(exportPosition)?.let { |
|
|
|
adapter.getItem(exportPosition)?.let { |
|
|
|
viewModel.export(uri.toString(), it) |
|
|
|
viewModel.export(uri.toString(), it) |
|
|
|
} |
|
|
|
} |
|
|
|