-
-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
changes to enable unified push notifications in generic build. Signed… #4169
Open
gavine99
wants to merge
1,182
commits into
nextcloud:master
Choose a base branch
from
gavine99:unified_push_nextcloud_notifications
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
1182 commits
Select commit
Hold shift + click to select a range
4c7d105
remove popup bubble dependency
sowjanyakch 9f5fa4a
Analysis: update lint results to reflect reduced error/warning count
invalid-email-address 8d0c948
add animation to "unread mentions" button + change design
mahibi d8bc113
Merge pull request #4474 from nextcloud/popup_bubble
mahibi e5c443c
Fix(l10n): Update translations from Transifex
nextcloud-bot 5fd966f
$s -> $d
tobiasKaminsky 744280a
Fix(l10n): Update translations from Transifex
nextcloud-bot 4547717
Merge pull request #4584 from nextcloud/correctTranslation
mahibi d89393c
Fix(l10n): Update translations from Transifex
nextcloud-bot 47afa10
Update dependency com.android.tools.build:gradle to v8.8.0
renovate[bot] 5887835
Fix(l10n): Update translations from Transifex
nextcloud-bot 46c5b47
Update dependency com.github.spotbugs.snom:spotbugs-gradle-plugin to …
renovate[bot] 0b80573
Merge pull request #4589 from nextcloud/renovate/com.github.spotbugs.…
AndyScherzinger cf2a597
Merge pull request #4588 from nextcloud/renovate/com.android.tools.bu…
AndyScherzinger 2956ca9
Update dependency com.github.spotbugs.snom:spotbugs-gradle-plugin to …
renovate[bot] 8218616
fix translation for polls_option_delete
mahibi 5e72621
Merge pull request #4591 from nextcloud/correctTranslationPollsDelete
mahibi 6d1ffbd
Fix(l10n): Update translations from Transifex
nextcloud-bot d114142
Migrating away from java.util.Date to java.time
rapterjet2004 eae4e43
Small fixes - new theming
rapterjet2004 63cb98e
Deleted old fragment + xml
rapterjet2004 73ed4cb
linter
rapterjet2004 a8f1d37
oops
rapterjet2004 490cd32
Impl changes, unable to replicate 1.)
rapterjet2004 5053c0e
fix SPDX header, remove comments
mahibi 6a01c59
Analysis: update lint results to reflect reduced error/warning count
invalid-email-address a34e0c6
Merge pull request #4552 from nextcloud/issue-4274-migrate-javautil-d…
mahibi 9cb40d4
add referenceId for "normal" sending of chat message
mahibi 3597cf2
use repository in MessageInputViewModel instead datasource
mahibi c33bd99
fixes after some wrong merge after merge conflict
mahibi 80d2e75
WIP add temporary message
mahibi 048551e
temp message is added (values are still wrong)
mahibi 0e682ed
WIP temp messages are replaced when same refId received from sever
mahibi a78c9e1
update temp messages also for initial pull of messages
mahibi e1c1574
show x when sending failed
mahibi 3f5f2f0
works okay (no resend logic yet, offline message mode not reworked)
mahibi 0f53244
prepare to replace no-internet-connection message handling (sorry Jul…
mahibi ec466e5
replace CharSequence with String for sendChatMessage
mahibi 1bfb3ba
WIP add options to temp messages
mahibi f88b1f1
fix after merge conflicts
mahibi 5ac130a
resend queued messages when connection gained
mahibi e9f3863
delete temp messages
mahibi 2c397ad
add manual resend button
mahibi 06c8509
add retry logic for sending messages, hide resend button when offline
mahibi 656be3f
revert ReadStatus SENDING and FAILED
mahibi f62941f
simplify "sent messages are queued" hint
mahibi cca4e69
Skip to send message when device is offline
mahibi 7d9c2fd
simplify to refresh message
mahibi a5049fb
adjust some pixels to avoid jump of message list
mahibi b529d13
delete roomId comments
mahibi 29362fa
add logging for unread messages popup bug
mahibi 0356f5a
fix to not accidentally show unread messages popup
mahibi 8f1f22f
Fix duplicate "Today"-bug
mahibi ab007fc
resolve codacy/ktlint warnings
mahibi 3dca00b
resolve warnings
mahibi 560f955
comment in opHelperFactory
mahibi a58607b
resolve detekt warnings
mahibi 4c79513
add DB migration
mahibi 3fdaa4b
fix parent message for temp messages
mahibi f665b1c
save "silent" in chat messages (incl DB)
mahibi 1731ca0
remove flickering of status icons
mahibi 1504e51
add strings for message status icons
mahibi 3094054
change visibility of temp message actions
mahibi aa5b4d0
remove click listener for failed messages (use default longclick)
mahibi 68065d7
fix lint warning
mahibi cd09636
change icons for message sending and messages sending failed
mahibi 4f4ac5e
Analysis: update lint results to reflect reduced error/warning count
invalid-email-address ca9b3c9
Merge pull request #4590 from nextcloud/renovate/com.github.spotbugs.…
AndyScherzinger 6ed20f4
Update daggerVersion to v2.55
renovate[bot] 88bb5d5
Merge pull request #4422 from nextcloud/feature/4378/addTemporaryMess…
mahibi 60bae87
Merge pull request #4587 from nextcloud/renovate/daggerversion
github-actions[bot] ba29db8
Update github/codeql-action action to v3.28.1
renovate[bot] 38018d1
Update actions/upload-artifact action to v4.6.0
renovate[bot] f829b8a
Merge pull request #4595 from nextcloud/renovate/actions-upload-artif…
AndyScherzinger 85a0f08
Merge pull request #4594 from nextcloud/renovate/github-codeql-action…
AndyScherzinger 7851de6
Fix(l10n): Update translations from Transifex
nextcloud-bot d3b3052
Fix(l10n): Update translations from Transifex
nextcloud-bot 6638f44
Fix(l10n): Update translations from Transifex
nextcloud-bot 36716fa
Weekly 21.0.0 Alpha 09
nextcloud-android-bot f0d7ff5
Fix(l10n): Update translations from Transifex
nextcloud-bot 19aec54
figured it out - was an error with offline conversations not syncing.…
rapterjet2004 f39b1dd
Merge pull request #4567 from nextcloud/issue-4454-fix-msg-input-frag…
mahibi 172eddb
Fix(l10n): Update translations from Transifex
nextcloud-bot db8c4de
fix to not cut off unread mentions bubble
mahibi 4045f8f
🔄 synced local '.github/workflows/' with remote 'config/workflows/'
nextcloud-android-bot 209a616
Merge pull request #4603 from nextcloud/bugfix/4599/unreadMentionCutoff
AndyScherzinger fdb38de
Merge pull request #4604 from nextcloud/repo-sync/android-config/master
AndyScherzinger 6c67bf7
timeout option immediate
parneet-guraya 6241c68
Merge pull request #4204 from nextcloud/timeout-immediate
mahibi 13e5626
hopefully fix NPE for currentUser
mahibi 44c84dd
Fix(l10n): Update translations from Transifex
nextcloud-bot ce7ed87
Merge pull request #4611 from nextcloud/bugfix/4610/fixNpeCurrentUser…
mahibi 6e1114d
fix TooManyRequestsException
mahibi ed13698
Update dependency androidx.datastore:datastore-core to v1.1.2
renovate[bot] 894c788
Merge pull request #4613 from nextcloud/renovate/androidx.datastore-d…
github-actions[bot] 0eabff6
Update dependency androidx.datastore:datastore-preferences to v1.1.2
renovate[bot] 6a4edc9
Update dependency com.github.spotbugs.snom:spotbugs-gradle-plugin to …
renovate[bot] 69ddeaa
use lifecycleScope from chatActivity in OutcomingTextMessageViewHolder
mahibi 2a4ca9f
Merge pull request #4614 from nextcloud/renovate/androidx.datastore-d…
github-actions[bot] 35d18cc
Merge pull request #4615 from nextcloud/renovate/com.github.spotbugs.…
github-actions[bot] 383546e
Merge pull request #4598 from nextcloud/bugfix/4503/fixTooManyRequest…
mahibi 9e7996b
style(reaction): make reactions background rounded instead of pill-st…
AndyScherzinger b26b598
style(reactions): Align reactions with text for preview messages
AndyScherzinger a2dac5e
style(reactions): ensure correct color coding of own reaction backgro…
AndyScherzinger 0a6a1a7
style(reactions): Add default vertical spacing at top of reactions
AndyScherzinger e4088d0
style(lint): Fix formatting
AndyScherzinger 9e3840c
style(lint): replace magic number with constant
AndyScherzinger 9fcd466
style(icons): Update pdf icon to latest server version / material sym…
AndyScherzinger 115f5e3
Fix(l10n): Update translations from Transifex
nextcloud-bot c127261
Update dependency com.github.spotbugs.snom:spotbugs-gradle-plugin to …
renovate[bot] 86db9f7
Merge pull request #4625 from nextcloud/renovate/com.github.spotbugs.…
AndyScherzinger 35f9e33
make sure that canDeleteConversation is used to determine if "Delete …
mahibi 779c162
Merge pull request #4620 from nextcloud/fix/4557/reactionsBackground
mahibi 20612c8
avoid shimmer animations overlay with chat messages
mahibi 5535bed
no "unread messages" popup for invisible messages
mahibi fba4e94
Fix(l10n): Update translations from Transifex
nextcloud-bot aa42f5c
Fix(l10n): Update translations from Transifex
nextcloud-bot d450c47
Weekly 21.0.0 Alpha 10
nextcloud-android-bot 28ffb7f
enable to select authentication cert in server selection screen
mahibi 3522ab7
Merge pull request #4634 from nextcloud/enableCertSelection
mahibi f9928ef
chore: switch uploadArtifact.sh to remote.php/dav
joshtrichards 6492308
chore: use remote.php/dav in analysis-wrapper.sh
joshtrichards e1a0f20
Merge pull request #4633 from nextcloud/jtr/chore-1478
mahibi 136ad56
Fix(l10n): Update translations from Transifex
nextcloud-bot 4bf5704
chore(deps): update actions/stale action to v9.1.0
renovate[bot] 6c5cbd5
Merge pull request #4637 from nextcloud/renovate/actions-stale-9.x
AndyScherzinger 3da9501
chore(deps): update github/codeql-action action to v3.28.2
renovate[bot] e9946f6
Merge pull request #4639 from nextcloud/renovate/github-codeql-action…
github-actions[bot] 5048465
Fix(l10n): Update translations from Transifex
nextcloud-bot b6e341b
cancel scope when onStop is reached
mahibi 1f105d4
check if scope is active during long polling
mahibi 9b6b012
remove scope cancelation for handleChatOnBackPress (replace with life…
mahibi d2d040d
Merge pull request #4629 from nextcloud/bugfix/4626/avoidChatLoadingS…
mahibi b172f68
Merge pull request #4627 from nextcloud/feature/4570/rework-can-leave…
mahibi 4f49dea
Merge pull request #4630 from nextcloud/bugfix/4628/noUnreadMessagesB…
mahibi 1ac537b
Merge pull request #4641 from nextcloud/bugfix/4605/fixDuplicateMessages
rapterjet2004 2be89d5
chore(deps): update github/codeql-action action to v3.28.3
renovate[bot] 22e2f75
Fix(l10n): Update translations from Transifex
nextcloud-bot 7d0c6d6
Merge pull request #4644 from nextcloud/renovate/github-codeql-action…
AndyScherzinger 3330fc8
fix shimmer and "offlineNoMessages"-info handling
mahibi 4c6c08b
Merge pull request #4645 from nextcloud/bugfix/4643/fixShimmerAndOffl…
mahibi a6055e5
Archived conversation improvements
rapterjet2004 71af112
change "No conversations archived" screen design
mahibi 3427f4c
change "Archive conversation" design in conversation-info screen
mahibi 7ac8c24
Show snackbar on archive/unarchive from bottomDialog
mahibi b3f32a0
Merge pull request #4624 from nextcloud/issue-4607-4608-archive-conve…
mahibi b44296c
Fix(l10n): Update translations from Transifex
nextcloud-bot f89efa1
bump version to 21.1.0 Alpha 1
mahibi 09a5dd6
chore(deps): update github/codeql-action action to v3.28.4
renovate[bot] 61cba43
fix(deps): update dependency androidx.compose:compose-bom to v2025
renovate[bot] 09cb8f7
Merge pull request #4619 from nextcloud/renovate/androidx.compose-com…
github-actions[bot] 8cbaff4
Merge pull request #4646 from nextcloud/renovate/github-codeql-action…
AndyScherzinger 34806b6
Fix(l10n): Update translations from Transifex
nextcloud-bot 296947d
chore(deps): update dependency gradle to v8.12.1
renovate[bot] f8068ac
Merge pull request #4651 from nextcloud/renovate/gradle-8.x
AndyScherzinger 9cdb2ce
chore(deps): update github/codeql-action action to v3.28.5
renovate[bot] eabe3f5
Merge pull request #4653 from nextcloud/renovate/github-codeql-action…
github-actions[bot] be6cc85
Fix(l10n): Update translations from Transifex
nextcloud-bot ad572b7
Fix(l10n): Update translations from Transifex
nextcloud-bot 97988a4
Fix(l10n): Update translations from Transifex
nextcloud-bot be235c8
Weekly 21.1.0 Alpha 02
nextcloud-android-bot 296ca07
fix(deps): update dependency com.github.spotbugs.snom:spotbugs-gradle…
renovate[bot] 28e9e90
Merge pull request #4656 from nextcloud/renovate/com.github.spotbugs.…
github-actions[bot] f13cc85
🔄 synced local '.github/workflows/' with remote 'config/workflows/'
nextcloud-android-bot 61854b7
Merge pull request #4660 from nextcloud/repo-sync/android-config/master
AndyScherzinger c7c287a
message of type actorId = "sample" should show talk logo avatar
sowjanyakch bf97d93
remove duplicated dependencies
mahibi 25df519
switched the btns in DateTimeCompose
rapterjet2004 0918cdd
Merge pull request #4663 from nextcloud/show_changelog_avatar
mahibi c58df32
Merge pull request #4659 from nextcloud/changing-btn-layout-date-time…
mahibi 307ebd3
ensure that getAnyUserAndSetAsActive will set other users to current=…
mahibi 22b8b59
fix to not execute getAnyUserAndSetAsActive() until userRepository.ge…
mahibi b69f215
self heal if multiple current users exist
mahibi 9aa9918
Merge pull request #4664 from nextcloud/fixDuplicatedDependencies
rapterjet2004 4880dcf
Fix(l10n): Update translations from Transifex
nextcloud-bot 1b6681d
🔄 synced local '.github/workflows/' with remote 'config/workflows/'
nextcloud-android-bot 42005a3
Merge pull request #4670 from nextcloud/repo-sync/android-config/master
AndyScherzinger b7d4cf6
Fix(l10n): Update translations from Transifex
nextcloud-bot 667a67b
Weekly 21.1.0 Alpha 03
nextcloud-android-bot a098de9
Fix(l10n): Update translations from Transifex
nextcloud-bot 3d2f999
Merge pull request #4667 from nextcloud/bugfix/4492/fixMissingUsersInUI
rapterjet2004 f6415e2
chore(CI): Updating pr-feedback.yml workflow from template
nextcloud-bot 5c32bfd
Merge pull request #4680 from nextcloud/feat/workflow-auto-update-pr-…
AndyScherzinger a9461ff
bump webrtc lib to 132.6834.0
mahibi 4fcbbea
update verification metadata
mahibi 17086d8
Merge pull request #4679 from nextcloud/updateWebRtcLibTo132.6834.0
mahibi b23ab8b
chore(deps): update plugin org.jetbrains.kotlin.plugin.compose to v2.…
renovate[bot] 9e6b1b5
Merge pull request #4662 from nextcloud/renovate/org.jetbrains.kotlin…
github-actions[bot] 6be40a3
chore(deps): update ubuntu:noble docker digest to 7229784
renovate[bot] f981a56
Merge pull request #4682 from nextcloud/renovate/ubuntu-noble
github-actions[bot] 6f09598
chore(deps): update plugin com.google.devtools.ksp to v2.1.10-1.0.29
renovate[bot] f41e552
Merge pull request #4683 from nextcloud/renovate/com.google.devtools.…
github-actions[bot] cef7075
fix(deps): update dependency androidx.compose.runtime:runtime to v1.7.7
renovate[bot] 905d97d
Merge pull request #4684 from nextcloud/renovate/androidx.compose.run…
github-actions[bot] 39391c8
calculate conversation description length
sowjanyakch b7074c5
set limit on conversation description
sowjanyakch bbedbf5
rename variable
sowjanyakch fdcff12
ktlintFormat
sowjanyakch ef78314
set limit on description
sowjanyakch 1663fca
ktlintFormat
sowjanyakch 2b30988
Added character counter to xml
rapterjet2004 c49a8f1
fix(deps): update dependency androidx.compose.ui:ui-test-junit4 to v1…
renovate[bot] c3fc9da
Merge pull request #4685 from nextcloud/renovate/androidx.compose.ui-…
github-actions[bot] cb7c3f5
fix(deps): update dependency androidx.compose:compose-bom to v2025.01.01
renovate[bot] 0e4e2f3
Merge pull request #4658 from nextcloud/conversation_description_length
mahibi e5b5a81
Merge pull request #4686 from nextcloud/renovate/androidx.compose-com…
github-actions[bot] 09a6cfb
avoid duplicated messages after sending
mahibi 43064a7
fix(deps): update dependency joda-time:joda-time to v2.13.1
renovate[bot] 31c194a
Merge pull request #4689 from nextcloud/renovate/joda-time-joda-time-2.x
github-actions[bot] ac9b7fe
chore(deps): update actions/setup-java action to v4.7.0
renovate[bot] 872446f
Merge pull request #4691 from nextcloud/renovate/actions-setup-java-4.x
github-actions[bot] 6a872a5
chore(deps): update gradle/actions action to v4.3.0
renovate[bot] 221a77b
Merge pull request #4692 from nextcloud/renovate/gradle-actions-4.x
github-actions[bot] 4632d20
Fix(l10n): Update translations from Transifex
nextcloud-bot 4425f82
Improved Search
rapterjet2004 93fa89f
linter -_-
rapterjet2004 b707ceb
Added intent handling on item click
rapterjet2004 f4a1b73
replace hardcoded number for 1:1 roomtype
mahibi 423fbbe
fix nullable createRoom param for FakeRepository classes
mahibi 69a9b96
lower SEARCH_MIN_CHARS to 1
mahibi b747765
Merge pull request #4674 from nextcloud/issue-4453-4657-improve-main-…
mahibi 34a8ca6
fix(deps): update dependency com.google.code.gson:gson to v2.12.1
renovate[bot] 02a9498
Merge pull request #4694 from nextcloud/renovate/com.google.code.gson…
github-actions[bot] 11fc9fa
Merge pull request #4688 from nextcloud/bugfix/noid/avoidDuplicatedMe…
mahibi 6d22fcb
changes to enable unified push notifications in generic build. Signed…
f78ec24
added wakelock when unified push messages received to allow notificat…
c6bb690
rebased onto remote master
f8eb01c
Merge remote-tracking branch 'origin/unified_push_nextcloud_notificat…
f02257d
add team support for mentions
sowjanyakch 0de8a3e
add avatar for autocomplete mentions in recycler view
sowjanyakch 64856cc
set chip avatar for team placeholder
sowjanyakch d927f8d
use proper avatar for circles
sowjanyakch ba37c7b
add mention support for circles
sowjanyakch 65707f2
add icon
sowjanyakch c08a004
format code
sowjanyakch 20a8a38
make system messages work for teams
sowjanyakch e40f367
format code
sowjanyakch 2d1c940
resize icons
sowjanyakch 13fe915
bump detekt issues by 2
mahibi c72c83b
add license headers
mahibi 798c024
Merge pull request #4678 from nextcloud/team_support
mahibi de9eb22
chore(deps): update github/codeql-action action to v3.28.9
renovate[bot] 4c26c2f
Merge pull request #4698 from nextcloud/renovate/github-codeql-action…
github-actions[bot] 5219eeb
replace userManager.currentUser usage by currentUserProvider usage
mahibi 40bcf74
Merge pull request #4695 from nextcloud/accessCurrentUserOnlyByCurren…
sowjanyakch 1dd0b7d
changes to enable unified push notifications in generic build. Signed…
d03a97c
added wakelock when unified push messages received to allow notificat…
7c01825
rebased onto remote master
9c442b9
changes to enable unified push notifications in generic build. Signed…
736fe47
Merge remote-tracking branch 'origin/unified_push_nextcloud_notificat…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!-- | ||
~ Nextcloud Talk - Android Client | ||
~ | ||
~ SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors | ||
~ SPDX-FileCopyrightText: 2021-2023 Marcel Hibbe <[email protected]> | ||
~ SPDX-FileCopyrightText: 2017-2019 Mario Danic <[email protected]> | ||
~ SPDX-License-Identifier: GPL-3.0-or-later | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<application> | ||
<receiver android:exported="true" android:enabled="true" android:name=".receivers.UnifiedPush"> | ||
<intent-filter> | ||
<action android:name="org.unifiedpush.android.connector.MESSAGE"/> | ||
<action android:name="org.unifiedpush.android.connector.UNREGISTERED"/> | ||
<action android:name="org.unifiedpush.android.connector.NEW_ENDPOINT"/> | ||
<action android:name="org.unifiedpush.android.connector.REGISTRATION_FAILED"/> | ||
</intent-filter> | ||
</receiver> | ||
</application> | ||
</manifest> |
163 changes: 163 additions & 0 deletions
163
app/src/generic/java/com/nextcloud/talk/receivers/UnifiedPush.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,163 @@ | ||
/* | ||
* Nextcloud Talk - Android Client | ||
* | ||
* SPDX-FileCopyrightText: 2024 Your Name <[email protected]> | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package com.nextcloud.talk.receivers | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import android.text.SpannableString | ||
import android.text.method.LinkMovementMethod | ||
import android.text.util.Linkify | ||
import android.util.Log | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.work.Data | ||
import androidx.work.OneTimeWorkRequest | ||
import androidx.work.WorkManager | ||
import com.nextcloud.talk.R | ||
import com.nextcloud.talk.activities.MainActivity | ||
import com.nextcloud.talk.jobs.NotificationWorker | ||
import com.nextcloud.talk.utils.bundle.BundleKeys | ||
import org.greenrobot.eventbus.EventBus | ||
import org.unifiedpush.android.connector.MessagingReceiver | ||
import org.unifiedpush.android.connector.PREF_MASTER | ||
import org.unifiedpush.android.connector.PREF_MASTER_NO_DISTRIB_DIALOG_ACK | ||
import org.unifiedpush.android.connector.UnifiedPush | ||
|
||
class UnifiedPush : MessagingReceiver() { | ||
private val TAG: String? = UnifiedPush::class.java.simpleName | ||
|
||
companion object { | ||
fun getNumberOfDistributorsAvailable(context: Context) : Int { | ||
return UnifiedPush.getDistributors(context).size | ||
} | ||
|
||
private fun resetSeenNoDistributorsInfo(context: Context) { | ||
context.getSharedPreferences(PREF_MASTER, Context.MODE_PRIVATE) | ||
.edit().putBoolean(PREF_MASTER_NO_DISTRIB_DIALOG_ACK, false).apply() | ||
} | ||
|
||
fun registerForPushMessaging(context: Context, accountName: String): Boolean { | ||
// if a distributor is registered and available, re-register to ensure in sync | ||
if (UnifiedPush.getSavedDistributor(context) !== null) { | ||
UnifiedPush.registerApp(context, accountName) | ||
return false | ||
} | ||
|
||
val distributors = UnifiedPush.getDistributors(context) | ||
|
||
// if no distributors available | ||
if (distributors.isEmpty()) { | ||
// if user has already been shown the info dialog, return | ||
val preferences = context.getSharedPreferences(PREF_MASTER, Context.MODE_PRIVATE) | ||
if (preferences.getBoolean(PREF_MASTER_NO_DISTRIB_DIALOG_ACK, false) == true) { | ||
return false | ||
} | ||
|
||
// show user some info about unified push | ||
val message = TextView(context) | ||
val s = SpannableString(context.getString(R.string.unified_push_no_distributors_dialog_text)) | ||
Linkify.addLinks(s, Linkify.WEB_URLS) | ||
message.text = s | ||
message.movementMethod = LinkMovementMethod.getInstance() | ||
message.setPadding(32, 32, 32, 32) | ||
AlertDialog.Builder(context) | ||
.setTitle(context.getString(R.string.unified_push_no_distributors_dialog_title)) | ||
.setView(message) | ||
.setPositiveButton(context.getString(R.string.nc_ok)) { | ||
_, _ -> preferences.edit().putBoolean(PREF_MASTER_NO_DISTRIB_DIALOG_ACK, true).apply() | ||
}.setOnDismissListener { | ||
// send message to main activity that it can move on to it's next default activity | ||
EventBus.getDefault().post(MainActivity.ProceedToConversationsListMessageEvent()) | ||
}.show() | ||
|
||
return true // have a dialog to show, need main activity to wait | ||
} | ||
|
||
// 1 distributor available | ||
if (distributors.size == 1) { | ||
UnifiedPush.saveDistributor(context, distributors.first()) | ||
UnifiedPush.registerApp(context, accountName) | ||
return false | ||
} | ||
|
||
// multiple distributors available, show dialog for user to choose | ||
val distributorsArray = distributors.toTypedArray() | ||
val distributorsNameArray = distributorsArray.map { | ||
try { | ||
val ai = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
context.packageManager.getApplicationInfo( | ||
it, | ||
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()) | ||
) | ||
} else { | ||
context.packageManager.getApplicationInfo(it, 0) | ||
} | ||
context.packageManager.getApplicationLabel(ai) | ||
} catch (e: PackageManager.NameNotFoundException) { | ||
it | ||
} as String | ||
}.toTypedArray() | ||
|
||
AlertDialog.Builder(context) | ||
.setTitle(context.getString(R.string.unified_push_choose_distributor_title)) | ||
.setItems(distributorsNameArray) { _, which -> | ||
val distributor = distributorsArray[which] | ||
UnifiedPush.saveDistributor(context, distributor) | ||
UnifiedPush.registerApp(context, accountName) | ||
}.setOnDismissListener { | ||
// send message to main activity that it can move on to it's next default activity | ||
EventBus.getDefault().post(MainActivity.ProceedToConversationsListMessageEvent()) | ||
}.show() | ||
|
||
return true // have a dialog to show, need main activity to wait | ||
} | ||
|
||
fun unregisterForPushMessaging(context: Context, accountName: String) { | ||
// try and unregister with unified push distributor | ||
UnifiedPush.unregisterApp(context, instance = accountName) | ||
resetSeenNoDistributorsInfo(context) | ||
} | ||
} | ||
|
||
override fun onMessage(context: Context, message: ByteArray, instance: String) { | ||
Log.d(TAG, "UP onMessage") | ||
|
||
val messageString = message.toString(Charsets.UTF_8) | ||
|
||
if (messageString.isNotEmpty() && instance.isNotEmpty()) { | ||
val messageData = Data.Builder() | ||
.putString(BundleKeys.KEY_NOTIFICATION_SUBJECT, messageString) | ||
.putString(BundleKeys.KEY_NOTIFICATION_SIGNATURE, instance) | ||
.putInt( | ||
BundleKeys.KEY_NOTIFICATION_BACKEND_TYPE, NotificationWorker.Companion.BackendType.UNIFIED_PUSH.value) | ||
.build() | ||
val notificationWork = | ||
OneTimeWorkRequest.Builder(NotificationWorker::class.java).setInputData(messageData) | ||
.build() | ||
WorkManager.getInstance().enqueue(notificationWork) | ||
} | ||
} | ||
|
||
override fun onNewEndpoint(context: Context, endpoint: String, instance: String) { | ||
// called when a new endpoint is to be used for sending push messages | ||
// do nothing | ||
} | ||
|
||
override fun onRegistrationFailed(context: Context, instance: String) { | ||
// called when the registration is not possible, eg. no network | ||
// just dump the registration to make sure it is cleaned up. re-register will be auto-reattempted | ||
unregisterForPushMessaging(context, instance) | ||
|
||
} | ||
|
||
override fun onUnregistered(context: Context, instance: String) { | ||
// called when this application is remotely unregistered from receiving push messages | ||
unregisterForPushMessaging(context, instance) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.