Skip to content

Commit

Permalink
#169: Update to android-9 sdk (API-28) + dynamic ask for WRITE_EXTERN…
Browse files Browse the repository at this point in the history
…AL_STORAGE
  • Loading branch information
k3b committed Mar 23, 2020
1 parent 77bc432 commit 2dd9c90
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 41 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
// Android 6.0 Marshmallow (API 23); Android 7.0 Nougat (API 24)
maxSdkVersion 28 // #155: android-10=api29

targetSdkVersion 21
targetSdkVersion 28

// non-fdroid release
// appXXX are defined in gradle.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ private File getOutpuFile() {
// #60: configure some of the mapsforge settings first
MapsForgeSupport.createInstance(this);

FotoSql.deleteMediaWithNullPath();

Log.i(Global.LOG_CONTEXT, getAppId() + " created");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

package de.k3b.android.androFotoFinder;

import android.os.Bundle;

import de.k3b.android.widget.ActivityWithAutoCloseDialogs;
import de.k3b.android.widget.ActivityWithCallContext;
import de.k3b.android.widget.BaseQueryActivity;
import de.k3b.android.widget.FilePermissionActivity;
import de.k3b.android.widget.LocalizedActivity;
import de.k3b.android.widget.PermissionBaseActivity;

/**
* Nearly all activities are inherited from {@link BaseActivity}.
* * {@link FilePermissionActivity} manage permission write to external-storage and to sdcard
* * {@link PermissionBaseActivity} can Ask for permission
* * {@link ActivityWithAutoCloseDialogs} Automatically closes pop-dialogs
* * {@link LocalizedActivity} Change the locale (language) and translation of its content at runtime
* * {@link ActivityWithCallContext} memorizes the activity call stack (parent Activities) for debugging purposes.
Expand All @@ -39,4 +39,9 @@
* ** {@link de.k3b.android.androFotoFinder.locationmap.MapGeoPickerActivity}
*/
public abstract class BaseActivity extends FilePermissionActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Global.debugMemory(Global.LOG_CONTEXT, "onCreate " + getClass().getSimpleName());
super.onCreate(savedInstanceState);
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/de/k3b/android/androFotoFinder/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ public interface Common {

/** detail,geoEdit: Activity.onActivityResult() - resultCode: one or more photo-files were modified. caller must invalidate cached files/directories. */
int RESULT_CHANGE = Activity.RESULT_OK;

int RESULT_NO_PERMISSIONS = -22;
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ public static void showActivity(String debugContext, Activity context, QueryPara
}

@Override
protected void onCreate(Bundle savedInstanceState) {
Global.debugMemory(mDebugPrefix, "onCreate");
super.onCreate(savedInstanceState);
protected void onCreateEx(Bundle savedInstanceState) {
final Intent intent = getIntent();

if (BuildConfig.DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
}

@Override
protected void onCreate(Bundle savedInstanceState) {
Global.debugMemory(mDebugPrefix, "onCreate");
super.onCreate(savedInstanceState);
protected void onCreateEx(Bundle savedInstanceState) {
final Intent intent = getIntent();

mGalleryFilterPathState = new GalleryFilterPathState().load(this, intent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ public static PhotoAutoprocessingDto getAutoprocessingData(Intent intent) {
}

@Override
protected void onCreate(Bundle savedInstanceState) {
Global.debugMemory(mDebugPrefix, "onCreate");
super.onCreate(savedInstanceState);

protected void onCreateEx(Bundle savedInstanceState) {
this.mLabelGenerator = new AndroidLabelGenerator(getApplicationContext(), "\n");
Intent intent = getIntent();
CharSequence title = (intent == null) ? null : intent.getStringExtra(EXTRA_TITLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
}

@Override
protected void onCreate(Bundle savedInstanceState) {
Global.debugMemory(mDebugPrefix, "onCreate");
super.onCreate(savedInstanceState);
protected void onCreateEx(Bundle savedInstanceState) {
setContentView(R.layout.activity_exif_edit);

edTitle = (EditText) findViewById(R.id.edit_title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ private void loadGuiFromData() {
}

@Override
protected void onCreate(Bundle savedInstanceState) {
Global.debugMemory(mDebugPrefix, "onCreate");
super.onCreate(savedInstanceState);
protected void onCreateEx(Bundle savedInstanceState) {
defineGui();

if (savedInstanceState != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ public static void showActivity(String debugContext, Activity context, Uri image
}

@Override
public void onCreate(Bundle savedInstanceState) {
mDebugPrefix = "ImageDetailActivityViewPager#" + (id++) + " ";
Global.debugMemory(mDebugPrefix, "onCreate");
protected void onCreateEx(Bundle savedInstanceState) {
this.mWaitingForMediaScannerResult = false;

// #17: let actionbar overlap image so there is no need to resize main view item
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019 by k3b.
* Copyright (c) 2015-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -113,9 +113,7 @@ public static void showActivity(String debugContext, Activity context, SelectedF
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

protected void onCreateEx(Bundle savedInstanceState) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
Intent intent = this.getIntent();
if (Global.debugEnabled && (intent != null)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
* Created by k3b on 04.06.2015.
*/
public class FotoSql extends FotoSqlBase {
private static boolean firstRun = true;
public static final String LOG_TAG = Global.LOG_CONTEXT + "-sql";

public static final int SORT_BY_DATE_OLD = 1;
Expand Down Expand Up @@ -282,6 +283,10 @@ public class FotoSql extends FotoSqlBase {
private static IMediaRepositoryApi mediaDBApi;

public static IMediaRepositoryApi getMediaDBApi() {
if ((firstRun) && (FotoSql.mediaDBApi != null)) {
firstRun = false;
FotoSql.deleteMediaWithNullPath();
}
return FotoSql.mediaDBApi;
}

Expand Down Expand Up @@ -1047,12 +1052,14 @@ public static int deleteMediaWithNullPath() {
// return deleteMedia("delete without path (_data = null)", context, wherePathIsNull.toAndroidWhere(), null, false);

SelectedFiles filesWitoutPath = getSelectedfiles(wherePathIsNull, FotoSql.SQL_COL_PATH, VISIBILITY.PRIVATE_PUBLIC);
String pksAsString = filesWitoutPath.toIdString();
if ((pksAsString != null) && (pksAsString.length() > 0)) {
QueryParameter whereInIds = new QueryParameter();
FotoSql.setWhereSelectionPks(whereInIds, pksAsString);
if (filesWitoutPath != null) {
String pksAsString = filesWitoutPath.toIdString();
if ((pksAsString != null) && (pksAsString.length() > 0)) {
QueryParameter whereInIds = new QueryParameter();
FotoSql.setWhereSelectionPks(whereInIds, pksAsString);

return mediaDBApi.deleteMedia("delete without path (_data = null)", whereInIds.toAndroidWhere(), null, true);
return mediaDBApi.deleteMedia("delete without path (_data = null)", whereInIds.toAndroidWhere(), null, true);
}
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ static Cursor createCursorForQuery(
excpetion = ex;
} finally {
if ((excpetion != null) || Global.debugEnabledSql || (out_debugMessage != null)) {
final int count = (query == null) ? 0 : query.getCount();
StringBuilder message = StringUtils.appendMessage(out_debugMessage, excpetion,
dbgContext, MODUL_NAME +
".createCursorForQuery:\n",
QueryParameter.toString(sqlSelectColums, null, from, sqlWhereStatement,
sqlWhereParameters, sqlSortOrder, query.getCount()));
sqlWhereParameters, sqlSortOrder, count));
if (out_debugMessage == null) {
Log.i(LOG_TAG, message.toString(), excpetion);
} // else logging is done by caller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,68 @@

package de.k3b.android.widget;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.widget.Toast;

import de.k3b.android.androFotoFinder.Common;
import de.k3b.android.androFotoFinder.Global;
import de.k3b.android.androFotoFinder.R;

/**
* Manage permission
* * write to external-storage and
* * write to sdcard/usbstick,....
*/
public abstract class FilePermissionActivity extends PermissionBaseActivity {
private void t() {
/*
super.requestPermisson(Manifest.permission.WRITE_EXTERNAL_STORAGE,
"To %s the app needs write permission.",
(_this, result) -> onSaveChangesWithGrant(_this, result));
*/
public abstract class FilePermissionActivity extends ActivityWithAutoCloseDialogs {

private static final int REQUEST_ID_WRITE_EXTERNAL_STORAGE = 2000;
private static final String PERMISSION_WRITE_EXTERNAL_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
&& ActivityCompat.checkSelfPermission(this, PERMISSION_WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
requestPermission(PERMISSION_WRITE_EXTERNAL_STORAGE, REQUEST_ID_WRITE_EXTERNAL_STORAGE);
} else {
onCreateEx(savedInstanceState);
}
}

protected abstract void onCreateEx(Bundle savedInstanceState);

/**
* Callback received when a permissions request has been completed.
*/
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_ID_WRITE_EXTERNAL_STORAGE: {
final boolean success = (grantResults != null)
&& (grantResults.length > 0)
&& (grantResults[0] == PackageManager.PERMISSION_GRANTED);
if (success) {
onCreateEx(null);
} else {
Log.i(Global.LOG_CONTEXT, this.getClass().getSimpleName()
+ ": " + getText(R.string.permission_error));
Toast.makeText(this, R.string.permission_error, Toast.LENGTH_LONG).show();
setResult(Common.RESULT_NO_PERMISSIONS, null);
finish();
}
return;
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

protected void requestPermission(final String permission, final int requestCode) {
ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,7 @@ You can undo hiding by calling the mediascanner from gallery-menu."</string>
<!-- #155: android10 -->
<string name="load_db_menu_title">(Re)Load Media Database</string>

<!-- #169: sd-card-saf-write-permission support -->
<string name="permission_error">Missing permisions</string>
</resources>

0 comments on commit 2dd9c90

Please sign in to comment.