mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
* Bug fix #2042 * Added a snack with retry when api in AA fails * Increased connection timeouts in okhttpclient builder * added missing string resource
This commit is contained in:
parent
2e29f4f7f9
commit
568f80766e
4 changed files with 36 additions and 5 deletions
|
|
@ -185,6 +185,7 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
|||
* which then calls parseJson when results are fetched
|
||||
*/
|
||||
private void setAchievements() {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
if (checkAccount()) {
|
||||
compositeDisposable.add(mediaWikiApi
|
||||
.getAchievements(Objects.requireNonNull(sessionManager.getCurrentAccount()).name)
|
||||
|
|
@ -195,17 +196,23 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
|||
if (response != null) {
|
||||
setUploadCount(Achievements.from(response));
|
||||
} else {
|
||||
onError();
|
||||
showSnackBarWithRetry();
|
||||
}
|
||||
},
|
||||
t -> {
|
||||
Timber.e(t, "Fetching achievements statistics failed");
|
||||
onError();
|
||||
showSnackBarWithRetry();
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private void showSnackBarWithRetry() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
ViewUtil.showDismissibleSnackBar(findViewById(android.R.id.content),
|
||||
R.string.achievements_fetch_failed, R.string.retry, view -> setAchievements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a generic error toast when error occurs while loading achievements or uploads
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.google.gson.GsonBuilder;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
|
@ -30,9 +31,11 @@ public class NetworkingModule {
|
|||
@Singleton
|
||||
public OkHttpClient provideOkHttpClient(Context context) {
|
||||
File dir = new File(context.getCacheDir(), "okHttpCache");
|
||||
return new OkHttpClient.Builder()
|
||||
.cache(new Cache(dir, OK_HTTP_CACHE_SIZE))
|
||||
.build();
|
||||
return new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.cache(new Cache(dir, OK_HTTP_CACHE_SIZE))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
|||
|
|
@ -87,4 +87,24 @@ public class ViewUtil {
|
|||
popup.showAsDropDown(anchorView);
|
||||
}
|
||||
|
||||
/**
|
||||
* A snack bar which has an action button which on click dismisses the snackbar and invokes the
|
||||
* listener passed
|
||||
*/
|
||||
public static void showDismissibleSnackBar(View view, int messageResourceId,
|
||||
int actionButtonResourceId, View.OnClickListener onClickListener) {
|
||||
if (view.getContext() == null) {
|
||||
return;
|
||||
}
|
||||
ExecutorUtils.uiExecutor().execute(() -> {
|
||||
Snackbar snackbar = Snackbar.make(view, view.getContext().getString(messageResourceId),
|
||||
Snackbar.LENGTH_INDEFINITE);
|
||||
snackbar.setAction(view.getContext().getString(actionButtonResourceId), v -> {
|
||||
snackbar.dismiss();
|
||||
onClickListener.onClick(v);
|
||||
});
|
||||
snackbar.show();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -420,5 +420,6 @@ Upload your first media by touching the camera or gallery icon above.</string>
|
|||
<string name="never_ask_again">Never ask this again</string>
|
||||
<string name="display_location_permission_title">Display location permission</string>
|
||||
<string name="display_location_permission_explanation">Ask for location permission when needed for nearby notification card view feature.</string>
|
||||
<string name="achievements_fetch_failed">Something went wrong, We could not fetch your achievements</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue