Skip to content

Commit 797ac60

Browse files
committed
updating commons with some material elements
1 parent 09e7ee0 commit 797ac60

21 files changed

+664
-578
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ android {
6363
}
6464

6565
dependencies {
66-
implementation 'com.github.SimpleMobileTools:Simple-Commons:e1e07bf005'
66+
implementation 'com.github.SimpleMobileTools:Simple-Commons:4f9c2f94ff'
6767
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
6868
implementation 'androidx.documentfile:documentfile:1.0.1'
6969

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt

Lines changed: 69 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class MainActivity : SimpleActivity() {
8787
super.onCreate(savedInstanceState)
8888
setContentView(R.layout.activity_main)
8989
appLaunched(BuildConfig.APPLICATION_ID)
90+
setupOptionsMenu()
91+
refreshMenuItems()
9092

9193
searchQueryET = findViewById(R.id.search_query)
9294
searchPrevBtn = findViewById(R.id.search_previous)
@@ -113,11 +115,12 @@ class MainActivity : SimpleActivity() {
113115

114116
override fun onResume() {
115117
super.onResume()
118+
setupToolbar(main_toolbar)
116119
if (storedEnableLineWrap != config.enableLineWrap) {
117120
initViewPager()
118121
}
119122

120-
invalidateOptionsMenu()
123+
refreshMenuItems()
121124
pager_title_strip.apply {
122125
setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize())
123126
setGravity(Gravity.CENTER_VERTICAL)
@@ -168,11 +171,26 @@ class MainActivity : SimpleActivity() {
168171
return true
169172
}
170173

171-
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
174+
private fun refreshMenuItems() {
172175
val multipleNotesExist = mNotes.size > 1
173176
val isCurrentItemChecklist = isCurrentItemChecklist()
174177

175-
menu.apply {
178+
main_toolbar.menu.apply {
179+
val areButtonsVisible = (showRedoButton || showUndoButton) && mCurrentNote.type == NoteType.TYPE_TEXT.value
180+
findItem(R.id.undo).apply {
181+
isVisible = areButtonsVisible
182+
isEnabled = showUndoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
183+
icon.alpha = if (isEnabled) 255 else 127
184+
}
185+
186+
findItem(R.id.redo).apply {
187+
isVisible = areButtonsVisible
188+
isEnabled = showRedoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
189+
icon.alpha = if (isEnabled) 255 else 127
190+
}
191+
}
192+
193+
main_toolbar.menu.apply {
176194
findItem(R.id.rename_note).isVisible = multipleNotesExist
177195
findItem(R.id.open_note).isVisible = multipleNotesExist
178196
findItem(R.id.delete_note).isVisible = multipleNotesExist
@@ -183,49 +201,51 @@ class MainActivity : SimpleActivity() {
183201
findItem(R.id.sort_checklist).isVisible = isCurrentItemChecklist
184202
findItem(R.id.import_folder).isVisible = !isQPlus()
185203
findItem(R.id.import_notes).isVisible = isQPlus()
186-
findItem(R.id.lock_note).isVisible = mNotes.isNotEmpty() && !mCurrentNote.isLocked()
187-
findItem(R.id.unlock_note).isVisible = mNotes.isNotEmpty() && mCurrentNote.isLocked()
204+
findItem(R.id.lock_note).isVisible = mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && !mCurrentNote.isLocked())
205+
findItem(R.id.unlock_note).isVisible = mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && mCurrentNote.isLocked())
188206

189207
saveNoteButton = findItem(R.id.save_note)
190-
saveNoteButton!!.isVisible = !config.autosaveNotes && showSaveButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
208+
saveNoteButton!!.isVisible =
209+
!config.autosaveNotes && showSaveButton && (::mCurrentNote.isInitialized && mCurrentNote.type == NoteType.TYPE_TEXT.value)
191210
}
192211

193212
pager_title_strip.beVisibleIf(multipleNotesExist)
194-
return super.onPrepareOptionsMenu(menu)
195-
}
196-
197-
override fun onOptionsItemSelected(item: MenuItem): Boolean {
198-
if (config.autosaveNotes && item.itemId != R.id.undo && item.itemId != R.id.redo) {
199-
saveCurrentNote(false)
200-
}
201-
202-
val fragment = getCurrentFragment()
203-
when (item.itemId) {
204-
R.id.open_search -> fragment?.handleUnlocking { openSearch() }
205-
R.id.open_note -> displayOpenNoteDialog()
206-
R.id.save_note -> fragment?.handleUnlocking { saveNote() }
207-
R.id.undo -> undo()
208-
R.id.redo -> redo()
209-
R.id.new_note -> displayNewNoteDialog()
210-
R.id.rename_note -> fragment?.handleUnlocking { displayRenameDialog() }
211-
R.id.share -> fragment?.handleUnlocking { shareText() }
212-
R.id.lock_note -> lockNote()
213-
R.id.unlock_note -> unlockNote()
214-
R.id.open_file -> tryOpenFile()
215-
R.id.import_folder -> openFolder()
216-
R.id.export_as_file -> fragment?.handleUnlocking { tryExportAsFile() }
217-
R.id.export_all_notes -> tryExportAllNotes()
218-
R.id.export_notes -> tryExportNotes()
219-
R.id.import_notes -> tryImportNotes()
220-
R.id.print -> fragment?.handleUnlocking { printText() }
221-
R.id.delete_note -> fragment?.handleUnlocking { displayDeleteNotePrompt() }
222-
R.id.settings -> launchSettings()
223-
R.id.about -> launchAbout()
224-
R.id.remove_done_items -> fragment?.handleUnlocking { removeDoneItems() }
225-
R.id.sort_checklist -> fragment?.handleUnlocking { displaySortChecklistDialog() }
226-
else -> return super.onOptionsItemSelected(item)
213+
}
214+
215+
private fun setupOptionsMenu() {
216+
main_toolbar.setOnMenuItemClickListener { menuItem ->
217+
if (config.autosaveNotes && menuItem.itemId != R.id.undo && menuItem.itemId != R.id.redo) {
218+
saveCurrentNote(false)
219+
}
220+
221+
val fragment = getCurrentFragment()
222+
when (menuItem.itemId) {
223+
R.id.open_search -> fragment?.handleUnlocking { openSearch() }
224+
R.id.open_note -> displayOpenNoteDialog()
225+
R.id.save_note -> fragment?.handleUnlocking { saveNote() }
226+
R.id.undo -> undo()
227+
R.id.redo -> redo()
228+
R.id.new_note -> displayNewNoteDialog()
229+
R.id.rename_note -> fragment?.handleUnlocking { displayRenameDialog() }
230+
R.id.share -> fragment?.handleUnlocking { shareText() }
231+
R.id.lock_note -> lockNote()
232+
R.id.unlock_note -> unlockNote()
233+
R.id.open_file -> tryOpenFile()
234+
R.id.import_folder -> openFolder()
235+
R.id.export_as_file -> fragment?.handleUnlocking { tryExportAsFile() }
236+
R.id.export_all_notes -> tryExportAllNotes()
237+
R.id.export_notes -> tryExportNotes()
238+
R.id.import_notes -> tryImportNotes()
239+
R.id.print -> fragment?.handleUnlocking { printText() }
240+
R.id.delete_note -> fragment?.handleUnlocking { displayDeleteNotePrompt() }
241+
R.id.settings -> launchSettings()
242+
R.id.about -> launchAbout()
243+
R.id.remove_done_items -> fragment?.handleUnlocking { removeDoneItems() }
244+
R.id.sort_checklist -> fragment?.handleUnlocking { displaySortChecklistDialog() }
245+
else -> return@setOnMenuItemClickListener false
246+
}
247+
return@setOnMenuItemClickListener true
227248
}
228-
return true
229249
}
230250

231251
// https://code.google.com/p/android/issues/detail?id=191430 quickfix
@@ -286,7 +306,7 @@ class MainActivity : SimpleActivity() {
286306
}
287307
}
288308

289-
private fun isCurrentItemChecklist() = if (this::mCurrentNote.isInitialized) mCurrentNote.type == NoteType.TYPE_CHECKLIST.value else false
309+
private fun isCurrentItemChecklist() = if (::mCurrentNote.isInitialized) mCurrentNote.type == NoteType.TYPE_CHECKLIST.value else false
290310

291311
@SuppressLint("NewApi")
292312
private fun checkShortcuts() {
@@ -422,7 +442,7 @@ class MainActivity : SimpleActivity() {
422442
.forEach(::removeProtection)
423443

424444
mNotes = notes
425-
invalidateOptionsMenu()
445+
refreshMenuItems()
426446
mCurrentNote = mNotes[0]
427447
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, this)
428448
view_pager.apply {
@@ -433,7 +453,7 @@ class MainActivity : SimpleActivity() {
433453
onPageChangeListener {
434454
mCurrentNote = mNotes[it]
435455
config.currentNoteId = mCurrentNote.id!!
436-
invalidateOptionsMenu()
456+
refreshMenuItems()
437457
}
438458
}
439459

@@ -463,7 +483,7 @@ class MainActivity : SimpleActivity() {
463483
view_pager.onPageChangeListener {
464484
currentTextFragment?.removeTextWatcher()
465485
currentNotesView()?.let { noteView ->
466-
noteView.text.clearBackgroundSpans()
486+
noteView.text!!.clearBackgroundSpans()
467487
}
468488

469489
closeSearch()
@@ -483,7 +503,7 @@ class MainActivity : SimpleActivity() {
483503
private fun searchTextChanged(text: String) {
484504
currentNotesView()?.let { noteView ->
485505
currentTextFragment?.removeTextWatcher()
486-
noteView.text.clearBackgroundSpans()
506+
noteView.text!!.clearBackgroundSpans()
487507

488508
if (text.isNotBlank() && text.length > 1) {
489509
searchMatches = noteView.value.searchMatches(text)
@@ -1263,7 +1283,7 @@ class MainActivity : SimpleActivity() {
12631283
private fun saveNote() {
12641284
saveCurrentNote(true)
12651285
showSaveButton = false
1266-
invalidateOptionsMenu()
1286+
refreshMenuItems()
12671287
}
12681288

12691289
private fun undo() {
@@ -1309,7 +1329,7 @@ class MainActivity : SimpleActivity() {
13091329
mCurrentNote.protectionHash = hash
13101330
mCurrentNote.protectionType = type
13111331
NotesHelper(this).insertOrUpdateNote(mCurrentNote) {
1312-
invalidateOptionsMenu()
1332+
refreshMenuItems()
13131333
}
13141334
}
13151335
}
@@ -1333,7 +1353,7 @@ class MainActivity : SimpleActivity() {
13331353
shouldShowLockedContent = true
13341354
checkLockState()
13351355
}
1336-
invalidateOptionsMenu()
1356+
refreshMenuItems()
13371357
}
13381358
}
13391359
}
@@ -1359,7 +1379,7 @@ class MainActivity : SimpleActivity() {
13591379
}
13601380

13611381
if (shouldRecreateMenu) {
1362-
invalidateOptionsMenu()
1382+
refreshMenuItems()
13631383
}
13641384
}
13651385
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.view.Menu
66
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
77
import com.simplemobiletools.commons.extensions.*
88
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
9+
import com.simplemobiletools.commons.helpers.NavigationIcon
910
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
1011
import com.simplemobiletools.commons.helpers.isOreoPlus
1112
import com.simplemobiletools.commons.models.RadioItem
@@ -26,6 +27,7 @@ class SettingsActivity : SimpleActivity() {
2627

2728
override fun onResume() {
2829
super.onResume()
30+
setupToolbar(settings_toolbar, NavigationIcon.Arrow)
2931

3032
setupCustomizeColors()
3133
setupUseEnglish()
@@ -42,8 +44,7 @@ class SettingsActivity : SimpleActivity() {
4244
setupCursorPlacement()
4345
setupIncognitoMode()
4446
setupCustomizeWidgetColors()
45-
updateTextColors(settings_scrollview)
46-
invalidateOptionsMenu()
47+
updateTextColors(settings_nested_scrollview)
4748

4849
arrayOf(
4950
settings_color_customization_label,

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class WidgetConfigureActivity : SimpleActivity() {
7373
override fun onResume() {
7474
super.onResume()
7575
text_note_view.setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize())
76+
setupToolbar(config_toolbar)
7677
}
7778

7879
override fun onCreateOptionsMenu(menu: Menu): Boolean {

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/DeleteNoteDialog.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs
22

33
import androidx.appcompat.app.AlertDialog
44
import com.simplemobiletools.commons.extensions.beVisible
5+
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
56
import com.simplemobiletools.commons.extensions.setupDialogStuff
67
import com.simplemobiletools.notes.pro.R
78
import com.simplemobiletools.notes.pro.activities.SimpleActivity
@@ -24,10 +25,10 @@ class DeleteNoteDialog(val activity: SimpleActivity, val note: Note, val callbac
2425
delete_note_description.text = message
2526
}
2627

27-
AlertDialog.Builder(activity)
28+
activity.getAlertDialogBuilder()
2829
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed(view.delete_note_checkbox.isChecked) }
2930
.setNegativeButton(R.string.cancel, null)
30-
.create().apply {
31+
.apply {
3132
activity.setupDialogStuff(view, this)
3233
}
3334
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFileDialog.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,33 @@ class ExportFileDialog(val activity: SimpleActivity, val note: Note, val callbac
2727
}
2828
}
2929

30-
AlertDialog.Builder(activity)
31-
.setPositiveButton(R.string.ok, null)
32-
.setNegativeButton(R.string.cancel, null)
33-
.create().apply {
34-
activity.setupDialogStuff(view, this, R.string.export_as_file) {
35-
showKeyboard(view.file_name)
36-
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
37-
val filename = view.file_name.value
38-
val extension = view.file_extension.value
39-
40-
if (filename.isEmpty()) {
41-
activity.toast(R.string.filename_cannot_be_empty)
42-
return@setOnClickListener
43-
}
44-
45-
val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
46-
if (!fullFilename.isAValidFilename()) {
47-
activity.toast(String.format(activity.getString(R.string.filename_invalid_characters_placeholder, fullFilename)))
48-
return@setOnClickListener
49-
}
50-
51-
activity.config.lastUsedExtension = extension
52-
activity.config.lastUsedSavePath = realPath
53-
callback("$realPath/$fullFilename")
54-
dismiss()
30+
activity.getAlertDialogBuilder()
31+
.setPositiveButton(R.string.ok, null)
32+
.setNegativeButton(R.string.cancel, null)
33+
.apply {
34+
activity.setupDialogStuff(view, this, R.string.export_as_file) { alertDialog ->
35+
alertDialog.showKeyboard(view.file_name)
36+
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
37+
val filename = view.file_name.value
38+
val extension = view.file_extension.value
39+
40+
if (filename.isEmpty()) {
41+
activity.toast(R.string.filename_cannot_be_empty)
42+
return@setOnClickListener
5543
}
44+
45+
val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
46+
if (!fullFilename.isAValidFilename()) {
47+
activity.toast(String.format(activity.getString(R.string.filename_invalid_characters_placeholder, fullFilename)))
48+
return@setOnClickListener
49+
}
50+
51+
activity.config.lastUsedExtension = extension
52+
activity.config.lastUsedSavePath = realPath
53+
callback("$realPath/$fullFilename")
54+
alertDialog.dismiss()
5655
}
5756
}
57+
}
5858
}
5959
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/ExportFilesDialog.kt

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package com.simplemobiletools.notes.pro.dialogs
22

33
import androidx.appcompat.app.AlertDialog
44
import com.simplemobiletools.commons.dialogs.FilePickerDialog
5-
import com.simplemobiletools.commons.extensions.humanizePath
6-
import com.simplemobiletools.commons.extensions.setupDialogStuff
7-
import com.simplemobiletools.commons.extensions.showKeyboard
8-
import com.simplemobiletools.commons.extensions.value
5+
import com.simplemobiletools.commons.extensions.*
96
import com.simplemobiletools.notes.pro.R
107
import com.simplemobiletools.notes.pro.activities.SimpleActivity
118
import com.simplemobiletools.notes.pro.extensions.config
@@ -27,22 +24,22 @@ class ExportFilesDialog(val activity: SimpleActivity, val notes: ArrayList<Note>
2724
}
2825
}
2926

30-
AlertDialog.Builder(activity)
31-
.setPositiveButton(R.string.ok, null)
32-
.setNegativeButton(R.string.cancel, null)
33-
.create().apply {
34-
activity.setupDialogStuff(view, this, R.string.export_as_file) {
35-
showKeyboard(view.file_extension)
36-
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
37-
activity.handleSAFDialog(realPath) {
38-
val extension = view.file_extension.value
39-
activity.config.lastUsedExtension = extension
40-
activity.config.lastUsedSavePath = realPath
41-
callback(realPath, extension)
42-
dismiss()
43-
}
27+
activity.getAlertDialogBuilder()
28+
.setPositiveButton(R.string.ok, null)
29+
.setNegativeButton(R.string.cancel, null)
30+
.apply {
31+
activity.setupDialogStuff(view, this, R.string.export_as_file) { alertDialog ->
32+
alertDialog.showKeyboard(view.file_extension)
33+
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
34+
activity.handleSAFDialog(realPath) {
35+
val extension = view.file_extension.value
36+
activity.config.lastUsedExtension = extension
37+
activity.config.lastUsedSavePath = realPath
38+
callback(realPath, extension)
39+
alertDialog.dismiss()
4440
}
4541
}
4642
}
43+
}
4744
}
4845
}

0 commit comments

Comments
 (0)