Skip to content

Commit

Permalink
#155: added feature toggle Global.allow_emulate_ao10
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Jan 29, 2020
1 parent 5f9b8a9 commit 5066b95
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 18 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Expand Up @@ -19,6 +19,8 @@ android {

minSdkVersion 14 // Android 4.0 Ice Cream Sandwich (API 14); Android 4.4 KitKat (API 19); Android 5.0 Lollipop (API 21);
// Android 6.0 Marshmallow (API 23); Android 7.0 Nougat (API 24)
maxSdkVersion 28 // #155: android-10=api29

targetSdkVersion 21

// non-fdroid release
Expand Down
Expand Up @@ -94,16 +94,16 @@ public static String getGetTeaserText(Context context, String linkUrlForDetails)

public static void setMediaImageDbReplacement(Context context, boolean useMediaImageDbReplacement) {
final IMediaRepositoryApi oldMediaDBApi = FotoSql.getMediaDBApi();
if ((oldMediaDBApi == null) || (Global.useMediaImageDbReplacement != useMediaImageDbReplacement)) {
if ((oldMediaDBApi == null) || (Global.useAo10MediaImageDbReplacement != useMediaImageDbReplacement)) {

// menu must be recreated
LocalizedActivity.setMustRecreate();

Global.useMediaImageDbReplacement = useMediaImageDbReplacement;
Global.useAo10MediaImageDbReplacement = useMediaImageDbReplacement;

final MediaContentproviderRepository mediaContentproviderRepository = new MediaContentproviderRepository(context);

if (Global.useMediaImageDbReplacement) {
if (Global.useAo10MediaImageDbReplacement) {
final SQLiteDatabase writableDatabase = DatabaseHelper.getWritableDatabase(context);
final MediaDBRepository mediaDBRepository = new MediaDBRepository(writableDatabase);
FotoSql.setMediaDBApi(new MergedMediaRepository(mediaDBRepository, mediaContentproviderRepository));
Expand Down
Expand Up @@ -168,7 +168,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
inflater.inflate(R.menu.menu_gallery_non_selected_only, menu);
inflater.inflate(R.menu.menu_gallery_non_multiselect, menu);

if (Global.useMediaImageDbReplacement) {
if (Global.useAo10MediaImageDbReplacement) {
inflater.inflate(R.menu.menu_ao10, menu);
}

Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/de/k3b/android/androFotoFinder/Global.java
Expand Up @@ -20,6 +20,7 @@
package de.k3b.android.androFotoFinder;

import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
Expand Down Expand Up @@ -124,17 +125,23 @@ public static class Media {
public static boolean initialImageDetailResolutionHigh = false; // false: MediaStore.Images.Thumbnails.MINI_KIND; true: FULL_SCREEN_KIND;
public static boolean mapsForgeEnabled = false;

// #155: Feature-Toggel: set to false while android10 incompatibility is not fixed
public final static boolean allow_emulate_ao10 = !isAndroid10OrAbove() && false;
// #155: fix android10 incompatibility
// Build.VERSION_CODES.??ANDROID10?? = 29
//!!!
public static boolean useMediaImageDbReplacement = true;
public static boolean useAo10MediaImageDbReplacement = isAndroid10OrAbove();

// public static final boolean useMediaImageDbReplacement = (Build.VERSION.SDK_INT >= 29);
/** map with blue selection markers: how much to area to increase */
public static final double mapMultiselectionBoxIncreaseByProcent = 100.0;
/** map with blue selection markers: minimum size of zoom box in degrees */
public static final double mapMultiselectionBoxIncreaseMinSizeInDegrees = 0.01;

private static boolean isAndroid10OrAbove() {
// #155: fix android10 incompatibility
// Build.VERSION_CODES.??ANDROID10?? = 29
return Build.VERSION.SDK_INT >= 29;
}

public static void debugMemory(String modul, String message) {
if (Global.debugEnabledMemory) {
Runtime r = Runtime.getRuntime();
Expand Down
Expand Up @@ -53,6 +53,7 @@
import uk.co.senab.photoview.log.LogManager;

public class SettingsActivity extends PreferenceActivity {
private static final String PREF_KEY_USE_MEDIA_IMAGE_DB_REPLACEMENT = "useMediaImageDbReplacement";
private static Boolean sOldEnableNonStandardIptcMediaScanner = null;
private SharedPreferences prefsInstance = null;
private ListPreference defaultLocalePreference; // #21: Support to change locale at runtime
Expand Down Expand Up @@ -92,7 +93,9 @@ public static void global2Prefs(Context context) {
prefs.putBoolean("xmp_file_schema_long", LibGlobal.preferLongXmpFormat);

prefs.putBoolean("mapsForgeEnabled", Global.mapsForgeEnabled);
prefs.putBoolean("useMediaImageDbReplacement", Global.useMediaImageDbReplacement);
if (Global.allow_emulate_ao10) {
prefs.putBoolean(PREF_KEY_USE_MEDIA_IMAGE_DB_REPLACEMENT, Global.useAo10MediaImageDbReplacement);
}

prefs.putBoolean("locked", Global.locked);
prefs.putString("passwordHash", Global.passwordHash);
Expand Down Expand Up @@ -172,7 +175,12 @@ public static void prefs2Global(Context context) {
LibGlobal.preferLongXmpFormat = getPref(prefs, "xmp_file_schema_long", LibGlobal.preferLongXmpFormat);

Global.mapsForgeEnabled = getPref(prefs, "mapsForgeEnabled", Global.mapsForgeEnabled);
AndroFotoFinderApp.setMediaImageDbReplacement(context.getApplicationContext(), getPref(prefs, "useMediaImageDbReplacement", Global.useMediaImageDbReplacement));

boolean useAo10MediaImageDbReplacement = Global.useAo10MediaImageDbReplacement;
if (Global.allow_emulate_ao10) {
useAo10MediaImageDbReplacement = getPref(prefs, PREF_KEY_USE_MEDIA_IMAGE_DB_REPLACEMENT, Global.useAo10MediaImageDbReplacement);
}
AndroFotoFinderApp.setMediaImageDbReplacement(context.getApplicationContext(), useAo10MediaImageDbReplacement);

Global.imageDetailThumbnailIfBiggerThan = getPref(prefs, "imageDetailThumbnailIfBiggerThan" , Global.imageDetailThumbnailIfBiggerThan);

Expand Down Expand Up @@ -232,7 +240,9 @@ protected void onCreate(final Bundle savedInstanceState) {
}

this.addPreferencesFromResource(R.xml.preferences);
this.addPreferencesFromResource(R.xml.preferences);
if (Global.allow_emulate_ao10) {
this.addPreferencesFromResource(R.xml.preferences_ao10_test);
}
prefsInstance = PreferenceManager
.getDefaultSharedPreferences(this);
global2Prefs(this.getApplication());
Expand Down
Expand Up @@ -63,7 +63,7 @@ public Cursor loadInBackground() {
try {
Cursor cursor;

cursor = FotoSql.getMediaDBApi().createCursorForQuery(null, "loadader", this.query, null, mCancellationSignal);
cursor = FotoSql.getMediaDBApi().createCursorForQuery(null, "loader", this.query, null, mCancellationSignal);
if (cursor != null) {
try {
// Ensure the cursor window is filled.
Expand Down
8 changes: 1 addition & 7 deletions app/src/main/res/xml/preferences.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2014-2019 k3b
Copyright (C) 2014-2020 k3b
This file is part of "A Photo Manager" (https://github.com/k3b/AndroFotoFinder/)
Expand Down Expand Up @@ -126,12 +126,6 @@ this program. If not, see <http://www.gnu.org/licenses/>

<PreferenceCategory android:title="@string/settings_group_debug_title"
android:key="pref_category_debug">
<CheckBoxPreference
android:defaultValue="true"
android:key="useMediaImageDbReplacement"
android:summary="Experimental"
android:title="TEST Android-10ff Workaround" />

<CheckBoxPreference android:key="debugEnabledSql"
android:defaultValue="false"
android:title="@string/settings_debug_sql_title"
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/xml/preferences_ao10_test.xml
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2020 k3b
This file is part of "A Photo Manager" (https://github.com/k3b/AndroFotoFinder/)
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>
-->

<!-- Expewrimental settings for #155: -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="preferences">
<PreferenceCategory
android:key="pref_category_debug"
android:title="@string/settings_group_debug_title">
<CheckBoxPreference
android:defaultValue="true"
android:key="useMediaImageDbReplacement"
android:summary="Experimental"
android:title="TEST Android-10ff Workaround" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 5066b95

Please sign in to comment.