mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
updating commons with some material elements
This commit is contained in:
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Note>
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<String>) -> Unit) {
|
||||
private val titles = mutableListOf<EditText>()
|
||||
private val titles = mutableListOf<AppCompatEditText>()
|
||||
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<String>
|
||||
callback(titles)
|
||||
dismiss()
|
||||
alertDialog.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
Reference in New Issue
Block a user