-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add push notification about new updates (#735)
**Background** Right now users want recieve notification about new updates in firmware channel **Changes** - Add notification enable dialog - Add row in settings app category **Test plan** Try enable notification via app and via settings
- Loading branch information
Showing
74 changed files
with
2,991 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id("flipper.android-lib") | ||
} | ||
|
||
android.namespace = "com.flipperdevices.core.permission.api" | ||
|
||
dependencies { | ||
} |
7 changes: 7 additions & 0 deletions
7
...sion/api/src/main/java/com/flipperdevices/core/permission/api/PermissionRequestHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.flipperdevices.core.permission.api | ||
|
||
typealias PermissionListener = (String, Boolean) -> Unit | ||
|
||
interface PermissionRequestHandler { | ||
fun requestPermission(vararg permissions: String, listener: PermissionListener) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
plugins { | ||
id("flipper.android-lib") | ||
id("flipper.anvil") | ||
} | ||
|
||
android.namespace = "com.flipperdevices.core.permission.impl" | ||
|
||
dependencies { | ||
implementation(projects.components.core.di) | ||
implementation(projects.components.core.permission.api) | ||
|
||
implementation(libs.dagger) | ||
implementation(libs.appcompat) | ||
|
||
implementation(libs.ktx.activity) | ||
} |
73 changes: 73 additions & 0 deletions
73
...mpl/src/main/java/com/flipperdevices/core/permission/impl/PermissionRequestHandlerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.flipperdevices.core.permission.impl | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.os.Bundle | ||
import androidx.activity.result.ActivityResultCallback | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.flipperdevices.core.di.AppGraph | ||
import com.flipperdevices.core.permission.api.PermissionListener | ||
import com.flipperdevices.core.permission.api.PermissionRequestHandler | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
@ContributesBinding(AppGraph::class, PermissionRequestHandler::class) | ||
class PermissionRequestHandlerImpl @Inject constructor() : | ||
PermissionRequestHandler, | ||
Application.ActivityLifecycleCallbacks, | ||
ActivityResultCallback<Map<String, @JvmSuppressWildcards Boolean>> { | ||
|
||
private var permissionRequest: ActivityResultLauncher<Array<String>>? = null | ||
private val permissionPendingListeners = mutableMapOf<String, List<PermissionListener>>() | ||
|
||
fun register(application: Application) { | ||
application.registerActivityLifecycleCallbacks(this) | ||
} | ||
|
||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { | ||
if (activity is AppCompatActivity) { | ||
permissionRequest = activity.registerForActivityResult( | ||
ActivityResultContracts.RequestMultiplePermissions(), this | ||
) | ||
} | ||
} | ||
|
||
override fun onActivityDestroyed(activity: Activity) { | ||
permissionRequest = null | ||
permissionPendingListeners.clear() | ||
} | ||
|
||
override fun onActivityResult(result: Map<String, Boolean>) { | ||
result.forEach { (permission, result) -> | ||
permissionPendingListeners.remove(permission)?.forEach { listener -> | ||
listener.invoke(permission, result) | ||
} | ||
} | ||
} | ||
|
||
override fun requestPermission(vararg permissions: String, listener: PermissionListener) { | ||
val request = permissionRequest | ||
if (request == null) { | ||
permissions.forEach { | ||
listener(it, false) | ||
} | ||
return | ||
} | ||
permissions.forEach { permission -> | ||
val currentList = permissionPendingListeners.getOrDefault(permission, listOf()) | ||
permissionPendingListeners[permission] = currentList + listener | ||
} | ||
request.launch(permissions.toList().toTypedArray()) | ||
} | ||
|
||
// Unused fun | ||
override fun onActivityResumed(activity: Activity) = Unit | ||
override fun onActivityStarted(activity: Activity) = Unit | ||
override fun onActivityPaused(activity: Activity) = Unit | ||
override fun onActivityStopped(activity: Activity) = Unit | ||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...flipperdevices/inappnotification/impl/composable/type/ComposableInAppNotificationError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.flipperdevices.inappnotification.impl.composable.type | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.flipperdevices.core.ui.theme.FlipperThemeInternal | ||
import com.flipperdevices.core.ui.theme.LocalPallet | ||
import com.flipperdevices.core.ui.theme.LocalTypography | ||
import com.flipperdevices.inappnotification.api.model.InAppNotification | ||
import com.flipperdevices.inappnotification.impl.R | ||
|
||
@Composable | ||
internal fun ComposableInAppNotificationError( | ||
error: InAppNotification.Error, | ||
onClickAction: () -> Unit | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(12.dp), | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Image( | ||
modifier = Modifier.size(24.dp), | ||
painter = painterResource(id = R.drawable.pic_update_error), | ||
contentDescription = stringResource(error.titleId), | ||
) | ||
Column(Modifier.weight(1f)) { | ||
Text( | ||
text = stringResource(error.titleId), | ||
style = LocalTypography.current.subtitleB12 | ||
) | ||
Text( | ||
text = stringResource(error.descId), | ||
style = LocalTypography.current.subtitleR12 | ||
) | ||
} | ||
val actionTextId = error.actionTextId | ||
val action = error.action | ||
if (actionTextId != null && action != null) { | ||
Text( | ||
modifier = Modifier | ||
.padding(start = 12.dp) | ||
.clickable { | ||
action() | ||
onClickAction() | ||
}, | ||
text = stringResource(actionTextId), | ||
style = LocalTypography.current.subtitleM12, | ||
color = LocalPallet.current.accentSecond | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun ComposableInAppNotificationErrorPreview() { | ||
FlipperThemeInternal { | ||
ComposableInAppNotificationError( | ||
error = InAppNotification.Error( | ||
titleId = R.string.hide_app_title, | ||
descId = R.string.hide_app_desc, | ||
actionTextId = null, | ||
action = null | ||
), | ||
onClickAction = {} | ||
) | ||
} | ||
} |
Oops, something went wrong.