- wip: app crash when gson can not deserialize note

This commit is contained in:
Pavol Franek
2020-02-29 10:28:54 +01:00
parent 51f1dc67b4
commit 86714229b4
13 changed files with 65 additions and 41 deletions

View File

@ -10,7 +10,7 @@ import com.simplemobiletools.notes.pro.fragments.ChecklistFragment
import com.simplemobiletools.notes.pro.fragments.NoteFragment
import com.simplemobiletools.notes.pro.fragments.TextFragment
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
import com.simplemobiletools.notes.pro.helpers.TYPE_TEXT
import com.simplemobiletools.notes.pro.helpers.NoteType
import com.simplemobiletools.notes.pro.models.Note
class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity: Activity) : FragmentStatePagerAdapter(fm) {
@ -30,7 +30,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
return fragments[position]!!
}
val fragment = if (note.type == TYPE_TEXT) TextFragment() else ChecklistFragment()
val fragment = if (note.type == NoteType.TYPE_TEXT.value) TextFragment() else ChecklistFragment()
fragment.arguments = bundle
fragments[position] = fragment
return fragment

View File

@ -37,7 +37,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
}
val textSize = context.getTextSize() / context.resources.displayMetrics.density
if (note!!.type == TYPE_CHECKLIST) {
if (note!!.type == NoteType.TYPE_CHECKLIST.value) {
remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply {
val checklistItem = checklistItems.getOrNull(position) ?: return@apply
setText(checklist_title, checklistItem.title)
@ -91,7 +91,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
widgetTextColor = intent.getIntExtra(WIDGET_TEXT_COLOR, DEFAULT_WIDGET_TEXT_COLOR)
val noteId = intent.getLongExtra(NOTE_ID, 0L)
note = context.notesDB.getNoteWithId(noteId)
if (note?.type == TYPE_CHECKLIST) {
if (note?.type == NoteType.TYPE_CHECKLIST.value) {
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
checklistItems = Gson().fromJson<ArrayList<ChecklistItem>>(note!!.value, checklistItemType) ?: ArrayList(1)
if (context.config.moveUndoneChecklistItems) {
@ -103,7 +103,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
override fun hasStableIds() = true
override fun getCount(): Int {
return if (note?.type == TYPE_CHECKLIST) {
return if (note?.type == NoteType.TYPE_CHECKLIST.value) {
checklistItems.size
} else {
1