Skip to content

Commit

Permalink
Fix theming issues when launched from notification
Browse files Browse the repository at this point in the history
  • Loading branch information
therealsujitk committed Sep 18, 2022
1 parent 6605db2 commit 0593482
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
Expand Up @@ -27,13 +27,19 @@ protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

Intent intent = new Intent();
if (this.getIntent().getExtras() != null) {
intent.putExtras(this.getIntent().getExtras());
}

if (SettingsRepository.isSignedIn(this.getApplicationContext())) {
startActivity(new Intent(LauncherActivity.this, MainActivity.class));
intent.setClass(LauncherActivity.this, MainActivity.class);
} else {
SettingsRepository.signOut(this.getApplicationContext()); // Delete old data
startActivity(new Intent(LauncherActivity.this, LoginActivity.class));
intent.setClass(LauncherActivity.this, LoginActivity.class);
}

startActivity(intent);
finish();
}
}
Expand Up @@ -27,10 +27,10 @@
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.Callable;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
Expand Down Expand Up @@ -302,9 +302,15 @@ protected void onCreate(Bundle savedInstanceState) {
});

int selectedItem = R.id.item_home;
Serializable launchFragment = this.getIntent().getSerializableExtra("launchFragment");

if (savedInstanceState != null) {
selectedItem = savedInstanceState.getInt("selectedItem");
} else if (launchFragment != null) {
// If the application is launched from notifications
if (AssignmentsFragment.class.equals(launchFragment)) {
selectedItem = R.id.item_assignments;
}
}

this.bottomNavigationView.setSelectedItemId(selectedItem);
Expand All @@ -325,17 +331,17 @@ public void onComplete() {
Check for updates
*/
Context context = this;
Observable.fromCallable((Callable<Integer>) () -> {
try {
StringBuilder sb = new StringBuilder();
URL url = new URL(SettingsRepository.APP_ABOUT_URL + "?v=" + BuildConfig.VERSION_NAME);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream in = httpURLConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(in);
int data = reader.read();

while (data != -1) {
char current = (char) data;
Observable.fromCallable(() -> {
try {
StringBuilder sb = new StringBuilder();
URL url = new URL(SettingsRepository.APP_ABOUT_URL + "?v=" + BuildConfig.VERSION_NAME);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream in = httpURLConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(in);
int data = reader.read();

while (data != -1) {
char current = (char) data;
sb.append(current);
data = reader.read();
}
Expand Down
Expand Up @@ -20,7 +20,8 @@
import java.util.Calendar;

import tk.therealsuji.vtopchennai.R;
import tk.therealsuji.vtopchennai.activities.MainActivity;
import tk.therealsuji.vtopchennai.activities.LauncherActivity;
import tk.therealsuji.vtopchennai.fragments.HomeFragment;
import tk.therealsuji.vtopchennai.models.Timetable;

public class NotificationHelper extends ContextWrapper {
Expand Down Expand Up @@ -97,7 +98,8 @@ public NotificationCompat.Builder notifyUpcoming(Timetable.AllData timetableItem
PendingIntent pendingIntent = PendingIntent.getActivity(
this,
0,
new Intent(this, MainActivity.class),
new Intent(this, LauncherActivity.class)
.putExtra("launchFragment", HomeFragment.class),
PendingIntent.FLAG_IMMUTABLE
);
String title = "Upcoming: " +
Expand Down Expand Up @@ -138,7 +140,8 @@ public NotificationCompat.Builder notifyOngoing(Timetable.AllData timetableItem)
PendingIntent pendingIntent = PendingIntent.getActivity(
this,
0,
new Intent(this, MainActivity.class),
new Intent(this, LauncherActivity.class)
.putExtra("launchFragment", HomeFragment.class),
PendingIntent.FLAG_IMMUTABLE
);
String title = "Ongoing: " +
Expand Down

0 comments on commit 0593482

Please sign in to comment.