Commit 39339adf authored by Donald's avatar Donald

backup of album media so the next time when you open that alum there will be...

backup of album media so the next time when you open that alum there will be the images before loading the new ones
parent 528c1d60
...@@ -54,6 +54,7 @@ import org.horaapps.leafpic.activities.base.SharedMediaActivity; ...@@ -54,6 +54,7 @@ import org.horaapps.leafpic.activities.base.SharedMediaActivity;
import org.horaapps.leafpic.adapters.AlbumsAdapter; import org.horaapps.leafpic.adapters.AlbumsAdapter;
import org.horaapps.leafpic.adapters.MediaAdapter; import org.horaapps.leafpic.adapters.MediaAdapter;
import org.horaapps.leafpic.data.CustomAlbumsHelper; import org.horaapps.leafpic.data.CustomAlbumsHelper;
import org.horaapps.leafpic.data.HandlingAlbums;
import org.horaapps.leafpic.data.Media; import org.horaapps.leafpic.data.Media;
import org.horaapps.leafpic.data.base.FilterMode; import org.horaapps.leafpic.data.base.FilterMode;
import org.horaapps.leafpic.data.base.SortingMode; import org.horaapps.leafpic.data.base.SortingMode;
...@@ -201,11 +202,8 @@ public class MainActivity extends SharedMediaActivity { ...@@ -201,11 +202,8 @@ public class MainActivity extends SharedMediaActivity {
toolbar.setTitle(getAlbum().getName()); toolbar.setTitle(getAlbum().getName());
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back)); toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
if (reload) { mediaAdapter.swapDataSet(getAlbum().getMedia());
//display available medias before reload if (reload) new PreparePhotosTask().execute();
mediaAdapter.swapDataSet(getAlbum().getMedia());
new PreparePhotosTask().execute();
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() { toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
...@@ -221,7 +219,6 @@ public class MainActivity extends SharedMediaActivity { ...@@ -221,7 +219,6 @@ public class MainActivity extends SharedMediaActivity {
displayAlbums(true); displayAlbums(true);
else { else {
displayAlbums(false); displayAlbums(false);
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
toggleRecyclersVisibility(true); toggleRecyclersVisibility(true);
} }
} }
...@@ -230,9 +227,8 @@ public class MainActivity extends SharedMediaActivity { ...@@ -230,9 +227,8 @@ public class MainActivity extends SharedMediaActivity {
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_menu)); toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_menu));
toolbar.setTitle(getString(R.string.app_name)); toolbar.setTitle(getString(R.string.app_name));
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
if (reload) new PrepareAlbumTask().execute(); if (reload) new PrepareAlbumTask().execute();
toolbar.setNavigationOnClickListener(new View.OnClickListener() { toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { mDrawerLayout.openDrawer(GravityCompat.START); } public void onClick(View v) { mDrawerLayout.openDrawer(GravityCompat.START); }
...@@ -266,12 +262,10 @@ public class MainActivity extends SharedMediaActivity { ...@@ -266,12 +262,10 @@ public class MainActivity extends SharedMediaActivity {
case SplashScreen.ALBUMS_PREFETCHED: case SplashScreen.ALBUMS_PREFETCHED:
displayAlbums(false); displayAlbums(false);
pickMode = data.getBoolean(SplashScreen.PICK_MODE); pickMode = data.getBoolean(SplashScreen.PICK_MODE);
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
toggleRecyclersVisibility(true); toggleRecyclersVisibility(true);
break; break;
case SplashScreen.ALBUMS_BACKUP: case SplashScreen.ALBUMS_BACKUP:
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
displayAlbums(true); displayAlbums(true);
pickMode = data.getBoolean(SplashScreen.PICK_MODE); pickMode = data.getBoolean(SplashScreen.PICK_MODE);
toggleRecyclersVisibility(true); toggleRecyclersVisibility(true);
...@@ -286,7 +280,6 @@ public class MainActivity extends SharedMediaActivity { ...@@ -286,7 +280,6 @@ public class MainActivity extends SharedMediaActivity {
} }
}).start(); }).start();
displayCurrentAlbumMedia(false); displayCurrentAlbumMedia(false);
mediaAdapter.swapDataSet(getAlbum().getMedia());
toggleRecyclersVisibility(false); toggleRecyclersVisibility(false);
break; break;
} }
...@@ -1423,6 +1416,8 @@ public class MainActivity extends SharedMediaActivity { ...@@ -1423,6 +1416,8 @@ public class MainActivity extends SharedMediaActivity {
@Override @Override
protected void onPostExecute(Void result) { protected void onPostExecute(Void result) {
mediaAdapter.swapDataSet(getAlbum().getMedia()); mediaAdapter.swapDataSet(getAlbum().getMedia());
if (!hidden)
HandlingAlbums.addAlbumToBackup(getApplicationContext(), getAlbum());
checkNothing(); checkNothing();
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
} }
......
...@@ -125,6 +125,8 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder ...@@ -125,6 +125,8 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
} }
public void swapDataSet(ArrayList<Album> asd) { public void swapDataSet(ArrayList<Album> asd) {
if (albums.equals(asd))
return;
albums = asd; albums = asd;
notifyDataSetChanged(); notifyDataSetChanged();
} }
......
...@@ -421,6 +421,14 @@ public class Album implements Serializable { ...@@ -421,6 +421,14 @@ public class Album implements Serializable {
return success; return success;
} }
@Override
public boolean equals(Object obj) {
if (obj instanceof Album) {
return getPath().equals(((Album) obj).getPath());
}
return super.equals(obj);
}
public boolean deleteSelectedMedia(Context context) { public boolean deleteSelectedMedia(Context context) {
boolean success = true; boolean success = true;
for (Media selectedMedia : selectedMedias) { for (Media selectedMedia : selectedMedias) {
......
...@@ -40,7 +40,7 @@ import java.util.Comparator; ...@@ -40,7 +40,7 @@ import java.util.Comparator;
public class HandlingAlbums { public class HandlingAlbums {
public final static String TAG = "HandlingAlbums"; public final static String TAG = "HandlingAlbums";
private String backupFile = "albums.dat"; private static String backupFile = "albums.dat";
public ArrayList<Album> dispAlbums; public ArrayList<Album> dispAlbums;
private ArrayList<Album> selectedAlbums; private ArrayList<Album> selectedAlbums;
...@@ -121,6 +121,43 @@ public class HandlingAlbums { ...@@ -121,6 +121,43 @@ public class HandlingAlbums {
} }
} }
public static void addAlbumToBackup(final Context context, final Album album) {
new Thread(new Runnable() {
public void run() {
try {
boolean success = false;
File f = new File(context.getCacheDir(), backupFile);
ObjectInputStream reader = new ObjectInputStream(new FileInputStream(f));
Object o = reader.readObject();
ArrayList<Album> list = null;
if (o != null) {
list = (ArrayList<Album>) o;
for(int i = 0; i < list.size(); i++) {
if (list.get(i).equals(album)) {
list.remove(i);
list.add(i, album);
success = true;
}
}
}
if (success) {
ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(f));
objectOutStream.writeObject(list);
objectOutStream.close();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}).start();
}
public void restoreBackup(Context context) { public void restoreBackup(Context context) {
FileInputStream inStream; FileInputStream inStream;
......
...@@ -6,7 +6,7 @@ buildscript { ...@@ -6,7 +6,7 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" } maven { url "https://plugins.gradle.org/m2/" }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-rc2' classpath 'com.android.tools.build:gradle:2.2.0'
classpath "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.2.2" classpath "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.2.2"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment