mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add logout dialog and static terms/privacy page embeds
This commit is contained in:
parent
872b8cf722
commit
1f15392b05
5 changed files with 142 additions and 43 deletions
|
|
@ -3,4 +3,7 @@ package app.omnivore.omnivore
|
|||
sealed class Routes(val route: String) {
|
||||
object Library : Routes("Library")
|
||||
object Settings: Routes("Settings")
|
||||
object Documentation: Routes("Documentation")
|
||||
object PrivacyPolicy: Routes("PrivacyPolicy")
|
||||
object TermsAndConditions: Routes("TermsAndConditions")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import app.omnivore.omnivore.ui.auth.LoginViewModel
|
|||
import app.omnivore.omnivore.ui.auth.WelcomeScreen
|
||||
import app.omnivore.omnivore.ui.library.LibraryView
|
||||
import app.omnivore.omnivore.ui.library.LibraryViewModel
|
||||
import app.omnivore.omnivore.ui.settings.PolicyWebView
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
|
||||
@Composable
|
||||
|
|
@ -78,5 +79,17 @@ fun PrimaryNavigator(
|
|||
composable(Routes.Settings.route) {
|
||||
SettingsView(loginViewModel = loginViewModel, navController = navController)
|
||||
}
|
||||
|
||||
composable(Routes.Documentation.route) {
|
||||
PolicyWebView(navController = navController, url = "https://docs.omnivore.app")
|
||||
}
|
||||
|
||||
composable(Routes.PrivacyPolicy.route) {
|
||||
PolicyWebView(navController = navController, url = "https://omnivore.app/app/privacy")
|
||||
}
|
||||
|
||||
composable(Routes.TermsAndConditions.route) {
|
||||
PolicyWebView(navController = navController, url = "https://omnivore.app/app/terms")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package app.omnivore.omnivore.ui.settings
|
||||
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignIn
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
|
||||
|
||||
@Composable
|
||||
fun LogoutDialog(onClose: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = { onClose(false) },
|
||||
title = { Text(text = "Logout") },
|
||||
text = {
|
||||
Text("Are you sure you want to logout?")
|
||||
},
|
||||
confirmButton = {
|
||||
Button(onClick = {
|
||||
// Sign out google users
|
||||
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
|
||||
.build()
|
||||
|
||||
val googleSignIn = GoogleSignIn.getClient(context, signInOptions)
|
||||
googleSignIn.signOut()
|
||||
onClose(true)
|
||||
}) {
|
||||
Text("Confirm")
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
Button(onClick = { onClose(false) }) {
|
||||
Text("Cancel")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package app.omnivore.omnivore.ui.settings
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.navigation.NavHostController
|
||||
import app.omnivore.omnivore.Routes
|
||||
|
||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter", "SetJavaScriptEnabled")
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PolicyWebView(navController: NavHostController, url: String) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { androidx.compose.material3.Text("Settings") },
|
||||
actions = {
|
||||
IconButton(onClick = { navController.navigate(Routes.Settings.route) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Home,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
}, colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
||||
)
|
||||
)
|
||||
}
|
||||
) {
|
||||
val isDarkMode = isSystemInDarkTheme()
|
||||
|
||||
Box {
|
||||
AndroidView(factory = {
|
||||
WebView(it).apply {
|
||||
if (isDarkMode) {
|
||||
setBackgroundColor(Color.Transparent.hashCode())
|
||||
}
|
||||
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
|
||||
settings.javaScriptEnabled = true
|
||||
settings.allowContentAccess = true
|
||||
settings.allowFileAccess = true
|
||||
settings.domStorageEnabled = true
|
||||
|
||||
alpha = 0.0f
|
||||
|
||||
webViewClient = object : WebViewClient() {
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
super.onPageFinished(view, url)
|
||||
view?.animate()?.alpha(1.0f)?.duration = 200
|
||||
}
|
||||
}
|
||||
|
||||
loadUrl(url)
|
||||
}
|
||||
}, update = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ import androidx.compose.ui.unit.dp
|
|||
import androidx.navigation.NavHostController
|
||||
import app.omnivore.omnivore.Routes
|
||||
import app.omnivore.omnivore.ui.auth.LoginViewModel
|
||||
import app.omnivore.omnivore.ui.settings.LogoutDialog
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignIn
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
|
||||
import io.intercom.android.sdk.Intercom
|
||||
|
|
@ -49,6 +50,7 @@ fun SettingsView(
|
|||
) { paddingValues ->
|
||||
SettingsViewContent(
|
||||
loginViewModel = loginViewModel,
|
||||
navController = navController,
|
||||
modifier = Modifier
|
||||
.padding(
|
||||
top = paddingValues.calculateTopPadding(),
|
||||
|
|
@ -59,7 +61,7 @@ fun SettingsView(
|
|||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsViewContent(loginViewModel: LoginViewModel, modifier: Modifier) {
|
||||
fun SettingsViewContent(loginViewModel: LoginViewModel, navController: NavHostController, modifier: Modifier) {
|
||||
val showLogoutDialog = remember { mutableStateOf(false) }
|
||||
|
||||
Box(
|
||||
|
|
@ -82,24 +84,24 @@ fun SettingsViewContent(loginViewModel: LoginViewModel, modifier: Modifier) {
|
|||
SettingRow(text = "Emails") { Log.d("settings", "emails button tapped") }
|
||||
RowDivider()
|
||||
SettingRow(text = "Subscriptions") { Log.d("settings", "subscriptions button tapped") }
|
||||
RowDivider()
|
||||
SettingRow(text = "Clubs") { Log.d("settings", "clubs button tapped") }
|
||||
// RowDivider()
|
||||
// SettingRow(text = "Clubs") { Log.d("settings", "clubs button tapped") }
|
||||
|
||||
SectionSpacer()
|
||||
|
||||
SettingRow(text = "Push Notifications") { Log.d("settings", "pn button tapped") }
|
||||
RowDivider()
|
||||
SettingRow(text = "Text to Speech") { Log.d("settings", "tts button tapped") }
|
||||
// SettingRow(text = "Push Notifications") { Log.d("settings", "pn button tapped") }
|
||||
// RowDivider()
|
||||
// SettingRow(text = "Text to Speech") { Log.d("settings", "tts button tapped") }
|
||||
//
|
||||
// SectionSpacer()
|
||||
|
||||
SectionSpacer()
|
||||
|
||||
SettingRow(text = "Documentation") { Log.d("settings", "docs button tapped") }
|
||||
SettingRow(text = "Documentation") { navController.navigate(Routes.Documentation.route) }
|
||||
RowDivider()
|
||||
SettingRow(text = "Feedback") { Intercom.client().present(space = IntercomSpace.Messages) }
|
||||
RowDivider()
|
||||
SettingRow(text = "Privacy Policy") { Log.d("settings", "privacy button tapped") }
|
||||
SettingRow(text = "Privacy Policy") { navController.navigate(Routes.PrivacyPolicy.route) }
|
||||
RowDivider()
|
||||
SettingRow(text = "Terms and Conditions") { Log.d("settings", "t&c button tapped") }
|
||||
SettingRow(text = "Terms and Conditions") { navController.navigate(Routes.TermsAndConditions.route) }
|
||||
|
||||
SectionSpacer()
|
||||
|
||||
|
|
@ -120,38 +122,6 @@ fun SettingsViewContent(loginViewModel: LoginViewModel, modifier: Modifier) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun LogoutDialog(onClose: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = { onClose(false) },
|
||||
title = { Text(text = "Logout") },
|
||||
text = {
|
||||
Text("Are you sure you want to logout?")
|
||||
},
|
||||
confirmButton = {
|
||||
Button(onClick = {
|
||||
// Sign out google users
|
||||
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
|
||||
.build()
|
||||
|
||||
val googleSignIn = GoogleSignIn.getClient(context, signInOptions)
|
||||
googleSignIn.signOut()
|
||||
onClose(true)
|
||||
}) {
|
||||
Text("Confirm")
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
Button(onClick = { onClose(false) }) {
|
||||
Text("Cancel")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RowDivider() {
|
||||
Divider(
|
||||
|
|
|
|||
Loading…
Reference in a new issue