From 62ae5c66d6e1fd1e77da7e63ed3a2e4b817392eb Mon Sep 17 00:00:00 2001 From: Olivier Bouillet Date: Thu, 24 Sep 2020 22:26:21 +0200 Subject: [PATCH] [Error] : Refactor Toast error management to split network error and server error --- .../peertube/activity/AccountActivity.java | 14 +++++----- .../peertube/activity/MeActivity.java | 2 ++ .../activity/SearchServerActivity.java | 3 ++- .../peertube/activity/VideoListActivity.java | 3 ++- .../fragment/VideoMetaDataFragment.java | 2 ++ .../fragment/VideoPlayerFragment.java | 3 ++- .../peertube/helper/ErrorHelper.java | 26 +++++++++++++++++++ app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/net/schueller/peertube/helper/ErrorHelper.java diff --git a/app/src/main/java/net/schueller/peertube/activity/AccountActivity.java b/app/src/main/java/net/schueller/peertube/activity/AccountActivity.java index d80b58c..7daf17b 100644 --- a/app/src/main/java/net/schueller/peertube/activity/AccountActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/AccountActivity.java @@ -37,6 +37,7 @@ import net.schueller.peertube.R; import net.schueller.peertube.adapter.ChannelAdapter; import net.schueller.peertube.adapter.VideoAdapter; import net.schueller.peertube.helper.APIUrlHelper; +import net.schueller.peertube.helper.ErrorHelper; import net.schueller.peertube.helper.MetaDataHelper; import net.schueller.peertube.model.Account; import net.schueller.peertube.model.Avatar; @@ -206,7 +207,7 @@ public class AccountActivity extends CommonActivity { } } else { - Toast.makeText(AccountActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); + ErrorHelper.showToastFromCommunicationError( AccountActivity.this, null ); } @@ -215,7 +216,7 @@ public class AccountActivity extends CommonActivity { @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { Log.wtf(TAG, t.fillInStackTrace()); - Toast.makeText(AccountActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); + ErrorHelper.showToastFromCommunicationError( AccountActivity.this, t ); } }); @@ -247,8 +248,7 @@ public class AccountActivity extends CommonActivity { } } else{ - Toast.makeText(AccountActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); - + ErrorHelper.showToastFromCommunicationError( AccountActivity.this, null ); } isLoadingVideos = false; @@ -258,7 +258,7 @@ public class AccountActivity extends CommonActivity { @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { Log.wtf("err", t.fillInStackTrace()); - Toast.makeText(AccountActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); + ErrorHelper.showToastFromCommunicationError( AccountActivity.this, t ); isLoadingVideos = false; swipeRefreshLayoutVideos.setRefreshing(false); } @@ -281,7 +281,7 @@ public class AccountActivity extends CommonActivity { } else { - Toast.makeText(AccountActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); + ErrorHelper.showToastFromCommunicationError( AccountActivity.this, null ); } @@ -290,7 +290,7 @@ public class AccountActivity extends CommonActivity { @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { Log.wtf(TAG, t.fillInStackTrace()); - Toast.makeText(AccountActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); + ErrorHelper.showToastFromCommunicationError( AccountActivity.this, t ); } }); } diff --git a/app/src/main/java/net/schueller/peertube/activity/MeActivity.java b/app/src/main/java/net/schueller/peertube/activity/MeActivity.java index 9e0c6da..7a62427 100644 --- a/app/src/main/java/net/schueller/peertube/activity/MeActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/MeActivity.java @@ -31,6 +31,7 @@ import android.widget.TextView; import net.schueller.peertube.R; import net.schueller.peertube.helper.APIUrlHelper; +import net.schueller.peertube.helper.ErrorHelper; import net.schueller.peertube.model.Avatar; import net.schueller.peertube.model.Me; import net.schueller.peertube.network.GetUserService; @@ -162,6 +163,7 @@ public class MeActivity extends CommonActivity { @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { + ErrorHelper.showToastFromCommunicationError( MeActivity.this, t ); account.setVisibility(View.GONE); } }); diff --git a/app/src/main/java/net/schueller/peertube/activity/SearchServerActivity.java b/app/src/main/java/net/schueller/peertube/activity/SearchServerActivity.java index 6c57cf7..39f7281 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SearchServerActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SearchServerActivity.java @@ -35,6 +35,7 @@ import android.widget.Toast; import net.schueller.peertube.R; import net.schueller.peertube.adapter.ServerSearchAdapter; import net.schueller.peertube.helper.APIUrlHelper; +import net.schueller.peertube.helper.ErrorHelper; import net.schueller.peertube.model.ServerList; import net.schueller.peertube.network.GetServerListDataService; import net.schueller.peertube.network.RetrofitInstance; @@ -171,7 +172,7 @@ public class SearchServerActivity extends CommonActivity { @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { Log.wtf("err", t.fillInStackTrace()); - Toast.makeText(SearchServerActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); + ErrorHelper.showToastFromCommunicationError( SearchServerActivity.this, t ); isLoading = false; swipeRefreshLayout.setRefreshing(false); } diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java index 868aba4..ae7b650 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java @@ -59,6 +59,7 @@ import com.mikepenz.iconics.IconicsDrawable; import net.schueller.peertube.R; import net.schueller.peertube.adapter.VideoAdapter; import net.schueller.peertube.helper.APIUrlHelper; +import net.schueller.peertube.helper.ErrorHelper; import net.schueller.peertube.model.Video; import net.schueller.peertube.model.VideoList; import net.schueller.peertube.network.GetUserService; @@ -372,7 +373,7 @@ public class VideoListActivity extends CommonActivity { @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { Log.wtf("err", t.fillInStackTrace()); - Toast.makeText(VideoListActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); + ErrorHelper.showToastFromCommunicationError( VideoListActivity.this, t ); isLoading = false; swipeRefreshLayout.setRefreshing(false); } diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java index 1d370e0..e357a5d 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java @@ -39,6 +39,7 @@ import com.squareup.picasso.Picasso; import net.schueller.peertube.R; import net.schueller.peertube.helper.APIUrlHelper; +import net.schueller.peertube.helper.ErrorHelper; import net.schueller.peertube.helper.MetaDataHelper; import net.schueller.peertube.intents.Intents; import net.schueller.peertube.model.Account; @@ -122,6 +123,7 @@ public class VideoMetaDataFragment extends Fragment { @Override public void onFailure(Call call, Throwable t) { + ErrorHelper.showToastFromCommunicationError( getActivity(), t ); // Do nothing. } }); diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index 3ac32ba..5180d3d 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -59,6 +59,7 @@ import com.mikepenz.iconics.Iconics; import net.schueller.peertube.R; import net.schueller.peertube.helper.APIUrlHelper; +import net.schueller.peertube.helper.ErrorHelper; import net.schueller.peertube.model.File; import net.schueller.peertube.model.Video; import net.schueller.peertube.network.GetVideoDataService; @@ -196,7 +197,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL @Override public void onFailure(@NonNull Call