|
|
@ -9,6 +9,7 @@ import android.view.MenuItem |
|
|
|
import android.view.SubMenu |
|
|
|
import android.view.SubMenu |
|
|
|
import androidx.appcompat.widget.PopupMenu |
|
|
|
import androidx.appcompat.widget.PopupMenu |
|
|
|
import androidx.appcompat.widget.SearchView |
|
|
|
import androidx.appcompat.widget.SearchView |
|
|
|
|
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
import androidx.lifecycle.Observer |
|
|
|
import androidx.lifecycle.Observer |
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
@ -37,6 +38,7 @@ import kotlinx.android.synthetic.main.view_search.* |
|
|
|
import org.jetbrains.anko.startActivity |
|
|
|
import org.jetbrains.anko.startActivity |
|
|
|
import org.jetbrains.anko.startActivityForResult |
|
|
|
import org.jetbrains.anko.startActivityForResult |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
|
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source), |
|
|
|
class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source), |
|
|
@ -48,7 +50,8 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r |
|
|
|
get() = getViewModel(RssSourceViewModel::class.java) |
|
|
|
get() = getViewModel(RssSourceViewModel::class.java) |
|
|
|
private val importRecordKey = "rssSourceRecordKey" |
|
|
|
private val importRecordKey = "rssSourceRecordKey" |
|
|
|
private val qrRequestCode = 101 |
|
|
|
private val qrRequestCode = 101 |
|
|
|
private val importSource = 124 |
|
|
|
private val importRequestCode = 124 |
|
|
|
|
|
|
|
private val exportRequestCode = 65 |
|
|
|
private lateinit var adapter: RssSourceAdapter |
|
|
|
private lateinit var adapter: RssSourceAdapter |
|
|
|
private var sourceLiveData: LiveData<List<RssSource>>? = null |
|
|
|
private var sourceLiveData: LiveData<List<RssSource>>? = null |
|
|
|
private var groups = hashSetOf<String>() |
|
|
|
private var groups = hashSetOf<String>() |
|
|
@ -78,7 +81,7 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r |
|
|
|
when (item.itemId) { |
|
|
|
when (item.itemId) { |
|
|
|
R.id.menu_add -> startActivity<RssSourceEditActivity>() |
|
|
|
R.id.menu_add -> startActivity<RssSourceEditActivity>() |
|
|
|
R.id.menu_import_source_local -> FilePicker |
|
|
|
R.id.menu_import_source_local -> FilePicker |
|
|
|
.selectFile(this, importSource, "text/*", arrayOf("txt", "json")) |
|
|
|
.selectFile(this, importRequestCode, "text/*", arrayOf("txt", "json")) |
|
|
|
R.id.menu_import_source_onLine -> showImportDialog() |
|
|
|
R.id.menu_import_source_onLine -> showImportDialog() |
|
|
|
R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode) |
|
|
|
R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode) |
|
|
|
R.id.menu_group_manage -> GroupManageDialog() |
|
|
|
R.id.menu_group_manage -> GroupManageDialog() |
|
|
@ -95,7 +98,7 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r |
|
|
|
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) |
|
|
|
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) |
|
|
|
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) |
|
|
|
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) |
|
|
|
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) |
|
|
|
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) |
|
|
|
R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection()) |
|
|
|
R.id.menu_export_selection -> FilePicker.selectFolder(this, exportRequestCode) |
|
|
|
R.id.menu_check_source -> { |
|
|
|
R.id.menu_check_source -> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -248,18 +251,24 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onFilePicked(requestCode: Int, currentPath: String) { |
|
|
|
override fun onFilePicked(requestCode: Int, currentPath: String) { |
|
|
|
if (requestCode == importSource) { |
|
|
|
when (requestCode) { |
|
|
|
|
|
|
|
importRequestCode -> { |
|
|
|
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() |
|
|
|
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() |
|
|
|
viewModel.importSourceFromFilePath(currentPath) { msg -> |
|
|
|
viewModel.importSourceFromFilePath(currentPath) { msg -> |
|
|
|
title_bar.snackbar(msg) |
|
|
|
title_bar.snackbar(msg) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
exportRequestCode -> viewModel.exportSelection( |
|
|
|
|
|
|
|
adapter.getSelection(), |
|
|
|
|
|
|
|
File(currentPath) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
when (requestCode) { |
|
|
|
when (requestCode) { |
|
|
|
importSource -> if (resultCode == Activity.RESULT_OK) { |
|
|
|
importRequestCode -> if (resultCode == Activity.RESULT_OK) { |
|
|
|
data?.data?.let { uri -> |
|
|
|
data?.data?.let { uri -> |
|
|
|
try { |
|
|
|
try { |
|
|
|
uri.readText(this)?.let { |
|
|
|
uri.readText(this)?.let { |
|
|
@ -282,6 +291,19 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
exportRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
|
|
|
|
data?.data?.let { uri -> |
|
|
|
|
|
|
|
if (uri.toString().isContentPath()) { |
|
|
|
|
|
|
|
DocumentFile.fromTreeUri(this, uri)?.let { |
|
|
|
|
|
|
|
viewModel.exportSelection(adapter.getSelection(), it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
uri.path?.let { |
|
|
|
|
|
|
|
viewModel.exportSelection(adapter.getSelection(), File(it)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|