mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-26 16:18:22 +01:00
write the text to the selected file
This commit is contained in:
parent
6e67949f0a
commit
0c8003105a
@ -32,7 +32,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.simplemobiletools:commons:2.9.1'
|
||||
compile 'com.simplemobiletools:commons:2.9.2'
|
||||
compile 'com.facebook.stetho:stetho:1.4.1'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import com.simplemobiletools.notes.helpers.TYPE_NOTE
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import java.io.File
|
||||
import java.nio.charset.Charset
|
||||
|
||||
class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
val STORAGE_OPEN_FILE = 1
|
||||
@ -188,10 +189,37 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
|
||||
private fun saveAsFile() {
|
||||
SaveAsDialog(this, mCurrentNote.title) {
|
||||
val file = File(it)
|
||||
if (file.isDirectory) {
|
||||
toast(R.string.directory_exists)
|
||||
return@SaveAsDialog
|
||||
}
|
||||
|
||||
val text = getCurrentNoteText()
|
||||
if (needsStupidWritePermissions(it)) {
|
||||
if (isShowingPermDialog(file))
|
||||
return@SaveAsDialog
|
||||
|
||||
var document = getFileDocument(it, config.treeUri) ?: return@SaveAsDialog
|
||||
if (!file.exists()) {
|
||||
document = document.createFile("", file.name)
|
||||
}
|
||||
contentResolver.openOutputStream(document.uri).apply {
|
||||
write(text.toByteArray(Charset.forName("UTF-8")))
|
||||
flush()
|
||||
close()
|
||||
}
|
||||
} else {
|
||||
file.printWriter().use { out ->
|
||||
out.write(text)
|
||||
}
|
||||
}
|
||||
toast(R.string.file_saved)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCurrentNoteText() = (view_pager.adapter as NotesPagerAdapter).getCurrentNoteText(view_pager.currentItem)
|
||||
|
||||
private fun displayDeleteNotePrompt() {
|
||||
val message = String.format(getString(R.string.delete_note_prompt_message), mCurrentNote.title)
|
||||
ConfirmationDialog(this, message) {
|
||||
@ -230,7 +258,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
}
|
||||
|
||||
private fun shareText() {
|
||||
val text = (view_pager.adapter as NotesPagerAdapter).getCurrentNoteText(view_pager.currentItem)
|
||||
val text = getCurrentNoteText()
|
||||
if (text.isEmpty()) {
|
||||
toast(R.string.cannot_share_empty_text)
|
||||
return
|
||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.notes.dialogs
|
||||
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.notes.R
|
||||
@ -39,6 +40,7 @@ class SaveAsDialog(val activity: SimpleActivity, val noteTitle: String, val call
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
activity.setupDialogStuff(view, this, R.string.save_as)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||
val filename = view.file_name.value
|
||||
|
Loading…
x
Reference in New Issue
Block a user