use of com.appspot.tbatv_prod_hrd.model.ModelsMobileApiMessagesSubscriptionCollection in project the-blue-alliance-android by the-blue-alliance.
the class MyTbaDatafeed method updateUserSubscriptions.
@WorkerThread
public void updateUserSubscriptions() {
String currentUser = mAccountController.getSelectedAccount();
String prefString = String.format(LAST_SUBSCRIPTIONS_UPDATE, currentUser);
Date now = new Date();
Date futureTime = new Date(mPrefs.getLong(prefString, 0) + Constants.MY_TBA_UPDATE_TIMEOUT);
if (now.before(futureTime)) {
TbaLogger.d("Not updating myTBA subscriptions. Too soon since last update");
return;
}
if (!ConnectionDetector.isConnectedToInternet(mApplicationContext)) {
return;
}
TbaLogger.d("Updating myTBA subscriptions");
if (!mAccountController.isMyTbaEnabled()) {
TbaLogger.e("MyTBA is not enabled");
Handler mainHandler = new Handler(mApplicationContext.getMainLooper());
mainHandler.post(() -> Toast.makeText(mApplicationContext, mRes.getString(R.string.mytba_error_no_account), Toast.LENGTH_SHORT).show());
return;
}
String authHeader = mAuthController.getAuthHeader();
Response<ModelsMobileApiMessagesSubscriptionCollection> subscriptionResponse;
try {
subscriptionResponse = mSubscriptionApi.list(authHeader).execute();
} catch (IOException e) {
TbaLogger.w("Unable to update myTBA favorites");
e.printStackTrace();
return;
}
List<Subscription> subscriptionModels = new ArrayList<>();
if (subscriptionResponse != null) {
try {
ModelsMobileApiMessagesSubscriptionCollection subscriptionCollection = subscriptionResponse.body();
if (subscriptionCollection != null && subscriptionCollection.subscriptions != null) {
SubscriptionsTable subscriptions = mDb.getSubscriptionsTable();
subscriptions.recreate(currentUser);
for (int i = 0; i < subscriptionCollection.subscriptions.size(); i++) {
ModelsMobileApiMessagesSubscriptionMessage s = subscriptionCollection.subscriptions.get(i);
subscriptionModels.add(new Subscription(currentUser, s.model_key, s.notifications, s.model_type));
}
subscriptions.add(subscriptionModels);
TbaLogger.d("Added " + subscriptionModels.size() + " subscriptions");
}
mPrefs.edit().putLong(prefString, now.getTime()).apply();
} catch (Exception ex) {
if (ex instanceof SQLiteDatabaseLockedException) {
TbaLogger.i("Database locked: " + ex.getMessage());
} else {
TbaLogger.e("Unable to update mytba subscriptions", ex);
}
}
}
}
Aggregations