-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from SuddenH4X/release/2.5.0
Release/2.5.0
- Loading branch information
Showing
17 changed files
with
346 additions
and
136 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
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
22 changes: 0 additions & 22 deletions
22
...app/src/androidTest/java/com/suddenh4x/ratingdialog/exampleapp/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
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
115 changes: 115 additions & 0 deletions
115
exampleapp/src/main/java/com/suddenh4x/ratingdialog/exampleapp/JetpackComposeActivity.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,115 @@ | ||
package com.suddenh4x.ratingdialog.exampleapp | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.SnackbarHost | ||
import androidx.compose.material.SnackbarHostState | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.google.android.material.composethemeadapter.MdcTheme | ||
import com.suddenh4x.ratingdialog.AppRating | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
class JetpackComposeActivity : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_jetpack_compose) | ||
AppRating.reset(this) | ||
|
||
val composeView = findViewById<ComposeView>(R.id.ComposeView) | ||
composeView.setContent { | ||
val snackbarHostState = remember { SnackbarHostState() } | ||
|
||
MdcTheme { | ||
Scaffold( | ||
snackbarHost = { SnackbarHost(snackbarHostState) }, | ||
topBar = { JetpackComposeExampleTopAppBar() }, | ||
) { paddingValues -> | ||
JetpackComposeExample(paddingValues, snackbarHostState) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun JetpackComposeExampleTopAppBar() { | ||
TopAppBar( | ||
title = { Text("Jetpack Compose Example") }, | ||
) | ||
} | ||
|
||
@Composable | ||
fun JetpackComposeExample(paddingValues: PaddingValues, snackbarHostState: SnackbarHostState) { | ||
val coroutineScope = rememberCoroutineScope() | ||
|
||
Column( | ||
modifier = Modifier | ||
.padding(paddingValues) | ||
.padding(16.dp) | ||
.fillMaxSize(), | ||
) { | ||
Text( | ||
text = "This is a Jetpack Compose example with a ComponentActivity. So the button below only " + | ||
"starts the Google in-app review. If you want to use the libraries dialog with Jetpack Compose " + | ||
"your activity has to extend from FragmentActivity (e.g. ComponentActivity).", | ||
) | ||
Button( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 20.dp), | ||
onClick = { openGoogleInAppReview(coroutineScope, snackbarHostState) }, | ||
) { | ||
Text(text = "Jetpack Compose Example") | ||
} | ||
} | ||
} | ||
|
||
private fun openGoogleInAppReview( | ||
coroutineScope: CoroutineScope, | ||
snackbarHostState: SnackbarHostState | ||
) { | ||
AppRating.Builder(this@JetpackComposeActivity) | ||
.useGoogleInAppReview() | ||
.setGoogleInAppReviewCompleteListener { successful -> | ||
showSnackbar(coroutineScope, snackbarHostState, successful) | ||
} | ||
.setDebug(true) | ||
.showIfMeetsConditions() | ||
} | ||
|
||
private fun showSnackbar( | ||
coroutineScope: CoroutineScope, | ||
snackbarHostState: SnackbarHostState, | ||
successful: Boolean | ||
) { | ||
coroutineScope.launch { | ||
snackbarHostState.showSnackbar( | ||
"Google in-app review completed " + | ||
"(successful: $successful)", | ||
) | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun JetpackComposeExamplePreview() { | ||
val snackbarHostState = remember { SnackbarHostState() } | ||
JetpackComposeExample(PaddingValues(), snackbarHostState) | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
exampleapp/src/main/res/layout/activity_jetpack_compose.xml
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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context=".JetpackComposeActivity"> | ||
|
||
<androidx.compose.ui.platform.ComposeView | ||
android:id="@+id/ComposeView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> | ||
|
||
</LinearLayout> |
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
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.