Commit ea34c439 authored by Donald's avatar Donald

display hidden Images

parent 68da6bd0
......@@ -28,6 +28,7 @@ import android.widget.Toast;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.leafpic.app.Adapters.AlbumsAdapter;
import com.leafpic.app.Base.MadiaStoreHandler;
import com.leafpic.app.utils.string;
import com.mikepenz.fontawesome_typeface_library.FontAwesome;
import com.mikepenz.materialdrawer.AccountHeader;
......@@ -165,6 +166,8 @@ public class AlbumsActivity extends AppCompatActivity {
break;
case 2: //hidden
hidden = true;
//albums.loadPreviewHiddenAlbums();
//adapt.notifyDataSetChanged();
checkPermissions();
break;
case 6: //settings
......@@ -409,8 +412,8 @@ public class AlbumsActivity extends AppCompatActivity {
private void loadAlbums() {
if (hidden) {
albums.loadPreviewHiddenAlbums();
}
//albums.loadPreviewHiddenAlbums();
else {
// db.updatePhotos();
albums.loadPreviewAlbums();
......
package com.leafpic.app.Base;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import com.leafpic.app.Album;
import com.leafpic.app.Photo;
import com.leafpic.app.utils.string;
import java.io.File;
import java.util.ArrayList;
/**
* Created by dnld on 12/31/15.
*/
public class HiddenPhotosHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "LeafPic";
private static final String TABLE_PHOTOS = "photo";
private static final String PHOTO_PATH = "path";
private static final String PHOTO_MIME = "mime";
private static final String PHOTO_FOLDER_PATH = "folderpath";
private static final String PHOTO_DATE_TAKEN = "datetaken";
Context context;
public HiddenPhotosHandler(Context ctx) {
super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
context = ctx;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " +
TABLE_PHOTOS + "(" +
PHOTO_PATH + " TEXT," +
PHOTO_MIME + " TEXT," +
PHOTO_FOLDER_PATH + " TEXT, " +
PHOTO_DATE_TAKEN + " TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_PHOTOS);
onCreate(db);
}
public void loadHiddenALbums() {
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM " + TABLE_PHOTOS);
db.close();
getAlbums(Environment.getExternalStorageDirectory());
}
public void deleteAlbum(String path) {
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM " + TABLE_PHOTOS + " WHERE " + PHOTO_FOLDER_PATH + "='" + string.quoteReplace(path) + "'");
db.close();
}
void getAlbums(File dir) {
if (dir.isDirectory() &&
!dir.getAbsolutePath().equals("/storage/emulated/0/Android") &&
!dir.getAbsolutePath().contains("Voice") &&
!dir.getAbsolutePath().contains("Audio")) {
String[] children = dir.list();
for (String child : children) {
File temp = new File(dir, child);
if (temp.isDirectory()) {
ArrayList<Photo> paths = getImagesFromFolder(temp);
for (Photo path : paths)
addPhoto(path);
getAlbums(temp);
}
}
}
}
private ArrayList<Photo> getImagesFromFolder(File dir) {
ArrayList<Photo> paths = new ArrayList<Photo>();
String[] children = dir.list();
File nomediafile = new File(dir, ".nomedia");
if (!nomediafile.exists())
return paths;
for (String child : children) {
File temp = new File(dir, child);
String mime = string.getMimeType(temp.getAbsolutePath());
if (mime != null && mime.contains("image"))
paths.add(new Photo(
temp.getAbsolutePath(),
String.valueOf(temp.lastModified()),
mime, dir.getAbsolutePath()));
}
return paths;
}
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_MIME, contact.MIME);
db.insert(TABLE_PHOTOS, null, values);
db.close();
}
public ArrayList<Album> getAlbums() {
ArrayList<Album> contactList = new ArrayList<Album>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT " + PHOTO_FOLDER_PATH + " FROM " + TABLE_PHOTOS + " WHERE " +
PHOTO_FOLDER_PATH + "=" + PHOTO_FOLDER_PATH + " GROUP BY (" + PHOTO_FOLDER_PATH + ");",
null);
if (cursor.moveToFirst()) {
do contactList.add(new Album(
string.quoteReverse(cursor.getString(0)),
string.getBucketNamebyImagePath(string.quoteReverse(cursor.getString(0))),
true, getHiddenPhotosCountByAlbum(cursor.getString(0))));
while (cursor.moveToNext());
}
cursor.close();
return contactList;
}
public ArrayList<Photo> getPhotosByAlbum(String path) {
ArrayList<Photo> contactList = new ArrayList<Photo>();
String selectQuery = "SELECT " + PHOTO_PATH + ", " + PHOTO_FOLDER_PATH + ", " +
PHOTO_MIME + ", " + PHOTO_DATE_TAKEN +
" FROM " + TABLE_PHOTOS + " WHERE " +
PHOTO_FOLDER_PATH + "='" +
string.quoteReplace(path) + "' ORDER BY " + PHOTO_DATE_TAKEN + " DESC";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
contactList.add(new Photo(
string.quoteReverse(cursor.getString(0)),
cursor.getString(3),
cursor.getString(2),
cursor.getString(1)));
} while (cursor.moveToNext());
}
cursor.close();
return contactList;
}
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";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst())
contactList.add(new Photo(
string.quoteReverse(cursor.getString(0)),
cursor.getString(1)));
cursor.close();
return contactList;
}
public int getHiddenPhotosCountByAlbum(String path) {
int count;
String countQuery = "SELECT * FROM " + TABLE_PHOTOS + " WHERE " + PHOTO_FOLDER_PATH + "='" + path + "'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
count = cursor.getCount();
cursor.close();
return count;
}
public int getPhotosCount() {
int count;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_PHOTOS, null);
count = cursor.getCount();
cursor.close();
return count;
}
}
\ No newline at end of file
package com.leafpic.app;
package com.leafpic.app.Base;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import com.leafpic.app.Album;
import com.leafpic.app.Photo;
import java.util.ArrayList;
/**
* Created by dnld on 12/31/15.
*/
class MadiaStoreHandler {
public class MadiaStoreHandler {
Context context;
......
This diff is collapsed.
......@@ -3,6 +3,8 @@ package com.leafpic.app;
import android.content.Context;
import android.media.MediaScannerConnection;
import android.net.Uri;
import com.leafpic.app.Base.HiddenPhotosHandler;
import com.leafpic.app.Base.MadiaStoreHandler;
import com.leafpic.app.utils.string;
import java.io.File;
......@@ -152,50 +154,55 @@ public class HandlingAlbums {
}
}
/*************
* This Metods doesnt work for the moment
**************/
public void loadPreviewHiddenAlbums() {
/* DatabaseHandler db = new DatabaseHandler(context);
if (db.getDataBaseHiddenPhotosCount() == 0)
HiddenPhotosHandler db = new HiddenPhotosHandler(context);
if (db.getPhotosCount() == 0)
db.loadHiddenALbums();
dispAlbums = db.getHiddenAlbums();
dispAlbums = db.getAlbums();
for (Album dispAlbum : dispAlbums) {
dispAlbum.setHidden(true);
dispAlbum.photos = db.getFirstPhotosByAlbum(dispAlbum.Path);
}
db.close();
*/
}
public void unHideSelectedAlbums() {
/*for (Album selectedAlbum : selectedAlbums)
unHideAlbum(selectedAlbum);
clearSelectedAlbums();*/
}
public void unHideAlbum(Album a) {
unHideAlbum(a.Path);
dispAlbums.remove(a);
}
public void unHideAlbum(String path) {
HiddenPhotosHandler db = new HiddenPhotosHandler(context);
File dirName = new File(path);
File file = new File(dirName, ".nomedia");
if (file.exists()) {
try {
file.delete();
scanFile(new String[]{file.getAbsolutePath()});
db.deleteAlbum(path);
} catch (Exception e) {
e.printStackTrace();
}
}
dispAlbums.remove(getAlbum(path));
}
/*************
* This Metods doesnt work for the moment
**************/
public void unHideSelectedAlbums() {
/*for (Album selectedAlbum : selectedAlbums)
unHideAlbum(selectedAlbum);
clearSelectedAlbums();*/
}
public void unHideAlbum(Album a) {
unHideAlbum(a.Path);
dispAlbums.remove(a);
}
public void excludeSelectedAlbums() {
/*for (Album selectedAlbum : selectedAlbums)
excludeAlbum(selectedAlbum);
......@@ -209,8 +216,6 @@ public class HandlingAlbums {
}
public void excludeAlbum(String path) {
DatabaseHandler db = new DatabaseHandler(context);
db.excludeAlbum(path);
db.close();
}
}
\ No newline at end of file
......@@ -3,6 +3,8 @@ package com.leafpic.app;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import com.leafpic.app.Base.HiddenPhotosHandler;
import com.leafpic.app.Base.MadiaStoreHandler;
import java.io.File;
import java.util.ArrayList;
......@@ -41,9 +43,14 @@ class HandlingPhotos implements Parcelable {
as = new MadiaStoreHandler(context);
FolderPath = album.Path;
hidden = album.isHidden();
photos = as.getAlbumPhotos(album);
selectedPhotos = new ArrayList<Photo>();
DisplayName = album.DisplayName;
if (!hidden) photos = as.getAlbumPhotos(album);
else {
HiddenPhotosHandler db = new HiddenPhotosHandler(context);
photos = db.getPhotosByAlbum(album.Path);
}
}
......
......@@ -17,11 +17,11 @@ public class Photo implements Parcelable {
return new Photo[size];
}
};
public String Path;
public String MIME;
String DateTaken;
String FolderPath;
String name;
public String DateTaken;
public String FolderPath;
boolean selected = false;
public Photo(String path) {
......@@ -33,20 +33,17 @@ public class Photo implements Parcelable {
DateTaken = dateTaken;
}
//hidden util
/*public Photo(String nome, String folderPath, String dateTaken) {
Path = string.getPhotoPathByFolderPathAndName(folderPath, nome);
FolderPath = folderPath;
public Photo(String path, String dateTaken, String mime) {
Path = path;
DateTaken = dateTaken;
name = nome;
}*/
MIME = mime;
}
public Photo(String path, String dateTaken, String mime) {
public Photo(String path, String dateTaken, String mime, String folderPath) {
Path = path;
DateTaken = dateTaken;
MIME = mime;
FolderPath = folderPath;
}
protected Photo(Parcel in) {
......@@ -54,7 +51,6 @@ public class Photo implements Parcelable {
DateTaken = in.readString();
MIME = in.readString();
FolderPath = in.readString();
name = in.readString();
selected = in.readByte() != 0x00;
}
......@@ -77,7 +73,6 @@ public class Photo implements Parcelable {
dest.writeString(DateTaken);
dest.writeString(MIME);
dest.writeString(FolderPath);
dest.writeString(name);
dest.writeByte((byte) (selected ? 0x01 : 0x00));
}
}
\ No newline at end of file
......@@ -31,12 +31,6 @@ import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide;
import com.leafpic.app.Adapters.PhotosAdapter;
import com.mikepenz.materialdrawer.AccountHeader;
import com.mikepenz.materialdrawer.AccountHeaderBuilder;
import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import java.io.File;
import java.util.ArrayList;
......@@ -329,11 +323,11 @@ public class PhotosActivity extends AppCompatActivity {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("image/*"); /* This example is sharing jpeg images. */
intent.setType("image/*");
ArrayList<Uri> files = new ArrayList<Uri>();
for (Photo f : photos.selectedPhotos /* List of the files you want to send */) {
for (Photo f : photos.selectedPhotos) {
File file = new File(f.Path);
files.add(Uri.fromFile(file));
}
......@@ -370,21 +364,27 @@ public class PhotosActivity extends AppCompatActivity {
/**** Navigation Bar*/
SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean NavBar = SP.getBoolean("nav_bar", false);
if ((android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)&&(NavBar==true)) {
if ((android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) && (NavBar)) {
getWindow().setNavigationBarColor(getColor(R.color.toolbar));
}
/**** Status Bar */
Window window = getWindow();
/*Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
setStatusBarTranslucent(true);
window.setStatusBarColor(getColor(R.color.toolbar));
window.setStatusBarColor(getColor(R.color.toolbar));*/
/**** ToolBar*/
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
headerImage = (ImageView) findViewById(R.id.image);
Glide.with(this)
.load(photos.getPreviewAlbumImg())
......@@ -408,37 +408,7 @@ public class PhotosActivity extends AppCompatActivity {
* DRAWER
* ******/
AccountHeader headerResult = new AccountHeaderBuilder()
.withActivity(this)
.withHeaderBackground(R.drawable.side_wall)
.withSelectionListEnabledForSingleProfile(false)
.withCompactStyle(true)
.build();
final Drawer result = new DrawerBuilder()
.withActivity(this)
.withAccountHeader(headerResult)
.withDrawerGravity(Gravity.END)
.addDrawerItems(
new DividerDrawerItem()
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
switch (position) {
default:
break;
}
return false;
}
})
.build();
//setPalette();
......
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/material_drawer_primary</item>
<item name="colorPrimaryDark">@color/material_drawer_primary_dark</item>
<item name="colorAccent">@color/material_drawer_accent</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
......
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