Skip to content

Commit

Permalink
[REFACTOR] Simplified authentication messages for better readability.
Browse files Browse the repository at this point in the history
[FEAT] Introduced a new splash icon to improve appearance on older Android versions.
[FIX] Resolved multiple lock screen issue in navGraph when app resumes from saved state.
  • Loading branch information
iZakirSheikh committed Sep 15, 2024
1 parent bc1ec7c commit 2b08c97
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId = "com.googol.android.apps.photos"
minSdk = 24
targetSdk = 35
versionCode = 18
versionName = "0.1.0-dev18"
versionCode = 19
versionName = "0.1.0-dev19"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
19 changes: 13 additions & 6 deletions app/src/main/java/com/zs/gallery/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import com.zs.gallery.common.getPackageInfoCompat
import com.zs.gallery.files.RouteTimeline
import com.zs.gallery.lockscreen.RouteLockScreen
import com.zs.gallery.settings.Settings
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.launchIn
Expand Down Expand Up @@ -188,7 +189,7 @@ class MainActivity : ComponentActivity(), SystemFacade, NavController.OnDestinat
// automatically navigated to the lock screen in onCreate().
if (timeAppWentToBackground != -1L && isAuthenticationRequired) {
Log.d(TAG, "onResume: navigating -> RouteLockScreen.")
navController?.navigate(RouteLockScreen()){
navController?.navigate(RouteLockScreen()) {
launchSingleTop = true
}
unlock()
Expand All @@ -202,12 +203,12 @@ class MainActivity : ComponentActivity(), SystemFacade, NavController.OnDestinat
PlatformToast.makeText(this, string, PlatformToast.LENGTH_SHORT).show()

@RequiresApi(Build.VERSION_CODES.P)
override fun authenticate(desc: String?, onAuthenticated: () -> Unit) {
override fun authenticate(subtitle: String?, desc: String?, onAuthenticated: () -> Unit) {
Log.d(TAG, "preparing to show authentication dialog.")
// Build the BiometricPrompt
val prompt = BiometricPrompt.Builder(this).apply {
setTitle(getString(R.string.scr_lock_screen_title))
setSubtitle(getString(R.string.scr_lock_screen_subtitle))
if (subtitle != null) setSubtitle(subtitle)
if (desc != null) setDescription(desc)
// Set allowed authenticators for Android R and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
Expand Down Expand Up @@ -256,7 +257,7 @@ class MainActivity : ComponentActivity(), SystemFacade, NavController.OnDestinat
getSystemService(name) as T

@SuppressLint("NewApi")
override fun unlock() = authenticate(getString(R.string.src_lock_screen_desc)) {
override fun unlock() = authenticate() {
val navController = navController ?: return@authenticate
// if it is initial app_lock update timeAppWentToBackground to 0
if (timeAppWentToBackground == -1L)
Expand Down Expand Up @@ -386,6 +387,11 @@ class MainActivity : ComponentActivity(), SystemFacade, NavController.OnDestinat
flow1.combine(flow2) { _, _ -> enableEdgeToEdge() }
.launchIn(scope = lifecycleScope)
lifecycleScope.launch { launchUpdateFlow() }
if (isAuthenticationRequired)
lifecycleScope.launch {
delay(1000)
unlock()
}
}

override fun launchUpdateFlow(report: Boolean) {
Expand Down Expand Up @@ -516,8 +522,9 @@ class MainActivity : ComponentActivity(), SystemFacade, NavController.OnDestinat
// since auth is required; we will cover the scrren with lock_screen
// only when user authenticate can remove this veil.
if (isAuthenticationRequired) {
navController.navigate(RouteLockScreen())
unlock()
navController.navigate(RouteLockScreen()) {
launchSingleTop = true
}
}
this@MainActivity.navController = navController
onDispose {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/zs/gallery/common/SystemFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ interface SystemFacade {
*
* @param onAuthenticated A callback function that will be executed upon successful authentication.
* @param desc A description of the authentication process. This description will be displayed
* @param subtitle A subtitle for the biometric prompt.
*/
@RequiresApi(Build.VERSION_CODES.P)
fun authenticate(desc: String? = null, onAuthenticated: () -> Unit)
fun authenticate(subtitle: String? = null, desc: String? = null, onAuthenticated: () -> Unit)

/**
* Guides the user to the system settings for biometric enrollment.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/zs/gallery/common/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ val NavHostController.current
/**
* Extracts the domain portion from a [NavDestination]'s route.
*
* The domain is considered to be the part ofthe route before the first '/'.
* The domain is considered to be the part of the route before the first '/'.
* For example, for the route "settings/profile", the domain would be "settings".
*
* @return The domain portion of the route, or null if the route is null or does not contain a '/'.
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/com/zs/gallery/impl/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ abstract class MainViewModel<T>(
val data = selected.toLongArray()
// Clear the selected items list.
selected.clear()
Log.d(TAG, "consume: ${data.size}")
return data
}

Expand Down Expand Up @@ -233,6 +234,7 @@ abstract class MainViewModel<T>(
if (isTrashEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
trash(activity)
else {
Log.d(TAG, "remove: ${selected.size}")
delete(activity)
}
}
Expand All @@ -241,10 +243,10 @@ abstract class MainViewModel<T>(
viewModelScope.launch {
val result = runCatching(TAG) {
// Get the selected items for deletion
val selected = consume()
val consumed = consume()
// For Android R and above, use the provider's delete function directly
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
return@runCatching provider.delete(activity, *selected)
return@runCatching provider.delete(activity, *consumed)
// For versions below Android R, show a confirmation toast
// If the user performs the action, proceed with deletion
// Otherwise, return -3 to indicate user cancellation
Expand All @@ -257,17 +259,18 @@ abstract class MainViewModel<T>(
)
// Delete the selected items
// else return -3 to indicate user cancellation
return@runCatching if (action == Toast.ACTION_PERFORMED)
provider.delete(*selected)
else
-3
if (action == Toast.ACTION_PERFORMED)
return@runCatching provider.delete(*consumed)
// else return user cancelled
-3
}
// Display a message based on the result of the deletion operation.
if (result == null || result == 0 || result == -1)
showToast(R.string.msg_files_delete_unknown_error)// General error
}
}


override fun share(activity: Activity) {
viewModelScope.launch {
// Get the list of selected items to share.
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/res/drawable/gallery_splash_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="288dp"
android:height="288dp"
android:viewportWidth="288"
android:viewportHeight="288">
<path
android:pathData="M178.68,112.63C178.89,112.9 178.84,113.22 178.84,113.52C178.84,120.3 178.84,127.07 178.84,133.85C178.84,137.72 176.2,140.36 172.34,140.38C170.93,140.38 169.53,140.41 168.12,140.43C167.79,140.43 167.46,140.4 167.13,140.4C154.2,140.4 141.27,140.4 128.34,140.4C127.65,140.41 126.96,140.32 126.29,140.15C123.82,139.5 121.24,137.18 121.75,132.9C121.83,132.84 121.91,132.77 121.99,132.7L144.28,110.42C144.44,110.26 144.62,110.11 144.65,109.86C144.99,109.81 145.15,109.52 145.36,109.31C148.79,105.88 152.29,102.51 155.64,98.99C158.19,96.3 162.35,96.22 165.02,98.99C168.58,102.69 172.26,106.27 175.9,109.9C176.82,110.82 177.75,111.72 178.68,112.63Z"
android:fillColor="#59D86B"/>
<path
android:pathData="M178.68,112.63C177.75,111.72 176.82,110.82 175.9,109.9C172.26,106.27 168.58,102.69 165.02,98.99C162.36,96.22 158.19,96.3 155.64,98.99C152.29,102.51 148.79,105.88 145.36,109.31C145.15,109.51 144.99,109.81 144.65,109.86C142.66,107.43 140.68,104.99 138.69,102.56C137.37,100.96 135.62,100.45 133.62,100.71C131.98,100.93 130.68,101.8 129.52,102.95C126.93,105.53 124.34,108.1 121.74,110.68C121.73,110.37 121.71,110.06 121.71,109.76C121.71,100.6 121.71,91.44 121.71,82.28C121.71,81.95 121.69,81.62 121.68,81.29C121.87,78.39 123.27,76.38 126.06,75.43C126.69,75.23 127.35,75.14 128.02,75.15C142.82,75.15 157.63,75.15 172.44,75.15C175.97,75.15 178.69,77.79 178.7,81.25C178.72,91.61 178.72,101.96 178.7,112.32C178.71,112.43 178.69,112.53 178.68,112.63ZM146.77,81.3C145.37,81.3 144.01,81.71 142.85,82.49C141.69,83.26 140.79,84.36 140.25,85.65C139.72,86.94 139.58,88.35 139.85,89.72C140.12,91.09 140.79,92.35 141.77,93.34C142.76,94.32 144.01,95 145.38,95.27C146.74,95.55 148.16,95.41 149.45,94.88C150.74,94.35 151.85,93.45 152.63,92.3C153.4,91.14 153.82,89.78 153.83,88.38C153.83,86.51 153.09,84.71 151.77,83.38C150.44,82.05 148.65,81.3 146.77,81.3Z"
android:fillColor="#00A0FE"/>
<path
android:pathData="M121.69,81.3C121.7,81.63 121.72,81.96 121.72,82.29C121.72,91.45 121.72,100.61 121.72,109.77C121.72,110.07 121.74,110.38 121.75,110.68C121.77,110.99 121.72,111.3 121.72,111.6C121.72,117.58 121.72,123.56 121.72,129.54C121.72,130.66 121.74,131.79 121.75,132.91C121.24,137.21 123.82,139.51 126.3,140.16C126.96,140.34 127.65,140.42 128.34,140.42C141.27,140.42 154.2,140.42 167.13,140.42C167.46,140.42 167.79,140.43 168.13,140.44C168.04,141.86 168.29,143.29 167.81,144.69C166.98,147.1 164.62,148.85 162.06,148.85H117.47C114.33,148.85 111.95,146.97 111.24,143.92C111.18,143.62 111.15,143.31 111.16,143.01C111.16,124.39 111.16,105.76 111.16,87.14C111.16,84.48 113.33,81.91 115.96,81.45C117.85,81.12 119.78,81.39 121.69,81.3Z"
android:fillColor="#D9EDFE"/>
<path
android:pathData="M121.75,132.9C121.75,131.77 121.72,130.65 121.72,129.53C121.72,123.55 121.72,117.57 121.72,111.59C121.72,111.29 121.74,110.98 121.76,110.68C124.35,108.1 126.94,105.52 129.53,102.95C130.68,101.8 131.97,100.93 133.63,100.71C135.63,100.45 137.38,100.96 138.7,102.56C140.7,104.99 142.67,107.43 144.66,109.86C144.63,110.11 144.46,110.27 144.29,110.42L121.99,132.71C121.91,132.77 121.83,132.84 121.75,132.9Z"
android:fillColor="#0ECE75"/>
<path
android:pathData="M146.77,81.3C148.17,81.29 149.53,81.71 150.7,82.48C151.86,83.26 152.76,84.37 153.3,85.66C153.83,86.95 153.97,88.37 153.7,89.74C153.42,91.11 152.74,92.37 151.75,93.36C150.76,94.34 149.5,95.01 148.13,95.28C146.76,95.55 145.34,95.4 144.05,94.86C142.76,94.32 141.66,93.41 140.89,92.25C140.12,91.08 139.71,89.71 139.72,88.32C139.73,86.45 140.48,84.67 141.8,83.36C143.12,82.04 144.9,81.3 146.77,81.3Z"
android:fillColor="#FDFEFE"/>
<path
android:pathData="M105.05,189.43H109.66C110.6,189.46 111.17,189.71 111.38,190.16C111.56,190.49 111.64,190.98 111.64,191.63V197.39C111.64,197.95 111.4,198.48 110.91,198.98C109.45,200.5 107.25,201.26 104.32,201.26C101.71,201.26 99.45,200.28 97.53,198.33C95.61,196.36 94.65,193.98 94.65,191.21C94.65,188.43 95.63,186.12 97.59,184.27C99.54,182.4 101.85,181.47 104.5,181.47C106.56,181.47 108.5,182.15 110.34,183.51C110.81,183.86 111.04,184.25 111.04,184.69C111.04,185.11 110.84,185.6 110.44,186.16C109.76,187.08 109.14,187.54 108.58,187.54C108.25,187.54 107.72,187.31 106.99,186.84C106.25,186.35 105.38,186.1 104.37,186.1C103.04,186.1 101.86,186.57 100.83,187.52C99.8,188.44 99.29,189.66 99.29,191.18C99.29,192.68 99.81,193.97 100.86,195.03C101.91,196.08 103.09,196.6 104.42,196.6C105.38,196.6 106.24,196.45 107.01,196.13V193.28H104.94C104.4,193.28 104.02,193.21 103.79,193.07C103.56,192.93 103.42,192.73 103.35,192.46C103.28,192.19 103.24,191.82 103.24,191.37C103.24,190.9 103.28,190.52 103.35,190.24C103.43,189.96 103.58,189.77 103.79,189.66C104.11,189.51 104.52,189.43 105.05,189.43ZM122.69,188.67C122.79,187.69 123.48,187.2 124.76,187.2C125.44,187.2 125.94,187.26 126.28,187.36C126.61,187.46 126.83,187.65 126.96,187.91C127.1,188.17 127.18,188.41 127.19,188.62C127.23,188.81 127.25,189.11 127.25,189.51V198.67C127.25,199.07 127.23,199.38 127.19,199.59C127.18,199.78 127.11,200.01 126.98,200.27C126.74,200.72 126.14,200.95 125.18,200.95C124.23,200.95 123.6,200.83 123.27,200.61C122.95,200.36 122.77,200.01 122.72,199.56C122.07,200.49 120.99,200.95 119.47,200.95C117.97,200.95 116.57,200.26 115.28,198.88C113.99,197.5 113.34,195.9 113.34,194.09C113.34,192.26 113.99,190.66 115.28,189.3C116.59,187.92 118.02,187.23 119.57,187.23C120.17,187.23 120.71,187.33 121.2,187.54C121.69,187.75 122.03,187.95 122.22,188.15C122.41,188.32 122.57,188.49 122.69,188.67ZM117.93,194.12C117.93,194.69 118.15,195.21 118.61,195.68C119.06,196.14 119.61,196.37 120.25,196.37C120.9,196.37 121.43,196.13 121.85,195.66C122.29,195.19 122.51,194.67 122.51,194.12C122.51,193.54 122.3,193.01 121.88,192.52C121.48,192.03 120.93,191.79 120.23,191.79C119.55,191.79 118.99,192.03 118.55,192.52C118.13,193.01 117.93,193.54 117.93,194.12ZM134.15,196.37C134.73,196.37 135.15,196.51 135.43,196.81C135.71,197.11 135.85,197.72 135.85,198.64C135.85,199.57 135.7,200.19 135.4,200.5C135.11,200.8 134.68,200.95 134.12,200.95C132.36,200.95 131.12,200.53 130.4,199.69C129.69,198.84 129.33,197.42 129.33,195.45V182.96C129.33,182.56 129.34,182.26 129.36,182.07C129.39,181.86 129.47,181.63 129.59,181.37C129.84,180.91 130.52,180.68 131.63,180.68C132.7,180.68 133.36,180.93 133.63,181.42C133.76,181.66 133.84,181.89 133.86,182.1C133.9,182.29 133.91,182.59 133.91,182.99V195.55C133.91,196.1 133.99,196.37 134.15,196.37ZM140.98,195.55C140.98,195.89 141.05,196.1 141.19,196.21C141.33,196.31 141.69,196.37 142.26,196.37C142.84,196.37 143.32,196.51 143.7,196.81C144.09,197.11 144.28,197.72 144.28,198.64C144.28,199.57 144.07,200.19 143.65,200.5C143.25,200.8 142.68,200.95 141.95,200.95C138.25,200.95 136.4,199.12 136.4,195.45L136.37,182.96C136.37,182.56 136.38,182.26 136.4,182.07C136.43,181.86 136.52,181.63 136.66,181.37C136.92,180.91 137.6,180.68 138.7,180.68C139.77,180.68 140.43,180.93 140.69,181.42C140.89,181.8 140.98,182.32 140.98,182.99V195.55ZM159.02,192.46C159.02,193.53 158.75,194.32 158.21,194.85C157.68,195.35 157.1,195.61 156.45,195.61H150.25C150.25,196.1 150.54,196.51 151.11,196.84C151.69,197.17 152.26,197.34 152.84,197.34C153.85,197.34 154.65,197.23 155.22,197.02L155.51,196.92C155.93,196.72 156.28,196.63 156.56,196.63C157.12,196.63 157.6,197.02 158,197.81C158.23,198.28 158.34,198.68 158.34,199.01C158.34,200.56 156.48,201.34 152.76,201.34C151.47,201.34 150.32,201.12 149.31,200.69C148.31,200.23 147.54,199.64 146.98,198.91C145.88,197.49 145.33,195.91 145.33,194.17C145.33,191.97 146.03,190.21 147.45,188.9C148.88,187.58 150.66,186.91 152.79,186.91C155.21,186.91 156.99,187.77 158.13,189.48C158.72,190.39 159.02,191.38 159.02,192.46ZM153.49,193.23C154.16,193.23 154.49,192.95 154.49,192.39C154.49,191.99 154.33,191.66 154.02,191.42C153.72,191.17 153.29,191.05 152.71,191.05C152.15,191.05 151.59,191.29 151.03,191.76C150.48,192.21 150.2,192.7 150.2,193.23H153.49ZM170.1,187.36C170.43,187.46 170.7,187.65 170.91,187.91C171.14,188.15 171.25,188.56 171.25,189.11C171.25,189.67 171.09,190.28 170.75,190.95C170.42,191.61 169.94,191.94 169.31,191.94C169,191.94 168.69,191.87 168.4,191.73C168.12,191.59 167.74,191.52 167.27,191.52C166.8,191.52 166.35,191.69 165.94,192.02C165.54,192.35 165.33,192.75 165.33,193.23V198.72C165.33,199.12 165.32,199.43 165.28,199.64C165.26,199.83 165.19,200.06 165.05,200.32C164.79,200.77 164.1,201 163,201C162.17,201 161.57,200.85 161.2,200.55C160.92,200.31 160.76,199.93 160.73,199.43C160.73,199.26 160.73,199 160.73,198.67V189.48C160.73,189.08 160.74,188.78 160.75,188.59C160.79,188.38 160.87,188.15 160.99,187.91C161.23,187.44 161.91,187.2 163.03,187.2C164.08,187.2 164.73,187.4 164.99,187.8C165.19,188.09 165.28,188.37 165.28,188.67C165.37,188.55 165.49,188.4 165.65,188.22C165.82,188.05 166.18,187.81 166.72,187.52C167.26,187.22 167.73,187.07 168.14,187.07C168.55,187.07 168.9,187.1 169.18,187.15C169.46,187.19 169.77,187.26 170.1,187.36ZM185.52,187.36C186.55,187.81 187.07,188.36 187.07,189.01C187.07,189.32 186.99,189.62 186.85,189.9C186.71,190.18 186.65,190.33 186.65,190.35L179.79,205.69C179.65,206.02 179.52,206.27 179.42,206.45C179.33,206.62 179.18,206.79 178.98,206.94C178.77,207.1 178.5,207.18 178.19,207.18C177.88,207.18 177.41,207.05 176.8,206.79C175.77,206.33 175.26,205.79 175.26,205.16C175.26,204.74 176.1,202.74 177.77,199.17L172.56,190.4C172.21,189.82 172.04,189.39 172.04,189.11C172.04,188.56 172.51,188 173.45,187.44C174.04,187.09 174.51,186.91 174.84,186.91C175.17,186.91 175.44,186.99 175.65,187.13C175.86,187.26 176.01,187.41 176.1,187.57C176.2,187.71 176.68,188.52 177.54,190C178.41,191.47 179.24,192.84 180.02,194.12C180.11,193.84 180.58,192.76 181.44,190.9C182.29,189.01 182.74,188.01 182.8,187.88C182.87,187.76 182.97,187.61 183.11,187.44C183.34,187.14 183.65,186.99 184.05,186.99C184.47,186.99 184.96,187.12 185.52,187.36Z"
android:fillColor="#808080"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<item name="postSplashScreenTheme">@style/Theme.Gallery</item>
<item name="windowSplashScreenBackground">@android:color/black</item>
<item name="isLightTheme">false</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/gallery_splash_icon</item>
<item name="android:windowSplashScreenBrandingImage" tools:ignore="NewApi">@drawable/logo_dark</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
Expand Down

0 comments on commit 2b08c97

Please sign in to comment.