Skip to content

Commit

Permalink
Couple rare crashes due to data races
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Dec 15, 2023
1 parent 8f9706e commit 6e37c29
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
7 changes: 6 additions & 1 deletion app/src/main/java/co/tinode/tindroid/CallFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,9 @@ private synchronized void stopSoundEffect() {

private void rearrangePeerViews(final Activity activity, boolean remoteVideoLive) {
activity.runOnUiThread(() -> {
if (activity.isFinishing() || activity.isDestroyed()) {
return;
}
if (remoteVideoLive) {
ConstraintSet cs = new ConstraintSet();
cs.clone(mLayout);
Expand All @@ -979,7 +982,9 @@ private void rearrangePeerViews(final Activity activity, boolean remoteVideoLive
cs.setHorizontalBias(R.id.peerName, 0.5f);
cs.applyTo(mLayout);
mPeerAvatar.setVisibility(View.VISIBLE);
mRemoteVideoView.setVisibility(View.INVISIBLE);
if (mRemoteVideoView != null) {
mRemoteVideoView.setVisibility(View.INVISIBLE);
}
}
});
}
Expand Down
48 changes: 28 additions & 20 deletions app/src/main/java/co/tinode/tindroid/TopicInfoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,38 @@ public void onViewCreated(@NonNull View view, Bundle savedInstance) {
// Set up listeners

final SwitchCompat muted = view.findViewById(R.id.switchMuted);
muted.setOnCheckedChangeListener((buttonView, isChecked) ->
mTopic.updateMuted(isChecked).thenCatch(new PromisedReply.FailureListener<ServerMessage>() {
@Override
public <E extends Exception> PromisedReply<ServerMessage> onFailure(E err) {
activity.runOnUiThread(() -> muted.setChecked(!isChecked));
if (err instanceof NotConnectedException) {
Toast.makeText(activity, R.string.no_connection, Toast.LENGTH_SHORT).show();
}
return null;
muted.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (mTopic == null) {
return;
}
mTopic.updateMuted(isChecked).thenCatch(new PromisedReply.FailureListener<ServerMessage>() {
@Override
public <E extends Exception> PromisedReply<ServerMessage> onFailure(E err) {
activity.runOnUiThread(() -> muted.setChecked(!isChecked));
if (err instanceof NotConnectedException) {
Toast.makeText(activity, R.string.no_connection, Toast.LENGTH_SHORT).show();
}
}));
return null;
}
});
});

final SwitchCompat archived = view.findViewById(R.id.switchArchived);
archived.setOnCheckedChangeListener((buttonView, isChecked) ->
mTopic.updateArchived(isChecked).thenCatch(new PromisedReply.FailureListener<ServerMessage>() {
@Override
public <E extends Exception> PromisedReply<ServerMessage> onFailure(E err) {
activity.runOnUiThread(() -> archived.setChecked(!isChecked));
if (err instanceof NotConnectedException) {
Toast.makeText(activity, R.string.no_connection, Toast.LENGTH_SHORT).show();
}
return null;
archived.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (mTopic == null) {
return;
}
mTopic.updateArchived(isChecked).thenCatch(new PromisedReply.FailureListener<ServerMessage>() {
@Override
public <E extends Exception> PromisedReply<ServerMessage> onFailure(E err) {
activity.runOnUiThread(() -> archived.setChecked(!isChecked));
if (err instanceof NotConnectedException) {
Toast.makeText(activity, R.string.no_connection, Toast.LENGTH_SHORT).show();
}
}));
return null;
}
});
});

view.findViewById(R.id.buttonCopyID).setOnClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
Expand Down

0 comments on commit 6e37c29

Please sign in to comment.