forked from ostrya/PresencePublisher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce explicit location consent setting
this should better fulfill google's requirement for background permission handling
- Loading branch information
Showing
15 changed files
with
179 additions
and
35 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
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
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
58 changes: 58 additions & 0 deletions
58
app/src/main/java/org/ostrya/presencepublisher/ui/initialization/EnsureLocationConsent.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,58 @@ | ||
package org.ostrya.presencepublisher.ui.initialization; | ||
|
||
import android.app.Activity; | ||
import androidx.fragment.app.FragmentManager; | ||
import androidx.preference.PreferenceManager; | ||
import com.hypertrack.hyperlog.HyperLog; | ||
import org.ostrya.presencepublisher.MainActivity; | ||
import org.ostrya.presencepublisher.R; | ||
import org.ostrya.presencepublisher.ui.dialog.ConfirmationDialogFragment; | ||
|
||
import java.util.Queue; | ||
|
||
import static org.ostrya.presencepublisher.ui.preference.about.LocationConsentPreference.LOCATION_CONSENT; | ||
|
||
public class EnsureLocationConsent extends AbstractChainedHandler<Void, Void> { | ||
protected EnsureLocationConsent(Queue<HandlerFactory> handlerChain) { | ||
super(null, handlerChain); | ||
} | ||
|
||
@Override | ||
protected void doInitialize(MainActivity activity) { | ||
if (activity.isLocationServiceNeeded() && !PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(LOCATION_CONSENT, false)) { | ||
HyperLog.i(TAG, "Location consent not yet granted, asking user ..."); | ||
FragmentManager fm = activity.getSupportFragmentManager(); | ||
|
||
ConfirmationDialogFragment fragment = ConfirmationDialogFragment.getInstance(this::onResult, | ||
R.string.location_consent_title, | ||
activity.getString(R.string.location_consent_dialog_summary, activity.getString(R.string.tab_about_title), activity.getString(R.string.privacy_title), activity.getString(R.string.location_consent_title))); | ||
fragment.setConfirmId(R.string.dialog_accept); | ||
fragment.setCancelId(R.string.dialog_decline); | ||
fragment.show(fm, null); | ||
} else { | ||
finishInitialization(); | ||
} | ||
} | ||
|
||
private void onResult(Activity parent, boolean ok) { | ||
if (ok) { | ||
PreferenceManager.getDefaultSharedPreferences(parent).edit() | ||
.putBoolean(LOCATION_CONSENT, true) | ||
.apply(); | ||
finishInitialization(); | ||
} else { | ||
HyperLog.i(getName(), "User did not give consent. Stopping any further actions."); | ||
cancelInitialization(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void doHandleResult(Void result) { | ||
HyperLog.w(TAG, "Skipping unexpected result"); | ||
} | ||
|
||
@Override | ||
protected String getName() { | ||
return "EnsureLocationConsent"; | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...main/java/org/ostrya/presencepublisher/ui/preference/about/LocationConsentPreference.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,13 @@ | ||
package org.ostrya.presencepublisher.ui.preference.about; | ||
|
||
import android.content.Context; | ||
import org.ostrya.presencepublisher.R; | ||
import org.ostrya.presencepublisher.ui.preference.common.BooleanPreferenceBase; | ||
|
||
public class LocationConsentPreference extends BooleanPreferenceBase { | ||
public static final String LOCATION_CONSENT = "locationConsent"; | ||
|
||
public LocationConsentPreference(Context context) { | ||
super(context, LOCATION_CONSENT, R.string.location_consent_title, R.string.location_consent_summary); | ||
} | ||
} |
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.