diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 96a3315..2aa07f6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -51,9 +51,6 @@ android:parentActivityName=".DrugListActivity" android:theme="@style/AppTheme" /> - diff --git a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java deleted file mode 100644 index 3ee2e7b..0000000 --- a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java +++ /dev/null @@ -1,133 +0,0 @@ -package net.foucry.pilldroid; - -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.app.job.JobParameters; -import android.app.job.JobService; -import android.content.Intent; -import android.util.Log; - -import androidx.core.app.NotificationCompat; -import androidx.core.app.NotificationManagerCompat; - -import java.util.List; - -/** - * Created by jacques on 17/09/16. - */ - -public class PillDroidJobService extends JobService { - private static final String TAG = JobService.class.getName(); - private boolean jobCancelled = false; - private final DBHelper dbHelper = new DBHelper(this); - - - @Override - public boolean onStartJob(JobParameters params) { - Log.d(TAG, "Job started"); - createNotificationChannel(); - doBackgroundWork(params); - - return false; - } - - /** - * Grab sorted list of medicaments - * test dateAlert of the first of the list - * if dateAlert < now - * schedule notification - * @param params JobParameters - */ - private void doBackgroundWork(final JobParameters params) { - - Log.d(TAG,"background job"); - if (jobCancelled) { - return; - } - List drugs = dbHelper.getAllDrugs(); - - Drug firstDrug = null; - - try { - firstDrug = drugs.get(0); - } - catch (Exception e){ - Log.e(TAG, e.toString()); - e.printStackTrace(); - } - - if (firstDrug != null) { - if (firstDrug.getTake() != 0) { - if(firstDrug.getStock() < firstDrug.getAlertThreshold()) { - scheduleNotification(); - } else - { - double dummy = (firstDrug.getStock() - firstDrug.getAlertThreshold()); - Log.d(TAG, "no notification scheduled " + dummy); - } - } - } - - Log.d(TAG, "Job finished"); - jobFinished(params, true); - } - - - @Override - public boolean onStopJob(JobParameters params) { - Log.d(TAG, "Job cancelled before completion"); - jobCancelled = true; - return false; - } - - /** - * Schedule Notification for the delay - */ - void scheduleNotification() { - Log.d(TAG, "schedule notification"); - createNotificationChannel(); - Intent intent = new Intent(this, DrugListActivity.class); - PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_MUTABLE); - NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "PillDroid") - .setSmallIcon(R.drawable.ic_pill_alarm) - .setContentTitle(getString(R.string.app_name)) - .setContentText(getString(R.string.notification_text)) - .setPriority(NotificationCompat.PRIORITY_HIGH) - .setContentIntent(pendingIntent) - .setAutoCancel(true); - - NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); - int notificationId = 666; - notificationManager.notify(notificationId, builder.build()); - } - - /** - * createNotificationChannelid for android API >= 28 - */ - private void createNotificationChannel() { - - Log.d(TAG, "start create notification channel"); - CharSequence name = getString(R.string.channel_name); - String description = getString(R.string.channel_description); - int importance = NotificationManager.IMPORTANCE_DEFAULT; - String CHANNEL_ID = "PillDroid"; - NotificationChannel channel; - channel = new NotificationChannel(CHANNEL_ID, name, importance); - - channel.setDescription(description); - // Register the channel with the system; you can't change the importance - // or other notification behaviors after this - NotificationManager notificationManager = getSystemService(NotificationManager.class); - try { - notificationManager.createNotificationChannel(channel); - } catch (Exception e) { - // This will catch any exception, because they are all descended from Exception - Log.e(TAG, e.toString()); - //At the level Exception Class handle the error in Exception Table - // Exception Create That Error Object and throw it - //E.g: FileNotFoundException ,etc - e.printStackTrace(); - } - } -} diff --git a/app/src/main/java/net/foucry/pilldroid/SlideAnimationUtil.java b/app/src/main/java/net/foucry/pilldroid/SlideAnimationUtil.java deleted file mode 100644 index 8be7edb..0000000 --- a/app/src/main/java/net/foucry/pilldroid/SlideAnimationUtil.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.foucry.pilldroid; - -import android.content.Context; -import android.view.View; -import android.view.animation.AnimationUtils; - -public class SlideAnimationUtil { - - /** - * Animates a view so that it slides in from the left of it's container. - * - * @param context Context - * @param view View - */ - public static void slideInFromLeft(Context context, View view) { - runSimpleAnimation(context, view, R.anim.slide_from_left); - } - - /** - * Animates a view so that it slides from its current position, out of view to the left. - * - * @param context Context - * @param view View - */ - public static void slideOutToLeft(Context context, View view) { - runSimpleAnimation(context, view, R.anim.slide_to_left); - } - - /** - * Animates a view so that it slides in the from the right of it's container. - * - * @param context Context - * @param view View - */ - public static void slideInFromRight(Context context, View view) { - runSimpleAnimation(context, view, R.anim.slide_from_right); - } - - /** - * Animates a view so that it slides from its current position, out of view to the right. - * - * @param context Context - * @param view View - */ - public static void slideOutToRight(Context context, View view) { - runSimpleAnimation(context, view, R.anim.slide_to_right); - } - - /** - * Runs a simple animation on a View with no extra parameters. - * - * @param context Context - * @param view View - * @param animationId int - */ - private static void runSimpleAnimation(Context context, View view, int animationId) { - view.startAnimation(AnimationUtils.loadAnimation( - context, animationId - )); - } - -}