Search in sources :

Example 1 with ServiceGenerator

use of app.insti.api.ServiceGenerator in project IITB-App by wncc.

the class NotificationBroadcastReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Constants.NOTIF_CANCELLED)) {
        // Get the notification id
        String id = intent.getExtras().getString(Constants.FCM_BUNDLE_NOTIFICATION_ID);
        if (id == null || id.equals(""))
            return;
        // Get retrofit and session id
        ServiceGenerator serviceGenerator = new ServiceGenerator(context);
        RetrofitInterface retrofitInterface = serviceGenerator.getRetrofitInterface();
        SessionManager session = new SessionManager(context);
        if (session.isLoggedIn()) {
            Utils.setSessionId(session.getSessionID());
        }
        // Mark as read
        retrofitInterface.markNotificationDeleted(Utils.getSessionIDHeader(), id).enqueue(new EmptyCallback<Void>());
        // Reduce current count
        ShortcutBadger.applyCount(context.getApplicationContext(), NotificationId.decrementAndGetCurrentCount());
    }
}
Also used : ServiceGenerator(app.insti.api.ServiceGenerator) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 2 with ServiceGenerator

use of app.insti.api.ServiceGenerator in project IITB-App by wncc.

the class LoginActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    // Initialize
    ServiceGenerator serviceGenerator = new ServiceGenerator(getApplicationContext());
    this.retrofitInterface = serviceGenerator.getRetrofitInterface();
    // Get FCM Id
    FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {

        @Override
        public void onSuccess(InstanceIdResult instanceIdResult) {
            fcmId = instanceIdResult.getToken();
        }
    });
    // Login if intent is present
    String action = getIntent().getAction();
    String data = getIntent().getDataString();
    if (Intent.ACTION_VIEW.equals(action) && data != null) {
        Uri query = Uri.parse(data);
        authCode = query.getQueryParameter("code");
        if (authCode != null) {
            /* Show progress dialog */
            progressDialog.setMessage("Logging In");
            progressDialog.setCancelable(false);
            progressDialog.setIndeterminate(true);
            if (!progressDialog.isShowing()) {
                progressDialog.show();
            }
            /* Perform the login */
            login(authCode, redirectUri);
        } else {
            Toast.makeText(this, "Login Failed!", Toast.LENGTH_SHORT).show();
        }
    }
    // Setup web view placeholder
    WebView webview = findViewById(R.id.login_webview);
    webview.setWebViewClient(new WvClient());
    webview.loadUrl("file:///android_asset/login.html");
}
Also used : ServiceGenerator(app.insti.api.ServiceGenerator) WebView(android.webkit.WebView) Uri(android.net.Uri) InstanceIdResult(com.google.firebase.iid.InstanceIdResult)

Example 3 with ServiceGenerator

use of app.insti.api.ServiceGenerator 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 ServiceGenerator

use of app.insti.api.ServiceGenerator 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

ServiceGenerator (app.insti.api.ServiceGenerator)4 SessionManager (app.insti.SessionManager)2 RetrofitInterface (app.insti.api.RetrofitInterface)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 WebView (android.webkit.WebView)1 RemoteViews (android.widget.RemoteViews)1 ActionBarDrawerToggle (androidx.appcompat.app.ActionBarDrawerToggle)1 Toolbar (androidx.appcompat.widget.Toolbar)1 DrawerLayout (androidx.drawerlayout.widget.DrawerLayout)1 FeedFragment (app.insti.fragment.FeedFragment)1 InstanceIdResult (com.google.firebase.iid.InstanceIdResult)1 List (java.util.List)1