diff --git a/app/src/main/java/fr/free/nrw/commons/utils/ImageUtils.java b/app/src/main/java/fr/free/nrw/commons/utils/ImageUtils.java
index 1c4af22874..6caa0c2262 100644
--- a/app/src/main/java/fr/free/nrw/commons/utils/ImageUtils.java
+++ b/app/src/main/java/fr/free/nrw/commons/utils/ImageUtils.java
@@ -1,5 +1,6 @@
package fr.free.nrw.commons.utils;
+import android.app.ProgressDialog;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
@@ -68,6 +69,8 @@ public class ImageUtils {
public static final int FILE_NAME_EXISTS = -4;
static final int NO_CATEGORY_SELECTED = -5;
+ private static ProgressDialog progressDialog;
+
@IntDef(
flag = true,
value = {
@@ -188,6 +191,7 @@ private static boolean checkIfImageIsDark(Bitmap bitmap) {
* @param imageUrl Url of the image
*/
public static void setWallpaperFromImageUrl(Context context, Uri imageUrl) {
+ showSettingWallpaperProgressBar(context);
Timber.d("Trying to set wallpaper from url %s", imageUrl.toString());
ImageRequest imageRequest = ImageRequestBuilder
.newBuilderWithSource(imageUrl)
@@ -224,11 +228,23 @@ private static void setWallpaper(Context context, Bitmap bitmap) {
try {
wallpaperManager.setBitmap(bitmap);
ViewUtil.showLongToast(context, context.getString(R.string.wallpaper_set_successfully));
+ if (progressDialog != null && progressDialog.isShowing()) {
+ progressDialog.dismiss();
+ }
} catch (IOException e) {
Timber.e(e, "Error setting wallpaper");
+ ViewUtil.showLongToast(context, context.getString(R.string.wallpaper_set_unsuccessfully));
+ if (progressDialog != null) {
+ progressDialog.cancel();
+ }
}
}
+ private static void showSettingWallpaperProgressBar(Context context) {
+ progressDialog = ProgressDialog.show(context, context.getString(R.string.setting_wallpaper_dialog_title),
+ context.getString(R.string.setting_wallpaper_dialog_message), true);
+ }
+
/**
* Result variable is a result of an or operation of all possible problems. Ie. if result
* is 0001 means IMAGE_DARK
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 32ab81e5a0..3b33c6f073 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -593,4 +593,7 @@ Upload your first media by tapping on the add button.
Is this a photo of Place %1$s?
Removed from bookmarks
Added to bookmarks
+ Something went wrong. Could not set the wallpaper
+ Set as Wallpaper
+ Setting Wallpaper. Please wait…