Skip to content

Commit 5945637

Browse files
Titouan Thibaudtitooan
authored andcommitted
Fix deeplink and install button on Treeherder screen.
1 parent 5cc41e9 commit 5945637

File tree

5 files changed

+50
-28
lines changed

5 files changed

+50
-28
lines changed

app/src/androidTest/java/org/mozilla/tryfox/MainActivityDeeplinkTest.kt

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package org.mozilla.tryfox
22

33
import android.content.Intent
44
import android.net.Uri
5+
import androidx.compose.ui.test.assert
6+
import androidx.compose.ui.test.hasText
57
import androidx.compose.ui.test.junit4.createComposeRule
68
import androidx.compose.ui.test.onNodeWithText
79
import androidx.test.core.app.ActivityScenario
@@ -23,27 +25,32 @@ class MainActivityDeeplinkTest {
2325
fun testDeeplink_withHash_populatesRevision() {
2426
val project = "try"
2527
val revision = "abcdef123456"
26-
val deeplinkUri = Uri.parse("https://treeherder.mozilla.org/#/jobs?repo=$project&revision=$revision")
27-
val intent = Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java).apply {
28-
action = Intent.ACTION_VIEW
29-
data = deeplinkUri
30-
}
28+
val deeplinkUri =
29+
Uri.parse("https://treeherder.mozilla.org/#/jobs?repo=$project&revision=$revision")
30+
val intent =
31+
Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java).apply {
32+
action = Intent.ACTION_VIEW
33+
data = deeplinkUri
34+
}
3135

3236
ActivityScenario.launch<MainActivity>(intent).use {
3337
composeTestRule.waitForIdle()
34-
composeTestRule.onNodeWithText(revision).assertExists()
38+
composeTestRule.onNodeWithText("Revision").assert(hasText(revision))
39+
composeTestRule.onNodeWithText("Project").assert(hasText(project))
3540
}
3641
}
3742

3843
@Test
3944
fun testDeeplink_withoutHash_populatesRevision() {
4045
val project = "mozilla-central"
4146
val revision = "fedcba654321"
42-
val deeplinkUri = Uri.parse("https://treeherder.mozilla.org/jobs?repo=$project&revision=$revision")
43-
val intent = Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java).apply {
44-
action = Intent.ACTION_VIEW
45-
data = deeplinkUri
46-
}
47+
val deeplinkUri =
48+
Uri.parse("https://treeherder.mozilla.org/jobs?repo=$project&revision=$revision")
49+
val intent =
50+
Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java).apply {
51+
action = Intent.ACTION_VIEW
52+
data = deeplinkUri
53+
}
4754

4855
ActivityScenario.launch<MainActivity>(intent).use {
4956
composeTestRule.waitForIdle()
@@ -58,12 +65,14 @@ class MainActivityDeeplinkTest {
5865

5966
val project = "autoland"
6067
val revision = "abcdef123456"
61-
val deeplinkUri = Uri.parse("https://treeherder.mozilla.org/#/jobs?repo=$project&revision=$revision")
62-
val intent = Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java).apply {
63-
action = Intent.ACTION_VIEW
64-
data = deeplinkUri
65-
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
66-
}
68+
val deeplinkUri =
69+
Uri.parse("https://treeherder.mozilla.org/#/jobs?repo=$project&revision=$revision")
70+
val intent =
71+
Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java).apply {
72+
action = Intent.ACTION_VIEW
73+
data = deeplinkUri
74+
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
75+
}
6776

6877
// Now send the deeplink intent
6978
ApplicationProvider.getApplicationContext<android.content.Context>().startActivity(intent)
@@ -76,11 +85,13 @@ class MainActivityDeeplinkTest {
7685
fun testDeeplink_withAuthorEmail_populatesProfileScreen() {
7786
val email = "tthibaud@mozilla.com"
7887
val encodedEmail = "tthibaud%40mozilla.com"
79-
val deeplinkUri = Uri.parse("https://treeherder.mozilla.org/jobs?repo=try&author=$encodedEmail")
80-
val intent = Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java).apply {
81-
action = Intent.ACTION_VIEW
82-
data = deeplinkUri
83-
}
88+
val deeplinkUri =
89+
Uri.parse("https://treeherder.mozilla.org/jobs?repo=try&author=$encodedEmail")
90+
val intent =
91+
Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java).apply {
92+
action = Intent.ACTION_VIEW
93+
data = deeplinkUri
94+
}
8495

8596
ActivityScenario.launch<MainActivity>(intent).use {
8697
composeTestRule.waitForIdle()

app/src/main/java/org/mozilla/tryfox/MainActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ class MainActivity : ComponentActivity() {
133133
},
134134
),
135135
) { backStackEntry ->
136-
val project = backStackEntry.arguments?.getString("project") ?: "try"
137-
val revision = backStackEntry.arguments?.getString("revision") ?: ""
136+
val project = backStackEntry.arguments?.getString("project")
137+
val revision = backStackEntry.arguments?.getString("revision")
138138
Log.d(
139139
"MainActivity",
140140
"TreeherderSearchWithArgs composable: project='$project', revision='$revision' from NavBackStackEntry. ID: ${backStackEntry.id}",

app/src/main/java/org/mozilla/tryfox/TryFoxViewModel.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.mozilla.tryfox.data.DownloadState
2222
import org.mozilla.tryfox.data.IFenixRepository
2323
import org.mozilla.tryfox.data.NetworkResult
2424
import org.mozilla.tryfox.data.managers.CacheManager
25+
import org.mozilla.tryfox.data.managers.IntentManager
2526
import org.mozilla.tryfox.model.CacheManagementState
2627
import org.mozilla.tryfox.ui.models.AbiUiModel
2728
import org.mozilla.tryfox.ui.models.ArtifactUiModel
@@ -35,19 +36,20 @@ import java.io.File
3536
* @param fenixRepository The repository for fetching data from the network.
3637
* @param cacheManager The manager for handling application cache.
3738
* @param revision The initial revision to search for.
38-
* @param repo The initial repository to search in.
39+
* @param project The initial repository to search in.
3940
*/
4041
class TryFoxViewModel(
4142
private val fenixRepository: IFenixRepository,
4243
private val downloadFileRepository: DownloadFileRepository,
4344
private val cacheManager: CacheManager,
45+
private val intentManager: IntentManager,
46+
project: String?,
4447
revision: String?,
45-
repo: String?,
4648
) : ViewModel() {
4749
var revision by mutableStateOf(revision ?: "")
4850
private set
4951

50-
var selectedProject by mutableStateOf(repo ?: "try")
52+
var selectedProject by mutableStateOf(project ?: "try")
5153
private set
5254

5355
var relevantPushComment by mutableStateOf<String?>(null)
@@ -78,6 +80,10 @@ class TryFoxViewModel(
7880
private val deviceSupportedAbis: List<String> by lazy { Build.SUPPORTED_ABIS.toList() }
7981

8082
init {
83+
Log.d("TryFoxViewModel", "TryFoxViewModel created with revision: $revision, repo: $project")
84+
if (revision != null) {
85+
searchJobsAndArtifacts()
86+
}
8187
cacheManager.cacheState.onEach { state ->
8288
if (state is CacheManagementState.IdleEmpty) {
8389
// Reset download states for artifacts in this ViewModel
@@ -369,4 +375,8 @@ class TryFoxViewModel(
369375
}
370376
checkAndUpdateDownloadingStatus()
371377
}
378+
379+
fun installApk(file: File) {
380+
intentManager.installApk(file)
381+
}
372382
}

app/src/main/java/org/mozilla/tryfox/di/AppModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ val viewModelModule = module {
151151
get(),
152152
get(),
153153
get(),
154+
get(),
154155
params.getOrNull(),
155156
params.getOrNull(),
156157
)

app/src/main/java/org/mozilla/tryfox/ui/composables/AppCard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,6 @@ private fun DisplayArtifactCard(
175175
onDownloadClick = {
176176
viewModel.downloadArtifact(artifact)
177177
},
178-
onInstallClick = { viewModel.onInstallApk?.invoke(it) },
178+
onInstallClick = { viewModel.installApk(it) },
179179
)
180180
}

0 commit comments

Comments
 (0)