Skip to content

Commit

Permalink
#155: Refactored: Moved notivication logic to PhotoChangeNotifyer and…
Browse files Browse the repository at this point in the history
… GlobalMediaContentObserver
  • Loading branch information
k3b committed Jan 28, 2020
1 parent 318f040 commit 5f9b8a9
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
Expand Down Expand Up @@ -51,6 +50,7 @@
import de.k3b.android.androFotoFinder.queries.MergedMediaRepository;
import de.k3b.android.osmdroid.forge.MapsForgeSupport;
import de.k3b.android.util.LogCat;
import de.k3b.android.util.PhotoChangeNotifyer;
import de.k3b.android.widget.ActivityWithCallContext;
import de.k3b.android.widget.LocalizedActivity;
import de.k3b.database.QueryParameter;
Expand Down Expand Up @@ -115,11 +115,10 @@ public static void setMediaImageDbReplacement(Context context, boolean useMediaI
MediaContent2DBUpdateService.instance.rebuild(context, null);
}

context.getApplicationContext().getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, GlobalMediaContentObserver.getInstance(context));
context.getApplicationContext().getContentResolver().registerContentObserver(MediaStore.Files.getContentUri("external"), true, GlobalMediaContentObserver.getInstance(context));
PhotoChangeNotifyer.registerContentObserver(context, GlobalMediaContentObserver.getInstance(context));

} else {
context.getApplicationContext().getContentResolver().unregisterContentObserver(GlobalMediaContentObserver.getInstance(context));
PhotoChangeNotifyer.unregisterContentObserver(context, GlobalMediaContentObserver.getInstance(context));
if ((oldMediaDBApi != null) && (MediaContent2DBUpdateService.instance != null)) {
// switching from mediaImageDbReplacement to Contentprovider
MediaContent2DBUpdateService.instance.clearMediaCopy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@

import de.k3b.android.androFotoFinder.Global;
import de.k3b.android.androFotoFinder.R;
import de.k3b.android.util.PhotoChangeNotifyer;
import de.k3b.io.AlbumFile;
import de.k3b.io.Directory;
import de.k3b.io.FileUtils;
import de.k3b.io.IDirectory;
import de.k3b.io.IExpandableListViewNavigation;

/**
* Maps android independent IExpandableListViewNavigation to android specific ExpandableListAdapter so it can be viewed in ExpandableList
*/

public class DirectoryListAdapter extends BaseExpandableListAdapter implements IExpandableListViewNavigation<Object, Object> {
public class DirectoryListAdapter extends BaseExpandableListAdapter implements
IExpandableListViewNavigation<Object, Object>, PhotoChangeNotifyer.PhotoChangedListener {


private LayoutInflater inflater;
Expand Down Expand Up @@ -219,4 +220,12 @@ public static Spanned getDirectoryDisplayText(String prefix, IDirectory director
Directory.appendCount(result, directory, options);
return Html.fromHtml(result.toString());
}

/**
* PhotoChangeNotifyer.PhotoChangedListener
**/
@Override
public void onNotifyPhotoChanged() {
notifyDataSetChanged();
}
}
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 @@ -70,6 +70,7 @@
import de.k3b.android.util.ClipboardUtil;
import de.k3b.android.util.FileManagerUtil;
import de.k3b.android.util.IntentUtil;
import de.k3b.android.util.PhotoChangeNotifyer;
import de.k3b.android.util.PhotoPropertiesMediaFilesScanner;
import de.k3b.android.widget.Dialogs;
import de.k3b.database.QueryParameter;
Expand Down Expand Up @@ -456,8 +457,8 @@ protected boolean onPopUpClick(MenuItem menuItem, IDirectory popUpSelection) {
}
}

public void notifyDataSetChanged() {
if (this.mAdapter != null) this.mAdapter.notifyDataSetChanged();
public void notifyPhotoChanged() {
PhotoChangeNotifyer.notifyPhotoChanged(this.getActivity(), this.mAdapter);
}

private boolean onCopy(IDirectory selection) {
Expand Down Expand Up @@ -607,7 +608,7 @@ private void onRenameDirAnswer(final IDirectory srcDir, String newFolderName) {
} else {
// update dirpicker
srcDir.rename(srcDirFile.getName(), newFolderName);
notifyDataSetChanged();
notifyPhotoChanged();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 by k3b.
* Copyright (c) 2018-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand All @@ -20,7 +20,6 @@
package de.k3b.android.androFotoFinder.directory;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -29,19 +28,15 @@

import java.io.File;

import de.k3b.android.androFotoFinder.AffUtils;
import de.k3b.android.androFotoFinder.R;
import de.k3b.android.androFotoFinder.imagedetail.ImageDetailActivityViewPager;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.util.AndroidFileCommands;
import de.k3b.android.util.OsUtils;
import de.k3b.io.AlbumFile;
import de.k3b.io.FileUtils;
import de.k3b.io.IDirectory;
import de.k3b.io.OSDirOrVirtualAlbumFile;
import de.k3b.io.OSDirectory;
import de.k3b.io.StringUtils;
import de.k3b.io.collections.SelectedFiles;

/**
* a picker with a fale name field and a directory picker.
Expand Down Expand Up @@ -132,7 +127,7 @@ protected void onDirectoryPick(IDirectory selection) {
// close dialog and return to caller
super.onDirectoryPick(result);
onFilePick(new File(result.getAbsolute()));
this.notifyDataSetChanged();
this.notifyPhotoChanged();
dismiss();
}
}
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 @@ -40,6 +40,7 @@
import de.k3b.android.androFotoFinder.imagedetail.HugeImageLoader;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.util.DBUtils;
import de.k3b.android.util.PhotoChangeNotifyer;
import de.k3b.io.collections.SelectedFiles;
import de.k3b.io.collections.SelectedItems;
import de.k3b.media.PhotoPropertiesUtil;
Expand All @@ -60,7 +61,7 @@
*
* Created by k3b on 02.06.2015.
*/
public class GalleryCursorAdapter extends CursorAdapter {
public class GalleryCursorAdapter extends CursorAdapter implements PhotoChangeNotifyer.PhotoChangedListener {
private static final int MAX_IMAGE_DIMENSION = HugeImageLoader.getMaxTextureSize();

// Identifies a particular Loader or a LoaderManager being used in this component
Expand Down Expand Up @@ -234,4 +235,12 @@ public long getImageId(int position) {
return DBUtils.getLong(cursor, FotoSql.SQL_COL_PK, 0);
}

/**
* PhotoChangeNotifyer.PhotoChangedListener
**/
@Override
public void onNotifyPhotoChanged() {
notifyDataSetChanged();
}

}
Loading

0 comments on commit 5f9b8a9

Please sign in to comment.