mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-20 18:40:20 +01:00
Checklists refactoring
This commit is contained in:
parent
0112f39ff0
commit
26cd68b132
app/src/main/kotlin/com/simplemobiletools/notes/pro
activities
adapters
fragments
@ -30,6 +30,8 @@ import com.simplemobiletools.notes.pro.models.Note
|
||||
import com.simplemobiletools.notes.pro.models.NoteType
|
||||
import com.simplemobiletools.notes.pro.models.Widget
|
||||
import kotlinx.android.synthetic.main.widget_config.*
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class WidgetConfigureActivity : SimpleActivity() {
|
||||
private var mBgAlpha = 0f
|
||||
|
@ -31,7 +31,7 @@ import kotlinx.android.synthetic.main.item_checklist.view.*
|
||||
import java.util.*
|
||||
|
||||
class ChecklistAdapter(
|
||||
activity: BaseSimpleActivity, var items: ArrayList<ChecklistItem>, val listener: ChecklistItemsListener?,
|
||||
activity: BaseSimpleActivity, var items: MutableList<ChecklistItem>, val listener: ChecklistItemsListener?,
|
||||
recyclerView: MyRecyclerView, val showIcons: Boolean, itemClick: (Any) -> Unit
|
||||
) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, itemClick), ItemTouchHelperContract {
|
||||
|
@ -21,6 +21,8 @@ import com.simplemobiletools.notes.pro.helpers.*
|
||||
import com.simplemobiletools.notes.pro.models.ChecklistItem
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import com.simplemobiletools.notes.pro.models.NoteType
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
private val textIds = arrayOf(
|
||||
@ -33,7 +35,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
|
||||
)
|
||||
private var widgetTextColor = DEFAULT_WIDGET_TEXT_COLOR
|
||||
private var note: Note? = null
|
||||
private var checklistItems = ArrayList<ChecklistItem>()
|
||||
private var checklistItems = mutableListOf<ChecklistItem>()
|
||||
|
||||
override fun getViewAt(position: Int): RemoteViews {
|
||||
val noteId = intent.getLongExtra(NOTE_ID, 0L)
|
||||
@ -125,8 +127,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
|
||||
val noteId = intent.getLongExtra(NOTE_ID, 0L)
|
||||
note = context.notesDB.getNoteWithId(noteId)
|
||||
if (note?.type == NoteType.TYPE_CHECKLIST) {
|
||||
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
||||
checklistItems = Gson().fromJson<ArrayList<ChecklistItem>>(note!!.getNoteStoredValue(context), checklistItemType) ?: ArrayList(1)
|
||||
checklistItems = note!!.getNoteStoredValue(context)?.let { Json.decodeFromString(it) } ?: mutableListOf()
|
||||
|
||||
// checklist title can be null only because of the glitch in upgrade to 6.6.0, remove this check in the future
|
||||
checklistItems = checklistItems.filter { it.title != null }.toMutableList() as ArrayList<ChecklistItem>
|
||||
|
@ -29,7 +29,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
||||
|
||||
lateinit var view: ViewGroup
|
||||
|
||||
var items = ArrayList<ChecklistItem>()
|
||||
var items = mutableListOf<ChecklistItem>()
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
|
||||
|
Loading…
x
Reference in New Issue
Block a user