mirror of
				https://github.com/SimpleMobileTools/Simple-Notes.git
				synced 2025-06-05 17:00:23 +02:00 
			
		
		
		
	handle saving/loading checklist items from the db
This commit is contained in:
		| @@ -5,12 +5,15 @@ import android.os.Bundle | |||||||
| import android.view.LayoutInflater | import android.view.LayoutInflater | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||||
|  | import com.google.gson.Gson | ||||||
|  | import com.google.gson.reflect.TypeToken | ||||||
| import com.simplemobiletools.commons.extensions.* | import com.simplemobiletools.commons.extensions.* | ||||||
| import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener | import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener | ||||||
| import com.simplemobiletools.notes.pro.R | import com.simplemobiletools.notes.pro.R | ||||||
| import com.simplemobiletools.notes.pro.activities.SimpleActivity | import com.simplemobiletools.notes.pro.activities.SimpleActivity | ||||||
| import com.simplemobiletools.notes.pro.adapters.ChecklistAdapter | import com.simplemobiletools.notes.pro.adapters.ChecklistAdapter | ||||||
| import com.simplemobiletools.notes.pro.dialogs.NewChecklistItemDialog | import com.simplemobiletools.notes.pro.dialogs.NewChecklistItemDialog | ||||||
|  | import com.simplemobiletools.notes.pro.extensions.notesDB | ||||||
| import com.simplemobiletools.notes.pro.helpers.NOTE_ID | import com.simplemobiletools.notes.pro.helpers.NOTE_ID | ||||||
| import com.simplemobiletools.notes.pro.helpers.NotesHelper | import com.simplemobiletools.notes.pro.helpers.NotesHelper | ||||||
| import com.simplemobiletools.notes.pro.models.ChecklistItem | import com.simplemobiletools.notes.pro.models.ChecklistItem | ||||||
| @@ -36,6 +39,9 @@ class ChecklistFragment : NoteFragment(), RefreshRecyclerViewListener { | |||||||
|         NotesHelper(activity!!).getNoteWithId(noteId) { |         NotesHelper(activity!!).getNoteWithId(noteId) { | ||||||
|             if (it != null && activity?.isDestroyed == false) { |             if (it != null && activity?.isDestroyed == false) { | ||||||
|                 note = it |                 note = it | ||||||
|  |  | ||||||
|  |                 val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type | ||||||
|  |                 items = Gson().fromJson<ArrayList<ChecklistItem>>(note!!.value, checklistItemType) ?: ArrayList(1) | ||||||
|                 setupFragment() |                 setupFragment() | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -59,6 +65,12 @@ class ChecklistFragment : NoteFragment(), RefreshRecyclerViewListener { | |||||||
|                     val checklistItem = ChecklistItem(currentMaxId + 1, it, false) |                     val checklistItem = ChecklistItem(currentMaxId + 1, it, false) | ||||||
|                     items.add(checklistItem) |                     items.add(checklistItem) | ||||||
|                     setupAdapter() |                     setupAdapter() | ||||||
|  |                     Thread { | ||||||
|  |                         if (note != null && context != null) { | ||||||
|  |                             note!!.value = Gson().toJson(items) | ||||||
|  |                             context?.notesDB?.insertOrUpdate(note!!) | ||||||
|  |                         } | ||||||
|  |                     }.start() | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ | |||||||
|         android:layout_centerVertical="true" |         android:layout_centerVertical="true" | ||||||
|         android:layout_marginLeft="@dimen/medium_margin" |         android:layout_marginLeft="@dimen/medium_margin" | ||||||
|         android:layout_marginTop="@dimen/medium_margin" |         android:layout_marginTop="@dimen/medium_margin" | ||||||
|         android:layout_marginRight="@dimen/medium_margin"/> |         android:layout_marginRight="@dimen/medium_margin" | ||||||
|  |         android:textSize="@dimen/bigger_text_size"/> | ||||||
|  |  | ||||||
| </RelativeLayout> | </RelativeLayout> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user