From 4680228609fe7bcbdcc72c514fc66de3e3eda4b0 Mon Sep 17 00:00:00 2001 From: "Ahmad N. Primordi" Date: Fri, 15 Nov 2019 13:22:29 +0700 Subject: [PATCH] update checkbox logic pojo gejala and meta-database. --- .../feature/diagnosis/DiagnosisActivity.kt | 3 +-- .../feature/diagnosis/DiagnosisAdapter.kt | 25 +++++++++++-------- .../feature/diagnosis/DiagnosisContract.kt | 2 +- .../feature/diagnosis/DiagnosisPresenter.kt | 22 ++++++++-------- .../lovebird/repository/model/Gejala.kt | 22 ++++++++-------- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisActivity.kt b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisActivity.kt index 6b37db6..0ef5138 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisActivity.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisActivity.kt @@ -23,7 +23,7 @@ class DiagnosisActivity : AppCompatActivity(), DiagnosisContract.View { override fun onLoadListGejalaSucceed(listGejala: List) { - + rvGejala.setHasFixedSize(true) adapter.loadListData(listGejala) } @@ -32,7 +32,6 @@ class DiagnosisActivity : AppCompatActivity(), DiagnosisContract.View { presenter.start() } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_diagnosis) diff --git a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisAdapter.kt b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisAdapter.kt index 9b63d47..c8a733c 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisAdapter.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisAdapter.kt @@ -8,11 +8,13 @@ import android.view.ViewGroup import android.widget.CheckBox import androidx.recyclerview.widget.RecyclerView import com.makaryostudio.lovebird.R +import com.makaryostudio.lovebird.feature.hasil.HasilActivity import com.makaryostudio.lovebird.repository.model.Gejala class DiagnosisAdapter internal constructor(private val context: Context) : RecyclerView.Adapter() { + private var mCheckedGejala: ArrayList = ArrayList() private var mListData: List init { @@ -39,24 +41,25 @@ class DiagnosisAdapter internal constructor(private val context: Context) : override fun onBindViewHolder(holder: ViewHolder, position: Int) { val gejala = mListData[position] - holder.mCbGejala.text = gejala.gejalaDialami - holder.mCbGejala.isChecked = gejala.checked + holder.mCbGejala.text = gejala.gejalaDialami.toString() + holder.mCbGejala.isChecked = gejala.isChecked holder.mCbGejala.setOnClickListener { - if (!gejala.checked) { + val intent = Intent(context, HasilActivity::class.java) + + if (!gejala.isChecked) { holder.mCbGejala.isChecked = true - gejala.checked = true + gejala.isChecked = true + mCheckedGejala.add(gejala) } else { holder.mCbGejala.isChecked = false - gejala.checked = false + gejala.isChecked = false + mCheckedGejala.remove(gejala) } - } -// if (holder.mCbGejala.isChecked) { -// val intent = Intent() -// intent.putExtra("checked", holder.mCbGejala.isChecked) -// intent.putExtra("gejala", gejala) -// } + intent.putExtra("checked", mCheckedGejala) + intent.putExtra("gejala", gejala) + } } class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { diff --git a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisContract.kt b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisContract.kt index 96442a5..b6b719d 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisContract.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisContract.kt @@ -7,7 +7,7 @@ import com.makaryostudio.lovebird.repository.model.Gejala interface DiagnosisContract { interface Presenter : BasePresenter { fun loadListGejala() - fun getSelectedItems(isSelected: Boolean): ArrayList +// fun getSelectedItems(isSelected: Boolean): ArrayList } interface View : BaseView { diff --git a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisPresenter.kt b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisPresenter.kt index 386cd1c..d1b5718 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisPresenter.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisPresenter.kt @@ -1,25 +1,25 @@ package com.makaryostudio.lovebird.feature.diagnosis +import com.makaryostudio.lovebird.R import com.makaryostudio.lovebird.repository.model.Gejala class DiagnosisPresenter internal constructor(private val view: DiagnosisContract.View) : DiagnosisContract.Presenter { - override fun getSelectedItems(isSelected: Boolean): ArrayList { - TODO("mengambil list yang dipilih") -// val list: ArrayList -// for (i in 0..18 ) { +// override fun getSelectedItems(isSelected: Boolean): ArrayList { +// TODO("mengambil list yang dipilih") +// var list: ArrayList = ArrayList() // +// val gejala: Gejala = Gejala() // -// } -// return list - } +// gejala.checked +// } override fun loadListGejala() { + val listGejala = arrayListOf( + Gejala(R.array.array_kode_gejala, R.array.array_nama_gejala, R.array.array_bobot_gejala) + ) - TODO("what kind of database are we going to use?") -// val listGejala -// -// view.onLoadListGejalaSucceed(listGejala) + view.onLoadListGejalaSucceed(listGejala) } override fun start() { diff --git a/app/src/main/java/com/makaryostudio/lovebird/repository/model/Gejala.kt b/app/src/main/java/com/makaryostudio/lovebird/repository/model/Gejala.kt index bf49c12..9ea6432 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/repository/model/Gejala.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/repository/model/Gejala.kt @@ -4,24 +4,25 @@ import android.os.Parcel import android.os.Parcelable data class Gejala( - var kodeGejala: String = "", - var gejalaDialami: String = "", - var bobot: Int, - var checked: Boolean = false + var kodeGejala: Int, + var gejalaDialami: Int, + var bobot: Int ) : Parcelable { + var isChecked: Boolean = false + constructor(parcel: Parcel) : this( - parcel.readString().toString(), - parcel.readString().toString(), parcel.readInt(), - parcel.readByte() != 0.toByte() + parcel.readInt(), + parcel.readInt() ) { + isChecked = parcel.readByte() != 0.toByte() } override fun writeToParcel(parcel: Parcel, flags: Int) { - parcel.writeString(kodeGejala) - parcel.writeString(gejalaDialami) + parcel.writeInt(kodeGejala) + parcel.writeInt(gejalaDialami) parcel.writeInt(bobot) - parcel.writeByte(if (checked) 1 else 0) + parcel.writeByte(if (isChecked) 1 else 0) } override fun describeContents(): Int { @@ -37,4 +38,5 @@ data class Gejala( return arrayOfNulls(size) } } + } \ No newline at end of file