Commit 44938229 authored by Donald's avatar Donald

immersive mode in single photo activity

parent 0b4db2de
package com.leafpic.app;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
......@@ -22,11 +27,14 @@ import android.widget.TextView;
import android.widget.Toast;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.folderselector.FolderChooserDialog;
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.mikepenz.fontawesome_typeface_library.FontAwesome;
import com.mikepenz.iconics.context.IconicsContextWrapper;
import com.mikepenz.materialdrawer.AccountHeader;
import com.mikepenz.materialdrawer.AccountHeaderBuilder;
import com.mikepenz.materialdrawer.Drawer;
......@@ -37,7 +45,9 @@ import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
public class AlbumsActivity extends AppCompatActivity {
import java.io.File;
public class AlbumsActivity extends AppCompatActivity implements FolderChooserDialog.FolderCallback {
HandlingAlbums albums = new HandlingAlbums(AlbumsActivity.this);
RecyclerView mRecyclerView;
......@@ -50,6 +60,7 @@ public class AlbumsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_albums);
SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
initUiTweaks();
......@@ -70,6 +81,7 @@ public class AlbumsActivity extends AppCompatActivity {
super.onResume();
}
public void initUiTweaks(){
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
......@@ -150,6 +162,46 @@ public class AlbumsActivity extends AppCompatActivity {
}
})
.build();
addHiddenFolder_FABEvent();
}
public void addHiddenFolder_FABEvent() {
FloatingActionButton btnAddFolder = (FloatingActionButton) findViewById(R.id.fabAddFolder);
if (hidden) {
btnAddFolder.setVisibility(View.VISIBLE);
int color = Color.parseColor(SP.getString("PrefColor", "#03A9F4"));
btnAddFolder.setBackgroundTintList(ColorStateList.valueOf(color));
btnAddFolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new FolderChooserDialog.Builder(AlbumsActivity.this)
.chooseButton(R.string.md_choose_label)
.initialPath(Environment.getExternalStorageDirectory().getPath())
.show();
}
});
} else
btnAddFolder.setVisibility(View.INVISIBLE);
}
@Override
public void onFolderSelection(@NonNull File folder) {
HiddenPhotosHandler h = new HiddenPhotosHandler(getApplicationContext());
string.showToast(getApplicationContext(), folder.getAbsolutePath());
h.addImagesFromFolder(folder);
albums.loadPreviewHiddenAlbums();
adapt.notifyDataSetChanged();
}
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(IconicsContextWrapper.wrap(newBase));
}
public void checkPermissions(){
......@@ -368,6 +420,12 @@ public class AlbumsActivity extends AppCompatActivity {
}
private void loadAlbums() {
runOnUiThread(new Runnable() {
public void run() {
albums.loadPreviewHiddenAlbums();
}
});
Thread t = new Thread(new Runnable() {
@Override
......@@ -377,7 +435,7 @@ public class AlbumsActivity extends AppCompatActivity {
.getDefaultSharedPreferences(getBaseContext());
boolean isFirstStart = getPrefs.getBoolean("firstStart", true);
if (isFirstStart) {
//albums.loadPreviewHiddenAlbums();
Intent i = new Intent(AlbumsActivity.this, IntroActivity.class);
startActivity(i);
SharedPreferences.Editor e = getPrefs.edit();
......@@ -388,8 +446,24 @@ public class AlbumsActivity extends AppCompatActivity {
});
t.start();
addHiddenFolder_FABEvent();
if (hidden) {
albums.loadPreviewHiddenAlbums();
final MaterialDialog dialog = new MaterialDialog.Builder(AlbumsActivity.this)
.title("Loading")
.progress(true, 0)
.progressIndeterminateStyle(true)
.build();
dialog.show();
runOnUiThread(new Runnable() {
public void run() {
albums.loadPreviewHiddenAlbums();
//dialog.dismiss();
}
});
//albums.LogAlbums();
}
else {
......
......@@ -63,6 +63,7 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
}
void getAlbums(File dir) {
if (dir.isDirectory() &&
!dir.getAbsolutePath().equals("/storage/emulated/0/Android") &&
!dir.getAbsolutePath().contains("Voice") &&
......@@ -72,33 +73,35 @@ public class HiddenPhotosHandler extends SQLiteOpenHelper {
for (String child : children) {
File temp = new File(dir, child);
if (temp.isDirectory()) {
ArrayList<Photo> paths = getImagesFromFolder(temp);
for (Photo path : paths)
addPhoto(path);
addHiddeNImagesFromFolder(temp);
getAlbums(temp);
}
}
}
}
private ArrayList<Photo> getImagesFromFolder(File dir) {
ArrayList<Photo> paths = new ArrayList<Photo>();
String[] children = dir.list();
public void addHiddeNImagesFromFolder(File dir) {
File nomediafile = new File(dir, ".nomedia");
if (!nomediafile.exists())
return paths;
return;
addImagesFromFolder(dir);
}
public void addImagesFromFolder(File dir) {
String[] children = dir.list();
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(
addPhoto(new Photo(
temp.getAbsolutePath(),
String.valueOf(temp.lastModified()),
mime, dir.getAbsolutePath()));
}
return paths;
}
void addPhoto(Photo contact) {
......
......@@ -84,11 +84,6 @@ public class PhotoActivity extends AppCompatActivity {
} catch (Exception e) {
e.printStackTrace();
}
//DA FIXXARE
hideSystemUI();
showSystemUI();
hideSystemUI();
}
@Override
......@@ -164,8 +159,11 @@ public class PhotoActivity extends AppCompatActivity {
/**** Navigation Bar */
getWindow().setNavigationBarColor(getColor(R.color.transparent_gray));
// TODO start immersiveMode [PORCODIO]
new Thread(new Runnable() {
public void run() {
hideSystemUI();
}
}).start();
}
private void toggleSystemUI() {
......@@ -176,30 +174,43 @@ public class PhotoActivity extends AppCompatActivity {
}
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
runOnUiThread(new Runnable() {
public void run() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
toolbar.animate().translationY(-toolbar.getHeight()).setInterpolator(new AccelerateInterpolator())
.start();
//getSupportActionBar().hide();
fullscreenmode = true;
}
});
//getSupportActionBar().hide();
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
fullscreenmode = true;
}
private void showSystemUI() {
toolbar.animate().translationY(getStatusBarHeight()).setInterpolator(new DecelerateInterpolator()).start();
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
fullscreenmode = false;
runOnUiThread(new Runnable() {
public void run() {
//getSupportActionBar().show();
toolbar.animate().translationY(getStatusBarHeight()).setInterpolator(new DecelerateInterpolator())
.start();
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
fullscreenmode = false;
}
});
}
public int getStatusBarHeight() {
......
......@@ -3,7 +3,6 @@ package com.leafpic.app;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri;
......@@ -16,7 +15,6 @@ 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.graphics.Palette;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
......@@ -35,6 +33,7 @@ import com.leafpic.app.Base.Album;
import com.leafpic.app.Base.HandlingAlbums;
import com.leafpic.app.Base.HandlingPhotos;
import com.leafpic.app.Base.Photo;
import com.leafpic.app.utils.string;
import java.io.File;
import java.util.ArrayList;
......@@ -74,22 +73,7 @@ public class PhotosActivity extends AppCompatActivity {
}
private void setPalette(Bitmap bitmap) { //TODO remaake doesn't work wiht image loaded by Glide
//Bitmap bitmap = ((BitmapDrawable) image.getDrawable()).getBitmap();
// Drawable b = new Drawable.createFromPath(photos.getPreviewAlbumImg());
//}.decode//.decodeFile(photos.getPreviewAlbumImg());
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
int primaryDark = getColor(R.color.toolbar);
int primary = getColor(R.color.toolbar);
collapsingToolbarLayout.setContentScrimColor(palette.getMutedColor(primary));
collapsingToolbarLayout.setStatusBarScrimColor(palette.getMutedColor(primary));
//collapsingToolbarLayout.setStatusBarScrimColor(palette.getDarkVibrantColor(primaryDark));
}
});
}
public void LoadPhotos() {
......@@ -251,8 +235,9 @@ public class PhotosActivity extends AppCompatActivity {
.input(null, photos.DisplayName, new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence input) {
albums.renameAlbum(photos.FolderPath, input.toString());
finish();// TODO make this better
/* albums.renameAlbum(photos.FolderPath, input.toString());
finish();// TODO make this better*/
string.showToast(getApplicationContext(), "I have to fix this!");
}
}).show();
break;
......@@ -265,8 +250,9 @@ public class PhotosActivity extends AppCompatActivity {
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
albums.excludeAlbum(photos.FolderPath);
finish();
string.showToast(getApplicationContext(), "Not implemented yet!");
//albums.excludeAlbum(photos.FolderPath);
//finish();
}
})
.show();
......@@ -306,16 +292,15 @@ public class PhotosActivity extends AppCompatActivity {
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
//Log.wtf("asdasdasdas", photos.FolderPath);
albums.hideAlbum(photos.FolderPath, photos.photos);
finish();
}
})
.onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
albums.excludeAlbum(photos.FolderPath);
finish();
string.showToast(getApplicationContext(), "Not implemented yet!");
//albums.excludeAlbum(photos.FolderPath);
// finish();
}
})
.show();
......
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.AppCompat.NoActionBar"
......@@ -22,4 +23,19 @@
android:numColumns="auto_fit"
/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabAddFolder"
android:onClick="addFolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:borderWidth="0dp"
app:elevation="40dp"
app:ico_color="@color/md_white_1000"
app:ico_icon="gmd-add"
app:ico_size="16dp"
android:layout_margin="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom|end"/>
</RelativeLayout>
......@@ -111,12 +111,12 @@
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:onClick="fabClicked"
style="@style/fab"
app:theme="@style/ThemeOverlay.AppCompat.Light"
app:borderWidth="0dp"
app:elevation="4dp"
android:layout_margin="16dp"
......@@ -125,7 +125,6 @@
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"/>
/>
<!--
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|right"
......
......@@ -7,6 +7,8 @@
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageView"
android:layout_width="match_parent" android:layout_height="match_parent"/>
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
android:layout_height="match_parent"/>
</LinearLayout>
\ No newline at end of file
......@@ -38,6 +38,16 @@
<item name="rippleColor">@android:color/white</item>
</style>
<style name="fabAddFolder">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">4dp</item>
<item name="borderWidth">0dp</item>
<item name="elevation">50dp</item>
<item name="pressedTranslationZ">12dp</item>
<item name="rippleColor">@android:color/white</item>
</style>
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
......
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