-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update code deprecate backgroundForground listener and update param p…
…ackageId for registerDeviceToken
- Loading branch information
Arief Nur Putranto
committed
Nov 6, 2024
1 parent
0908d6a
commit 255d079
Showing
6 changed files
with
112 additions
and
20 deletions.
There are no files selected for viewing
60 changes: 53 additions & 7 deletions
60
chat-core/src/main/java/com/qiscus/sdk/chat/core/BackgroundForegroundListener.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 |
---|---|---|
@@ -1,15 +1,61 @@ | ||
package com.qiscus.sdk.chat.core; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.lifecycle.DefaultLifecycleObserver; | ||
import androidx.lifecycle.LifecycleOwner; | ||
import com.qiscus.sdk.chat.core.util.QiscusLogger; | ||
import com.qiscus.sdk.chat.core.util.QiscusServiceUtil; | ||
|
||
import android.app.Activity; | ||
import android.util.Log; | ||
enum BackgroundForegroundListener implements DefaultLifecycleObserver { | ||
INSTANCE; | ||
private static boolean foreground; | ||
@Override | ||
public void onCreate(@NonNull LifecycleOwner owner) { | ||
DefaultLifecycleObserver.super.onCreate(owner); | ||
QiscusLogger.print("BackgroundForegroundListener", "onCreate"); | ||
} | ||
|
||
@Override | ||
public void onStart(@NonNull LifecycleOwner owner) { | ||
DefaultLifecycleObserver.super.onStart(owner); | ||
QiscusLogger.print("BackgroundForegroundListener", "onStart"); | ||
foreground = true; | ||
if (!QiscusServiceUtil.isMyServiceRunning() && !QiscusCore.isSyncServiceDisabledManually()) { | ||
QiscusCore.startSyncService(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onResume(@NonNull LifecycleOwner owner) { | ||
DefaultLifecycleObserver.super.onResume(owner); | ||
QiscusLogger.print("BackgroundForegroundListener", "onResume"); | ||
} | ||
|
||
@Override | ||
public void onPause(@NonNull LifecycleOwner owner) { | ||
DefaultLifecycleObserver.super.onPause(owner); | ||
QiscusLogger.print("BackgroundForegroundListener", "onPause"); | ||
} | ||
|
||
@Override | ||
public void onStop(@NonNull LifecycleOwner owner) { | ||
DefaultLifecycleObserver.super.onStop(owner); | ||
QiscusLogger.print("BackgroundForegroundListener", "onStop"); | ||
foreground = false; | ||
} | ||
|
||
@Override | ||
public void onDestroy(@NonNull LifecycleOwner owner) { | ||
DefaultLifecycleObserver.super.onDestroy(owner); | ||
foreground = false; | ||
QiscusLogger.print("BackgroundForegroundListener", "onDestroy"); | ||
} | ||
|
||
class MyAppLifecycleObserver : ApplicationLifecycleObserver() { | ||
override fun onAppForeground(owner: LifecycleOwner) { | ||
Log.d(this::class.simpleName, "onAppForeground: Application resumed") | ||
boolean isForeground() { | ||
return foreground; | ||
} | ||
|
||
override fun onAppBackground(owner: LifecycleOwner) { | ||
Log.d(this::class.simpleName, "onAppBackground: Application paused") | ||
public static void setAppActiveOrForground(){ | ||
foreground = true; | ||
} | ||
} |
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