mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-12 22:50:07 +01:00
commit
3801fec5cf
@ -14,10 +14,7 @@ import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_LEAK_CANARY
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_RTL
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_STETHO
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.models.FAQItem
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
@ -138,6 +135,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
R.id.rename_note -> displayRenameDialog()
|
||||
R.id.share -> shareText()
|
||||
R.id.open_file -> tryOpenFile()
|
||||
R.id.import_folder -> tryOpenFolder()
|
||||
R.id.export_as_file -> tryExportAsFile()
|
||||
R.id.export_all_notes -> tryExportAllNotes()
|
||||
R.id.delete_note -> displayDeleteNotePrompt()
|
||||
@ -309,6 +307,13 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun openFolder(path: String, onChecksPassed: (file: File) -> Unit) {
|
||||
val file = File(path)
|
||||
if (file.isDirectory) {
|
||||
onChecksPassed(file)
|
||||
}
|
||||
}
|
||||
|
||||
private fun importFileWithSync(uri: Uri) {
|
||||
when (uri.scheme) {
|
||||
"file" -> openPath(uri.path)
|
||||
@ -334,6 +339,31 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryOpenFolder() {
|
||||
handlePermission(PERMISSION_READ_STORAGE) {
|
||||
if (it) {
|
||||
openFolder()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun openFolder() {
|
||||
FilePickerDialog(this, pickFile = false) {
|
||||
openFolder(it) {
|
||||
ImportFolderDialog(this, it.path) {
|
||||
mNotes = dbHelper.getNotes()
|
||||
showSaveButton = false
|
||||
invalidateOptionsMenu()
|
||||
initViewPager()
|
||||
updateSelectedNote(it)
|
||||
view_pager.onGlobalLayout {
|
||||
mAdapter?.focusEditText(getNoteIndexWithId(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryExportAsFile() {
|
||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||
if (it) {
|
||||
|
@ -0,0 +1,72 @@
|
||||
package com.simplemobiletools.notes.dialogs
|
||||
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.extensions.dbHelper
|
||||
import com.simplemobiletools.notes.helpers.TYPE_NOTE
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
import kotlinx.android.synthetic.main.dialog_import_folder.view.*
|
||||
import java.io.File
|
||||
|
||||
class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: (id: Int) -> Unit) : AlertDialog.Builder(activity) {
|
||||
private var dialog: AlertDialog
|
||||
|
||||
init {
|
||||
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_folder, null) as ViewGroup).apply {
|
||||
open_file_filename.text = activity.humanizePath(path)
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.import_folder) {
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val updateFilesOnEdit = view.open_file_type.checkedRadioButtonId == R.id.open_file_update_file
|
||||
saveFolder(updateFilesOnEdit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveFolder(updateFilesOnEdit: Boolean) {
|
||||
val folder = File(path)
|
||||
var lastSavedNoteId = -1;
|
||||
folder.listFiles({ file ->
|
||||
val filename = file.path.getFilenameFromPath()
|
||||
when {
|
||||
filename.isImageVideoGif() -> false
|
||||
file.length() > 10 * 1000 * 1000 -> false
|
||||
activity.dbHelper.doesTitleExist(filename) -> false
|
||||
else -> true
|
||||
}
|
||||
}).forEach {
|
||||
val storePath = if (updateFilesOnEdit) it.path else ""
|
||||
val storeContent = if (updateFilesOnEdit) "" else it.readText()
|
||||
|
||||
if (updateFilesOnEdit) {
|
||||
activity.handleSAFDialog(path) {
|
||||
lastSavedNoteId = saveNote(storeContent, storePath)
|
||||
}
|
||||
} else {
|
||||
lastSavedNoteId = saveNote(storeContent, storePath)
|
||||
}
|
||||
}
|
||||
|
||||
if (lastSavedNoteId != -1) {
|
||||
callback(lastSavedNoteId)
|
||||
}
|
||||
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
private fun saveNote(storeContent: String, storePath: String): Int {
|
||||
val filename = storePath.getFilenameFromPath()
|
||||
val note = Note(0, filename, storeContent, TYPE_NOTE, storePath)
|
||||
val id = activity.dbHelper.insertNote(note)
|
||||
return id
|
||||
}
|
||||
}
|
51
app/src/main/res/layout/dialog_import_folder.xml
Normal file
51
app/src/main/res/layout/dialog_import_folder.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/open_file_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/open_file_filename_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/folder"
|
||||
android:textSize="@dimen/smaller_text_size"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/open_file_filename"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/small_margin"
|
||||
android:paddingTop="@dimen/small_margin"/>
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/open_file_type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/open_file_update_file"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/update_file_at_note"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/open_file_content_only"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/only_import_file_content"/>
|
||||
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
@ -30,6 +30,10 @@
|
||||
android:id="@+id/open_file"
|
||||
android:title="@string/open_file"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/import_folder"
|
||||
android:title="@string/import_folder"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/export_as_file"
|
||||
android:title="@string/export_as_file"
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Eksporter alle noter som filer</string>
|
||||
<string name="import_notes">Importer flere filer som noter</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Alle Notizen als Dateien exportieren</string>
|
||||
<string name="import_notes">Mehrere Dateien als Notizen importieren</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Exportar todas las notas como archivos</string>
|
||||
<string name="import_notes">Importar múltiples archivos como notas</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Exporter toutes les notes en tant que fichiers</string>
|
||||
<string name="import_notes">Importer plusieurs fichiers en tant que notes</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -48,6 +48,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Exportar todas as notas como ficheiros</string>
|
||||
<string name="import_notes">Importar varios ficheiros como notas</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Izvezi sve bilješke kao datoteke</string>
|
||||
<string name="import_notes">Uvezi više datoteka kao bilješke</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Export all notes as files</string>
|
||||
<string name="import_notes">Import multiple files as notes</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Export all notes as files</string>
|
||||
<string name="import_notes">Import multiple files as notes</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Export all notes as files</string>
|
||||
<string name="import_notes">Import multiple files as notes</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Eksportuoti visus užrašus kaip bylas</string>
|
||||
<string name="import_notes">Importuoti keletą bylų, kaip užrašus</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Export all notes as files</string>
|
||||
<string name="import_notes">Import multiple files as notes</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Eksportuj wszystkie notatki jako pliki</string>
|
||||
<string name="import_notes">Importuj pliki jako notatki</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Export all notes as files</string>
|
||||
<string name="import_notes">Import multiple files as notes</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Exportar todas as notas como ficheiros</string>
|
||||
<string name="import_notes">Importar ficheiros para notas</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Экспортировать все заметки в файлы</string>
|
||||
<string name="import_notes">Импортировать несколько файлов в заметки</string>
|
||||
<string name="import_folder">Импортировать папку</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Exportovať všetky poznámky ako súbory</string>
|
||||
<string name="import_notes">Importovať viacero súborov ako poznámky</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Exportera alla anteckningar som filer</string>
|
||||
<string name="import_notes">Importera flera filer som anteckningar</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Tüm notları dosya olarak dışa aktar</string>
|
||||
<string name="import_notes">Birden çok dosyayı not olarak içe aktar</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Export all notes as files</string>
|
||||
<string name="import_notes">Import multiple files as notes</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">將全部筆記匯出成檔案</string>
|
||||
<string name="import_notes">將多個檔案匯入成筆記</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -45,6 +45,7 @@
|
||||
<!-- Import / Export -->
|
||||
<string name="export_all_notes">Export all notes as files</string>
|
||||
<string name="import_notes">Import multiple files as notes</string>
|
||||
<string name="import_folder">Import folder</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user