Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/gradle/androidx.recyclerview-recy…
Browse files Browse the repository at this point in the history
…clerview-1.4.0
  • Loading branch information
cooltey authored Jan 17, 2025
2 parents e4bbdfb + a24d953 commit 3f57182
Show file tree
Hide file tree
Showing 26 changed files with 166 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.app.Activity
import android.content.Context
import android.view.MenuItem
import android.view.View
import android.widget.Checkable
import android.widget.CompoundButton
import android.widget.TextView
import androidx.fragment.app.Fragment
import kotlinx.serialization.SerialName
Expand Down Expand Up @@ -37,11 +37,11 @@ class BreadCrumbLogEvent(
if (context is SettingsActivity) {
return
}
val viewReadableName = BreadCrumbViewUtil.getReadableNameForView(view)
val str = "$viewReadableName." + when (view) {
is Checkable -> if (!view.isChecked) "on" else "off"
else -> "click"
var viewReadableName = BreadCrumbViewUtil.getReadableNameForView(view)
if (view.tag is String && (view.tag as String).isNotEmpty()) {
viewReadableName += "." + view.tag as String
}
val str = "$viewReadableName." + if (view is CompoundButton) { if (!view.isChecked) "on" else "off" } else "click"
EventPlatformClient.submit(BreadCrumbLogEvent(BreadCrumbViewUtil.getReadableScreenName(context), str))
}

Expand All @@ -61,6 +61,11 @@ class BreadCrumbLogEvent(
"show" + invokeSource?.let { ".from." + it.value }.orEmpty()))
}

fun logImpression(context: Context, name: String) {
EventPlatformClient.submit(BreadCrumbLogEvent(BreadCrumbViewUtil.getReadableScreenName(context),
"impression.$name"))
}

fun logBackPress(context: Context) {
EventPlatformClient.submit(BreadCrumbLogEvent(BreadCrumbViewUtil.getReadableScreenName(context), "back"))
}
Expand Down
35 changes: 19 additions & 16 deletions app/src/main/java/org/wikipedia/dataclient/RestService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,25 @@ interface RestService {

@Headers("x-analytics: preview=1", "Accept: $ACCEPT_HEADER_SUMMARY")
@GET("page/summary/{title}")
suspend fun getSummaryResponse(
suspend fun getPageSummary(
@Path("title") title: String,
@Header("Referer") referrerUrl: String? = null,
@Header("Cache-Control") cacheControl: String? = null,
@Header(OfflineCacheInterceptor.SAVE_HEADER) saveHeader: String? = null,
@Header(OfflineCacheInterceptor.LANG_HEADER) langHeader: String? = null,
@Header(OfflineCacheInterceptor.TITLE_HEADER) titleHeader: String? = null
): Response<PageSummary>
): PageSummary

@Headers("x-analytics: preview=1", "Accept: $ACCEPT_HEADER_SUMMARY")
@GET("page/summary/{title}")
suspend fun getPageSummary(
@Header("Referer") referrerUrl: String?,
@Path("title") title: String
): PageSummary
suspend fun getSummaryResponse(
@Path("title") title: String,
@Header("Referer") referrerUrl: String? = null,
@Header("Cache-Control") cacheControl: String? = null,
@Header(OfflineCacheInterceptor.SAVE_HEADER) saveHeader: String? = null,
@Header(OfflineCacheInterceptor.LANG_HEADER) langHeader: String? = null,
@Header(OfflineCacheInterceptor.TITLE_HEADER) titleHeader: String? = null
): Response<PageSummary>

@Headers("Accept: $ACCEPT_HEADER_DEFINITION")
@GET("page/definition/{title}")
Expand All @@ -56,21 +60,20 @@ interface RestService {
@Headers("Accept: $ACCEPT_HEADER_SUMMARY")
suspend fun getRandomSummary(): PageSummary

@GET("page/media-list/{title}/{revision}")
@GET("page/media-list/{title}")
suspend fun getMediaList(
@Path("title") title: String,
@Path("revision") revision: Long
@Header("Cache-Control") cacheControl: String? = null,
@Header(OfflineCacheInterceptor.SAVE_HEADER) saveHeader: String? = null,
@Header(OfflineCacheInterceptor.LANG_HEADER) langHeader: String? = null,
@Header(OfflineCacheInterceptor.TITLE_HEADER) titleHeader: String? = null
): MediaList

@GET("page/media-list/{title}/{revision}")
suspend fun getMediaListResponse(
@Path("title") title: String?,
@Path("revision") revision: Long,
@Header("Cache-Control") cacheControl: String?,
@Header(OfflineCacheInterceptor.SAVE_HEADER) saveHeader: String?,
@Header(OfflineCacheInterceptor.LANG_HEADER) langHeader: String?,
@Header(OfflineCacheInterceptor.TITLE_HEADER) titleHeader: String?
): Response<MediaList>
suspend fun getMediaList(
@Path("title") title: String,
@Path("revision") revision: Long
): MediaList

@GET("feed/onthisday/events/{mm}/{dd}")
suspend fun getOnThisDay(@Path("mm") month: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DescriptionEditViewModel(savedStateHandle: SavedStateHandle) : ViewModel()
}) {
_loadPageSummaryState.value = Resource.Loading()
editingAllowed = false
val summaryResponse = async { ServiceFactory.getRest(pageTitle.wikiSite).getPageSummary(null, pageTitle.prefixedText) }
val summaryResponse = async { ServiceFactory.getRest(pageTitle.wikiSite).getPageSummary(pageTitle.prefixedText) }
val infoResponse = async { ServiceFactory.get(pageTitle.wikiSite).getWikiTextForSectionWithInfo(pageTitle.prefixedText, 0) }

val editError = infoResponse.await().query?.firstPage()?.getErrorForAction("edit")
Expand Down Expand Up @@ -145,8 +145,8 @@ class DescriptionEditViewModel(savedStateHandle: SavedStateHandle) : ViewModel()
var revision = -1L
while (revision < newRevision && retry < 10) {
delay(2000)
val pageSummaryResponse = ServiceFactory.getRest(pageTitle.wikiSite).getSummaryResponse(pageTitle.prefixedText, cacheControl = OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK.toString())
revision = pageSummaryResponse.body()?.revision ?: -1L
val pageSummary = ServiceFactory.getRest(pageTitle.wikiSite).getPageSummary(pageTitle.prefixedText, cacheControl = OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK.toString())
revision = pageSummary.revision
retry++
}
_waitForRevisionState.value = Resource.Success(true)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/wikipedia/edit/EditSectionViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class EditSectionViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
while (revision < newRevision && retry < 10) {
delay(2000)
val pageSummaryResponse = ServiceFactory.getRest(pageTitle.wikiSite)
.getSummaryResponse(pageTitle.prefixedText, cacheControl = OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK.toString())
revision = pageSummaryResponse.body()?.revision ?: -1L
.getPageSummary(pageTitle.prefixedText, cacheControl = OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK.toString())
revision = pageSummaryResponse.revision
retry++
}
_waitForRevisionState.value = Resource.Success(revision)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Announcement(val id: String = "",
// for iOS versions, so these need to be serialized manually.
@SerialName("min_version") private val minVersion: JsonElement? = null,
@SerialName("max_version") private val maxVersion: JsonElement? = null,
val imageAspectRatio: Double? = null,
val border: Boolean? = null,
val beta: Boolean? = null,
val placement: String = PLACEMENT_FEED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ open class AnnouncementCard(private val announcement: Announcement) : Card() {
fun hasBorder(): Boolean {
return announcement.border == true
}

fun getId(): String {
return announcement.id
}

fun aspectRatio(): Double {
return announcement.imageAspectRatio ?: 0.0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import android.content.Context
import android.net.Uri
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.content.ContextCompat
import androidx.core.text.method.LinkMovementMethodCompat
import androidx.core.view.updateLayoutParams
import org.wikipedia.R
import org.wikipedia.analytics.eventplatform.BreadCrumbLogEvent
import org.wikipedia.databinding.ViewCardAnnouncementBinding
import org.wikipedia.feed.model.Card
import org.wikipedia.feed.onboarding.YIROnboardingCard
import org.wikipedia.feed.view.DefaultFeedCardView
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.StringUtil
Expand Down Expand Up @@ -44,18 +47,32 @@ class AnnouncementCardView(context: Context) : DefaultFeedCardView<AnnouncementC
} else {
binding.viewAnnouncementCardButtonsContainer.visibility = VISIBLE
binding.viewAnnouncementActionPositive.text = it.actionTitle()
binding.viewAnnouncementActionPositive.tag = it.getId()
binding.viewAnnouncementDialogActionPositive.text = it.actionTitle()
binding.viewAnnouncementDialogActionPositive.tag = it.getId()
}
if (!it.negativeText().isNullOrEmpty()) {
binding.viewAnnouncementActionNegative.text = it.negativeText()
binding.viewAnnouncementActionNegative.tag = it.getId()
binding.viewAnnouncementDialogActionNegative.text = it.negativeText()
binding.viewAnnouncementDialogActionNegative.tag = it.getId()
} else {
binding.viewAnnouncementActionNegative.visibility = GONE
binding.viewAnnouncementDialogActionNegative.visibility = GONE
}
if (it.hasImage()) {
binding.viewAnnouncementHeaderImage.visibility = VISIBLE
binding.viewAnnouncementHeaderImage.loadImage(it.image())
if (it.aspectRatio() != 0.0) {
binding.viewAnnouncementHeaderImage.scaleType = ImageView.ScaleType.FIT_CENTER
binding.viewAnnouncementHeaderImage.post {
binding.viewAnnouncementHeaderImage.updateLayoutParams {
height = (binding.viewAnnouncementHeaderImage.width / it.aspectRatio()).toInt()
}
binding.viewAnnouncementHeaderImage.loadImage(it.image())
}
} else {
binding.viewAnnouncementHeaderImage.loadImage(it.image())
}
} else {
binding.viewAnnouncementHeaderImage.visibility = GONE
}
Expand Down Expand Up @@ -86,6 +103,10 @@ class AnnouncementCardView(context: Context) : DefaultFeedCardView<AnnouncementC
binding.viewAnnouncementContainer.radius = 0f
}
}

if (value is YIROnboardingCard) {
BreadCrumbLogEvent.logImpression(context, "YIR2024")
}
}

private fun onPositiveActionClick() {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/org/wikipedia/feed/model/CardType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ enum class CardType constructor(private val code: Int,
return PlacesCardView(ctx)
}
},
// TODO: refactor this item when the new Modern Event Platform is finished.
ARTICLE_ANNOUNCEMENT(96) {
YEAR_IN_REVIEW_ANNOUNCEMENT(96) {
override fun newView(ctx: Context): FeedCardView<*> {
// This is not actually used, since this type of card will not be shown in the feed.
return AnnouncementCardView(ctx)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OnboardingClient : FeedClient {

private fun getCards(context: Context): List<Card> {
val cards = ArrayList<Card>()
val card: OnboardingCard
var card: OnboardingCard

// NOTE: When adding new onboarding cards, please add them to the *beginning* of the list.

Expand All @@ -41,6 +41,20 @@ class OnboardingClient : FeedClient {
if (card.shouldShow() && Prefs.exploreFeedVisitCount <= SHOW_CUSTOMIZE_ONBOARDING_CARD_COUNT) {
cards.add(card)
}

card = YIROnboardingCard(
Announcement(id = "yir2024Card",
text = context.getString(R.string.year_in_review_text),
imageUrl = "https://upload.wikimedia.org/wikipedia/commons/2/21/WYiR_Block_1.gif",
action = Announcement.Action(context.getString(R.string.year_in_review_action_positive), "https://wikimediafoundation.org/wikipedia-year-in-review-2024/"),
negativeText = context.getString(R.string.view_announcement_card_negative_action),
imageAspectRatio = 4.0 / 3.0
)
)
if (card.shouldShow()) {
cards.add(card)
}

return cards
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.wikipedia.feed.onboarding

import org.wikipedia.R
import org.wikipedia.WikipediaApp
import org.wikipedia.feed.announcement.Announcement
import org.wikipedia.feed.model.CardType
import org.wikipedia.util.GeoUtil
import java.time.LocalDate

class YIROnboardingCard(announcement: Announcement) : OnboardingCard(announcement) {

override fun type(): CardType {
return CardType.YEAR_IN_REVIEW_ANNOUNCEMENT
}

override fun shouldShow(): Boolean {
return super.shouldShow() &&
WikipediaApp.instance.appOrSystemLanguageCode == "en" &&
LocalDate.now() <= LocalDate.of(2025, 2, 28) &&
!excludedCountries.contains(GeoUtil.geoIPCountry)
}

override fun prefKey(): Int {
return R.string.preference_key_feed_yir_onboarding_card_enabled
}

private val excludedCountries = setOf("RU", "IR", "CN", "HK", "MO", "SA", "CU", "MM", "BY", "EG", "PS", "GN", "PK", "KH", "VN", "SD", "AE", "SY", "JO", "VE", "AF")
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import org.wikipedia.descriptions.DescriptionEditActivity.Action.TRANSLATE_CAPTI
import org.wikipedia.descriptions.DescriptionEditActivity.Action.TRANSLATE_DESCRIPTION
import org.wikipedia.descriptions.DescriptionEditReviewView.Companion.ARTICLE_EXTRACT_MAX_LINE_WITHOUT_IMAGE
import org.wikipedia.descriptions.DescriptionEditReviewView.Companion.ARTICLE_EXTRACT_MAX_LINE_WITH_IMAGE
import org.wikipedia.gallery.GalleryActivity
import org.wikipedia.history.HistoryEntry
import org.wikipedia.page.PageActivity
import org.wikipedia.page.PageTitle
Expand Down Expand Up @@ -93,7 +92,7 @@ class SuggestedEditsCardItemFragment : Fragment() {
}
val pageTitle = viewModel.sourceSummaryForEdit!!.pageTitle
if (viewModel.cardActionType === ADD_CAPTION || viewModel.cardActionType === TRANSLATE_CAPTION) {
it.context.startActivity(GalleryActivity.newIntent(it.context, pageTitle, pageTitle.prefixedText, pageTitle.wikiSite, 0))
it.context.startActivity(FilePageActivity.newIntent(it.context, pageTitle))
} else {
it.context.startActivity(PageActivity.newIntentForNewTab(it.context, HistoryEntry(pageTitle, HistoryEntry.SOURCE_SUGGESTED_EDITS), pageTitle))
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/wikipedia/gallery/GalleryActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ class GalleryActivity : BaseActivity(), LinkPreviewDialog.LoadPageCallback, Gall
const val EXTRA_FILENAME = "filename"
const val EXTRA_REVISION = "revision"

fun newIntent(context: Context, pageTitle: PageTitle?, filename: String, wiki: WikiSite, revision: Long): Intent {
fun newIntent(context: Context, pageTitle: PageTitle?, filename: String, wiki: WikiSite, revision: Long? = null): Intent {
return Intent(context, GalleryActivity::class.java)
.putExtra(Constants.ARG_WIKISITE, wiki)
.putExtra(Constants.ARG_TITLE, pageTitle)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/wikipedia/gallery/GalleryViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.wikipedia.util.Resource
class GalleryViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
val pageTitle = savedStateHandle.get<PageTitle>(Constants.ARG_TITLE)
val wikiSite = savedStateHandle.get<WikiSite>(Constants.ARG_WIKISITE)!!
val revision = savedStateHandle[GalleryActivity.EXTRA_REVISION] ?: 0L
val revision = savedStateHandle[GalleryActivity.EXTRA_REVISION] as Long?
var initialFilename = savedStateHandle.get<String>(GalleryActivity.EXTRA_FILENAME)

private val _uiState = MutableStateFlow(Resource<MediaList>())
Expand All @@ -34,7 +34,7 @@ class GalleryViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
_uiState.value = Resource.Error(throwable)
}) {
pageTitle?.let {
val response = ServiceFactory.getRest(it.wikiSite).getMediaList(it.prefixedText, revision)
val response = if (revision != null) ServiceFactory.getRest(it.wikiSite).getMediaList(it.prefixedText, revision) else ServiceFactory.getRest(it.wikiSite).getMediaList(it.prefixedText)
_uiState.value = Resource.Success(response)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/wikipedia/page/PageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class PageActivity : BaseActivity(), PageFragment.Callback, LinkPreviewDialog.Lo
startActivity(FilePageActivity.newIntent(this, imageTitle))
} else if (action === DescriptionEditActivity.Action.ADD_CAPTION || action === DescriptionEditActivity.Action.TRANSLATE_CAPTION) {
pageFragment.title?.let { pageTitle ->
startActivity(GalleryActivity.newIntent(this, pageTitle, imageTitle.prefixedText, wikiSite, 0))
startActivity(GalleryActivity.newIntent(this, pageTitle, imageTitle.prefixedText, wikiSite))
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/org/wikipedia/page/PageFragmentLoadState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ class PageFragmentLoadState(private var model: PageViewModel,
}

val pageSummaryRequest = async {
ServiceFactory.getRest(title.wikiSite).getSummaryResponse(title.prefixedText, null, model.cacheControl.toString(),
if (model.isInReadingList) OfflineCacheInterceptor.SAVE_HEADER_SAVE else null, title.wikiSite.languageCode, UriUtil.encodeURL(title.prefixedText))
ServiceFactory.getRest(title.wikiSite).getSummaryResponse(title.prefixedText, cacheControl = model.cacheControl.toString(),
saveHeader = if (model.isInReadingList) OfflineCacheInterceptor.SAVE_HEADER_SAVE else null,
langHeader = title.wikiSite.languageCode, titleHeader = UriUtil.encodeURL(title.prefixedText))
}
val watchedRequest = async {
if (WikipediaApp.instance.isOnline && AccountUtil.isLoggedIn) {
Expand All @@ -155,8 +156,8 @@ class PageFragmentLoadState(private var model: PageViewModel,

val pageSummaryResponse = pageSummaryRequest.await()
val watchedResponse = watchedRequest.await()
val isWatched = watchedResponse.query?.firstPage()?.watched ?: false
val hasWatchlistExpiry = watchedResponse.query?.firstPage()?.hasWatchlistExpiry() ?: false
val isWatched = watchedResponse.query?.firstPage()?.watched == true
val hasWatchlistExpiry = watchedResponse.query?.firstPage()?.hasWatchlistExpiry() == true
if (pageSummaryResponse.body() == null) {
throw RuntimeException("Summary response was invalid.")
}
Expand Down
Loading

0 comments on commit 3f57182

Please sign in to comment.