use of app.insti.SessionManager in project IITB-App by wncc.
the class SettingsFragment method logout.
private void logout() {
final SessionManager sessionManager = new SessionManager(getContext());
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.logout(Utils.getSessionIDHeader()).enqueue(new EmptyCallback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) {
sessionManager.logout();
Utils.clearCookies(getActivity());
Intent intent = new Intent(getContext(), LoginActivity.class);
startActivity(intent);
getActivity().finish();
}
}
});
}
use of app.insti.SessionManager in project IITB-App by wncc.
the class LoginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
session = new SessionManager(mContext);
if (session.isLoggedIn()) {
openMainActivity();
} else {
setContentView(R.layout.activity_login);
progressDialog = new ProgressDialog(LoginActivity.this);
}
}
use of app.insti.SessionManager in project IITB-App by wncc.
the class MainActivity method onCreate.
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* Check for dark theme */
SharedPreferences sharedPref = getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
Utils.isDarkTheme = sharedPref.getBoolean(Constants.DARK_THEME, false);
if (Utils.isDarkTheme)
this.setTheme(R.style.AppThemeDark);
ServiceGenerator serviceGenerator = new ServiceGenerator(getApplicationContext());
Utils.setRetrofitInterface(serviceGenerator.getRetrofitInterface());
Utils.makeGson();
Utils.makeMarkwon(getApplicationContext());
/* Make notification channel on oreo */
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
createNotificationChannel();
}
setContentView(R.layout.activity_main);
session = new SessionManager(getApplicationContext());
if (session.isLoggedIn()) {
Utils.setSessionId(session.getSessionID());
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
feedFragment = new FeedFragment();
updateFragment(feedFragment);
Intent intent = getIntent();
if (intent != null) {
// 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 {
handleIntent(intent);
}
}
checkLatestVersion();
}
use of app.insti.SessionManager in project IITB-App by wncc.
the class SettingsFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences, rootKey);
// Get preferences and editor
SharedPreferences sharedPref = getActivity().getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
editor = sharedPref.edit();
// Show contact number
showContactPref = (SwitchPreferenceCompat) findPreference("show_contact");
showContactPref.setOnPreferenceChangeListener((preference, option) -> {
toggleShowContact((SwitchPreferenceCompat) preference, option);
return false;
});
showContactPref.setEnabled(false);
// Dark Theme
SwitchPreferenceCompat darkThemePref = (SwitchPreferenceCompat) findPreference("dark_theme");
darkThemePref.setOnPreferenceChangeListener((preference, option) -> {
toggleDarkTheme((boolean) option);
return true;
});
darkThemePref.setChecked(sharedPref.getBoolean(Constants.DARK_THEME, false));
// Add to Calendar
ListPreference calendarPref = (ListPreference) findPreference("add_to_calendar");
calendarPref.setOnPreferenceChangeListener((preference, option) -> {
toggleCalendarDialog((String) option);
return true;
});
calendarPref.setValue(sharedPref.getString(Constants.CALENDAR_DIALOG, Constants.CALENDAR_DIALOG_ALWAYS_ASK));
// Update Profile
Preference profilePref = findPreference("profile");
profilePref.setOnPreferenceClickListener(preference -> {
openWebURL("https://gymkhana.iitb.ac.in/sso/user");
return false;
});
// Feedback
Preference feedbackPref = findPreference("feedback");
feedbackPref.setOnPreferenceClickListener(preference -> {
openWebURL("https://www.insti.app/feedback");
return false;
});
// About
Preference aboutPref = findPreference("about");
aboutPref.setOnPreferenceClickListener(preference -> {
openAbout();
return false;
});
// Logout
Preference logoutPref = findPreference("logout");
logoutPref.setOnPreferenceClickListener(preference -> {
logout();
return false;
});
// Disable buttons if not logged in
final SessionManager sessionManager = new SessionManager(getContext());
if (!sessionManager.isLoggedIn()) {
showContactPref.setVisible(false);
logoutPref.setVisible(false);
}
}
use of app.insti.SessionManager in project IITB-App by wncc.
the class MessMenuWidget method updateAppWidget.
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
// Construct the RemoteViews object
views = new RemoteViews(context.getPackageName(), R.layout.mess_menu_widget);
SessionManager sessionManager = new SessionManager(context);
if (sessionManager.isLoggedIn()) {
ServiceGenerator serviceGenerator = new ServiceGenerator(context);
RetrofitInterface retrofitInterface = serviceGenerator.getRetrofitInterface();
retrofitInterface.getInstituteMessMenu(sessionManager.getSessionID()).enqueue(new Callback<List<HostelMessMenu>>() {
@Override
public void onResponse(Call<List<HostelMessMenu>> call, Response<List<HostelMessMenu>> response) {
if (response.isSuccessful()) {
instituteMessMenu = response.body();
displayMenu(sessionManager.getCurrentUser().getHostel());
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
@Override
public void onFailure(Call<List<HostelMessMenu>> call, Throwable t) {
// Network error
}
});
} else {
views.setTextViewText(R.id.meal_text_view, "Login to see your mess menu");
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
Aggregations