From aa06ecaedfbe25b5c6d3399dc3937c2c9b8e5690 Mon Sep 17 00:00:00 2001 From: Tien Date: Sun, 29 May 2022 13:53:45 +0700 Subject: [PATCH] Handle profile navigation --- .../BaseApplication.java | 2 +- .../uikit/activities/ChannelActivity.java | 46 +++++++++++++++++-- .../uikit/fragments/ChannelFragment.java | 8 ++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/uikit-sample/src/main/java/com/sendbird/uikit_messaging_android/BaseApplication.java b/uikit-sample/src/main/java/com/sendbird/uikit_messaging_android/BaseApplication.java index e330c3cf..48bc6b0f 100644 --- a/uikit-sample/src/main/java/com/sendbird/uikit_messaging_android/BaseApplication.java +++ b/uikit-sample/src/main/java/com/sendbird/uikit_messaging_android/BaseApplication.java @@ -19,7 +19,7 @@ public class BaseApplication extends MultiDexApplication { - private static final String APP_ID = "A602CBEC-EC8C-4EFA-83CE-CAE057853DD7"; + private static final String APP_ID = "033D0C2B-1B69-4592-90E5-2B6D8D58A86B"; private static final MutableLiveData initState = new MutableLiveData<>(); @Override diff --git a/uikit/src/main/java/com/sendbird/uikit/activities/ChannelActivity.java b/uikit/src/main/java/com/sendbird/uikit/activities/ChannelActivity.java index 0c45a62a..8f735be9 100644 --- a/uikit/src/main/java/com/sendbird/uikit/activities/ChannelActivity.java +++ b/uikit/src/main/java/com/sendbird/uikit/activities/ChannelActivity.java @@ -3,12 +3,14 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentManager; +import com.sendbird.android.Member; import com.sendbird.uikit.R; import com.sendbird.uikit.SendBirdUIKit; import com.sendbird.uikit.consts.StringSet; @@ -18,6 +20,8 @@ import com.sendbird.uikit.utils.TextUtils; import com.sendbird.uikit.widgets.AudioManager; +import java.util.List; + /** * Activity displays a list of messages from a channel. */ @@ -59,29 +63,62 @@ public static Intent newIntentFromCustomActivity(@NonNull Context context, @NonN } private String url; + private View.OnClickListener onBackClickListener; + private View.OnClickListener onInfoClickListener; + private ChannelFragment channelFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(SendBirdUIKit.isDarkMode() ? R.style.SendBird_Dark : R.style.SendBird); - setContentView(R.layout.sb_activity); + setContentView(getLayoutId()); + + initialize(); url = getIntent().getStringExtra(StringSet.KEY_CHANNEL_URL); String title = getIntent().getStringExtra(StringSet.KEY_HEADER_TITLE); if (TextUtils.isEmpty(url)) { ContextUtils.toastError(this, R.string.sb_text_error_get_channel); } else { - ChannelFragment fragment = createChannelFragment(url, title); + channelFragment = createChannelFragment(url, title); FragmentManager manager = getSupportFragmentManager(); manager.popBackStack(); manager.beginTransaction() - .replace(R.id.sb_fragment_container, fragment) + .replace(R.id.sb_fragment_container, channelFragment) .commit(); } AudioManager.getInstance().attachLifecycle(getLifecycle()); } + public int getLayoutId() { + return R.layout.sb_activity; + } + + public void initialize() { + + } + + public String getChannelUrl() { + return url; + } + + public List getMembers() { + return channelFragment.getMembers(); + } + + public boolean isSingleChat() { + return channelFragment.isSingleChat(); + } + + public void setOnBackClickListener(View.OnClickListener backClickListener) { + this.onBackClickListener = backClickListener; + } + + public void setOnInfoClickListener(View.OnClickListener infoClickListener) { + this.onInfoClickListener = infoClickListener; + } + @Override protected void onResume() { Intent intent = new Intent(StringSet.KEY_ACTION_CLEAR_CHAT_NOTIFICATION); @@ -116,6 +153,9 @@ protected ChannelFragment createChannelFragment(@NonNull String channelUrl, @Nul if (intent.hasExtra(StringSet.KEY_FROM_SEARCH_RESULT)) { builder.setUseHeaderRightButton(intent.getBooleanExtra(StringSet.KEY_FROM_SEARCH_RESULT, false)); } + + builder.setHeaderLeftButtonListener(onBackClickListener); + builder.setHeaderRightButtonListener(onInfoClickListener); return builder.build(); } diff --git a/uikit/src/main/java/com/sendbird/uikit/fragments/ChannelFragment.java b/uikit/src/main/java/com/sendbird/uikit/fragments/ChannelFragment.java index c2ae3d18..82cbd7e5 100644 --- a/uikit/src/main/java/com/sendbird/uikit/fragments/ChannelFragment.java +++ b/uikit/src/main/java/com/sendbird/uikit/fragments/ChannelFragment.java @@ -1799,6 +1799,14 @@ private void setOnListItemLongClickListener(OnIdentifiableItemLongClickListener< this.listItemLongClickListener = listItemLongClickListener; } + public boolean isSingleChat() { + return channel.getMemberCount() <= 2; + } + + public List getMembers() { + return channel.getMembers(); + } + public static class Builder { private final Bundle bundle; private ChannelFragment customFragment;