Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
notifications
Browse files Browse the repository at this point in the history
smaller notif icon

Signed-off-by: avi parshan <avi.pars@gmail.com>
  • Loading branch information
avipars committed Aug 26, 2018
1 parent 89f235b commit 022404d
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions app/src/main/java/com/aviparshan/pazamcount/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.DatePickerDialog;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
Expand Down Expand Up @@ -39,6 +41,7 @@
public class Main extends AppCompatActivity {

private static final String[] paths = {"2 Years 8 Months", "2 Years 6 Months", "2 Years 4 Months", "2 Years", "1 Year 6 Months", "1 Year", "6 Months"};
public static final String CHANNEL_ID = "PazamOlam Channel";
private Spinner spinner;
DatePicker datePicker;
String start_date;
Expand Down Expand Up @@ -225,6 +228,7 @@ public void checkFirstRun() {
.edit()
.putBoolean(help.firstRunKey, false)
.apply();
createNotificationChannel();
} else if (Helper.getBoolPref(help.goBackKey, getApplicationContext())) {
Helper.putPref(help.goBackKey, false, getApplicationContext());
} else {
Expand All @@ -243,4 +247,21 @@ void showFAB() {
fab.startAnimation(show_fab);
}

private void createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.channel_name);
String description = getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel 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);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
}
}
51 changes: 49 additions & 2 deletions app/src/main/java/com/aviparshan/pazamcount/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
Expand Down Expand Up @@ -39,6 +42,7 @@
import java.util.Date;
import java.util.Locale;

import static com.aviparshan.pazamcount.Main.CHANNEL_ID;
import static java.lang.Math.abs;

public class Results extends AppCompatActivity {
Expand All @@ -54,6 +58,8 @@ public class Results extends AppCompatActivity {
Date f;
int progress;
boolean released = false;
boolean reachedYear = false;
int days_left;
private Handler handler = new Handler();
private Runnable runnable;
Toolbar toolbar;
Expand All @@ -71,7 +77,6 @@ public static void setStatusBarGradient(Activity activity) {
}
}


void setProcessBar(int progress) {
ProgressBarAnimation anim = new ProgressBarAnimation(prog, 0, progress);
anim.setDuration(1500);
Expand Down Expand Up @@ -102,9 +107,12 @@ void setDiff() {

DateTime now = new DateTime();
LocalDate today = now.toLocalDate();
int days_left = Days.daysBetween(new LocalDate(today), new LocalDate(f)).getDays();
days_left = Days.daysBetween(new LocalDate(today), new LocalDate(f)).getDays();
int total_days = Days.daysBetween(new LocalDate(startD), new LocalDate(f)).getDays();
int served = total_days - days_left;
if (served == 365) {
reachedYear = true;
}
double monthsLeft = (days_left) / 30.4375;
double weeksLeft = (days_left) / 7;
double hoursLeft = (days_left) * 24;
Expand Down Expand Up @@ -218,7 +226,24 @@ protected void onCreate(Bundle savedInstanceState) {
setDiff();
if (released) {
card3.setVisibility(View.GONE);
notifyMilestones(1, "Milestone Reached", "You have finished your service, congrats! ");
}
if (progress == 50) {
notifyMilestones(2, "Milestone Reached", "You have hit the wall, congrats! ");
}
if (reachedYear) {
notifyMilestones(3, "Pazamhuledet", "You have finished a year of service, congrats! ");
}
if (progress == 50) {
notifyMilestones(2, "Milestone Reached", "You have hit the wall, congrats! ");
}
if (days_left == 1 || days_left == 0) {
notifyMilestones(2, "Almost Out", "You are almost out of the army, congrats! ");

}



// card.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
Expand Down Expand Up @@ -262,6 +287,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
// getMenuInflater().inflate(R.menu.menu_patient_home_screen, menu);

menu.add(0, 1, 1, menuIconWithText(getResources().getDrawable(R.drawable.ic_date_), getResources().getString(R.string.go_back)));

return true;
}

Expand Down Expand Up @@ -300,6 +326,27 @@ private void stopUpdates() {
isTimerRunning = false;
}
}

private void notifyMilestones(int notificationId, String title, String achievement) {

// Create an explicit intent for an Activity in your app
Intent intent = new Intent(this, Results.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.date)
.setContentTitle(title)
.setContentText(achievement + progress + "% Reached")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

// notificationId is a unique int for each notification that you must define

notificationManager.notify(notificationId, mBuilder.build());
}
}


9 changes: 9 additions & 0 deletions app/src/main/res/drawable/date.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M9,11L7,11v2h2v-2zM13,11h-2v2h2v-2zM17,11h-2v2h2v-2zM19,4h-1L18,2h-2v2L8,4L8,2L6,2v2L5,4c-1.11,0 -1.99,0.9 -1.99,2L3,20c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.9,-2 -2,-2zM19,20L5,20L5,9h14v11z" />
</vector>
5 changes: 2 additions & 3 deletions app/src/main/res/layout/activity_results.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,10 @@
android:textSize="18sp" />
</android.support.v7.widget.CardView>

<com.startapp.android.publish.ads.banner.Mrec
android:id="@+id/startAppMrec"
<com.startapp.android.publish.ads.banner.Banner
android:id="@+id/startAppBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@id/card3"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">PazamCount</string>
<string name="app_name">PazamOlam Dashboard</string>
<string name="draft_date">Draft Date</string>
<string name="btn_sign_up">Save</string>
<string name="service_time">Service Time</string>
Expand All @@ -8,4 +8,6 @@
<string name="percentage_of_service">% Done</string>
<string name="pazam">Days Served</string>
<string name="click">Click on a date to continue</string>
<string name="channel_name">PazamOlam Notification Channel</string>
<string name="channel_description">Here, we will send you notifications based on milestones in your service.</string>
</resources>

0 comments on commit 022404d

Please sign in to comment.