Skip to content

Commit 04fa7f3

Browse files
committed
[+]add place history button @ dashboard, [#]replace textinputlayout with spinner, [#]set icon based on history category
1 parent 5a4f6a3 commit 04fa7f3

20 files changed

+183
-30
lines changed

app/src/main/java/com/soerjdev/smkcodingproject2/adapter/PlaceHistoryAdapter.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ class PlaceHistoryAdapter(
4444
fun bindItem(item: PlaceHistory){
4545
tvPlaceNameItemPlaceHistory.text = item.placeName
4646
tvAddresItemPlaceHistory.text = item.placeAddres
47+
tvDateItemPlaceHistory.text = item.placeDate
48+
49+
when (item.placeCategory){
50+
"Pekerjaan" -> ivTypeItemPlaceHistory.setBackgroundResource(R.drawable.ic_action_work)
51+
"Belajar" -> ivTypeItemPlaceHistory.setBackgroundResource(R.drawable.ic_action_school)
52+
"Belanja" -> ivTypeItemPlaceHistory.setBackgroundResource(R.drawable.ic_action_local_grocery_store)
53+
}
4754

4855
val database = FirebaseDatabase.getInstance()
4956
val auth = FirebaseAuth.getInstance()

app/src/main/java/com/soerjdev/smkcodingproject2/ui/AddPlaceHistoryActivity.kt

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package com.soerjdev.smkcodingproject2.ui
33
import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
55
import android.util.Log
6+
import android.view.View
7+
import android.widget.AdapterView
8+
import android.widget.ArrayAdapter
69
import android.widget.Toast
710
import com.google.firebase.auth.FirebaseAuth
811
import com.google.firebase.database.DatabaseReference
@@ -14,14 +17,19 @@ import com.soerjdev.smkcodingproject2.utils.showToast
1417
import kotlinx.android.synthetic.*
1518
import kotlinx.android.synthetic.main.activity_add_place_history.*
1619

17-
class AddPlaceHistoryActivity : AppCompatActivity() {
20+
class AddPlaceHistoryActivity : AppCompatActivity(),
21+
AdapterView.OnItemSelectedListener {
1822

1923
private val database = FirebaseDatabase.getInstance()
2024
private val auth = FirebaseAuth.getInstance()
2125
private lateinit var databaseRef: DatabaseReference
2226
private var OPERATION_TYPE = ""
2327
private var updatedDataUid = ""
2428

29+
private lateinit var adapter: ArrayAdapter<CharSequence>
30+
31+
private var categoryPlaceHistory = ""
32+
2533
private var TAG = AddPlaceHistoryActivity::class.java.name
2634

2735
companion object {
@@ -47,6 +55,14 @@ class AddPlaceHistoryActivity : AppCompatActivity() {
4755

4856
OPERATION_TYPE = intent.getStringExtra(TAG_OPERATION_TYPE)!!
4957

58+
adapter = ArrayAdapter.createFromResource(
59+
this,
60+
R.array.place_history_type,
61+
android.R.layout.simple_spinner_item
62+
)
63+
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
64+
spinnerCategoryAddPlaceHistory.adapter = adapter
65+
5066
if(OPERATION_TYPE == "Update"){
5167
val placeName = intent.getStringExtra(PLACE_NAME)
5268
val placeAddress = intent.getStringExtra(PLACE_ADDRESS)
@@ -59,6 +75,8 @@ class AddPlaceHistoryActivity : AppCompatActivity() {
5975

6076
databaseRef = database.getReference("place_history")
6177

78+
spinnerCategoryAddPlaceHistory.onItemSelectedListener = this
79+
6280
tbAddPlaceHistory.setNavigationOnClickListener { finish() }
6381

6482
if(OPERATION_TYPE == "Update"){
@@ -75,24 +93,26 @@ class AddPlaceHistoryActivity : AppCompatActivity() {
7593
private fun setToTextInput(placeName: String?, placeDate: String?, placeAddress: String?, placeType: String?) {
7694
tieNameAddPlaceHistory.setText(placeName)
7795
tieAddressAddPlaceHistory.setText(placeAddress)
78-
tieCategoryAddPlaceHistory.setText(placeType)
96+
97+
val spinnerPosition = adapter.getPosition(placeType)
98+
spinnerCategoryAddPlaceHistory.setSelection(spinnerPosition)
99+
79100
tieDateAddPlaceHistory.setText(placeDate)
80101
}
81102

82103
private fun checkForm() {
83104
val placeName = tieNameAddPlaceHistory.text.toString()
84105
val placeAddress = tieAddressAddPlaceHistory.text.toString()
85-
val placeType = tieCategoryAddPlaceHistory.text.toString()
86106
val placeDate = tieDateAddPlaceHistory.text.toString()
87107

88108
when {
89109
placeName.isEmpty() -> tilNameAddPlaceHistory.error = "Isi nama tempat !"
90110
placeAddress.isEmpty() -> tilAddressAddPlaceHistory.error = "Isi alamat tempat !"
91-
placeType.isEmpty() -> tilCategoryAddPlaceHistory.error = "Isi jenis perjalanan !"
111+
categoryPlaceHistory.isEmpty() -> showToast(this,"Isi jenis perjalanan !")
92112
placeDate.isEmpty() -> tilDateAddPlaceHistory.error = "Isi tanggal perjalanan !"
93113
else -> when(OPERATION_TYPE){
94-
"Input" -> insertData(placeName, placeAddress, placeType, placeDate)
95-
"Update" -> updateData(placeName, placeAddress, placeType, placeDate)
114+
"Input" -> insertData(placeName, placeAddress, categoryPlaceHistory, placeDate)
115+
"Update" -> updateData(placeName, placeAddress, categoryPlaceHistory, placeDate)
96116
}
97117
}
98118
}
@@ -125,4 +145,13 @@ class AddPlaceHistoryActivity : AppCompatActivity() {
125145
super.onDestroy()
126146
this.clearFindViewByIdCache()
127147
}
148+
149+
150+
override fun onNothingSelected(p0: AdapterView<*>?) {
151+
152+
}
153+
154+
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
155+
categoryPlaceHistory = parent?.getItemAtPosition(position).toString()
156+
}
128157
}

app/src/main/java/com/soerjdev/smkcodingproject2/ui/fragment/DashboardFragment.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.soerjdev.smkcodingproject2.model.provdata.ProvData
1919
import com.soerjdev.smkcodingproject2.model.updatedata.UpdateData
2020
import com.soerjdev.smkcodingproject2.ui.AllCountryDataActivity
2121
import com.soerjdev.smkcodingproject2.ui.AllProvinceDataActivity
22+
import com.soerjdev.smkcodingproject2.ui.PlaceHistoryListActivity
2223
import com.soerjdev.smkcodingproject2.utils.ApiUtils
2324
import com.soerjdev.smkcodingproject2.viewmodel.GlobalSummaryViewModel
2425
import com.soerjdev.smkcodingproject2.viewmodel.IndoSummaryViewModel
@@ -82,6 +83,10 @@ class DashboardFragment : Fragment() {
8283
startActivity(Intent(context, AllCountryDataActivity::class.java))
8384
}
8485

86+
containerPlaceHistoryDashboard.setOnClickListener {
87+
startActivity(Intent(context, PlaceHistoryListActivity::class.java))
88+
}
89+
8590
indoSummaryViewModel.indoSummaryData.observe(viewLifecycleOwner, androidx.lifecycle.Observer { indoSummary ->
8691
indoSummary?.let {
8792
if(it != null){
@@ -250,7 +255,7 @@ class DashboardFragment : Fragment() {
250255
globalRecovered = response.body()!!.recovered.value
251256
globalDeath = response.body()!!.deaths.value
252257

253-
globalSummaryData = GlobalSummary(response.body()!!.confirmed.value, response.body()!!.recovered.value, response.body()!!.deaths.value)
258+
globalSummaryData = GlobalSummary(response.body()!!.confirmed.value, response.body()!!.deaths.value, response.body()!!.recovered.value)
254259
globalSummaryViewModel.insert(globalSummaryData)
255260

256261
containerDataDashboard.visibility = View.VISIBLE
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package com.soerjdev.smkcodingproject2.utils
22

3-
import android.app.ProgressDialog
43
import android.content.Context
54

app/src/main/res/drawable-anydpi/ic_action_local_grocery_store.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
android:height="24dp"
44
android:viewportWidth="24"
55
android:viewportHeight="24"
6-
android:tint="#4560DF"
6+
android:tint="#FFFFFF"
77
android:alpha="0.8">
88
<path
99
android:fillColor="#FF000000"

app/src/main/res/drawable-anydpi/ic_action_work.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
android:height="24dp"
44
android:viewportWidth="24"
55
android:viewportHeight="24"
6-
android:tint="#3185A4"
6+
android:tint="#FFFFFF"
77
android:alpha="0.8">
88
<path
99
android:fillColor="#FF000000"
-132 Bytes
Loading
-50 Bytes
Loading
-72 Bytes
Loading
-133 Bytes
Loading

0 commit comments

Comments
 (0)