Skip to content

Commit e8b8d2b

Browse files
committed
Changed NoteType to the enum class in Note.kt
1 parent 932699a commit e8b8d2b

File tree

11 files changed

+54
-45
lines changed

11 files changed

+54
-45
lines changed

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import com.simplemobiletools.notes.pro.extensions.*
4444
import com.simplemobiletools.notes.pro.fragments.TextFragment
4545
import com.simplemobiletools.notes.pro.helpers.*
4646
import com.simplemobiletools.notes.pro.models.Note
47+
import com.simplemobiletools.notes.pro.models.NoteType
4748
import kotlinx.android.synthetic.main.activity_main.*
4849
import kotlinx.android.synthetic.main.item_checklist.*
4950
import java.io.File
@@ -165,12 +166,12 @@ class MainActivity : SimpleActivity() {
165166

166167
main_toolbar.menu.apply {
167168
findItem(R.id.undo).apply {
168-
isVisible = showUndoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
169+
isVisible = showUndoButton && mCurrentNote.type == NoteType.TYPE_TEXT
169170
icon?.alpha = if (isEnabled) 255 else 127
170171
}
171172

172173
findItem(R.id.redo).apply {
173-
isVisible = showRedoButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
174+
isVisible = showRedoButton && mCurrentNote.type == NoteType.TYPE_TEXT
174175
icon?.alpha = if (isEnabled) 255 else 127
175176
}
176177

@@ -187,7 +188,7 @@ class MainActivity : SimpleActivity() {
187188

188189
saveNoteButton = findItem(R.id.save_note)
189190
saveNoteButton!!.isVisible =
190-
!config.autosaveNotes && showSaveButton && (::mCurrentNote.isInitialized && mCurrentNote.type == NoteType.TYPE_TEXT.value)
191+
!config.autosaveNotes && showSaveButton && (::mCurrentNote.isInitialized && mCurrentNote.type == NoteType.TYPE_TEXT)
191192
}
192193

193194
pager_tab_strip.beVisibleIf(multipleNotesExist)
@@ -281,7 +282,7 @@ class MainActivity : SimpleActivity() {
281282
}
282283
}
283284

284-
private fun isCurrentItemChecklist() = if (::mCurrentNote.isInitialized) mCurrentNote.type == NoteType.TYPE_CHECKLIST.value else false
285+
private fun isCurrentItemChecklist() = if (::mCurrentNote.isInitialized) mCurrentNote.type == NoteType.TYPE_CHECKLIST else false
285286

286287
@SuppressLint("NewApi")
287288
private fun checkShortcuts() {
@@ -353,10 +354,10 @@ class MainActivity : SimpleActivity() {
353354
val file = File(realPath)
354355
handleUri(Uri.fromFile(file))
355356
} else if (intent.getBooleanExtra(NEW_TEXT_NOTE, false)) {
356-
val newTextNote = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
357+
val newTextNote = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_TEXT, "", PROTECTION_NONE, "")
357358
addNewNote(newTextNote)
358359
} else if (intent.getBooleanExtra(NEW_CHECKLIST, false)) {
359-
val newChecklist = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
360+
val newChecklist = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_CHECKLIST, "", PROTECTION_NONE, "")
360361
addNewNote(newChecklist)
361362
} else {
362363
handleUri(data!!)
@@ -431,7 +432,7 @@ class MainActivity : SimpleActivity() {
431432
}
432433
}
433434

434-
if (!config.showKeyboard || mCurrentNote.type == NoteType.TYPE_CHECKLIST.value) {
435+
if (!config.showKeyboard || mCurrentNote.type == NoteType.TYPE_CHECKLIST) {
435436
hideKeyboard()
436437
}
437438
refreshMenuItems()
@@ -663,7 +664,7 @@ class MainActivity : SimpleActivity() {
663664
val checklistItems = fileText.parseChecklistItems()
664665
if (checklistItems != null) {
665666
val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.')
666-
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
667+
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST, "", PROTECTION_NONE, "")
667668
runOnUiThread {
668669
OpenFileDialog(this, it.path) {
669670
displayNewNoteDialog(note.value, title = it.title, it.path, setChecklistAsDefault = true)
@@ -765,7 +766,7 @@ class MainActivity : SimpleActivity() {
765766
}
766767
}
767768

768-
val noteType = if (checklistItems != null) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value
769+
val noteType = if (checklistItems != null) NoteType.TYPE_CHECKLIST else NoteType.TYPE_TEXT
769770
if (!canSyncNoteWithFile) {
770771
val note = Note(null, noteTitle, content, noteType, "", PROTECTION_NONE, "")
771772
displayNewNoteDialog(note.value, title = noteTitle, "")
@@ -791,9 +792,9 @@ class MainActivity : SimpleActivity() {
791792
val fileText = it.readText().trim()
792793
val checklistItems = fileText.parseChecklistItems()
793794
val note = if (checklistItems != null) {
794-
Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "")
795+
Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST, "", PROTECTION_NONE, "")
795796
} else {
796-
Note(null, title, "", NoteType.TYPE_TEXT.value, path, PROTECTION_NONE, "")
797+
Note(null, title, "", NoteType.TYPE_TEXT, path, PROTECTION_NONE, "")
797798
}
798799

799800
if (mNotes.any { it.title.equals(note.title, true) }) {
@@ -864,10 +865,10 @@ class MainActivity : SimpleActivity() {
864865

865866
private fun exportAsFile() {
866867
ExportFileDialog(this, mCurrentNote) {
867-
val textToExport = if (mCurrentNote.type == NoteType.TYPE_TEXT.value) getCurrentNoteText() else mCurrentNote.value
868+
val textToExport = if (mCurrentNote.type == NoteType.TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value
868869
if (textToExport == null || textToExport.isEmpty()) {
869870
toast(R.string.unknown_error_occurred)
870-
} else if (mCurrentNote.type == NoteType.TYPE_TEXT.value) {
871+
} else if (mCurrentNote.type == NoteType.TYPE_TEXT) {
871872
showExportFilePickUpdateDialog(it, textToExport)
872873
} else {
873874
tryExportNoteValueToFile(it, mCurrentNote.title, textToExport, true)
@@ -1018,15 +1019,15 @@ class MainActivity : SimpleActivity() {
10181019
private fun getCurrentNoteText() = getPagerAdapter().getCurrentNoteViewText(view_pager.currentItem)
10191020

10201021
private fun getCurrentNoteValue(): String {
1021-
return if (mCurrentNote.type == NoteType.TYPE_TEXT.value) {
1022+
return if (mCurrentNote.type == NoteType.TYPE_TEXT) {
10221023
getCurrentNoteText() ?: ""
10231024
} else {
10241025
getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
10251026
}
10261027
}
10271028

10281029
private fun getPrintableText(): String {
1029-
return if (mCurrentNote.type == NoteType.TYPE_TEXT.value) {
1030+
return if (mCurrentNote.type == NoteType.TYPE_TEXT) {
10301031
getCurrentNoteText() ?: ""
10311032
} else {
10321033
var printableText = ""
@@ -1041,7 +1042,7 @@ class MainActivity : SimpleActivity() {
10411042

10421043
private fun saveCurrentNote(force: Boolean) {
10431044
getPagerAdapter().saveCurrentNote(view_pager.currentItem, force)
1044-
if (mCurrentNote.type == NoteType.TYPE_CHECKLIST.value) {
1045+
if (mCurrentNote.type == NoteType.TYPE_CHECKLIST) {
10451046
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
10461047
}
10471048
}
@@ -1139,8 +1140,8 @@ class MainActivity : SimpleActivity() {
11391140
}
11401141

11411142
private fun shareText() {
1142-
val text = if (mCurrentNote.type == NoteType.TYPE_TEXT.value) getCurrentNoteText() else mCurrentNote.value
1143-
if (text == null || text.isEmpty()) {
1143+
val text = if (mCurrentNote.type == NoteType.TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value
1144+
if (text.isNullOrEmpty()) {
11441145
toast(R.string.cannot_share_empty_text)
11451146
return
11461147
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.simplemobiletools.notes.pro.extensions.widgetsDB
2727
import com.simplemobiletools.notes.pro.helpers.*
2828
import com.simplemobiletools.notes.pro.models.ChecklistItem
2929
import com.simplemobiletools.notes.pro.models.Note
30+
import com.simplemobiletools.notes.pro.models.NoteType
3031
import com.simplemobiletools.notes.pro.models.Widget
3132
import kotlinx.android.synthetic.main.widget_config.*
3233

@@ -156,7 +157,7 @@ class WidgetConfigureActivity : SimpleActivity() {
156157
mCurrentNoteId = note.id!!
157158
notes_picker_value.text = note.title
158159
text_note_view_title.text = note.title
159-
if (note.type == NoteType.TYPE_CHECKLIST.value) {
160+
if (note.type == NoteType.TYPE_CHECKLIST) {
160161
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
161162
val items = Gson().fromJson<ArrayList<ChecklistItem>>(note.value, checklistItemType) ?: ArrayList(1)
162163
items.apply {

app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import com.simplemobiletools.notes.pro.fragments.ChecklistFragment
1010
import com.simplemobiletools.notes.pro.fragments.NoteFragment
1111
import com.simplemobiletools.notes.pro.fragments.TextFragment
1212
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
13-
import com.simplemobiletools.notes.pro.helpers.NoteType
1413
import com.simplemobiletools.notes.pro.models.Note
14+
import com.simplemobiletools.notes.pro.models.NoteType
1515

1616
class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity: Activity) : FragmentStatePagerAdapter(fm) {
1717
private var fragments: HashMap<Int, NoteFragment> = LinkedHashMap()
@@ -30,7 +30,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
3030
return fragments[position]!!
3131
}
3232

33-
val fragment = if (note.type == NoteType.TYPE_TEXT.value) TextFragment() else ChecklistFragment()
33+
val fragment = if (note.type == NoteType.TYPE_TEXT) TextFragment() else ChecklistFragment()
3434
fragment.arguments = bundle
3535
fragments[position] = fragment
3636
return fragment

app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/WidgetAdapter.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.simplemobiletools.notes.pro.extensions.notesDB
2020
import com.simplemobiletools.notes.pro.helpers.*
2121
import com.simplemobiletools.notes.pro.models.ChecklistItem
2222
import com.simplemobiletools.notes.pro.models.Note
23+
import com.simplemobiletools.notes.pro.models.NoteType
2324

2425
class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
2526
private val textIds = arrayOf(
@@ -43,7 +44,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
4344
}
4445

4546
val textSize = context.getPercentageFontSize() / context.resources.displayMetrics.density
46-
if (note!!.type == NoteType.TYPE_CHECKLIST.value) {
47+
if (note!!.type == NoteType.TYPE_CHECKLIST) {
4748
remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply {
4849
val checklistItem = checklistItems.getOrNull(position) ?: return@apply
4950
val widgetNewTextColor = if (checklistItem.isDone) widgetTextColor.adjustAlpha(DONE_CHECKLIST_ITEM_ALPHA) else widgetTextColor
@@ -123,7 +124,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
123124
widgetTextColor = intent.getIntExtra(WIDGET_TEXT_COLOR, DEFAULT_WIDGET_TEXT_COLOR)
124125
val noteId = intent.getLongExtra(NOTE_ID, 0L)
125126
note = context.notesDB.getNoteWithId(noteId)
126-
if (note?.type == NoteType.TYPE_CHECKLIST.value) {
127+
if (note?.type == NoteType.TYPE_CHECKLIST) {
127128
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
128129
checklistItems = Gson().fromJson<ArrayList<ChecklistItem>>(note!!.getNoteStoredValue(context), checklistItemType) ?: ArrayList(1)
129130

@@ -135,7 +136,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
135136
override fun hasStableIds() = true
136137

137138
override fun getCount(): Int {
138-
return if (note?.type == NoteType.TYPE_CHECKLIST.value) {
139+
return if (note?.type == NoteType.TYPE_CHECKLIST) {
139140
checklistItems.size
140141
} else {
141142
1

app/src/main/kotlin/com/simplemobiletools/notes/pro/databases/NotesDatabase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
99
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
1010
import com.simplemobiletools.notes.pro.R
1111
import com.simplemobiletools.notes.pro.helpers.DEFAULT_WIDGET_TEXT_COLOR
12-
import com.simplemobiletools.notes.pro.helpers.NoteType
1312
import com.simplemobiletools.notes.pro.interfaces.NotesDao
1413
import com.simplemobiletools.notes.pro.interfaces.WidgetsDao
1514
import com.simplemobiletools.notes.pro.models.Note
15+
import com.simplemobiletools.notes.pro.models.NoteType
1616
import com.simplemobiletools.notes.pro.models.Widget
1717
import java.util.concurrent.Executors
1818

@@ -57,7 +57,7 @@ abstract class NotesDatabase : RoomDatabase() {
5757
private fun insertFirstNote(context: Context) {
5858
Executors.newSingleThreadScheduledExecutor().execute {
5959
val generalNote = context.resources.getString(R.string.general_note)
60-
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
60+
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT, "", PROTECTION_NONE, "")
6161
db!!.NotesDao().insertOrUpdate(note)
6262
}
6363
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import com.simplemobiletools.notes.pro.R
99
import com.simplemobiletools.notes.pro.activities.SimpleActivity
1010
import com.simplemobiletools.notes.pro.extensions.notesDB
1111
import com.simplemobiletools.notes.pro.extensions.parseChecklistItems
12-
import com.simplemobiletools.notes.pro.helpers.NoteType
1312
import com.simplemobiletools.notes.pro.helpers.NotesHelper
1413
import com.simplemobiletools.notes.pro.models.Note
15-
import kotlinx.android.synthetic.main.dialog_import_folder.view.*
14+
import com.simplemobiletools.notes.pro.models.NoteType
15+
import kotlinx.android.synthetic.main.dialog_import_folder.view.open_file_filename
16+
import kotlinx.android.synthetic.main.dialog_import_folder.view.open_file_type
1617
import java.io.File
1718

1819
class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) {
@@ -50,21 +51,21 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
5051
activity.notesDB.getNoteIdWithTitle(filename) != null -> false
5152
else -> true
5253
}
53-
}.forEach {
54+
}?.forEach {
5455
val storePath = if (updateFilesOnEdit) it.absolutePath else ""
5556
val title = it.absolutePath.getFilenameFromPath()
5657
val value = if (updateFilesOnEdit) "" else it.readText()
5758
val fileText = it.readText().trim()
5859
val checklistItems = fileText.parseChecklistItems()
5960
if (checklistItems != null) {
60-
saveNote(title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value, "")
61+
saveNote(title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST, "")
6162
} else {
6263
if (updateFilesOnEdit) {
6364
activity.handleSAFDialog(path) {
64-
saveNote(title, value, NoteType.TYPE_TEXT.value, storePath)
65+
saveNote(title, value, NoteType.TYPE_TEXT, storePath)
6566
}
6667
} else {
67-
saveNote(title, value, NoteType.TYPE_TEXT.value, storePath)
68+
saveNote(title, value, NoteType.TYPE_TEXT, storePath)
6869
}
6970
}
7071
}
@@ -75,7 +76,7 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
7576
}
7677
}
7778

78-
private fun saveNote(title: String, value: String, type: Int, path: String) {
79+
private fun saveNote(title: String, value: String, type: NoteType, path: String) {
7980
val note = Note(null, title, value, type, path, PROTECTION_NONE, "")
8081
NotesHelper(activity).insertOrUpdateNote(note)
8182
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
88
import com.simplemobiletools.notes.pro.R
99
import com.simplemobiletools.notes.pro.extensions.config
1010
import com.simplemobiletools.notes.pro.extensions.notesDB
11-
import com.simplemobiletools.notes.pro.helpers.NoteType
1211
import com.simplemobiletools.notes.pro.models.Note
12+
import com.simplemobiletools.notes.pro.models.NoteType
1313
import kotlinx.android.synthetic.main.dialog_new_note.view.*
1414

1515
class NewNoteDialog(val activity: Activity, title: String? = null, val setChecklistAsDefault: Boolean, callback: (note: Note) -> Unit) {
@@ -40,12 +40,12 @@ class NewNoteDialog(val activity: Activity, title: String? = null, val setCheckl
4040
activity.notesDB.getNoteIdWithTitle(newTitle) != null -> activity.toast(R.string.title_taken)
4141
else -> {
4242
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) {
43-
NoteType.TYPE_CHECKLIST.value
43+
NoteType.TYPE_CHECKLIST
4444
} else {
45-
NoteType.TYPE_TEXT.value
45+
NoteType.TYPE_TEXT
4646
}
4747

48-
activity.config.lastCreatedNoteType = type
48+
activity.config.lastCreatedNoteType = type.value
4949
val newNote = Note(null, newTitle, "", type, "", PROTECTION_NONE, "")
5050
callback(newNote)
5151
alertDialog.dismiss()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
99
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
1010
import com.simplemobiletools.notes.pro.R
1111
import com.simplemobiletools.notes.pro.activities.SimpleActivity
12-
import com.simplemobiletools.notes.pro.helpers.NoteType
1312
import com.simplemobiletools.notes.pro.models.Note
13+
import com.simplemobiletools.notes.pro.models.NoteType
1414
import kotlinx.android.synthetic.main.dialog_open_file.view.*
1515
import java.io.File
1616

@@ -47,7 +47,7 @@ class OpenFileDialog(val activity: SimpleActivity, val path: String, val callbac
4747

4848
private fun saveNote(storeContent: String, storePath: String) {
4949
val filename = path.getFilenameFromPath()
50-
val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT.value, storePath, PROTECTION_NONE, "")
50+
val note = Note(null, filename, storeContent, NoteType.TYPE_TEXT, storePath, PROTECTION_NONE, "")
5151
callback(note)
5252
dialog?.dismiss()
5353
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Config.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Context
55
import android.os.Environment
66
import android.view.Gravity
77
import com.simplemobiletools.commons.helpers.BaseConfig
8+
import com.simplemobiletools.notes.pro.models.NoteType
89

910
class Config(context: Context) : BaseConfig(context) {
1011
companion object {

app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/NotesHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.simplemobiletools.notes.pro.R
1010
import com.simplemobiletools.notes.pro.extensions.config
1111
import com.simplemobiletools.notes.pro.extensions.notesDB
1212
import com.simplemobiletools.notes.pro.models.Note
13+
import com.simplemobiletools.notes.pro.models.NoteType
1314
import java.io.File
1415

1516
class NotesHelper(val context: Context) {
@@ -36,7 +37,7 @@ class NotesHelper(val context: Context) {
3637

3738
if (notes.isEmpty()) {
3839
val generalNote = context.resources.getString(R.string.general_note)
39-
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "")
40+
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT, "", PROTECTION_NONE, "")
4041
context.notesDB.insertOrUpdate(note)
4142
notes.add(note)
4243
}

0 commit comments

Comments
 (0)