From 797ac60d568ed0dc0744d58338e5096155cbf78a Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 11 Jul 2022 23:28:40 +0200 Subject: [PATCH] updating commons with some material elements --- app/build.gradle | 2 +- .../notes/pro/activities/MainActivity.kt | 112 +-- .../notes/pro/activities/SettingsActivity.kt | 5 +- .../pro/activities/WidgetConfigureActivity.kt | 1 + .../notes/pro/dialogs/DeleteNoteDialog.kt | 5 +- .../notes/pro/dialogs/ExportFileDialog.kt | 48 +- .../notes/pro/dialogs/ExportFilesDialog.kt | 33 +- .../notes/pro/dialogs/ImportFolderDialog.kt | 30 +- .../pro/dialogs/NewChecklistItemDialog.kt | 19 +- .../notes/pro/dialogs/NewNoteDialog.kt | 33 +- .../notes/pro/dialogs/OpenFileDialog.kt | 35 +- .../notes/pro/dialogs/OpenNoteDialog.kt | 7 +- .../pro/dialogs/RenameChecklistItemDialog.kt | 34 +- .../notes/pro/dialogs/RenameNoteDialog.kt | 12 +- .../notes/pro/dialogs/SortChecklistDialog.kt | 7 +- .../notes/pro/fragments/TextFragment.kt | 2 +- app/src/main/res/layout/activity_main.xml | 61 +- app/src/main/res/layout/activity_settings.xml | 681 +++++++++--------- app/src/main/res/layout/dialog_open_note.xml | 7 +- app/src/main/res/layout/open_note_item.xml | 3 +- app/src/main/res/layout/widget_config.xml | 261 +++---- 21 files changed, 742 insertions(+), 656 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8c674df5..804de00b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:e1e07bf005' + implementation 'com.github.SimpleMobileTools:Simple-Commons:4f9c2f94ff' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.documentfile:documentfile:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index b9c2ad0f..53e27f38 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -87,6 +87,8 @@ class MainActivity : SimpleActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) appLaunched(BuildConfig.APPLICATION_ID) + setupOptionsMenu() + refreshMenuItems() searchQueryET = findViewById(R.id.search_query) searchPrevBtn = findViewById(R.id.search_previous) @@ -113,11 +115,12 @@ class MainActivity : SimpleActivity() { override fun onResume() { super.onResume() + setupToolbar(main_toolbar) if (storedEnableLineWrap != config.enableLineWrap) { initViewPager() } - invalidateOptionsMenu() + refreshMenuItems() pager_title_strip.apply { setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize()) setGravity(Gravity.CENTER_VERTICAL) @@ -168,11 +171,26 @@ class MainActivity : SimpleActivity() { return true } - override fun onPrepareOptionsMenu(menu: Menu): Boolean { + private fun refreshMenuItems() { val multipleNotesExist = mNotes.size > 1 val isCurrentItemChecklist = isCurrentItemChecklist() - menu.apply { + main_toolbar.menu.apply { + val areButtonsVisible = (showRedoButton || showUndoButton) && mCurrentNote.type == NoteType.TYPE_TEXT.value + findItem(R.id.undo).apply { + isVisible = areButtonsVisible + isEnabled = showUndoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value + icon.alpha = if (isEnabled) 255 else 127 + } + + findItem(R.id.redo).apply { + isVisible = areButtonsVisible + isEnabled = showRedoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value + icon.alpha = if (isEnabled) 255 else 127 + } + } + + main_toolbar.menu.apply { findItem(R.id.rename_note).isVisible = multipleNotesExist findItem(R.id.open_note).isVisible = multipleNotesExist findItem(R.id.delete_note).isVisible = multipleNotesExist @@ -183,49 +201,51 @@ class MainActivity : SimpleActivity() { findItem(R.id.sort_checklist).isVisible = isCurrentItemChecklist findItem(R.id.import_folder).isVisible = !isQPlus() findItem(R.id.import_notes).isVisible = isQPlus() - findItem(R.id.lock_note).isVisible = mNotes.isNotEmpty() && !mCurrentNote.isLocked() - findItem(R.id.unlock_note).isVisible = mNotes.isNotEmpty() && mCurrentNote.isLocked() + findItem(R.id.lock_note).isVisible = mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && !mCurrentNote.isLocked()) + findItem(R.id.unlock_note).isVisible = mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && mCurrentNote.isLocked()) saveNoteButton = findItem(R.id.save_note) - saveNoteButton!!.isVisible = !config.autosaveNotes && showSaveButton && mCurrentNote.type == NoteType.TYPE_TEXT.value + saveNoteButton!!.isVisible = + !config.autosaveNotes && showSaveButton && (::mCurrentNote.isInitialized && mCurrentNote.type == NoteType.TYPE_TEXT.value) } pager_title_strip.beVisibleIf(multipleNotesExist) - return super.onPrepareOptionsMenu(menu) } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (config.autosaveNotes && item.itemId != R.id.undo && item.itemId != R.id.redo) { - saveCurrentNote(false) - } + private fun setupOptionsMenu() { + main_toolbar.setOnMenuItemClickListener { menuItem -> + if (config.autosaveNotes && menuItem.itemId != R.id.undo && menuItem.itemId != R.id.redo) { + saveCurrentNote(false) + } - val fragment = getCurrentFragment() - when (item.itemId) { - R.id.open_search -> fragment?.handleUnlocking { openSearch() } - R.id.open_note -> displayOpenNoteDialog() - R.id.save_note -> fragment?.handleUnlocking { saveNote() } - R.id.undo -> undo() - R.id.redo -> redo() - R.id.new_note -> displayNewNoteDialog() - R.id.rename_note -> fragment?.handleUnlocking { displayRenameDialog() } - R.id.share -> fragment?.handleUnlocking { shareText() } - R.id.lock_note -> lockNote() - R.id.unlock_note -> unlockNote() - R.id.open_file -> tryOpenFile() - R.id.import_folder -> openFolder() - R.id.export_as_file -> fragment?.handleUnlocking { tryExportAsFile() } - R.id.export_all_notes -> tryExportAllNotes() - R.id.export_notes -> tryExportNotes() - R.id.import_notes -> tryImportNotes() - R.id.print -> fragment?.handleUnlocking { printText() } - R.id.delete_note -> fragment?.handleUnlocking { displayDeleteNotePrompt() } - R.id.settings -> launchSettings() - R.id.about -> launchAbout() - R.id.remove_done_items -> fragment?.handleUnlocking { removeDoneItems() } - R.id.sort_checklist -> fragment?.handleUnlocking { displaySortChecklistDialog() } - else -> return super.onOptionsItemSelected(item) + val fragment = getCurrentFragment() + when (menuItem.itemId) { + R.id.open_search -> fragment?.handleUnlocking { openSearch() } + R.id.open_note -> displayOpenNoteDialog() + R.id.save_note -> fragment?.handleUnlocking { saveNote() } + R.id.undo -> undo() + R.id.redo -> redo() + R.id.new_note -> displayNewNoteDialog() + R.id.rename_note -> fragment?.handleUnlocking { displayRenameDialog() } + R.id.share -> fragment?.handleUnlocking { shareText() } + R.id.lock_note -> lockNote() + R.id.unlock_note -> unlockNote() + R.id.open_file -> tryOpenFile() + R.id.import_folder -> openFolder() + R.id.export_as_file -> fragment?.handleUnlocking { tryExportAsFile() } + R.id.export_all_notes -> tryExportAllNotes() + R.id.export_notes -> tryExportNotes() + R.id.import_notes -> tryImportNotes() + R.id.print -> fragment?.handleUnlocking { printText() } + R.id.delete_note -> fragment?.handleUnlocking { displayDeleteNotePrompt() } + R.id.settings -> launchSettings() + R.id.about -> launchAbout() + R.id.remove_done_items -> fragment?.handleUnlocking { removeDoneItems() } + R.id.sort_checklist -> fragment?.handleUnlocking { displaySortChecklistDialog() } + else -> return@setOnMenuItemClickListener false + } + return@setOnMenuItemClickListener true } - return true } // https://code.google.com/p/android/issues/detail?id=191430 quickfix @@ -286,7 +306,7 @@ class MainActivity : SimpleActivity() { } } - private fun isCurrentItemChecklist() = if (this::mCurrentNote.isInitialized) mCurrentNote.type == NoteType.TYPE_CHECKLIST.value else false + private fun isCurrentItemChecklist() = if (::mCurrentNote.isInitialized) mCurrentNote.type == NoteType.TYPE_CHECKLIST.value else false @SuppressLint("NewApi") private fun checkShortcuts() { @@ -422,7 +442,7 @@ class MainActivity : SimpleActivity() { .forEach(::removeProtection) mNotes = notes - invalidateOptionsMenu() + refreshMenuItems() mCurrentNote = mNotes[0] mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, this) view_pager.apply { @@ -433,7 +453,7 @@ class MainActivity : SimpleActivity() { onPageChangeListener { mCurrentNote = mNotes[it] config.currentNoteId = mCurrentNote.id!! - invalidateOptionsMenu() + refreshMenuItems() } } @@ -463,7 +483,7 @@ class MainActivity : SimpleActivity() { view_pager.onPageChangeListener { currentTextFragment?.removeTextWatcher() currentNotesView()?.let { noteView -> - noteView.text.clearBackgroundSpans() + noteView.text!!.clearBackgroundSpans() } closeSearch() @@ -483,7 +503,7 @@ class MainActivity : SimpleActivity() { private fun searchTextChanged(text: String) { currentNotesView()?.let { noteView -> currentTextFragment?.removeTextWatcher() - noteView.text.clearBackgroundSpans() + noteView.text!!.clearBackgroundSpans() if (text.isNotBlank() && text.length > 1) { searchMatches = noteView.value.searchMatches(text) @@ -1263,7 +1283,7 @@ class MainActivity : SimpleActivity() { private fun saveNote() { saveCurrentNote(true) showSaveButton = false - invalidateOptionsMenu() + refreshMenuItems() } private fun undo() { @@ -1309,7 +1329,7 @@ class MainActivity : SimpleActivity() { mCurrentNote.protectionHash = hash mCurrentNote.protectionType = type NotesHelper(this).insertOrUpdateNote(mCurrentNote) { - invalidateOptionsMenu() + refreshMenuItems() } } } @@ -1333,7 +1353,7 @@ class MainActivity : SimpleActivity() { shouldShowLockedContent = true checkLockState() } - invalidateOptionsMenu() + refreshMenuItems() } } } @@ -1359,7 +1379,7 @@ class MainActivity : SimpleActivity() { } if (shouldRecreateMenu) { - invalidateOptionsMenu() + refreshMenuItems() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt index c8c24b7f..16046e98 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt @@ -6,6 +6,7 @@ import android.view.Menu import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS +import com.simplemobiletools.commons.helpers.NavigationIcon import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.isOreoPlus import com.simplemobiletools.commons.models.RadioItem @@ -26,6 +27,7 @@ class SettingsActivity : SimpleActivity() { override fun onResume() { super.onResume() + setupToolbar(settings_toolbar, NavigationIcon.Arrow) setupCustomizeColors() setupUseEnglish() @@ -42,8 +44,7 @@ class SettingsActivity : SimpleActivity() { setupCursorPlacement() setupIncognitoMode() setupCustomizeWidgetColors() - updateTextColors(settings_scrollview) - invalidateOptionsMenu() + updateTextColors(settings_nested_scrollview) arrayOf( settings_color_customization_label, diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt index 3426aba7..9e6ac6f2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt @@ -73,6 +73,7 @@ class WidgetConfigureActivity : SimpleActivity() { override fun onResume() { super.onResume() text_note_view.setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize()) + setupToolbar(config_toolbar) } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/DeleteNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/DeleteNoteDialog.kt index 5e05e720..fd13c1df 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/DeleteNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/DeleteNoteDialog.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.extensions.beVisible +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.notes.pro.R import com.simplemobiletools.notes.pro.activities.SimpleActivity @@ -24,10 +25,10 @@ class DeleteNoteDialog(val activity: SimpleActivity, val note: Note, val callbac delete_note_description.text = message } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed(view.delete_note_checkbox.isChecked) } .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFileDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFileDialog.kt index d96b65fd..81c54dda 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFileDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFileDialog.kt @@ -27,33 +27,33 @@ class ExportFileDialog(val activity: SimpleActivity, val note: Note, val callbac } } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - 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 + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.export_as_file) { alertDialog -> + alertDialog.showKeyboard(view.file_name) + alertDialog.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 - } - - 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() + 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") + alertDialog.dismiss() } } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFilesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFilesDialog.kt index b01f8028..bd8896fa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFilesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFilesDialog.kt @@ -2,10 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs import androidx.appcompat.app.AlertDialog 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.commons.extensions.* import com.simplemobiletools.notes.pro.R import com.simplemobiletools.notes.pro.activities.SimpleActivity import com.simplemobiletools.notes.pro.extensions.config @@ -27,22 +24,22 @@ class ExportFilesDialog(val activity: SimpleActivity, val notes: ArrayList } } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - 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() - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.export_as_file) { alertDialog -> + alertDialog.showKeyboard(view.file_extension) + alertDialog.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) + alertDialog.dismiss() } } } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ImportFolderDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ImportFolderDialog.kt index a0a518ff..f722c5a0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ImportFolderDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ImportFolderDialog.kt @@ -2,10 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import com.simplemobiletools.commons.extensions.getFilenameFromPath -import com.simplemobiletools.commons.extensions.humanizePath -import com.simplemobiletools.commons.extensions.isMediaFile -import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PROTECTION_NONE import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.notes.pro.R @@ -19,26 +16,27 @@ import kotlinx.android.synthetic.main.dialog_import_folder.view.* import java.io.File class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) { - private var dialog: AlertDialog + private var dialog: AlertDialog? = null 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 - ensureBackgroundThread { - saveFolder(updateFilesOnEdit) - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.import_folder) { alertDialog -> + dialog = alertDialog + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val updateFilesOnEdit = view.open_file_type.checkedRadioButtonId == R.id.open_file_update_file + ensureBackgroundThread { + saveFolder(updateFilesOnEdit) } } } + } } private fun saveFolder(updateFilesOnEdit: Boolean) { @@ -73,7 +71,7 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal activity.runOnUiThread { callback() - dialog.dismiss() + dialog?.dismiss() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewChecklistItemDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewChecklistItemDialog.kt index 88f64ff1..28cd499f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewChecklistItemDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewChecklistItemDialog.kt @@ -6,15 +6,14 @@ import android.view.KeyEvent import android.view.View import android.view.ViewGroup import android.view.inputmethod.EditorInfo -import android.widget.EditText -import androidx.appcompat.app.AlertDialog +import androidx.appcompat.widget.AppCompatEditText import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.notes.pro.R import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.* import kotlinx.android.synthetic.main.item_add_checklist.view.* class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayList) -> Unit) { - private val titles = mutableListOf() + private val titles = mutableListOf() private val textColor = activity.getProperTextColor() private val view: ViewGroup = activity.layoutInflater.inflate(R.layout.dialog_new_checklist_item, null) as ViewGroup @@ -28,19 +27,19 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis } } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.add_new_checklist_items) { - showKeyboard(titles.first()) - getButton(BUTTON_POSITIVE).setOnClickListener { + .apply { + activity.setupDialogStuff(view, this, R.string.add_new_checklist_items) { alertDialog -> + alertDialog.showKeyboard(titles.first()) + alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener { when { - titles.all { it.text.isEmpty() } -> activity.toast(R.string.empty_name) + titles.all { it.text!!.isEmpty() } -> activity.toast(R.string.empty_name) else -> { val titles = titles.map { it.text.toString() }.filter { it.isNotEmpty() }.toMutableList() as ArrayList callback(titles) - dismiss() + alertDialog.dismiss() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt index 5a2499f4..90ccaba9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt @@ -2,11 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs import android.app.Activity import android.content.DialogInterface.BUTTON_POSITIVE -import androidx.appcompat.app.AlertDialog -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.commons.extensions.* import com.simplemobiletools.commons.helpers.PROTECTION_NONE import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.notes.pro.R @@ -30,24 +26,29 @@ class NewNoteDialog(val activity: Activity, title: String? = null, val setCheckl view.note_title.setText(title) - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.new_note) { - showKeyboard(view.note_title) - getButton(BUTTON_POSITIVE).setOnClickListener { - val title = view.note_title.value + .apply { + activity.setupDialogStuff(view, this, R.string.new_note) { alertDialog -> + alertDialog.showKeyboard(view.note_title) + alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener { + val newTitle = view.note_title.value ensureBackgroundThread { when { - title.isEmpty() -> activity.toast(R.string.no_title) - activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken) + newTitle.isEmpty() -> activity.toast(R.string.no_title) + activity.notesDB.getNoteIdWithTitle(newTitle) != null -> activity.toast(R.string.title_taken) else -> { - val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value + val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) { + NoteType.TYPE_CHECKLIST.value + } else { + NoteType.TYPE_TEXT.value + } + activity.config.lastCreatedNoteType = type - val newNote = Note(null, title, "", type, "", PROTECTION_NONE, "") + val newNote = Note(null, newTitle, "", type, "", PROTECTION_NONE, "") callback(newNote) - dismiss() + alertDialog.dismiss() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenFileDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenFileDialog.kt index fbea6566..b610da99 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenFileDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenFileDialog.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs import android.view.ViewGroup import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.getFilenameFromPath import com.simplemobiletools.commons.extensions.humanizePath import com.simplemobiletools.commons.extensions.setupDialogStuff @@ -10,44 +11,44 @@ import com.simplemobiletools.notes.pro.R import com.simplemobiletools.notes.pro.activities.SimpleActivity import com.simplemobiletools.notes.pro.helpers.NoteType import com.simplemobiletools.notes.pro.models.Note -import kotlinx.android.synthetic.main.dialog_open_file.* import kotlinx.android.synthetic.main.dialog_open_file.view.* import java.io.File class OpenFileDialog(val activity: SimpleActivity, val path: String, val callback: (note: Note) -> Unit) : AlertDialog.Builder(activity) { - private var dialog: AlertDialog + private var dialog: AlertDialog? = null init { val view = (activity.layoutInflater.inflate(R.layout.dialog_open_file, 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.open_file) { - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val updateFileOnEdit = view.open_file_type.checkedRadioButtonId == open_file_update_file.id - val storePath = if (updateFileOnEdit) path else "" - val storeContent = if (updateFileOnEdit) "" else File(path).readText() + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.open_file) { alertDialog -> + dialog = alertDialog + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val updateFileOnEdit = view.open_file_type.checkedRadioButtonId == view.open_file_update_file.id + val storePath = if (updateFileOnEdit) path else "" + val storeContent = if (updateFileOnEdit) "" else File(path).readText() - if (updateFileOnEdit) { - activity.handleSAFDialog(path) { - saveNote(storeContent, storePath) - } - } else { + if (updateFileOnEdit) { + activity.handleSAFDialog(path) { saveNote(storeContent, storePath) } + } else { + saveNote(storeContent, storePath) } } } + } } private fun saveNote(storeContent: String, storePath: String) { val filename = path.getFilenameFromPath() val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT.value, storePath, PROTECTION_NONE, "") callback(note) - dialog.dismiss() + dialog?.dismiss() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt index e0fef706..325d1f62 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt @@ -57,9 +57,10 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long, new } } - dialog = AlertDialog.Builder(activity) - .create().apply { - activity.setupDialogStuff(view, this, R.string.open_note) + activity.getAlertDialogBuilder().apply { + activity.setupDialogStuff(view, this, R.string.open_note) { alertDialog -> + dialog = alertDialog } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/RenameChecklistItemDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/RenameChecklistItemDialog.kt index c6851bf9..c65ae193 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/RenameChecklistItemDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/RenameChecklistItemDialog.kt @@ -2,11 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs import android.app.Activity import android.content.DialogInterface.BUTTON_POSITIVE -import androidx.appcompat.app.AlertDialog -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.commons.extensions.* import com.simplemobiletools.notes.pro.R import kotlinx.android.synthetic.main.dialog_rename_checklist_item.view.* @@ -16,23 +12,23 @@ class RenameChecklistItemDialog(val activity: Activity, val oldTitle: String, ca checklist_item_title.setText(oldTitle) } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) { - showKeyboard(view.checklist_item_title) - getButton(BUTTON_POSITIVE).setOnClickListener { - val newTitle = view.checklist_item_title.value - when { - newTitle.isEmpty() -> activity.toast(R.string.empty_name) - else -> { - callback(newTitle) - dismiss() - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> + alertDialog.showKeyboard(view.checklist_item_title) + alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener { + val newTitle = view.checklist_item_title.value + when { + newTitle.isEmpty() -> activity.toast(R.string.empty_name) + else -> { + callback(newTitle) + alertDialog.dismiss() } } } } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/RenameNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/RenameNoteDialog.kt index 6acd37a4..e9d0dd0a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/RenameNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/RenameNoteDialog.kt @@ -20,16 +20,16 @@ class RenameNoteDialog(val activity: SimpleActivity, val note: Note, val current val view = activity.layoutInflater.inflate(R.layout.dialog_rename_note, null) view.note_title.setText(note.title) - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.rename_note) { - showKeyboard(view.note_title) - getButton(BUTTON_POSITIVE).setOnClickListener { + .apply { + activity.setupDialogStuff(view, this, R.string.rename_note) { alertDialog -> + alertDialog.showKeyboard(view.note_title) + alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener { val title = view.note_title.value ensureBackgroundThread { - newTitleConfirmed(title, this) + newTitleConfirmed(title, alertDialog) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/SortChecklistDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/SortChecklistDialog.kt index 3a5d2d1b..ab77cc4d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/SortChecklistDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/SortChecklistDialog.kt @@ -1,7 +1,7 @@ package com.simplemobiletools.notes.pro.dialogs -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.extensions.beGoneIf +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM import com.simplemobiletools.commons.helpers.SORT_BY_DATE_CREATED @@ -21,10 +21,11 @@ class SortChecklistDialog(private val activity: SimpleActivity, private val call setupSortRadio() setupOrderRadio() setupMoveUndoneChecklistItems() - AlertDialog.Builder(activity) + + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { _, _ -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this, R.string.sort_by) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt index 02496d9f..509d7eb9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt @@ -136,7 +136,7 @@ class TextFragment : NoteFragment() { setTextWatcher() } skipTextUpdating = false - setSelection(if (config.placeCursorToEnd) text.length else 0) + setSelection(if (config.placeCursorToEnd) text!!.length else 0) } if (config.showKeyboard && isMenuVisible && (!note!!.isLocked() || shouldShowLockedContent)) { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d81301d1..8d6666b3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,25 +1,50 @@ - + android:layout_height="match_parent"> - - - + android:layout_height="wrap_content"> - + android:layout_height="?attr/actionBarSize" + android:background="@color/color_primary" + app:menu="@menu/menu" + app:title="@string/app_launcher_name" + app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" /> - - + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index bf90c33d..afcd4dc2 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,350 +1,375 @@ - + android:layout_height="match_parent"> - + android:layout_height="wrap_content"> - + android:layout_height="?attr/actionBarSize" + android:background="@color/color_primary" + app:title="@string/settings" + app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" /> + + + + - + android:text="@string/color_customization" /> - - - - - + android:layout_margin="@dimen/medium_margin" + android:background="@drawable/section_holder_stroke" + android:orientation="vertical"> - + android:background="@drawable/ripple_top_corners"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/app/src/main/res/layout/dialog_open_note.xml b/app/src/main/res/layout/dialog_open_note.xml index 0c646dfa..0e015af1 100644 --- a/app/src/main/res/layout/dialog_open_note.xml +++ b/app/src/main/res/layout/dialog_open_note.xml @@ -29,14 +29,15 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/dialog_open_note_divider" - android:padding="@dimen/normal_margin"> + android:paddingStart="@dimen/normal_margin" + android:paddingTop="@dimen/small_margin" + android:paddingEnd="@dimen/normal_margin" + android:paddingBottom="@dimen/small_margin"> diff --git a/app/src/main/res/layout/open_note_item.xml b/app/src/main/res/layout/open_note_item.xml index e76e7176..b4364e4d 100644 --- a/app/src/main/res/layout/open_note_item.xml +++ b/app/src/main/res/layout/open_note_item.xml @@ -3,7 +3,8 @@ android:id="@+id/open_note_item_holder" android:layout_width="match_parent" android:layout_height="match_parent" - android:padding="@dimen/normal_margin"> + android:paddingStart="@dimen/normal_margin" + android:paddingEnd="@dimen/normal_margin"> - + android:layout_height="match_parent"> + + + + + + + android:layout_centerHorizontal="true" + android:layout_margin="@dimen/activity_margin" + android:paddingBottom="@dimen/activity_margin" + app:layout_behavior="@string/appbar_scrolling_view_behavior"> + android:paddingBottom="@dimen/activity_margin"> - + android:background="?attr/selectableItemBackground" + android:padding="@dimen/activity_margin"> + + + + + + + + - - - - - - - - - - - - - - - - + android:layout_below="@+id/notes_picker_holder" + android:background="@null" + android:ellipsize="end" + android:gravity="center" + android:lines="1" + android:padding="@dimen/tiny_margin" + android:text="@string/title" + android:textSize="@dimen/smaller_text_size" /> + + + + + + + + + + + + + + + +