Browse Source

patrol certain error strings

renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
fbb5c244ae
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 5
      app/src/main/java/awais/instagrabber/dialogs/GifPickerBottomDialogFragment.java
  2. 3
      app/src/main/java/awais/instagrabber/fragments/UserSearchFragment.java
  3. 3
      app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageInboxFragment.java
  4. 15
      app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java
  5. 9
      app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java
  6. 10
      app/src/main/java/awais/instagrabber/managers/InboxManager.java
  7. 31
      app/src/main/java/awais/instagrabber/managers/ThreadManager.java
  8. 16
      app/src/main/java/awais/instagrabber/models/Resource.java
  9. 5
      app/src/main/java/awais/instagrabber/viewmodels/GifPickerViewModel.java
  10. 7
      app/src/main/java/awais/instagrabber/viewmodels/UserSearchViewModel.java
  11. 7
      app/src/main/res/values/strings.xml

5
app/src/main/java/awais/instagrabber/dialogs/GifPickerBottomDialogFragment.java

@ -131,7 +131,10 @@ public class GifPickerBottomDialogFragment extends BottomSheetDialogFragment {
case ERROR:
final Context context = getContext();
if (context != null && imagesResource.message != null) {
Snackbar.make(context, binding.getRoot(), imagesResource.message, Snackbar.LENGTH_LONG);
Snackbar.make(context, binding.getRoot(), imagesResource.message, Snackbar.LENGTH_LONG).show();
}
if (context != null && imagesResource.resId != 0) {
Snackbar.make(context, binding.getRoot(), getString(imagesResource.resId), Snackbar.LENGTH_LONG).show();
}
break;
case LOADING:

3
app/src/main/java/awais/instagrabber/fragments/UserSearchFragment.java

@ -204,6 +204,9 @@ public class UserSearchFragment extends Fragment {
if (results.message != null) {
Snackbar.make(binding.getRoot(), results.message, Snackbar.LENGTH_LONG).show();
}
if (results.resId != 0) {
Snackbar.make(binding.getRoot(), results.resId, Snackbar.LENGTH_LONG).show();
}
if (results.data != null) {
resultsAdapter.submitList(results.data);
}

3
app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageInboxFragment.java

@ -193,6 +193,9 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
if (inboxResource.message != null) {
Snackbar.make(binding.getRoot(), inboxResource.message, Snackbar.LENGTH_LONG).show();
}
if (inboxResource.resId != 0) {
Snackbar.make(binding.getRoot(), inboxResource.resId, Snackbar.LENGTH_LONG).show();
}
binding.swipeRefreshLayout.setRefreshing(false);
break;
case LOADING:

15
app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java

@ -329,6 +329,9 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
if (resource.message != null) {
Snackbar.make(binding.getRoot(), resource.message, Snackbar.LENGTH_LONG).show();
}
if (resource.resId != 0) {
Snackbar.make(binding.getRoot(), resource.resId, Snackbar.LENGTH_LONG).show();
}
break;
case LOADING:
buttonView.setEnabled(false);
@ -427,6 +430,9 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
if (resource.message != null) {
Snackbar.make(binding.getRoot(), resource.message, Snackbar.LENGTH_LONG).show();
}
if (resource.resId != 0) {
Snackbar.make(binding.getRoot(), resource.resId, Snackbar.LENGTH_LONG).show();
}
break;
}
});
@ -450,6 +456,9 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
if (resource.message != null) {
Snackbar.make(binding.getRoot(), resource.message, Snackbar.LENGTH_LONG).show();
}
if (resource.resId != 0) {
Snackbar.make(binding.getRoot(), resource.resId, Snackbar.LENGTH_LONG).show();
}
break;
}
pendingUsersAdapter.notifyItemChanged(position);
@ -477,6 +486,9 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
if (resource.message != null) {
Snackbar.make(binding.getRoot(), resource.message, Snackbar.LENGTH_LONG).show();
}
if (resource.resId != 0) {
Snackbar.make(binding.getRoot(), resource.resId, Snackbar.LENGTH_LONG).show();
}
break;
case LOADING:
binding.leave.setEnabled(false);
@ -497,6 +509,9 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
if (resource.message != null) {
Snackbar.make(binding.getRoot(), resource.message, Snackbar.LENGTH_LONG).show();
}
if (resource.resId != 0) {
Snackbar.make(binding.getRoot(), resource.resId, Snackbar.LENGTH_LONG).show();
}
break;
case LOADING:
binding.end.setEnabled(false);

9
app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java

@ -612,6 +612,9 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
if (fetchingResource.message != null) {
Snackbar.make(binding.getRoot(), fetchingResource.message, Snackbar.LENGTH_LONG).show();
}
if (fetchingResource.resId != 0) {
Snackbar.make(binding.getRoot(), fetchingResource.resId, Snackbar.LENGTH_LONG).show();
}
break;
case LOADING:
setTitle(getString(R.string.dms_thread_updating));
@ -750,6 +753,9 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
if (resource.message != null) {
Snackbar.make(binding.getRoot(), resource.message, Snackbar.LENGTH_LONG).show();
}
if (resource.resId != 0) {
Snackbar.make(binding.getRoot(), resource.resId, Snackbar.LENGTH_LONG).show();
}
resourceLiveData.removeObservers(getViewLifecycleOwner());
break;
}
@ -1141,6 +1147,9 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
if (resource.message != null) {
Snackbar.make(binding.getRoot(), resource.message, Snackbar.LENGTH_LONG).show();
}
if (resource.resId != 0) {
Snackbar.make(binding.getRoot(), resource.resId, Snackbar.LENGTH_LONG).show();
}
resourceLiveData.removeObservers(getViewLifecycleOwner());
break;
}

10
app/src/main/java/awais/instagrabber/managers/InboxManager.java

@ -21,6 +21,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import awais.instagrabber.R;
import awais.instagrabber.models.Resource;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectBadgeCount;
@ -156,7 +157,7 @@ public final class InboxManager {
final DirectBadgeCount directBadgeCount = response.body();
if (directBadgeCount == null) {
Log.e(TAG, "onResponse: directBadgeCount Response is null");
unseenCount.postValue(Resource.error("Unseen count response is null", getCurrentUnseenCount()));
unseenCount.postValue(Resource.error(R.string.dms_inbox_error_null_count, getCurrentUnseenCount()));
return;
}
unseenCount.postValue(Resource.success(directBadgeCount.getBadgeCount()));
@ -188,14 +189,13 @@ public final class InboxManager {
private void parseInboxResponse(final DirectInboxResponse response) {
if (response == null) {
Log.e(TAG, "parseInboxResponse: Response is null");
inbox.postValue(Resource.error("Response is null", getCurrentDirectInbox()));
inbox.postValue(Resource.error(R.string.generic_null_response, getCurrentDirectInbox()));
hasOlder = false;
return;
}
if (!response.getStatus().equals("ok")) {
final String msg = "DM inbox fetch response: status not ok";
Log.e(TAG, msg);
inbox.postValue(Resource.error(msg, getCurrentDirectInbox()));
Log.e(TAG, "DM inbox fetch response: status not ok");
inbox.postValue(Resource.error(R.string.generic_not_ok_response, getCurrentDirectInbox()));
hasOlder = false;
return;
}

31
app/src/main/java/awais/instagrabber/managers/ThreadManager.java

@ -32,6 +32,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import awais.instagrabber.R;
import awais.instagrabber.customviews.emoji.Emoji;
import awais.instagrabber.models.Resource;
import awais.instagrabber.models.Resource.Status;
@ -83,10 +84,6 @@ import static awais.instagrabber.utils.Utils.settingsHelper;
public final class ThreadManager {
private static final String TAG = ThreadManager.class.getSimpleName();
private static final Object LOCK = new Object();
private static final String ERROR_INVALID_USER = "Invalid user";
private static final String ERROR_RESPONSE_NOT_OK = "Response status from server was not ok";
private static final String ERROR_VIDEO_TOO_LONG = "Instagram does not allow uploading videos longer than 60 secs for Direct messages";
private static final String ERROR_AUDIO_TOO_LONG = "Instagram does not allow uploading audio longer than 60 secs";
private static final Map<String, ThreadManager> INSTANCE_MAP = new ConcurrentHashMap<>();
private final MutableLiveData<Resource<Object>> fetching = new MutableLiveData<>();
@ -363,12 +360,12 @@ public final class ThreadManager {
public void onResponse(@NonNull final Call<DirectThreadFeedResponse> call, @NonNull final Response<DirectThreadFeedResponse> response) {
final DirectThreadFeedResponse feedResponse = response.body();
if (feedResponse == null) {
fetching.postValue(Resource.error("response was null!", null));
fetching.postValue(Resource.error(R.string.generic_null_response, null));
Log.e(TAG, "onResponse: response was null!");
return;
}
if (!feedResponse.getStatus().equals("ok")) {
fetching.postValue(Resource.error("response was not ok", null));
fetching.postValue(Resource.error(R.string.generic_not_ok_response, null));
return;
}
final DirectThread thread = feedResponse.getThread();
@ -674,7 +671,7 @@ public final class ThreadManager {
final long byteLength) {
if (duration > 60000) {
// instagram does not allow uploading audio longer than 60 secs for Direct messages
data.postValue(Resource.error(ERROR_AUDIO_TOO_LONG, null));
data.postValue(Resource.error(R.string.dms_ERROR_AUDIO_TOO_LONG, null));
return;
}
final Long userId = getCurrentUserId(data);
@ -794,7 +791,7 @@ public final class ThreadManager {
handleErrorBody(call, response, data);
return;
}
data.postValue(Resource.error("request was not successful and response error body was null", item));
data.postValue(Resource.error(R.string.generic_failed_request, item));
}
@Override
@ -1056,7 +1053,7 @@ public final class ThreadManager {
final int height) {
if (duration > 60000) {
// instagram does not allow uploading videos longer than 60 secs for Direct messages
data.postValue(Resource.error(ERROR_VIDEO_TOO_LONG, null));
data.postValue(Resource.error(R.string.dms_ERROR_VIDEO_TOO_LONG, null));
return;
}
final Long userId = getCurrentUserId(data);
@ -1125,7 +1122,7 @@ public final class ThreadManager {
if (response.isSuccessful()) {
final DirectThreadBroadcastResponse broadcastResponse = response.body();
if (broadcastResponse == null) {
data.postValue(Resource.error("Response was null from server", directItem));
data.postValue(Resource.error(R.string.generic_null_response, directItem));
Log.e(TAG, "enqueueRequest: onResponse: response body is null");
return;
}
@ -1155,7 +1152,7 @@ public final class ThreadManager {
if (response.errorBody() != null) {
handleErrorBody(call, response, data);
}
data.postValue(Resource.error("request was not successful and response error body was null", directItem));
data.postValue(Resource.error(R.string.generic_failed_request, directItem));
}
@Override
@ -1215,12 +1212,12 @@ public final class ThreadManager {
@NonNull final MediaUploader.MediaUploadResponse response) {
final JSONObject responseJson = response.getResponse();
if (responseJson == null || response.getResponseCode() != HttpURLConnection.HTTP_OK) {
data.postValue(Resource.error(ERROR_RESPONSE_NOT_OK, null));
data.postValue(Resource.error(R.string.generic_not_ok_response, null));
return true;
}
final String status = responseJson.optString("status");
if (TextUtils.isEmpty(status) || !status.equals("ok")) {
data.postValue(Resource.error(ERROR_RESPONSE_NOT_OK, null));
data.postValue(Resource.error(R.string.generic_not_ok_response, null));
return true;
}
return false;
@ -1253,12 +1250,12 @@ public final class ThreadManager {
handleErrorBody(call, response, data);
return;
}
data.postValue(Resource.error("request was not successful and response error body was null", item));
data.postValue(Resource.error(R.string.generic_failed_request, item));
return;
}
final DirectThreadBroadcastResponse body = response.body();
if (body == null) {
data.postValue(Resource.error("Response is null!", item));
data.postValue(Resource.error(R.string.generic_null_response, item));
}
// otherwise nothing to do? maybe update the timestamp in the emoji?
}
@ -1282,7 +1279,7 @@ public final class ThreadManager {
@Nullable
private Long getCurrentUserId(final MutableLiveData<Resource<Object>> data) {
if (currentUser == null || currentUser.getPk() <= 0) {
data.postValue(Resource.error(ERROR_INVALID_USER, null));
data.postValue(Resource.error(R.string.dms_ERROR_INVALID_USER, null));
return null;
}
return currentUser.getPk();
@ -1777,7 +1774,7 @@ public final class ThreadManager {
}
final DirectThreadDetailsChangeResponse changeResponse = response.body();
if (changeResponse == null) {
data.postValue(Resource.error("Response is null", null));
data.postValue(Resource.error(R.string.generic_null_response, null));
return;
}
data.postValue(Resource.success(new Object()));

16
app/src/main/java/awais/instagrabber/models/Resource.java

@ -9,28 +9,36 @@ public class Resource<T> {
public final Status status;
public final T data;
public final String message;
public final int resId;
private Resource(@NonNull Status status,
@Nullable T data,
@Nullable String message) {
@Nullable String message,
int resId) {
this.status = status;
this.data = data;
this.message = message;
this.resId = resId;
}
@NonNull
public static <T> Resource<T> success(@NonNull T data) {
return new Resource<>(Status.SUCCESS, data, null);
return new Resource<>(Status.SUCCESS, data, null, 0);
}
@NonNull
public static <T> Resource<T> error(String msg, @Nullable T data) {
return new Resource<>(Status.ERROR, data, msg);
return new Resource<>(Status.ERROR, data, msg, 0);
}
@NonNull
public static <T> Resource<T> error(int resId, @Nullable T data) {
return new Resource<>(Status.ERROR, data, null, resId);
}
@NonNull
public static <T> Resource<T> loading(@Nullable T data) {
return new Resource<>(Status.LOADING, data, null);
return new Resource<>(Status.LOADING, data, null, 0);
}
@Override

5
app/src/main/java/awais/instagrabber/viewmodels/GifPickerViewModel.java

@ -14,6 +14,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import awais.instagrabber.R;
import awais.instagrabber.models.Resource;
import awais.instagrabber.repositories.responses.giphy.GiphyGif;
import awais.instagrabber.repositories.responses.giphy.GiphyGifResponse;
@ -70,7 +71,7 @@ public class GifPickerViewModel extends ViewModel {
Log.e(TAG, "onResponse: ", e);
}
}
images.postValue(Resource.error("request was not successful and response error body was null", getCurrentImages()));
images.postValue(Resource.error(R.string.generic_failed_request, getCurrentImages()));
}
@Override
@ -85,7 +86,7 @@ public class GifPickerViewModel extends ViewModel {
private void parseResponse(final Response<GiphyGifResponse> response) {
final GiphyGifResponse giphyGifResponse = response.body();
if (giphyGifResponse == null) {
images.postValue(Resource.error("Response body was null", getCurrentImages()));
images.postValue(Resource.error(R.string.generic_null_response, getCurrentImages()));
return;
}
final GiphyGifResults results = giphyGifResponse.getResults();

7
app/src/main/java/awais/instagrabber/viewmodels/UserSearchViewModel.java

@ -20,6 +20,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import awais.instagrabber.R;
import awais.instagrabber.fragments.UserSearchFragment;
import awais.instagrabber.models.Resource;
import awais.instagrabber.repositories.responses.User;
@ -205,7 +206,7 @@ public class UserSearchViewModel extends ViewModel {
}
final RankedRecipientsResponse rankedRecipientsResponse = response.body();
if (rankedRecipientsResponse == null) {
recipients.postValue(Resource.error("Response is null!", getCachedRecipients()));
recipients.postValue(Resource.error(R.string.generic_null_response, getCachedRecipients()));
searchRequest = null;
return;
}
@ -234,7 +235,7 @@ public class UserSearchViewModel extends ViewModel {
}
final UserSearchResponse userSearchResponse = response.body();
if (userSearchResponse == null) {
recipients.postValue(Resource.error("Response is null!", getCachedRecipients()));
recipients.postValue(Resource.error(R.string.generic_null_response, getCachedRecipients()));
searchRequest = null;
return;
}
@ -286,7 +287,7 @@ public class UserSearchViewModel extends ViewModel {
final ResponseBody errorBody = response.errorBody();
if (errorBody == null) {
if (updateResource) {
recipients.postValue(Resource.error("Request failed!", getCachedRecipients()));
recipients.postValue(Resource.error(R.string.generic_failed_request, getCachedRecipients()));
}
return;
}

7
app/src/main/res/values/strings.xml

@ -211,6 +211,7 @@
<string name="dms_inbox_raven_media_suggested">Suggested</string>
<string name="dms_inbox_raven_media_screenshot">Screenshotted</string>
<string name="dms_inbox_raven_media_cant_deliver">Cannot deliver</string>
<string name="dms_inbox_error_null_count">Unseen count response is null!</string>
<string name="dms_thread_message_hint">Message...</string>
<string name="dms_thread_audio_hint">Press and hold to record audio</string>
<string name="dms_thread_updating">Updating...</string>
@ -219,6 +220,9 @@
<string name="dms_action_leave_question">Leave this chat?</string>
<string name="dms_action_kick">Kick</string>
<string name="dms_left_users">Left users</string>
<string name="dms_ERROR_INVALID_USER">Invalid user</string>
<string name="dms_ERROR_VIDEO_TOO_LONG">Instagram does not allow uploading videos longer than 60 secs for DM.</string>
<string name="dms_ERROR_AUDIO_TOO_LONG">Instagram does not allow uploading audio longer than 60 secs.</string>
<string name="direct_download">Download directly</string>
<string name="direct_download_desc">Downloads posts directly to the phone!</string>
<string name="direct_download_loading">Fetching post(s)</string>
@ -494,4 +498,7 @@
<string name="secs">secs</string>
<string name="mins">mins</string>
<string name="search_giphy">Search GIPHY</string>
<string name="generic_null_response">Response is null!</string>
<string name="generic_not_ok_response">Response status is not ok!</string>
<string name="generic_failed_request">Request failed!</string>
</resources>
Loading…
Cancel
Save