kopia lustrzana https://github.com/ryukoposting/Signal-Android
Prevent NPE in safety number change dialog.
rodzic
8d6d8019fe
commit
9363f0ebb4
|
@ -7,6 +7,7 @@ import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
@ -156,13 +157,19 @@ public final class SafetyNumberChangeDialog extends DialogFragment implements Sa
|
||||||
|
|
||||||
builder.setTitle(R.string.safety_number_change_dialog__safety_number_changes)
|
builder.setTitle(R.string.safety_number_change_dialog__safety_number_changes)
|
||||||
.setView(dialogView)
|
.setView(dialogView)
|
||||||
.setCancelable(false)
|
|
||||||
.setPositiveButton(continueText, this::handleSendAnyway)
|
.setPositiveButton(continueText, this::handleSendAnyway)
|
||||||
.setNegativeButton(cancelText, this::handleCancel);
|
.setNegativeButton(cancelText, this::handleCancel);
|
||||||
|
|
||||||
setCancelable(false);
|
setCancelable(false);
|
||||||
|
|
||||||
return builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
|
dialog.setOnShowListener(d -> {
|
||||||
|
Button positive = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||||
|
positive.setEnabled(false);
|
||||||
|
viewModel.getTrustOrVerifyReady().observe(getViewLifecycleOwner(), positive::setEnabled);
|
||||||
|
});
|
||||||
|
|
||||||
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,6 +22,8 @@ public final class SafetyNumberChangeViewModel extends ViewModel {
|
||||||
private final SafetyNumberChangeRepository safetyNumberChangeRepository;
|
private final SafetyNumberChangeRepository safetyNumberChangeRepository;
|
||||||
private final MutableLiveData<Collection<RecipientId>> recipientIds;
|
private final MutableLiveData<Collection<RecipientId>> recipientIds;
|
||||||
private final LiveData<SafetyNumberChangeState> safetyNumberChangeState;
|
private final LiveData<SafetyNumberChangeState> safetyNumberChangeState;
|
||||||
|
private final LiveData<List<ChangedRecipient>> changedRecipients;
|
||||||
|
private final LiveData<Boolean> trustOrVerifyReady;
|
||||||
|
|
||||||
private SafetyNumberChangeViewModel(@NonNull List<RecipientId> recipientIds,
|
private SafetyNumberChangeViewModel(@NonNull List<RecipientId> recipientIds,
|
||||||
@Nullable Long messageId,
|
@Nullable Long messageId,
|
||||||
|
@ -31,10 +33,16 @@ public final class SafetyNumberChangeViewModel extends ViewModel {
|
||||||
this.safetyNumberChangeRepository = safetyNumberChangeRepository;
|
this.safetyNumberChangeRepository = safetyNumberChangeRepository;
|
||||||
this.recipientIds = new MutableLiveData<>(recipientIds);
|
this.recipientIds = new MutableLiveData<>(recipientIds);
|
||||||
this.safetyNumberChangeState = LiveDataUtil.mapAsync(this.recipientIds, ids -> this.safetyNumberChangeRepository.getSafetyNumberChangeState(ids, messageId, messageType));
|
this.safetyNumberChangeState = LiveDataUtil.mapAsync(this.recipientIds, ids -> this.safetyNumberChangeRepository.getSafetyNumberChangeState(ids, messageId, messageType));
|
||||||
|
this.changedRecipients = Transformations.map(safetyNumberChangeState, SafetyNumberChangeState::getChangedRecipients);
|
||||||
|
this.trustOrVerifyReady = Transformations.map(safetyNumberChangeState, Objects::nonNull);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull LiveData<List<ChangedRecipient>> getChangedRecipients() {
|
@NonNull LiveData<List<ChangedRecipient>> getChangedRecipients() {
|
||||||
return Transformations.map(safetyNumberChangeState, SafetyNumberChangeState::getChangedRecipients);
|
return changedRecipients;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull LiveData<Boolean> getTrustOrVerifyReady() {
|
||||||
|
return trustOrVerifyReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull LiveData<TrustAndVerifyResult> trustOrVerifyChangedRecipients() {
|
@NonNull LiveData<TrustAndVerifyResult> trustOrVerifyChangedRecipients() {
|
||||||
|
|
Ładowanie…
Reference in New Issue