Commit 3b0027da authored by Gilbert Ndresaj's avatar Gilbert Ndresaj

Merge pull request #7 from DNLDsht/master

Merge Donald
parents 2c5619b0 99a2c0d4
......@@ -18,11 +18,7 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.*;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
......@@ -36,7 +32,7 @@ import com.leafpic.app.Adapters.AlbumsAdapter;
import com.leafpic.app.Base.Album;
import com.leafpic.app.Base.HandlingAlbums;
import com.leafpic.app.Base.HiddenPhotosHandler;
import com.leafpic.app.utils.string;
import com.leafpic.app.utils.StringUtils;
import com.mikepenz.fontawesome_typeface_library.FontAwesome;
import com.mikepenz.iconics.context.IconicsContextWrapper;
import com.mikepenz.materialdrawer.AccountHeader;
......@@ -212,7 +208,7 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
@Override
public void onFolderSelection(@NonNull File folder) {
HiddenPhotosHandler h = new HiddenPhotosHandler(getApplicationContext());
string.showToast(getApplicationContext(), folder.getAbsolutePath());
StringUtils.showToast(getApplicationContext(), folder.getAbsolutePath());
h.addImagesFromFolder(folder);
albums.loadPreviewHiddenAlbums();
......@@ -230,7 +226,7 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(AlbumsActivity.this,
Manifest.permission.INTERNET))
string.showToast(AlbumsActivity.this, "eddai dammi internet");
StringUtils.showToast(AlbumsActivity.this, "eddai dammi internet");
else
ActivityCompat.requestPermissions(AlbumsActivity.this,
new String[]{Manifest.permission.INTERNET}, 1);
......@@ -240,7 +236,7 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(AlbumsActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE))
string.showToast(AlbumsActivity.this, "no storage permission");
StringUtils.showToast(AlbumsActivity.this, "no storage permission");
else
ActivityCompat.requestPermissions(AlbumsActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
......@@ -311,7 +307,7 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
string.showToast(getApplicationContext(), "asdasd");
StringUtils.showToast(getApplicationContext(), "asdasd");
return true;
case R.id.sort_action:
......@@ -433,7 +429,7 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
break;
case 1:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
string.showToast(AlbumsActivity.this, "i got NET");
StringUtils.showToast(AlbumsActivity.this, "i got NET");
break;
}
}
......
......@@ -3,7 +3,7 @@ package com.leafpic.app.Base;
import android.os.Parcel;
import android.os.Parcelable;
import com.leafpic.app.R;
import com.leafpic.app.utils.string;
import com.leafpic.app.utils.StringUtils;
import java.util.ArrayList;
......@@ -40,6 +40,9 @@ public class Album implements Parcelable {
imagesCount = count;
}
public Album() {
}
public Album(String path, String displayName, boolean hidden, int count) {
photos = new ArrayList<Photo>();
......@@ -66,7 +69,7 @@ public class Album implements Parcelable {
public void setPath() {
try {
Path = string.getBucketPathbyImagePath(photos.get(0).Path);
Path = StringUtils.getBucketPathbyImagePath(photos.get(0).Path);
} catch (NullPointerException e) {
e.printStackTrace();
}
......
package com.leafpic.app.Base;
/**
* Created by dnld on 2/4/16.
*/
public class AlbumSettings {
public String coverPath;
public String columnSortingMode;
public Boolean ascending;
String columnCount;
public AlbumSettings(String cover, String SortingMode, Boolean asce) {
coverPath = cover;
columnSortingMode = SortingMode;
ascending = asce;
}
public AlbumSettings() {
coverPath = null;
columnSortingMode = null;
ascending = false;
}
public String getSQLSortingMode() {
if (ascending)
return columnSortingMode + " ASC";
else
return columnSortingMode + " DESC";
}
}
......@@ -6,13 +6,15 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.leafpic.app.utils.string;
import com.leafpic.app.utils.StringUtils;
import java.util.ArrayList;
/**
* Created by dnld on 2/1/16.
*/
public class CustomAlbumsHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
......@@ -23,6 +25,7 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
private static final String ALBUM_EXCLUDED = "excluded";
private static final String ALBUM_COVER = "cover_path";
private static final String ALBUM_DEAFAULT_SORTMODE = "sort_mode";
private static final String ALBUM_DEAFAULT_SORT_ASCENDING = "sort_ascending";
private static final String ALBUM_COLUMN_COUNT = "column_count";
Context context;
......@@ -39,9 +42,22 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
ALBUM_EXCLUDED + " BOOLEAN," +
ALBUM_COVER + " TEXT, " +
ALBUM_DEAFAULT_SORTMODE + " TEXT, " +
ALBUM_DEAFAULT_SORT_ASCENDING + " BOOLEAN, " +
ALBUM_COLUMN_COUNT + " TEXT)");
}
public AlbumSettings getSettings(String id) {
checkAndCreateAlbum(id);
AlbumSettings s = new AlbumSettings();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT " + ALBUM_COVER + ", " + ALBUM_DEAFAULT_SORTMODE + ", " + ALBUM_DEAFAULT_SORT_ASCENDING + " FROM " + TABLE_ALBUMS + " WHERE " + ALBUM_ID + "='" + StringUtils.quoteReplace(id) + "'", null);
if (cursor.moveToFirst())
s = new AlbumSettings(cursor.getString(0), cursor.getString(1), Boolean.valueOf(cursor.getString(2)));
cursor.close();
db.close();
return s;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ALBUMS);
......@@ -50,10 +66,10 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
public void checkAndCreateAlbum(String id) {
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT " + ALBUM_ID + " FROM " + TABLE_ALBUMS + " WHERE " + ALBUM_ID + "='" + string.quoteReplace(id) + "'", null);
Cursor cursor = db.rawQuery("SELECT " + ALBUM_ID + " FROM " + TABLE_ALBUMS + " WHERE " + ALBUM_ID + "='" + StringUtils.quoteReplace(id) + "'", null);
if (cursor.getCount() == 0) {
ContentValues values = new ContentValues();
values.put(ALBUM_ID, string.quoteReplace(id));
values.put(ALBUM_ID, StringUtils.quoteReplace(id));
db.insert(TABLE_ALBUMS, null, values);
}
cursor.close();
......@@ -63,14 +79,14 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
public void excludeAlbum(String id) {
checkAndCreateAlbum(id);
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_EXCLUDED + "='true' WHERE " + ALBUM_ID + "='" + string.quoteReplace(id) + "'");
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_EXCLUDED + "='true' WHERE " + ALBUM_ID + "='" + StringUtils.quoteReplace(id) + "'");
db.close();
}
public String getPhotPrevieAlbum(String id) {
String s = null;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT " + ALBUM_COVER + " FROM " + TABLE_ALBUMS + " WHERE " + ALBUM_ID + "='" + string.quoteReplace(id)
Cursor cursor = db.rawQuery("SELECT " + ALBUM_COVER + " FROM " + TABLE_ALBUMS + " WHERE " + ALBUM_ID + "='" + StringUtils.quoteReplace(id)
+ "'", null);
if (cursor.moveToFirst())
s = cursor.getString(0);
......@@ -83,7 +99,23 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
public void setAlbumPhotPreview(String id, String path) {
checkAndCreateAlbum(id);
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_COVER + "='" + path + "' WHERE " + ALBUM_ID + "='" + string.quoteReplace(id) + "'");
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_COVER + "='" + path + "' WHERE " + ALBUM_ID + "='" + StringUtils.quoteReplace(id) + "'");
db.close();
}
public void setAlbumSortingMode(String id, String column) {
checkAndCreateAlbum(id);
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_DEAFAULT_SORTMODE + "='" + column +
"' WHERE " + ALBUM_ID + "='" + StringUtils.quoteReplace(id) + "'");
db.close();
}
public void setAlbumSortingAscending(String id, Boolean asc) {
checkAndCreateAlbum(id);
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_DEAFAULT_SORT_ASCENDING + "='" + String.valueOf(asc) +
"' WHERE " + ALBUM_ID + "='" + StringUtils.quoteReplace(id) + "'");
db.close();
}
......
......@@ -3,8 +3,7 @@ package com.leafpic.app.Base;
import android.content.Context;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.util.Log;
import com.leafpic.app.utils.string;
import com.leafpic.app.utils.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
......@@ -184,8 +183,6 @@ public class HandlingAlbums {
}
});
t.start();
} catch (Exception e) {
e.printStackTrace();
}
......@@ -250,15 +247,6 @@ public class HandlingAlbums {
db.close();
}
public void LogAlbums() {
for (Album dispAlbum : dispAlbums) {
Log.wtf("asdasd", dispAlbum.Path);
for (Photo photo : dispAlbum.photos) {
Log.d("asdasdasdasd", photo.Path);
}
}
}
/*************
* This Metods doesnt work for the moment
**************/
......@@ -266,9 +254,15 @@ public class HandlingAlbums {
public void renameAlbum(String olderPath, String name) {
try {
File from = new File(olderPath);
File to = new File(string.getAlbumPathRenamed(olderPath, name));
File to = new File(StringUtils.getAlbumPathRenamed(olderPath, name));
String s[] = from.list(), dirPath = from.getAbsolutePath();
for (String paht : s) scanFile(new String[]{dirPath + "/" + paht});
from.renameTo(to);
scanFile(new String[]{from.getAbsolutePath(), to.getAbsolutePath()});
s = to.list();
dirPath = to.getAbsolutePath();
for (String paht : s) scanFile(new String[]{dirPath + "/" + paht});
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -3,6 +3,8 @@ package com.leafpic.app.Base;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.util.Log;
import java.io.File;
import java.util.ArrayList;
......@@ -31,12 +33,12 @@ public class HandlingPhotos implements Parcelable {
public ArrayList<Photo> photos;
public ArrayList<Photo> selectedPhotos;
public boolean hidden;
public AlbumSettings settings;
Context context;
MadiaStoreHandler as;
private int current;
private int last_position_selecte = -1;
public HandlingPhotos(Context ctx, Album album) {
context = ctx;
as = new MadiaStoreHandler(context);
......@@ -45,21 +47,20 @@ public class HandlingPhotos implements Parcelable {
selectedPhotos = new ArrayList<Photo>();
DisplayName = album.DisplayName;
if (!hidden) {
ID = album.ID;
photos = as.getAlbumPhotos(album);
setSettings();
photos = as.getAlbumPhotos(album, getSortingMode());
} else {
ID = album.Path;
setSettings();
HiddenPhotosHandler db = new HiddenPhotosHandler(context);
photos = db.getPhotosByAlbum(album.Path);
}
}
/***
* parcellable
**/
protected HandlingPhotos(Parcel in) {
FolderPath = in.readString();
if (in.readByte() == 0x01) {
......@@ -79,13 +80,58 @@ public class HandlingPhotos implements Parcelable {
hidden = in.readByte() != 0x00;
}
public void sort() {
if (!hidden) {
Album a = new Album();
a.ID = ID;
photos = as.getAlbumPhotos(a, getSortingMode());
} else {
HiddenPhotosHandler db = new HiddenPhotosHandler(context);
photos = db.getPhotosByAlbum(ID);
}
}
public void setDefaultSortingMode(String column) {
CustomAlbumsHandler h = new CustomAlbumsHandler(context);
h.setAlbumSortingMode(ID, column);
settings.columnSortingMode = column;
}
public void setDefaultSortingAscending(Boolean ascending) {
CustomAlbumsHandler h = new CustomAlbumsHandler(context);
h.setAlbumSortingAscending(ID, ascending);
settings.ascending = ascending;
}
public String getSortingMode() {
if (settings.columnSortingMode != null) return settings.getSQLSortingMode();
else return MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC";
}
public String getPreviewAlbumImg() {
Log.wtf("asdfsfd", settings.coverPath);
if (settings.coverPath != null) return settings.coverPath;
return photos.get(0).Path;
}
public void setSelectedPhotoAsPreview() {
if (selectedPhotos.size() > 0) {
CustomAlbumsHandler h = new CustomAlbumsHandler(context);
h.setAlbumPhotPreview(ID, selectedPhotos.get(0).Path);
settings.coverPath = selectedPhotos.get(0).Path;
}
}
public void setSettings() {
CustomAlbumsHandler h = new CustomAlbumsHandler(context);
settings = h.getSettings(ID);
}
public void setContext(Context ctx) {
context = ctx;
}
public void clearSelectedPhotos() {
for (Photo photo : photos) {
photo.setSelected(false);
......@@ -105,17 +151,6 @@ public class HandlingPhotos implements Parcelable {
setCurrentPhotoIndex(getPhotoIndex(path));
}
public String getPreviewAlbumImg(){
CustomAlbumsHandler h = new CustomAlbumsHandler(context);
String s = h.getPhotPrevieAlbum(ID);
if (s != null) return s;
return photos.get(0).Path;
}
public void setContext(Context ctx) {
context = ctx;
}
int getPhotoIndex(String path) {
for (int i = 0; i < photos.size(); i++) {
if (photos.get(i).Path.equals(path)) return i;
......@@ -195,4 +230,5 @@ public class HandlingPhotos implements Parcelable {
// dest.writeValue(context);
dest.writeByte((byte) (hidden ? 0x01 : 0x00));
}
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import com.leafpic.app.utils.string;
import com.leafpic.app.utils.StringUtils;
import java.io.File;
import java.util.ArrayList;
......@@ -56,7 +56,7 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
public void deleteAlbum(String path) {
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM " + TABLE_PHOTOS + " WHERE " + PHOTO_FOLDER_PATH + "='" + string.quoteReplace(path) + "'");
db.execSQL("DELETE FROM " + TABLE_PHOTOS + " WHERE " + PHOTO_FOLDER_PATH + "='" + StringUtils.quoteReplace(path) + "'");
db.close();
}
......@@ -89,7 +89,7 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
for (String child : dir.list()) {
File temp = new File(dir, child);
String mime = string.getMimeType(temp.getAbsolutePath());
String mime = StringUtils.getMimeType(temp.getAbsolutePath());
if (mime != null && mime.contains("image"))
addPhoto(new Photo(
temp.getAbsolutePath(),
......@@ -101,8 +101,8 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
void addPhoto(Photo contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(PHOTO_FOLDER_PATH, string.quoteReplace(contact.FolderPath));
values.put(PHOTO_PATH, string.quoteReplace(contact.Path));
values.put(PHOTO_FOLDER_PATH, StringUtils.quoteReplace(contact.FolderPath));
values.put(PHOTO_PATH, StringUtils.quoteReplace(contact.Path));
values.put(PHOTO_MIME, contact.MIME);
db.insert(TABLE_PHOTOS, null, values);
db.close();
......@@ -117,8 +117,8 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
null);
if (cursor.moveToFirst()) {
do contactList.add(new Album(
string.quoteReverse(cursor.getString(0)),
string.getBucketNamebyBucketPath(string.quoteReverse(cursor.getString(0))),
StringUtils.quoteReverse(cursor.getString(0)),
StringUtils.getBucketNamebyBucketPath(StringUtils.quoteReverse(cursor.getString(0))),
true, getHiddenPhotosCountByAlbum(cursor.getString(0))));
while (cursor.moveToNext());
}
......@@ -132,7 +132,7 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
PHOTO_MIME + ", " + PHOTO_DATE_TAKEN +
" FROM " + TABLE_PHOTOS + " WHERE " +
PHOTO_FOLDER_PATH + "='" +
string.quoteReplace(path) + "' ORDER BY " + PHOTO_DATE_TAKEN + " DESC";
StringUtils.quoteReplace(path) + "' ORDER BY " + PHOTO_DATE_TAKEN + " DESC";
SQLiteDatabase db = this.getWritableDatabase();
......@@ -141,7 +141,7 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
if (cursor.moveToFirst()) {
do {
contactList.add(new Photo(
string.quoteReverse(cursor.getString(0)),
StringUtils.quoteReverse(cursor.getString(0)),
cursor.getString(3),
cursor.getString(2),
cursor.getString(1)));
......@@ -154,7 +154,7 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
public ArrayList<Photo> getFirstPhotosByAlbum(String path) {
ArrayList<Photo> contactList = new ArrayList<Photo>();
String selectQuery = "SELECT " + PHOTO_PATH + ", " + PHOTO_DATE_TAKEN + " FROM " + TABLE_PHOTOS + " WHERE " +
PHOTO_FOLDER_PATH + "='" + string.quoteReplace(path) + "' ORDER BY " + PHOTO_DATE_TAKEN + " DESC";
PHOTO_FOLDER_PATH + "='" + StringUtils.quoteReplace(path) + "' ORDER BY " + PHOTO_DATE_TAKEN + " DESC";
SQLiteDatabase db = this.getWritableDatabase();
......@@ -162,7 +162,7 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
if (cursor.moveToFirst())
contactList.add(new Photo(
string.quoteReverse(cursor.getString(0)),
StringUtils.quoteReverse(cursor.getString(0)),
cursor.getString(1)));
cursor.close();
......
......@@ -94,6 +94,43 @@ public class MadiaStoreHandler {
return list;
}
public ArrayList<Photo> getAlbumPhotos(Album a, String sort) {
ArrayList<Photo> list = new ArrayList<Photo>();
String[] projection = new String[]{
MediaStore.Images.Media.DATE_TAKEN,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.MIME_TYPE
};
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Cursor cur = context.getContentResolver().query(
images,
projection,
MediaStore.Images.Media.BUCKET_ID + " = ?",
new String[]{a.ID}, " " + sort);
if (cur.moveToFirst()) {
int pathColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATA);
int dateColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATE_TAKEN);
int mimeColumn = cur.getColumnIndex(
MediaStore.Images.Media.MIME_TYPE);
do {
list.add(new Photo(
cur.getString(pathColumn),
cur.getString(dateColumn),
cur.getString(mimeColumn)
));
} while (cur.moveToNext());
}
cur.close();
return list;
}
public int getAlbumPhotosCount(String id) {
int c;
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
......
......@@ -18,7 +18,7 @@ import com.afollestad.materialdialogs.MaterialDialog;
import com.leafpic.app.Adapters.PhotosPagerAdapter;
import com.leafpic.app.Animations.DepthPageTransformer;
import com.leafpic.app.Base.HandlingPhotos;
import com.leafpic.app.utils.string;
import com.leafpic.app.utils.StringUtils;
/**
* Created by dnld on 12/12/15.
......@@ -88,7 +88,7 @@ public class PhotoActivity extends AppCompatActivity {
case R.id.shareButton:
String file_path = photos.photos.get(mViewPager.getCurrentItem()).Path;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType(string.getMimeType(file_path));
share.setType(StringUtils.getMimeType(file_path));
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file_path));
startActivity(Intent.createChooser(share, "Share Image"));
return true;
......@@ -102,10 +102,11 @@ public class PhotoActivity extends AppCompatActivity {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
int index = mViewPager.getCurrentItem();
mViewPager.removeViewAt(index);
mViewPager.removeView(mViewPager.getChildAt(index));
//TODO improve delete single photo
photos.deleteCurrentPhoto();
mCustomPagerAdapter.notifyDataSetChanged();
mViewPager.destroyDrawingCache();
mViewPager.setCurrentItem(index + 1);
}
})
......@@ -119,7 +120,7 @@ public class PhotoActivity extends AppCompatActivity {
String file_path_use_as = photos.photos.get(mViewPager.getCurrentItem()).Path;
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(Uri.parse("file://" + file_path_use_as), "image/*");
intent.putExtra("jpg", string.getMimeType(file_path_use_as));
intent.putExtra("jpg", StringUtils.getMimeType(file_path_use_as));
startActivity(Intent.createChooser(intent, "Use As"));
return true;
......
......@@ -15,10 +15,7 @@ import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.*;
import android.text.Html;
import android.text.InputType;
import android.transition.Slide;
......@@ -30,7 +27,7 @@ import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide;
import com.leafpic.app.Adapters.PhotosAdapter;
import com.leafpic.app.Base.*;
import com.leafpic.app.utils.string;
import com.leafpic.app.utils.StringUtils;
import java.io.File;
import java.util.ArrayList;
......@@ -247,6 +244,49 @@ public class PhotosActivity extends AppCompatActivity {
finishEditMode();
updateHeaderContent();
break;
case R.id.sortPhotos:
if (!photos.hidden) {
final PopupMenu popup = new PopupMenu(PhotosActivity.this, findViewById(R.id.sortPhotos));
popup.setGravity(Gravity.AXIS_PULL_BEFORE);
popup.getMenuInflater().inflate(R.menu.sort, popup.getMenu());
popup.getMenu().findItem(R.id.ascending_sort_action).setChecked(photos.settings.ascending);
if (photos.settings.columnSortingMode == null || photos.settings.columnSortingMode.equals(MediaStore.Images.ImageColumns.DATE_TAKEN))
popup.getMenu().findItem(R.id.date_taken_sort_action).setChecked(true);
else if (photos.settings.columnSortingMode.equals(MediaStore.Images.ImageColumns.DISPLAY_NAME))
popup.getMenu().findItem(R.id.name_sort_action).setChecked(true);
else if (photos.settings.columnSortingMode.equals(MediaStore.Images.ImageColumns.SIZE))
popup.getMenu().findItem(R.id.size_sort_action).setChecked(true);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.name_sort_action:
photos.setDefaultSortingMode(MediaStore.Images.ImageColumns.DISPLAY_NAME);
break;
case R.id.size_sort_action:
photos.setDefaultSortingMode(MediaStore.Images.ImageColumns.SIZE);
break;
case R.id.date_taken_sort_action:
photos.setDefaultSortingMode(MediaStore.Images.ImageColumns.DATE_TAKEN);
break;
case R.id.ascending_sort_action:
photos.setDefaultSortingAscending(!photos.settings.ascending);
break;
default:
break;
}
photos.sort();
LoadPhotos();
return true;
}
});
popup.show();
} else StringUtils.showToast(getApplicationContext(), " In progress");
break;
case R.id.renameAlbum:
new MaterialDialog.Builder(this)
......@@ -258,9 +298,11 @@ public class PhotosActivity extends AppCompatActivity {
public void onInput(MaterialDialog dialog, CharSequence input) {
/* TODO make this better
albums.renameAlbum(photos.FolderPath, input.toString());
finish();
*/
string.showToast(getApplicationContext(), "I have to fix this!");
//onBackPressed();
//finish();*/
StringUtils.showToast(getApplicationContext(), "I have to fix this!");
}
}).show();
break;
......@@ -320,7 +362,7 @@ public class PhotosActivity extends AppCompatActivity {
.onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
string.showToast(getApplicationContext(), "Not implemented yet!");
StringUtils.showToast(getApplicationContext(), "Not implemented yet!");
//albums.excludeAlbum(photos.FolderPath);
// finish();
}
......
......@@ -7,7 +7,8 @@ import android.widget.Toast;
/**
* Created by dnld on 1/3/16.
*/
public class string {
public class StringUtils {
public static String getMimeType(String url) {
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
......@@ -52,13 +53,9 @@ public class string {
return quoteReplace(folderPath + "/" + name);
}
public static String getAlbumPathRenamed(String olderPath, String newName) {
String b[] = olderPath.split("/");
String