-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
19 changed files
with
390 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
org.gradle.daemon=false | ||
org.gradle.parallel=true | ||
org.gradle.workers.max=2 | ||
|
||
kotlin.incremental=false | ||
|
||
# Controls KotlinOptions.allWarningsAsErrors. | ||
# This value used in CI and is currently set to false. | ||
# If you want to treat warnings as errors locally, set this property to true | ||
# in your ~/.gradle/gradle.properties file. | ||
warningsAsErrors=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Api Binary Check | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
|
||
concurrency: | ||
group: build-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
api-check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
cache: gradle | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Validate binary api | ||
run: ./gradlew clean apiCheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 13 additions & 104 deletions
117
app/src/main/java/com/farsitel/bazaar/bazaarupdaterSample/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,46 @@ | ||
package com.farsitel.bazaar.bazaarupdaterSample | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.farsitel.bazaar.bazaarupdaterSample.ui.theme.BazaarupdaterSampleTheme | ||
import com.farsitel.bazaar.bazaarupdaterSample.ui.theme.BazaarUpdaterSampleTheme | ||
import com.farsitel.bazaar.updater.BazaarUpdater | ||
import com.farsitel.bazaar.updater.UpdateResult | ||
|
||
class MainActivity : ComponentActivity() { | ||
|
||
private val updateState = mutableStateOf<UpdateResult?>(null) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
enableEdgeToEdge() | ||
setContent { | ||
BazaarupdaterSampleTheme { | ||
BazaarUpdaterSampleTheme { | ||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> | ||
UpdateScreen( | ||
modifier = Modifier.padding(innerPadding) | ||
updateState = updateState, | ||
modifier = Modifier.padding(innerPadding), | ||
onUpdateClick = ::updateApplication, | ||
onCheckVersionClick = ::checkUpdateState, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun UpdateScreen( | ||
modifier: Modifier = Modifier | ||
) { | ||
val updateState = remember { mutableStateOf<UpdateResult?>(null) } | ||
val context = LocalContext.current | ||
fun onResult(result: UpdateResult) { | ||
updateState.value = result | ||
private fun updateApplication() { | ||
BazaarUpdater.updateApplication(context = this) | ||
} | ||
Box( | ||
modifier = modifier.fillMaxSize(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
when (val state = updateState.value) { | ||
UpdateResult.AlreadyUpdated -> AlreadyUpdatedView() | ||
is UpdateResult.Error -> ErrorView(message = state.throwable.message.orEmpty()) | ||
is UpdateResult.NeedUpdate -> NeedUpdateView( | ||
targetVersion = state.targetVersion, | ||
onResult = { | ||
BazaarUpdater.updateApplication(context = context) | ||
} | ||
) | ||
|
||
null -> CheckUpdateStateView(context = LocalContext.current, onResult = ::onResult) | ||
private fun checkUpdateState() { | ||
BazaarUpdater.getLastUpdateState(context = this) { result -> | ||
updateState.value = result | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun AlreadyUpdatedView(modifier: Modifier = Modifier) { | ||
Text(modifier = modifier, text = stringResource(R.string.your_application_is_updated)) | ||
} | ||
|
||
@Composable | ||
private fun ErrorView(message: String, modifier: Modifier = Modifier) { | ||
Column { | ||
Text(modifier = modifier, text = message) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun NeedUpdateView( | ||
targetVersion: Long, | ||
modifier: Modifier = Modifier, | ||
onResult: (UpdateResult) -> Unit = {} | ||
) { | ||
UpdateButton( | ||
context = LocalContext.current, | ||
text = stringResource(R.string.there_is_new_update_version, targetVersion), | ||
modifier = modifier, | ||
onResult = onResult, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun UpdateButton( | ||
context: Context, | ||
text: String, | ||
modifier: Modifier = Modifier, | ||
onResult: (UpdateResult) -> Unit = {} | ||
) { | ||
Button( | ||
modifier = modifier, | ||
onClick = { | ||
checkUpdateState( | ||
context = context, | ||
onResult = onResult | ||
) | ||
} | ||
) { | ||
Text(text = text) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun CheckUpdateStateView(context: Context, onResult: (UpdateResult) -> Unit) { | ||
UpdateButton( | ||
context = context, | ||
onResult = onResult, | ||
text = stringResource(R.string.check_update) | ||
) | ||
} | ||
|
||
private fun checkUpdateState(context: Context, onResult: (UpdateResult) -> Unit) { | ||
BazaarUpdater.getLastUpdateState(context = context, onResult = onResult) | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun UpdateScreenPreview() { | ||
BazaarupdaterSampleTheme { | ||
UpdateScreen() | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
app/src/main/java/com/farsitel/bazaar/bazaarupdaterSample/UpdateScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.farsitel.bazaar.bazaarupdaterSample | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.farsitel.bazaar.bazaarupdaterSample.ui.theme.BazaarUpdaterSampleTheme | ||
import com.farsitel.bazaar.updater.UpdateResult | ||
|
||
@Composable | ||
fun UpdateScreen( | ||
updateState: State<UpdateResult?>, | ||
modifier: Modifier = Modifier, | ||
onUpdateClick: () -> Unit = {}, | ||
onCheckVersionClick: () -> Unit = {}, | ||
) { | ||
Box( | ||
modifier = modifier.fillMaxSize(), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
when (val state = updateState.value) { | ||
UpdateResult.AlreadyUpdated -> { | ||
AlreadyUpdatedView() | ||
} | ||
is UpdateResult.Error -> { | ||
ErrorView( | ||
message = state.throwable.message.orEmpty(), | ||
) | ||
} | ||
is UpdateResult.NeedUpdate -> { | ||
NeedUpdateView( | ||
targetVersion = state.getTargetVersionCode(), | ||
onClick = onUpdateClick, | ||
) | ||
} | ||
else -> { | ||
CheckUpdateStateView( | ||
onClick = onCheckVersionClick, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun AlreadyUpdatedView( | ||
modifier: Modifier = Modifier, | ||
) { | ||
Text( | ||
modifier = modifier, | ||
text = stringResource(R.string.your_application_is_updated), | ||
) | ||
} | ||
|
||
@Composable | ||
private fun ErrorView( | ||
message: String, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Text( | ||
modifier = modifier, | ||
text = message, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun NeedUpdateView( | ||
targetVersion: Long, | ||
modifier: Modifier = Modifier, | ||
onClick: () -> Unit = {}, | ||
) { | ||
UpdateButton( | ||
text = stringResource(R.string.there_is_new_update_version, targetVersion), | ||
modifier = modifier, | ||
onClick = onClick, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun CheckUpdateStateView( | ||
modifier: Modifier = Modifier, | ||
onClick: () -> Unit = {}, | ||
) { | ||
UpdateButton( | ||
text = stringResource(R.string.check_update), | ||
modifier = modifier, | ||
onClick = onClick, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun UpdateButton( | ||
text: String, | ||
modifier: Modifier = Modifier, | ||
onClick: () -> Unit = {}, | ||
) { | ||
Button( | ||
modifier = modifier, | ||
onClick = onClick, | ||
) { | ||
Text(text = text) | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
private fun UpdateScreenPreview() { | ||
BazaarUpdaterSampleTheme { | ||
UpdateScreen( | ||
updateState = remember { | ||
mutableStateOf(null) | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.