Skip to content

Commit

Permalink
Sliding Drawer 구현
Browse files Browse the repository at this point in the history
버그 다수 존재
  • Loading branch information
SangwonYoon committed Jul 4, 2022
1 parent 3f19a5f commit ee3cdca
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 25 deletions.
39 changes: 39 additions & 0 deletions app/src/main/java/com/example/publictoilet/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import android.provider.Settings
import android.util.Base64
import android.util.Log
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.Toast
import androidx.annotation.NonNull
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.google.android.material.tabs.TabLayout
import net.daum.mf.map.api.MapPOIItem
import net.daum.mf.map.api.MapPoint
import net.daum.mf.map.api.MapView
Expand All @@ -38,6 +40,18 @@ class MainActivity : AppCompatActivity() {
findViewById(R.id.map_view)
}

private val tabs : TabLayout by lazy{
findViewById(R.id.tabs)
}

private val container : FrameLayout by lazy{
findViewById(R.id.container)
}

private val searchToiletFragment = SearchToiletFragment()

private val resultFragment = ResultFragment()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand All @@ -47,6 +61,8 @@ class MainActivity : AppCompatActivity() {

val myHome = makeMarker(37.6106656, 127.0064049, 0, "my Home")
mapView.addPOIItem(myHome)

initSlidingDrawer()
}

/**
Expand Down Expand Up @@ -142,6 +158,29 @@ class MainActivity : AppCompatActivity() {
}
}

private fun initSlidingDrawer(){
tabs.addTab(tabs.newTab().setText("화장실 위치 검색"))
tabs.addTab(tabs.newTab().setText("검색 결과"))

supportFragmentManager.beginTransaction().add(R.id.container, searchToiletFragment).commit()

tabs.setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
val position = tab.position
var selected = if (position == 0) searchToiletFragment
else resultFragment
supportFragmentManager.beginTransaction().replace(R.id.container, selected).commit()
}

override fun onTabUnselected(tab: TabLayout.Tab) {

}
override fun onTabReselected(tab: TabLayout.Tab) {

}
})
}

companion object{
var MY_PERMISSION_STORAGE = 1000
}
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/example/publictoilet/ResultFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.publictoilet

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment

class ResultFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.result_tab, container, false)

//TODO Recycler View adapter

return view
}
}
19 changes: 7 additions & 12 deletions app/src/main/java/com/example/publictoilet/SearchToiletFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,17 @@ class SearchToiletFragment : Fragment() {

spinner.adapter = adapter

/*
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
when(position){
0 ->
}
}
override fun onNothingSelected(p0: AdapterView<*>?) {
TODO("Not yet implemented")
searchButton.setOnClickListener {
val range = when(spinner.selectedItem.toString()){
"300m" -> 300
"500m" -> 500
"1km" -> 1000
else -> 3000
}

//TODO 화장실 검색 API 호출
}

*/

return view
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_search_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
</vector>
24 changes: 13 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,40 @@
android:layout_height="match_parent"
android:allowSingleTap="true"
android:animateOnClick="true"
android:bottomOffset="5dp"
android:bottomOffset="-10dp"
android:content="@id/search_drawer_content"
android:handle="@id/search_drawer_handle"
android:orientation="vertical"
android:topOffset="60dp">

<ImageView
android:id="@+id/search_drawer_handle"
android:src=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_baseline_search_24"/>

<RelativeLayout
android:id="@+id/search_drawer_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="300dp"
android:orientation="vertical">

<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:elevation="3dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:elevation="3dp"
app:tabGravity="fill"
app:tabTextColor="@color/black"
app:tabSelectedTextColor="@color/teal_200"/>
app:tabSelectedTextColor="@color/teal_200"
app:tabTextColor="@color/black"/>

<FrameLayout
android:id="@+id/container"
android:layout_below="@id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:layout_below="@id/tabs"
android:background="@color/black"/>

</RelativeLayout>

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/result_tab.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/search_toilet_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="100dp"
android:layout_marginEnd="100dp"
android:layout_marginTop="30dp"/>
android:layout_marginTop="300dp"/>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/search_button"
Expand Down

0 comments on commit ee3cdca

Please sign in to comment.