-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed location service issues when recreating MainActivity
- Loading branch information
Showing
6 changed files
with
144 additions
and
38 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
48 changes: 48 additions & 0 deletions
48
android/app/src/main/java/info/varden/hauk/manager/ServiceRelauncher.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,48 @@ | ||
package info.varden.hauk.manager; | ||
|
||
import android.content.Context; | ||
|
||
import info.varden.hauk.caching.ResumableSessions; | ||
import info.varden.hauk.caching.ResumeHandler; | ||
import info.varden.hauk.struct.Session; | ||
import info.varden.hauk.struct.Share; | ||
import info.varden.hauk.utils.Log; | ||
|
||
/** | ||
* {@link ResumeHandler} implementation used by {@link SessionManager} to automatically resume | ||
* sessions following a service relaunch. This can happen if the main activity is terminated, but | ||
* the share itself keeps running in the background. | ||
* | ||
* @author Marius Lindvall | ||
*/ | ||
public class ServiceRelauncher implements ResumeHandler { | ||
/** | ||
* The session manager to call to resume the shares. | ||
*/ | ||
private final SessionManager manager; | ||
|
||
/** | ||
* The manager's resumption handler. This is used to clear the resumption data before the shares | ||
* are resumed by the session manager, as the session manager will re-flag the shares as | ||
* resumable when it adds them to its internal share list. | ||
*/ | ||
private final ResumableSessions resumptionHandler; | ||
|
||
public ServiceRelauncher(SessionManager manager, ResumableSessions resumptionHandler) { | ||
this.manager = manager; | ||
this.resumptionHandler = resumptionHandler; | ||
} | ||
|
||
@Override | ||
public void onSharesFetched(Context ctx, Session session, Share[] shares) { | ||
Log.i("Resuming %s share(s) automatically found for session %s", shares.length, session); //NON-NLS | ||
// The shares provided by ResumableSessions do not have a session attached to them. Attach | ||
// it to the shares so that they can be shown properly by the prompt and so that the updates | ||
// have a backend to be broadcast to when the shares are resumed. | ||
this.resumptionHandler.clearResumableSession(); | ||
for (Share share : shares) { | ||
share.setSession(session); | ||
this.manager.shareLocation(share, SessionInitiationReason.SERVICE_RELAUNCH); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
android/app/src/main/java/info/varden/hauk/manager/SessionInitiationReason.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,34 @@ | ||
package info.varden.hauk.manager; | ||
|
||
import info.varden.hauk.struct.Session; | ||
import info.varden.hauk.struct.Share; | ||
|
||
/** | ||
* Describes the reason a session was initiated. | ||
* | ||
* @author Marius Lindvall | ||
*/ | ||
public enum SessionInitiationReason { | ||
/** | ||
* The user requested to start a new sharing session. | ||
*/ | ||
USER_STARTED, | ||
|
||
/** | ||
* The user requested to resume a previous sharing session. | ||
*/ | ||
USER_RESUMED, | ||
|
||
/** | ||
* The sharing session is automatically resumed as a result of a relaunch of the location | ||
* sharing service. | ||
*/ | ||
SERVICE_RELAUNCH, | ||
|
||
/** | ||
* The session was created because a share was added to it. This should never be received by | ||
* {@link SessionListener#onSessionCreated(Session, Share, SessionInitiationReason)} under any | ||
* normal circumstances. | ||
*/ | ||
SHARE_ADDED | ||
} |
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