Commit 5abf1ff0 authored by DNLDsht's avatar DNLDsht

PICK and GET_CONTENT Intent added

clean and updated stuff
parent 44be04a3
......@@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
......
......@@ -77,7 +77,7 @@ public class Album {
selectedMedias = new ArrayList<Media>();
this.path = path;
this.name = name;
updatePhotos();
//updatePhotos();
}
public void updatePhotos() {
......
......@@ -159,7 +159,6 @@ public class HandlingAlbums {
shortcutIntent = new Intent(appCtx, SplashScreen.class);
shortcutIntent.setAction(SplashScreen.ACTION_OPEN_ALBUM);
shortcutIntent.putExtra("albumPath", selectedAlbum.getPath());
shortcutIntent.putExtra("albumName", selectedAlbum.getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
......
......@@ -68,39 +68,36 @@ public class MainActivity extends ThemedActivity {
public static String TAG = "AlbumsAct";
CustomAlbumsHandler customAlbumsHandler = new CustomAlbumsHandler(MainActivity.this);
Album album;
SharedPreferences SP;
HandlingAlbums albums;
Album album;
RecyclerView mRecyclerView;
PhotosAdapter adapter;
AlbumsAdapter adapt;
GridSpacingItemDecoration albumsDecoration;
GridSpacingItemDecoration photosDecoration;
FloatingActionButton fabCamera;
DrawerLayout mDrawerLayout;
Toolbar toolbar;
SelectAlbumBottomSheet bottomSheetDialogFragment;
private SwipeRefreshLayout SwipeContainerRV;
boolean pickmode = false;
boolean editmode = false, albumsMode = true, contentReady = false, firstLaunch = true;
GridSpacingItemDecoration albumsDecoration;
GridSpacingItemDecoration photosDecoration;
boolean pickmode = false, editmode = false, albumsMode = true, contentReady = false, firstLaunch = true;
View.OnLongClickListener photosOnLongClickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
TextView is = (TextView) v.findViewById(R.id.photo_path);
int index = Integer.parseInt(v.findViewById(R.id.photo_path).getTag().toString());
if (!editmode) {
// If it is the first long press
adapter.notifyItemChanged(album.toggleSelectPhoto(Integer.parseInt(is.getTag().toString())));
adapter.notifyItemChanged(album.toggleSelectPhoto(index));
editmode = true;
} else {
album.selectAllPhotosUpTo(Integer.parseInt(is.getTag().toString()), adapter);
}
} else
album.selectAllPhotosUpTo(index, adapter);
invalidateOptionsMenu();
return true;
}
......@@ -110,15 +107,20 @@ public class MainActivity extends ThemedActivity {
@Override
public void onClick(View v) {
if (contentReady) {
TextView is = (TextView) v.findViewById(R.id.photo_path);
if (editmode) {
adapter.notifyItemChanged(album.toggleSelectPhoto(Integer.parseInt(is.getTag().toString())));
invalidateOptionsMenu();
int index = Integer.parseInt(v.findViewById(R.id.photo_path).getTag().toString());
if (!pickmode) {
if (editmode) {
adapter.notifyItemChanged(album.toggleSelectPhoto(index));
invalidateOptionsMenu();
} else {
album.setCurrentPhotoIndex(index);
Intent intent = new Intent(MainActivity.this, PhotoPagerActivity.class);
intent.setAction(PhotoPagerActivity.ACTION_OPEN_ALBUM);
startActivity(intent);
}
} else {
album.setCurrentPhotoIndex(Integer.parseInt(is.getTag().toString()));
Intent intent = new Intent(MainActivity.this, PhotoPagerActivity.class);
intent.setAction(PhotoPagerActivity.ACTION_OPEN_ALBUM);
startActivity(intent);
setResult(RESULT_OK, new Intent().setData(album.getMedia(index).getUri()));
finish();
}
}
}
......@@ -127,8 +129,10 @@ public class MainActivity extends ThemedActivity {
private View.OnLongClickListener albumOnLongCLickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
TextView a = (TextView) v.findViewById(R.id.album_name);
adapt.notifyItemChanged(albums.toggleSelectAlbum(Integer.parseInt(a.getTag().toString())));
int index = Integer.parseInt(v.findViewById(R.id.album_name).getTag().toString());
//TextView a = (TextView) v.findViewById(R.id.album_name);
adapt.notifyItemChanged(albums.toggleSelectAlbum(index));
editmode = true;
invalidateOptionsMenu();
return true;
......@@ -139,13 +143,13 @@ public class MainActivity extends ThemedActivity {
@Override
public void onClick(View v) {
if (contentReady) {
TextView a = (TextView) v.findViewById(R.id.album_name);
int index = Integer.parseInt(v.findViewById(R.id.album_name).getTag().toString());
if (editmode) {
adapt.notifyItemChanged(albums.toggleSelectAlbum(Integer.parseInt(a.getTag().toString())));
adapt.notifyItemChanged(albums.toggleSelectAlbum(index));
invalidateOptionsMenu();
} else {
openAlbum(albums.getAlbum(Integer.parseInt(a.getTag().toString())));
setRecentApp(albums.getAlbum(Integer.parseInt(a.getTag().toString())).getName());
openAlbum(albums.getAlbum(index));
setRecentApp(albums.getAlbum(index).getName());
}
}
}
......@@ -193,6 +197,8 @@ public class MainActivity extends ThemedActivity {
album.setSettings(getApplicationContext());
toolbar.setTitle(a.getName());
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
mDrawerLayout.setEnabled(false);
mRecyclerView.removeItemDecoration(albumsDecoration);
mRecyclerView.addItemDecoration(photosDecoration);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, Measure.getPhotosColums(getApplicationContext())));
......@@ -222,6 +228,7 @@ public class MainActivity extends ThemedActivity {
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_menu));
toolbar.setTitle(getString(R.string.app_name));
mDrawerLayout.setEnabled(true);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, Measure.getAlbumsColums(getApplicationContext())));
mRecyclerView.removeItemDecoration(photosDecoration);
......@@ -294,12 +301,18 @@ public class MainActivity extends ThemedActivity {
if (content == SplashScreen.ALBUMS_PREFETCHED) {
albums = ((MyApplication) getApplicationContext()).getAlbums();
displayAlbums(false);
pickmode=data.getBoolean(SplashScreen.PICK_MODE);
pickmode = data.getBoolean(SplashScreen.PICK_MODE);
} else if (content == SplashScreen.PHOTS_PREFETCHED) {
/*album = data.getParcelable("album");
assert album != null;
album.setContext(MainActivity.this);
openAlbum(album,false);*/
album = ((MyApplication) getApplicationContext()).getCurrentAlbum();
new Thread(new Runnable() {
@Override
public void run() {
albums = new HandlingAlbums(getApplicationContext());
albums.loadPreviewAlbums();
}
}).start();
openAlbum(album,false);
}
contentReady = true;
} catch (NullPointerException e) { e.printStackTrace(); }
......
......@@ -9,6 +9,7 @@ import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
......@@ -19,6 +20,9 @@ import com.horaapps.leafpic.Base.Album;
import com.horaapps.leafpic.Views.ThemedActivity;
import com.horaapps.leafpic.utils.ColorPalette;
import com.horaapps.leafpic.utils.PermissionUtils;
import com.horaapps.leafpic.utils.StringUtils;
import java.io.File;
/**
* Created by dnld on 01/04/16.
......@@ -26,6 +30,7 @@ import com.horaapps.leafpic.utils.PermissionUtils;
public class SplashScreen extends ThemedActivity {
public final int READ_EXTERNAL_STORAGE_ID = 12;
static final int PICK_MEDIA_REQUEST = 44;
public final static String CONTENT = "content";
public final static String PICK_MODE = "pick_mode";
......@@ -59,7 +64,7 @@ public class SplashScreen extends ThemedActivity {
}
*/
albums = new HandlingAlbums(getApplicationContext());//new HandlingAlbums(SplashScreen.this);
albums = new HandlingAlbums(getApplicationContext());
TextView logo = (TextView) findViewById(R.id.txtLogo);
logo.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Figa.ttf"));
......@@ -76,36 +81,37 @@ public class SplashScreen extends ThemedActivity {
setStatusBarColor();
if (PermissionUtils.isDeviceInfoGranted(this)) {
new PrefetchAlbumsData().execute();
//startActivity(new Intent(SplashScreen.this, MainActivity.class));
/* if (getIntent().getAction().equals(Intent.ACTION_MAIN))
if (getIntent().getAction().equals(Intent.ACTION_MAIN))
new PrefetchAlbumsData().execute();
else if (getIntent().getAction().equals(Intent.ACTION_GET_CONTENT)
|| getIntent().getAction().equals(Intent.ACTION_PICK)) {
PICK_INTENT = true;
Log.wtf("albums","pickmode");
new PrefetchAlbumsData().execute();
} else if (getIntent().getAction().equals(ACTION_OPEN_ALBUM)) {
Bundle data = getIntent().getExtras();
if (data != null) {
String ab = data.getString("albumID");
String ab = data.getString("albumPath");
if (ab != null) {
album = new Album(ab, SplashScreen.this);
album.DisplayName = data.getString("albumName");
File dir = new File(ab);
album = new Album(dir.getAbsolutePath(),dir.getName());
new PrefetchPhotosData().execute();
}
} else StringUtils.showToast(getApplicationContext(), "Album not found");
}
*/
} else {
String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE};
PermissionUtils.requestPermissions(this, READ_EXTERNAL_STORAGE_ID, permissions);
}
}
if (getIntent().getAction() != null &&
(getIntent().getAction().equals(Intent.ACTION_GET_CONTENT) ||
getIntent().getAction().equals(Intent.ACTION_PICK))) {
PICK_INTENT = true;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_MEDIA_REQUEST) {
if (resultCode == RESULT_OK) {
setResult(RESULT_OK, data);
finish();
}
}
}
......@@ -156,8 +162,12 @@ public class SplashScreen extends ThemedActivity {
b.putInt(CONTENT, ALBUMS_PREFETCHED);
b.putBoolean(PICK_MODE, PICK_INTENT);
i.putExtras(b);
startActivity(i);
finish();
if (PICK_INTENT)
startActivityForResult(i, PICK_MEDIA_REQUEST);
else {
startActivity(i);
finish();
}
}
}
......
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.android.tools.build:gradle:2.1.0'
// 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