Skip to content

Commit 90a1dad

Browse files
anhanh11001nikit19
authored andcommitted
fix: Show skip button when only needed
Details: - Change navigation from WelcomeFragment similar to eventbrite - Show skip button only when safeArgs attribute state so Fixes: #2063
1 parent 127d612 commit 90a1dad

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed

app/src/fdroid/java/org/fossasia/openevent/general/search/location/GeoLocationViewModel.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package org.fossasia.openevent.general.search.location
22

33
import androidx.lifecycle.LiveData
4-
import androidx.lifecycle.MutableLiveData
54
import androidx.lifecycle.ViewModel
65
import io.reactivex.disposables.CompositeDisposable
76
import io.reactivex.rxkotlin.plusAssign
87
import org.fossasia.openevent.general.common.SingleLiveEvent
98
import java.lang.IllegalArgumentException
109

1110
class GeoLocationViewModel(private val locationService: LocationService) : ViewModel() {
12-
private val mutableLocation = MutableLiveData<String>()
11+
private val mutableLocation = SingleLiveEvent<String>()
1312
val location: LiveData<String> = mutableLocation
1413
private val mutableErrorMessage = SingleLiveEvent<String>()
1514
val errorMessage: LiveData<String> = mutableErrorMessage

app/src/main/java/org/fossasia/openevent/general/auth/AuthFragment.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import org.fossasia.openevent.general.BuildConfig
2424
import org.fossasia.openevent.general.ComplexBackPressFragment
2525
import org.fossasia.openevent.general.PLAY_STORE_BUILD_FLAVOR
2626
import org.fossasia.openevent.general.R
27-
import org.fossasia.openevent.general.data.Preference
2827
import org.fossasia.openevent.general.event.EVENT_DETAIL_FRAGMENT
28+
import org.fossasia.openevent.general.search.location.SEARCH_LOCATION_FRAGMENT
2929
import org.fossasia.openevent.general.ticket.TICKETS_FRAGMENT
3030
import org.fossasia.openevent.general.utils.Utils.hideSoftKeyboard
3131
import org.fossasia.openevent.general.utils.Utils.show
@@ -39,14 +39,11 @@ import org.jetbrains.anko.design.snackbar
3939
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
4040
import org.koin.androidx.viewmodel.ext.android.viewModel
4141

42-
private const val FIRST_TIME_LOGIN = "firstTimeLogin"
43-
4442
class AuthFragment : Fragment(), ComplexBackPressFragment {
4543
private lateinit var rootView: View
4644
private val authViewModel by viewModel<AuthViewModel>()
4745
private val safeArgs: AuthFragmentArgs by navArgs()
4846
private val smartAuthViewModel by sharedViewModel<SmartAuthViewModel>()
49-
private val preference = Preference()
5047

5148
override fun onCreate(savedInstanceState: Bundle?) {
5249
super.onCreate(savedInstanceState)
@@ -70,9 +67,8 @@ class AuthFragment : Fragment(), ComplexBackPressFragment {
7067
val snackbarMessage = safeArgs.snackbarMessage
7168
if (!snackbarMessage.isNullOrEmpty()) rootView.snackbar(snackbarMessage)
7269

73-
rootView.skipTextView.isVisible = preference.getBoolean(FIRST_TIME_LOGIN, true)
70+
rootView.skipTextView.isVisible = safeArgs.showSkipButton
7471
rootView.skipTextView.setOnClickListener {
75-
preference.putBoolean(FIRST_TIME_LOGIN, false)
7672
findNavController(rootView).navigate(
7773
AuthFragmentDirections.actionAuthToEventsPop()
7874
)
@@ -159,6 +155,7 @@ class AuthFragment : Fragment(), ComplexBackPressFragment {
159155
TICKETS_FRAGMENT -> findNavController(rootView).popBackStack(R.id.ticketsFragment, false)
160156
EVENT_DETAIL_FRAGMENT -> findNavController(rootView).popBackStack(R.id.eventDetailsFragment, false)
161157
WELCOME_FRAGMENT -> findNavController(rootView).popBackStack(R.id.welcomeFragment, false)
158+
SEARCH_LOCATION_FRAGMENT -> findNavController(rootView).popBackStack(R.id.searchLocationFragment, false)
162159
PROFILE_FRAGMENT -> findNavController(rootView).popBackStack(R.id.profileFragment, false)
163160
else -> findNavController(rootView).navigate(AuthFragmentDirections.actionAuthToEventsPop())
164161
}

app/src/main/java/org/fossasia/openevent/general/search/location/SearchLocationFragment.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ import org.fossasia.openevent.general.R
3636
import org.fossasia.openevent.general.search.SEARCH_FILTER_FRAGMENT
3737
import org.fossasia.openevent.general.search.SEARCH_FRAGMENT
3838
import org.fossasia.openevent.general.utils.Utils
39+
import org.fossasia.openevent.general.utils.Utils.hideSoftKeyboard
3940
import org.fossasia.openevent.general.utils.Utils.isLocationEnabled
4041
import org.fossasia.openevent.general.utils.Utils.setToolbar
4142
import org.fossasia.openevent.general.utils.Utils.showSoftKeyboard
4243
import org.fossasia.openevent.general.utils.extensions.nonNull
44+
import org.fossasia.openevent.general.welcome.WELCOME_FRAGMENT
4345
import org.jetbrains.anko.design.snackbar
4446
import org.koin.androidx.viewmodel.ext.android.viewModel
4547

4648
const val LOCATION_PERMISSION_REQUEST = 1000
49+
const val SEARCH_LOCATION_FRAGMENT = "searchLocationFragment"
4750

4851
class SearchLocationFragment : Fragment() {
4952
private lateinit var rootView: View
@@ -71,7 +74,7 @@ class SearchLocationFragment : Fragment() {
7174
checkLocationPermission()
7275
if (isLocationEnabled(requireContext())) {
7376
geoLocationViewModel.configure()
74-
rootView.locationProgressBar.visibility = View.VISIBLE
77+
rootView.locationProgressBar.isVisible = true
7578
}
7679
}
7780

@@ -83,7 +86,7 @@ class SearchLocationFragment : Fragment() {
8386
.nonNull()
8487
.observe(viewLifecycleOwner, Observer {
8588
rootView.snackbar(it)
86-
rootView.locationProgressBar.visibility = View.GONE
89+
rootView.locationProgressBar.isVisible = false
8790
})
8891

8992
searchLocationViewModel.placeSuggestions.observe(viewLifecycleOwner, Observer {
@@ -145,6 +148,8 @@ class SearchLocationFragment : Fragment() {
145148
val fragmentId = when (safeArgs.fromFragmentName) {
146149
SEARCH_FRAGMENT -> SearchLocationFragmentDirections.actionSearchLocationToSearch()
147150
SEARCH_FILTER_FRAGMENT -> SearchLocationFragmentDirections.actionSearchLocationToSearchFilter()
151+
WELCOME_FRAGMENT -> SearchLocationFragmentDirections
152+
.actionSearchLocationToAuth(redirectedFrom = SEARCH_LOCATION_FRAGMENT, showSkipButton = true)
148153
else -> SearchLocationFragmentDirections.actionSearchLocationToEvents()
149154
}
150155
Navigation.findNavController(rootView).navigate(fragmentId)
@@ -180,6 +185,7 @@ class SearchLocationFragment : Fragment() {
180185

181186
private fun savePlaceAndRedirectToMain(place: String) {
182187
searchLocationViewModel.saveSearch(place)
188+
hideSoftKeyboard(context, rootView)
183189
redirectToMain()
184190
}
185191

app/src/main/java/org/fossasia/openevent/general/welcome/WelcomeFragment.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.view.View
88
import android.view.ViewGroup
99
import androidx.appcompat.app.AppCompatActivity
1010
import androidx.core.content.ContextCompat
11+
import androidx.core.view.isVisible
1112
import androidx.fragment.app.Fragment
1213
import androidx.lifecycle.Observer
1314
import androidx.navigation.Navigation
@@ -45,7 +46,7 @@ class WelcomeFragment : Fragment() {
4546
checkLocationPermission()
4647
if (isLocationEnabled(requireContext())) {
4748
geoLocationViewModel.configure()
48-
rootView.locationProgressBar.visibility = View.VISIBLE
49+
rootView.locationProgressBar.isVisible = true
4950
}
5051
}
5152

@@ -59,7 +60,7 @@ class WelcomeFragment : Fragment() {
5960
})
6061

6162
geoLocationViewModel.errorMessage.observe(this, Observer { message ->
62-
rootView.locationProgressBar.visibility = View.GONE
63+
rootView.locationProgressBar.isVisible = false
6364
Snackbar.make(rootView, message, Snackbar.LENGTH_SHORT).show()
6465
})
6566

@@ -73,7 +74,7 @@ class WelcomeFragment : Fragment() {
7374
geoLocationViewModel.configure()
7475
} else {
7576
Snackbar.make(rootView, "Cannot fetch location!", Snackbar.LENGTH_SHORT).show()
76-
rootView.locationProgressBar.visibility = View.GONE
77+
rootView.locationProgressBar.isVisible = false
7778
}
7879
}
7980
}
@@ -89,10 +90,8 @@ class WelcomeFragment : Fragment() {
8990
}
9091

9192
private fun redirectToAuth() {
92-
Navigation.findNavController(rootView).navigate(
93-
WelcomeFragmentDirections.actionWelcomeToAuth(
94-
redirectedFrom = WELCOME_FRAGMENT
95-
)
93+
Navigation.findNavController(rootView).navigate(WelcomeFragmentDirections.actionWelcomeToAuth(
94+
redirectedFrom = WELCOME_FRAGMENT, showSkipButton = true)
9695
)
9796
}
9897
}

app/src/main/res/layout/fragment_auth.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
android:layout_height="wrap_content"
8383
android:layout_gravity="center_horizontal"
8484
android:layout_marginTop="@dimen/layout_margin_medium"
85+
android:textStyle="bold"
86+
android:background="?selectableItemBackground"
87+
android:padding="@dimen/padding_large"
8588
android:textColor="@android:color/holo_blue_light"
8689
android:text="@string/skip_for_now"
8790
android:textSize="@dimen/text_size_medium"/>

app/src/main/res/navigation/navigation_graph.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@
101101
android:label="SearchLocationFragment"
102102
tools:layout="@layout/fragment_search_location">
103103

104+
<action android:id="@+id/action_search_location_to_auth"
105+
app:destination="@id/authFragment"
106+
app:popEnterAnim="@anim/fade_in"
107+
app:popExitAnim="@anim/fade_out"
108+
app:enterAnim="@anim/fade_in"
109+
app:exitAnim="@anim/fade_out"/>
110+
104111
<action android:id="@+id/action_search_location_to_search_filter"
105112
app:destination="@id/searchFilterFragment"
106113
app:popUpToInclusive="false"
@@ -976,5 +983,9 @@
976983
android:name="email"
977984
app:argType="string"
978985
android:defaultValue=""/>
986+
<argument
987+
android:name="showSkipButton"
988+
app:argType="boolean"
989+
android:defaultValue="false"/>
979990
</fragment>
980991
</navigation>

0 commit comments

Comments
 (0)