Skip to content

Commit 3d0048a

Browse files
Added progress dialog for setting wallpaper (commons-app#3427)
* Added progress dialog for setting wallpaper * Updated dialog strings
1 parent 39cb190 commit 3d0048a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

app/src/main/java/fr/free/nrw/commons/utils/ImageUtils.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.free.nrw.commons.utils;
22

3+
import android.app.ProgressDialog;
34
import android.app.WallpaperManager;
45
import android.content.Context;
56
import android.graphics.Bitmap;
@@ -68,6 +69,8 @@ public class ImageUtils {
6869
public static final int FILE_NAME_EXISTS = -4;
6970
static final int NO_CATEGORY_SELECTED = -5;
7071

72+
private static ProgressDialog progressDialog;
73+
7174
@IntDef(
7275
flag = true,
7376
value = {
@@ -188,6 +191,7 @@ private static boolean checkIfImageIsDark(Bitmap bitmap) {
188191
* @param imageUrl Url of the image
189192
*/
190193
public static void setWallpaperFromImageUrl(Context context, Uri imageUrl) {
194+
showSettingWallpaperProgressBar(context);
191195
Timber.d("Trying to set wallpaper from url %s", imageUrl.toString());
192196
ImageRequest imageRequest = ImageRequestBuilder
193197
.newBuilderWithSource(imageUrl)
@@ -224,11 +228,23 @@ private static void setWallpaper(Context context, Bitmap bitmap) {
224228
try {
225229
wallpaperManager.setBitmap(bitmap);
226230
ViewUtil.showLongToast(context, context.getString(R.string.wallpaper_set_successfully));
231+
if (progressDialog != null && progressDialog.isShowing()) {
232+
progressDialog.dismiss();
233+
}
227234
} catch (IOException e) {
228235
Timber.e(e, "Error setting wallpaper");
236+
ViewUtil.showLongToast(context, context.getString(R.string.wallpaper_set_unsuccessfully));
237+
if (progressDialog != null) {
238+
progressDialog.cancel();
239+
}
229240
}
230241
}
231242

243+
private static void showSettingWallpaperProgressBar(Context context) {
244+
progressDialog = ProgressDialog.show(context, context.getString(R.string.setting_wallpaper_dialog_title),
245+
context.getString(R.string.setting_wallpaper_dialog_message), true);
246+
}
247+
232248
/**
233249
* Result variable is a result of an or operation of all possible problems. Ie. if result
234250
* is 0001 means IMAGE_DARK

app/src/main/res/values/strings.xml

+3
Original file line numberDiff line numberDiff line change
@@ -593,4 +593,7 @@ Upload your first media by tapping on the add button.</string>
593593
<string name="upload_nearby_place_found_description">Is this a photo of Place %1$s?</string>
594594
<string name="remove_bookmark">Removed from bookmarks</string>
595595
<string name="add_bookmark">Added to bookmarks</string>
596+
<string name="wallpaper_set_unsuccessfully">Something went wrong. Could not set the wallpaper</string>
597+
<string name="setting_wallpaper_dialog_title">Set as Wallpaper</string>
598+
<string name="setting_wallpaper_dialog_message">Setting Wallpaper. Please wait…</string>
596599
</resources>

0 commit comments

Comments
 (0)