Merge pull request #831 from nextcloud/location-permission-for-lightdark-mode

only request location permission if automatic theme switching is enabled
This commit is contained in:
David Luhmer 2020-02-07 17:52:35 -04:00 committed by GitHub
commit 1b8990881b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View file

@ -115,7 +115,7 @@ repositories {
jcenter()
maven { url "https://jitpack.io" }
maven { url 'https://guardian.github.com/maven/repo-releases' } //needed for com.gu:option:1.3 in Android-DirectoryChooser
maven { url "https://dl.bintray.com/lukaville/maven" } //Needed for com.nbsp:library:1.02 in Material File Picker
maven { url "https://dl.bintray.com/lukaville/maven" } //Needed for com.nbsp:library:1.8 in Material File Picker
}
final DAGGER_VERSION = '2.22.1'

View file

@ -271,8 +271,14 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
}
if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{ACCESS_FINE_LOCATION}, REQUEST_CODE_PERMISSION_LOCATION);
// In case automatic theme selection based on time is selected, check if location permission
// for twilight manager is given.. otherwise request it
if(ThemeChooser.isAutoThemeSelectionEnabled() && ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
new String[]{ ACCESS_FINE_LOCATION },
REQUEST_CODE_PERMISSION_LOCATION
);
}
}
@ -993,7 +999,6 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
builder.setTitle(getString(R.string.permission_req_location_twilight_title))
.setMessage(getString(R.string.permission_req_location_twilight_text))
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
//ActivityCompat.requestPermissions(this, new String[]{ACCESS_COARSE_LOCATION}, 1349);
ActivityCompat.requestPermissions(this, new String[]{ACCESS_FINE_LOCATION}, REQUEST_CODE_PERMISSION_LOCATION);
})
.setNegativeButton(android.R.string.cancel, (dialog, id) -> {})

View file

@ -107,6 +107,15 @@ public class ThemeChooser {
*/
}
/**
* Returns true if automatic theme selection based on Twilight Manager is enabled.
* Otherwise it'll return false
*/
public static boolean isAutoThemeSelectionEnabled() {
int selectedTheme = getSelectedThemeFromPreferences(false);
return selectedTheme == 0; // 0 => Auto (Light / Dark)
}
// Check if the currently loaded theme is different from the one set in the settings, or if OLED mode changed
public static boolean themeRequiresRestartOfUI() {
boolean themeChanged = !mSelectedThemeFromPreferences.equals(getSelectedThemeFromPreferences(true));