Commit 3fd98965 authored by atharvkotwal's avatar atharvkotwal

erge remote-tracking branch 'upstream/master'

parents 553d3f1e 6fdd22fb
...@@ -37,6 +37,8 @@ import com.google.firebase.iid.InstanceIdResult; ...@@ -37,6 +37,8 @@ import com.google.firebase.iid.InstanceIdResult;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import java.util.List;
import app.insti.Constants; import app.insti.Constants;
import app.insti.R; import app.insti.R;
import app.insti.SessionManager; import app.insti.SessionManager;
...@@ -44,6 +46,7 @@ import app.insti.api.RetrofitInterface; ...@@ -44,6 +46,7 @@ import app.insti.api.RetrofitInterface;
import app.insti.api.ServiceGenerator; import app.insti.api.ServiceGenerator;
import app.insti.data.Body; import app.insti.data.Body;
import app.insti.data.Event; import app.insti.data.Event;
import app.insti.data.Notification;
import app.insti.data.Role; import app.insti.data.Role;
import app.insti.data.User; import app.insti.data.User;
import app.insti.fragment.BackHandledFragment; import app.insti.fragment.BackHandledFragment;
...@@ -83,6 +86,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -83,6 +86,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private User currentUser; private User currentUser;
private boolean showNotifications = false; private boolean showNotifications = false;
private BackHandledFragment selectedFragment; private BackHandledFragment selectedFragment;
private Menu menu;
public static void hideKeyboard(Activity activity) { public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
...@@ -136,11 +140,34 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -136,11 +140,34 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
} }
fetchNotifications();
checkLatestVersion(); checkLatestVersion();
NotificationEventReceiver.setupAlarm(getApplicationContext()); NotificationEventReceiver.setupAlarm(getApplicationContext());
} }
private void fetchNotifications() {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getNotifications(getSessionIDHeader()).enqueue(new Callback<List<Notification>>() {
@Override
public void onResponse(Call<List<Notification>> call, Response<List<Notification>> response) {
if (response.isSuccessful()) {
List<Notification> notifications = response.body();
if (notifications != null && !notifications.isEmpty()) {
menu.findItem(R.id.action_notifications).setIcon(R.drawable.baseline_notifications_active_white_24);
} else {
menu.findItem(R.id.action_notifications).setIcon(R.drawable.ic_notifications_white_24dp);
}
}
}
@Override
public void onFailure(Call<List<Notification>> call, Throwable t) {
}
});
}
private void checkLatestVersion() { private void checkLatestVersion() {
try { try {
PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0); PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
...@@ -366,7 +393,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -366,7 +393,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu); this.menu = menu;
fetchNotifications();
getMenuInflater().inflate(R.menu.main, this.menu);
return true; return true;
} }
......
...@@ -66,6 +66,7 @@ public class AboutFragment extends BaseFragment { ...@@ -66,6 +66,7 @@ public class AboutFragment extends BaseFragment {
put(R.id.ranveerimg, "ranveer.jpg"); put(R.id.ranveerimg, "ranveer.jpg");
put(R.id.amangourimg, "amangour.jpg"); put(R.id.amangourimg, "amangour.jpg");
put(R.id.wnccimg, "wncc.jpg"); put(R.id.wnccimg, "wncc.jpg");
put(R.id.safwanimg, "safwan.jpg");
}}; }};
/* Show team pics */ /* Show team pics */
......
...@@ -5,14 +5,21 @@ import android.app.NotificationManager; ...@@ -5,14 +5,21 @@ import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.media.Image;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.support.v4.app.JobIntentService; import android.support.v4.app.JobIntentService;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import com.squareup.picasso.Picasso;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import app.insti.Constants; import app.insti.Constants;
...@@ -27,6 +34,7 @@ import retrofit2.Call; ...@@ -27,6 +34,7 @@ import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
public class NotificationIntentService extends JobIntentService { public class NotificationIntentService extends JobIntentService {
public static final String ACTION_OPEN_EVENT = "ACTION_OPEN_EVENT"; public static final String ACTION_OPEN_EVENT = "ACTION_OPEN_EVENT";
...@@ -58,6 +66,37 @@ public class NotificationIntentService extends JobIntentService { ...@@ -58,6 +66,37 @@ public class NotificationIntentService extends JobIntentService {
return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS); return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS);
} }
public static Bitmap getImageBitmapFromURL(final String imageUrl){
Bitmap imageBitmap = null;
try {
imageBitmap = new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... params) {
{
int targetHeight = 200;
int targetWidth = 200;
try {
return Picasso.get()
.load(String.valueOf(imageUrl)).get();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}.execute().get();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e)
{
e.printStackTrace();
}
return imageBitmap;
}
@Override @Override
protected void onHandleWork(Intent intent) { protected void onHandleWork(Intent intent) {
Log.d(getClass().getSimpleName(), "onHandleIntent, started handling a notification event"); Log.d(getClass().getSimpleName(), "onHandleIntent, started handling a notification event");
...@@ -129,7 +168,9 @@ public class NotificationIntentService extends JobIntentService { ...@@ -129,7 +168,9 @@ public class NotificationIntentService extends JobIntentService {
.setColor(getResources().getColor(R.color.colorAccent)) .setColor(getResources().getColor(R.color.colorAccent))
.setContentText("Event is about to start in " + getDateDiff(new Date(), event.getEventStartTime(), TimeUnit.MINUTES) + ((getDateDiff(new Date(), event.getEventStartTime(), TimeUnit.MINUTES) == 1) ? " minute." : " minutes.")) .setContentText("Event is about to start in " + getDateDiff(new Date(), event.getEventStartTime(), TimeUnit.MINUTES) + ((getDateDiff(new Date(), event.getEventStartTime(), TimeUnit.MINUTES) == 1) ? " minute." : " minutes."))
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.lotus_white)) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.lotus_white))
.setSmallIcon(R.drawable.lotus_white); .setSmallIcon(R.drawable.lotus_white)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(getImageBitmapFromURL(event.getEventImageURL())));
Intent intent = new Intent(getApplicationContext(), MainActivity.class); Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setAction(ACTION_OPEN_EVENT); intent.setAction(ACTION_OPEN_EVENT);
...@@ -143,14 +184,17 @@ public class NotificationIntentService extends JobIntentService { ...@@ -143,14 +184,17 @@ public class NotificationIntentService extends JobIntentService {
builder.setContentIntent(pendingIntent); builder.setContentIntent(pendingIntent);
builder.setDeleteIntent(NotificationEventReceiver.getDeleteIntent(getApplicationContext())); builder.setDeleteIntent(NotificationEventReceiver.getDeleteIntent(getApplicationContext()));
Intent navigateIntent = new Intent(getApplicationContext(), NotificationIntentService.class); if(event.getEventVenues().size() > 0)
navigateIntent.setAction(ACTION_NAVIGATE); {
navigateIntent.putExtra(Constants.EVENT_ID, event.getEventID()); Intent navigateIntent = new Intent(getApplicationContext(), NotificationIntentService.class);
navigateIntent.putExtra(Constants.EVENT_LATITUDE, event.getEventVenues().get(0).getVenueLatitude()); navigateIntent.setAction(ACTION_NAVIGATE);
navigateIntent.putExtra(Constants.EVENT_LONGITUDE, event.getEventVenues().get(0).getVenueLongitude()); navigateIntent.putExtra(Constants.EVENT_ID, event.getEventID());
navigateIntent.putExtra("NOTIFICATION_ID", NOTIFICATION_ID); navigateIntent.putExtra(Constants.EVENT_LATITUDE, event.getEventVenues().get(0).getVenueLatitude());
PendingIntent navigatePendingIntent = PendingIntent.getService(getApplicationContext(), 0, navigateIntent, PendingIntent.FLAG_UPDATE_CURRENT); navigateIntent.putExtra(Constants.EVENT_LONGITUDE, event.getEventVenues().get(0).getVenueLongitude());
builder.addAction(R.drawable.baseline_navigation_white_24, "Navigate", navigatePendingIntent); navigateIntent.putExtra("NOTIFICATION_ID", NOTIFICATION_ID);
PendingIntent navigatePendingIntent = PendingIntent.getService(getApplicationContext(), 0, navigateIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.baseline_navigation_white_24, "Navigate", navigatePendingIntent);
}
Intent notGoingIntent = new Intent(getApplicationContext(), NotificationIntentService.class); Intent notGoingIntent = new Intent(getApplicationContext(), NotificationIntentService.class);
notGoingIntent.setAction(ACTION_NOT_GOING); notGoingIntent.setAction(ACTION_NOT_GOING);
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M7.58,4.08L6.15,2.65C3.75,4.48 2.17,7.3 2.03,10.5h2c0.15,-2.65 1.51,-4.97 3.55,-6.42zM19.97,10.5h2c-0.15,-3.2 -1.73,-6.02 -4.12,-7.85l-1.42,1.43c2.02,1.45 3.39,3.77 3.54,6.42zM18,11c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2v-5zM12,22c0.14,0 0.27,-0.01 0.4,-0.04 0.65,-0.14 1.18,-0.58 1.44,-1.18 0.1,-0.24 0.15,-0.5 0.15,-0.78h-4c0.01,1.1 0.9,2 2.01,2z"/>
</vector>
...@@ -375,22 +375,65 @@ ...@@ -375,22 +375,65 @@
</LinearLayout> </LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/maitreyaimg"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_gravity="center"
android:layout_marginTop="20dp" />
<TextView
android:id="@+id/maitreya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp" <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:gravity="center" android:gravity="center"
android:text="Maitreya Verma" android:orientation="horizontal">
android:textStyle="bold" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/maitreyaimg"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_gravity="center"
android:layout_marginEnd="50dp" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/safwanimg"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_gravity="center"
android:layout_marginStart="50dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/maitreya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="35dp"
android:gravity="center"
android:text="Maitreya Verma"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="@+id/safwan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:gravity="center"
android:text="Mohd Safwan"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
<TextView <TextView
android:id="@+id/alumni" android:id="@+id/alumni"
...@@ -403,6 +446,12 @@ ...@@ -403,6 +446,12 @@
android:textSize="18sp" android:textSize="18sp"
android:textStyle="bold" /> android:textStyle="bold" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
......
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