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());
}
}
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");
}
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();
}
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);
}
}
Aggregations