Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions moti/app/src/main/java/com/example/moti/ui/map/MapFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.ImageButton
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.app.ActivityCompat
Expand Down Expand Up @@ -55,6 +58,10 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class MapFragment : Fragment(), OnMapReadyCallback, GoogleMap.OnMarkerClickListener {

private lateinit var colorFilterSpinner: Spinner
private var selectedTagColor: TagColor? = null

private val radioButtonViewModel: RadioButtonViewModel by activityViewModels()
private lateinit var googleMap: GoogleMap
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
Expand Down Expand Up @@ -128,6 +135,37 @@ class MapFragment : Fragment(), OnMapReadyCallback, GoogleMap.OnMarkerClickListe
tagColorViewModel.selectedTagColor.observe(viewLifecycleOwner) { tagColor ->
updateMarkerColor(tagColor)
}


colorFilterSpinner = view.findViewById(R.id.spinner_color_filter)
val adapter = ArrayAdapter.createFromResource(
requireContext(),
R.array.tag_colors_array,
R.layout.custom_spinner_item
)
adapter.setDropDownViewResource(R.layout.custom_spinner_dropdown_item)
colorFilterSpinner.adapter = adapter

colorFilterSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) {
selectedTagColor = when (position) {
1 -> TagColor.RD
2 -> TagColor.OG
3 -> TagColor.YE
4 -> TagColor.GN
5 -> TagColor.BU
6 -> TagColor.PU
7 -> TagColor.BK
else -> null
}
filteringMarkers()
}

override fun onNothingSelected(parent: AdapterView<*>) {
selectedTagColor = null
filteringMarkers()
}
}
}

private fun updateMarkerColor(tagColor: TagColor) {
Expand Down Expand Up @@ -283,6 +321,13 @@ class MapFragment : Fragment(), OnMapReadyCallback, GoogleMap.OnMarkerClickListe
TagColor.BK to R.drawable.black_pin_marker
)

private fun filteringMarkers() {
markers.forEach { marker ->
val place = places.find { it.alarmId.toString() == marker.snippet }
marker.isVisible = selectedTagColor == null || place?.tagColor == selectedTagColor
}
}

private fun updateMarkers() {
markers.forEach { marker ->
// ๋งˆ์ปค ์•„์ด์ฝ˜์„ ๋ณ€๊ฒฝํ•˜๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜
Expand Down
5 changes: 5 additions & 0 deletions moti/app/src/main/res/drawable/spinner_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/white" />
<corners android:radius="8dp" />
<stroke android:width="1dp" android:color="@android:color/darker_gray" />
</shape>
10 changes: 10 additions & 0 deletions moti/app/src/main/res/layout/custom_spinner_dropdown_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_spinner_dropdown_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textColor="@android:color/black"
android:background="?android:attr/selectableItemBackground"
android:textSize="16sp"
android:gravity="center_vertical" />
10 changes: 10 additions & 0 deletions moti/app/src/main/res/layout/custom_spinner_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_spinner_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textColor="@android:color/black"
android:background="?android:attr/selectableItemBackground"
android:textSize="16sp"
android:gravity="center_vertical" />
12 changes: 10 additions & 2 deletions moti/app/src/main/res/layout/fragment_map.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.map.MapFragment">

<fragment
Expand Down Expand Up @@ -35,4 +35,12 @@
app:backgroundTint="@color/mt_main"
android:contentDescription="search" />

</FrameLayout>
<Spinner
android:id="@+id/spinner_color_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_gravity="top|start"
android:entries="@array/tag_colors_array"
android:background="@drawable/spinner_background" />
</FrameLayout>
11 changes: 11 additions & 0 deletions moti/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@
<string name="silent_alarm_summary">silent alarm</string>
<string name="cancel_share">๊ณต์œ  ์ทจ์†Œ</string>
<string name="complete">์™„๋ฃŒ</string>
<string-array name="tag_colors_array">
<item>๋ชจ๋“  ์ƒ‰์ƒ</item>
<item>๋นจ๊ฐ•</item>
<item>์ฃผํ™ฉ</item>
<item>๋…ธ๋ž‘</item>
<item>์ดˆ๋ก</item>
<item>ํŒŒ๋ž‘</item>
<item>๋ณด๋ผ</item>
<item>๊ฒ€์ •</item>
</string-array>

</resources>