Skip to content

Commit

Permalink
fix(ProfileScreen): handle click events
Browse files Browse the repository at this point in the history
1. Donate button
2. Help button
3. Login card
  • Loading branch information
urFate committed Apr 22, 2024
1 parent 2695d38 commit 298922c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package live.shirabox.shirabox.ui.activity.settings.category
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
Expand All @@ -29,8 +28,8 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat.startActivity
import live.shirabox.core.util.Util
import live.shirabox.core.util.Util.Companion.openUri
import live.shirabox.shirabox.BuildConfig
import live.shirabox.shirabox.R

Expand Down Expand Up @@ -129,12 +128,4 @@ fun AboutSettingsScreen() {
}
}
}
}

private fun openUri(context: Context, uri: Uri) {
startActivity(
context,
Intent(Intent.ACTION_VIEW).setData(uri),
null
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package live.shirabox.shirabox.ui.screen.profile

import android.content.Intent
import android.net.Uri
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -13,7 +15,7 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
import androidx.compose.material.icons.automirrored.outlined.Login
import androidx.compose.material.icons.automirrored.rounded.Login
import androidx.compose.material.icons.filled.History
import androidx.compose.material.icons.outlined.Savings
import androidx.compose.material.icons.outlined.Settings
Expand All @@ -31,6 +33,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import live.shirabox.core.util.Util.Companion.openUri
import live.shirabox.shirabox.R
import live.shirabox.shirabox.ui.activity.settings.SettingsActivity
import live.shirabox.shirabox.ui.activity.update.AppUpdateActivity
Expand All @@ -40,6 +43,11 @@ import live.shirabox.shirabox.ui.theme.ShiraBoxTheme
@Composable
fun ProfileScreen(navController: NavController){
val context = LocalContext.current
val site = "https://www.shirabox.live"

val donationUri = Uri.parse("$site/donate")
val helpUri = Uri.parse("$site/faq")


ShiraBoxTheme {
Column(
Expand All @@ -48,16 +56,19 @@ fun ProfileScreen(navController: NavController){
OutlinedCard(
shape = RoundedCornerShape(10.dp),
modifier = Modifier
.fillMaxWidth(1f) // Set the desired width percentage
.fillMaxWidth(1f)
.padding(16.dp)
.height(72.dp)
.clickable {
Toast.makeText(context, "В разработке...", Toast.LENGTH_SHORT).show()
}
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(16.dp)
) {
Icon(
imageVector = Icons.AutoMirrored.Outlined.Login,
imageVector = Icons.AutoMirrored.Rounded.Login,
contentDescription = "Login Icon",
tint = MaterialTheme.colorScheme.onSurfaceVariant
)
Expand Down Expand Up @@ -94,7 +105,9 @@ fun ProfileScreen(navController: NavController){
)
ListItem(
headlineContent = { Text(stringResource(id = R.string.donate) ) },
modifier = Modifier.clickable { },
modifier = Modifier.clickable {
openUri(context, donationUri)
},
leadingContent = {
Icon(
Icons.Outlined.Savings,
Expand Down Expand Up @@ -135,7 +148,9 @@ fun ProfileScreen(navController: NavController){
)
ListItem(
headlineContent = { Text(stringResource(id = R.string.help)) },
modifier = Modifier.clickable { },
modifier = Modifier.clickable {
openUri(context, helpUri)
},
leadingContent = {
Icon(
Icons.AutoMirrored.Outlined.HelpOutline,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
Login Card
-->
<string name="unauthorized">Вход не выполнен</string>
<string name="unauthorized_suggestion">Войти в аккаунт TomuID</string>
<string name="unauthorized_suggestion">Войти в аккаунт ShiraBox</string>
<string name="title_activity_resource">ResourceActivity</string>

<!--
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/live/shirabox/core/util/Util.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package live.shirabox.core.util

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Build
import android.text.Html
import androidx.core.content.ContextCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
Expand Down Expand Up @@ -149,6 +152,14 @@ class Util {
return if (number < 9) number.toString() else "9+"
}

fun openUri(context: Context, uri: Uri) {
ContextCompat.startActivity(
context,
Intent(Intent.ACTION_VIEW).setData(uri),
null
)
}

inline fun <VM : ViewModel> viewModelFactory(crossinline f: () -> VM) =
object : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T = f() as T
Expand Down

0 comments on commit 298922c

Please sign in to comment.