Commit c8cc290a authored by Donald's avatar Donald

asd

parent e669a260
......@@ -13,8 +13,8 @@ android {
applicationId "org.horaapps.leafpic"
minSdkVersion 19
targetSdkVersion 25
versionName "v0.6-beta-1"
versionCode 13
versionName "v0.6-beta-2"
versionCode 14
}
lintOptions {
disable 'MissingTranslation'
......
......@@ -86,7 +86,7 @@
<activity
android:name="org.horaapps.leafpic.activities.SingleMediaActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|uiMode|touchscreen|screenLayout"
android:configChanges="orientation|screenSize|uiMode|screenLayout|navigation"
android:parentActivityName="org.horaapps.leafpic.activities.MainActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
<meta-data
......
......@@ -74,7 +74,7 @@ import java.util.Locale;
public class MainActivity extends SharedMediaActivity {
private static String TAG = "AlbumsAct";
private static String TAG = MainActivity.class.getSimpleName();
private PreferenceUtil SP;
......@@ -92,7 +92,6 @@ public class MainActivity extends SharedMediaActivity {
private SwipeRefreshLayout swipeRefreshLayout;
private CoordinatorLayout coordinatorMainLayout;
private boolean hidden = false, pickMode = false, editMode = false, albumsMode = true, firstLaunch = true;
private View.OnLongClickListener photosOnLongClickListener = new View.OnLongClickListener() {
......@@ -129,14 +128,12 @@ public class MainActivity extends SharedMediaActivity {
setResult(RESULT_OK, new Intent().setData(m.getUri()));
finish();
}
}
};
private View.OnLongClickListener albumOnLongCLickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
albumsAdapter.notifyItemChanged(getAlbums().toggleSelectAlbum(((Album) v.findViewById(R.id.album_name).getTag())));
editMode = true;
supportInvalidateOptionsMenu();
......@@ -173,7 +170,7 @@ public class MainActivity extends SharedMediaActivity {
SP = PreferenceUtil.getInstance(getApplicationContext());
initUi();
displayData(getIntent().getExtras());
displayData(getIntent());
}
@Override
......@@ -245,37 +242,31 @@ public class MainActivity extends SharedMediaActivity {
}
}
private boolean displayData(Bundle data){
if (data!=null) {
switch (data.getInt(SplashScreen.CONTENT)) {
case SplashScreen.ALBUMS_PREFETCHED:
displayAlbums(false);
pickMode = data.getBoolean(SplashScreen.PICK_MODE);
toggleRecyclersVisibility(true);
return true;
case SplashScreen.ALBUMS_BACKUP:
displayAlbums(true);
pickMode = data.getBoolean(SplashScreen.PICK_MODE);
toggleRecyclersVisibility(true);
return true;
case SplashScreen.PHOTOS_PREFETCHED:
//TODO ask password if hidden
new Thread(new Runnable() {
@Override
public void run() {
getAlbums().loadAlbums(getApplicationContext(), getAlbum().isHidden());
}
}).start();
displayCurrentAlbumMedia(false);
toggleRecyclersVisibility(false);
return true;
}
}
private boolean displayData(Intent data){
pickMode = data.getBooleanExtra(SplashScreen.PICK_MODE, false);
switch (data.getIntExtra(SplashScreen.CONTENT, SplashScreen.ALBUMS_BACKUP)) {
case SplashScreen.ALBUMS_PREFETCHED:
displayAlbums(false);
toggleRecyclersVisibility(true);
return true;
displayAlbums(true);
return false;
default: case SplashScreen.ALBUMS_BACKUP:
displayAlbums(true);
toggleRecyclersVisibility(true);
return true;
case SplashScreen.PHOTOS_PREFETCHED:
//TODO ask password if hidden
new Thread(new Runnable() {
@Override
public void run() {
getAlbums().loadAlbums(getApplicationContext(), getAlbum().isHidden());
}
}).start();
displayCurrentAlbumMedia(false);
toggleRecyclersVisibility(false);
return true;
}
}
private void initUi() {
......@@ -481,8 +472,7 @@ public class MainActivity extends SharedMediaActivity {
}
private void updateColumnsRvs() {
int spanCountAlbums;
int spanCountMedias;
int spanCountAlbums, spanCountMedias;
if (getResources().getConfiguration().orientation==Configuration.ORIENTATION_PORTRAIT) {
spanCountAlbums = SP.getInt("n_columns_folders", 2);
spanCountMedias = SP.getInt("n_columns_media", 3);
......@@ -490,13 +480,13 @@ public class MainActivity extends SharedMediaActivity {
spanCountAlbums = SP.getInt("n_columns_folders_landscape", 3);
spanCountMedias = SP.getInt("n_columns_media_landscape", 4);
}
if (spanCountAlbums!= ((GridLayoutManager) rvAlbums.getLayoutManager()).getSpanCount()) {
if (spanCountAlbums != ((GridLayoutManager) rvAlbums.getLayoutManager()).getSpanCount()) {
rvAlbums.removeItemDecoration(rvAlbumsDecoration);
rvAlbumsDecoration = new GridSpacingItemDecoration(spanCountAlbums, Measure.pxToDp(3, getApplicationContext()), true);
rvAlbums.addItemDecoration(rvAlbumsDecoration);
rvAlbums.setLayoutManager(new GridLayoutManager(this, spanCountAlbums));
}
if (spanCountMedias!= ((GridLayoutManager) rvMedia.getLayoutManager()).getSpanCount()) {
if (spanCountMedias != ((GridLayoutManager) rvMedia.getLayoutManager()).getSpanCount()) {
((GridLayoutManager) rvMedia.getLayoutManager()).getSpanCount();
rvMedia.removeItemDecoration(rvMediaDecoration);
rvMediaDecoration = new GridSpacingItemDecoration(spanCountMedias, Measure.pxToDp(3, getApplicationContext()), true);
......@@ -507,7 +497,7 @@ public class MainActivity extends SharedMediaActivity {
private void updateSelectedStuff() {
if (albumsMode) {
if (editMode) toolbar.setTitle(getAlbums().getSelectedCount() + "/" + getAlbums().albums.size());
if (editMode) toolbar.setTitle(getAlbums().getSelectedCount() + "/" + getAlbums().getCount());
else {
toolbar.setTitle(getString(R.string.app_name));
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_menu));
......@@ -559,7 +549,7 @@ public class MainActivity extends SharedMediaActivity {
((IconicsImageView) findViewById(R.id.nothing_to_show_icon)).setColor(getSubTextColor());
((TextView) findViewById(R.id.nothing_to_show)).setTextColor(getSubTextColor());
((LinearLayout) findViewById(R.id.ll_nothing_to_show)).setVisibility(
albumsMode && getAlbums().albums.size() == 0 ||
albumsMode && getAlbums().getCount() == 0 ||
!albumsMode && getAlbum().getMedia().size() == 0
? View.VISIBLE : View.GONE);
}
......
......@@ -17,7 +17,6 @@ import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Surface;
......@@ -66,6 +65,8 @@ import java.io.InputStream;
@SuppressWarnings("ResourceAsColor")
public class SingleMediaActivity extends SharedMediaActivity {
private static final String TAG = SingleMediaActivity.class.getSimpleName();
private static final String ISLOCKED_ARG = "isLocked";
static final String ACTION_OPEN_ALBUM = "android.intent.action.pagerAlbumMedia";
private static final String ACTION_REVIEW = "com.android.camera.action.REVIEW";
......@@ -73,7 +74,7 @@ public class SingleMediaActivity extends SharedMediaActivity {
private HackyViewPager mViewPager;
private MediaPagerAdapter adapter;
private PreferenceUtil SP;
private RelativeLayout ActivityBackground;
private RelativeLayout activityBackground;
private Toolbar toolbar;
private boolean fullScreenMode, customUri = false;
......@@ -83,6 +84,7 @@ public class SingleMediaActivity extends SharedMediaActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_media);
toolbar = (Toolbar) findViewById(R.id.toolbar);
activityBackground = (RelativeLayout) findViewById(R.id.PhotoPager_Layout);
mViewPager = (HackyViewPager) findViewById(R.id.photos_pager);
SP = PreferenceUtil.getInstance(getApplicationContext());
......@@ -156,7 +158,6 @@ public class SingleMediaActivity extends SharedMediaActivity {
mViewPager.setAdapter(adapter);
mViewPager.setCurrentItem(getAlbum().getCurrentMediaIndex());
mViewPager.setPageTransformer(true, new DepthPageTransformer());
mViewPager.setOffscreenPageLimit(3);
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { }
......@@ -169,9 +170,7 @@ public class SingleMediaActivity extends SharedMediaActivity {
@Override public void onPageScrollStateChanged(int state) { }
});
Display aa = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
if (aa.getRotation() == Surface.ROTATION_90) {
if (((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getRotation() == Surface.ROTATION_90) {
Configuration configuration = new Configuration();
configuration.orientation = Configuration.ORIENTATION_LANDSCAPE;
onConfigurationChanged(configuration);
......@@ -181,6 +180,7 @@ public class SingleMediaActivity extends SharedMediaActivity {
public void updateUiElements() {
/**** Theme ****/
toolbar = (Toolbar) findViewById(R.id.toolbar);
activityBackground = (RelativeLayout) findViewById(R.id.PhotoPager_Layout);
toolbar.setBackgroundColor(
themeOnSingleImgAct()
? ColorPalette.getTransparentColor (getPrimaryColor(), getTransparency())
......@@ -188,8 +188,8 @@ public class SingleMediaActivity extends SharedMediaActivity {
toolbar.setPopupTheme(getPopupToolbarStyle());
ActivityBackground = (RelativeLayout) findViewById(R.id.PhotoPager_Layout);
ActivityBackground.setBackgroundColor(getBackgroundColor());
activityBackground.setBackgroundColor(getBackgroundColor());
setStatusBarColor();
setNavBarColor();
......@@ -610,6 +610,12 @@ public class SingleMediaActivity extends SharedMediaActivity {
public void run() {
toolbar.animate().translationY(-toolbar.getHeight()).setInterpolator(new AccelerateInterpolator())
.setDuration(200).start();
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
Log.wtf(TAG, "ui changed: "+visibility);
}
});
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
......@@ -664,7 +670,7 @@ public class SingleMediaActivity extends SharedMediaActivity {
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
ActivityBackground.setBackgroundColor((Integer) animator.getAnimatedValue());
activityBackground.setBackgroundColor((Integer) animator.getAnimatedValue());
}
});
colorAnimation.start();
......
......@@ -29,24 +29,26 @@ import org.horaapps.leafpic.util.PreferenceUtil;
import org.horaapps.leafpic.util.StringUtils;
import java.io.File;
import java.util.List;
/**
* Created by dnld on 01/04/16.
*/
public class SplashScreen extends SharedMediaActivity {
private final String TAG = SplashScreen.class.getSimpleName();
private final int READ_EXTERNAL_STORAGE_ID = 12;
private static final int PICK_MEDIA_REQUEST = 44;
final static String CONTENT = "content";
final static String PICK_MODE = "pick_mode";
final static int ALBUMS_PREFETCHED = 23;
final static int PHOTOS_PREFETCHED = 2;
final static int ALBUMS_BACKUP = 60;
final static int ALBUMS_PREFETCHED = 2376;
final static int PHOTOS_PREFETCHED = 2567;
final static int ALBUMS_BACKUP = 1312;
private boolean PICK_INTENT = false;
public final static String ACTION_OPEN_ALBUM = "com.horaapps.leafpic.OPEN_ALBUM";
public final static String ACTION_OPEN_ALBUM = "org.horaapps.leafpic.OPEN_ALBUM";
private Album tmpAlbum;
private PreferenceUtil SP;
......@@ -56,7 +58,6 @@ public class SplashScreen extends SharedMediaActivity {
super.onCreate(savedInstanceState);
setContentView(org.horaapps.leafpic.R.layout.activity_splash);
SP = PreferenceUtil.getInstance(getApplicationContext());
startLookingForMedia();
getWindow().getDecorView().setSystemUiVisibility(
......@@ -67,30 +68,26 @@ public class SplashScreen extends SharedMediaActivity {
setStatusBarColor();
if (PermissionUtils.isDeviceInfoGranted(this)) {
if (getIntent().getAction().equals(ACTION_OPEN_ALBUM)) {
Bundle data = getIntent().getExtras();
if (data != null) {
String ab = data.getString("albumPath");
if (ab != null) {
File dir = new File(ab);
// TODO: 19/08/16 look for id
tmpAlbum = new Album(getApplicationContext(), dir.getAbsolutePath(), data.getInt("albumId", -1), dir.getName(), -1);
new PrefetchPhotosData().execute();
}
} else StringUtils.showToast(getApplicationContext(), "Album not found");
} else { // default intent
} else // default intent
new PrefetchAlbumsData().execute();
}
PICK_INTENT = getIntent().getAction().equals(Intent.ACTION_GET_CONTENT) || getIntent().getAction().equals(Intent.ACTION_PICK);
if (getIntent().getAction().equals(Intent.ACTION_GET_CONTENT) || getIntent().getAction().equals(Intent.ACTION_PICK))
PICK_INTENT = true;
} else
PermissionUtils.requestPermissions(this, READ_EXTERNAL_STORAGE_ID, Manifest.permission.READ_EXTERNAL_STORAGE);
} else {
String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE};
PermissionUtils.requestPermissions(this, READ_EXTERNAL_STORAGE_ID, permissions);
}
startLookingForMedia();
}
private void startLookingForMedia() {
......@@ -98,32 +95,21 @@ public class SplashScreen extends SharedMediaActivity {
new Thread(new Runnable() {
@Override
public void run() {
ComponentName serviceName = new ComponentName(getApplicationContext(), LookForMediaJob.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (getAlbums().getFoldersCount(HandlingAlbums.EXCLUDED) > 0) {
JobInfo job = new JobInfo.Builder(0, serviceName)
.setPeriodic(1000)
.setRequiresDeviceIdle(true)
.build();
JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (scheduler.getAllPendingJobs().size() == 0) {
List<JobInfo> allPendingJobs = scheduler.getAllPendingJobs();
Log.wtf("FUCK", allPendingJobs.size() + "");
int result = scheduler.schedule(job);
if (result == JobScheduler.RESULT_SUCCESS) {
Log.wtf("FUCK", "Job scheduled successfully!");
} else
Log.wtf("FUCK", "Job scheduled failed!");
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && getAlbums().getFoldersCount(HandlingAlbums.INCLUDED) > 0) {
JobInfo job = new JobInfo.Builder(0, new ComponentName(getApplicationContext(), LookForMediaJob.class))
.setPeriodic(1000)
.setRequiresDeviceIdle(true)
.build();
JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (scheduler.getAllPendingJobs().size() == 0)
Log.wtf(TAG, scheduler.schedule(job) == JobScheduler.RESULT_SUCCESS
? "LookForMediaJob scheduled successfully!" : "LookForMediaJob scheduled failed!");
}
}
}).start();
}
@Override
......@@ -159,11 +145,8 @@ public class SplashScreen extends SharedMediaActivity {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case READ_EXTERNAL_STORAGE_ID:
boolean granted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
if (granted)
new PrefetchAlbumsData().execute(SP.getBoolean(getString(org.horaapps.leafpic.R.string.preference_auto_update_media), false));
else
Toast.makeText(SplashScreen.this, getString(org.horaapps.leafpic.R.string.storage_permission_denied), Toast.LENGTH_LONG).show();
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) new PrefetchAlbumsData().execute();
else Toast.makeText(SplashScreen.this, getString(org.horaapps.leafpic.R.string.storage_permission_denied), Toast.LENGTH_LONG).show();
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
......@@ -176,12 +159,11 @@ public class SplashScreen extends SharedMediaActivity {
findViewById(org.horaapps.leafpic.R.id.Splah_Bg).setBackgroundColor(getBackgroundColor());
}
private class PrefetchAlbumsData extends AsyncTask<Boolean, Boolean, Boolean> {
private class PrefetchAlbumsData extends AsyncTask<Void, Boolean, Boolean> {
@Override
protected Boolean doInBackground(Boolean... arg0) {
getAlbums().restoreBackup(getApplicationContext());
if(getAlbums().albums.size() == 0) {
protected Boolean doInBackground(Void... arg0) {
if(!getAlbums().restoreBackup(getApplicationContext()) || getAlbums().getCount() == 0) {
getAlbums().loadAlbums(getApplicationContext(), false);
return true;
}
......@@ -193,16 +175,15 @@ public class SplashScreen extends SharedMediaActivity {
super.onPostExecute(result);
Intent i = new Intent(SplashScreen.this, MainActivity.class);
Bundle b = new Bundle();
b.putInt(CONTENT, result ? ALBUMS_PREFETCHED : ALBUMS_BACKUP);
b.putBoolean(PICK_MODE, PICK_INTENT);
i.putExtras(b);
if (PICK_INTENT)
startActivityForResult(i, PICK_MEDIA_REQUEST);
else {
i.putExtra(CONTENT, result ? ALBUMS_PREFETCHED : ALBUMS_BACKUP);
i.putExtra(PICK_MODE, PICK_INTENT);
if (!PICK_INTENT) {
startActivity(i);
finish();
}
} else
startActivityForResult(i, PICK_MEDIA_REQUEST);
if(result)
getAlbums().saveBackup(getApplicationContext());
}
......@@ -219,10 +200,8 @@ public class SplashScreen extends SharedMediaActivity {
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Intent i = new Intent(SplashScreen.this, MainActivity.class);
Bundle b = new Bundle();
getAlbums().addAlbum(0, tmpAlbum);
b.putInt(CONTENT, PHOTOS_PREFETCHED);
i.putExtras(b);
i.putExtra(CONTENT, PHOTOS_PREFETCHED);
startActivity(i);
finish();
}
......
......@@ -113,7 +113,6 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
}
}
holder.llMdia.setVisibility(SP.getBoolean("show_n_photos", true) ? View.VISIBLE : View.GONE);
String albumNameHtml = "<i><font color='" + textColor + "'>" + a.getName() + "</font></i>";
String albumPhotoCountHtml = "<b><font color='" + hexAccentColor + "'>" + a.getCount() + "</font></b>";
......
......@@ -20,8 +20,9 @@ import java.util.ArrayList;
public class MediaPagerAdapter extends FragmentStatePagerAdapter {
private final String TAG = "asd";
private ArrayList<Media> media;
private SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();
private SparseArray<Fragment> registeredFragments = new SparseArray<>();
public MediaPagerAdapter(FragmentManager fm, ArrayList<Media> media) {
super(fm);
......@@ -30,9 +31,7 @@ public class MediaPagerAdapter extends FragmentStatePagerAdapter {
@Override public Fragment getItem(int pos) {
Media media = this.media.get(pos);
if (media.isVideo()) {
return VideoFragment.newInstance(media);
}
if (media.isVideo()) return VideoFragment.newInstance(media);
if (media.isGif()) return GifFragment.newInstance(media);
else return ImageFragment.newInstance(media);
}
......
......@@ -31,13 +31,13 @@ import uk.co.senab.photoview.PhotoViewAttacher;
public class ImageFragment extends Fragment {
private Media img;
private final String TAG = "asd";
public static ImageFragment newInstance(Media media) {
ImageFragment imageFragment = new ImageFragment();
Bundle args = new Bundle();
args.putParcelable("image", media);
imageFragment.setArguments(args);
return imageFragment;
}
......@@ -50,7 +50,7 @@ public class ImageFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (PreferenceUtil.getInstance(getContext()).getBoolean(getString(R.string.preference_sub_scaling) , false)) {
if (PreferenceUtil.getInstance(getContext()).getBoolean(getString(R.string.preference_sub_scaling) , true)) {
SubsamplingScaleImageView imageView = new SubsamplingScaleImageView(getContext());
imageView.setImage(ImageSource.uri(img.getUri()));
imageView.setOnClickListener(new View.OnClickListener() {
......
......@@ -15,6 +15,7 @@ import android.media.ThumbnailUtils;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import org.horaapps.leafpic.R;
import org.horaapps.leafpic.activities.SplashScreen;
......@@ -23,16 +24,17 @@ import org.horaapps.leafpic.model.base.SortingMode;
import org.horaapps.leafpic.model.base.SortingOrder;
import org.horaapps.leafpic.util.ContentHelper;
import org.horaapps.leafpic.util.PreferenceUtil;
import org.horaapps.leafpic.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
/**
* Created by dnld on 27/04/16.
......@@ -55,7 +57,7 @@ public class HandlingAlbums extends SQLiteOpenHelper {
private static final String ALBUM_SORTING_ORDER = "sort_ascending";
private static final String ALBUM_COLUMN_COUNT = "sorting_order";
private static final String backupFile = "albums.bck";
private static final String backupFile = "albums2.bck";
private static HandlingAlbums mInstance = null;
public ArrayList<Album> albums = null;
......@@ -271,8 +273,7 @@ public class HandlingAlbums extends SQLiteOpenHelper {
new Thread(new Runnable() {
public void run() {
try {
FileOutputStream outStream = new FileOutputStream(new File(context.getCacheDir(), backupFile));
ObjectOutputStream objectOutStream = new ObjectOutputStream(outStream);
ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(new File(context.getCacheDir(), backupFile)));
objectOutStream.writeObject(albums);
objectOutStream.close();
} catch (Exception e) {
......@@ -301,8 +302,7 @@ public class HandlingAlbums extends SQLiteOpenHelper {
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);
list.set(i, album);
success = true;
}
}
......@@ -322,17 +322,26 @@ public class HandlingAlbums extends SQLiteOpenHelper {
}
public void restoreBackup(Context context) {
FileInputStream inStream;
public boolean restoreBackup(Context context) {
boolean success = false;
ObjectInputStream objectInStream = null;
try {
File f = new File(context.getCacheDir(), backupFile);
inStream = new FileInputStream(f);
ObjectInputStream objectInStream = new ObjectInputStream(inStream);
objectInStream = new ObjectInputStream(new FileInputStream(f));
Object o = objectInStream.readObject();
if(o.getClass().equals(ArrayList.class))
if(o.getClass().equals(ArrayList.class)) {
albums = (ArrayList<Album>) o;
objectInStream.close();
} catch (Exception e) { albums.clear(); }
success = true;
}
} catch (Exception e) {
albums.clear();
success = false;
} finally {
if (objectInStream != null)
try { objectInStream.close(); }
catch (IOException ignored) { }
}
return success;
}
private int toggleSelectAlbum(int index) {
......@@ -371,11 +380,11 @@ public class HandlingAlbums extends SQLiteOpenHelper {
selectedAlbums.clear();
}
public void installShortcutForSelectedAlbums(Context appCtx) {
public void installShortcutForSelectedAlbums(Context context) {
for (Album selectedAlbum : selectedAlbums) {
Intent shortcutIntent;
shortcutIntent = new Intent(appCtx, SplashScreen.class);
shortcutIntent = new Intent(context, SplashScreen.class);
shortcutIntent.setAction(SplashScreen.ACTION_OPEN_ALBUM);
shortcutIntent.putExtra("albumPath", selectedAlbum.getPath());
shortcutIntent.putExtra("albumId", selectedAlbum.getId());
......@@ -386,22 +395,22 @@ public class HandlingAlbums extends SQLiteOpenHelper {
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, selectedAlbum.getName());
File image = new File(selectedAlbum.getCoverAlbum().getPath());
Bitmap bitmap;
Media coverAlbum = selectedAlbum.getCoverAlbum();
File image = new File(coverAlbum.getPath());
Bitmap bitmap = coverAlbum.isVideo() ? ThumbnailUtils.createVideoThumbnail(coverAlbum.getPath(), MediaStore.Images.Thumbnails.MINI_KIND)
: BitmapFactory.decodeFile(image.getAbsolutePath(), new BitmapFactory.Options());
String mime = StringUtils.getMimeType(image.getAbsolutePath());
if (bitmap == null) {
Toast.makeText(context, R.string.error_thumbnail, Toast.LENGTH_SHORT).show();
// TODO: 12/31/16
return;
}
if(mime.startsWith("image")) {
bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), new BitmapFactory.Options());
} else if(mime.startsWith("video")) {
bitmap = ThumbnailUtils.createVideoThumbnail(selectedAlbum.getCoverAlbum().getPath(),
MediaStore.Images.Thumbnails.MINI_KIND);
} else return;
bitmap = Bitmap.createScaledBitmap(getCroppedBitmap(bitmap), 128, 128, false);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, addWhiteBorder(bitmap, 5));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
appCtx.sendBroadcast(addIntent);
context.sendBroadcast(addIntent);
}
}
......@@ -511,9 +520,12 @@ public class HandlingAlbums extends SQLiteOpenHelper {
Album camera = null;
for(Album album : albums) {
if (album.getName().equals("Camera") && albums.remove(album)) {
camera = album;
Iterator<Album> iterator = albums.iterator();
while (iterator.hasNext()) {
Album a = iterator.next();
if (a.getName().equals("Camera")) {
camera = a;
iterator.remove();
break;
}
}
......@@ -527,8 +539,4 @@ public class HandlingAlbums extends SQLiteOpenHelper {
}
public Album getSelectedAlbum(int index) { return selectedAlbums.get(index); }
public void loadAlbums(Context applicationContext) {
loadAlbums(applicationContext, hidden);
}
}
......@@ -371,4 +371,5 @@ and this could make the media inaccessible from other apps. Use the exclude opti
White-listed folders will be scanned periodically when the device is in idle mode, so it won\'t cause any performance issue</string>
<string name="no_media_in_this_folder">No media in this folder</string>
<string name="error_occured_open_media">An error occurred opening this media.</string>
<string name="error_thumbnail">Unable to find a thumbnail for the album!</string>
</resources>
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