Skip to content

Commit

Permalink
Update logic for Places survey. (#4456)
Browse files Browse the repository at this point in the history
* Update logic for Places survey.

* Cleanup.

---------

Co-authored-by: Sharvani Haran <[email protected]>
  • Loading branch information
dbrant and sharvaniharan authored Feb 7, 2024
1 parent e81ac6e commit a6d95d4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
12 changes: 0 additions & 12 deletions app/src/main/java/org/wikipedia/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import org.wikipedia.dataclient.WikiSite
import org.wikipedia.navtab.NavTab
import org.wikipedia.onboarding.InitialOnboardingActivity
import org.wikipedia.page.PageActivity
import org.wikipedia.places.PlacesFragment
import org.wikipedia.settings.Prefs
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.FeedbackUtil
import org.wikipedia.util.ResourceUtil
import org.wikipedia.views.SurveyDialog

class MainActivity : SingleFragmentActivity<MainFragment>(), MainFragment.Callback {

Expand Down Expand Up @@ -63,20 +61,10 @@ class MainActivity : SingleFragmentActivity<MainFragment>(), MainFragment.Callba
}

override fun onResume() {
maybeShowPlacesSurvey()
super.onResume()
invalidateOptionsMenu()
}

private fun maybeShowPlacesSurvey() {
binding.root.postDelayed({
if (!isDestroyed && Prefs.shouldShowOneTimePlacesSurvey == PlacesFragment.SURVEY_SHOW) {
Prefs.shouldShowOneTimePlacesSurvey = PlacesFragment.SURVEY_DO_NOT_SHOW
SurveyDialog.showFeedbackOptionsDialog(this, Constants.InvokeSource.PLACES)
}
}, 1000)
}

override fun createFragment(): MainFragment {
return MainFragment.newInstance()
}
Expand Down
17 changes: 12 additions & 5 deletions app/src/main/java/org/wikipedia/places/PlacesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import org.wikipedia.util.StringUtil
import org.wikipedia.util.TabUtil
import org.wikipedia.util.log.L
import org.wikipedia.views.DrawableItemDecoration
import org.wikipedia.views.SurveyDialog
import org.wikipedia.views.ViewUtil
import java.util.Locale
import kotlin.math.abs
Expand Down Expand Up @@ -393,6 +394,8 @@ class PlacesFragment : Fragment(), LinkPreviewDialog.LoadPageCallback, LinkPrevi
FeedbackUtil.showError(requireActivity(), it.throwable)
}
}

maybeShowSurvey()
}

private fun updateToggleViews(isMapVisible: Boolean) {
Expand Down Expand Up @@ -544,9 +547,6 @@ class PlacesFragment : Fragment(), LinkPreviewDialog.LoadPageCallback, LinkPrevi

clearAnnotationCache()
markerBitmapBase.recycle()
if (Prefs.shouldShowOneTimePlacesSurvey == SURVEY_NOT_INITIALIZED) {
Prefs.shouldShowOneTimePlacesSurvey = SURVEY_SHOW
}
super.onDestroyView()
}

Expand Down Expand Up @@ -752,6 +752,15 @@ class PlacesFragment : Fragment(), LinkPreviewDialog.LoadPageCallback, LinkPrevi
return false
}

private fun maybeShowSurvey() {
binding.root.postDelayed({
if (isAdded && Prefs.shouldShowOneTimePlacesSurvey == 1) {
Prefs.shouldShowOneTimePlacesSurvey++
SurveyDialog.showFeedbackOptionsDialog(requireActivity(), Constants.InvokeSource.PLACES)
}
}, 1000)
}

private inner class RecyclerViewAdapter(val nearbyPages: List<PlacesFragmentViewModel.NearbyPage>) : RecyclerView.Adapter<RecyclerViewItemHolder>() {
override fun getItemCount(): Int {
return nearbyPages.size
Expand Down Expand Up @@ -831,8 +840,6 @@ class PlacesFragment : Fragment(), LinkPreviewDialog.LoadPageCallback, LinkPrevi
const val CLUSTER_CIRCLE_LAYER_ID = "mapbox-android-cluster-circle0"
const val ZOOM_IN_ANIMATION_DURATION = 1000
const val SURVEY_NOT_INITIALIZED = -1
const val SURVEY_SHOW = 0
const val SURVEY_DO_NOT_SHOW = 1

val CLUSTER_FONT_STACK = arrayOf("Open Sans Semibold")
val MARKER_FONT_STACK = arrayOf("Open Sans Regular")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class PlacesFragmentViewModel(bundle: Bundle) : ViewModel() {
var lastKnownLocation: Location? = null
val nearbyPagesLiveData = MutableLiveData<Resource<List<NearbyPage>>>()

init {
Prefs.shouldShowOneTimePlacesSurvey++
}

fun fetchNearbyPages(latitude: Double, longitude: Double, radius: Int, maxResults: Int) {
viewModelScope.launch(CoroutineExceptionHandler { _, throwable ->
nearbyPagesLiveData.postValue(Resource.Error(throwable))
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/developer_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@
<org.wikipedia.settings.IntPreference
style="@style/IntPreference"
android:key="@string/preference_key_places_show_one_time_survey"
android:title="Survey status for places feature \n(-1=not initiated, 0=show the survey, 1=survey shown)" />
android:title="Survey status for places feature \n(-1=not initiated, 1=show survey, >1=do not show survey)" />

</PreferenceCategory>

Expand Down

0 comments on commit a6d95d4

Please sign in to comment.