Search in sources :

Example 1 with SessionManager

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();
            }
        }
    });
}
Also used : LoginActivity(app.insti.activity.LoginActivity) SessionManager(app.insti.SessionManager) Intent(android.content.Intent) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 2 with SessionManager

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);
    }
}
Also used : SessionManager(app.insti.SessionManager) ProgressDialog(android.app.ProgressDialog)

Example 3 with SessionManager

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();
}
Also used : SharedPreferences(android.content.SharedPreferences) ServiceGenerator(app.insti.api.ServiceGenerator) SessionManager(app.insti.SessionManager) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Intent(android.content.Intent) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) FeedFragment(app.insti.fragment.FeedFragment) Toolbar(androidx.appcompat.widget.Toolbar) SuppressLint(android.annotation.SuppressLint)

Example 4 with SessionManager

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);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) SwitchPreferenceCompat(androidx.preference.SwitchPreferenceCompat) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) SessionManager(app.insti.SessionManager) ListPreference(androidx.preference.ListPreference)

Example 5 with SessionManager

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);
    }
}
Also used : RemoteViews(android.widget.RemoteViews) SessionManager(app.insti.SessionManager) ServiceGenerator(app.insti.api.ServiceGenerator) List(java.util.List) RetrofitInterface(app.insti.api.RetrofitInterface)

Aggregations

SessionManager (app.insti.SessionManager)5 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 RetrofitInterface (app.insti.api.RetrofitInterface)2 ServiceGenerator (app.insti.api.ServiceGenerator)2 SuppressLint (android.annotation.SuppressLint)1 ProgressDialog (android.app.ProgressDialog)1 RemoteViews (android.widget.RemoteViews)1 ActionBarDrawerToggle (androidx.appcompat.app.ActionBarDrawerToggle)1 Toolbar (androidx.appcompat.widget.Toolbar)1 DrawerLayout (androidx.drawerlayout.widget.DrawerLayout)1 ListPreference (androidx.preference.ListPreference)1 Preference (androidx.preference.Preference)1 SwitchPreferenceCompat (androidx.preference.SwitchPreferenceCompat)1 LoginActivity (app.insti.activity.LoginActivity)1 FeedFragment (app.insti.fragment.FeedFragment)1 List (java.util.List)1