|
|
|
@ -20,12 +20,11 @@ import io.legado.app.R |
|
|
|
|
import io.legado.app.base.VMBaseActivity |
|
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
|
import io.legado.app.help.ItemTouchCallback |
|
|
|
|
import io.legado.app.help.permission.Permissions |
|
|
|
|
import io.legado.app.help.permission.PermissionsCompat |
|
|
|
|
import io.legado.app.lib.dialogs.* |
|
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
|
import io.legado.app.lib.theme.primaryTextColor |
|
|
|
|
import io.legado.app.ui.filechooser.FileChooserDialog |
|
|
|
|
import io.legado.app.ui.filechooser.FilePicker |
|
|
|
|
import io.legado.app.ui.qrcode.QrCodeActivity |
|
|
|
|
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity |
|
|
|
|
import io.legado.app.ui.widget.SelectActionBar |
|
|
|
@ -38,7 +37,6 @@ import kotlinx.android.synthetic.main.view_search.* |
|
|
|
|
import org.jetbrains.anko.startActivity |
|
|
|
|
import org.jetbrains.anko.startActivityForResult |
|
|
|
|
import org.jetbrains.anko.toast |
|
|
|
|
import java.io.FileNotFoundException |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source), |
|
|
|
@ -79,7 +77,8 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r |
|
|
|
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
|
when (item.itemId) { |
|
|
|
|
R.id.menu_add -> startActivity<RssSourceEditActivity>() |
|
|
|
|
R.id.menu_import_source_local -> selectFileSys() |
|
|
|
|
R.id.menu_import_source_local -> FilePicker |
|
|
|
|
.selectFile(this, importSource, "text/*", arrayOf("txt", "json")) |
|
|
|
|
R.id.menu_import_source_onLine -> showImportDialog() |
|
|
|
|
R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode) |
|
|
|
|
R.id.menu_group_manage -> GroupManageDialog() |
|
|
|
@ -248,33 +247,6 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r |
|
|
|
|
}.show().applyTint() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun selectFileSys() { |
|
|
|
|
try { |
|
|
|
|
val intent = Intent(Intent.ACTION_GET_CONTENT) |
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE) |
|
|
|
|
intent.type = "text/*"//设置类型 |
|
|
|
|
startActivityForResult(intent, importSource) |
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
PermissionsCompat.Builder(this) |
|
|
|
|
.addPermissions( |
|
|
|
|
Permissions.READ_EXTERNAL_STORAGE, |
|
|
|
|
Permissions.WRITE_EXTERNAL_STORAGE |
|
|
|
|
) |
|
|
|
|
.rationale(R.string.bg_image_per) |
|
|
|
|
.onGranted { |
|
|
|
|
selectFile() |
|
|
|
|
} |
|
|
|
|
.request() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun selectFile() { |
|
|
|
|
FileChooserDialog.show( |
|
|
|
|
supportFragmentManager, importSource, |
|
|
|
|
allowExtensions = arrayOf("txt", "json") |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onFilePicked(requestCode: Int, currentPath: String) { |
|
|
|
|
if (requestCode == importSource) { |
|
|
|
|
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() |
|
|
|
@ -297,17 +269,6 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r |
|
|
|
|
title_bar.snackbar(msg) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e: FileNotFoundException) { |
|
|
|
|
PermissionsCompat.Builder(this) |
|
|
|
|
.addPermissions( |
|
|
|
|
Permissions.READ_EXTERNAL_STORAGE, |
|
|
|
|
Permissions.WRITE_EXTERNAL_STORAGE |
|
|
|
|
) |
|
|
|
|
.rationale(R.string.bg_image_per) |
|
|
|
|
.onGranted { |
|
|
|
|
selectFileSys() |
|
|
|
|
} |
|
|
|
|
.request() |
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
toast(e.localizedMessage ?: "ERROR") |
|
|
|
|
} |
|
|
|
|