@@ -4,27 +4,25 @@ import android.Manifest
4
4
import android.content.pm.PackageManager
5
5
import android.os.Bundle
6
6
import android.view.LayoutInflater
7
+ import android.view.MenuItem
7
8
import android.view.View
8
9
import android.view.ViewGroup
9
10
import androidx.appcompat.app.AppCompatActivity
11
+ import androidx.appcompat.widget.SearchView
10
12
import androidx.core.content.ContextCompat
11
13
import androidx.fragment.app.Fragment
12
14
import androidx.lifecycle.Observer
13
15
import androidx.navigation.Navigation
14
16
import androidx.navigation.fragment.navArgs
15
17
import com.google.android.material.snackbar.Snackbar
16
- import com.mapbox.api.geocoding.v5.models.CarmenFeature
17
- import com.mapbox.mapboxsdk.plugins.places.autocomplete.model.PlaceOptions
18
- import com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.PlaceAutocompleteFragment
19
- import com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.PlaceSelectionListener
20
18
import kotlinx.android.synthetic.main.fragment_search_location.view.currentLocationLinearLayout
21
19
import kotlinx.android.synthetic.main.fragment_search_location.view.locationProgressBar
22
- import org.fossasia.openevent.general.BuildConfig
20
+ import kotlinx.android.synthetic.main.fragment_search_location.view.locationSearchView
23
21
import org.fossasia.openevent.general.R
22
+ import org.fossasia.openevent.general.utils.Utils
24
23
import org.koin.androidx.viewmodel.ext.android.viewModel
25
24
26
25
const val LOCATION_PERMISSION_REQUEST = 1000
27
- const val AUTOCOMPLETE_FRAG_TAG = " AutoComplete_Frag"
28
26
29
27
class SearchLocationFragment : Fragment () {
30
28
private lateinit var rootView: View
@@ -37,7 +35,8 @@ class SearchLocationFragment : Fragment() {
37
35
38
36
val thisActivity = activity
39
37
if (thisActivity is AppCompatActivity ) {
40
- thisActivity.supportActionBar?.hide()
38
+ thisActivity.supportActionBar?.show()
39
+ thisActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true )
41
40
}
42
41
setHasOptionsMenu(true )
43
42
@@ -56,11 +55,37 @@ class SearchLocationFragment : Fragment() {
56
55
redirectToMain()
57
56
})
58
57
59
- setupPlaceAutoCompleteFrag(savedInstanceState)
58
+ rootView.locationSearchView.setOnQueryTextListener(object : SearchView .OnQueryTextListener {
59
+ override fun onQueryTextSubmit (query : String ): Boolean {
60
+ searchLocationViewModel.saveSearch(query)
61
+ redirectToMain()
62
+ return false
63
+ }
64
+
65
+ override fun onQueryTextChange (newText : String ): Boolean {
66
+ return false
67
+ }
68
+ })
60
69
61
70
return rootView
62
71
}
63
72
73
+ override fun onResume () {
74
+ super .onResume()
75
+ Utils .showSoftKeyboard(context, rootView.locationSearchView)
76
+ }
77
+
78
+ override fun onOptionsItemSelected (item : MenuItem ): Boolean {
79
+ return when (item.itemId) {
80
+ android.R .id.home -> {
81
+ Utils .hideSoftKeyboard(context, rootView)
82
+ activity?.onBackPressed()
83
+ true
84
+ }
85
+ else -> super .onOptionsItemSelected(item)
86
+ }
87
+ }
88
+
64
89
private fun checkLocationPermission () {
65
90
val permission =
66
91
ContextCompat .checkSelfPermission(requireContext(), Manifest .permission.ACCESS_COARSE_LOCATION )
@@ -75,37 +100,6 @@ class SearchLocationFragment : Fragment() {
75
100
Navigation .findNavController(rootView).popBackStack(fragmentId, false )
76
101
}
77
102
78
- private fun setupPlaceAutoCompleteFrag (savedInstanceState : Bundle ? ) {
79
-
80
- val autocompleteFragment: PlaceAutocompleteFragment ?
81
- if (savedInstanceState == null ) {
82
- val placeOptions = PlaceOptions .builder().build(PlaceOptions .MODE_CARDS )
83
- autocompleteFragment = PlaceAutocompleteFragment .newInstance(
84
- BuildConfig .MAPBOX_KEY , placeOptions)
85
- val transaction = fragmentManager?.beginTransaction()
86
- transaction?.add(R .id.autocomplete_frag_container, autocompleteFragment,
87
- AUTOCOMPLETE_FRAG_TAG )
88
- transaction?.commit()
89
- } else {
90
- autocompleteFragment = fragmentManager?.findFragmentByTag(
91
- AUTOCOMPLETE_FRAG_TAG ) as ? PlaceAutocompleteFragment
92
- }
93
-
94
- autocompleteFragment?.setOnPlaceSelectedListener(object : PlaceSelectionListener {
95
- override fun onPlaceSelected (carmenFeature : CarmenFeature ) {
96
- val location = carmenFeature.placeName()?.split(" ," )?.first()
97
- location?.let {
98
- searchLocationViewModel.saveSearch(it)
99
- redirectToMain()
100
- }
101
- }
102
-
103
- override fun onCancel () {
104
- activity?.onBackPressed()
105
- }
106
- })
107
- }
108
-
109
103
override fun onRequestPermissionsResult (requestCode : Int , permissions : Array <String >, grantResults : IntArray ) {
110
104
when (requestCode) {
111
105
LOCATION_PERMISSION_REQUEST -> {
0 commit comments