|
|
@ -8,6 +8,7 @@ import android.view.MenuItem |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
import androidx.lifecycle.Observer |
|
|
|
import androidx.lifecycle.Observer |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.VMBaseActivity |
|
|
|
import io.legado.app.base.VMBaseActivity |
|
|
@ -19,10 +20,7 @@ import io.legado.app.help.permission.Permissions |
|
|
|
import io.legado.app.help.permission.PermissionsCompat |
|
|
|
import io.legado.app.help.permission.PermissionsCompat |
|
|
|
import io.legado.app.service.help.Download |
|
|
|
import io.legado.app.service.help.Download |
|
|
|
import io.legado.app.ui.filechooser.FileChooserDialog |
|
|
|
import io.legado.app.ui.filechooser.FileChooserDialog |
|
|
|
import io.legado.app.utils.ACache |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
|
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
|
|
|
|
import io.legado.app.utils.observeEvent |
|
|
|
|
|
|
|
import kotlinx.android.synthetic.main.activity_download.* |
|
|
|
import kotlinx.android.synthetic.main.activity_download.* |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
@ -137,9 +135,7 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow |
|
|
|
if (path.isNullOrEmpty()) { |
|
|
|
if (path.isNullOrEmpty()) { |
|
|
|
toast("没有默认路径") |
|
|
|
toast("没有默认路径") |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
adapter.getItem(exportPosition)?.let { |
|
|
|
startExport(path) |
|
|
|
viewModel.export(path, it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
1 -> { |
|
|
|
1 -> { |
|
|
@ -170,13 +166,21 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow |
|
|
|
}.show() |
|
|
|
}.show() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun startExport(path: String) { |
|
|
|
|
|
|
|
adapter.getItem(exportPosition)?.let { book -> |
|
|
|
|
|
|
|
Snackbar.make(title_bar, R.string.exporting, Snackbar.LENGTH_INDEFINITE) |
|
|
|
|
|
|
|
.show() |
|
|
|
|
|
|
|
viewModel.export(path, book) { |
|
|
|
|
|
|
|
title_bar.snackbar(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
ACache.get(this@DownloadActivity).put(exportBookPathKey, currentPath) |
|
|
|
adapter.getItem(exportPosition)?.let { |
|
|
|
startExport(currentPath) |
|
|
|
viewModel.export(currentPath, it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -191,9 +195,7 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow |
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
|
) |
|
|
|
) |
|
|
|
ACache.get(this@DownloadActivity).put(exportBookPathKey, uri.toString()) |
|
|
|
ACache.get(this@DownloadActivity).put(exportBookPathKey, uri.toString()) |
|
|
|
adapter.getItem(exportPosition)?.let { |
|
|
|
startExport(uri.toString()) |
|
|
|
viewModel.export(uri.toString(), it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|