mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
SettingsViewModel: use LiveEvent instead of LiveData
This commit is contained in:
committed by
Torsten Grote
parent
d3cf3d680e
commit
a2174e7677
@@ -61,13 +61,14 @@ public class SettingsActivity extends BriarActivity {
|
|||||||
us.getLocalAuthor().getId(), us.getAuthorInfo());
|
us.getLocalAuthor().getId(), us.getAuthorInfo());
|
||||||
});
|
});
|
||||||
|
|
||||||
settingsViewModel.getSetAvatarFailed().observe(this, failed -> {
|
settingsViewModel.getSetAvatarFailed()
|
||||||
if (failed) {
|
.observeEvent(this, failed -> {
|
||||||
Toast.makeText(this,
|
if (failed) {
|
||||||
R.string.change_profile_picture_failed_message,
|
Toast.makeText(this,
|
||||||
LENGTH_LONG).show();
|
R.string.change_profile_picture_failed_message,
|
||||||
}
|
LENGTH_LONG).show();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
View avatarGroup = findViewById(R.id.avatarGroup);
|
View avatarGroup = findViewById(R.id.avatarGroup);
|
||||||
avatarGroup.setOnClickListener(e -> selectAvatarImage());
|
avatarGroup.setOnClickListener(e -> selectAvatarImage());
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.util.LogUtils;
|
import org.briarproject.bramble.util.LogUtils;
|
||||||
import org.briarproject.briar.android.attachment.ImageCompressor;
|
import org.briarproject.briar.android.attachment.ImageCompressor;
|
||||||
import org.briarproject.briar.android.attachment.UnsupportedMimeTypeException;
|
import org.briarproject.briar.android.attachment.UnsupportedMimeTypeException;
|
||||||
|
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||||
|
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||||
import org.briarproject.briar.api.avatar.AvatarManager;
|
import org.briarproject.briar.api.avatar.AvatarManager;
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
@@ -51,8 +53,8 @@ class SettingsViewModel extends AndroidViewModel {
|
|||||||
private final MutableLiveData<OwnIdentityInfo> ownIdentityInfo =
|
private final MutableLiveData<OwnIdentityInfo> ownIdentityInfo =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
|
|
||||||
private final MutableLiveData<Boolean> setAvatarFailed =
|
private final MutableLiveEvent<Boolean> setAvatarFailed =
|
||||||
new MutableLiveData<>();
|
new MutableLiveEvent<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SettingsViewModel(Application application,
|
SettingsViewModel(Application application,
|
||||||
@@ -77,7 +79,7 @@ class SettingsViewModel extends AndroidViewModel {
|
|||||||
return ownIdentityInfo;
|
return ownIdentityInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<Boolean> getSetAvatarFailed() {
|
public LiveEvent<Boolean> getSetAvatarFailed() {
|
||||||
return setAvatarFailed;
|
return setAvatarFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +102,7 @@ class SettingsViewModel extends AndroidViewModel {
|
|||||||
trySetAvatar(uri);
|
trySetAvatar(uri);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtils.logException(LOG, WARNING, e);
|
LogUtils.logException(LOG, WARNING, e);
|
||||||
setAvatarFailed.postValue(true);
|
setAvatarFailed.postEvent(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -125,7 +127,7 @@ class SettingsViewModel extends AndroidViewModel {
|
|||||||
loadOwnIdentityInfo();
|
loadOwnIdentityInfo();
|
||||||
} catch (IOException | DbException e) {
|
} catch (IOException | DbException e) {
|
||||||
LogUtils.logException(LOG, WARNING, e);
|
LogUtils.logException(LOG, WARNING, e);
|
||||||
setAvatarFailed.postValue(true);
|
setAvatarFailed.postEvent(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user