Commit d4e7fabe authored by Donald's avatar Donald Committed by GitHub

Merge pull request #378 from HoraApps/white-list

folders white-list, album card style dialog, a lot of clean
parents ffec88d6 a7dd8e83
......@@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-feature
android:name="android.hardware.touchscreen"
......@@ -160,8 +161,8 @@
</activity>
<activity
android:name="org.horaapps.leafpic.activities.ExcludedAlbumsActivity"
android:label="@string/excluded_albums"
android:name="org.horaapps.leafpic.activities.WhiteListActivity"
android:label="@string/chose_folders"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.ExcludedAlbums" />
......@@ -189,5 +190,10 @@
android:resource="@xml/provider_paths"/>
</provider>
<service
android:name=".LookForMediaJob"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>
</application>
</manifest>
package org.horaapps.leafpic;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.media.MediaScannerConnection;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import org.horaapps.leafpic.model.HandlingAlbums;
import org.horaapps.leafpic.model.base.ImageFileFilter;
import java.io.File;
import java.util.ArrayList;
/**
* Created by dnld on 11/29/16.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class LookForMediaJob extends JobService {
private final String TAG = "FUCK";
@Override
public void onCreate() {
super.onCreate();
Log.wtf(TAG, "JOB created");
}
@Override
public boolean onStartJob(final JobParameters jobParameters) {
Log.wtf(TAG, "JOB started");
new Thread(new Runnable() {
@Override
public void run() {
try {
HandlingAlbums instance = HandlingAlbums.getInstance(getApplicationContext());
ArrayList<String> whiteList = instance.getWhiteList();
for (String s : whiteList) {
scanFolder(s);
Log.wtf(TAG, s);
}
notification(whiteList);
} finally {
jobFinished(jobParameters, false);
}
}
}).start();
return true;
}
private void notification(ArrayList<String> list) {
StringBuilder builder = new StringBuilder();
for (String s : list)
builder.append(s).append("\n");
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Looked for media")
.setContentText(builder.toString()); //Required on Gingerbread and below
NotificationManager notificationManager =
(NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
Notification notification = mBuilder.build();
notificationManager.notify(0, notification);
}
private void scanFolder(String path) {
String[] list = new File(path).list(new ImageFileFilter(true));
if (list != null)
MediaScannerConnection.scanFile(getApplicationContext(), list, null, null);
}
@Override
public boolean onStopJob(JobParameters jobParameters) {
Log.wtf(TAG, "JOB stop");
return false;
}
}
......@@ -10,27 +10,11 @@ import org.horaapps.leafpic.model.HandlingAlbums;
*/
public class MyApplication extends Application {
private HandlingAlbums albums = null;
public Album getAlbum() {
return albums.dispAlbums.size() > 0 ? albums.getCurrentAlbum() : Album.getEmptyAlbum();
}
@Override
public void onCreate() {
albums = new HandlingAlbums(getApplicationContext());
super.onCreate();
return getAlbums().getCount() > 0 ? getAlbums().getCurrentAlbum() : Album.getEmptyAlbum();
}
public HandlingAlbums getAlbums() {
return albums;
}
public void setAlbums(HandlingAlbums albums) {
this.albums = albums;
}
public void updateAlbums() {
albums.loadAlbums(getApplicationContext());
return HandlingAlbums.getInstance(getApplicationContext());
}
}
\ No newline at end of file
package org.horaapps.leafpic.activities;
import android.os.Bundle;
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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.view.IconicsImageView;
import org.horaapps.leafpic.MyApplication;
import org.horaapps.leafpic.activities.base.ThemedActivity;
import org.horaapps.leafpic.model.CustomAlbumsHelper;
import java.io.File;
import java.util.ArrayList;
/**
* Created by Jibo on 04/04/2016.
*/
public class ExcludedAlbumsActivity extends ThemedActivity {
private ArrayList<File> excludedFolders = new ArrayList<File>();
private CustomAlbumsHelper h;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.horaapps.leafpic.R.layout.activity_excluded);
h = CustomAlbumsHelper.getInstance(getApplicationContext());
excludedFolders = h.getExcludedFolders();
checkNothing();
initUI();
}
private void checkNothing() {
TextView a = (TextView) findViewById(org.horaapps.leafpic.R.id.nothing_to_show);
a.setTextColor(getTextColor());
a.setVisibility(excludedFolders.size() == 0 ? View.VISIBLE : View.GONE);
}
private void initUI(){
RecyclerView mRecyclerView;
Toolbar toolbar;
/** TOOLBAR **/
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
/** RECYCLE VIEW**/
mRecyclerView = (RecyclerView) findViewById(org.horaapps.leafpic.R.id.excluded_albums);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(new ExcludedItemsAdapter());
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 1));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setBackgroundColor(getBackgroundColor());
/**SET UP UI COLORS**/
toolbar.setBackgroundColor(getPrimaryColor());
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
setStatusBarColor();
setNavBarColor();
setRecentApp(getString(org.horaapps.leafpic.R.string.excluded_albums));
findViewById(org.horaapps.leafpic.R.id.rl_ea).setBackgroundColor(getBackgroundColor());
}
private class ExcludedItemsAdapter extends RecyclerView.Adapter<ExcludedItemsAdapter.ViewHolder> {
private View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
String path = v.getTag().toString();
int pos;
if((pos = getIndex(path)) !=-1) {
h.clearAlbumExclude(excludedFolders.remove(pos).getAbsolutePath());
new Thread(new Runnable() {
@Override
public void run() {
((MyApplication) getApplicationContext()).getAlbums().loadAlbums(getApplicationContext());
}
});
notifyItemRemoved(pos);
checkNothing();
}
}
};
public ExcludedItemsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(org.horaapps.leafpic.R.layout.card_excluded_album, parent, false);
v.findViewById(org.horaapps.leafpic.R.id.UnExclude_icon).setOnClickListener(listener);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(final ExcludedItemsAdapter.ViewHolder holder, final int position) {
File excludedFolder = excludedFolders.get(position);
holder.album_path.setText(excludedFolder.getAbsolutePath());
holder.album_name.setText(excludedFolder.getName());
holder.imgUnExclude.setTag(excludedFolder.getAbsolutePath());
holder.imgFolder.setIcon(GoogleMaterial.Icon.gmd_folder);
/**SET LAYOUT THEME**/
holder.album_name.setTextColor(getTextColor());
holder.album_path.setTextColor(getSubTextColor());
holder.imgFolder.setColor(getIconColor());
holder.imgUnExclude.setColor(getIconColor());
holder.card_layout.setBackgroundColor(getCardBackgroundColor());
}
public int getItemCount() {
return excludedFolders.size();
}
int getIndex(String path) {
for (int i = 0; i < excludedFolders.size(); i++)
if (excludedFolders.get(i).getAbsolutePath().equals(path)) return i;
return -1;
}
class ViewHolder extends RecyclerView.ViewHolder {
LinearLayout card_layout;
IconicsImageView imgUnExclude;
IconicsImageView imgFolder;
TextView album_name;
TextView album_path;
ViewHolder(View itemView) {
super(itemView);
card_layout = (LinearLayout) itemView.findViewById(org.horaapps.leafpic.R.id.linear_card_excluded);
imgUnExclude = (IconicsImageView) itemView.findViewById(org.horaapps.leafpic.R.id.UnExclude_icon);
imgFolder = (IconicsImageView) itemView.findViewById(org.horaapps.leafpic.R.id.folder_icon);
album_name = (TextView) itemView.findViewById(org.horaapps.leafpic.R.id.Excluded_Title_Item);
album_path = (TextView) itemView.findViewById(org.horaapps.leafpic.R.id.Excluded_Path_Item);
}
}
}
}
......@@ -107,10 +107,54 @@ public class PlayerActivity extends ThemedActivity implements SurfaceHolder.Call
private Toolbar toolbar;
private boolean fullscreen = false;
@SuppressWarnings("ResourceAsColor")
private void initUI(){
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.horaapps.leafpic.R.layout.activity_player);
FrameLayout root = (FrameLayout) findViewById(org.horaapps.leafpic.R.id.root);
findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggleControlsVisibility();
}
});
root.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
}
});
root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));
shutterView = findViewById(org.horaapps.leafpic.R.id.shutter);
videoFrame = (AspectRatioFrameLayout) findViewById(org.horaapps.leafpic.R.id.video_frame);
surfaceView = (SurfaceView) findViewById(org.horaapps.leafpic.R.id.surface_view);
surfaceView.getHolder().addCallback(this);
mediaController = new CustomMediaController(this, this);
mediController_anchor = findViewById(org.horaapps.leafpic.R.id.media_player_anchor);
mediaController.setAnchorView(root);
initUi();
CookieHandler currentHandler = CookieHandler.getDefault();
if (currentHandler != defaultCookieManager)
CookieHandler.setDefault(defaultCookieManager);
audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
audioCapabilitiesReceiver.register();
}
private void initUi() {
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent_black));
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
......@@ -119,24 +163,27 @@ public class PlayerActivity extends ThemedActivity implements SurfaceHolder.Call
}
});
toolbar.setTitle(getIntent().getData().getPath());
//getSupportActionBar().setDisplayShowTitleEnabled(false);
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_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
toolbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent_black));
toolbar.animate().translationY(-toolbar.getHeight()).setInterpolator(new AccelerateInterpolator())
.setDuration(0).start();
mediController_anchor.setPadding(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
mediaController.setBackgroundColor(ContextCompat.getColor(getApplicationContext() ,R.color.transparent_black));
mediaController.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent_black));
}
setStatusBarColor();
setNavBarColor();
@SuppressWarnings("ResourceAsColor")
public void updateUiElements() {
setRecentApp(getString(org.horaapps.leafpic.R.string.app_name));
}
......@@ -149,7 +196,7 @@ public class PlayerActivity extends ThemedActivity implements SurfaceHolder.Call
@Override
public void setNavBarColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(ContextCompat.getColor(getApplicationContext() ,R.color.transparent_black));
getWindow().setNavigationBarColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent_black));
}
}
......@@ -204,50 +251,7 @@ public class PlayerActivity extends ThemedActivity implements SurfaceHolder.Call
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.horaapps.leafpic.R.layout.activity_player);
FrameLayout root = (FrameLayout) findViewById(org.horaapps.leafpic.R.id.root);
findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggleControlsVisibility();
}
});
root.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
}
});
root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),R.color.md_black_1000));
shutterView = findViewById(org.horaapps.leafpic.R.id.shutter);
videoFrame = (AspectRatioFrameLayout) findViewById(org.horaapps.leafpic.R.id.video_frame);
surfaceView = (SurfaceView) findViewById(org.horaapps.leafpic.R.id.surface_view);
surfaceView.getHolder().addCallback(this);
mediaController = new CustomMediaController(this, this);
mediController_anchor = findViewById(org.horaapps.leafpic.R.id.media_player_anchor);
mediaController.setAnchorView(root);
//mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
initUI();
CookieHandler currentHandler = CookieHandler.getDefault();
if (currentHandler != defaultCookieManager)
CookieHandler.setDefault(defaultCookieManager);
audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
audioCapabilitiesReceiver.register();
}
@Override
public void onNewIntent(Intent intent) {
......
package org.horaapps.leafpic.activities;
import android.Manifest;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.PorterDuff;
......@@ -9,11 +13,12 @@ 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.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Toast;
import org.horaapps.leafpic.LookForMediaJob;
import org.horaapps.leafpic.R;
import org.horaapps.leafpic.activities.base.SharedMediaActivity;
import org.horaapps.leafpic.model.Album;
......@@ -23,6 +28,7 @@ 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.
......@@ -40,9 +46,7 @@ public class SplashScreen extends SharedMediaActivity {
final static int ALBUMS_BACKUP = 60;
private boolean PICK_INTENT = false;
public final static String ACTION_OPEN_ALBUM = "com.horaapps.leafpic.OPEN_ALBUM";
//private HandlingAlbums albums;
private Album album;
private Album tmpAlbum;
private PreferenceUtil SP;
......@@ -51,11 +55,8 @@ public class SplashScreen extends SharedMediaActivity {
super.onCreate(savedInstanceState);
setContentView(org.horaapps.leafpic.R.layout.activity_splash);
SP = PreferenceUtil.getInstance(getApplicationContext());
startLookingForMedia();
((ProgressBar) findViewById(R.id.progress_splash)).getIndeterminateDrawable().setColorFilter(getPrimaryColor(), PorterDuff.Mode.SRC_ATOP);
RelativeLayout RelLay = (RelativeLayout) findViewById(org.horaapps.leafpic.R.id.Splah_Bg);
RelLay.setBackgroundColor(getBackgroundColor());
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
......@@ -73,7 +74,7 @@ public class SplashScreen extends SharedMediaActivity {
if (ab != null) {
File dir = new File(ab);
// TODO: 19/08/16 look for id
album = new Album(getApplicationContext(), dir.getAbsolutePath(), data.getInt("albumId", -1), dir.getName(), -1);
tmpAlbum = new Album(getApplicationContext(), dir.getAbsolutePath(), data.getInt("albumId", -1), dir.getName(), -1);
new PrefetchPhotosData().execute();
}
} else StringUtils.showToast(getApplicationContext(), "Album not found");
......@@ -89,13 +90,38 @@ public class SplashScreen extends SharedMediaActivity {
}
}
private void startLookingForMedia() {
ComponentName serviceName = new ComponentName(getApplicationContext(), LookForMediaJob.class);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
JobInfo job = new JobInfo.Builder(0, serviceName)
.setPeriodic(1000)
.setRequiresDeviceIdle(true)
.build();
JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
// TODO: 11/29/16 asdasd
//scheduler.cancelAll();
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!");
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_MEDIA_REQUEST) {
if (resultCode == RESULT_OK) {
setResult(RESULT_OK, data);
finish();
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PICK_MEDIA_REQUEST:
if (resultCode == RESULT_OK) {
setResult(RESULT_OK, data);
finish();
}
break;
default: super.onActivityResult(requestCode, resultCode, data);
}
}
......@@ -130,6 +156,12 @@ public class SplashScreen extends SharedMediaActivity {
}
}
@Override
public void updateUiElements() {
((ProgressBar) findViewById(R.id.progress_splash)).getIndeterminateDrawable().setColorFilter(getPrimaryColor(), PorterDuff.Mode.SRC_ATOP);
findViewById(org.horaapps.leafpic.R.id.Splah_Bg).setBackgroundColor(getBackgroundColor());
}
private class PrefetchAlbumsData extends AsyncTask<Boolean, Boolean, Boolean> {
@Override
......@@ -165,7 +197,7 @@ public class SplashScreen extends SharedMediaActivity {
private class PrefetchPhotosData extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... arg0) {
album.updatePhotos(getApplicationContext());
tmpAlbum.updatePhotos(getApplicationContext());
return null;
}
......@@ -174,7 +206,7 @@ public class SplashScreen extends SharedMediaActivity {
super.onPostExecute(result);
Intent i = new Intent(SplashScreen.this, MainActivity.class);
Bundle b = new Bundle();
getAlbums().addAlbum(0, album);
getAlbums().addAlbum(0, tmpAlbum);
b.putInt(CONTENT, PHOTOS_PREFETCHED);
i.putExtras(b);
startActivity(i);
......
package org.horaapps.leafpic.activities.base;
import android.os.Bundle;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AlertDialog;
import android.widget.Toast;
import org.horaapps.leafpic.MyApplication;
import org.horaapps.leafpic.R;
import org.horaapps.leafpic.model.Album;
import org.horaapps.leafpic.model.HandlingAlbums;
import org.horaapps.leafpic.util.AlertDialogsHelper;
import org.horaapps.leafpic.util.ContentHelper;
/**
* Created by dnld on 03/08/16.
*/
public class SharedMediaActivity extends ThemedActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public abstract class SharedMediaActivity extends ThemedActivity {
public HandlingAlbums getAlbums() {
return ((MyApplication) getApplicationContext()).getAlbums();
}
private int REQUEST_CODE_SD_CARD_PERMISSIONS = 42;
public Album getAlbum() {
return ((MyApplication) getApplicationContext()).getAlbum();
}
public HandlingAlbums getAlbums() {
return ((MyApplication) getApplicationContext()).getAlbums();
}
public Album getAlbum() {
return ((MyApplication) getApplicationContext()).getAlbum();
}
public void requestSdCardPermissions() {