Skip to content

Commit

Permalink
Integrate language selection a bit further.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrant committed Jan 30, 2025
1 parent 77d170e commit f814249
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,18 @@ class DescriptionEditViewModel(savedStateHandle: SavedStateHandle) : ViewModel()
_loadPageSummaryState.value = Resource.Loading()
editingAllowed = false
val summaryResponse = async { ServiceFactory.getRest(pageTitle.wikiSite).getPageSummary(pageTitle.prefixedText) }
val infoResponse = async { ServiceFactory.get(pageTitle.wikiSite).getWikiTextForSectionWithInfo(pageTitle.prefixedText, 0) }
val infoResponseCall = async { ServiceFactory.get(pageTitle.wikiSite).getWikiTextForSectionWithInfo(pageTitle.prefixedText, 0) }
val page = infoResponseCall.await().query?.firstPage()

val editError = infoResponse.await().query?.firstPage()?.getErrorForAction("edit")
page?.revisions?.firstOrNull()?.let { revision ->
revision.contentMain?.let {
if (it.contains(DescriptionEditViewModel.TEMPLATE_PARSE_REGEX.toRegex())) {
editingAllowed = true
}
}
}

val editError = page?.getErrorForAction("edit")
var error: MwServiceError? = null
if (editError.isNullOrEmpty()) {
editingAllowed = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WikiGamesCardView(context: Context) : DefaultFeedCardView<WikiGamesCard>(c
init {
binding.viewWikiGamesCardContentContainer.setCardBackgroundColor(ResourceUtil.getThemedColor(context, R.attr.progressive_color))
binding.viewWikiGamesCardContentContainer.setOnClickListener {
context.startActivity(OnThisDayGameActivity.newIntent(context, Constants.InvokeSource.FEED))
context.startActivity(OnThisDayGameActivity.newIntent(context, Constants.InvokeSource.FEED, card!!.wikiSite))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.wikipedia.Constants
import org.wikipedia.R
import org.wikipedia.activity.BaseActivity
import org.wikipedia.databinding.ActivityOnThisDayGameBinding
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.feed.onthisday.OnThisDay
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.Resource
Expand Down Expand Up @@ -399,8 +400,9 @@ class OnThisDayGameActivity : BaseActivity() {
}

companion object {
fun newIntent(context: Context, invokeSource: Constants.InvokeSource, date: LocalDate? = null): Intent {
fun newIntent(context: Context, invokeSource: Constants.InvokeSource, wikiSite: WikiSite, date: LocalDate? = null): Intent {
val intent = Intent(context, OnThisDayGameActivity::class.java)
.putExtra(Constants.ARG_WIKISITE, wikiSite)
.putExtra(Constants.INTENT_EXTRA_INVOKE_SOURCE, invokeSource)
if (date != null) {
intent.putExtra(OnThisDayGameViewModel.EXTRA_DATE, date.atStartOfDay().toInstant(ZoneOffset.UTC).epochSecond)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class OnThisDayGameFinalFragment : Fragment(), WeeklyActivityView.Callback {
override fun onDayClick(date: LocalDate) {
viewModel.resetCurrentDayState()
requireActivity().finish()
startActivity(OnThisDayGameActivity.newIntent(requireContext(), viewModel.invokeSource, date))
startActivity(OnThisDayGameActivity.newIntent(requireContext(), viewModel.invokeSource, viewModel.wikiSite, date))
}

private fun updateOnLoading() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.wikipedia.Constants
import org.wikipedia.Constants.InvokeSource
import org.wikipedia.R
import org.wikipedia.WikipediaApp
import org.wikipedia.databinding.FragmentOnThisDayGameOnboardingBinding
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.feed.FeedContentType
import org.wikipedia.settings.Prefs
import org.wikipedia.util.DateUtil
import org.wikipedia.util.FeedbackUtil
Expand Down Expand Up @@ -51,16 +54,16 @@ class OnThisDayGameOnboardingFragment : Fragment() {
}
}

fun maybeShowOnThisDayGameDialog(activity: Activity) {
if (!Prefs.otdEntryDialogShown) {
fun maybeShowOnThisDayGameDialog(activity: Activity, wikiSite: WikiSite = WikipediaApp.instance.wikiSite) {
if (!Prefs.otdEntryDialogShown && FeedContentType.WIKI_GAMES.langCodesSupported.contains(wikiSite.languageCode)) {
Prefs.otdEntryDialogShown = true
val dialogView = activity.layoutInflater.inflate(R.layout.dialog_on_this_day_game, null)
val dialog = MaterialAlertDialogBuilder(activity)
.setView(dialogView)
.setCancelable(false)
.show()
dialogView.findViewById<Button>(R.id.playGameButton).setOnClickListener {
activity.startActivity(OnThisDayGameActivity.newIntent(activity, InvokeSource.PAGE_ACTIVITY))
activity.startActivity(OnThisDayGameActivity.newIntent(activity, InvokeSource.PAGE_ACTIVITY, wikiSite))
dialog.dismiss()
}
dialogView.findViewById<ImageView>(R.id.closeButton).setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import org.wikipedia.Constants
import org.wikipedia.WikipediaApp
import org.wikipedia.database.AppDatabase
import org.wikipedia.dataclient.ServiceFactory
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.dataclient.page.PageSummary
import org.wikipedia.feed.onthisday.OnThisDay
import org.wikipedia.json.JsonUtil
Expand All @@ -33,6 +33,7 @@ class OnThisDayGameViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
val gameState: LiveData<Resource<GameState>> get() = _gameState

val invokeSource = savedStateHandle.get<Constants.InvokeSource>(Constants.INTENT_EXTRA_INVOKE_SOURCE)!!
val wikiSite = savedStateHandle.get<WikiSite>(Constants.ARG_WIKISITE)!!

private lateinit var currentState: GameState
private val overrideDate = savedStateHandle.contains(EXTRA_DATE)
Expand All @@ -56,7 +57,7 @@ class OnThisDayGameViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
}) {
_gameState.postValue(Resource.Loading())

val eventsFromApi = ServiceFactory.getRest(WikipediaApp.instance.wikiSite).getOnThisDay(currentMonth, currentDay).events
val eventsFromApi = ServiceFactory.getRest(wikiSite).getOnThisDay(currentMonth, currentDay).events

// Here is the logic for arranging the events:
// First we filter out any events that actually mention a year in the text, since those might give away the answer.
Expand Down Expand Up @@ -103,7 +104,7 @@ class OnThisDayGameViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {

savedPages.clear()
getArticlesMentioned().forEach { pageSummary ->
val inAnyList = AppDatabase.instance.readingListPageDao().findPageInAnyList(pageSummary.getPageTitle(WikipediaApp.instance.wikiSite)) != null
val inAnyList = AppDatabase.instance.readingListPageDao().findPageInAnyList(pageSummary.getPageTitle(wikiSite)) != null
if (inAnyList) {
savedPages.add(pageSummary)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/wikipedia/page/PageFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ class PageFragment : Fragment(), BackPressedHandler, CommunicationBridge.Communi
webView.visibility = View.VISIBLE
}
maybeShowAnnouncement()
OnThisDayGameOnboardingFragment.maybeShowOnThisDayGameDialog(requireActivity())
OnThisDayGameOnboardingFragment.maybeShowOnThisDayGameDialog(requireActivity(), model.title?.wikiSite ?: WikipediaApp.instance.wikiSite)

bridge.onMetadataReady()
// Explicitly set the top margin (even though it might have already been set in the setup
Expand Down

0 comments on commit f814249

Please sign in to comment.