mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-25 12:38:45 +02:00
write the text to the selected file
This commit is contained in:
parent
6e67949f0a
commit
0c8003105a
@ -32,7 +32,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.simplemobiletools:commons:2.9.1'
|
compile 'com.simplemobiletools:commons:2.9.2'
|
||||||
compile 'com.facebook.stetho:stetho:1.4.1'
|
compile 'com.facebook.stetho:stetho:1.4.1'
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
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 com.simplemobiletools.notes.models.Note
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||||
val STORAGE_OPEN_FILE = 1
|
val STORAGE_OPEN_FILE = 1
|
||||||
@ -188,9 +189,36 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
|||||||
|
|
||||||
private fun saveAsFile() {
|
private fun saveAsFile() {
|
||||||
SaveAsDialog(this, mCurrentNote.title) {
|
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() {
|
private fun displayDeleteNotePrompt() {
|
||||||
val message = String.format(getString(R.string.delete_note_prompt_message), mCurrentNote.title)
|
val message = String.format(getString(R.string.delete_note_prompt_message), mCurrentNote.title)
|
||||||
@ -230,7 +258,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun shareText() {
|
private fun shareText() {
|
||||||
val text = (view_pager.adapter as NotesPagerAdapter).getCurrentNoteText(view_pager.currentItem)
|
val text = getCurrentNoteText()
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
toast(R.string.cannot_share_empty_text)
|
toast(R.string.cannot_share_empty_text)
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.notes.dialogs
|
|||||||
|
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.WindowManager
|
||||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.notes.R
|
import com.simplemobiletools.notes.R
|
||||||
@ -39,6 +40,7 @@ class SaveAsDialog(val activity: SimpleActivity, val noteTitle: String, val call
|
|||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.create().apply {
|
.create().apply {
|
||||||
|
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||||
activity.setupDialogStuff(view, this, R.string.save_as)
|
activity.setupDialogStuff(view, this, R.string.save_as)
|
||||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||||
val filename = view.file_name.value
|
val filename = view.file_name.value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user