allow changing the filename of the file where events will be exported
This commit is contained in:
parent
749f7f1fb0
commit
4efacece63
|
@ -39,7 +39,6 @@ import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.commons.models.Release
|
import com.simplemobiletools.commons.models.Release
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.io.File
|
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -309,16 +308,14 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
||||||
private fun exportEvents() {
|
private fun exportEvents() {
|
||||||
FilePickerDialog(this, pickFile = false) {
|
FilePickerDialog(this, pickFile = false) {
|
||||||
val path = it
|
val path = it
|
||||||
ExportEventsDialog(this, path) {
|
ExportEventsDialog(this, path) { exportPastEvents, file ->
|
||||||
Thread({
|
Thread({
|
||||||
val events = dbHelper.getEventsToExport(it)
|
val events = dbHelper.getEventsToExport(exportPastEvents)
|
||||||
if (events.isEmpty()) {
|
if (events.isEmpty()) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
toast(R.string.no_events_for_exporting)
|
toast(R.string.no_events_for_exporting)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val filename = "events_${System.currentTimeMillis() / 1000}.ics"
|
|
||||||
val file = File(path, filename)
|
|
||||||
IcsExporter().exportEvents(this, file, events) {
|
IcsExporter().exportEvents(this, file, events) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
toast(when (it) {
|
toast(when (it) {
|
||||||
|
|
|
@ -4,21 +4,39 @@ import android.app.Activity
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.commons.extensions.humanizePath
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
|
||||||
import kotlinx.android.synthetic.main.dialog_export_events.view.*
|
import kotlinx.android.synthetic.main.dialog_export_events.view.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class ExportEventsDialog(val activity: Activity, val path: String, val callback: (exportPastEvents: Boolean) -> Unit) : AlertDialog.Builder(activity) {
|
class ExportEventsDialog(val activity: Activity, val path: String, val callback: (exportPastEvents: Boolean, file: File) -> Unit) : AlertDialog.Builder(activity) {
|
||||||
init {
|
init {
|
||||||
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_events, null) as ViewGroup).apply {
|
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_events, null) as ViewGroup).apply {
|
||||||
export_events_folder.text = activity.humanizePath(path)
|
export_events_folder.text = activity.humanizePath(path)
|
||||||
|
export_events_filename.setText("events_${System.currentTimeMillis() / 1000}")
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog.Builder(activity)
|
AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.ok, { dialog, which -> callback(view.export_events_checkbox.isChecked) })
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.create().apply {
|
.create().apply {
|
||||||
activity.setupDialogStuff(view, this, R.string.export_events)
|
activity.setupDialogStuff(view, this, R.string.export_events)
|
||||||
|
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||||
|
val filename = view.export_events_filename.value
|
||||||
|
if (filename.isEmpty()) {
|
||||||
|
context.toast(R.string.empty_name)
|
||||||
|
} else if (filename.isAValidFilename()) {
|
||||||
|
val file = File(path, "$filename.ics")
|
||||||
|
if (file.exists()) {
|
||||||
|
context.toast(R.string.name_taken)
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(view.export_events_checkbox.isChecked, file)
|
||||||
|
dismiss()
|
||||||
|
} else {
|
||||||
|
context.toast(R.string.invalid_name)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue