Skip to content

Commit

Permalink
update checkbox logic pojo gejala and meta-database.
Browse files Browse the repository at this point in the history
  • Loading branch information
anprimordi committed Nov 15, 2019
1 parent 282bb8f commit 4680228
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DiagnosisActivity : AppCompatActivity(), DiagnosisContract.View {


override fun onLoadListGejalaSucceed(listGejala: List<Gejala>) {

rvGejala.setHasFixedSize(true)
adapter.loadListData(listGejala)
}

Expand All @@ -32,7 +32,6 @@ class DiagnosisActivity : AppCompatActivity(), DiagnosisContract.View {
presenter.start()
}


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_diagnosis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiagnosisAdapter.ViewHolder>() {

private var mCheckedGejala: ArrayList<Gejala> = ArrayList()
private var mListData: List<Gejala>

init {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.makaryostudio.lovebird.repository.model.Gejala
interface DiagnosisContract {
interface Presenter : BasePresenter {
fun loadListGejala()
fun getSelectedItems(isSelected: Boolean): ArrayList<Gejala>
// fun getSelectedItems(isSelected: Boolean): ArrayList<Gejala>
}

interface View : BaseView<Presenter> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Gejala> {
TODO("mengambil list yang dipilih")
// val list: ArrayList<Gejala>
// for (i in 0..18 ) {
// override fun getSelectedItems(isSelected: Boolean): ArrayList<Gejala> {
// TODO("mengambil list yang dipilih")
// var list: ArrayList<Gejala> = 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -37,4 +38,5 @@ data class Gejala(
return arrayOfNulls(size)
}
}

}

0 comments on commit 4680228

Please sign in to comment.