add a menu button for exporting events to ics file

This commit is contained in:
tibbi 2017-04-02 19:31:21 +02:00
parent b2be9add1e
commit 5265f216cf
2 changed files with 29 additions and 7 deletions

View File

@ -44,6 +44,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
private val PREFILLED_WEEKS = 41 private val PREFILLED_WEEKS = 41
private val STORAGE_PERMISSION_IMPORT = 1 private val STORAGE_PERMISSION_IMPORT = 1
private val STORAGE_PERMISSION_EXPORT = 2 private val STORAGE_PERMISSION_EXPORT = 2
private val STORAGE_PERMISSION_EXPORT_RAW = 3
private var mIsMonthSelected = false private var mIsMonthSelected = false
private var mStoredTextColor = 0 private var mStoredTextColor = 0
@ -124,7 +125,8 @@ class MainActivity : SimpleActivity(), NavigationListener {
R.id.go_to_today -> goToToday() R.id.go_to_today -> goToToday()
R.id.filter -> showFilterDialog() R.id.filter -> showFilterDialog()
R.id.import_events -> tryImportEvents() R.id.import_events -> tryImportEvents()
R.id.export_raw -> tryExportDatabase() R.id.export_events -> tryExportEvents()
R.id.export_raw -> tryExportRaw()
R.id.settings -> launchSettings() R.id.settings -> launchSettings()
R.id.about -> launchAbout() R.id.about -> launchAbout()
else -> return super.onOptionsItemSelected(item) else -> return super.onOptionsItemSelected(item)
@ -247,15 +249,29 @@ class MainActivity : SimpleActivity(), NavigationListener {
} }
} }
private fun tryExportDatabase() { private fun tryExportEvents() {
if (hasWriteStoragePermission()) { if (hasReadStoragePermission()) {
exportDatabase() exportEvents()
} else { } else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION_EXPORT) ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), STORAGE_PERMISSION_EXPORT)
} }
} }
private fun exportDatabase() { private fun exportEvents() {
FilePickerDialog(this, pickFile = false) {
}
}
private fun tryExportRaw() {
if (hasWriteStoragePermission()) {
exportRaw()
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION_EXPORT_RAW)
}
}
private fun exportRaw() {
FilePickerDialog(this, pickFile = false) { FilePickerDialog(this, pickFile = false) {
val source = getDatabasePath(DBHelper.DB_NAME) val source = getDatabasePath(DBHelper.DB_NAME)
val destination = File(it, "calendar_${System.currentTimeMillis()}.db") val destination = File(it, "calendar_${System.currentTimeMillis()}.db")
@ -495,7 +511,9 @@ class MainActivity : SimpleActivity(), NavigationListener {
if (requestCode == STORAGE_PERMISSION_IMPORT) { if (requestCode == STORAGE_PERMISSION_IMPORT) {
importEvents() importEvents()
} else if (requestCode == STORAGE_PERMISSION_EXPORT) { } else if (requestCode == STORAGE_PERMISSION_EXPORT) {
exportDatabase() exportEvents()
} else if (requestCode == STORAGE_PERMISSION_EXPORT_RAW) {
exportRaw()
} }
} }
} }

View File

@ -20,6 +20,10 @@
android:id="@+id/import_events" android:id="@+id/import_events"
android:title="@string/import_events_from_ics" android:title="@string/import_events_from_ics"
app:showAsAction="never"/> app:showAsAction="never"/>
<item
android:id="@+id/export_events"
android:title="@string/export_events_to_ics"
app:showAsAction="never"/>
<item <item
android:id="@+id/export_raw" android:id="@+id/export_raw"
android:title="@string/export_raw_database" android:title="@string/export_raw_database"