Merge pull request #228 from freeboub/bugfix/refactor_error_management

[Error] : Refactor Toast error management to split network error and …
This commit is contained in:
Stefan Schüller 2020-09-25 07:58:50 +02:00 committed by GitHub
commit 53fd6ed179
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 10 deletions

View File

@ -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<Account> 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<VideoList> 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<ChannelList> 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 );
}
});
}

View File

@ -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<Me> call, @NonNull Throwable t) {
ErrorHelper.showToastFromCommunicationError( MeActivity.this, t );
account.setVisibility(View.GONE);
}
});

View File

@ -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<ServerList> 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);
}

View File

@ -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<VideoList> 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);
}

View File

@ -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<Rating> call, Throwable t) {
ErrorHelper.showToastFromCommunicationError( getActivity(), t );
// Do nothing.
}
});

View File

@ -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;
@ -207,7 +208,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
@Override
public void onFailure(@NonNull Call<Video> call, @NonNull Throwable t) {
Log.wtf(TAG, t.fillInStackTrace());
Toast.makeText(context, "Something went wrong: " + t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
ErrorHelper.showToastFromCommunicationError( getActivity(), t );
}
});
}

View File

@ -0,0 +1,26 @@
package net.schueller.peertube.helper;
import android.content.Context;
import android.widget.Toast;
import net.schueller.peertube.R;
import java.io.IOException;
import retrofit2.HttpException;
public class ErrorHelper {
public static void showToastFromCommunicationError( Context context, Throwable throwable ) {
if (throwable instanceof IOException ) {
//handle network error
Toast.makeText( context, context.getString( R.string.network_error), Toast.LENGTH_SHORT).show();
} else if (throwable instanceof HttpException ) {
//handle HTTP error response code
Toast.makeText(context, context.getString(R.string.api_error), Toast.LENGTH_SHORT).show();
} else {
//handle other exceptions
Toast.makeText(context, context.getString(R.string.api_error), Toast.LENGTH_SHORT).show();
}
}
}

View File

@ -109,6 +109,7 @@
<string name="account_about_description">Description :</string>
<string name="account_about_joined">Inscrit·e le :</string>
<string name="api_error">Quelque chose sest mal passé, veuillez essayer plus tard !</string>
<string name="network_error">Problème réseau, veuillez vérifier votre connection</string>
<string name="action_bar_title_server_selection">Sélectionnez un serveur</string>
<string name="ab">abkhaze</string>
<string name="aa">afar</string>

View File

@ -315,6 +315,7 @@
<string name="account_about_description">Description:</string>
<string name="account_about_joined">Joined:</string>
<string name="api_error">Something went wrong, please try later!</string>
<string name="network_error">Network access error, please check your connectivity</string>
<string name="action_bar_title_server_selection">Select Server</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="action_bar_title_address_book"/>