forked from SEL-Columbia/dristhi-app
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a BroadcastReceiver to tell BaseActivity and BaseRegisterActivity if sync is currently running Part of fix for issue #474 Signed-off-by: Jason Rogena <jasonrogena@gmail.com>
- Loading branch information
1 parent
8c18f26
commit 1eba121
Showing
5 changed files
with
167 additions
and
62 deletions.
There are no files selected for viewing
9 changes: 7 additions & 2 deletions
9
opensrp-app/src/main/java/org/ei/opensrp/domain/FetchStatus.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
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
59 changes: 59 additions & 0 deletions
59
opensrp-path/src/main/java/org/ei/opensrp/path/receiver/SyncStatusBroadcastReceiver.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,59 @@ | ||
package org.ei.opensrp.path.receiver; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
|
||
import org.ei.opensrp.domain.FetchStatus; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by Jason Rogena - jrogena@ona.io on 12/05/2017. | ||
*/ | ||
|
||
public class SyncStatusBroadcastReceiver extends BroadcastReceiver { | ||
public static final String ACTION_SYNC_STATUS = "sync_status"; | ||
public static final String EXTRA_FETCH_STATUS = "fetch_status"; | ||
|
||
private final ArrayList<SyncStatusListener> syncStatusListeners; | ||
|
||
public SyncStatusBroadcastReceiver() { | ||
syncStatusListeners = new ArrayList<>(); | ||
} | ||
|
||
public void addSyncStatusListener(SyncStatusListener syncStatusListener) { | ||
syncStatusListeners.add(syncStatusListener); | ||
} | ||
|
||
public void removeSyncStatusListener(SyncStatusListener syncStatusListener) { | ||
if (syncStatusListeners.contains(syncStatusListener)) { | ||
syncStatusListeners.remove(syncStatusListener); | ||
} | ||
} | ||
|
||
public interface SyncStatusListener { | ||
void onSyncStart(); | ||
|
||
void onSyncComplete(FetchStatus fetchStatus); | ||
} | ||
|
||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Bundle data = intent.getExtras(); | ||
if (data != null) { | ||
FetchStatus fetchStatus = (FetchStatus) data.getSerializable(EXTRA_FETCH_STATUS); | ||
if (fetchStatus.equals(FetchStatus.fetchStarted)) { | ||
for (SyncStatusListener syncStatusListener : syncStatusListeners) { | ||
syncStatusListener.onSyncStart(); | ||
} | ||
} else { | ||
for (SyncStatusListener syncStatusListener : syncStatusListeners) { | ||
syncStatusListener.onSyncComplete(fetchStatus); | ||
} | ||
} | ||
} | ||
} | ||
} |
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