Skip to content

Commit e760b95

Browse files
authored
Add GitHub repository link beside app version (#83)
1 parent 21d045a commit e760b95

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

‎app/src/main/java/net/megaproxy487/MainActivity.kt‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package net.megaproxy487
22

33
import android.Manifest
44
import android.app.Activity
5+
import android.content.ActivityNotFoundException
56
import android.content.Intent
67
import android.content.pm.PackageManager
8+
import android.net.Uri
79
import android.net.VpnService
810
import android.os.Build
911
import android.os.Bundle
@@ -23,6 +25,8 @@ import androidx.compose.foundation.layout.BoxWithConstraints
2325
import androidx.compose.foundation.layout.heightIn
2426
import androidx.compose.ui.platform.LocalDensity
2527
import androidx.compose.foundation.layout.Column
28+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
29+
import androidx.compose.foundation.layout.FlowRow
2630
import androidx.compose.foundation.layout.Row
2731
import androidx.compose.foundation.layout.Spacer
2832
import androidx.compose.foundation.layout.fillMaxSize
@@ -235,7 +239,7 @@ private fun ProfileSelectorLabel(
235239
}
236240
}
237241

238-
@OptIn(ExperimentalMaterial3Api::class)
242+
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
239243
@Composable
240244
internal fun MainScreen(
241245
activity: Activity,
@@ -667,12 +671,27 @@ internal fun MainScreen(
667671
connectionStats?.let { stats ->
668672
ConnectionStatsCard(stats, quic = transportProtocol == VpnTransportProtocol.HTTP_3)
669673
}
670-
Text(
671-
stringResource(R.string.version_and_commit, BuildConfig.VERSION_NAME, BuildConfig.GIT_COMMIT_HASH),
672-
style = MaterialTheme.typography.bodySmall,
673-
color = MaterialTheme.colorScheme.onSurfaceVariant,
674-
modifier = Modifier.align(Alignment.CenterHorizontally).padding(top = 8.dp),
675-
)
674+
FlowRow(
675+
horizontalArrangement = Arrangement.Center,
676+
modifier = Modifier.fillMaxWidth().padding(top = 8.dp),
677+
) {
678+
Text(
679+
stringResource(R.string.version_and_commit, BuildConfig.VERSION_NAME, BuildConfig.GIT_COMMIT_HASH),
680+
style = MaterialTheme.typography.bodySmall,
681+
color = MaterialTheme.colorScheme.onSurfaceVariant,
682+
modifier = Modifier.align(Alignment.CenterVertically),
683+
)
684+
TextButton(onClick = {
685+
try {
686+
activity.startActivity(Intent(Intent.ACTION_VIEW,
687+
Uri.parse("https://github.com/andre487/AndroidMegaProxy")))
688+
} catch (_: ActivityNotFoundException) {
689+
error = activity.uiText(R.string.no_browser)
690+
}
691+
}) {
692+
Text(stringResource(R.string.update_github), style = MaterialTheme.typography.bodySmall)
693+
}
694+
}
676695
}
677696
}
678697
}

‎app/src/test/java/net/megaproxy487/MainScreenUiTest.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ class MainScreenUiTest : MainUiTestBase() {
3030
assertNull(shadowOf(activity.application as Application).nextStartedService)
3131
}
3232

33+
@Test fun githubLinkNextToVersionOpensApplicationRepository() {
34+
screen()
35+
compose.onNodeWithText(activity.getString(R.string.version_and_commit,
36+
BuildConfig.VERSION_NAME, BuildConfig.GIT_COMMIT_HASH)).performScrollTo().assertIsDisplayed()
37+
node(R.string.update_github).performScrollTo().assertIsDisplayed().performClick()
38+
val intent = shadowOf(activity).nextStartedActivity
39+
assertEquals(Intent.ACTION_VIEW, intent?.action)
40+
assertEquals("https://github.com/andre487/AndroidMegaProxy", intent?.dataString)
41+
noCommand()
42+
}
43+
3344
@Test fun connectDispatchesStartAndPersistsDesiredState() {
3445
screen()
3546
node(R.string.connect).performScrollTo().assertIsEnabled().performClick()

0 commit comments

Comments
 (0)