Merge remote-tracking branch 'origin/master' into feat/more_dialogs

# Conflicts:
#	samples/src/main/kotlin/com/simplemobiletools/commons/samples/activities/MainActivity.kt
This commit is contained in:
FunkyMuse 2023-10-12 16:17:56 +02:00
commit 0345d07717
11 changed files with 401 additions and 256 deletions

View file

@ -17,6 +17,7 @@ import androidx.compose.ui.unit.dp
import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.extensions.rememberMutableInteractionSource
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.SimpleTheme
private val dropDownPaddings = Modifier.padding(horizontal = 14.dp, vertical = 16.dp)
@ -37,16 +38,20 @@ fun SimpleDropDownMenuItem(
indication: Indication? = LocalIndication.current,
onClick: () -> Unit
) =
Box(modifier = modifier
.fillMaxWidth()
.clickable(interactionSource = interactionSource, indication = indication, onClick = onClick)
.then(dropDownPaddings)) {
Text(
text = text,
modifier = Modifier
.fillMaxWidth()
)
}
SimpleDropDownMenuItem(
modifier = modifier,
interactionSource = interactionSource,
indication = indication,
onClick = onClick,
text = {
Text(
text = text,
modifier = Modifier
.fillMaxWidth(),
color = SimpleTheme.colorScheme.onSurface
)
}
)
@Composable
fun SimpleDropDownMenuItem(

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.commons.compose.menus
import androidx.annotation.StringRes
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
@ -30,6 +31,8 @@ import com.simplemobiletools.commons.compose.extensions.rememberMutableInteracti
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.Shapes
import com.simplemobiletools.commons.compose.theme.SimpleTheme
import com.simplemobiletools.commons.dialogs.dialogBorder
import com.simplemobiletools.commons.dialogs.dialogContainerColor
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
@ -140,6 +143,9 @@ fun ActionMenu(
}
}
DropdownMenu(
modifier = Modifier
.background(dialogContainerColor)
.dialogBorder,
expanded = isMenuVisible,
onDismissRequest = { onMenuToggle(false) },
) {

View file

@ -1,7 +1,19 @@
package com.simplemobiletools.commons.dialogs
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.sp
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.databinding.DialogOpenDeviceSettingsBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.openDeviceSettings
@ -23,3 +35,54 @@ class OpenDeviceSettingsDialog(val activity: BaseSimpleActivity, message: String
}
}
}
@Composable
fun OpenDeviceSettingsAlertDialog(
alertDialogState: AlertDialogState,
modifier: Modifier = Modifier,
message: String
) {
val context = LocalContext.current
AlertDialog(
containerColor = dialogContainerColor,
modifier = modifier
.dialogBorder,
onDismissRequest = alertDialogState::hide,
shape = dialogShape,
tonalElevation = dialogElevation,
text = {
Text(
fontSize = 16.sp,
text = message,
color = dialogTextColor
)
},
dismissButton = {
TextButton(onClick = {
alertDialogState.hide()
}) {
Text(text = stringResource(id = R.string.close))
}
},
confirmButton = {
TextButton(onClick = {
context.openDeviceSettings()
alertDialogState.hide()
}) {
Text(text = stringResource(id = R.string.go_to_settings))
}
},
)
}
@Composable
@MyDevices
private fun OpenDeviceSettingsAlertDialogPreview() {
AppThemeSurface {
OpenDeviceSettingsAlertDialog(
alertDialogState = rememberAlertDialogState(),
message = "Test dialog"
)
}
}

View file

@ -218,10 +218,14 @@ open class BaseConfig(val context: Context) {
prefs.edit().putBoolean(USE_ENGLISH, useEnglish).commit()
}
val useEnglishFlow = ::useEnglish.asFlowNonNull()
var wasUseEnglishToggled: Boolean
get() = prefs.getBoolean(WAS_USE_ENGLISH_TOGGLED, false)
set(wasUseEnglishToggled) = prefs.edit().putBoolean(WAS_USE_ENGLISH_TOGGLED, wasUseEnglishToggled).apply()
val wasUseEnglishToggledFlow = ::wasUseEnglishToggled.asFlowNonNull()
var wasSharedThemeEverActivated: Boolean
get() = prefs.getBoolean(WAS_SHARED_THEME_EVER_ACTIVATED, false)
set(wasSharedThemeEverActivated) = prefs.edit().putBoolean(WAS_SHARED_THEME_EVER_ACTIVATED, wasSharedThemeEverActivated).apply()

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ok">باشه</string>
<string name="ok">تایید</string>
<string name="cancel">لغو</string>
<string name="close">Close</string>
<string name="back">Back</string>
<string name="nothing">Nothing</string>
<string name="close">بستن</string>
<string name="back">بازگشت</string>
<string name="nothing">هیچ‌چیز</string>
<string name="later">بعدا</string>
<string name="save_as">ذخیره به عنوان</string>
<string name="file_saved">پرونده با موفقیت ذخیره شد</string>
@ -347,14 +347,14 @@
<string name="default_color">پیش‌گزیده</string>
<string name="change_color">تغییر رنگ</string>
<string name="theme">شِما</string>
<string name="changing_color_description">تغییر یک رنگ آن را به شِما سفارشی تعویض خواهد میکند</string>
<string name="changing_color_description">تغییر یک رنگ آن را به شِما سفارشی تعویض میکند</string>
<string name="save">ذخیره</string>
<string name="discard">دورانداختن</string>
<string name="undo_changes">برگرداندن تغییرات</string>
<string name="undo_changes_confirmation">آیا از برگرداندن تغییرات خود مطمئنید؟</string>
<string name="cannot_be_undone">This action cannot be undone.</string>
<string name="cannot_be_undone">این کار قابل برگشت نیست.</string>
<string name="save_before_closing">شما تغییرات ذخیره نشده دارید. قبل از خروج ذخیره شوند؟</string>
<string name="apply_to_all_apps">اعمال رنگ‌ها به همه برنامه‌های آسان</string>
<string name="apply_to_all_apps">اعمال رنگ‌ها به همه برنامه‌های ساده</string>
<string name="app_icon_color_warning">WARNING: Some launchers do not handle app icon customization properly. In case the icon will disappear, try launching the app via Google Play or some widget, if available.
Once launched, just set back the default orange icon #F57C00. You might have to reinstall the app in the worst case.</string>
<string name="share_colors_success">Colors updated successfully. A new Theme called \'Shared\' has been added, please use that for updating all app colors in the future.</string>
@ -367,15 +367,15 @@
<!-- Themes -->
<string name="light_theme">روشن</string>
<string name="dark_theme">تاریک</string>
<string name="auto_theme">Auto</string>
<string name="auto_light_dark_theme">Auto light / dark</string>
<string name="auto_theme">خودکار</string>
<string name="auto_light_dark_theme">روشن / تاریک خودکار</string>
<string name="solarized">آفتابی</string>
<string name="dark_red">قرمز تاریک</string>
<string name="white">سفید</string>
<string name="black_white">سیاه &amp; سفید</string>
<string name="black_white">سیاه و سفید</string>
<string name="custom">سفارشی</string>
<string name="shared">اشتراک گذاری شد</string>
<string name="system_default">System default</string>
<string name="system_default">پیش‌فرض سامانه</string>
<!-- What's new -->
<string name="whats_new">چه چیز جدید است</string>
<string name="whats_new_disclaimer">* only the bigger updates are listed here, there are always some smaller improvements too</string>
@ -385,7 +385,7 @@
<string name="rename">تغییر نام</string>
<string name="share">اشتراک گذاری</string>
<string name="share_via">اشتراک گذاری به وسیلهٔ</string>
<string name="resize">Resize</string>
<string name="resize">تغيير اندازه</string>
<string name="select_all">گزینش همه</string>
<string name="select_text">گزینش متن</string>
<string name="hide">مخفی</string>
@ -401,7 +401,7 @@
<string name="redo">انجام دوباره</string>
<string name="print">چاپ</string>
<string name="print_pro">چاپ (Pro)</string>
<string name="shortcut">Shortcut</string>
<string name="shortcut">میانبر</string>
<string name="create_shortcut">ساخت میانبر</string>
<string name="create_shortcut_pro">ساخت میانبر (Pro)</string>
<string name="add_number_to_contact">افزودن شماره به مخاطبین</string>
@ -413,9 +413,9 @@
<string name="move_to_bottom">جابه‌جایی به پایین</string>
<string name="pin_item">Pin item</string>
<string name="unpin_item">Unpin item</string>
<string name="send_sms">Send SMS</string>
<string name="send_email">Send email</string>
<string name="call">Call</string>
<string name="send_sms">ارسال پیامک</string>
<string name="send_email">ارسال ایمیل</string>
<string name="call">تماس</string>
<string name="contact_details">Contact details</string>
<string name="add_contact">Add contact</string>
<string name="wallpapers">Wallpapers</string>
@ -428,14 +428,14 @@
<string name="name">نام</string>
<string name="size">اندازه</string>
<string name="last_modified">اخرین اصلاح</string>
<string name="date_created">Date created</string>
<string name="date_created">تاریخ ایجاد</string>
<string name="date_taken">تاریخ گرفتن</string>
<string name="date_added">Date added</string>
<string name="date_added">تاریخ افزودن</string>
<string name="title">عنوان</string>
<string name="filename">نام پرونده</string>
<string name="extension">پسوند</string>
<string name="random">تصادفی</string>
<string name="sort_randomly">Sort randomly</string>
<string name="sort_randomly">ترتیب تصادفی</string>
<string name="ascending">Ascending</string>
<string name="descending">Descending</string>
<string name="use_for_this_folder">Use for this folder only</string>
@ -842,31 +842,31 @@
<string name="upgraded_from_free_notes">Hello,\n\nseems like you just upgraded from the free version. If you want to migrate your notes over, you have to do it manually by exporting them into a file in the free app version and importing here through the top menu. \n\nOnce you are satisfied with your setup in the Pro version, you can uninstall the old free one as you won\'t need it anymore.\n\nThanks!</string>
<!-- About -->
<string name="about">درباره</string>
<string name="website">Website</string>
<string name="website">وب‌سایت</string>
<string name="website_label">For the source codes visit</string>
<string name="email_label">Send your feedback or suggestions to</string>
<string name="upgrade_to_pro">Upgrade to Pro</string>
<string name="more_apps">More apps</string>
<string name="more_apps_from_us">More apps from us</string>
<string name="invite_friends">Invite friends</string>
<string name="email_label">پیشنهادات و بازخوردهایتان را بفرستید به</string>
<string name="upgrade_to_pro">ارتقا به Pro</string>
<string name="more_apps">سایر برنامه‌ها</string>
<string name="more_apps_from_us">برنامه‌های دیگر ما</string>
<string name="invite_friends">دعوت دوستان</string>
<string name="share_text">Hey, come check out %1$s at %2$s</string>
<string name="invite_via">Invite via</string>
<string name="invite_via">دعوت با</string>
<string name="rate_us">امتیاز به ما</string>
<string name="rate">امتیاز</string>
<string name="donate">اهدا</string>
<string name="follow_us">پیگیری ما</string>
<string name="copyright">v %1$s\nCopyright © Simple Mobile Tools %2$d</string>
<string name="support">Support</string>
<string name="help_us">Help us</string>
<string name="social">Social</string>
<string name="other">Other</string>
<string name="privacy_policy">Privacy policy</string>
<string name="version_placeholder">Version %s</string>
<string name="hello">Hello :)</string>
<string name="about_footer">Made with ❤️ in Slovakia</string>
<string name="support">حمایت</string>
<string name="help_us">کمک به ما</string>
<string name="social">شبکه‌های اجتماعی</string>
<string name="other">سایر</string>
<string name="privacy_policy">سیاست حفظ حریم خصوصی</string>
<string name="version_placeholder">نسخهٔ %s</string>
<string name="hello">سلام :)</string>
<string name="about_footer">ساخته‌شده با ❤️ در اسلواکی</string>
<string name="additional_info">اطلاعات اضافی</string>
<string name="app_version">نسخه برنامه: %s</string>
<string name="device_os">سیستم عامل دستگاه: %s</string>
<string name="app_version">نسخهٔ برنامه: %s</string>
<string name="device_os">سیستمعامل دستگاه: %s</string>
<string name="donate_please">
<![CDATA[
Hello,<br><br>
@ -1131,4 +1131,4 @@
<string name="pro_app_refund">Don\'t forget that if you uninstall any paid app within 2 hours, you will automatically be refunded. If you want a refund anytime later, just contact us at hello@simplemobiletools.com and you will get it. That makes it easy to try it out :)</string>
<!-- Description of our developer profile on Google Play, it can have max 140 characters -->
<string name="developer_description">A group of simple, open source Android apps with customizable widgets, without ads and unnecessary permissions.</string>
</resources>
</resources>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ok">OK</string>
<string name="ok">Valider</string>
<string name="cancel">Annuler</string>
<string name="close">Fermer</string>
<string name="back">Retour</string>
@ -95,7 +95,7 @@
<!-- View types -->
<string name="change_view_type">Modifier le mode d\'affichage</string>
<string name="grid">Grille</string>
<string name="grid_pro">Grille (Pro)</string>
<string name="grid_pro">Grille (version \"Pro\")</string>
<string name="uneven_grid">Grille irrégulière</string>
<string name="list">Liste</string>
<string name="increase_column_count">Ajouter une colonne</string>
@ -124,7 +124,7 @@
<string name="block_numbers">Bloquer les numéros</string>
<string name="blocked_numbers">Numéros bloqués</string>
<string name="export_blocked_numbers">Exporter les numéros bloqués</string>
<string name="import_blocked_numbers">Importer les numéros bloqués</string>
<string name="import_blocked_numbers">Importer des numéros bloqués</string>
<string name="must_make_default_dialer">Vous devez définir cette application comme application de numérotation par défaut afin de pouvoir utiliser les numéros bloqués.</string>
<string name="set_as_default">Définir par défaut</string>
<string name="block_confirmation">Voulez-vous vraiment bloquer "%s" \?</string>
@ -150,11 +150,11 @@
<string name="search_in_placeholder">Rechercher dans %s</string>
<string name="type_2_characters">Saisissez au moins deux caractères pour lancer la recherche.</string>
<string name="show_search">Afficher une barre de recherche</string>
<string name="search_contacts">Rechercher des contacts</string>
<string name="search_favorites">Rechercher des favoris</string>
<string name="search_contacts">Rechercher parmi les contacts</string>
<string name="search_favorites">Rechercher parmi les favoris</string>
<string name="search_apps">Rechercher des applications</string>
<string name="search_events">Rechercher des évènements</string>
<string name="search_groups">Rechercher des groupes</string>
<string name="search_groups">Rechercher parmi les groupes</string>
<string name="search_history">Rechercher dans l\'historique</string>
<string name="search_calls">Rechercher des appels</string>
<string name="search_files">Rechercher des fichiers</string>
@ -169,7 +169,7 @@
<string name="search_recordings">Rechercher des enregistrements</string>
<!-- Filters -->
<string name="filter">Filtrer</string>
<string name="filter_pro">Filtrer (Pro)</string>
<string name="filter_pro">Filtrer (version \"Pro\")</string>
<string name="no_items_found">Aucun élément n\'a été trouvé.</string>
<string name="change_filter">Modifier le filtre</string>
<!-- Permissions -->
@ -408,10 +408,10 @@
<string name="undo">Annuler</string>
<string name="redo">Rétablir</string>
<string name="print">Imprimer</string>
<string name="print_pro">Imprimer (Pro)</string>
<string name="print_pro">Imprimer (version \"Pro\")</string>
<string name="shortcut">Raccourci</string>
<string name="create_shortcut">Créer un raccourci</string>
<string name="create_shortcut_pro">Créer un raccourci (Pro)</string>
<string name="create_shortcut_pro">Créer un raccourci (version \"Pro\")</string>
<string name="add_number_to_contact">Ajouter un numéro au contact</string>
<string name="view_contact_details">Afficher les détails du contact</string>
<string name="call_from_sim_1">Appeler depuis la carte SIM 1</string>
@ -500,7 +500,7 @@
<string name="protection_setup_successfully">Configuration du mot de passe réussie. Veuillez réinstaller l\'application en cas d\'oubli.</string>
<string name="fingerprint_setup_successfully">Configuration de la protection réussie. Veuillez réinstaller l\'application en cas de problèmes de réinitialisation.</string>
<string name="lock_folder">Verrouiller le dossier</string>
<string name="lock_folder_pro">Verrouiller le dossier (Pro)</string>
<string name="lock_folder_pro">Verrouiller le dossier (version \"Pro\")</string>
<string name="unlock_folder">Déverrouiller le dossier</string>
<string name="lock_folder_notice">Le verrouillage ne fonctionne que dans cette application. Cette protection ne remplace pas un véritable chiffrage système.</string>
<string name="enter_password">Saisir le mot de passe</string>
@ -729,7 +729,7 @@
<string name="empty_recycle_bin">Vider la corbeille</string>
<string name="force_portrait_mode">Forcer le mode portrait</string>
<string name="export_settings">Exporter les paramètres</string>
<string name="import_settings">Importer les paramètres</string>
<string name="import_settings">Importer des paramètres</string>
<string name="settings_exported_successfully">Exportation des paramètres réussie</string>
<string name="settings_imported_successfully">Importation des paramètres réussie</string>
<string name="start_name_with_surname">Positionner le prénom avant le nom de famille</string>
@ -876,11 +876,11 @@
<string name="saturday_short">Sam.</string>
<string name="sunday_short">Dim.</string>
<!-- Pro version -->
<string name="upgrade_to_pro_long">La version de votre application ne sera plus mise à jour. Veuillez passer à la version Pro pour recevoir de nouveaux correctifs et bénéficier d\'autres améliorations.</string>
<string name="upgrade_to_pro_long_click">La version de votre application ne sera plus mise à jour. Veuillez passer à la version Pro pour recevoir de nouveaux correctifs et bénéficier d\'autres améliorations en cliquant ici.</string>
<string name="upgrade_to_pro_long">La version de votre application ne sera plus mise à jour. Veuillez passer à la version \"Pro\" pour recevoir de nouveaux correctifs et bénéficier d\'autres améliorations.</string>
<string name="upgrade_to_pro_long_click">La version de votre application ne sera plus mise à jour. Veuillez passer à la version \"Pro\" pour recevoir de nouveaux correctifs et bénéficier d\'autres améliorations en cliquant ici.</string>
<string name="it_is_free">Elle est gratuite jusqu\'au : %s. Si vous la téléchargez avant cette date, vous pourrez l\'utiliser gratuitement à vie.</string>
<string name="more_info">Plus d\'informations</string>
<string name="upgrade">Passer à la version Pro</string>
<string name="upgrade">Mettre à jour</string>
<string name="upgrade_calendar">Vous devez migrer manuellement les évènements stockés localement en les exportant dans un fichier \".ics\", puis en les important. Vous trouverez les boutons d\'exportation/importation dans le menu de l\'écran principal.</string>
<string name="upgraded_from_free_gallery">Bonjour,
\n
@ -930,7 +930,7 @@
<string name="email_label">Envoyez vos commentaires ou suggestions à</string>
<string name="upgrade_to_pro">Passer à la version \"Pro\"</string>
<string name="more_apps">Plus d\'applications</string>
<string name="more_apps_from_us">Plus d\'applications</string>
<string name="more_apps_from_us">Plus d\'applications simples</string>
<string name="invite_friends">Inviter des amis</string>
<string name="share_text">Salut, viens voir %1$s sur %2$s</string>
<string name="invite_via">Inviter via</string>
@ -947,7 +947,7 @@
<string name="privacy_policy">Politique de confidentialité</string>
<string name="version_placeholder">Version %s</string>
<string name="hello">Bonjour :)</string>
<string name="about_footer">Codé avec ❤️ en Slovaquie</string>
<string name="about_footer">Codée avec ❤️ en Slovaquie</string>
<string name="additional_info">Informations supplémentaires</string>
<string name="app_version">Version de l\'application : %s</string>
<string name="device_os">Système d\'exploitation de l\'appareil : %s</string>
@ -1195,4 +1195,4 @@
<string name="pro_app_refund">N\'oubliez pas que si vous désinstallez une application payante dans les deux heures qui suivent son achat, le remboursement sera automatique. À tout moment, si vous souhaitez un remboursement, contactez-nous à l\'adresse électronique suivante : hello@simplemobiletools.com et vous l\'obtiendrez dans les plus brefs délais. Cela facilite l\'essai de nos applications :)</string>
<!-- Description of our developer profile on Google Play, it can have max 140 characters -->
<string name="developer_description">Une suite d\'applications Android simples, à code source ouvert, comprenant des widgets personnalisables, sans publicités ni permissions inutiles.</string>
</resources>
</resources>

View file

@ -2,7 +2,7 @@
<resources>
<string name="ok">OK</string>
<string name="cancel">Prekliči</string>
<string name="close">Close</string>
<string name="close">Zapri</string>
<string name="back">Nazaj</string>
<string name="nothing">Nič</string>
<string name="later">Pozneje</string>
@ -100,7 +100,7 @@
<string name="increase_column_count">Povečaj število stolpcev</string>
<string name="reduce_column_count">Zmanjšaj število stolpcev</string>
<string name="column_count">Število stolpcev</string>
<string name="row_count">Row count</string>
<string name="row_count">Število vrstic</string>
<string name="portrait_column_count">Število pokončnih stolpcev</string>
<string name="landscape_column_count">Ležeče število stolpcev</string>
<string name="change_cover_image">Spremeni naslovno fotografijo</string>
@ -319,7 +319,7 @@
<string name="select_storage">Izberi shrambo</string>
<string name="storage">Shramba</string>
<string name="internal">Notranja shramba</string>
<string name="internal_storage">Internal Storage</string>
<string name="internal_storage">Notranja shramba</string>
<string name="sd_card">SD kartica</string>
<string name="root">Korenska mapa</string>
<string name="wrong_root_selected">Izbrali ste napačno mapo. Izbrati morate korensko mapo SD kartice</string>
@ -1240,4 +1240,4 @@
<string name="pro_app_refund">Ne pozabite - če odstranite katerokoli plačljivo aplikacijo v dveh urah, dobite povrnjen avtomatično denar. Če želite povrnitev denarja po preteku tega časa, nas kontaktirajte na hello@simplemobiletools.com in poskrbeli bomo za to. Zaradi tega je preizkušanje aplikacije še bolj preprosto. :)</string>
<!-- Description of our developer profile on Google Play, it can have max 140 characters -->
<string name="developer_description">Skupina preprostih odprtokodnih aplikacij za Android s prilagodljivimi pripomočki, brez oglasov in nepotrebnih dovoljenj.</string>
</resources>
</resources>

View file

@ -2,59 +2,103 @@ package com.simplemobiletools.commons.samples.activities
import android.content.Intent
import android.os.Bundle
import android.util.Log
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import com.simplemobiletools.commons.activities.AboutActivity
import com.simplemobiletools.commons.activities.CustomizationActivity
import com.simplemobiletools.commons.activities.ManageBlockedNumbersActivity
import com.simplemobiletools.commons.dialogs.BottomSheetChooserDialog
import com.simplemobiletools.commons.dialogs.CustomIntervalPickerDialog
import com.simplemobiletools.commons.extensions.appLaunched
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.viewBinding
import com.simplemobiletools.commons.helpers.LICENSE_AUTOFITTEXTVIEW
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
import com.simplemobiletools.commons.compose.extensions.*
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.DonateAlertDialog
import com.simplemobiletools.commons.dialogs.RateStarsAlertDialog
import com.simplemobiletools.commons.extensions.hideKeyboard
import com.simplemobiletools.commons.extensions.launchMoreAppsFromUsIntent
import com.simplemobiletools.commons.extensions.launchViewIntent
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.commons.models.SimpleListItem
import com.simplemobiletools.commons.samples.BuildConfig
import com.simplemobiletools.commons.samples.R
import com.simplemobiletools.commons.samples.databinding.ActivityMainBinding
class MainActivity : BaseSimpleActivity() {
override fun getAppLauncherName() = getString(R.string.smtco_app_name)
override fun getAppIconIDs(): ArrayList<Int> {
val ids = ArrayList<Int>()
ids.add(R.mipmap.commons_launcher)
return ids
}
private val binding by viewBinding(ActivityMainBinding::inflate)
import com.simplemobiletools.commons.samples.screens.MainScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
appLaunched(BuildConfig.APPLICATION_ID)
updateMaterialActivityViews(binding.mainCoordinator, binding.mainHolder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(binding.mainNestedScrollview, binding.mainToolbar)
enableEdgeToEdgeSimple()
setContent {
AppThemeSurface {
val showMoreApps = onEventValue { !resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations) }
binding.mainColorCustomization.setOnClickListener {
startCustomizationActivity()
}
binding.bottomSheetChooser.setOnClickListener {
launchAbout()
}
binding.manageBlockedNumbers.setOnClickListener {
startActivity(Intent(this, ManageBlockedNumbersActivity::class.java))
}
binding.composeDialogs.setOnClickListener {
startActivity(Intent(this, TestDialogActivity::class.java))
}
binding.testButton.setOnClickListener {
CustomIntervalPickerDialog(this, 0, showSeconds = false) {
Log.d("CustomIntervalPickerDialog", it.toString())
MainScreen(
openColorCustomization = ::startCustomizationActivity,
manageBlockedNumbers = {
startActivity(Intent(this@MainActivity, ManageBlockedNumbersActivity::class.java))
},
showComposeDialogs = {
startActivity(Intent(this@MainActivity, TestDialogActivity::class.java))
},
openTestButton = {
ConfirmationDialog(
this@MainActivity,
FAKE_VERSION_APP_LABEL,
positive = com.simplemobiletools.commons.R.string.ok,
negative = 0
) {
launchViewIntent(DEVELOPER_PLAY_STORE_URL)
}
},
showMoreApps = showMoreApps,
openAbout = ::launchAbout,
moreAppsFromUs = ::launchMoreAppsFromUsIntent
)
AppLaunched()
}
}
}
@Composable
private fun AppLaunched(
donateAlertDialogState: AlertDialogState = getDonateAlertDialogState(),
rateStarsAlertDialogState: AlertDialogState = getRateStarsAlertDialogState(),
) {
LaunchedEffect(Unit) {
appLaunchedCompose(
appId = BuildConfig.APPLICATION_ID,
showDonateDialog = donateAlertDialogState::show,
showRateUsDialog = rateStarsAlertDialogState::show,
showUpgradeDialog = {}
)
}
}
@Composable
private fun getDonateAlertDialogState() =
rememberAlertDialogState().apply {
DialogMember {
DonateAlertDialog(alertDialogState = this)
}
}
@Composable
private fun getRateStarsAlertDialogState() = rememberAlertDialogState().apply {
DialogMember {
RateStarsAlertDialog(alertDialogState = this, onRating = ::rateStarsRedirectAndThankYou)
}
}
private fun startCustomizationActivity() {
Intent(applicationContext, CustomizationActivity::class.java).apply {
putExtra(APP_ICON_IDS, getAppIconIDs())
putExtra(APP_LAUNCHER_NAME, getAppLauncherName())
startActivity(this)
}
}
private fun launchAbout() {
val licenses = LICENSE_AUTOFITTEXTVIEW
@ -72,27 +116,29 @@ class MainActivity : BaseSimpleActivity() {
startAboutActivity(R.string.smtco_app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
}
private fun launchBottomSheetDemo() {
BottomSheetChooserDialog.createChooser(
fragmentManager = supportFragmentManager,
title = com.simplemobiletools.commons.R.string.please_select_destination,
items = arrayOf(
SimpleListItem(1, com.simplemobiletools.commons.R.string.record_video, com.simplemobiletools.commons.R.drawable.ic_camera_vector),
SimpleListItem(
2,
com.simplemobiletools.commons.R.string.record_audio,
com.simplemobiletools.commons.R.drawable.ic_microphone_vector,
selected = true
),
SimpleListItem(4, com.simplemobiletools.commons.R.string.choose_contact, com.simplemobiletools.commons.R.drawable.ic_add_person_vector)
)
) {
toast("Clicked ${it.id}")
private fun startAboutActivity(
appNameId: Int, licenseMask: Long, versionName: String, faqItems: ArrayList<FAQItem>, showFAQBeforeMail: Boolean,
getAppIconIDs: ArrayList<Int> = getAppIconIDs(),
getAppLauncherName: String = getAppLauncherName()
) {
hideKeyboard()
Intent(applicationContext, AboutActivity::class.java).apply {
putExtra(APP_ICON_IDS, getAppIconIDs)
putExtra(APP_LAUNCHER_NAME, getAppLauncherName)
putExtra(APP_NAME, getString(appNameId))
putExtra(APP_LICENSES, licenseMask)
putExtra(APP_VERSION_NAME, versionName)
putExtra(APP_FAQ, faqItems)
putExtra(SHOW_FAQ_BEFORE_MAIL, showFAQBeforeMail)
startActivity(this)
}
}
override fun onResume() {
super.onResume()
setupToolbar(binding.mainToolbar)
private fun getAppLauncherName() = getString(R.string.smtco_app_name)
private fun getAppIconIDs(): ArrayList<Int> {
val ids = ArrayList<Int>()
ids.add(R.mipmap.commons_launcher)
return ids
}
}

View file

@ -1,129 +0,0 @@
package com.simplemobiletools.commons.samples.activities
import android.annotation.SuppressLint
import android.view.*
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.interfaces.ItemMoveCallback
import com.simplemobiletools.commons.interfaces.ItemTouchHelperContract
import com.simplemobiletools.commons.interfaces.StartReorderDragListener
import com.simplemobiletools.commons.samples.databinding.ListItemBinding
import com.simplemobiletools.commons.views.MyRecyclerView
import java.util.*
class StringsAdapter(
activity: BaseSimpleActivity, var strings: MutableList<String>, recyclerView: MyRecyclerView, val swipeRefreshLayout: SwipeRefreshLayout,
itemClick: (Any) -> Unit
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), ItemTouchHelperContract {
private var isChangingOrder = false
private var startReorderDragListener: StartReorderDragListener
init {
setupDragListener(true)
val touchHelper = ItemTouchHelper(ItemMoveCallback(this, true))
touchHelper.attachToRecyclerView(recyclerView)
startReorderDragListener = object : StartReorderDragListener {
override fun requestDrag(viewHolder: RecyclerView.ViewHolder) {
touchHelper.startDrag(viewHolder)
}
}
}
override fun getActionMenuId() = com.simplemobiletools.commons.R.menu.cab_delete_only
override fun prepareActionMode(menu: Menu) {}
override fun actionItemPressed(id: Int) {
if (selectedKeys.isEmpty()) {
return
}
when (id) {
com.simplemobiletools.commons.R.id.cab_delete -> changeOrder()
}
}
override fun getSelectableItemCount() = strings.size
override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = strings.getOrNull(position)?.hashCode()
override fun getItemKeyPosition(key: Int) = strings.indexOfFirst { it.hashCode() == key }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false).run { ViewHolder(root) }
override fun onActionModeCreated() {}
override fun onActionModeDestroyed() {
if (isChangingOrder) {
notifyDataSetChanged()
}
isChangingOrder = false
}
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val item = strings[position]
holder.bindView(item, true, true) { itemView, layoutPosition ->
setupView(ListItemBinding.bind(itemView), item, holder)
}
bindViewHolder(holder)
}
override fun getItemCount() = strings.size
private fun changeOrder() {
isChangingOrder = true
notifyDataSetChanged()
}
@SuppressLint("ClickableViewAccessibility")
private fun setupView(view: ListItemBinding, string: String, holder: ViewHolder) {
val isSelected = selectedKeys.contains(string.hashCode())
view.apply {
itemFrame.isSelected = isSelected
itemName.text = string
dragHandle.beVisibleIf(isChangingOrder)
if (isChangingOrder) {
dragHandle.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
startReorderDragListener.requestDrag(holder)
}
false
}
}
}
}
override fun onRowMoved(fromPosition: Int, toPosition: Int) {
if (fromPosition < toPosition) {
for (i in fromPosition until toPosition) {
Collections.swap(strings, i, i + 1)
}
} else {
for (i in fromPosition downTo toPosition + 1) {
Collections.swap(strings, i, i - 1)
}
}
notifyItemMoved(fromPosition, toPosition)
}
override fun onRowSelected(myViewHolder: ViewHolder?) {
swipeRefreshLayout.isEnabled = false
}
override fun onRowClear(myViewHolder: ViewHolder?) {
swipeRefreshLayout.isEnabled = true
}
}

View file

@ -55,6 +55,7 @@ class TestDialogActivity : ComponentActivity() {
ShowButton(getFeatureLockedAlertDialogState(), text = "Feature Locked")
ShowButton(getPurchaseThankYouAlertDialogState(), text = "Purchase thank you")
ShowButton(getLineColorPickerAlertDialogState(), text = "Line color picker")
ShowButton(getOpenDeviceSettingsAlertDialogState(), text = "Open device settings")
ShowButton(getColorPickerAlertDialogState(), text = "Color picker")
ShowButton(getCallConfirmationAlertDialogState(), text = "Call confirmation")
ShowButton(getChangeDateTimeFormatAlertDialogState(), text = "Change date time")
@ -257,6 +258,16 @@ class TestDialogActivity : ComponentActivity() {
}
}
@Composable
private fun getOpenDeviceSettingsAlertDialogState() = rememberAlertDialogState().apply {
DialogMember {
OpenDeviceSettingsAlertDialog(
alertDialogState = this,
message = "Test message"
)
}
}
@Composable
private fun getColorPickerAlertDialogState() = rememberAlertDialogState().apply {
DialogMember {

View file

@ -0,0 +1,139 @@
package com.simplemobiletools.commons.samples.screens
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.lists.SimpleScaffold
import com.simplemobiletools.commons.compose.lists.simpleTopAppBarColors
import com.simplemobiletools.commons.compose.lists.topAppBarInsets
import com.simplemobiletools.commons.compose.lists.topAppBarPaddings
import com.simplemobiletools.commons.compose.menus.ActionItem
import com.simplemobiletools.commons.compose.menus.ActionMenu
import com.simplemobiletools.commons.compose.menus.OverflowMode
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
@Composable
fun MainScreen(
openColorCustomization: () -> Unit,
manageBlockedNumbers: () -> Unit,
showComposeDialogs: () -> Unit,
openTestButton: () -> Unit,
showMoreApps: Boolean,
openAbout: () -> Unit,
moreAppsFromUs: () -> Unit,
) {
SimpleScaffold(
customTopBar = { scrolledColor: Color, _: MutableInteractionSource, scrollBehavior: TopAppBarScrollBehavior, statusBarColor: Int, colorTransitionFraction: Float, contrastColor: Color ->
TopAppBar(
title = {},
actions = {
val actionMenus = remember {
buildActionMenuItems(
showMoreApps = showMoreApps,
openAbout = openAbout,
moreAppsFromUs = moreAppsFromUs
)
}
var isMenuVisible by remember { mutableStateOf(false) }
ActionMenu(
items = actionMenus,
numIcons = 2,
isMenuVisible = isMenuVisible,
onMenuToggle = { isMenuVisible = it },
iconsColor = scrolledColor
)
},
scrollBehavior = scrollBehavior,
colors = simpleTopAppBarColors(statusBarColor, colorTransitionFraction, contrastColor),
modifier = Modifier.topAppBarPaddings(),
windowInsets = topAppBarInsets()
)
}
) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Button(
onClick = openColorCustomization
) {
Text(stringResource(id = R.string.color_customization))
}
Button(
onClick = openAbout
) {
Text("About")
}
Button(
onClick = manageBlockedNumbers
) {
Text("Manage blocked numbers")
}
Button(
onClick = showComposeDialogs
) {
Text("Compose dialogs")
}
Button(
onClick = openTestButton
) {
Text("Test button")
}
}
}
}
private fun buildActionMenuItems(
showMoreApps: Boolean,
openAbout: () -> Unit,
moreAppsFromUs: () -> Unit
): ImmutableList<ActionItem> {
val list = mutableListOf<ActionItem>()
list += ActionItem(
R.string.about,
icon = Icons.Outlined.Info,
doAction = openAbout,
overflowMode = OverflowMode.NEVER_OVERFLOW
)
if (showMoreApps) {
list += ActionItem(
R.string.more_apps_from_us,
doAction = moreAppsFromUs,
overflowMode = OverflowMode.ALWAYS_OVERFLOW
)
}
return list.toImmutableList()
}
@Composable
@MyDevices
private fun MainScreenPreview() {
AppThemeSurface {
MainScreen(
openColorCustomization = {},
manageBlockedNumbers = {},
showComposeDialogs = {},
openTestButton = {},
showMoreApps = true,
openAbout = {},
moreAppsFromUs = {}
)
}
}