Skip to content

Commit

Permalink
Merge branch 'develop' into feature/ALTAPPS-960/Shared-Send-user-time…
Browse files Browse the repository at this point in the history
…-zone-to-api-notifications-set-time
  • Loading branch information
XanderZhu committed Sep 27, 2023
2 parents 8423402 + 1512307 commit 98e21a1
Show file tree
Hide file tree
Showing 37 changed files with 538 additions and 102 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/android_beta_deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Gradle Wrapper Validation
uses: gradle/[email protected]
Expand All @@ -36,7 +36,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/android_release_deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Gradle Wrapper Validation
uses: gradle/[email protected]
Expand All @@ -39,7 +39,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand All @@ -64,7 +64,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_caches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
uses: ./.github/actions/setup-android
Expand All @@ -55,7 +55,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cleanup_pr_caches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Cleanup
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Detect changes
uses: dorny/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh_pages_analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
uses: ./.github/actions/setup-android
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle_wrapper_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Gradle Wrapper Validation
uses: gradle/[email protected]
4 changes: 2 additions & 2 deletions .github/workflows/ios_beta_deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Gradle Wrapper Validation
uses: gradle/[email protected]
Expand All @@ -36,7 +36,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ios_release_deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Gradle Wrapper Validation
uses: gradle/[email protected]
Expand All @@ -36,7 +36,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
uses: ./.github/actions/setup-android
Expand All @@ -59,7 +59,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup Ruby
uses: ruby/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/merge_main_into_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0
with:
fetch-depth: 0
token: ${{ secrets.GH_PAT }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand All @@ -69,7 +69,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand All @@ -93,7 +93,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
uses: actions/checkout@v4.1.0

- name: Setup CI
id: setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,48 @@ import android.content.pm.PackageManager
import android.os.Build
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment

class NotificationPermissionDelegate(
private val fragment: Fragment
private val fragment: Fragment,
private val onResult: ((Result) -> Unit)
) {
private var onResult: ((Result) -> Unit)? = null

companion object {
private const val SAVED_STATE_PROVIDER_KEY = "NOTIFICATION_PERMISSION_DELEGATE"
private const val SHOULD_SHOW_REQUEST_PERMISSION_RATIONALE_BEFORE =
"SHOULD_SHOW_REQUEST_PERMISSION_RATIONALE_BEFORE"
}

private var shouldShowRequestPermissionRationaleBefore: Boolean = false

init {
this.shouldShowRequestPermissionRationaleBefore =
fragment.savedStateRegistry.consumeRestoredStateForKey(SAVED_STATE_PROVIDER_KEY)
?.getBoolean(SHOULD_SHOW_REQUEST_PERMISSION_RATIONALE_BEFORE, false)
?: false
fragment.savedStateRegistry.registerSavedStateProvider(SAVED_STATE_PROVIDER_KEY) {
bundleOf(SHOULD_SHOW_REQUEST_PERMISSION_RATIONALE_BEFORE to shouldShowRequestPermissionRationaleBefore)
}
}

private val notificationPermissionCallback = fragment.registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isNotificationPermissionGranted ->
val result = when {
isNotificationPermissionGranted -> Result.GRANTED
// User denied permission another time
// System request was shown for the last time
shouldShowRequestPermissionRationaleBefore &&
!fragment.shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS) -> Result.DENIED
!fragment.shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS) -> Result.DONT_ASK
else -> Result.DENIED
}
onResult?.invoke(result)
onResult.invoke(result)
}

fun requestNotificationPermission(onResult: (Result) -> Unit) {
fun requestNotificationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val notificationPermissionGranted =
ContextCompat.checkSelfPermission(
Expand All @@ -33,7 +56,8 @@ class NotificationPermissionDelegate(
if (notificationPermissionGranted) {
onResult(Result.GRANTED)
} else {
this.onResult = onResult
shouldShowRequestPermissionRationaleBefore =
fragment.shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)
notificationPermissionCallback.launch(Manifest.permission.POST_NOTIFICATIONS)
}
} else {
Expand Down
Loading

0 comments on commit 98e21a1

Please sign in to comment.