Skip to content

Commit

Permalink
Dhizuku v2.1
Browse files Browse the repository at this point in the history
MD3 Request Permission Dialog
  • Loading branch information
iamr0s committed May 4, 2023
1 parent 4c55006 commit a765924
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 240 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
applicationId = "com.rosan.dhizuku"
minSdk = 21
targetSdk = 33
versionCode = 3
versionName = "2.0"
versionCode = 4
versionName = "2.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@

<activity
android:name=".ui.activity.RequestPermissionActivity"
android:excludeFromRecents="false"
android:excludeFromRecents="true"
android:exported="true"
android:launchMode="singleInstance"
android:permission="com.rosan.dhizuku.permission.API"
android:theme="@style/Theme.Dhizuku.Translucent">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@ package com.rosan.dhizuku.ui.activity

import android.content.pm.PackageManager
import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.view.Gravity
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding
import androidx.compose.material.Text
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.TextButton
import androidx.compose.foundation.layout.size
import androidx.compose.material3.AlertDialogDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.text.HtmlCompat
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.rosan.dhizuku.R
import com.rosan.dhizuku.aidl.IDhizukuRequestPermissionListener
import com.rosan.dhizuku.data.settings.model.room.entity.AppEntity
import com.rosan.dhizuku.data.settings.repo.AppRepo
import com.rosan.dhizuku.shared.DhizukuVariables
import com.rosan.dhizuku.ui.theme.InstallerTheme
import com.rosan.dhizuku.ui.widget.dialog.DialogButton
import com.rosan.dhizuku.ui.widget.dialog.DialogButtons
import com.rosan.dhizuku.ui.widget.dialog.PositionDialog
import com.rosan.dhizuku.util.toast
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -77,38 +87,44 @@ class RequestPermissionActivity : ComponentActivity(), KoinComponent {
.fillMaxSize()
.imePadding()
) {
AlertDialog(onDismissRequest = {
PositionDialog(onDismissRequest = {
finish()
}, icon = {
}, centerIcon = {
Image(
painter = rememberDrawablePainter(drawable = icon),
contentDescription = null
contentDescription = null,
modifier = Modifier.size(32.dp)
)
}, title = {
Text(text = stringResource(id = R.string.request_permission_title))
}, text = {
Text(
text = stringResource(
id = R.string.request_permission_text,
label
}, centerTitle = {
val textSize = MaterialTheme.typography.titleLarge.fontSize.value
val textColor = AlertDialogDefaults.textContentColor.toArgb()
AndroidView(factory = {
val view = TextView(it)
view.movementMethod = LinkMovementMethod.getInstance()
view.setTextColor(textColor)
view.textSize = textSize
view.gravity = Gravity.CENTER
view.text = HtmlCompat.fromHtml(
it.getString(R.string.request_permission_text, label),
HtmlCompat.FROM_HTML_MODE_COMPACT
)
return@AndroidView view
})
}, centerButton = {
DialogButtons(
listOf(
DialogButton(stringResource(R.string.agree)) {
grantResult = PackageManager.PERMISSION_GRANTED
updateAppEntity()
finish()
},
DialogButton(stringResource(R.string.refuse)) {
grantResult = PackageManager.PERMISSION_DENIED
updateAppEntity()
finish()
}
)
)
}, confirmButton = {
TextButton(onClick = {
grantResult = PackageManager.PERMISSION_GRANTED
updateAppEntity()
finish()
}) {
Text(text = stringResource(id = R.string.agree))
}
}, dismissButton = {
TextButton(onClick = {
grantResult = PackageManager.PERMISSION_DENIED
updateAppEntity()
finish()
}) {
Text(text = stringResource(id = R.string.refuse))
}
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding
import androidx.compose.material.AlertDialog
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.hjq.permissions.Permission
Expand Down
177 changes: 0 additions & 177 deletions app/src/main/java/com/rosan/dhizuku/ui/widget/dialog/AlertDialog.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.rosan.dhizuku.ui.widget.dialog

data class DialogButton(
val text: String,
val onClick: () -> Unit
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.rosan.dhizuku.ui.widget.dialog

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun DialogButtons(
buttons: List<DialogButton>
) {
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
buttons.forEachIndexed { index, button ->
val specialCornerSize = CornerSize(12.dp)
val shape = RoundedCornerShape(4.dp).let {
if (index != 0) it
else it.copy(topStart = specialCornerSize, topEnd = specialCornerSize)
}.let {
if (index + 1 != buttons.size) it
else it.copy(bottomStart = specialCornerSize, bottomEnd = specialCornerSize)
}
TextButton(
button.onClick,
modifier = Modifier.fillMaxWidth(),
shape = shape,
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
),
contentPadding = PaddingValues(16.dp)
) {
Text(button.text)
}
}
}
}
Loading

0 comments on commit a765924

Please sign in to comment.