From 153fd8115006dcbacac77df7be1e33fba0709573 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 5 Apr 2018 15:47:07 +0200 Subject: [PATCH] update commons to 3.18.9 --- app/build.gradle | 2 +- .../notes/activities/MainActivity.kt | 20 ++-- .../notes/activities/SettingsActivity.kt | 3 +- .../activities/WidgetConfigureActivity.kt | 16 ++-- .../notes/dialogs/DeleteNoteDialog.kt | 4 +- .../notes/dialogs/ExportFileDialog.kt | 43 +++++---- .../notes/dialogs/ExportFilesDialog.kt | 24 ++--- .../notes/dialogs/NewNoteDialog.kt | 26 ++--- .../notes/dialogs/OpenFileDialog.kt | 24 ++--- .../notes/dialogs/OpenNoteDialog.kt | 4 +- .../notes/dialogs/RenameNoteDialog.kt | 71 +++++++------- app/src/main/res/layout/activity_settings.xml | 94 +++++++++++-------- build.gradle | 4 +- 13 files changed, 175 insertions(+), 160 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b3eac872..c0d11770 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.13.9' + implementation 'com.simplemobiletools:commons:3.18.9' implementation 'com.facebook.stetho:stetho:1.5.0' debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion" diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt index b10a68cd..81af578e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -14,7 +14,10 @@ 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.* +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.models.FAQItem import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.models.RadioItem @@ -44,7 +47,6 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { private var noteViewWithTextSelected: MyEditText? = null private var wasInit = false - private var storedUseEnglish = false private var storedEnableLineWrap = true private var showSaveButton = false private var saveNoteButton: MenuItem? = null @@ -84,11 +86,6 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { override fun onResume() { super.onResume() - if (storedUseEnglish != config.useEnglish) { - restartActivity() - return - } - if (storedEnableLineWrap != config.enableLineWrap) { initViewPager() } @@ -173,7 +170,6 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { private fun storeStateVariables() { config.apply { - storedUseEnglish = useEnglish storedEnableLineWrap = enableLineWrap } } @@ -241,7 +237,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { } private fun displayRenameDialog() { - RenameNoteDialog(this, dbHelper, mCurrentNote) { + RenameNoteDialog(this, mCurrentNote) { mCurrentNote = it initViewPager() } @@ -276,10 +272,10 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { private fun launchAbout() { val faqItems = arrayListOf( FAQItem(R.string.faq_1_title_commons, R.string.faq_1_text_commons), - FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons), - FAQItem(R.string.faq_4_title_commons, R.string.faq_4_text_commons) + FAQItem(R.string.faq_4_title_commons, R.string.faq_4_text_commons), + FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons) ) - startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_STETHO or LICENSE_RTL or LICENSE_LEAK_CANARY, BuildConfig.VERSION_NAME, faqItems) + startAboutActivity(R.string.app_name, LICENSE_STETHO or LICENSE_RTL or LICENSE_LEAK_CANARY, BuildConfig.VERSION_NAME, faqItems) } private fun tryOpenFile() { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt index 97354d88..31ee59db 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt @@ -6,7 +6,6 @@ import android.view.View import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.updateTextColors -import com.simplemobiletools.commons.extensions.useEnglishToggled import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.notes.R import com.simplemobiletools.notes.extensions.config @@ -61,7 +60,7 @@ class SettingsActivity : SimpleActivity() { settings_use_english_holder.setOnClickListener { settings_use_english.toggle() config.useEnglish = settings_use_english.isChecked - useEnglishToggled() + System.exit(0) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/WidgetConfigureActivity.kt index 861f771e..cd6ce40f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/WidgetConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/WidgetConfigureActivity.kt @@ -111,16 +111,20 @@ class WidgetConfigureActivity : SimpleActivity() { } private fun pickBackgroundColor() { - ColorPickerDialog(this, mBgColorWithoutTransparency) { - mBgColorWithoutTransparency = it - updateBackgroundColor() + ColorPickerDialog(this, mBgColorWithoutTransparency) { wasPositivePressed, color -> + if (wasPositivePressed) { + mBgColorWithoutTransparency = color + updateBackgroundColor() + } } } private fun pickTextColor() { - ColorPickerDialog(this, mTextColor) { - mTextColor = it - updateTextColor() + ColorPickerDialog(this, mTextColor) { wasPositivePressed, color -> + if (wasPositivePressed) { + mTextColor = color + updateTextColor() + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/DeleteNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/DeleteNoteDialog.kt index fb094382..550288b0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/DeleteNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/DeleteNoteDialog.kt @@ -25,8 +25,8 @@ class DeleteNoteDialog(val activity: SimpleActivity, val note: Note, val callbac .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed(view.delete_note_checkbox.isChecked) }) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this) - } + activity.setupDialogStuff(view, this) + } } private fun dialogConfirmed(deleteFile: Boolean) { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ExportFileDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ExportFileDialog.kt index c82a1b5c..b342ff52 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ExportFileDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ExportFileDialog.kt @@ -1,7 +1,6 @@ package com.simplemobiletools.notes.dialogs import android.support.v7.app.AlertDialog -import android.view.WindowManager import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.notes.R @@ -32,29 +31,29 @@ class ExportFileDialog(val activity: SimpleActivity, val note: Note, val callbac .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.export_as_file) { - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val filename = view.file_name.value - val extension = view.file_extension.value + activity.setupDialogStuff(view, this, R.string.export_as_file) { + showKeyboard(view.file_name) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val filename = view.file_name.value + val extension = view.file_extension.value - if (filename.isEmpty()) { - activity.toast(R.string.filename_cannot_be_empty) - return@setOnClickListener + if (filename.isEmpty()) { + activity.toast(R.string.filename_cannot_be_empty) + return@setOnClickListener + } + + val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension" + if (!fullFilename.isAValidFilename()) { + activity.toast(String.format(activity.getString(R.string.filename_invalid_characters_placeholder, fullFilename))) + return@setOnClickListener + } + + activity.config.lastUsedExtension = extension + activity.config.lastUsedSavePath = realPath + callback("$realPath/$fullFilename") + dismiss() + } } - - val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension" - if (!fullFilename.isAValidFilename()) { - activity.toast(String.format(activity.getString(R.string.filename_invalid_characters_placeholder, fullFilename))) - return@setOnClickListener - } - - activity.config.lastUsedExtension = extension - activity.config.lastUsedSavePath = realPath - callback("$realPath/$fullFilename") - dismiss() } - } - } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ExportFilesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ExportFilesDialog.kt index ea69f64a..8b195ed8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ExportFilesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ExportFilesDialog.kt @@ -1,10 +1,10 @@ package com.simplemobiletools.notes.dialogs import android.support.v7.app.AlertDialog -import android.view.WindowManager import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.humanizePath import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.showKeyboard import com.simplemobiletools.commons.extensions.value import com.simplemobiletools.notes.R import com.simplemobiletools.notes.activities.SimpleActivity @@ -31,18 +31,18 @@ class ExportFilesDialog(val activity: SimpleActivity, val notes: ArrayList .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.export_as_file) { - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - activity.handleSAFDialog(realPath) { - val extension = view.file_extension.value - activity.config.lastUsedExtension = extension - activity.config.lastUsedSavePath = realPath - callback(realPath, extension) - dismiss() + activity.setupDialogStuff(view, this, R.string.export_as_file) { + showKeyboard(view.file_extension) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + activity.handleSAFDialog(realPath) { + val extension = view.file_extension.value + activity.config.lastUsedExtension = extension + activity.config.lastUsedSavePath = realPath + callback(realPath, extension) + dismiss() + } + } } } - } - } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/NewNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/NewNoteDialog.kt index b9da0d24..213d0c50 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/NewNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/NewNoteDialog.kt @@ -3,8 +3,8 @@ package com.simplemobiletools.notes.dialogs import android.app.Activity import android.content.DialogInterface.BUTTON_POSITIVE import android.support.v7.app.AlertDialog -import android.view.WindowManager import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.showKeyboard import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.value import com.simplemobiletools.notes.R @@ -19,20 +19,20 @@ class NewNoteDialog(val activity: Activity, val db: DBHelper, callback: (title: .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.new_note) { - getButton(BUTTON_POSITIVE).setOnClickListener { - val title = view.note_name.value - when { - title.isEmpty() -> activity.toast(R.string.no_title) - db.doesTitleExist(title) -> activity.toast(R.string.title_taken) - else -> { - callback(title) - dismiss() + activity.setupDialogStuff(view, this, R.string.new_note) { + showKeyboard(view.note_name) + getButton(BUTTON_POSITIVE).setOnClickListener { + val title = view.note_name.value + when { + title.isEmpty() -> activity.toast(R.string.no_title) + db.doesTitleExist(title) -> activity.toast(R.string.title_taken) + else -> { + callback(title) + dismiss() + } + } } } } - } - } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenFileDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenFileDialog.kt index ea7673cd..14e190b8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenFileDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenFileDialog.kt @@ -25,22 +25,22 @@ class OpenFileDialog(val activity: SimpleActivity, val path: String, val callbac .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this, R.string.open_file) { - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val updateFileOnEdit = view.open_file_type.checkedRadioButtonId == open_file_update_file - val storePath = if (updateFileOnEdit) path else "" - val storeContent = if (updateFileOnEdit) "" else File(path).readText() + activity.setupDialogStuff(view, this, R.string.open_file) { + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val updateFileOnEdit = view.open_file_type.checkedRadioButtonId == open_file_update_file + val storePath = if (updateFileOnEdit) path else "" + val storeContent = if (updateFileOnEdit) "" else File(path).readText() - if (updateFileOnEdit) { - activity.handleSAFDialog(path) { - saveNote(storeContent, storePath) + if (updateFileOnEdit) { + activity.handleSAFDialog(path) { + saveNote(storeContent, storePath) + } + } else { + saveNote(storeContent, storePath) + } } - } else { - saveNote(storeContent, storePath) } } - } - } } private fun saveNote(storeContent: String, storePath: String) { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenNoteDialog.kt index 72e48f8f..f23d7b69 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenNoteDialog.kt @@ -47,7 +47,7 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> U dialog = AlertDialog.Builder(activity) .create().apply { - activity.setupDialogStuff(view, this, R.string.pick_a_note) - } + activity.setupDialogStuff(view, this, R.string.pick_a_note) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt index 2a38927b..c28cf766 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt @@ -2,16 +2,15 @@ package com.simplemobiletools.notes.dialogs import android.content.DialogInterface.BUTTON_POSITIVE import android.support.v7.app.AlertDialog -import android.view.WindowManager import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.notes.R import com.simplemobiletools.notes.activities.SimpleActivity -import com.simplemobiletools.notes.helpers.DBHelper +import com.simplemobiletools.notes.extensions.dbHelper import com.simplemobiletools.notes.models.Note import kotlinx.android.synthetic.main.dialog_new_note.view.* import java.io.File -class RenameNoteDialog(val activity: SimpleActivity, val db: DBHelper, val note: Note, callback: (note: Note) -> Unit) { +class RenameNoteDialog(val activity: SimpleActivity, val note: Note, callback: (note: Note) -> Unit) { init { val view = activity.layoutInflater.inflate(R.layout.dialog_rename_note, null) @@ -21,46 +20,46 @@ class RenameNoteDialog(val activity: SimpleActivity, val db: DBHelper, val note: .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.rename_note) { - getButton(BUTTON_POSITIVE).setOnClickListener { - val title = view.note_name.value - when { - title.isEmpty() -> activity.toast(R.string.no_title) - db.doesTitleExist(title) -> activity.toast(R.string.title_taken) - else -> { - note.title = title - val path = note.path - if (path.isNotEmpty()) { - if (title.isEmpty()) { - activity.toast(R.string.filename_cannot_be_empty) - return@setOnClickListener - } + activity.setupDialogStuff(view, this, R.string.rename_note) { + showKeyboard(view.note_name) + getButton(BUTTON_POSITIVE).setOnClickListener { + val title = view.note_name.value + when { + title.isEmpty() -> activity.toast(R.string.no_title) + activity.dbHelper.doesTitleExist(title) -> activity.toast(R.string.title_taken) + else -> { + note.title = title + val path = note.path + if (path.isNotEmpty()) { + if (title.isEmpty()) { + activity.toast(R.string.filename_cannot_be_empty) + return@setOnClickListener + } - val file = File(path) - val newFile = File(file.parent, title) - if (!newFile.name.isAValidFilename()) { - activity.toast(R.string.invalid_name) - return@setOnClickListener - } + val file = File(path) + val newFile = File(file.parent, title) + if (!newFile.name.isAValidFilename()) { + activity.toast(R.string.invalid_name) + return@setOnClickListener + } - activity.renameFile(file.absolutePath, newFile.absolutePath) { - if (it) { - note.path = newFile.absolutePath - db.updateNotePath(note) - } else { - activity.toast(R.string.rename_file_error) - return@renameFile + activity.renameFile(file.absolutePath, newFile.absolutePath) { + if (it) { + note.path = newFile.absolutePath + activity.dbHelper.updateNotePath(note) + } else { + activity.toast(R.string.rename_file_error) + return@renameFile + } + } } + activity.dbHelper.updateNoteTitle(note) + dismiss() + callback(note) } } - db.updateNoteTitle(note) - dismiss() - callback(note) } } } - } - } } } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 37e90a9c..bc76afcf 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -17,7 +17,10 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/medium_margin" android:background="?attr/selectableItemBackground" - android:padding="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin"> + android:paddingBottom="@dimen/activity_margin" + android:paddingLeft="@dimen/normal_margin" + android:paddingRight="@dimen/normal_margin" + android:paddingTop="@dimen/activity_margin">