@@ -24,26 +24,18 @@ import org.fossasia.openevent.general.R
2424import org.koin.androidx.viewmodel.ext.android.viewModel
2525
2626const val LOCATION_PERMISSION_REQUEST = 1000
27+ const val AUTOCOMPLETE_FRAG_TAG = " AutoComplete_Frag"
2728
2829class SearchLocationFragment : Fragment () {
2930 private lateinit var rootView: View
3031 private val searchLocationViewModel by viewModel<SearchLocationViewModel >()
3132 private val geoLocationViewModel by viewModel<GeoLocationViewModel >()
3233 private val safeArgs: SearchLocationFragmentArgs by navArgs()
3334
34- private val AUTOCOMPLETE_FRAG_TAG = " AutoComplete_Frag"
35-
36- override fun onCreateView (
37- inflater : LayoutInflater ,
38- container : ViewGroup ? ,
39- savedInstanceState : Bundle ?
40- ): View ? {
35+ override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View ? {
4136 rootView = inflater.inflate(R .layout.fragment_search_location, container, false )
4237
43- val thisActivity = activity
44- if (thisActivity is AppCompatActivity ) {
45- thisActivity.supportActionBar?.hide()
46- }
38+ setActionBarVisibility(false )
4739 setHasOptionsMenu(true )
4840
4941 geoLocationViewModel.currentLocationVisibility.observe(this , Observer {
@@ -68,8 +60,7 @@ class SearchLocationFragment : Fragment() {
6860
6961 private fun checkLocationPermission () {
7062 val permission =
71- ContextCompat .checkSelfPermission(requireContext(),
72- Manifest .permission.ACCESS_COARSE_LOCATION )
63+ ContextCompat .checkSelfPermission(requireContext(), Manifest .permission.ACCESS_COARSE_LOCATION )
7364 if (permission != PackageManager .PERMISSION_GRANTED ) {
7465 requestPermissions(arrayOf(Manifest .permission.ACCESS_COARSE_LOCATION ,
7566 Manifest .permission.ACCESS_FINE_LOCATION ), LOCATION_PERMISSION_REQUEST )
@@ -81,6 +72,16 @@ class SearchLocationFragment : Fragment() {
8172 Navigation .findNavController(rootView).popBackStack(fragmentId, false )
8273 }
8374
75+ private fun setActionBarVisibility (status : Boolean ) {
76+ val thisActivity = activity
77+ if (thisActivity is AppCompatActivity ) {
78+ if (! status)
79+ thisActivity.supportActionBar?.hide()
80+ else
81+ thisActivity.supportActionBar?.show()
82+ }
83+ }
84+
8485 private fun setupPlaceAutoCompleteFrag (savedInstanceState : Bundle ? ) {
8586
8687 val autocompleteFragment: PlaceAutocompleteFragment ?
@@ -112,11 +113,7 @@ class SearchLocationFragment : Fragment() {
112113 })
113114 }
114115
115- override fun onRequestPermissionsResult (
116- requestCode : Int ,
117- permissions : Array <String >,
118- grantResults : IntArray
119- ) {
116+ override fun onRequestPermissionsResult (requestCode : Int , permissions : Array <String >, grantResults : IntArray ) {
120117 when (requestCode) {
121118 LOCATION_PERMISSION_REQUEST -> {
122119 if (grantResults.isNotEmpty() && grantResults[0 ] == PackageManager .PERMISSION_GRANTED ) {
@@ -128,4 +125,9 @@ class SearchLocationFragment : Fragment() {
128125 }
129126 }
130127 }
128+
129+ override fun onDestroyView () {
130+ super .onDestroyView()
131+ setActionBarVisibility(true )
132+ }
131133}
0 commit comments