Commit 3ed11a83 authored by Varun Patil's avatar Varun Patil

Follow notifications for event, user, body

parent 118767a2
...@@ -28,6 +28,10 @@ public class Constants { ...@@ -28,6 +28,10 @@ public class Constants {
public static final String LOGIN_MESSAGE = "Please login to continue!"; public static final String LOGIN_MESSAGE = "Please login to continue!";
public static final String MAIN_INTENT_EXTRAS = "MAIN_EXTRA";
public static final String FCM_BUNDLE_TYPE = "type";
public static final String FCM_BUNDLE_ID = "id";
/* Map */ /* Map */
public static final double MAP_Xn = 19.134417, MAP_Yn = 72.901229, MAP_Zn = 1757, MAP_Zyn = 501; public static final double MAP_Xn = 19.134417, MAP_Yn = 72.901229, MAP_Zn = 1757, MAP_Zyn = 501;
public static final double[] MAP_WEIGHTS_X = {-11.392001766454612, -36.31634553309953, 73.91269388324432, -24.14021153064087, 3.4508817531539115, -0.1462262375477863, 5.532505074667804, -1.542391995870977, 36.14211738142935}; public static final double[] MAP_WEIGHTS_X = {-11.392001766454612, -36.31634553309953, 73.91269388324432, -24.14021153064087, 3.4508817531539115, -0.1462262375477863, 5.532505074667804, -1.542391995870977, 36.14211738142935};
......
...@@ -18,6 +18,7 @@ import com.google.android.gms.tasks.OnSuccessListener; ...@@ -18,6 +18,7 @@ import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.iid.FirebaseInstanceId; import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult; import com.google.firebase.iid.InstanceIdResult;
import app.insti.Constants;
import app.insti.R; import app.insti.R;
import app.insti.SessionManager; import app.insti.SessionManager;
import app.insti.api.RetrofitInterface; import app.insti.api.RetrofitInterface;
...@@ -58,6 +59,13 @@ public class LoginActivity extends AppCompatActivity { ...@@ -58,6 +59,13 @@ public class LoginActivity extends AppCompatActivity {
private void openMainActivity() { private void openMainActivity() {
Intent i = new Intent(mContext, MainActivity.class); Intent i = new Intent(mContext, MainActivity.class);
/* Pass FCM data if available */
Intent myIntent = getIntent();
if (myIntent.getExtras() != null) {
i.putExtra(Constants.MAIN_INTENT_EXTRAS, myIntent.getExtras());
}
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i); startActivity(i);
......
...@@ -62,10 +62,10 @@ import app.insti.fragment.MyEventsFragment; ...@@ -62,10 +62,10 @@ import app.insti.fragment.MyEventsFragment;
import app.insti.fragment.NewsFragment; import app.insti.fragment.NewsFragment;
import app.insti.fragment.NotificationsFragment; import app.insti.fragment.NotificationsFragment;
import app.insti.fragment.PlacementBlogFragment; import app.insti.fragment.PlacementBlogFragment;
import app.insti.fragment.UserFragment;
import app.insti.fragment.QuickLinksFragment; import app.insti.fragment.QuickLinksFragment;
import app.insti.fragment.SettingsFragment; import app.insti.fragment.SettingsFragment;
import app.insti.fragment.TrainingBlogFragment; import app.insti.fragment.TrainingBlogFragment;
import app.insti.fragment.UserFragment;
import app.insti.notifications.NotificationEventReceiver; import app.insti.notifications.NotificationEventReceiver;
import okhttp3.Cache; import okhttp3.Cache;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
...@@ -139,7 +139,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -139,7 +139,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
Intent intent = getIntent(); Intent intent = getIntent();
if (intent != null) { if (intent != null) {
if (intent.getAction() != null && intent.getAction().equals(ACTION_OPEN_EVENT)) { // Check for data passed by FCM
if (intent.getExtras() != null && intent.getBundleExtra(Constants.MAIN_INTENT_EXTRAS) != null) {
handleFCMIntent(intent.getBundleExtra(Constants.MAIN_INTENT_EXTRAS));
} else if (intent.getAction() != null && intent.getAction().equals(ACTION_OPEN_EVENT)) {
EventFragment eventFragment = new EventFragment(); EventFragment eventFragment = new EventFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(Constants.EVENT_JSON, intent.getStringExtra(Constants.EVENT_JSON)); bundle.putString(Constants.EVENT_JSON, intent.getStringExtra(Constants.EVENT_JSON));
...@@ -248,23 +251,56 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -248,23 +251,56 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
mNotificationManager.createNotificationChannel(mChannel); mNotificationManager.createNotificationChannel(mChannel);
} }
/** Handle opening event/body/blog from FCM notification */
private void handleFCMIntent(Bundle bundle) {
chooseIntent(
bundle.getString(Constants.FCM_BUNDLE_TYPE),
bundle.getString(Constants.FCM_BUNDLE_ID)
);
}
/** Handle intents for links */
private void handleIntent(Intent appLinkIntent) { private void handleIntent(Intent appLinkIntent) {
String appLinkAction = appLinkIntent.getAction(); String appLinkAction = appLinkIntent.getAction();
String appLinkData = appLinkIntent.getDataString(); String appLinkData = appLinkIntent.getDataString();
if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null) { if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null) {
switch (getType(appLinkData)) { chooseIntent(getType(appLinkData), getID(appLinkData));
}
}
/** Open the proper fragment from given type and id */
private void chooseIntent(String type, String id) {
if (type == null || id == null) { return; }
switch (type) {
case "body": case "body":
Body body = new Body(getID(appLinkData)); openBodyFragment(id);
BodyFragment bodyFragment = BodyFragment.newInstance(body);
updateFragment(bodyFragment);
break; break;
case "user": case "user":
UserFragment userFragment = UserFragment.newInstance(getID(appLinkData)); openUserFragment(id);
updateFragment(userFragment);
break; break;
case "event": case "event":
openEventFragment(id);
break;
}
}
/** Open user fragment from given id */
private void openUserFragment(String id) {
UserFragment userFragment = UserFragment.newInstance(id);
updateFragment(userFragment);
}
/** Open the body fragment from given id */
private void openBodyFragment(String id) {
Body body = new Body(id);
BodyFragment bodyFragment = BodyFragment.newInstance(body);
updateFragment(bodyFragment);
}
/** Open the event fragment from the provided id */
private void openEventFragment(String id) {
RetrofitInterface retrofitInterface = getRetrofitInterface(); RetrofitInterface retrofitInterface = getRetrofitInterface();
retrofitInterface.getEvent(getSessionIDHeader(), getID(appLinkData)).enqueue(new Callback<Event>() { retrofitInterface.getEvent(getSessionIDHeader(), id).enqueue(new Callback<Event>() {
@Override @Override
public void onResponse(Call<Event> call, Response<Event> response) { public void onResponse(Call<Event> call, Response<Event> response) {
EventFragment eventFragment = new EventFragment(); EventFragment eventFragment = new EventFragment();
...@@ -275,13 +311,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -275,13 +311,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
@Override @Override
public void onFailure(Call<Event> call, Throwable t) { public void onFailure(Call<Event> call, Throwable t) {}
}
}); });
} }
}
}
private String getID(String appLinkData) { private String getID(String appLinkData) {
if (appLinkData.charAt(appLinkData.length() - 1) == '/') if (appLinkData.charAt(appLinkData.length() - 1) == '/')
...@@ -342,8 +374,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -342,8 +374,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
@Override @Override
public void onFailure(Call<User> call, Throwable t) { public void onFailure(Call<User> call, Throwable t) {}
}
}); });
} }
}); });
...@@ -492,9 +523,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -492,9 +523,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
case R.id.nav_settings: case R.id.nav_settings:
SettingsFragment settingsFragment = new SettingsFragment(); SettingsFragment settingsFragment = new SettingsFragment();
updateFragment(settingsFragment); updateFragment(settingsFragment);
//Checking the about fragment
//AboutFragment aboutFragment = new AboutFragment();
//updateFragment(aboutFragment);
break; break;
} }
......
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