Display error message toast when updating profile picture fails

This commit is contained in:
Sebastian Kürten
2020-12-04 12:25:24 +01:00
committed by Torsten Grote
parent cbb87aa00c
commit d3cf3d680e
3 changed files with 20 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import org.briarproject.bramble.api.FeatureFlags;
import org.briarproject.briar.R;
@@ -21,6 +22,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.lifecycle.ViewModelProvider;
import de.hdodenhof.circleimageview.CircleImageView;
import static android.widget.Toast.LENGTH_LONG;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_AVATAR_IMAGE;
public class SettingsActivity extends BriarActivity {
@@ -59,6 +61,14 @@ public class SettingsActivity extends BriarActivity {
us.getLocalAuthor().getId(), us.getAuthorInfo());
});
settingsViewModel.getSetAvatarFailed().observe(this, failed -> {
if (failed) {
Toast.makeText(this,
R.string.change_profile_picture_failed_message,
LENGTH_LONG).show();
}
});
View avatarGroup = findViewById(R.id.avatarGroup);
avatarGroup.setOnClickListener(e -> selectAvatarImage());
} else {

View File

@@ -51,6 +51,9 @@ class SettingsViewModel extends AndroidViewModel {
private final MutableLiveData<OwnIdentityInfo> ownIdentityInfo =
new MutableLiveData<>();
private final MutableLiveData<Boolean> setAvatarFailed =
new MutableLiveData<>();
@Inject
SettingsViewModel(Application application,
IdentityManager identityManager,
@@ -74,6 +77,10 @@ class SettingsViewModel extends AndroidViewModel {
return ownIdentityInfo;
}
public MutableLiveData<Boolean> getSetAvatarFailed() {
return setAvatarFailed;
}
private void loadOwnIdentityInfo() {
dbExecutor.execute(() -> {
try {
@@ -93,6 +100,7 @@ class SettingsViewModel extends AndroidViewModel {
trySetAvatar(uri);
} catch (IOException e) {
LogUtils.logException(LOG, WARNING, e);
setAvatarFailed.postValue(true);
}
});
}
@@ -117,6 +125,7 @@ class SettingsViewModel extends AndroidViewModel {
loadOwnIdentityInfo();
} catch (IOException | DbException e) {
LogUtils.logException(LOG, WARNING, e);
setAvatarFailed.postValue(true);
}
});
}

View File

@@ -457,6 +457,7 @@
<string name="change_profile_picture">Tap to change your profile picture</string>
<string name="dialog_confirm_profile_picture_title">Change profile picture</string>
<string name="dialog_confirm_profile_picture_remark">Only your contacts can see your profile image</string>
<string name="change_profile_picture_failed_message">We\'re sorry, but something went wrong while updating your profile picture</string>
<!-- Settings Display -->
<string name="pref_language_title">Language &amp; region</string>