Skip to content

Commit

Permalink
[FIX] Replaced the ic_splash.png with a relevant one for v24. The o…
Browse files Browse the repository at this point in the history
…ld one was not consistent with the original.

[FEAT] Updated `Toast`.kt to use priority instead of `duration`. The priority now has four values: `low`, `medium`, `high`, and `critical`. The critical priority displays a non-swipeable `toast` in `expanded` form.
  • Loading branch information
iZakirSheikh committed Nov 13, 2024
1 parent 6370a29 commit 34348af
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 118 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ android {
applicationId = "com.prime.player"
minSdk = 21
targetSdk = 35
versionCode = 159
versionName = "3.0.1"
versionCode = 160
versionName = "3.0.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { useSupportLibrary = true }
// init different config fields.
Expand Down
39 changes: 17 additions & 22 deletions app/src/main/java/com/prime/media/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
val res = toastHostState.showToast(
"Restart the app for changes to take effect.",
"Restart",
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_HIGH
)
// Restart the app if the user chooses to
if (res == Toast.ACTION_PERFORMED)
Expand Down Expand Up @@ -266,20 +266,15 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList

@Suppress("UNCHECKED_CAST")
override fun <T> getDeviceService(name: String): T = getSystemService(name) as T
override fun showToast(
message: CharSequence,
icon: ImageVector?,
accent: Color,
duration: Int
) {
override fun showToast(message: CharSequence, icon: ImageVector?, accent: Color, priority: Int) {
lifecycleScope.launch {
toastHostState.showToast(message, null, icon, accent, duration)
toastHostState.showToast(message, null, icon, accent, priority)
}
}

override fun showToast(message: Int, icon: ImageVector?, accent: Color, duration: Int) {
override fun showToast(message: Int, icon: ImageVector?, accent: Color, priority: Int) {
lifecycleScope.launch {
toastHostState.showToast(resources.getText2(id = message), null, icon, accent, duration)
toastHostState.showToast(resources.getText2(id = message), null, icon, accent, priority)
}
}

Expand Down Expand Up @@ -357,7 +352,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
val res = toastHostState.showToast(
message = resources.getText2(R.string.msg_new_update_downloaded),
action = resources.getText2(R.string.install),
duration = Toast.DURATION_INDEFINITE,
priority = Toast.PRIORITY_HIGH,
accent = Color.MetroGreen,
icon = Icons.Outlined.Downloading
)
Expand Down Expand Up @@ -484,7 +479,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
),
icon = Icons.Outlined.AdsClick,
action = getString(R.string.claim).uppercase(),
duration = Toast.DURATION_INDEFINITE,
priority = Toast.PRIORITY_HIGH,
accent = Color.MetroGreen2
)
if (result == Toast.ACTION_PERFORMED) {
Expand Down Expand Up @@ -518,7 +513,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
remaining
),
icon = Icons.Outlined.AdsClick,
duration = Toast.DURATION_INDEFINITE,
priority = Toast.PRIORITY_HIGH,
accent = Color.MetroGreen,
)
}
Expand Down Expand Up @@ -588,7 +583,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
val result = toastHostState.showToast(
info.richDesc,
action = info.formattedPrice ?: "N/A",
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_CRITICAL
)
if (result == Toast.ACTION_PERFORMED)
initiatePurchaseFlow(BuildConfig.IAP_NO_ADS)
Expand All @@ -602,7 +597,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
val result = toastHostState.showToast(
info.richDesc,
action = info.formattedPrice ?: "N/A",
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_CRITICAL
)
if (result == Toast.ACTION_PERFORMED)
initiatePurchaseFlow(BuildConfig.IAP_CODEX)
Expand All @@ -616,7 +611,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
val result = toastHostState.showToast(
info.richDesc,
action = info.formattedPrice ?: getText(R.string.abbr_not_available),
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_CRITICAL
)
if (result == Toast.ACTION_PERFORMED)
initiatePurchaseFlow(BuildConfig.IAP_BUY_ME_COFFEE)
Expand All @@ -630,7 +625,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
val result = toastHostState.showToast(
info.richDesc,
action = info.formattedPrice ?: getText(R.string.abbr_not_available),
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_CRITICAL
)
if (result == Toast.ACTION_PERFORMED)
initiatePurchaseFlow(BuildConfig.IAP_TAG_EDITOR_PRO)
Expand All @@ -645,7 +640,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
val result = toastHostState.showToast(
resources.getText2(R.string.msg_promotion_gallery_app),
action = resources.getText2(R.string.dive_in),
duration = Toast.DURATION_INDEFINITE,
priority = Toast.PRIORITY_CRITICAL,
accent = Color.Amber,
icon = Icons.Outlined.GetApp
)
Expand All @@ -656,8 +651,8 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
// promo message for widgets.
5 -> {
val result = toastHostState.showToast(
"Personalize your app now with in-app widgets!",
duration = Toast.DURATION_INDEFINITE,
resources.getText2(R.string.msg_promo_personalize),
priority = Toast.PRIORITY_CRITICAL,
accent = Color.MetroGreen,
icon = Icons.Outlined.ColorLens,
action = "View"
Expand Down Expand Up @@ -712,7 +707,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
id = R.string.msg_install_dynamic_module_ss,
details.title
),
duration = Toast.DURATION_INDEFINITE,
priority = Toast.PRIORITY_HIGH,
action = resources.getText2(R.string.install)
)
if (response == Toast.ACTION_PERFORMED)
Expand All @@ -737,7 +732,7 @@ class MainActivity : ComponentActivity(), SystemFacade, OnDestinationChangedList
preferences[KEY_APP_VERSION_CODE] = versionCode
showToast(
R.string.what_s_new_toast,
duration = Toast.DURATION_INDEFINITE,
priority = Toast.PRIORITY_HIGH,
icon = Icons.Outlined.Whatshot
)
}
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/java/com/prime/media/common/SystemFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package com.prime.media.common

import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.util.Log
Expand All @@ -24,7 +23,7 @@ import com.prime.media.MainActivity
import com.primex.preferences.Key
import com.zs.core.paymaster.Purchase
import com.zs.core_ui.WindowStyle
import com.zs.core_ui.toast.Duration
import com.zs.core_ui.toast.Priority
import com.zs.core_ui.toast.Toast
import kotlinx.coroutines.flow.map

Expand Down Expand Up @@ -126,7 +125,7 @@ interface SystemFacade {
message: CharSequence,
icon: ImageVector? = null,
accent: Color = Color.Unspecified,
@Duration duration: Int = Toast.DURATION_SHORT,
@Priority priority: Int = Toast.PRIORITY_LOW,
)

/**
Expand All @@ -136,7 +135,7 @@ interface SystemFacade {
@StringRes message: Int,
icon: ImageVector? = null,
accent: Color = Color.Unspecified,
@Duration duration: Int = Toast.DURATION_SHORT,
@Priority priority: Int = Toast.PRIORITY_LOW,
)

/**
Expand All @@ -161,12 +160,12 @@ interface SystemFacade {
/**
* @see com.zs.core_ui.showPlatformToast
*/
fun showPlatformToast(message: String, @Duration duration: Int = Toast.DURATION_SHORT)
fun showPlatformToast(message: String, @Priority priority: Int = Toast.PRIORITY_LOW)

/**
* @see com.zs.core_ui.showPlatformToast
*/
fun showPlatformToast(@StringRes message: Int, @Duration duration: Int = Toast.DURATION_SHORT)
fun showPlatformToast(@StringRes message: Int, @Priority priority: Int = Toast.PRIORITY_LOW)

/**
* Returns the handle to a system-level service by name.
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/com/prime/media/impl/KoinViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.primex.core.OrientRed
import com.primex.core.getText2
import com.primex.core.withSpanStyle
import com.primex.preferences.Preferences
import com.zs.core_ui.toast.Duration
import com.zs.core_ui.toast.Priority
import com.zs.core_ui.toast.Result
import com.zs.core_ui.toast.Toast
import com.zs.core_ui.toast.ToastHostState
Expand All @@ -62,34 +62,34 @@ abstract class KoinViewModel : ScopeViewModel() {

fun showPlatformToast(
@StringRes message: Int,
@Duration duration: Int = Toast.DURATION_SHORT
) = context.showAndroidToast(message, duration)
@Priority priority: Int = Toast.PRIORITY_LOW
) = context.showAndroidToast(message, priority)

fun showPlatformToast(
message: String,
@Duration duration: Int = Toast.DURATION_SHORT
) = context.showAndroidToast(message, duration)
@Priority priority: Int = Toast.PRIORITY_LOW
) = context.showAndroidToast(message, priority)

suspend fun showToast(
message: CharSequence,
action: CharSequence? = null,
icon: ImageVector? = null,
accent: Color = Color.Unspecified,
@Duration duration: Int = if (action == null) Toast.DURATION_SHORT else Toast.DURATION_INDEFINITE
): @Result Int = toastHostState.showToast(message, action, icon, accent, duration)
@Priority priority: Int = if (action == null) Toast.PRIORITY_LOW else Toast.PRIORITY_HIGH
): @Result Int = toastHostState.showToast(message, action, icon, accent, priority)

suspend fun showToast(
@StringRes message: Int,
@StringRes action: Int = ResourcesCompat.ID_NULL,
icon: ImageVector? = null,
accent: Color = Color.Unspecified,
@Duration duration: Int = if (action == ResourcesCompat.ID_NULL) Toast.DURATION_SHORT else Toast.DURATION_INDEFINITE
@Priority priority: Int = if (action == ResourcesCompat.ID_NULL) Toast.PRIORITY_LOW else Toast.PRIORITY_HIGH
): @Result Int = showToast(
message = resources.getText2(message),
action = if (action == ResourcesCompat.ID_NULL) null else resources.getText2(action),
icon = icon,
accent = accent,
duration = duration
priority = priority
)

fun getText(@StringRes id: Int): CharSequence = resources.getText2(id)
Expand All @@ -109,7 +109,7 @@ abstract class KoinViewModel : ScopeViewModel() {
action = "REPORT",
icon = Icons.Outlined.Error,
accent = Color.OrientRed,
duration = Toast.DURATION_LONG
priority = Toast.PRIORITY_MEDIUM
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PlaylistsViewModel(val playlists: Playlists) : KoinViewModel(), PlaylistsV
action = "Delete",
icon = Icons.Outlined.FolderDelete,
accent = Color.RedViolet,
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_HIGH
)
if (result != Toast.ACTION_PERFORMED) return@launch
// Attempt to delete the playlist from the data source (e.g., database).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ fun SystemFacade.launchEqualizer(id: Int) {
showToast(
message = R.string.msg_3rd_party_equalizer_not_found,
accent = Color.OrientRed,
duration = Toast.DURATION_SHORT
priority = Toast.PRIORITY_LOW
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.prime.media.R
import com.prime.media.old.common.Artwork
import com.prime.media.common.composable
import com.prime.media.old.common.composable
import com.prime.media.old.common.util.addDistinct
import com.prime.media.old.common.util.toMediaItem
Expand Down Expand Up @@ -131,7 +130,7 @@ class MembersViewModel(
"Error",
icon = Icons.Outlined.Error,
accent = Color.Rose,
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_HIGH
)
}.stateIn(viewModelScope, SharingStarted.Lazily, emptyMap())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ArtistsViewModel (
"Error\nSome unknown error occured!.",
icon = Icons.Outlined.Error,
accent = Color.Rose,
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_HIGH
)
}
.stateIn(viewModelScope, SharingStarted.Lazily, emptyMap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class AudiosViewModel (
"Error\nSome unknown error occured!. $it",
icon = Icons.Outlined.Error,
accent = Color.Rose,
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_HIGH
)
}
.stateIn(viewModelScope, SharingStarted.Lazily, emptyMap())
Expand Down Expand Up @@ -509,10 +509,10 @@ class AudiosViewModel (
"Delete",
icon = Icons.Outlined.WarningAmber,
accent = Color.Rose,
Toast.DURATION_INDEFINITE
Toast.PRIORITY_HIGH
)
// check if user is interested in deleting the files or not.
if (res == Toast.RESULT_DISMISSED)
if (res == Toast.ACTION_DISMISSED)
return@launch
// return
repository.delete(activity, *uris.toTypedArray(), trash = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class FoldersViewModel (
"Error\nSome unknown error occured!. ${it.message}",
icon = Icons.Outlined.Error,
accent = Color.Rose,
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_HIGH
)
}
.stateIn(viewModelScope, SharingStarted.Lazily, emptyMap())
Expand All @@ -134,17 +134,17 @@ class FoldersViewModel (
"Warning\nYou are about to block folder $name",
icon = Icons.Outlined.Block,
accent = Color.DahliaYellow,
duration = Toast.DURATION_INDEFINITE,
priority = Toast.PRIORITY_HIGH,
)
if (response == Toast.RESULT_DISMISSED)
if (response == Toast.ACTION_DISMISSED)
return@launch
val result = preferences.block(path)
if (result > 0)
showToast(
"$name has been added to block list",
icon = Icons.Outlined.Block,
accent = Color.Rose,
duration = Toast.DURATION_SHORT,
priority = Toast.PRIORITY_LOW,
)
else
showToast("Oops! some unknown error has occurred.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class GenresViewModel (
"Error\nSome unknown error occured!.",
icon = Icons.Outlined.Error,
accent = Color.Rose,
duration = Toast.DURATION_INDEFINITE
priority = Toast.PRIORITY_HIGH
)
}
.stateIn(viewModelScope, SharingStarted.Lazily, emptyMap())
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/com/prime/media/old/impl/SystemDelegate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import androidx.annotation.PluralsRes
import androidx.annotation.StringRes
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.core.content.res.ResourcesCompat
import com.primex.core.getQuantityText2
import com.primex.core.getText2
import com.zs.core_ui.toast.Duration
import com.zs.core_ui.toast.Priority
import com.zs.core_ui.toast.Result
import com.zs.core_ui.toast.ToastHostState

Expand Down Expand Up @@ -58,21 +57,21 @@ interface SystemDelegate {
action: CharSequence? = null,
icon: ImageVector? = null,
accent: Color = Color.Unspecified,
@Duration duration: Int = if (action == null) com.zs.core_ui.toast.Toast.DURATION_SHORT else com.zs.core_ui.toast.Toast.DURATION_INDEFINITE
@Priority priority: Int = if (action == null) com.zs.core_ui.toast.Toast.PRIORITY_LOW else com.zs.core_ui.toast.Toast.PRIORITY_HIGH
): @Result Int

suspend fun showSnackbar(
@StringRes message: Int,
@StringRes action: Int = ResourcesCompat.ID_NULL,
icon: ImageVector? = null,
accent: Color = Color.Unspecified,
@Duration duration: Int = if (action == ResourcesCompat.ID_NULL) com.zs.core_ui.toast.Toast.DURATION_SHORT else com.zs.core_ui.toast.Toast.DURATION_INDEFINITE
@Priority priority: Int = if (action == ResourcesCompat.ID_NULL) com.zs.core_ui.toast.Toast.PRIORITY_LOW else com.zs.core_ui.toast.Toast.PRIORITY_HIGH
): @Result Int = showSnackbar(
message = resources.getText2(message),
action = if (action == ResourcesCompat.ID_NULL) null else resources.getText2(action),
icon = icon,
accent = accent,
duration = duration
priority = priority
)
}

Expand Down
Loading

0 comments on commit 34348af

Please sign in to comment.