|
1 | 1 | package fr.free.nrw.commons.utils;
|
2 | 2 |
|
| 3 | +import android.app.ProgressDialog; |
3 | 4 | import android.app.WallpaperManager;
|
4 | 5 | import android.content.Context;
|
5 | 6 | import android.graphics.Bitmap;
|
@@ -68,6 +69,8 @@ public class ImageUtils {
|
68 | 69 | public static final int FILE_NAME_EXISTS = -4;
|
69 | 70 | static final int NO_CATEGORY_SELECTED = -5;
|
70 | 71 |
|
| 72 | + private static ProgressDialog progressDialog; |
| 73 | + |
71 | 74 | @IntDef(
|
72 | 75 | flag = true,
|
73 | 76 | value = {
|
@@ -188,6 +191,7 @@ private static boolean checkIfImageIsDark(Bitmap bitmap) {
|
188 | 191 | * @param imageUrl Url of the image
|
189 | 192 | */
|
190 | 193 | public static void setWallpaperFromImageUrl(Context context, Uri imageUrl) {
|
| 194 | + showSettingWallpaperProgressBar(context); |
191 | 195 | Timber.d("Trying to set wallpaper from url %s", imageUrl.toString());
|
192 | 196 | ImageRequest imageRequest = ImageRequestBuilder
|
193 | 197 | .newBuilderWithSource(imageUrl)
|
@@ -224,11 +228,23 @@ private static void setWallpaper(Context context, Bitmap bitmap) {
|
224 | 228 | try {
|
225 | 229 | wallpaperManager.setBitmap(bitmap);
|
226 | 230 | ViewUtil.showLongToast(context, context.getString(R.string.wallpaper_set_successfully));
|
| 231 | + if (progressDialog != null && progressDialog.isShowing()) { |
| 232 | + progressDialog.dismiss(); |
| 233 | + } |
227 | 234 | } catch (IOException e) {
|
228 | 235 | 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 | + } |
229 | 240 | }
|
230 | 241 | }
|
231 | 242 |
|
| 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 | + |
232 | 248 | /**
|
233 | 249 | * Result variable is a result of an or operation of all possible problems. Ie. if result
|
234 | 250 | * is 0001 means IMAGE_DARK
|
|
0 commit comments