mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-15 15:57:24 +02:00
handle the SAF dialog when opening a note from SD card with sync
This commit is contained in:
parent
a25f826c5a
commit
255a5ade89
@ -1,6 +1,5 @@
|
|||||||
package com.simplemobiletools.notes.dialogs
|
package com.simplemobiletools.notes.dialogs
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -9,18 +8,21 @@ import com.simplemobiletools.commons.extensions.humanizePath
|
|||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import com.simplemobiletools.notes.R
|
import com.simplemobiletools.notes.R
|
||||||
import com.simplemobiletools.notes.R.id.open_file_update_file
|
import com.simplemobiletools.notes.R.id.open_file_update_file
|
||||||
|
import com.simplemobiletools.notes.activities.SimpleActivity
|
||||||
import com.simplemobiletools.notes.helpers.TYPE_NOTE
|
import com.simplemobiletools.notes.helpers.TYPE_NOTE
|
||||||
import com.simplemobiletools.notes.models.Note
|
import com.simplemobiletools.notes.models.Note
|
||||||
import kotlinx.android.synthetic.main.dialog_open_file.view.*
|
import kotlinx.android.synthetic.main.dialog_open_file.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class OpenFileDialog(val activity: Activity, val path: String, val callback: (note: Note) -> Unit) : AlertDialog.Builder(activity) {
|
class OpenFileDialog(val activity: SimpleActivity, val path: String, val callback: (note: Note) -> Unit) : AlertDialog.Builder(activity) {
|
||||||
|
private var dialog: AlertDialog
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val view = (LayoutInflater.from(activity).inflate(R.layout.dialog_open_file, null) as ViewGroup).apply {
|
val view = (LayoutInflater.from(activity).inflate(R.layout.dialog_open_file, null) as ViewGroup).apply {
|
||||||
open_file_filename.text = activity.humanizePath(path)
|
open_file_filename.text = activity.humanizePath(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.create().apply {
|
.create().apply {
|
||||||
@ -30,11 +32,21 @@ class OpenFileDialog(val activity: Activity, val path: String, val callback: (no
|
|||||||
val storePath = if (updateFileOnEdit) path else ""
|
val storePath = if (updateFileOnEdit) path else ""
|
||||||
val storeContent = if (updateFileOnEdit) "" else File(path).readText()
|
val storeContent = if (updateFileOnEdit) "" else File(path).readText()
|
||||||
|
|
||||||
val filename = path.getFilenameFromPath()
|
if (updateFileOnEdit) {
|
||||||
val note = Note(0, filename, storeContent, TYPE_NOTE, storePath)
|
activity.handleSAFDialog(File(path)) {
|
||||||
callback.invoke(note)
|
saveNote(storeContent, storePath)
|
||||||
dismiss()
|
}
|
||||||
|
} else {
|
||||||
|
saveNote(storeContent, storePath)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun saveNote(storeContent: String, storePath: String) {
|
||||||
|
val filename = path.getFilenameFromPath()
|
||||||
|
val note = Note(0, filename, storeContent, TYPE_NOTE, storePath)
|
||||||
|
callback.invoke(note)
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user