aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-13 05:01:18 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-13 05:01:18 +0000
commitf6aca0e9a0510e520f6fb1e81f85df5c6e8d0f81 (patch)
treeb8b3240ab300041e539bb1bd21e29d40fdfb970d /app/src/main/java/ml/docilealligator/infinityforreddit
parentb856f5baeb3a6353009c3362d07bd4363bacc152 (diff)
downloadinfinity-for-reddit-f6aca0e9a0510e520f6fb1e81f85df5c6e8d0f81.tar
infinity-for-reddit-f6aca0e9a0510e520f6fb1e81f85df5c6e8d0f81.tar.gz
infinity-for-reddit-f6aca0e9a0510e520f6fb1e81f85df5c6e8d0f81.tar.bz2
infinity-for-reddit-f6aca0e9a0510e520f6fb1e81f85df5c6e8d0f81.tar.lz
infinity-for-reddit-f6aca0e9a0510e520f6fb1e81f85df5c6e8d0f81.tar.xz
infinity-for-reddit-f6aca0e9a0510e520f6fb1e81f85df5c6e8d0f81.tar.zst
infinity-for-reddit-f6aca0e9a0510e520f6fb1e81f85df5c6e8d0f81.zip
Show error message when loading RPAN broadcasts failed.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java47
2 files changed, 45 insertions, 4 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java
index 2a26ae10..b5452989 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java
@@ -7,6 +7,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
+import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@@ -189,6 +190,7 @@ public class LinkResolverActivity extends AppCompatActivity {
startActivity(intent);
} else if (path.matches(RPAN_BROADCAST_PATTERN)) {
Intent intent = new Intent(this, RPANActivity.class);
+ Log.i("asdfasdf", "sd " + path);
intent.putExtra(RPANActivity.EXTRA_RPAN_BROADCAST_FULLNAME_OR_ID, path.substring(path.lastIndexOf('/') + 1));
startActivity(intent);
} else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java
index 38dd995f..76ec456b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java
@@ -27,12 +27,14 @@ import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.evernote.android.state.State;
+import com.google.android.material.snackbar.Snackbar;
import com.livefront.bridge.Bridge;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.concurrent.Executor;
@@ -53,6 +55,7 @@ import ml.docilealligator.infinityforreddit.font.TitleFontFamily;
import ml.docilealligator.infinityforreddit.fragments.ViewRPANBroadcastFragment;
import ml.docilealligator.infinityforreddit.utils.JSONUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -131,8 +134,26 @@ public class RPANActivity extends AppCompatActivity {
if (response.isSuccessful()) {
parseRPANBroadcasts(response.body());
} else {
- Toast.makeText(RPANActivity.this,
- R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ try {
+ ResponseBody responseBody = response.errorBody();
+ if (responseBody != null) {
+ JSONObject errorObject = new JSONObject(responseBody.string());
+ String errorMessage = errorObject.getString(JSONUtils.DATA_KEY);
+ if (!errorMessage.isEmpty() && !errorMessage.equals("null")) {
+ Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
}
}
@@ -162,8 +183,26 @@ public class RPANActivity extends AppCompatActivity {
}
});
} else {
- Toast.makeText(RPANActivity.this,
- R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ try {
+ ResponseBody responseBody = response.errorBody();
+ if (responseBody != null) {
+ JSONObject errorObject = new JSONObject(responseBody.string());
+ String errorMessage = errorObject.getString(JSONUtils.DATA_KEY);
+ if (!errorMessage.isEmpty() && !errorMessage.equals("null")) {
+ Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
}
}