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;
import org.horaapps.leafpic.adapters.AlbumsAdapter;
import org.horaapps.leafpic.adapters.MediaAdapter;
import org.horaapps.leafpic.data.CustomAlbumsHelper;
import org.horaapps.leafpic.data.HandlingAlbums;
import org.horaapps.leafpic.data.Media;
import org.horaapps.leafpic.data.base.FilterMode;
import org.horaapps.leafpic.data.base.SortingMode;
......@@ -201,11 +202,8 @@ public class MainActivity extends SharedMediaActivity {
toolbar.setTitle(getAlbum().getName());
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
if (reload) {
//display available medias before reload
mediaAdapter.swapDataSet(getAlbum().getMedia());
new PreparePhotosTask().execute();
}
mediaAdapter.swapDataSet(getAlbum().getMedia());
if (reload) new PreparePhotosTask().execute();
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -221,7 +219,6 @@ public class MainActivity extends SharedMediaActivity {
displayAlbums(true);
else {
displayAlbums(false);
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
toggleRecyclersVisibility(true);
}
}
......@@ -230,9 +227,8 @@ public class MainActivity extends SharedMediaActivity {
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_menu));
toolbar.setTitle(getString(R.string.app_name));
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
if (reload) new PrepareAlbumTask().execute();
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { mDrawerLayout.openDrawer(GravityCompat.START); }
......@@ -266,12 +262,10 @@ public class MainActivity extends SharedMediaActivity {
case SplashScreen.ALBUMS_PREFETCHED:
displayAlbums(false);
pickMode = data.getBoolean(SplashScreen.PICK_MODE);
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
toggleRecyclersVisibility(true);
break;
case SplashScreen.ALBUMS_BACKUP:
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
displayAlbums(true);
pickMode = data.getBoolean(SplashScreen.PICK_MODE);
toggleRecyclersVisibility(true);
......@@ -286,7 +280,6 @@ public class MainActivity extends SharedMediaActivity {
}
}).start();
displayCurrentAlbumMedia(false);
mediaAdapter.swapDataSet(getAlbum().getMedia());
toggleRecyclersVisibility(false);
break;
}
......@@ -1423,6 +1416,8 @@ public class MainActivity extends SharedMediaActivity {
@Override
protected void onPostExecute(Void result) {
mediaAdapter.swapDataSet(getAlbum().getMedia());
if (!hidden)
HandlingAlbums.addAlbumToBackup(getApplicationContext(), getAlbum());
checkNothing();
swipeRefreshLayout.setRefreshing(false);
}
......
......@@ -125,6 +125,8 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
}
public void swapDataSet(ArrayList<Album> asd) {
if (albums.equals(asd))
return;
albums = asd;
notifyDataSetChanged();
}
......
......@@ -421,6 +421,14 @@ public class Album implements Serializable {
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) {
boolean success = true;
for (Media selectedMedia : selectedMedias) {
......
......@@ -40,7 +40,7 @@ import java.util.Comparator;
public class HandlingAlbums {
public final static String TAG = "HandlingAlbums";
private String backupFile = "albums.dat";
private static String backupFile = "albums.dat";
public ArrayList<Album> dispAlbums;
private ArrayList<Album> selectedAlbums;
......@@ -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) {
FileInputStream inStream;
......
......@@ -6,7 +6,7 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
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"
// NOTE: Do not place your application dependencies here; they belong
// 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