Skip to content

Commit

Permalink
Updated the app to AppCompat
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai-Cristian Condrea committed Jun 2, 2024
1 parent f75d276 commit d8f79b8
Show file tree
Hide file tree
Showing 28 changed files with 693 additions and 434 deletions.
3 changes: 1 addition & 2 deletions app/src/main/kotlin/com/d4rk/cleaner/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.d4rk.cleaner

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -17,7 +16,7 @@ import com.android.volley.TimeoutError
import com.d4rk.cleaner.data.store.DataStore
import com.d4rk.cleaner.notifications.managers.AppUpdateNotificationsManager
import com.d4rk.cleaner.notifications.managers.AppUsageNotificationsManager
import com.d4rk.cleaner.ui.settings.display.theme.AppTheme
import com.d4rk.cleaner.ui.settings.display.theme.style.AppTheme
import com.d4rk.cleaner.ui.startup.StartupActivity
import com.google.android.gms.ads.MobileAds
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.d4rk.cleaner.dialogs

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.Language
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
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.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.d4rk.cleaner.R
import com.d4rk.cleaner.data.store.DataStore
import kotlinx.coroutines.flow.firstOrNull

@Composable
fun LanguageDialog(
dataStore: DataStore , onDismiss: () -> Unit , onLanguageSelected: (String) -> Unit
) {
val selectedLanguage = remember { mutableStateOf("") }
val languageEntries = stringArrayResource(R.array.preference_language_entries).toList()
val languageValues = stringArrayResource(R.array.preference_language_values).toList()

AlertDialog(onDismissRequest = onDismiss, text = {
LanguageDialogContent(
selectedLanguage, dataStore, languageEntries, languageValues
)
}, icon = {
Icon(Icons.Outlined.Language, contentDescription = null)
}, confirmButton = {
TextButton(onClick = {
onLanguageSelected(selectedLanguage.value)
onDismiss()
}) {
Text(stringResource(android.R.string.ok))
}
}, dismissButton = {
TextButton(onClick = onDismiss) {
Text(stringResource(android.R.string.cancel))
}
})
}

@Composable
fun LanguageDialogContent(
selectedLanguage: MutableState<String>,
dataStore: DataStore,
languageEntries: List<String>,
languageValues: List<String>
) {
LaunchedEffect(Unit) {
selectedLanguage.value = dataStore.getLanguage().firstOrNull() ?: ""
}

Column {
Text(stringResource(id = R.string.dialog_language_subtitle))
Box(
modifier = Modifier
.fillMaxWidth()
.weight(1f)
) {
LazyColumn {
items(languageEntries.size) { index ->
Row(
Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Start
) {
RadioButton(
selected = selectedLanguage.value == languageValues[index],
onClick = {
selectedLanguage.value = languageValues[index]
})
Text(
modifier = Modifier.padding(start = 8.dp),
text = languageEntries[index],
style = MaterialTheme.typography.bodyMedium.merge()
)
}
}
}
}
Spacer(modifier = Modifier.height(24.dp))
Icon(imageVector = Icons.Outlined.Info, contentDescription = null)
Spacer(modifier = Modifier.height(12.dp))
Text(stringResource(id = R.string.dialog_info_language))
}

LaunchedEffect(selectedLanguage.value) {
dataStore.saveLanguage(selectedLanguage.value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.d4rk.cleaner.ui.settings.display.theme.AppTheme
import com.d4rk.cleaner.ui.settings.display.theme.style.AppTheme
import com.d4rk.cleaner.utils.Utils
import com.google.android.play.core.review.ReviewManager
import com.google.android.play.core.review.ReviewManagerFactory
Expand Down
108 changes: 54 additions & 54 deletions app/src/main/kotlin/com/d4rk/cleaner/ui/help/HelpComposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,41 @@ fun HelpComposable(activity: HelpActivity) {
}
DropdownMenu(expanded = showMenu, onDismissRequest = { showMenu = false }) {
DropdownMenuItem(text = { Text(stringResource(R.string.view_in_google_play_store)) },
onClick = {
Utils.openUrl(
context,
"https://play.google.com/store/apps/details?id=${activity.packageName}"
)
})
onClick = {
Utils.openUrl(
context,
"https://play.google.com/store/apps/details?id=${activity.packageName}"
)
})
DropdownMenuItem(text = { Text(stringResource(R.string.version_info)) },
onClick = { showDialog.value = true })
onClick = { showDialog.value = true })
DropdownMenuItem(text = { Text(stringResource(R.string.beta_program)) },
onClick = {
Utils.openUrl(
context,
"https://play.google.com/apps/testing/${activity.packageName}"
)
})
onClick = {
Utils.openUrl(
context,
"https://play.google.com/apps/testing/${activity.packageName}"
)
})
DropdownMenuItem(text = { Text(stringResource(R.string.terms_of_service)) },
onClick = {
Utils.openUrl(
context,
"https://sites.google.com/view/d4rk7355608/more/apps/terms-of-service"
)
})
onClick = {
Utils.openUrl(
context,
"https://sites.google.com/view/d4rk7355608/more/apps/terms-of-service"
)
})
DropdownMenuItem(text = { Text(stringResource(R.string.privacy_policy)) },
onClick = {
Utils.openUrl(
context,
"https://sites.google.com/view/d4rk7355608/more/apps/privacy-policy"
)
})
onClick = {
Utils.openUrl(
context,
"https://sites.google.com/view/d4rk7355608/more/apps/privacy-policy"
)
})
DropdownMenuItem(text = { Text(stringResource(com.google.android.gms.oss.licenses.R.string.oss_license_title)) },
onClick = {
Utils.openActivity(
context, OssLicensesMenuActivity::class.java
)
})
onClick = {
Utils.openActivity(
context, OssLicensesMenuActivity::class.java
)
})
}
if (showDialog.value) {
VersionInfoDialog(onDismiss = { showDialog.value = false })
Expand All @@ -113,25 +113,25 @@ fun HelpComposable(activity: HelpActivity) {
}) { paddingValues ->
Box(
modifier = Modifier
.padding(start = 16.dp, end = 16.dp)
.fillMaxSize()
.safeDrawingPadding()
.padding(start = 16.dp, end = 16.dp)
.fillMaxSize()
.safeDrawingPadding()
) {
ConstraintLayout(modifier = Modifier.padding(paddingValues)) {
val (faqTitle, faqCard) = createRefs()
Text(text = stringResource(R.string.faq),
modifier = Modifier
.padding(bottom = 24.dp)
.constrainAs(faqTitle) {
top.linkTo(parent.top)
start.linkTo(parent.start)
})
modifier = Modifier
.padding(bottom = 24.dp)
.constrainAs(faqTitle) {
top.linkTo(parent.top)
start.linkTo(parent.start)
})
Card(modifier = Modifier
.fillMaxWidth()
.constrainAs(faqCard) {
top.linkTo(faqTitle.bottom)
bottom.linkTo(parent.bottom)
}) {
.fillMaxWidth()
.constrainAs(faqCard) {
top.linkTo(faqTitle.bottom)
bottom.linkTo(parent.bottom)
}) {
FAQComposable()
}
}
Expand All @@ -146,9 +146,9 @@ fun HelpComposable(activity: HelpActivity) {
)
},
modifier = Modifier
.bounceClick()
.padding(bottom = 16.dp)
.align(Alignment.BottomEnd),
.bounceClick()
.padding(bottom = 16.dp)
.align(Alignment.BottomEnd),
)
}
}
Expand Down Expand Up @@ -218,19 +218,19 @@ fun FAQComposable() {
fun QuestionComposable(title: String, summary: String) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
.fillMaxWidth()
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Outlined.QuestionAnswer,
contentDescription = null,
modifier = Modifier
.size(48.dp)
.background(
color = MaterialTheme.colorScheme.primaryContainer, shape = CircleShape
)
.padding(8.dp)
.size(48.dp)
.background(
color = MaterialTheme.colorScheme.primaryContainer, shape = CircleShape
)
.padding(8.dp)
)
Spacer(modifier = Modifier.width(16.dp))
Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.d4rk.cleaner.ui.settings.display.theme.AppTheme
import com.d4rk.cleaner.ui.settings.display.theme.style.AppTheme

class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package com.d4rk.cleaner.ui.settings.about

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.d4rk.cleaner.ui.settings.display.theme.AppTheme
import com.d4rk.cleaner.ui.settings.display.theme.style.AppTheme

class AboutSettingsActivity : ComponentActivity() {
class AboutSettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
AppTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background
) {
AboutSettingsComposable(this@AboutSettingsActivity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fun AboutSettingsComposable(activity: AboutSettingsActivity) {
}) { paddingValues ->
LazyColumn(
modifier = Modifier
.fillMaxHeight()
.padding(paddingValues),
.fillMaxHeight()
.padding(paddingValues),
) {
item {
PreferenceCategoryItem(title = stringResource(R.string.app_info))
Expand All @@ -60,10 +60,10 @@ fun AboutSettingsComposable(activity: AboutSettingsActivity) {
summary = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
)
PreferenceItem(title = stringResource(com.google.android.gms.oss.licenses.R.string.oss_license_title),
summary = stringResource(R.string.summary_preference_settings_oss),
onClick = {
Utils.openActivity(context, OssLicensesMenuActivity::class.java)
})
summary = stringResource(R.string.summary_preference_settings_oss),
onClick = {
Utils.openActivity(context, OssLicensesMenuActivity::class.java)
})
}
item {
PreferenceCategoryItem(title = stringResource(R.string.device_info))
Expand All @@ -77,12 +77,12 @@ fun AboutSettingsComposable(activity: AboutSettingsActivity) {
)

PreferenceItem(title = stringResource(id = R.string.device_info),
summary = version,
onClick = {
val clip = ClipData.newPlainText("text", version)
clipboardManager.setPrimaryClip(clip)
// Show snackbar
})
summary = version,
onClick = {
val clip = ClipData.newPlainText("text", version)
clipboardManager.setPrimaryClip(clip)
// TODO: Show snackbar
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.d4rk.cleaner.ui.settings.advanced

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.d4rk.cleaner.ui.settings.display.theme.AppTheme
import com.d4rk.cleaner.ui.settings.display.theme.style.AppTheme

class AdvancedSettingsActivity : ComponentActivity() {
class AdvancedSettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
Expand Down
Loading

0 comments on commit d8f79b8

Please sign in to comment.