Commit 5cf93afe authored by Donald's avatar Donald

draft look for media job

parent 7abf321a
......@@ -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"
......@@ -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;
}
}
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,13 @@ 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 +29,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.
......@@ -51,6 +58,7 @@ 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);
......@@ -89,6 +97,28 @@ 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) {
......
......@@ -113,6 +113,10 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
String albumPhotoCountHtml = "<b><font color='" + hexAccentColor + "'>" + a.getCount() + "</font></b>" + "<font " +
"color='" + textColor + "'> " + holder.nPhotos.getContext().getString(R.string.media) + "</font>";
if (cvs.equals(CardViewStyle.CARD_COMPACT)) {
albumPhotoCountHtml = "<b><font color='" + textColor + "'>#" + a.getCount() + "</font></b>";
}
holder.name.setText(StringUtils.html(albumNameHtml));
holder.nPhotos.setText(StringUtils.html(albumPhotoCountHtml));
......
......@@ -216,6 +216,17 @@ public class HandlingAlbums extends SQLiteOpenHelper {
sortAlbums(context);
}
public ArrayList<String> getWhiteList() {
ArrayList<String> list = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cur = db.query(TABLE_ALBUMS, new String[]{ ALBUM_PATH }, null, null, null, null, null);
while (cur.moveToNext())
list.add(cur.getString(0));
cur.close();
db.close();
return list;
}
public void addAlbum(int position, Album album) {
dispAlbums.add(position, album);
setCurrentAlbum(album);
......
......@@ -43,26 +43,28 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:orientation="horizontal"
>
android:orientation="horizontal">
<TextView
android:id="@+id/album_name"
android:layout_width="match_parent"
android:id="@+id/album_photos_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:padding="@dimen/small_spacing"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textSize="14sp"
android:paddingStart="8dp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
/>
<TextView
android:id="@+id/album_photos_count"
android:layout_width="match_parent"
android:id="@+id/album_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:padding="@dimen/small_spacing"
android:textColor="@android:color/white"
android:textSize="14sp"
android:visibility="gone"
android:textSize="16sp"
/>
</LinearLayout>
</org.horaapps.leafpic.views.SquareRelativeLayout>
</LinearLayout>
......
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