From 6ff61c7c2fbbd8ef176f9ff2f4e5354e30f3a7f4 Mon Sep 17 00:00:00 2001 From: "Ahmad N. Primordi" Date: Wed, 20 Nov 2019 20:23:50 +0700 Subject: [PATCH] update hasil activity, add hasil adapter --- .../feature/diagnosis/DiagnosisAdapter.kt | 354 ++++++++---------- .../lovebird/feature/hasil/HasilActivity.kt | 23 ++ .../lovebird/feature/hasil/HasilAdapter.kt | 51 +++ .../lovebird/repository/model/Penyakit.kt | 3 + .../main/res/drawable/ic_circle_green_8dp.xml | 4 + app/src/main/res/layout/activity_hasil.xml | 4 +- app/src/main/res/layout/item_hasil.xml | 25 ++ app/src/main/res/values/strings.xml | 2 + 8 files changed, 263 insertions(+), 203 deletions(-) create mode 100644 app/src/main/java/com/makaryostudio/lovebird/feature/hasil/HasilAdapter.kt create mode 100644 app/src/main/res/drawable/ic_circle_green_8dp.xml create mode 100644 app/src/main/res/layout/item_hasil.xml 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 4e5e5d8..152c766 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 @@ -15,16 +15,16 @@ class DiagnosisAdapter internal constructor(private val context: Context) : RecyclerView.Adapter() { private var mCheckedGejala: ArrayList = ArrayList() - private var inputGejala : ArrayList = ArrayList() + private var inputGejala: ArrayList = ArrayList() //Array Penyakit - private var cacingan : ArrayList = arrayListOf(0,1,2,3,4) - private var kutuBurung : ArrayList = arrayListOf(0,4,5,6,9) - private var snot : ArrayList = arrayListOf(0,7,8,11,12) - private var berakKapur : ArrayList = arrayListOf(0,1,10,17) - private var mencretBakteri : ArrayList = arrayListOf(0,1,2) - private var bubul : ArrayList = arrayListOf(13,14) - private var virusBurung: ArrayList = arrayListOf(15,16) + private var cacingan: ArrayList = arrayListOf(0, 1, 2, 3, 4) + private var kutuBurung: ArrayList = arrayListOf(0, 4, 5, 6, 9) + private var snot: ArrayList = arrayListOf(0, 7, 8, 11, 12) + private var berakKapur: ArrayList = arrayListOf(0, 1, 10, 17) + private var mencretBakteri: ArrayList = arrayListOf(0, 1, 2) + private var bubul: ArrayList = arrayListOf(13, 14) + private var virusBurung: ArrayList = arrayListOf(15, 16) private var mListData: List @@ -52,7 +52,7 @@ class DiagnosisAdapter internal constructor(private val context: Context) : override fun onBindViewHolder(holder: ViewHolder, position: Int) { val gejala = mListData[position] - holder.mCbGejala.text = gejala.gejalaDialami.toString() + holder.mCbGejala.text = gejala.gejalaDialami holder.mCbGejala.isChecked = gejala.isChecked holder.mCbGejala.setOnClickListener { @@ -69,8 +69,6 @@ class DiagnosisAdapter internal constructor(private val context: Context) : println(element) } - - } else { holder.mCbGejala.isChecked = false gejala.isChecked = false @@ -78,64 +76,56 @@ class DiagnosisAdapter internal constructor(private val context: Context) : inputGejala.remove(gejala.kodeGejala) } - intent.putExtra("checked", mCheckedGejala) intent.putExtra("gejala", gejala) } - - - - } - fun cbr(){ - - - var hs1:Float =0f - var hs2:Float =0f - var hs3:Float =0f - var hs4:Float =0f - var hs5:Float =0f - var hs6:Float =0f - var hs7:Float =0f - - + class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + var mCbGejala: CheckBox = itemView.findViewById(R.id.checkbox_gejala) + } - var tb1:Float =0f - var tb2:Float =0f - var tb3:Float =0f - var tb4:Float =0f - var tb5:Float =0f - var tb6:Float =0f - var tb7:Float =0f + fun cbr() { + var hs1: Float = 0f + var hs2: Float = 0f + var hs3: Float = 0f + var hs4: Float = 0f + var hs5: Float = 0f + var hs6: Float = 0f + var hs7: Float = 0f - var tbp1:Float =0f - var tbp2:Float =0f - var tbp3:Float =0f - var tbp4:Float =0f - var tbp5:Float =0f - var tbp6:Float =0f - var tbp7:Float =0f + var tb1: Float = 0f + var tb2: Float = 0f + var tb3: Float = 0f + var tb4: Float = 0f + var tb5: Float = 0f + var tb6: Float = 0f + var tb7: Float = 0f + var tbp1: Float = 0f + var tbp2: Float = 0f + var tbp3: Float = 0f + var tbp4: Float = 0f + var tbp5: Float = 0f + var tbp6: Float = 0f + var tbp7: Float = 0f - var Penyakit: String="" - var persentaseCBR: Float=0f - var bobotMax: Float=0f + var Penyakit: String = "" + var persentaseCBR: Float = 0f + var bobotMax: Float = 0f //Penyakit 1 - for (i in 0 until cacingan.size){ + for (i in 0 until cacingan.size) { - //total bobot - tbp1 += mListData[cacingan[i]].bobot - for(j in 0 until inputGejala.size) - { + //total bobot + tbp1 += mListData[cacingan[i]].bobot + for (j in 0 until inputGejala.size) { - if(cacingan[i]==inputGejala[j]) - { + if (cacingan[i] == inputGejala[j]) { tb1 += mListData[cacingan[i]].bobot } @@ -143,14 +133,12 @@ class DiagnosisAdapter internal constructor(private val context: Context) : } //Penyakit 2 - for (i in 0 until kutuBurung.size){ + for (i in 0 until kutuBurung.size) { //total bobot tbp2 += mListData[kutuBurung[i]].bobot - for(j in 0 until inputGejala.size) - { - if(kutuBurung[i]==inputGejala[j]) - { + for (j in 0 until inputGejala.size) { + if (kutuBurung[i] == inputGejala[j]) { tb2 += mListData[kutuBurung[i]].bobot } @@ -159,14 +147,12 @@ class DiagnosisAdapter internal constructor(private val context: Context) : //Penyakit 3 - for (i in 0 until snot.size){ + for (i in 0 until snot.size) { //total bobot tbp3 += mListData[snot[i]].bobot - for(j in 0 until inputGejala.size) - { - if(snot[i]==inputGejala[j]) - { + for (j in 0 until inputGejala.size) { + if (snot[i] == inputGejala[j]) { tb3 += mListData[snot[i]].bobot } @@ -175,14 +161,12 @@ class DiagnosisAdapter internal constructor(private val context: Context) : //Penyakit 4 - for (i in 0 until berakKapur.size){ + for (i in 0 until berakKapur.size) { //total bobot tbp4 += mListData[berakKapur[i]].bobot - for(j in 0 until inputGejala.size) - { - if(berakKapur[i]==inputGejala[j]) - { + for (j in 0 until inputGejala.size) { + if (berakKapur[i] == inputGejala[j]) { tb4 += mListData[berakKapur[i]].bobot } @@ -190,192 +174,160 @@ class DiagnosisAdapter internal constructor(private val context: Context) : } //Penyakit 5 - for (i in 0 until mencretBakteri.size){ + for (i in 0 until mencretBakteri.size) { //total bobot tbp5 += mListData[mencretBakteri[i]].bobot - for(j in 0 until inputGejala.size) - { - if(mencretBakteri[i]==inputGejala[j]) - { + for (j in 0 until inputGejala.size) { + if (mencretBakteri[i] == inputGejala[j]) { tb5 += mListData[mencretBakteri[i]].bobot - } } } //Penyakit 6 - for (i in 0 until bubul.size){ + for (i in 0 until bubul.size) { //total bobot tbp6 += mListData[bubul[i]].bobot - for(j in 0 until inputGejala.size) - { - if(bubul[i]==inputGejala[j]) - { + for (j in 0 until inputGejala.size) { + if (bubul[i] == inputGejala[j]) { tb6 += mListData[bubul[i]].bobot - } } } //Penyakit 7 - for (i in 0 until virusBurung.size){ + for (i in 0 until virusBurung.size) { //total bobot tbp7 += mListData[virusBurung[i]].bobot - for(j in 0 until inputGejala.size) - { - if(virusBurung[i]==inputGejala[j]) - { + for (j in 0 until inputGejala.size) { + if (virusBurung[i] == inputGejala[j]) { tb7 += mListData[virusBurung[i]].bobot } } } - - hs1=(tb1/tbp1)*100 - hs2=(tb2/tbp2)*100 - hs3=(tb3/tbp3)*100 - hs4=(tb4/tbp4)*100 - hs5=(tb5/tbp5)*100 - hs6=(tb6/tbp7)*100 - hs7=(tb7/tbp7)*100 - println("Hasil : "+hs1) - println("TB : "+ tb1) - println("TBP : "+ tbp1) - println("Hasil : "+hs2) - println("TB : "+ tb2) - println("TBP : "+ tbp2) - println("Hasil : "+hs3) - println("TB : "+ tb3) - println("TBP : "+ tbp3) - println("Hasil : "+hs4) - println("TB : "+ tb4) - println("TBP : "+ tbp4) - println("Hasil : "+hs5) - println("TB : "+ tb5) - println("TBP : "+ tbp5) - println("Hasil : "+hs6) - println("TB : "+ tb6) - println("TBP : "+ tbp6) - println("Hasil : "+hs7) - println("TB : "+ tb7) - println("TBP : "+ tbp7) - - + hs1 = (tb1 / tbp1) * 100 + hs2 = (tb2 / tbp2) * 100 + hs3 = (tb3 / tbp3) * 100 + hs4 = (tb4 / tbp4) * 100 + hs5 = (tb5 / tbp5) * 100 + hs6 = (tb6 / tbp7) * 100 + hs7 = (tb7 / tbp7) * 100 + println("Hasil : $hs1") + println("TB : $tb1") + println("TBP : $tbp1") + println("Hasil : $hs2") + println("TB : $tb2") + println("TBP : $tbp2") + println("Hasil : $hs3") + println("TB : $tb3") + println("TBP : $tbp3") + println("Hasil : $hs4") + println("TB : $tb4") + println("TBP : $tbp4") + println("Hasil : $hs5") + println("TB : $tb5") + println("TBP : $tbp5") + println("Hasil : $hs6") + println("TB : $tb6") + println("TBP : $tbp6") + println("Hasil : $hs7") + println("TB : $tb7") + println("TBP : $tbp7") //Searching paling besar - if (hs1>persentaseCBR){ - persentaseCBR=hs1 - Penyakit="Cacingan" - bobotMax=tb1 - } - else if(hs1==persentaseCBR) { - if (bobotMax < tb1) - { - persentaseCBR=hs1 - Penyakit="Cacingan" - bobotMax=tb1 + if (hs1 > persentaseCBR) { + persentaseCBR = hs1 + Penyakit = "Cacingan" + bobotMax = tb1 + } else if (hs1 == persentaseCBR) { + if (bobotMax < tb1) { + persentaseCBR = hs1 + Penyakit = "Cacingan" + bobotMax = tb1 } } - if (hs2>persentaseCBR){ - persentaseCBR=hs2 - Penyakit="Kutu Burung" - bobotMax=tb2 - } - else if(hs2==persentaseCBR) { - if (bobotMax < tb2) - { - persentaseCBR=hs2 - Penyakit="Kutu Burung" - bobotMax=tb2 + if (hs2 > persentaseCBR) { + persentaseCBR = hs2 + Penyakit = "Kutu Burung" + bobotMax = tb2 + } else if (hs2 == persentaseCBR) { + if (bobotMax < tb2) { + persentaseCBR = hs2 + Penyakit = "Kutu Burung" + bobotMax = tb2 } } - if (hs3>persentaseCBR){ - persentaseCBR=hs3 - Penyakit="Snot" - bobotMax=tb3 - } - else if(hs3==persentaseCBR) { - if (bobotMax < tb3) - { - persentaseCBR=hs3 - Penyakit="Snot" - bobotMax=tb3 + if (hs3 > persentaseCBR) { + persentaseCBR = hs3 + Penyakit = "Snot" + bobotMax = tb3 + } else if (hs3 == persentaseCBR) { + if (bobotMax < tb3) { + persentaseCBR = hs3 + Penyakit = "Snot" + bobotMax = tb3 } } - if (hs4>persentaseCBR){ - persentaseCBR=hs4 - Penyakit="Berak Kapur" - bobotMax=tb4 - } - else if(hs4==persentaseCBR) { - if (bobotMax < tb4) - { - persentaseCBR=hs4 - Penyakit="Berak Kapur" - bobotMax=tb4 + if (hs4 > persentaseCBR) { + persentaseCBR = hs4 + Penyakit = "Berak Kapur" + bobotMax = tb4 + } else if (hs4 == persentaseCBR) { + if (bobotMax < tb4) { + persentaseCBR = hs4 + Penyakit = "Berak Kapur" + bobotMax = tb4 } } - if (hs5>persentaseCBR){ - persentaseCBR=hs5 - Penyakit="Mencret Bakteri" - bobotMax=tb5 - } - else if(hs5==persentaseCBR) { - if (bobotMax < tb5) - { - persentaseCBR=hs5 - Penyakit="Mencret Bakteri" - bobotMax=tb5 + if (hs5 > persentaseCBR) { + persentaseCBR = hs5 + Penyakit = "Mencret Bakteri" + bobotMax = tb5 + } else if (hs5 == persentaseCBR) { + if (bobotMax < tb5) { + persentaseCBR = hs5 + Penyakit = "Mencret Bakteri" + bobotMax = tb5 } } - if (hs6>persentaseCBR){ - persentaseCBR=hs6 - Penyakit="Bubul" - bobotMax=tb6 - } - else if(hs6==persentaseCBR) { - if (bobotMax < tb6) - { - persentaseCBR=hs6 - Penyakit="Bubul" - bobotMax=tb6 + if (hs6 > persentaseCBR) { + persentaseCBR = hs6 + Penyakit = "Bubul" + bobotMax = tb6 + } else if (hs6 == persentaseCBR) { + if (bobotMax < tb6) { + persentaseCBR = hs6 + Penyakit = "Bubul" + bobotMax = tb6 } } - if (hs7>persentaseCBR){ - persentaseCBR=hs7 - Penyakit="Virus Burung" - bobotMax=tb7 - } - else if(hs7==persentaseCBR) { - if (bobotMax < tb7) - { - persentaseCBR=hs7 - Penyakit="Virus Burung" - bobotMax=tb7 + if (hs7 > persentaseCBR) { + persentaseCBR = hs7 + Penyakit = "Virus Burung" + bobotMax = tb7 + } else if (hs7 == persentaseCBR) { + if (bobotMax < tb7) { + persentaseCBR = hs7 + Penyakit = "Virus Burung" + bobotMax = tb7 } } - println("Diagnosa Penyakit : "+Penyakit) - println("Persentase CBR : "+persentaseCBR) - + println("Diagnosa Penyakit : " + Penyakit) + println("Persentase CBR : " + persentaseCBR) } - class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - var mCbGejala: CheckBox = itemView.findViewById(R.id.checkbox_gejala) - } - - - } \ No newline at end of file diff --git a/app/src/main/java/com/makaryostudio/lovebird/feature/hasil/HasilActivity.kt b/app/src/main/java/com/makaryostudio/lovebird/feature/hasil/HasilActivity.kt index f2917e5..8d59f70 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/feature/hasil/HasilActivity.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/feature/hasil/HasilActivity.kt @@ -2,12 +2,35 @@ package com.makaryostudio.lovebird.feature.hasil import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView import com.makaryostudio.lovebird.R +import com.makaryostudio.lovebird.repository.model.Gejala class HasilActivity : AppCompatActivity() { + private lateinit var textNamaBurung: TextView + private lateinit var adapter: RecyclerView + private lateinit var textHasilDiagnosis: TextView + private lateinit var textSolusi: TextView + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_hasil) + + val gejala = intent.getParcelableExtra("gejala") + val checked = intent.getBooleanArrayExtra("checked") + val namaBurung = intent.getStringExtra("namaBurung") + + textNamaBurung.text = namaBurung + + bindView() + } + + private fun bindView() { + textNamaBurung = findViewById(R.id.text_nama_burung) + adapter = findViewById(R.id.rv_gejala_dialami) + textHasilDiagnosis = findViewById(R.id.text_hasil_diagnosis) + textSolusi = findViewById(R.id.text_solusi) } } diff --git a/app/src/main/java/com/makaryostudio/lovebird/feature/hasil/HasilAdapter.kt b/app/src/main/java/com/makaryostudio/lovebird/feature/hasil/HasilAdapter.kt new file mode 100644 index 0000000..d893e47 --- /dev/null +++ b/app/src/main/java/com/makaryostudio/lovebird/feature/hasil/HasilAdapter.kt @@ -0,0 +1,51 @@ +package com.makaryostudio.lovebird.feature.hasil + +import android.content.Context +import android.content.Intent +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.makaryostudio.lovebird.R +import com.makaryostudio.lovebird.repository.model.Gejala +import com.makaryostudio.lovebird.repository.model.Penyakit +import kotlinx.android.synthetic.main.item_hasil.view.* + +class HasilAdapter internal constructor(private val context: Context) : + RecyclerView.Adapter() { + + private var mListData: List + + init { + mListData = ArrayList() + notifyDataSetChanged() + } + + //constructor mListData + fun loadListData(mListData: List) { + this.mListData = mListData + notifyDataSetChanged() + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.item_hasil, parent, false) + return ViewHolder(view) + } + + override fun getItemCount(): Int { + return mListData.size + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val penyakit = mListData[position] + +// val gejala = Intent() +// gejala.getParcelableExtra("gejala") + holder.textGejalaDialami.text = penyakit.gejalaDialami + } + + class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + var textGejalaDialami: TextView = itemView.findViewById(R.id.text_hasil_gejala) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/makaryostudio/lovebird/repository/model/Penyakit.kt b/app/src/main/java/com/makaryostudio/lovebird/repository/model/Penyakit.kt index aafd417..0b32f12 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/repository/model/Penyakit.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/repository/model/Penyakit.kt @@ -6,11 +6,13 @@ import android.os.Parcelable data class Penyakit( var kodePenyakit: Int, var namaPenyakit: String?, + var gejalaDialami: String?, var deskripsiPenyakit: String? ) : Parcelable { constructor(parcel: Parcel) : this( parcel.readInt(), parcel.readString(), + parcel.readString(), parcel.readString() ) { } @@ -18,6 +20,7 @@ data class Penyakit( override fun writeToParcel(parcel: Parcel, flags: Int) { parcel.writeInt(kodePenyakit) parcel.writeString(namaPenyakit) + parcel.writeString(gejalaDialami) parcel.writeString(deskripsiPenyakit) } diff --git a/app/src/main/res/drawable/ic_circle_green_8dp.xml b/app/src/main/res/drawable/ic_circle_green_8dp.xml new file mode 100644 index 0000000..6d958e8 --- /dev/null +++ b/app/src/main/res/drawable/ic_circle_green_8dp.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/layout/activity_hasil.xml b/app/src/main/res/layout/activity_hasil.xml index 0497357..3c20a90 100644 --- a/app/src/main/res/layout/activity_hasil.xml +++ b/app/src/main/res/layout/activity_hasil.xml @@ -21,7 +21,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:text="@string/diagnosis_isi_form_text" + android:text="@string/hasil_diagnosis_text" android:textAppearance="@style/TextAppearance.AppCompat.Large" android:textColor="@color/primary_text" app:layout_constraintBottom_toTopOf="@id/guideline_horizontal_top" @@ -94,7 +94,7 @@ app:layout_constraintEnd_toEndOf="@id/text_nama_burung" app:layout_constraintStart_toStartOf="@id/text_nama_burung" app:layout_constraintTop_toBottomOf="@id/text_gejala_dialami" - tools:listitem="@layout/item_gejala" /> + tools:listitem="@layout/item_hasil" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa1f82d..f24a39a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -19,6 +19,8 @@ Gejala yang dialami Diagnosis penyakit Solusi + Hasil Diagnosis + Gambar titik hijau pada item hasil