Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show skip button when only needed #2068

Merged
merged 1 commit into from Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,15 +1,14 @@
package org.fossasia.openevent.general.search.location

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
import org.fossasia.openevent.general.common.SingleLiveEvent
import java.lang.IllegalArgumentException

class GeoLocationViewModel(private val locationService: LocationService) : ViewModel() {
private val mutableLocation = MutableLiveData<String>()
private val mutableLocation = SingleLiveEvent<String>()
val location: LiveData<String> = mutableLocation
private val mutableErrorMessage = SingleLiveEvent<String>()
val errorMessage: LiveData<String> = mutableErrorMessage
Expand Down
Expand Up @@ -24,8 +24,8 @@ import org.fossasia.openevent.general.BuildConfig
import org.fossasia.openevent.general.ComplexBackPressFragment
import org.fossasia.openevent.general.PLAY_STORE_BUILD_FLAVOR
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.data.Preference
import org.fossasia.openevent.general.event.EVENT_DETAIL_FRAGMENT
import org.fossasia.openevent.general.search.location.SEARCH_LOCATION_FRAGMENT
import org.fossasia.openevent.general.ticket.TICKETS_FRAGMENT
import org.fossasia.openevent.general.utils.Utils.hideSoftKeyboard
import org.fossasia.openevent.general.utils.Utils.show
Expand All @@ -39,14 +39,11 @@ import org.jetbrains.anko.design.snackbar
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel

private const val FIRST_TIME_LOGIN = "firstTimeLogin"

class AuthFragment : Fragment(), ComplexBackPressFragment {
private lateinit var rootView: View
private val authViewModel by viewModel<AuthViewModel>()
private val safeArgs: AuthFragmentArgs by navArgs()
private val smartAuthViewModel by sharedViewModel<SmartAuthViewModel>()
private val preference = Preference()

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

rootView.skipTextView.isVisible = preference.getBoolean(FIRST_TIME_LOGIN, true)
rootView.skipTextView.isVisible = safeArgs.showSkipButton
rootView.skipTextView.setOnClickListener {
preference.putBoolean(FIRST_TIME_LOGIN, false)
findNavController(rootView).navigate(
AuthFragmentDirections.actionAuthToEventsPop()
)
Expand Down Expand Up @@ -159,6 +155,7 @@ class AuthFragment : Fragment(), ComplexBackPressFragment {
TICKETS_FRAGMENT -> findNavController(rootView).popBackStack(R.id.ticketsFragment, false)
EVENT_DETAIL_FRAGMENT -> findNavController(rootView).popBackStack(R.id.eventDetailsFragment, false)
WELCOME_FRAGMENT -> findNavController(rootView).popBackStack(R.id.welcomeFragment, false)
SEARCH_LOCATION_FRAGMENT -> findNavController(rootView).popBackStack(R.id.searchLocationFragment, false)
PROFILE_FRAGMENT -> findNavController(rootView).popBackStack(R.id.profileFragment, false)
else -> findNavController(rootView).navigate(AuthFragmentDirections.actionAuthToEventsPop())
}
Expand Down
Expand Up @@ -36,14 +36,17 @@ import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.search.SEARCH_FILTER_FRAGMENT
import org.fossasia.openevent.general.search.SEARCH_FRAGMENT
import org.fossasia.openevent.general.utils.Utils
import org.fossasia.openevent.general.utils.Utils.hideSoftKeyboard
import org.fossasia.openevent.general.utils.Utils.isLocationEnabled
import org.fossasia.openevent.general.utils.Utils.setToolbar
import org.fossasia.openevent.general.utils.Utils.showSoftKeyboard
import org.fossasia.openevent.general.utils.extensions.nonNull
import org.fossasia.openevent.general.welcome.WELCOME_FRAGMENT
import org.jetbrains.anko.design.snackbar
import org.koin.androidx.viewmodel.ext.android.viewModel

const val LOCATION_PERMISSION_REQUEST = 1000
const val SEARCH_LOCATION_FRAGMENT = "searchLocationFragment"

class SearchLocationFragment : Fragment() {
private lateinit var rootView: View
Expand Down Expand Up @@ -71,7 +74,7 @@ class SearchLocationFragment : Fragment() {
checkLocationPermission()
if (isLocationEnabled(requireContext())) {
geoLocationViewModel.configure()
rootView.locationProgressBar.visibility = View.VISIBLE
rootView.locationProgressBar.isVisible = true
}
}

Expand All @@ -83,7 +86,7 @@ class SearchLocationFragment : Fragment() {
.nonNull()
.observe(viewLifecycleOwner, Observer {
rootView.snackbar(it)
rootView.locationProgressBar.visibility = View.GONE
rootView.locationProgressBar.isVisible = false
})

searchLocationViewModel.placeSuggestions.observe(viewLifecycleOwner, Observer {
Expand Down Expand Up @@ -145,6 +148,8 @@ class SearchLocationFragment : Fragment() {
val fragmentId = when (safeArgs.fromFragmentName) {
SEARCH_FRAGMENT -> SearchLocationFragmentDirections.actionSearchLocationToSearch()
SEARCH_FILTER_FRAGMENT -> SearchLocationFragmentDirections.actionSearchLocationToSearchFilter()
WELCOME_FRAGMENT -> SearchLocationFragmentDirections
.actionSearchLocationToAuth(redirectedFrom = SEARCH_LOCATION_FRAGMENT, showSkipButton = true)
else -> SearchLocationFragmentDirections.actionSearchLocationToEvents()
}
Navigation.findNavController(rootView).navigate(fragmentId)
Expand Down Expand Up @@ -180,6 +185,7 @@ class SearchLocationFragment : Fragment() {

private fun savePlaceAndRedirectToMain(place: String) {
searchLocationViewModel.saveSearch(place)
hideSoftKeyboard(context, rootView)
redirectToMain()
}

Expand Down
Expand Up @@ -8,6 +8,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.navigation.Navigation
Expand Down Expand Up @@ -45,7 +46,7 @@ class WelcomeFragment : Fragment() {
checkLocationPermission()
if (isLocationEnabled(requireContext())) {
geoLocationViewModel.configure()
rootView.locationProgressBar.visibility = View.VISIBLE
rootView.locationProgressBar.isVisible = true
}
}

Expand All @@ -59,7 +60,7 @@ class WelcomeFragment : Fragment() {
})

geoLocationViewModel.errorMessage.observe(this, Observer { message ->
rootView.locationProgressBar.visibility = View.GONE
rootView.locationProgressBar.isVisible = false
Snackbar.make(rootView, message, Snackbar.LENGTH_SHORT).show()
})

Expand All @@ -73,7 +74,7 @@ class WelcomeFragment : Fragment() {
geoLocationViewModel.configure()
} else {
Snackbar.make(rootView, "Cannot fetch location!", Snackbar.LENGTH_SHORT).show()
rootView.locationProgressBar.visibility = View.GONE
rootView.locationProgressBar.isVisible = false
}
}
}
Expand All @@ -89,10 +90,8 @@ class WelcomeFragment : Fragment() {
}

private fun redirectToAuth() {
Navigation.findNavController(rootView).navigate(
WelcomeFragmentDirections.actionWelcomeToAuth(
redirectedFrom = WELCOME_FRAGMENT
)
Navigation.findNavController(rootView).navigate(WelcomeFragmentDirections.actionWelcomeToAuth(
redirectedFrom = WELCOME_FRAGMENT, showSkipButton = true)
)
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/layout/fragment_auth.xml
Expand Up @@ -82,6 +82,9 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/layout_margin_medium"
android:textStyle="bold"
android:background="?selectableItemBackground"
android:padding="@dimen/padding_large"
android:textColor="@android:color/holo_blue_light"
android:text="@string/skip_for_now"
android:textSize="@dimen/text_size_medium"/>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/navigation/navigation_graph.xml
Expand Up @@ -101,6 +101,13 @@
android:label="SearchLocationFragment"
tools:layout="@layout/fragment_search_location">

<action android:id="@+id/action_search_location_to_auth"
app:destination="@id/authFragment"
app:popEnterAnim="@anim/fade_in"
app:popExitAnim="@anim/fade_out"
app:enterAnim="@anim/fade_in"
app:exitAnim="@anim/fade_out"/>

<action android:id="@+id/action_search_location_to_search_filter"
app:destination="@id/searchFilterFragment"
app:popUpToInclusive="false"
Expand Down Expand Up @@ -976,5 +983,9 @@
android:name="email"
app:argType="string"
android:defaultValue=""/>
<argument
android:name="showSkipButton"
app:argType="boolean"
android:defaultValue="false"/>
</fragment>
</navigation>