From 789041b0e254376fa7e260355bf3ff688e7313f4 Mon Sep 17 00:00:00 2001 From: Dmitry Brant Date: Fri, 17 Jan 2025 08:39:51 -0500 Subject: [PATCH 1/4] Fix a couple of issues when invoking Gallery from Suggested Edits. --- app/src/main/java/org/wikipedia/dataclient/RestService.kt | 2 +- .../feed/suggestededits/SuggestedEditsCardItemFragment.kt | 3 +-- app/src/main/java/org/wikipedia/gallery/GalleryActivity.kt | 2 +- .../main/java/org/wikipedia/gallery/GalleryViewModel.kt | 2 +- app/src/main/java/org/wikipedia/page/PageActivity.kt | 2 +- .../org/wikipedia/page/linkpreview/LinkPreviewDialog.kt | 7 ++----- .../org/wikipedia/page/linkpreview/LinkPreviewViewModel.kt | 4 ++-- 7 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/wikipedia/dataclient/RestService.kt b/app/src/main/java/org/wikipedia/dataclient/RestService.kt index c51e4bb6186..0a692a2c8a6 100644 --- a/app/src/main/java/org/wikipedia/dataclient/RestService.kt +++ b/app/src/main/java/org/wikipedia/dataclient/RestService.kt @@ -59,7 +59,7 @@ interface RestService { @GET("page/media-list/{title}/{revision}") suspend fun getMediaList( @Path("title") title: String, - @Path("revision") revision: Long + @Path("revision") revision: Long? = null ): MediaList @GET("page/media-list/{title}/{revision}") diff --git a/app/src/main/java/org/wikipedia/feed/suggestededits/SuggestedEditsCardItemFragment.kt b/app/src/main/java/org/wikipedia/feed/suggestededits/SuggestedEditsCardItemFragment.kt index 0fa2503290d..4ad015dff1f 100644 --- a/app/src/main/java/org/wikipedia/feed/suggestededits/SuggestedEditsCardItemFragment.kt +++ b/app/src/main/java/org/wikipedia/feed/suggestededits/SuggestedEditsCardItemFragment.kt @@ -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 @@ -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)) } diff --git a/app/src/main/java/org/wikipedia/gallery/GalleryActivity.kt b/app/src/main/java/org/wikipedia/gallery/GalleryActivity.kt index 772621589ff..7f3d763d5bd 100644 --- a/app/src/main/java/org/wikipedia/gallery/GalleryActivity.kt +++ b/app/src/main/java/org/wikipedia/gallery/GalleryActivity.kt @@ -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) diff --git a/app/src/main/java/org/wikipedia/gallery/GalleryViewModel.kt b/app/src/main/java/org/wikipedia/gallery/GalleryViewModel.kt index c6c0db77f64..b074ba778ea 100644 --- a/app/src/main/java/org/wikipedia/gallery/GalleryViewModel.kt +++ b/app/src/main/java/org/wikipedia/gallery/GalleryViewModel.kt @@ -19,7 +19,7 @@ import org.wikipedia.util.Resource class GalleryViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { val pageTitle = savedStateHandle.get(Constants.ARG_TITLE) val wikiSite = savedStateHandle.get(Constants.ARG_WIKISITE)!! - val revision = savedStateHandle[GalleryActivity.EXTRA_REVISION] ?: 0L + val revision = savedStateHandle[GalleryActivity.EXTRA_REVISION] as Long? var initialFilename = savedStateHandle.get(GalleryActivity.EXTRA_FILENAME) private val _uiState = MutableStateFlow(Resource()) diff --git a/app/src/main/java/org/wikipedia/page/PageActivity.kt b/app/src/main/java/org/wikipedia/page/PageActivity.kt index ba5001bcaf5..c242aed702c 100644 --- a/app/src/main/java/org/wikipedia/page/PageActivity.kt +++ b/app/src/main/java/org/wikipedia/page/PageActivity.kt @@ -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)) } } } diff --git a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.kt b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.kt index 51dc3245f26..c5ff63ab71e 100644 --- a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.kt +++ b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.kt @@ -78,7 +78,6 @@ class LinkPreviewDialog : ExtendedBottomSheetDialogFragment(), LinkPreviewErrorV private var linkPreviewInteraction: ArticleLinkPreviewInteraction? = null private var overlayView: LinkPreviewOverlayView? = null private var navigateSuccess = false - private var revision: Long = 0 private val viewModel: LinkPreviewViewModel by viewModels() private val menuListener = PopupMenu.OnMenuItemClickListener { item -> @@ -142,7 +141,7 @@ class LinkPreviewDialog : ExtendedBottomSheetDialogFragment(), LinkPreviewErrorV options = ActivityOptionsCompat.makeSceneTransitionAnimation(requireActivity(), view, requireActivity().getString(R.string.transition_page_gallery)) } requestGalleryLauncher.launch(GalleryActivity.newIntent(requireContext(), viewModel.pageTitle, - imageName, viewModel.pageTitle.wikiSite, revision), options) + imageName, viewModel.pageTitle.wikiSite), options) } private val requestGalleryLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { @@ -238,8 +237,6 @@ class LinkPreviewDialog : ExtendedBottomSheetDialogFragment(), LinkPreviewErrorV ) linkPreviewInteraction?.logLinkClick() - revision = summary.revision - binding.linkPreviewTitle.text = StringUtil.fromHtml(summary.displayTitle) if (viewModel.fromPlaces) { viewModel.location?.let { startLocation -> @@ -374,7 +371,7 @@ class LinkPreviewDialog : ExtendedBottomSheetDialogFragment(), LinkPreviewErrorV } private fun showPreview(contents: LinkPreviewContents) { - viewModel.loadGallery(revision) + viewModel.loadGallery() setPreviewContents(contents) } diff --git a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewViewModel.kt b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewViewModel.kt index 80070cf9b59..28fd591ee43 100644 --- a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewViewModel.kt +++ b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewViewModel.kt @@ -76,13 +76,13 @@ class LinkPreviewViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { } } - fun loadGallery(revision: Long) { + fun loadGallery() { if (Prefs.isImageDownloadEnabled && !pageTitle.isFilePage) { viewModelScope.launch(CoroutineExceptionHandler { _, throwable -> L.w("Failed to fetch gallery collection.", throwable) }) { val mediaList = ServiceFactory.getRest(pageTitle.wikiSite) - .getMediaList(pageTitle.prefixedText, revision) + .getMediaList(pageTitle.prefixedText) val maxImages = 10 val items = mediaList.getItems("image", "video").asReversed() val titleList = From bf51225d00dcd1c878aef45eeb7a33062cb1975b Mon Sep 17 00:00:00 2001 From: Dmitry Brant Date: Fri, 17 Jan 2025 08:51:38 -0500 Subject: [PATCH 2/4] Split off overloads. --- app/src/main/java/org/wikipedia/dataclient/RestService.kt | 7 ++++++- .../main/java/org/wikipedia/gallery/GalleryViewModel.kt | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/wikipedia/dataclient/RestService.kt b/app/src/main/java/org/wikipedia/dataclient/RestService.kt index 0a692a2c8a6..4ff38a0fcff 100644 --- a/app/src/main/java/org/wikipedia/dataclient/RestService.kt +++ b/app/src/main/java/org/wikipedia/dataclient/RestService.kt @@ -56,10 +56,15 @@ interface RestService { @Headers("Accept: $ACCEPT_HEADER_SUMMARY") suspend fun getRandomSummary(): PageSummary + @GET("page/media-list/{title}") + suspend fun getMediaList( + @Path("title") title: String + ): MediaList + @GET("page/media-list/{title}/{revision}") suspend fun getMediaList( @Path("title") title: String, - @Path("revision") revision: Long? = null + @Path("revision") revision: Long ): MediaList @GET("page/media-list/{title}/{revision}") diff --git a/app/src/main/java/org/wikipedia/gallery/GalleryViewModel.kt b/app/src/main/java/org/wikipedia/gallery/GalleryViewModel.kt index b074ba778ea..c2a3b56b77a 100644 --- a/app/src/main/java/org/wikipedia/gallery/GalleryViewModel.kt +++ b/app/src/main/java/org/wikipedia/gallery/GalleryViewModel.kt @@ -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) } } From 874410ee4e348a37ca75b495300e8c645b524c97 Mon Sep 17 00:00:00 2001 From: Dmitry Brant Date: Fri, 17 Jan 2025 09:55:18 -0500 Subject: [PATCH 3/4] Streamline calls to PageSummary and MediaList. --- .../org/wikipedia/dataclient/RestService.kt | 32 ++++++------ .../descriptions/DescriptionEditViewModel.kt | 6 +-- .../wikipedia/edit/EditSectionViewModel.kt | 4 +- .../wikipedia/page/PageFragmentLoadState.kt | 4 +- .../savedpages/SavedPageSyncService.kt | 52 ++++++++----------- ...uggestedEditsImageRecsFragmentViewModel.kt | 2 +- .../provider/EditingSuggestionsProvider.kt | 6 +-- .../main/java/org/wikipedia/util/L10nUtil.kt | 2 +- .../widgets/WidgetFeaturedPageWorker.kt | 4 +- 9 files changed, 50 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/org/wikipedia/dataclient/RestService.kt b/app/src/main/java/org/wikipedia/dataclient/RestService.kt index 4ff38a0fcff..14a39f80284 100644 --- a/app/src/main/java/org/wikipedia/dataclient/RestService.kt +++ b/app/src/main/java/org/wikipedia/dataclient/RestService.kt @@ -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 @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 @Headers("Accept: $ACCEPT_HEADER_DEFINITION") @GET("page/definition/{title}") @@ -58,7 +62,11 @@ interface RestService { @GET("page/media-list/{title}") suspend fun getMediaList( - @Path("title") title: String + @Path("title") title: String, + @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}") @@ -67,16 +75,6 @@ interface RestService { @Path("revision") revision: Long ): 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 - @GET("feed/onthisday/events/{mm}/{dd}") suspend fun getOnThisDay(@Path("mm") month: Int, @Path("dd") day: Int): OnThisDay diff --git a/app/src/main/java/org/wikipedia/descriptions/DescriptionEditViewModel.kt b/app/src/main/java/org/wikipedia/descriptions/DescriptionEditViewModel.kt index d361ae7d539..c5efb996259 100644 --- a/app/src/main/java/org/wikipedia/descriptions/DescriptionEditViewModel.kt +++ b/app/src/main/java/org/wikipedia/descriptions/DescriptionEditViewModel.kt @@ -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") @@ -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) diff --git a/app/src/main/java/org/wikipedia/edit/EditSectionViewModel.kt b/app/src/main/java/org/wikipedia/edit/EditSectionViewModel.kt index 2bc5eee3f45..6ff02ee5bb1 100644 --- a/app/src/main/java/org/wikipedia/edit/EditSectionViewModel.kt +++ b/app/src/main/java/org/wikipedia/edit/EditSectionViewModel.kt @@ -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) diff --git a/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.kt b/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.kt index b3b35437072..9b6f436f7eb 100644 --- a/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.kt +++ b/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.kt @@ -155,8 +155,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.") } diff --git a/app/src/main/java/org/wikipedia/savedpages/SavedPageSyncService.kt b/app/src/main/java/org/wikipedia/savedpages/SavedPageSyncService.kt index a896f5a6922..f365b897a32 100644 --- a/app/src/main/java/org/wikipedia/savedpages/SavedPageSyncService.kt +++ b/app/src/main/java/org/wikipedia/savedpages/SavedPageSyncService.kt @@ -9,6 +9,7 @@ import androidx.work.OneTimeWorkRequestBuilder import androidx.work.WorkManager import androidx.work.WorkerParameters import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async import kotlinx.coroutines.withContext import okhttp3.Request import okio.Buffer @@ -23,9 +24,7 @@ import org.wikipedia.dataclient.WikiSite import org.wikipedia.dataclient.okhttp.HttpStatusException import org.wikipedia.dataclient.okhttp.OfflineCacheInterceptor import org.wikipedia.dataclient.okhttp.OkHttpConnectionFactory -import org.wikipedia.dataclient.page.PageSummary import org.wikipedia.events.PageDownloadEvent -import org.wikipedia.gallery.MediaList import org.wikipedia.page.PageTitle import org.wikipedia.pageimages.db.PageImage import org.wikipedia.readinglist.database.ReadingListPage @@ -35,7 +34,6 @@ import org.wikipedia.settings.Prefs import org.wikipedia.util.* import org.wikipedia.util.log.L import org.wikipedia.views.CircularProgressBar -import retrofit2.Response import java.io.IOException import java.util.concurrent.TimeUnit @@ -158,11 +156,21 @@ class SavedPageSyncService(context: Context, params: WorkerParameters) : Corouti return withContext(Dispatchers.IO) { val pageTitle = ReadingListPage.toPageTitle(page) - // API calls - val summaryResponse = reqPageSummary(pageTitle) - val revision = summaryResponse.body()?.revision ?: 0 - val mediaListResponse = reqMediaList(pageTitle, revision) - val mobileHTMLResponse = reqMobileHTML(pageTitle) + val summaryCall = async { ServiceFactory.getRest(pageTitle.wikiSite).getPageSummary(pageTitle.prefixedText, + cacheControl = OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK.toString(), + saveHeader = OfflineCacheInterceptor.SAVE_HEADER_SAVE, langHeader = pageTitle.wikiSite.languageCode, + titleHeader = UriUtil.encodeURL(pageTitle.prefixedText)) } + + val mediaListCall = async { ServiceFactory.getRest(pageTitle.wikiSite).getMediaList(pageTitle.prefixedText, + cacheControl = OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK.toString(), + saveHeader = OfflineCacheInterceptor.SAVE_HEADER_SAVE, langHeader = pageTitle.wikiSite.languageCode, + titleHeader = UriUtil.encodeURL(pageTitle.prefixedText)) } + + val mobileHTMLCall = async { reqMobileHTML(pageTitle) } + + val summaryResponse = summaryCall.await() + val mediaListResponse = mediaListCall.await() + val mobileHTMLResponse = mobileHTMLCall.await() page.downloadProgress = MEDIA_LIST_PROGRESS FlowEventBus.post(PageDownloadEvent(page)) @@ -175,22 +183,22 @@ class SavedPageSyncService(context: Context, params: WorkerParameters) : Corouti } if (Prefs.isImageDownloadEnabled) { // download thumbnail and lead image - if (!summaryResponse.body()?.thumbnailUrl.isNullOrEmpty()) { - page.thumbUrl = UriUtil.resolveProtocolRelativeUrl(pageTitle.wikiSite, summaryResponse.body()?.thumbnailUrl.orEmpty()) + if (!summaryResponse.thumbnailUrl.isNullOrEmpty()) { + page.thumbUrl = UriUtil.resolveProtocolRelativeUrl(pageTitle.wikiSite, summaryResponse.thumbnailUrl.orEmpty()) AppDatabase.instance.pageImagesDao().insertPageImageSync(PageImage(pageTitle, page.thumbUrl.orEmpty())) fileUrls.add(UriUtil.resolveProtocolRelativeUrl( ImageUrlUtil.getUrlForPreferredSize(page.thumbUrl.orEmpty(), DimenUtil.calculateLeadImageWidth()))) } // download article images - for (item in mediaListResponse.body()?.getItems("image").orEmpty()) { + for (item in mediaListResponse.getItems("image")) { item.srcSets.let { fileUrls.add(item.getImageUrl(DimenUtil.densityScalar)) } } } - page.displayTitle = summaryResponse.body()?.displayTitle.orEmpty() - page.description = summaryResponse.body()?.description.orEmpty() + page.displayTitle = summaryResponse.displayTitle.orEmpty() + page.description = summaryResponse.description.orEmpty() reqSaveFiles(page, pageTitle, fileUrls) @@ -202,24 +210,6 @@ class SavedPageSyncService(context: Context, params: WorkerParameters) : Corouti } } - private suspend fun reqPageSummary(pageTitle: PageTitle): Response { - return withContext(Dispatchers.IO) { - ServiceFactory.getRest(pageTitle.wikiSite).getSummaryResponse(pageTitle.prefixedText, - null, OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK.toString(), - OfflineCacheInterceptor.SAVE_HEADER_SAVE, pageTitle.wikiSite.languageCode, - UriUtil.encodeURL(pageTitle.prefixedText)) - } - } - - private suspend fun reqMediaList(pageTitle: PageTitle, revision: Long): Response { - return withContext(Dispatchers.IO) { - ServiceFactory.getRest(pageTitle.wikiSite).getMediaListResponse(pageTitle.prefixedText, - revision, OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK.toString(), - OfflineCacheInterceptor.SAVE_HEADER_SAVE, pageTitle.wikiSite.languageCode, - UriUtil.encodeURL(pageTitle.prefixedText)) - } - } - private suspend fun reqMobileHTML(pageTitle: PageTitle): okhttp3.Response { val request = makeUrlRequest(pageTitle.wikiSite, ServiceFactory.getRestBasePath(pageTitle.wikiSite) + diff --git a/app/src/main/java/org/wikipedia/suggestededits/SuggestedEditsImageRecsFragmentViewModel.kt b/app/src/main/java/org/wikipedia/suggestededits/SuggestedEditsImageRecsFragmentViewModel.kt index 69b0cadec29..113c5983c5f 100644 --- a/app/src/main/java/org/wikipedia/suggestededits/SuggestedEditsImageRecsFragmentViewModel.kt +++ b/app/src/main/java/org/wikipedia/suggestededits/SuggestedEditsImageRecsFragmentViewModel.kt @@ -66,7 +66,7 @@ class SuggestedEditsImageRecsFragmentViewModel(savedStateHandle: SavedStateHandl recommendation = page?.growthimagesuggestiondata?.first()!! val wikiSite = WikiSite.forLanguageCode(langCode) - summary = ServiceFactory.getRest(wikiSite).getPageSummary(null, page.title) + summary = ServiceFactory.getRest(wikiSite).getPageSummary(page.title) pageTitle = summary.getPageTitle(wikiSite) val thumbUrl = UriUtil.resolveProtocolRelativeUrl(ImageUrlUtil.getUrlForPreferredSize(recommendation.images[0].metadata!!.thumbUrl, Constants.PREFERRED_CARD_THUMBNAIL_SIZE)) diff --git a/app/src/main/java/org/wikipedia/suggestededits/provider/EditingSuggestionsProvider.kt b/app/src/main/java/org/wikipedia/suggestededits/provider/EditingSuggestionsProvider.kt index 8d2c7a4296e..0b0777febbd 100644 --- a/app/src/main/java/org/wikipedia/suggestededits/provider/EditingSuggestionsProvider.kt +++ b/app/src/main/java/org/wikipedia/suggestededits/provider/EditingSuggestionsProvider.kt @@ -94,7 +94,7 @@ object EditingSuggestionsProvider { } } - pageSummary = ServiceFactory.getRest(wiki).getPageSummary(null, title) + pageSummary = ServiceFactory.getRest(wiki).getPageSummary(title) } finally { mutex.release() } @@ -154,14 +154,14 @@ object EditingSuggestionsProvider { titles?.let { val sourcePageSummary = async { - ServiceFactory.getRest(it.first.wikiSite).getPageSummary(null, it.first.prefixedText).apply { + ServiceFactory.getRest(it.first.wikiSite).getPageSummary(it.first.prefixedText).apply { if (description.isNullOrEmpty()) { description = it.first.description } } } val targetPageSummary = async { - ServiceFactory.getRest(it.second.wikiSite).getPageSummary(null, it.second.prefixedText) + ServiceFactory.getRest(it.second.wikiSite).getPageSummary(it.second.prefixedText) } pair = sourcePageSummary.await() to targetPageSummary.await() } diff --git a/app/src/main/java/org/wikipedia/util/L10nUtil.kt b/app/src/main/java/org/wikipedia/util/L10nUtil.kt index 2b118ee735b..b812f15d1e6 100644 --- a/app/src/main/java/org/wikipedia/util/L10nUtil.kt +++ b/app/src/main/java/org/wikipedia/util/L10nUtil.kt @@ -159,7 +159,7 @@ object L10nUtil { if (shouldUpdateExtracts) { list.map { pageSummary -> async { - ServiceFactory.getRest(wikiSite).getPageSummary(null, pageSummary.apiTitle) + ServiceFactory.getRest(wikiSite).getPageSummary(pageSummary.apiTitle) } }.awaitAll().forEachIndexed { index, pageSummary -> list[index].extract = pageSummary.extract diff --git a/app/src/main/java/org/wikipedia/widgets/WidgetFeaturedPageWorker.kt b/app/src/main/java/org/wikipedia/widgets/WidgetFeaturedPageWorker.kt index a8596a0c1d4..1c971fb9e0b 100644 --- a/app/src/main/java/org/wikipedia/widgets/WidgetFeaturedPageWorker.kt +++ b/app/src/main/java/org/wikipedia/widgets/WidgetFeaturedPageWorker.kt @@ -31,13 +31,13 @@ class WidgetFeaturedPageWorker( val summary = if (result.tfa != null) { val hasParentLanguageCode = !WikipediaApp.instance.languageState.getDefaultLanguageCode(WikipediaApp.instance.wikiSite.languageCode).isNullOrEmpty() if (hasParentLanguageCode) { - ServiceFactory.getRest(WikipediaApp.instance.wikiSite).getPageSummary(null, result.tfa.apiTitle) + ServiceFactory.getRest(WikipediaApp.instance.wikiSite).getPageSummary(result.tfa.apiTitle) } else { result.tfa } } else { val response = ServiceFactory.get(mainPageTitle.wikiSite).parseTextForMainPage(mainPageTitle.prefixedText) - ServiceFactory.getRest(WikipediaApp.instance.wikiSite).getPageSummary(null, findFeaturedArticleTitle(response.text)) + ServiceFactory.getRest(WikipediaApp.instance.wikiSite).getPageSummary(findFeaturedArticleTitle(response.text)) } val pageTitle = summary.getPageTitle(app.wikiSite) From f1a311371f1194c0139c4b25c3a2ca4298357e11 Mon Sep 17 00:00:00 2001 From: Dmitry Brant Date: Fri, 17 Jan 2025 10:12:23 -0500 Subject: [PATCH 4/4] Use named parameters. --- .../main/java/org/wikipedia/page/PageFragmentLoadState.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.kt b/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.kt index 9b6f436f7eb..c42c04923fb 100644 --- a/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.kt +++ b/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.kt @@ -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) {