use of com.appspot.tbatv_prod_hrd.model.ModelsMobileApiMessagesBaseResponse in project the-blue-alliance-android by the-blue-alliance.
the class TbaSuggestionController method suggest.
/**
* <b>MUST BE CALLED FROM BACKGROUND THREAD</b>
* Uses {@link GceAuthController#getAuthHeader()}
*/
@WorkerThread
public void suggest(String teamKey, int year, String link, String deletehash) {
String authHeader = mGceAuthController.getAuthHeader();
ModelsMobileApiMessagesMediaSuggestionMessage message = buildSuggestionMessage(teamKey, year, link, deletehash);
Call<ModelsMobileApiMessagesBaseResponse> request = mTeamMediaApi.suggestion(authHeader, message);
request.enqueue(new Callback<ModelsMobileApiMessagesBaseResponse>() {
@Override
public void onResponse(Call<ModelsMobileApiMessagesBaseResponse> call, Response<ModelsMobileApiMessagesBaseResponse> response) {
// TODO stuff
}
@Override
public void onFailure(Call<ModelsMobileApiMessagesBaseResponse> call, Throwable t) {
// TODO stuff
}
});
}
use of com.appspot.tbatv_prod_hrd.model.ModelsMobileApiMessagesBaseResponse in project the-blue-alliance-android by the-blue-alliance.
the class MyTbaDatafeed method unregister.
@WorkerThread
public boolean unregister() {
TbaLogger.d("Unregistering for GCM");
if (!ConnectionDetector.isConnectedToInternet(mApplicationContext)) {
return false;
}
String authHeader = mAuthController.getAuthHeader();
ModelsMobileApiMessagesRegistrationRequest request = new ModelsMobileApiMessagesRegistrationRequest();
request.mobile_id = mGcmController.getRegistrationId();
request.operating_system = GcmController.OS_ANDROID;
request.device_uuid = Utilities.getDeviceUUID(mApplicationContext);
Response<ModelsMobileApiMessagesBaseResponse> response = null;
try {
response = mTbaMobile.unregister(authHeader, request).execute();
} catch (IOException e) {
e.printStackTrace();
}
return (response != null && (response.code() == 200 || response.code() == 304));
}
use of com.appspot.tbatv_prod_hrd.model.ModelsMobileApiMessagesBaseResponse in project the-blue-alliance-android by the-blue-alliance.
the class ImgurSuggestionService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
TbaLogger.d("IMGUR SERVICE START");
String filepath = intent.getStringExtra(EXTRA_FILEPATH);
String title = intent.getStringExtra(EXTRA_TITLE);
String description = intent.getStringExtra(EXTRA_DESCRIPTION);
String teamKey = intent.getStringExtra(EXTRA_TEAMKEY);
int year = intent.getIntExtra(EXTRA_YEAR, 0);
ImgurUploadNotification notification = new ImgurUploadNotification(getApplicationContext());
notification.onUploadStarting();
boolean successful = true;
// Get a wake lock so any long uploads will not be interrupted
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
wakeLock.acquire();
// TODO should we catch each exception individually and handle them better (e.g. retyr?)
try {
String authToken = getAuthHeader();
File file = new File(filepath);
RequestBody body = RequestBody.create(MediaType.parse("multipart/form-data"), file);
RequestBody titlePart = RequestBody.create(MediaType.parse("text/plain"), title);
RequestBody descPart = RequestBody.create(MediaType.parse("text/plain"), description);
Response<UploadResponse> response = mImgurApi.uploadImage(authToken, titlePart, descPart, body).execute();
if (response != null && response.isSuccessful()) {
UploadResponse uploadResponse = response.body();
TbaLogger.d("Uploaded imgur image: " + uploadResponse.data.link);
String link = uploadResponse.data.link;
String deletehash = uploadResponse.data.deletehash;
TbaLogger.d("Imgur link: " + link);
// Do suggestion
String authHeader = mGceAuthController.getAuthHeader();
ModelsMobileApiMessagesMediaSuggestionMessage message = buildSuggestionMessage(teamKey, year, link, deletehash);
Response<ModelsMobileApiMessagesBaseResponse> suggestionResponse = mTeamMediaApi.suggestion(authHeader, message).execute();
if (suggestionResponse != null && suggestionResponse.isSuccessful()) {
// Yay, everything worked!
} else {
// Crap
// TODO handle this
successful = false;
}
} else {
TbaLogger.e("Error uploading imgur image\n" + response.code() + " " + response.message());
successful = false;
}
} catch (Exception e) {
// Something broke
successful = false;
e.printStackTrace();
} finally {
if (successful) {
notification.onUploadSuccess();
} else {
notification.onUploadFailure();
}
// Delete the temp cached image
new File(filepath).delete();
wakeLock.release();
}
}
use of com.appspot.tbatv_prod_hrd.model.ModelsMobileApiMessagesBaseResponse in project the-blue-alliance-android by the-blue-alliance.
the class MyTbaDatafeed method updateModelSettings.
@WorkerThread
@ModelPrefsResult
public int updateModelSettings(ModelNotificationFavoriteSettings settings) {
String modelKey = settings.modelKey;
List<String> notifications = settings.enabledNotifications;
boolean isFavorite = settings.isFavorite;
String user = mAccountController.getSelectedAccount();
String key = MyTBAHelper.createKey(user, modelKey);
ModelType modelType = settings.modelType;
ModelsMobileApiMessagesModelPreferenceMessage request = new ModelsMobileApiMessagesModelPreferenceMessage();
request.model_key = modelKey;
request.device_key = mGcmController.getRegistrationId();
request.notifications = notifications;
request.favorite = isFavorite;
request.model_type = modelType.getEnum();
SubscriptionsTable subscriptionsTable = mDb.getSubscriptionsTable();
FavoritesTable favoritesTable = mDb.getFavoritesTable();
// Determine if we have to do anything
List<String> existingNotificationsList = new ArrayList<>();
Subscription existingSubscription = subscriptionsTable.get(key);
if (existingSubscription != null) {
existingNotificationsList = existingSubscription.getNotificationList();
}
Collections.sort(notifications);
Collections.sort(existingNotificationsList);
TbaLogger.d("New notifications: " + notifications.toString());
TbaLogger.d("Existing notifications: " + existingNotificationsList.toString());
boolean notificationsHaveChanged = !(notifications.equals(existingNotificationsList));
// and if the existing notification mSettings equal the new ones, do nothing.
if (((isFavorite && favoritesTable.exists(key)) || (!isFavorite && !favoritesTable.exists(key))) && !notificationsHaveChanged) {
// nothing has changed, no-op
return MODEL_PREF_NOOP;
} else {
try {
String authHeader = mAuthController.getAuthHeader();
Response<ModelsMobileApiMessagesBaseResponse> response = mModelApi.setPreferences(authHeader, request).execute();
if (response == null) {
TbaLogger.w("Null response for mytba update");
return MODEL_PREF_FAIL;
}
if (!response.isSuccessful()) {
TbaLogger.w("mytba update error " + response.code() + ": " + response.message());
return MODEL_PREF_FAIL;
}
ModelsMobileApiMessagesBaseResponse prefResponse = response.body();
TbaLogger.d("Mytba result: " + prefResponse.code + "/" + prefResponse.message);
if (response.code() == 401 || prefResponse.code == 401) {
TbaLogger.e(prefResponse.message);
return MODEL_PREF_FAIL;
}
JsonObject responseJson = JSONHelper.getasJsonObject(prefResponse.message);
if (responseJson == null || responseJson.isJsonNull()) {
return MODEL_PREF_FAIL;
}
JsonObject fav = responseJson.get("favorite").getAsJsonObject(), sub = responseJson.get("subscription").getAsJsonObject();
int favCode = fav.get("code").getAsInt(), subCode = sub.get("code").getAsInt();
if (subCode == 200) {
// Request was successful, update the local databases
if (notifications.isEmpty()) {
subscriptionsTable.remove(key);
} else if (subscriptionsTable.exists(key)) {
subscriptionsTable.update(key, new Subscription(user, modelKey, notifications, modelType.getEnum()));
} else {
subscriptionsTable.add(new Subscription(user, modelKey, notifications, modelType.getEnum()));
}
} else if (subCode == 500) {
Toast.makeText(mApplicationContext, mApplicationContext.getString(R.string.mytba_error, subCode, sub.get("message").getAsString()), Toast.LENGTH_SHORT).show();
}
if (favCode == 200) {
if (!isFavorite) {
favoritesTable.remove(key);
} else if (!favoritesTable.exists(key)) {
favoritesTable.add(new Favorite(user, modelKey, modelType.getEnum()));
}
} else if (favCode == 500) {
Toast.makeText(mApplicationContext, mApplicationContext.getString(R.string.mytba_error, favCode, fav.get("message").getAsString()), Toast.LENGTH_SHORT).show();
}
return MODEL_PREF_SUCCESS;
} catch (IOException e) {
TbaLogger.e("IO Exception while updating model preferences!", e);
e.printStackTrace();
return MODEL_PREF_FAIL;
}
}
}
use of com.appspot.tbatv_prod_hrd.model.ModelsMobileApiMessagesBaseResponse in project the-blue-alliance-android by the-blue-alliance.
the class MyTbaDatafeed method register.
@WorkerThread
public boolean register(String regId) {
TbaLogger.d("Registering for GCM");
if (!ConnectionDetector.isConnectedToInternet(mApplicationContext)) {
return false;
}
String authHeader = mAuthController.getAuthHeader();
ModelsMobileApiMessagesRegistrationRequest request = new ModelsMobileApiMessagesRegistrationRequest();
request.mobile_id = regId;
request.operating_system = GcmController.OS_ANDROID;
request.device_uuid = Utilities.getDeviceUUID(mApplicationContext);
if (BuildConfig.DEBUG) {
request.name = android.os.Build.MODEL + " (Debug)";
} else {
request.name = android.os.Build.MODEL;
}
Response<ModelsMobileApiMessagesBaseResponse> response = null;
try {
response = mTbaMobile.register(authHeader, request).execute();
TbaLogger.d("MyTBA Registration response: " + response);
} catch (IOException e) {
e.printStackTrace();
}
return (response != null && (response.code() == 200 || response.code() == 304));
}
Aggregations