Skip to content

Commit d015e1f

Browse files
Merge branch 'main' into Serializable_extensions
2 parents 5a4b837 + 1089ec6 commit d015e1f

File tree

88 files changed

+1643
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1643
-367
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300

301301
<activity
302302
android:name=".activity.SingleWebViewActivity"
303-
android:theme="@style/AppTheme.ActionBar" />
303+
android:theme="@style/AppTheme" />
304304

305305
<activity
306306
android:name=".page.customize.CustomizeToolbarActivity"

app/src/main/java/org/wikipedia/activity/SingleWebViewActivity.kt

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,33 @@ import android.annotation.SuppressLint
44
import android.content.Context
55
import android.content.Intent
66
import android.graphics.Bitmap
7+
import android.net.Uri
78
import android.os.Bundle
9+
import android.view.Menu
10+
import android.view.MenuItem
811
import android.view.ViewGroup
912
import android.webkit.WebView
1013
import androidx.core.view.isVisible
14+
import org.wikipedia.R
1115
import org.wikipedia.WikipediaApp
1216
import org.wikipedia.databinding.ActivitySingleWebViewBinding
1317
import org.wikipedia.dataclient.WikiSite
1418
import org.wikipedia.dataclient.okhttp.OkHttpWebViewClient
19+
import org.wikipedia.extensions.parcelableExtra
20+
import org.wikipedia.history.HistoryEntry
1521
import org.wikipedia.page.LinkHandler
22+
import org.wikipedia.page.PageActivity
1623
import org.wikipedia.page.PageTitle
1724
import org.wikipedia.page.PageViewModel
25+
import org.wikipedia.util.UriUtil
1826

1927
class SingleWebViewActivity : BaseActivity() {
2028
private lateinit var binding: ActivitySingleWebViewBinding
2129
private lateinit var blankLinkHandler: LinkHandler
2230
private lateinit var targetUrl: String
31+
private var currentUrl: String? = null
32+
private var pageTitle: PageTitle? = null
33+
private var showBackButton: Boolean = false
2334
val blankModel = PageViewModel()
2435

2536
@SuppressLint("SetJavaScriptEnabled")
@@ -28,11 +39,18 @@ class SingleWebViewActivity : BaseActivity() {
2839
binding = ActivitySingleWebViewBinding.inflate(layoutInflater)
2940
setContentView(binding.root)
3041

42+
setSupportActionBar(binding.toolbar)
3143
supportActionBar?.title = ""
3244

3345
targetUrl = intent.getStringExtra(EXTRA_URL)!!
46+
showBackButton = intent.getBooleanExtra(EXTRA_SHOW_BACK_BUTTON, false)
47+
pageTitle = intent.parcelableExtra(EXTRA_PAGE_TITLE)
3448
blankLinkHandler = EditLinkHandler(this, WikipediaApp.instance.wikiSite)
3549

50+
binding.backButton.isVisible = showBackButton
51+
binding.backButton.setOnClickListener {
52+
goBack()
53+
}
3654
binding.webView.settings.javaScriptEnabled = true
3755
binding.webView.settings.mediaPlaybackRequiresUserGesture = false
3856
binding.webView.webViewClient = object : OkHttpWebViewClient() {
@@ -42,11 +60,14 @@ class SingleWebViewActivity : BaseActivity() {
4260
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
4361
super.onPageStarted(view, url, favicon)
4462
binding.progressBar.isVisible = true
63+
invalidateOptionsMenu()
4564
}
4665

4766
override fun onPageFinished(view: WebView?, url: String?) {
4867
super.onPageFinished(view, url)
4968
binding.progressBar.isVisible = false
69+
currentUrl = url
70+
invalidateOptionsMenu()
5071
}
5172
}
5273

@@ -55,6 +76,29 @@ class SingleWebViewActivity : BaseActivity() {
5576
}
5677
}
5778

79+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
80+
menuInflater.inflate(R.menu.menu_single_webview, menu)
81+
return true
82+
}
83+
84+
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
85+
menu.findItem(R.id.menu_group)?.isVisible = !binding.progressBar.isVisible && !currentUrl.isNullOrEmpty()
86+
return super.onPrepareOptionsMenu(menu)
87+
}
88+
89+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
90+
super.onOptionsItemSelected(item)
91+
return when (item.itemId) {
92+
R.id.menu_in_new -> {
93+
currentUrl?.let {
94+
UriUtil.visitInExternalBrowser(this@SingleWebViewActivity, Uri.parse(it))
95+
}
96+
true
97+
}
98+
else -> super.onOptionsItemSelected(item)
99+
}
100+
}
101+
58102
override fun onDestroy() {
59103
binding.webView.clearAllListeners()
60104
(binding.webView.parent as ViewGroup).removeView(binding.webView)
@@ -66,9 +110,18 @@ class SingleWebViewActivity : BaseActivity() {
66110
binding.webView.goBack()
67111
return
68112
}
113+
goBack()
69114
super.onBackPressed()
70115
}
71116

117+
private fun goBack() {
118+
pageTitle?.let {
119+
val entry = HistoryEntry(it, HistoryEntry.SOURCE_SINGLE_WEBVIEW)
120+
startActivity(PageActivity.newIntentForExistingTab(this@SingleWebViewActivity, entry, entry.title))
121+
}
122+
finish()
123+
}
124+
72125
inner class EditLinkHandler constructor(context: Context, override var wikiSite: WikiSite) : LinkHandler(context) {
73126
override fun onPageLinkClicked(anchor: String, linkText: String) { }
74127
override fun onInternalLinkClicked(title: PageTitle) { }
@@ -78,10 +131,14 @@ class SingleWebViewActivity : BaseActivity() {
78131

79132
companion object {
80133
const val EXTRA_URL = "url"
134+
const val EXTRA_SHOW_BACK_BUTTON = "goBack"
135+
const val EXTRA_PAGE_TITLE = "pageTitle"
81136

82-
fun newIntent(context: Context, url: String): Intent {
137+
fun newIntent(context: Context, url: String, showBackButton: Boolean = false, pageTitle: PageTitle? = null): Intent {
83138
return Intent(context, SingleWebViewActivity::class.java)
84139
.putExtra(EXTRA_URL, url)
140+
.putExtra(EXTRA_SHOW_BACK_BUTTON, showBackButton)
141+
.putExtra(EXTRA_PAGE_TITLE, pageTitle)
85142
}
86143
}
87144
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.wikipedia.analytics.eventplatform
2+
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
5+
import org.wikipedia.WikipediaApp
6+
7+
@Suppress("unused")
8+
@Serializable
9+
@SerialName("/analytics/mobile_apps/app_interaction/1.0.0")
10+
class DonorExperienceEvent(
11+
private val action: String,
12+
private val active_interface: String,
13+
private val action_data: String,
14+
private val primary_language: String,
15+
private val wiki_id: String,
16+
private val platform: String = "android"
17+
) : MobileAppsEvent(STREAM_NAME) {
18+
19+
companion object {
20+
private const val STREAM_NAME = "app_donor_experience"
21+
22+
fun logImpression(activeInterface: String, actionData: String = "", wikiId: String = "") {
23+
submitDonorExperienceEvent("impression", activeInterface, actionData, wikiId)
24+
}
25+
26+
fun logAction(
27+
action: String,
28+
activeInterface: String,
29+
wikiId: String = "",
30+
campaignId: Long? = null
31+
) {
32+
submitDonorExperienceEvent(
33+
action,
34+
activeInterface,
35+
getActionDataString(campaignId),
36+
wikiId
37+
)
38+
}
39+
40+
fun getActionDataString(campaignId: Long? = null): String {
41+
return campaignId?.let { "campaign_id: $it, " }.orEmpty()
42+
}
43+
44+
private fun submitDonorExperienceEvent(
45+
action: String,
46+
activeInterface: String,
47+
actionData: String,
48+
wikiId: String
49+
) {
50+
EventPlatformClient.submit(
51+
DonorExperienceEvent(
52+
action,
53+
activeInterface,
54+
actionData,
55+
WikipediaApp.instance.languageState.appLanguageCode,
56+
wikiId
57+
)
58+
)
59+
}
60+
}
61+
}

app/src/main/java/org/wikipedia/dataclient/RestService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ interface RestService {
106106
@GET("feed/onthisday/events/{mm}/{dd}")
107107
fun getOnThisDay(@Path("mm") month: Int, @Path("dd") day: Int): Observable<OnThisDay>
108108

109+
// TODO: Remove this before next fundraising campaign in 2024
109110
@get:GET("feed/announcements")
110111
@get:Headers("Accept: " + ACCEPT_HEADER_PREFIX + "announcements/0.1.0\"")
111112
val announcements: Observable<AnnouncementList>

app/src/main/java/org/wikipedia/dataclient/discussiontools/ThreadItem.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ class ThreadItem(
3232
@IgnoredOnParcel @Transient val plainText = StringUtil.fromHtml(StringUtil.removeStyleTags(html)).toString()
3333
@IgnoredOnParcel @Transient val plainOtherContent = StringUtil.fromHtml(StringUtil.removeStyleTags(othercontent)).toString()
3434

35-
@IgnoredOnParcel val allReplies: List<ThreadItem>
36-
get() {
37-
val list = mutableListOf<ThreadItem>()
35+
@IgnoredOnParcel val allReplies: Sequence<ThreadItem>
36+
get() = sequence {
3837
replies.forEach {
39-
list.add(it)
40-
list.addAll(it.allReplies)
38+
yield(it)
39+
yieldAll(it.allReplies)
4140
}
42-
return list
4341
}
4442

4543
@IgnoredOnParcel @Transient val date = try {

app/src/main/java/org/wikipedia/dataclient/donate/CampaignCollection.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ object CampaignCollection {
1717
private const val CAMPAIGN_VERSION = 1
1818

1919
private const val CAMPAIGNS_URL = "https://donate.wikimedia.org/wiki/MediaWiki:AppsCampaignConfig.json?action=raw"
20-
private const val CAMPAIGNS_URL_DEBUG = "https://donate.wikimedia.org/wiki/MediaWiki:AppsCampaignConfigStaging.json?action=raw"
20+
private const val CAMPAIGNS_URL_DEBUG = "https://test.wikipedia.org/wiki/MediaWiki:AppsCampaignConfig.json?action=raw"
2121

2222
suspend fun getActiveCampaigns(): List<Campaign> {
2323
val campaignList = mutableListOf<Campaign>()
2424

2525
withContext(Dispatchers.IO) {
26-
val request = Request.Builder().url(CAMPAIGNS_URL_DEBUG).build()
26+
val url = if (Prefs.announcementDebugUrl) CAMPAIGNS_URL_DEBUG else CAMPAIGNS_URL
27+
val request = Request.Builder().url(url).build()
2728
val response = OkHttpConnectionFactory.client.newCall(request).execute()
2829
val campaigns = JsonUtil.decodeFromString<List<JsonElement>>(response.body?.string()).orEmpty()
2930

app/src/main/java/org/wikipedia/feed/announcement/AnnouncementClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import org.wikipedia.settings.Prefs
1616
import org.wikipedia.util.GeoUtil
1717
import org.wikipedia.util.ReleaseUtil
1818
import org.wikipedia.util.log.L
19-
import java.util.*
19+
import java.util.Date
2020

2121
class AnnouncementClient : FeedClient {
2222

app/src/main/java/org/wikipedia/history/HistoryEntry.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.wikipedia.dataclient.WikiSite
1313
import org.wikipedia.json.DateSerializer
1414
import org.wikipedia.page.PageTitle
1515
import org.wikipedia.parcel.DateParceler
16-
import java.util.*
16+
import java.util.Date
1717

1818
@Serializable
1919
@Parcelize
@@ -94,5 +94,6 @@ class HistoryEntry(
9494
const val SOURCE_ARCHIVED_TALK = 37
9595
const val SOURCE_USER_CONTRIB = 38
9696
const val SOURCE_FILE_PAGE = 39
97+
const val SOURCE_SINGLE_WEBVIEW = 40
9798
}
9899
}

app/src/main/java/org/wikipedia/notifications/NotificationActivity.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -373,18 +373,19 @@ class NotificationActivity : BaseActivity() {
373373
ImageViewCompat.setImageTintList(binding.notificationItemImage, if (n.isUnread) notificationColor else
374374
ResourceUtil.getThemedColorStateList(this@NotificationActivity, R.attr.placeholder_color))
375375
n.contents?.let {
376-
binding.notificationSubtitle.text = RichTextUtil.stripHtml(it.header)
377-
StringUtil.highlightAndBoldenText(binding.notificationSubtitle, viewModel.currentSearchQuery, true, Color.YELLOW)
378-
if (it.body.trim().isNotEmpty() && it.body.trim().isNotBlank()) {
379-
binding.notificationDescription.text = RichTextUtil.stripHtml(it.body)
380-
StringUtil.highlightAndBoldenText(binding.notificationDescription, viewModel.currentSearchQuery, true, Color.YELLOW)
381-
binding.notificationDescription.visibility = View.VISIBLE
382-
} else {
383-
binding.notificationDescription.visibility = View.GONE
376+
StringUtil.setHighlightedAndBoldenedText(binding.notificationSubtitle,
377+
RichTextUtil.stripHtml(it.header), viewModel.currentSearchQuery)
378+
379+
val showDescription = it.body.isNotBlank()
380+
binding.notificationDescription.isVisible = showDescription
381+
if (showDescription) {
382+
StringUtil.setHighlightedAndBoldenedText(binding.notificationDescription,
383+
RichTextUtil.stripHtml(it.body), viewModel.currentSearchQuery)
384384
}
385+
385386
it.links?.secondary?.firstOrNull()?.let { link ->
386-
binding.notificationTitle.text = link.label
387-
StringUtil.highlightAndBoldenText(binding.notificationTitle, viewModel.currentSearchQuery, true, Color.YELLOW)
387+
StringUtil.setHighlightedAndBoldenedText(binding.notificationTitle, link.label,
388+
viewModel.currentSearchQuery)
388389
} ?: run {
389390
binding.notificationTitle.text = getString(notificationCategory.title)
390391
}
@@ -402,8 +403,8 @@ class NotificationActivity : BaseActivity() {
402403
L10nUtil.setConditionalLayoutDirection(itemView, langCode)
403404

404405
n.title?.let { title ->
405-
binding.notificationSource.text = title.full
406-
StringUtil.highlightAndBoldenText(binding.notificationSource, viewModel.currentSearchQuery, true, Color.YELLOW)
406+
StringUtil.setHighlightedAndBoldenedText(binding.notificationSource, title.full,
407+
viewModel.currentSearchQuery)
407408
n.contents?.links?.getPrimary()?.url?.let {
408409
binding.notificationSource.setCompoundDrawablesRelative(null, null,
409410
if (UriUtil.isAppSupportedLink(Uri.parse(it))) null else externalLinkIcon, null)

app/src/main/java/org/wikipedia/page/AnnouncementDialog.kt

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)