forked from sk22/megalodon
-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Helper for some UnifiedPush functions
- Loading branch information
Showing
3 changed files
with
65 additions
and
24 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
51 changes: 51 additions & 0 deletions
51
mastodon/src/main/java/org/joinmastodon/android/utils/UnifiedPushHelper.java
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,51 @@ | ||
package org.joinmastodon.android.utils; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.joinmastodon.android.api.session.AccountSession; | ||
import org.joinmastodon.android.api.session.AccountSessionManager; | ||
import org.unifiedpush.android.connector.UnifiedPush; | ||
|
||
public class UnifiedPushHelper { | ||
|
||
/** | ||
* @param context | ||
* @return `true` if UnifiedPush is used | ||
*/ | ||
public static boolean isUnifiedPushEnabled(@NonNull Context context) { | ||
return UnifiedPush.getAckDistributor(context) != null; | ||
} | ||
|
||
/** | ||
* If any distributor is installed on the device | ||
* @param context | ||
* @return `true` if at least one is installed | ||
*/ | ||
public static boolean hasAnyDistributorInstalled(@NonNull Context context) { | ||
return !UnifiedPush.getDistributors(context).isEmpty(); | ||
} | ||
|
||
public static void registerAllAccounts(@NonNull Context context) { | ||
for (AccountSession accountSession : AccountSessionManager.getInstance().getLoggedInAccounts()){ | ||
UnifiedPush.register( | ||
context, | ||
accountSession.getID(), | ||
null, | ||
null | ||
); | ||
} | ||
} | ||
|
||
public static void unregisterAllAccounts(@NonNull Context context) { | ||
for (AccountSession accountSession : AccountSessionManager.getInstance().getLoggedInAccounts()){ | ||
UnifiedPush.unregister( | ||
context, | ||
accountSession.getID() | ||
); | ||
// use FCM again | ||
accountSession.getPushSubscriptionManager().registerAccountForPush(null); | ||
} | ||
} | ||
} |