Skip to content

Commit

Permalink
fix toolbar when changing topic avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Sep 2, 2022
1 parent 140a046 commit d1afd38
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 15 deletions.
8 changes: 8 additions & 0 deletions app/src/main/java/co/tinode/tindroid/ImageViewFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.res.ResourcesCompat;
import androidx.exifinterface.media.ExifInterface;
import androidx.fragment.app.Fragment;
Expand Down Expand Up @@ -189,6 +190,13 @@ public void onResume() {
return;
}

Toolbar toolbar = activity.findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setTitle(R.string.image_preview);
toolbar.setSubtitle(null);
toolbar.setLogo(null);
}

mAvatarUpload = args.getBoolean(AttachmentHandler.ARG_AVATAR);

mMatrix.reset();
Expand Down
38 changes: 23 additions & 15 deletions app/src/main/java/co/tinode/tindroid/MessageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ boolean changeTopic(String topicName, boolean forceReset) {
changed = true;

if (mTopic == null) {
Log.i(TAG, "setupToolbar 2");
UiUtils.setupToolbar(this, null, mTopicName, false, null, false);
try {
//noinspection unchecked
Expand All @@ -302,15 +303,15 @@ boolean changeTopic(String topicName, boolean forceReset) {
}
showFragment(FRAGMENT_INVALID, null, false);

} else {
// Check if another fragment is already visible. If so, don't change it.
} else if (forceReset || UiUtils.getVisibleFragment(getSupportFragmentManager()) == null) {
Log.i(TAG, "setupToolbar 1");
UiUtils.setupToolbar(this, mTopic.getPub(), mTopicName,
mTopic.getOnline(), mTopic.getLastSeen(), mTopic.isDeleted());
// Check if another fragment is already visible. If so, don't change it.
if (forceReset || UiUtils.getVisibleFragment(getSupportFragmentManager()) == null) {
// Reset requested or no fragment is visible. Show default and clear back stack.
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
showFragment(FRAGMENT_MESSAGES, null, false);
}

// Reset requested or no fragment is visible. Show default and clear back stack.
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
showFragment(FRAGMENT_MESSAGES, null, false);
}
}

Expand Down Expand Up @@ -394,7 +395,7 @@ public void onPause() {
mNoteReadHandler.removeMessages(0);
}

private void showMessagesFragmentOnAttach() {
private Fragment maybeShowMessagesFragmentOnAttach() {
FragmentManager fm = getSupportFragmentManager();
Fragment visible = UiUtils.getVisibleFragment(fm);
if (visible instanceof InvalidTopicFragment) {
Expand All @@ -407,6 +408,7 @@ private void showMessagesFragmentOnAttach() {
fragmsg.topicChanged(mTopicName, true);
}
}
return visible;
}

private void topicAttach(boolean interactive) {
Expand All @@ -432,8 +434,9 @@ private void topicAttach(boolean interactive) {

if (mTopic.isDeleted()) {
setRefreshing(false);
Log.i(TAG, "setupToolbar 3");
UiUtils.setupToolbar(this, mTopic.getPub(), mTopicName, false, null, true);
showMessagesFragmentOnAttach();
maybeShowMessagesFragmentOnAttach();
return;
}

Expand All @@ -446,10 +449,13 @@ public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
changeTopic(result.ctrl.getStringParam("topic", null), false);
return null;
}
UiUtils.setupToolbar(MessageActivity.this, mTopic.getPub(),
mTopicName, mTopic.getOnline(), mTopic.getLastSeen(), mTopic.isDeleted());
Log.i(TAG, "setupToolbar 4");
runOnUiThread(() -> {
showMessagesFragmentOnAttach();
Fragment fragment = maybeShowMessagesFragmentOnAttach();
if (fragment instanceof MessagesFragment) {
UiUtils.setupToolbar(MessageActivity.this, mTopic.getPub(),
mTopicName, mTopic.getOnline(), mTopic.getLastSeen(), mTopic.isDeleted());
}
});
// Resume message sender and submit pending messages for processing:
// publish queued, delete marked for deletion.
Expand Down Expand Up @@ -758,7 +764,7 @@ public void onAcceptAvatar(String topicName, Bitmap avatar) {
return;
}

//noinspection unchecked
// noinspection unchecked
UiUtils.updateAvatar(Cache.getTinode().getTopic(topicName), avatar);
}

Expand Down Expand Up @@ -956,13 +962,15 @@ public void onSubsUpdated() {
@Override
public void onMetaDesc(final Description<VxCard, PrivateType> desc) {
runOnUiThread(() -> {
UiUtils.setupToolbar(MessageActivity.this, mTopic.getPub(), mTopic.getName(),
mTopic.getOnline(), mTopic.getLastSeen(), mTopic.isDeleted());
Fragment fragment = UiUtils.getVisibleFragment(getSupportFragmentManager());
if (fragment != null) {
if (fragment instanceof DataSetChangeListener) {
((DataSetChangeListener) fragment).notifyDataSetChanged();
} else if (fragment instanceof MessagesFragment) {
Log.i(TAG, "setupToolbar 5");
UiUtils.setupToolbar(MessageActivity.this, mTopic.getPub(), mTopic.getName(),
mTopic.getOnline(), mTopic.getLastSeen(), mTopic.isDeleted());

((MessagesFragment) fragment).notifyDataSetChanged(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import co.tinode.tindroid.media.VxCard;
Expand Down Expand Up @@ -83,6 +84,11 @@ public void onViewCreated(@NonNull View view, Bundle savedInstance) {
return;
}

Toolbar toolbar = activity.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.topic_settings);
toolbar.setSubtitle(null);
toolbar.setLogo(null);

view.findViewById(R.id.uploadAvatar).setOnClickListener(v -> {
if (activity.isFinishing() || activity.isDestroyed()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import co.tinode.tindroid.media.VxCard;
Expand Down Expand Up @@ -62,6 +63,11 @@ public void onViewCreated(@NonNull View fragment, Bundle savedInstance) {
return;
}

Toolbar toolbar = activity.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.topic_settings);
toolbar.setSubtitle(null);
toolbar.setLogo(null);

mFailureListener = new UiUtils.ToastFailureListener(activity);

// Set up listeners
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,5 @@
<string name="toggle_microphone_button">Mikrofon umschalten</string>
<string name="voice_calls_limited">Sie können einige eingehende Sprachanrufe nicht empfangen.</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="image_preview">Bildvorschau</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,5 @@
<string name="toggle_microphone_button">Alternar micrófono</string>
<string name="voice_calls_limited">No podrá recibir algunas llamadas de voz entrantes.</string>
<string name="copied_to_clipboard">Copiar al portapapeles</string>
<string name="image_preview">Vista previa de la imagen</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,5 @@
<string name="toggle_microphone_button">Basculer le microphone</string>
<string name="voice_calls_limited">Vous ne pourrez pas recevoir certains appels vocaux entrants.</string>
<string name="copied_to_clipboard">Copié dans le presse-papiers</string>
<string name="image_preview">Aperçu de l\'image</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,5 @@
<string name="toggle_microphone_button">마이크 토글</string>
<string name="voice_calls_limited">일부 수신 음성 전화를 받을 수 없습니다.</string>
<string name="copied_to_clipboard">클립보드에 복사 되었습니다</string>
<string name="image_preview">이미지 미리보기</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,5 @@
<string name="incoming_call">Входящий звонок</string>
<string name="voice_calls_limited">Вы не сможете принимать некоторые входящие звонки.</string>
<string name="copied_to_clipboard">Скопировано в буфер обмена</string>
<string name="image_preview">Превью картинки</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,5 @@
<string name="toggle_microphone_button">切換麥克風</string>
<string name="voice_calls_limited">您將無法接聽某些來電。</string>
<string name="copied_to_clipboard">拷貝成功</string>
<string name="image_preview">圖像預覽</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,5 @@
<string name="toggle_microphone_button">切换麦克风</string>
<string name="voice_calls_limited">您将无法接听某些来电。</string>
<string name="copied_to_clipboard">复制成功</string>
<string name="image_preview">图像预览</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,6 @@
<string name="video_calls_unavailable">Video calls unavailable</string>
<string name="voice_calls_limited">You will not be able to receive some incoming voice calls.</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="image_preview">Image preview</string>

</resources>

0 comments on commit d1afd38

Please sign in to comment.