Skip to content

Commit eaf041c

Browse files
committed
Merge branch 'trunk' into feat/CMM-964-auto-generate-Application-Password-redirect-to-webview-login-if-the-cookie-creation-failed
# Conflicts: # WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt # WordPress/src/main/java/org/wordpress/android/ui/mysite/SiteNavigationAction.kt # WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/applicationpassword/ApplicationPasswordViewModelSlice.kt # libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/rs/WpApiClientProvider.kt
2 parents ffc5af0 + 50139f4 commit eaf041c

File tree

34 files changed

+726
-1230
lines changed

34 files changed

+726
-1230
lines changed

WordPress/src/main/java/org/wordpress/android/AppInitializer.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ import org.wordpress.android.util.analytics.AnalyticsUtils
110110
import org.wordpress.android.util.config.AppConfig
111111
import org.wordpress.android.util.config.OpenWebLinksWithJetpackFlowFeatureConfig
112112
import org.wordpress.android.util.enqueuePeriodicUploadWorkRequestForAllSites
113-
import org.wordpress.android.util.experiments.ExPlat
114113
import org.wordpress.android.util.image.ImageManager
115114
import org.wordpress.android.widgets.AppReviewManager
116115
import org.wordpress.android.workers.WordPressWorkersFactory
@@ -184,9 +183,6 @@ class AppInitializer @Inject constructor(
184183
@Inject
185184
lateinit var imageEditorFileUtils: ImageEditorFileUtils
186185

187-
@Inject
188-
lateinit var exPlat: ExPlat
189-
190186
@Inject
191187
lateinit var wordPressWorkerFactory: WordPressWorkersFactory
192188

@@ -372,8 +368,6 @@ class AppInitializer @Inject constructor(
372368
systemNotificationsTracker.checkSystemNotificationsState()
373369
ImageEditorInitializer.init(imageManager, imageEditorTracker, imageEditorFileUtils, appScope)
374370

375-
exPlat.forceRefresh()
376-
377371
initDebugCookieManager()
378372

379373
if (!initialized && BuildConfig.DEBUG && Build.VERSION.SDK_INT >= VERSION_CODES.R) {
@@ -662,9 +656,6 @@ class AppInitializer @Inject constructor(
662656
if (accountStore.hasAccessToken()) {
663657
// Make sure the Push Notification token is sent to our servers after a successful login
664658
gcmRegistrationScheduler.scheduleRegistration()
665-
666-
// Force a refresh if user has logged in. This can be removed once we start using an anonymous ID.
667-
exPlat.forceRefresh()
668659
}
669660
}
670661

@@ -727,9 +718,6 @@ class AppInitializer @Inject constructor(
727718

728719
// Clear WordPress.com account cookie cache
729720
wordPressCookieAuthenticator.clearAllCachedCookies()
730-
731-
// Clear cached assignments if user has logged out. This can be removed once we start using an anonymous ID.
732-
exPlat.clear()
733721
}
734722

735723
/*
@@ -934,11 +922,6 @@ class AppInitializer @Inject constructor(
934922

935923
// Let's migrate the old editor preference if available in AppPrefs to the remote backend
936924
SiteUtils.migrateAppWideMobileEditorPreferenceToRemote(accountStore, siteStore, dispatcher)
937-
if (!firstActivityResumed) {
938-
// Since we're force refreshing on app startup, we don't need to try refreshing again when starting
939-
// our first Activity.
940-
exPlat.refreshIfNeeded()
941-
}
942925
if (firstActivityResumed) {
943926
deferredInit()
944927
}

WordPress/src/main/java/org/wordpress/android/modules/ExperimentModule.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.wordpress.android.support.he.model
2+
3+
enum class ConversationStatus {
4+
WAITING_FOR_SUPPORT,
5+
WAITING_FOR_USER,
6+
CLOSED,
7+
SOLVED,
8+
UNKNOWN;
9+
10+
companion object {
11+
fun fromStatus(status: String): ConversationStatus {
12+
return when (status.lowercase()) {
13+
"open", "new", "hold" -> WAITING_FOR_SUPPORT
14+
"closed" -> CLOSED
15+
"pending" -> WAITING_FOR_USER
16+
"solved" -> SOLVED
17+
else -> UNKNOWN
18+
}
19+
}
20+
}
21+
}

WordPress/src/main/java/org/wordpress/android/support/he/model/SupportConversation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ data class SupportConversation(
88
val title: String,
99
val description: String,
1010
val lastMessageSentAt: Date,
11+
val status: String,
1112
val messages: List<SupportMessage>
1213
): Conversation {
1314
override fun getConversationId(): Long = id
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.wordpress.android.support.he.model
2+
3+
import java.io.File
4+
5+
sealed class VideoDownloadState {
6+
object Idle : VideoDownloadState()
7+
object Downloading : VideoDownloadState()
8+
object Error : VideoDownloadState()
9+
data class Success(val file: File) : VideoDownloadState()
10+
}

WordPress/src/main/java/org/wordpress/android/support/he/repository/HESupportRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class HESupportRepository @Inject constructor(
181181
title = it.title,
182182
description = it.description,
183183
lastMessageSentAt = it.updatedAt,
184+
status = it.status,
184185
messages = emptyList()
185186
)
186187
}
@@ -191,6 +192,7 @@ class HESupportRepository @Inject constructor(
191192
title = title,
192193
description = description,
193194
lastMessageSentAt = updatedAt,
195+
status = status,
194196
messages = messages.map { it.toSupportMessage() }
195197
)
196198

WordPress/src/main/java/org/wordpress/android/support/he/ui/AttachmentFullscreenImagePreview.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,23 @@ import androidx.compose.ui.window.DialogProperties
4040
import coil.compose.SubcomposeAsyncImage
4141
import coil.request.ImageRequest
4242
import org.wordpress.android.R
43+
import org.wordpress.android.support.he.ui.HESupportActivity.Companion.AUTHORIZATION_TAG
4344
import org.wordpress.android.ui.compose.theme.AppThemeM3
4445

4546
@Composable
4647
fun AttachmentFullscreenImagePreview(
4748
imageUrl: String,
49+
onGetAuthorizationHeaderArgument: () -> String,
4850
onDismiss: () -> Unit,
49-
onDownload: () -> Unit = {}
51+
onDownload: () -> Unit = {},
5052
) {
5153
var scale by remember { mutableFloatStateOf(1f) }
5254
var offsetX by remember { mutableFloatStateOf(0f) }
5355
var offsetY by remember { mutableFloatStateOf(0f) }
5456

57+
// Cache authorization header to avoid repeated function calls during composition
58+
val authorizationHeader = remember { onGetAuthorizationHeaderArgument() }
59+
5560
// Load semantics
5661
val loadingImageDescription = stringResource(R.string.he_support_loading_image)
5762
val attachmentImageDescription = stringResource(R.string.he_support_attachment_image)
@@ -90,6 +95,9 @@ fun AttachmentFullscreenImagePreview(
9095
model = ImageRequest.Builder(LocalContext.current)
9196
.data(imageUrl)
9297
.crossfade(true)
98+
.apply {
99+
addHeader(AUTHORIZATION_TAG, authorizationHeader)
100+
}
93101
.build(),
94102
contentDescription = attachmentImageDescription,
95103
modifier = Modifier
@@ -181,6 +189,7 @@ private fun AttachmentFullscreenImagePreviewPreview() {
181189
AppThemeM3(isDarkTheme = false) {
182190
AttachmentFullscreenImagePreview(
183191
imageUrl = "https://via.placeholder.com/800x600",
192+
onGetAuthorizationHeaderArgument = { "" },
184193
onDismiss = { },
185194
onDownload = { }
186195
)
@@ -193,6 +202,7 @@ private fun AttachmentFullscreenImagePreviewPreviewDark() {
193202
AppThemeM3(isDarkTheme = true) {
194203
AttachmentFullscreenImagePreview(
195204
imageUrl = "https://via.placeholder.com/800x600",
205+
onGetAuthorizationHeaderArgument = { "" },
196206
onDismiss = { },
197207
onDownload = { }
198208
)

WordPress/src/main/java/org/wordpress/android/support/he/ui/AttachmentFullscreenVideoPlayer.kt

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.wordpress.android.support.he.ui
22

33
import android.view.ViewGroup
4-
import androidx.core.net.toUri
54
import android.widget.FrameLayout
65
import androidx.compose.foundation.background
76
import androidx.compose.foundation.layout.Arrangement
@@ -21,7 +20,7 @@ import androidx.compose.material3.Icon
2120
import androidx.compose.material3.IconButton
2221
import androidx.compose.material3.Text
2322
import androidx.compose.runtime.Composable
24-
import androidx.compose.runtime.DisposableEffect
23+
import androidx.compose.runtime.LaunchedEffect
2524
import androidx.compose.runtime.getValue
2625
import androidx.compose.runtime.mutableStateOf
2726
import androidx.compose.runtime.remember
@@ -37,67 +36,64 @@ import androidx.compose.ui.unit.dp
3736
import androidx.compose.ui.viewinterop.AndroidView
3837
import androidx.compose.ui.window.Dialog
3938
import androidx.compose.ui.window.DialogProperties
39+
import androidx.core.net.toUri
4040
import com.google.android.exoplayer2.MediaItem
4141
import com.google.android.exoplayer2.Player
4242
import com.google.android.exoplayer2.SimpleExoPlayer
4343
import com.google.android.exoplayer2.ui.PlayerView
4444
import org.wordpress.android.R
45-
import org.wordpress.android.support.he.util.VideoUrlResolver
45+
import org.wordpress.android.support.he.model.VideoDownloadState
46+
import org.wordpress.android.util.AppLog
47+
import java.io.File
4648

4749
@Composable
4850
fun AttachmentFullscreenVideoPlayer(
4951
videoUrl: String,
5052
onDismiss: () -> Unit,
5153
onDownload: () -> Unit = {},
52-
videoUrlResolver: VideoUrlResolver? = null
54+
downloadState: VideoDownloadState,
55+
onStartVideoDownload: (String) -> Unit,
56+
onResetVideoDownloadState: () -> Unit = {},
5357
) {
5458
val context = LocalContext.current
55-
var hasError by remember { mutableStateOf(false) }
56-
var resolvedUrl by remember { mutableStateOf<String?>(null) }
57-
var isResolving by remember { mutableStateOf(true) }
59+
var localVideoFile by remember { mutableStateOf<File?>(null) }
60+
61+
// Start download when composable is first launched
62+
LaunchedEffect(videoUrl) {
63+
onStartVideoDownload(videoUrl)
64+
}
5865

59-
// Resolve URL redirects before playing
60-
androidx.compose.runtime.LaunchedEffect(videoUrl) {
61-
if (videoUrlResolver != null) {
62-
resolvedUrl = videoUrlResolver.resolveUrl(videoUrl)
63-
} else {
64-
resolvedUrl = videoUrl
66+
// Update local file when download succeeds
67+
LaunchedEffect(downloadState) {
68+
if (downloadState is VideoDownloadState.Success) {
69+
localVideoFile = downloadState.file
6570
}
66-
isResolving = false
6771
}
6872

69-
val exoPlayer = remember(resolvedUrl) {
70-
// Don't create player until URL is resolved
71-
val url = resolvedUrl ?: return@remember null
73+
val exoPlayer = remember(localVideoFile) {
74+
// Don't create player until video is downloaded
75+
val file = localVideoFile ?: return@remember null
7276

7377
SimpleExoPlayer.Builder(context).build().apply {
74-
// Add error listener
78+
// Add error listener for logging
7579
addListener(object : Player.EventListener {
7680
override fun onPlayerError(error: com.google.android.exoplayer2.ExoPlaybackException) {
77-
hasError = true
81+
AppLog.e(AppLog.T.SUPPORT, "Video playback error", error)
7882
}
7983
})
8084

81-
// Simple configuration using MediaItem
82-
val mediaItem = MediaItem.fromUri(url.toUri())
85+
// Play from local file
86+
val mediaItem = MediaItem.fromUri(file.toUri())
8387
setMediaItem(mediaItem)
8488
prepare()
8589
playWhenReady = true
8690
repeatMode = Player.REPEAT_MODE_OFF
8791
}
8892
}
8993

90-
DisposableEffect(Unit) {
91-
onDispose {
92-
exoPlayer?.stop()
93-
exoPlayer?.release()
94-
}
95-
}
96-
9794
Dialog(
9895
onDismissRequest = {
99-
exoPlayer?.stop()
100-
onDismiss()
96+
closeFullScreen(exoPlayer, onDismiss, onResetVideoDownloadState)
10197
},
10298
properties = DialogProperties(
10399
usePlatformDefaultWidth = false,
@@ -110,15 +106,16 @@ fun AttachmentFullscreenVideoPlayer(
110106
.fillMaxSize()
111107
.background(Color.Black)
112108
) {
113-
when {
114-
isResolving -> {
115-
// Show loading indicator while resolving URL
109+
when (downloadState) {
110+
is VideoDownloadState.Idle,
111+
is VideoDownloadState.Downloading -> {
112+
// Show loading indicator while downloading video
116113
CircularProgressIndicator(
117114
modifier = Modifier.align(Alignment.Center),
118115
color = Color.White
119116
)
120117
}
121-
hasError -> {
118+
is VideoDownloadState.Error -> {
122119
// Show error message when video fails to load
123120
Column(
124121
modifier = Modifier
@@ -146,17 +143,16 @@ fun AttachmentFullscreenVideoPlayer(
146143
)
147144
Button(
148145
onClick = {
149-
exoPlayer?.stop()
150146
onDownload()
151-
onDismiss()
147+
closeFullScreen(exoPlayer, onDismiss, onResetVideoDownloadState)
152148
}
153149
) {
154150
Text(stringResource(R.string.he_support_download_video_button))
155151
}
156152
}
157153
}
158-
else -> {
159-
// Show video player when URL is resolved and no error
154+
is VideoDownloadState.Success -> {
155+
// Show video player when video is downloaded successfully
160156
exoPlayer?.let { player ->
161157
AndroidView(
162158
factory = { ctx ->
@@ -190,9 +186,8 @@ fun AttachmentFullscreenVideoPlayer(
190186
// Download button
191187
IconButton(
192188
onClick = {
193-
exoPlayer?.stop()
194-
onDownload.invoke()
195-
onDismiss.invoke()
189+
onDownload()
190+
closeFullScreen(exoPlayer, onDismiss, onResetVideoDownloadState)
196191
}
197192
) {
198193
Icon(
@@ -206,8 +201,7 @@ fun AttachmentFullscreenVideoPlayer(
206201
// Close button
207202
IconButton(
208203
onClick = {
209-
exoPlayer?.stop()
210-
onDismiss()
204+
closeFullScreen(exoPlayer, onDismiss, onResetVideoDownloadState)
211205
}
212206
) {
213207
Icon(
@@ -221,3 +215,14 @@ fun AttachmentFullscreenVideoPlayer(
221215
}
222216
}
223217
}
218+
219+
fun closeFullScreen(
220+
exoPlayer: SimpleExoPlayer?,
221+
onDismiss: () -> Unit,
222+
onResetVideoDownloadState: () -> Unit,
223+
) {
224+
exoPlayer?.stop()
225+
exoPlayer?.release()
226+
onDismiss()
227+
onResetVideoDownloadState()
228+
}

0 commit comments

Comments
 (0)