Skip to content

Commit

Permalink
Added progress dialog for setting wallpaper (#3427)
Browse files Browse the repository at this point in the history
* Added progress dialog for setting wallpaper

* Updated dialog strings
  • Loading branch information
madhurgupta10 authored Feb 23, 2020
1 parent 39cb190 commit 3d0048a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/utils/ImageUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,7 @@ Upload your first media by tapping on the add button.</string>
<string name="upload_nearby_place_found_description">Is this a photo of Place %1$s?</string>
<string name="remove_bookmark">Removed from bookmarks</string>
<string name="add_bookmark">Added to bookmarks</string>
<string name="wallpaper_set_unsuccessfully">Something went wrong. Could not set the wallpaper</string>
<string name="setting_wallpaper_dialog_title">Set as Wallpaper</string>
<string name="setting_wallpaper_dialog_message">Setting Wallpaper. Please wait…</string>
</resources>

0 comments on commit 3d0048a

Please sign in to comment.