From 2b104d8df3269756ba46f701913f79597d3dadf5 Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Wed, 5 Feb 2020 16:43:06 -0400 Subject: [PATCH] only request location permission if automatic theme switching is enabled --- News-Android-App/build.gradle | 2 +- .../owncloudnewsreader/NewsReaderListActivity.java | 11 ++++++++--- .../owncloudnewsreader/helper/ThemeChooser.java | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/News-Android-App/build.gradle b/News-Android-App/build.gradle index 8fb1c6a0..180c27cb 100644 --- a/News-Android-App/build.gradle +++ b/News-Android-App/build.gradle @@ -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' diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index 63ffde85..4a625ed5 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -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) -> {}) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ThemeChooser.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ThemeChooser.java index 9ff7fe00..bca65568 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ThemeChooser.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ThemeChooser.java @@ -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));