Skip to content

Commit

Permalink
Remove non-null assertions in NotesListAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
shubertm committed Nov 29, 2023
1 parent 4eac79d commit 3858f14
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import dev.arkbuilders.arkmemo.utils.replaceFragment
class NotesListAdapter(private val notes: List<Note>):
RecyclerView.Adapter<NotesListAdapter.NoteViewHolder>() {

private var activity: MainActivity? = null
private var fragmentManager: FragmentManager? = null
private lateinit var activity: MainActivity
private lateinit var fragmentManager: FragmentManager

fun setActivity(activity: AppCompatActivity) {
this.activity = activity as MainActivity
Expand All @@ -40,7 +40,7 @@ class NotesListAdapter(private val notes: List<Note>):
override fun onBindViewHolder(holder: NoteViewHolder, position: Int) {
holder.title.text = notes[position].title
holder.date.text = notes[position].resource?.modified?.toString() ?:
activity?.getString(R.string.ark_memo_just_now)
activity.getString(R.string.ark_memo_just_now)
}

override fun getItemCount() = notes.size
Expand All @@ -56,19 +56,19 @@ class NotesListAdapter(private val notes: List<Note>):
private val clickNoteToEditListener = View.OnClickListener {
var tag = EditTextNotesFragment.TAG
when (val selectedNote = notes[bindingAdapterPosition]) {
is TextNote -> activity?.fragment = EditTextNotesFragment.newInstance(selectedNote)
is TextNote -> activity.fragment = EditTextNotesFragment.newInstance(selectedNote)
is GraphicNote -> {
activity?.fragment = EditGraphicNotesFragment.newInstance(selectedNote)
activity.fragment = EditGraphicNotesFragment.newInstance(selectedNote)
tag = EditGraphicNotesFragment.TAG
}
}
activity?.replaceFragment(activity?.fragment!!, tag)
activity.replaceFragment(activity.fragment, tag)
}

private val deleteNoteClickListener = View.OnClickListener {
NoteDeleteDialog()
.setNoteToBeDeleted(notes[bindingAdapterPosition])
.show(fragmentManager!!, NoteDeleteDialog.TAG)
.show(fragmentManager, NoteDeleteDialog.TAG)
}

init {
Expand Down

0 comments on commit 3858f14

Please sign in to comment.