Skip to content

Commit

Permalink
Added GHA aab (#40)
Browse files Browse the repository at this point in the history
* Added GHA aab

* Enlarged firestore README.md images

* Added token

* Added permission

* Added if

* Added snackbar for invalid link

* Okay
  • Loading branch information
JackEblan authored Aug 29, 2024
1 parent 996b5f2 commit 6c8f5aa
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 36 deletions.
46 changes: 25 additions & 21 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 120

permissions:
contents: write

steps:
- name: Enable KVM group perms
run: |
Expand Down Expand Up @@ -50,7 +53,7 @@ jobs:
echo $DATA > /home/runner/work/SocialWorkReviewer/SocialWorkReviewer/app/google-services.json
- name: Build release variant including baseline profile generation
run: ./gradlew :app:assembleRelease
run: ./gradlew :app:assembleRelease :app:bundleRelease
-Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile
-Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect"
-Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true
Expand All @@ -69,26 +72,27 @@ jobs:
env:
BUILD_TOOLS_VERSION: "34.0.0"

- name: Rename signed APK
run: mv ${{steps.sign_release_apk.outputs.signedReleaseFile}} app/build/outputs/apk/release/geto-${{ github.ref_name }}.apk

- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Sign release AAB
uses: r0adkll/sign-android-release@v1
id: sign_release_aab
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false

- name: Upload release asset
uses: actions/upload-release-asset@v1
releaseDirectory: app/build/outputs/bundle/release
signingKeyBase64: ${{ secrets.SIGNING_KEY_BASE64 }}
alias: ${{ secrets.SIGNING_KEY_ALIAS }}
keyStorePassword: ${{ secrets.SIGNING_KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_TOOLS_VERSION: "34.0.0"

- name: Rename signed Files
run: |
mv ${{steps.sign_release_apk.outputs.signedReleaseFile}} app/build/outputs/apk/release/swr-${{ github.ref_name }}.apk
mv ${{steps.sign_release_aab.outputs.signedReleaseFile}} app/build/outputs/bundle/release/swr-${{ github.ref_name }}.aab
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/build/outputs/apk/release/geto-${{ github.ref_name }}.apk
asset_name: geto-${{ github.ref_name }}.apk
asset_content_type: application/vnd.android.package-archive
files: |
app/build/outputs/apk/release/swr-${{ github.ref_name }}.apk
app/build/outputs/bundle/release/swr-${{ github.ref_name }}.aab
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ from [Now in Android](https://github.com/android/nowinandroid). **The developmen
Refer to the images below to see how the database is structured.
<div style="width:100%; display:flex; justify-content:space-between;">

[<img src="docs/images/6.jpg" width=19% alt="6">](docs/images/6.jpg)
[<img src="docs/images/7.jpg" width=19% alt="7">](docs/images/7.jpg)
[<img src="docs/images/8.jpg" width=19% alt="8">](docs/images/8.jpg)
[<img src="docs/images/6.jpg" width=50% alt="6">](docs/images/6.jpg)
[<img src="docs/images/7.jpg" width=50% alt="7">](docs/images/7.jpg)
[<img src="docs/images/8.jpg" width=50% alt="8">](docs/images/8.jpg)
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
*/
package com.eblan.socialworkreviewer.navigation

import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
Expand All @@ -34,11 +37,18 @@ import com.eblan.socialworkreviewer.feature.question.navigation.navigateToQuesti
import com.eblan.socialworkreviewer.feature.question.navigation.questionScreen
import com.eblan.socialworkreviewer.feature.settings.navigation.navigateToSettings
import com.eblan.socialworkreviewer.feature.settings.navigation.settingsScreen
import kotlinx.coroutines.launch

@Composable
fun SwrNavHost(modifier: Modifier = Modifier) {
val swrNavHostController = rememberNavController()

val snackbarHostState = remember {
SnackbarHostState()
}

val scope = rememberCoroutineScope()

val topLevelDestinations = listOf(
CategoryDestination(),
AnnouncementDestination(),
Expand All @@ -52,6 +62,7 @@ fun SwrNavHost(modifier: Modifier = Modifier) {
startDestination = HomeRouteData::class,
) {
homeScreen(
snackbarHostState = snackbarHostState,
topLevelDestinations = topLevelDestinations,
startDestination = CategoryRouteData::class,
onItemClick = { homeNavHostController, homeDestination ->
Expand All @@ -69,7 +80,13 @@ fun SwrNavHost(modifier: Modifier = Modifier) {

settingsScreen()

aboutScreen()
aboutScreen(
onShowSnackBar = { message ->
scope.launch {
snackbarHostState.showSnackbar(message = message)
}
},
)
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ package com.eblan.socialworkreviewer.core.testing.linkparser

import com.eblan.socialworkreviewer.framework.linkparser.LinkParser

class DummyLinkParser : LinkParser {
override fun openLink(url: String) {
class FakeLinkParser : LinkParser {
private var _openLink = false

override fun openLink(url: String): Boolean {
return _openLink
}

fun setOpenLInk(value: Boolean) {
_openLink = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -71,9 +72,19 @@ import com.eblan.socialworkreviewer.core.model.About
internal fun AboutRoute(
modifier: Modifier = Modifier,
viewModel: AboutViewModel = hiltViewModel(),
onShowSnackBar: (String) -> Unit,
) {
val aboutUiState = viewModel.aboutUiState.collectAsStateWithLifecycle().value

val openLinkResult = viewModel.openLinkResult.collectAsStateWithLifecycle().value

LaunchedEffect(key1 = openLinkResult) {
if (openLinkResult != null && openLinkResult.not()) {
onShowSnackBar("Invalid link")
viewModel.resetOpenLinkResult()
}
}

AboutScreen(modifier = modifier, aboutUiState = aboutUiState, onLinkCLick = viewModel::openLink)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ import androidx.lifecycle.viewModelScope
import com.eblan.socialworkreviewer.core.data.repository.AboutRepository
import com.eblan.socialworkreviewer.framework.linkparser.LinkParser
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import javax.inject.Inject

@HiltViewModel
Expand All @@ -38,7 +41,18 @@ class AboutViewModel @Inject constructor(
initialValue = AboutUiState.Loading,
)

private val _openLinkResult = MutableStateFlow<Boolean?>(null)
val openLinkResult = _openLinkResult.asStateFlow()

fun openLink(url: String) {
linkParser.openLink(url = url)
_openLinkResult.update {
linkParser.openLink(url = url)
}
}

fun resetOpenLinkResult() {
_openLinkResult.update {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ fun NavController.navigateToAboutScreen() {
}
}

fun NavGraphBuilder.aboutScreen() {
fun NavGraphBuilder.aboutScreen(onShowSnackBar: (String) -> Unit) {
composable<AboutRouteData> {
AboutRoute()
AboutRoute(onShowSnackBar = onShowSnackBar)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.eblan.socialworkreviewer.feature.about

import com.eblan.socialworkreviewer.core.model.About
import com.eblan.socialworkreviewer.core.testing.linkparser.DummyLinkParser
import com.eblan.socialworkreviewer.core.testing.linkparser.FakeLinkParser
import com.eblan.socialworkreviewer.core.testing.repository.FakeAboutRepository
import com.eblan.socialworkreviewer.core.testing.util.MainDispatcherRule
import kotlinx.coroutines.flow.collect
Expand All @@ -28,23 +28,25 @@ import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertIs
import kotlin.test.assertTrue

class AboutViewModelTest {
@get:Rule
val mainDispatcherRule = MainDispatcherRule()

private lateinit var aboutRepository: FakeAboutRepository

private lateinit var linkParser: DummyLinkParser
private lateinit var linkParser: FakeLinkParser

private lateinit var viewModel: AboutViewModel

@Before
fun setup() {
aboutRepository = FakeAboutRepository()

linkParser = DummyLinkParser()
linkParser = FakeLinkParser()

viewModel = AboutViewModel(aboutRepository = aboutRepository, linkParser = linkParser)
}
Expand Down Expand Up @@ -75,4 +77,22 @@ class AboutViewModelTest {

collectJob.cancel()
}

@Test
fun openLink_isTrue() = runTest {
linkParser.setOpenLInk(true)

viewModel.openLink("")

assertTrue(viewModel.openLinkResult.value!!)
}

@Test
fun openLink_isFalse() = runTest {
linkParser.setOpenLInk(false)

viewModel.openLink("")

assertFalse(viewModel.openLinkResult.value!!)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults.enterAlwaysScrollBehavior
import androidx.compose.material3.TopAppBarScrollBehavior
Expand All @@ -50,6 +52,7 @@ import kotlin.reflect.KClass
@Composable
internal fun HomeScreen(
modifier: Modifier = Modifier,
snackbarHostState: SnackbarHostState,
navController: NavHostController = rememberNavController(),
topLevelDestinations: List<HomeDestination>,
startDestination: KClass<*>,
Expand Down Expand Up @@ -90,6 +93,9 @@ internal fun HomeScreen(
topAppBarScrollBehavior = topAppBarScrollBehavior,
)
},
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
},
) { paddingValues ->
NavHost(
modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@
*/
package com.eblan.socialworkreviewer.feature.home.navigation

import androidx.compose.material3.SnackbarHostState
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import com.eblan.socialworkreviewer.feature.home.HomeScreen
import kotlin.reflect.KClass

fun NavGraphBuilder.homeScreen(
snackbarHostState: SnackbarHostState,
topLevelDestinations: List<HomeDestination>,
startDestination: KClass<*>,
onItemClick: (NavHostController, HomeDestination) -> Unit,
builder: NavGraphBuilder.() -> Unit,
) {
composable<HomeRouteData> {
HomeScreen(
snackbarHostState = snackbarHostState,
topLevelDestinations = topLevelDestinations,
startDestination = startDestination,
onItemClick = onItemClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.eblan.socialworkreviewer.framework.linkparser

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
Expand All @@ -26,13 +27,18 @@ import javax.inject.Inject

internal class DefaultLinkParser @Inject constructor(@ApplicationContext private val context: Context) :
LinkParser {
override fun openLink(url: String) {
override fun openLink(url: String): Boolean {
val intent = Intent().apply {
action = Intent.ACTION_VIEW
data = Uri.parse(url)
flags = FLAG_ACTIVITY_NEW_TASK
}

context.startActivity(intent)
return try {
context.startActivity(intent)
true
} catch (_: ActivityNotFoundException) {
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
package com.eblan.socialworkreviewer.framework.linkparser

interface LinkParser {
fun openLink(url: String)
fun openLink(url: String): Boolean
}

0 comments on commit 6c8f5aa

Please sign in to comment.