Skip to content

Commit 77d7e12

Browse files
committed
Launch exam schedule on notification click
- Minor notification improvements
1 parent a8305f8 commit 77d7e12

File tree

5 files changed

+52
-28
lines changed

5 files changed

+52
-28
lines changed

app/src/main/java/tk/therealsuji/vtopchennai/activities/LauncherActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ protected void onCreate(Bundle savedInstanceState) {
3131
super.onCreate(savedInstanceState);
3232

3333
Intent intent = new Intent();
34+
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
35+
3436
if (this.getIntent().getExtras() != null) {
3537
intent.putExtras(this.getIntent().getExtras());
3638
}

app/src/main/java/tk/therealsuji/vtopchennai/activities/MainActivity.java

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ private void hideBottomNavigationView() {
135135
this.bottomNavigationView.clearAnimation();
136136
this.bottomNavigationView.post(() -> this.bottomNavigationView.animate().translationY(bottomNavigationView.getMeasuredHeight()));
137137

138-
int gestureLeft = 0;
139-
140138
if (Build.VERSION.SDK_INT >= 29) {
141-
gestureLeft = this.getWindow().getDecorView().getRootWindowInsets().getSystemGestureInsets().left;
142-
}
139+
this.getWindow().getDecorView().post(() -> {
140+
int gestureLeft = this.getWindow().getDecorView().getRootWindowInsets().getSystemGestureInsets().left;
143141

144-
if (gestureLeft == 0) {
145-
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
142+
if (gestureLeft == 0) {
143+
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
144+
}
145+
});
146146
}
147147
}
148148

@@ -165,9 +165,9 @@ private void getUnreadCount() {
165165
Bundle unreadCount = new Bundle();
166166

167167
Observable.concat(
168-
Observable.fromSingle(appDatabase.spotlightDao().getUnreadCount()),
169-
Observable.fromSingle(appDatabase.marksDao().getMarksUnreadCount())
170-
)
168+
Observable.fromSingle(appDatabase.spotlightDao().getUnreadCount()),
169+
Observable.fromSingle(appDatabase.marksDao().getMarksUnreadCount())
170+
)
171171
.subscribeOn(Schedulers.single())
172172
.observeOn(AndroidSchedulers.mainThread())
173173
.subscribe(new Observer<Integer>() {
@@ -264,6 +264,8 @@ protected void onCreate(Bundle savedInstanceState) {
264264
getSupportFragmentManager().setFragmentResultListener("syncData", this, (requestKey, result) -> this.syncData());
265265
getSupportFragmentManager().setFragmentResultListener("getUnreadCount", this, (requestKey, result) -> this.getUnreadCount());
266266

267+
this.getUnreadCount();
268+
267269
this.bottomNavigationView.setOnItemSelectedListener(item -> {
268270
Fragment selectedFragment;
269271
String selectedFragmentTag;
@@ -309,13 +311,20 @@ protected void onCreate(Bundle savedInstanceState) {
309311

310312
int selectedItem = R.id.item_home;
311313
Serializable launchFragment = this.getIntent().getSerializableExtra("launchFragment");
314+
String launchSubFragment = this.getIntent().getStringExtra("launchSubFragment");
312315

313316
if (savedInstanceState != null) {
314317
selectedItem = savedInstanceState.getInt("selectedItem");
315318
} else if (launchFragment != null) {
316319
// If the application is launched from notifications
317-
if (AssignmentsFragment.class.equals(launchFragment)) {
318-
selectedItem = R.id.item_assignments;
320+
if (launchFragment.equals(ProfileFragment.class)) {
321+
selectedItem = R.id.item_profile;
322+
}
323+
324+
if (launchSubFragment != null) {
325+
Bundle launchSubFragmentBundle = new Bundle();
326+
launchSubFragmentBundle.putString("subFragment", launchSubFragment);
327+
getSupportFragmentManager().setFragmentResult("launchSubFragment", launchSubFragmentBundle);
319328
}
320329
}
321330

@@ -348,18 +357,18 @@ public void onComplete() {
348357

349358
while (data != -1) {
350359
char current = (char) data;
351-
sb.append(current);
352-
data = reader.read();
353-
}
360+
sb.append(current);
361+
data = reader.read();
362+
}
354363

355-
String result = sb.toString();
356-
JSONObject about = new JSONObject(result);
364+
String result = sb.toString();
365+
JSONObject about = new JSONObject(result);
357366

358-
return about.getInt("versionCode");
359-
} catch (Exception ignored) {
360-
return 0;
361-
}
362-
})
367+
return about.getInt("versionCode");
368+
} catch (Exception ignored) {
369+
return 0;
370+
}
371+
})
363372
.subscribeOn(Schedulers.io())
364373
.observeOn(AndroidSchedulers.mainThread())
365374
.subscribe(new Observer<Integer>() {

app/src/main/java/tk/therealsuji/vtopchennai/fragments/ProfileFragment.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ public void onResume() {
280280
bundle.putString(FirebaseAnalytics.Param.SCREEN_CLASS, "ProfileFragment");
281281
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, "Profile");
282282
FirebaseAnalytics.getInstance(this.requireContext()).logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle);
283+
284+
getParentFragmentManager().setFragmentResultListener("launchSubFragment", this, (requestKey, result) -> {
285+
String subFragment = result.getString("subFragment");
286+
287+
if (subFragment.equals("ExamSchedule")) {
288+
SettingsRepository.openViewPagerFragment(
289+
requireActivity(),
290+
R.string.exam_schedule,
291+
ViewPagerFragment.TYPE_EXAMS
292+
);
293+
}
294+
});
283295
}
284296

285297
@Override

app/src/main/java/tk/therealsuji/vtopchennai/helpers/NotificationHelper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public NotificationCompat.Builder notifyUpcoming(Timetable.AllData timetableItem
126126
0,
127127
new Intent(this, LauncherActivity.class)
128128
.putExtra("launchFragment", HomeFragment.class),
129-
PendingIntent.FLAG_IMMUTABLE
129+
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
130130
);
131131
String title = "Upcoming: " +
132132
SettingsRepository.getSystemFormattedTime(this, timetableItem.startTime) + " - " +
@@ -166,7 +166,7 @@ public NotificationCompat.Builder notifyOngoing(Timetable.AllData timetableItem)
166166
0,
167167
new Intent(this, LauncherActivity.class)
168168
.putExtra("launchFragment", HomeFragment.class),
169-
PendingIntent.FLAG_IMMUTABLE
169+
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
170170
);
171171
String title = "Ongoing: " +
172172
SettingsRepository.getSystemFormattedTime(this, timetableItem.startTime) + " - " +
@@ -210,8 +210,9 @@ public NotificationCompat.Builder notifyExam(Exam.AllData examItem) {
210210
this,
211211
0,
212212
new Intent(this, LauncherActivity.class)
213-
.putExtra("launchFragment", ProfileFragment.class),
214-
PendingIntent.FLAG_IMMUTABLE
213+
.putExtra("launchFragment", ProfileFragment.class)
214+
.putExtra("launchSubFragment", "ExamSchedule"),
215+
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
215216
);
216217
String title = "All the best for your exam!";
217218
String message = examItem.courseCode + " - " + examItem.courseTitle;

app/src/main/java/tk/therealsuji/vtopchennai/helpers/SettingsRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ public static void setTimetableNotifications(Context context, Timetable timetabl
311311
alarm.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timetable.startTime.split(":")[0]));
312312
alarm.set(Calendar.MINUTE, Integer.parseInt(timetable.startTime.split(":")[1]));
313313

314-
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, alarmCount++, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
314+
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, alarmCount++, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
315315
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarm.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, pendingIntent);
316316

317317
alarm.add(Calendar.MINUTE, -30);
318-
pendingIntent = PendingIntent.getBroadcast(context, alarmCount++, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
318+
pendingIntent = PendingIntent.getBroadcast(context, alarmCount++, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
319319
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarm.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, pendingIntent);
320320
}
321321

@@ -343,7 +343,7 @@ public static void setExamNotifications(Context context, List<Exam> exams) {
343343
alarm.setTime(new Date(exam.startTime));
344344
alarm.add(Calendar.MINUTE, -30);
345345

346-
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, alarmCount++, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
346+
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, alarmCount++, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
347347
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarm.getTimeInMillis(), pendingIntent);
348348
}
349349

0 commit comments

Comments
 (0)