diff --git a/chat/src/main/java/cn/wildfire/chat/app/Config.java b/chat/src/main/java/cn/wildfire/chat/app/Config.java index 0e4fa52bc..03d110434 100644 --- a/chat/src/main/java/cn/wildfire/chat/app/Config.java +++ b/chat/src/main/java/cn/wildfire/chat/app/Config.java @@ -18,10 +18,6 @@ public interface Config { String ICE_USERNAME = "wfchat"; String ICE_PASSWORD = "wfchat"; - String QR_CODE_PREFIX_PC_SESSION = "wildfirechat://pcsession/"; - String QR_CODE_PREFIX_USER = "wildfirechat://user/"; - String QR_CODE_PREFIX_GROUP = "wildfirechat://group/"; - int DEFAULT_MAX_AUDIO_RECORD_TIME_SECOND = 120; String VIDEO_SAVE_DIR = Environment.getExternalStorageDirectory().getPath() + "/wfc/video"; diff --git a/chat/src/main/java/cn/wildfire/chat/app/main/MainActivity.java b/chat/src/main/java/cn/wildfire/chat/app/main/MainActivity.java index 071de753b..935c2d529 100644 --- a/chat/src/main/java/cn/wildfire/chat/app/main/MainActivity.java +++ b/chat/src/main/java/cn/wildfire/chat/app/main/MainActivity.java @@ -12,6 +12,12 @@ import android.view.View; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProviders; +import androidx.viewpager.widget.ViewPager; + import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import com.google.android.material.bottomnavigation.BottomNavigationMenuView; @@ -23,14 +29,10 @@ import java.util.Arrays; import java.util.List; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProviders; -import androidx.viewpager.widget.ViewPager; import butterknife.Bind; -import cn.wildfire.chat.app.Config; import cn.wildfire.chat.kit.WfcBaseActivity; +import cn.wildfire.chat.kit.WfcScheme; +import cn.wildfire.chat.kit.channel.ChannelInfoActivity; import cn.wildfire.chat.kit.contact.ContactFragment; import cn.wildfire.chat.kit.contact.ContactViewModel; import cn.wildfire.chat.kit.contact.newfriend.SearchUserActivity; @@ -274,15 +276,18 @@ private void onScanPcQrCode(String qrcode) { // uri.getAuthority(); // uri.getQuery() switch (prefix) { - case Config.QR_CODE_PREFIX_PC_SESSION: + case WfcScheme.QR_CODE_PREFIX_PC_SESSION: pcLogin(value); break; - case Config.QR_CODE_PREFIX_USER: + case WfcScheme.QR_CODE_PREFIX_USER: showUser(value); break; - case Config.QR_CODE_PREFIX_GROUP: + case WfcScheme.QR_CODE_PREFIX_GROUP: joinGroup(value); break; + case WfcScheme.QR_CODE_PREFIX_CHANNEL: + subscribeChannel(value); + break; default: Toast.makeText(this, "qrcode: " + qrcode, Toast.LENGTH_SHORT).show(); break; @@ -313,6 +318,12 @@ private void joinGroup(String groupId) { startActivity(intent); } + private void subscribeChannel(String channelId) { + Intent intent = new Intent(this, ChannelInfoActivity.class); + intent.putExtra("channelId", channelId); + startActivity(intent); + } + private boolean checkDisplayName() { UserViewModel userViewModel = ViewModelProviders.of(this).get(UserViewModel.class); SharedPreferences sp = getSharedPreferences("config", Context.MODE_PRIVATE); diff --git a/chat/src/main/java/cn/wildfire/chat/app/main/MeFragment.java b/chat/src/main/java/cn/wildfire/chat/app/main/MeFragment.java index f4a44574b..2f7bcc99a 100644 --- a/chat/src/main/java/cn/wildfire/chat/app/main/MeFragment.java +++ b/chat/src/main/java/cn/wildfire/chat/app/main/MeFragment.java @@ -9,17 +9,18 @@ import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProviders; + import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.lqr.optionitemview.OptionItemView; import java.util.List; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.Observer; -import androidx.lifecycle.ViewModelProviders; import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; diff --git a/chat/src/main/java/cn/wildfire/chat/kit/WfcScheme.java b/chat/src/main/java/cn/wildfire/chat/kit/WfcScheme.java new file mode 100644 index 000000000..02aea2bd9 --- /dev/null +++ b/chat/src/main/java/cn/wildfire/chat/kit/WfcScheme.java @@ -0,0 +1,8 @@ +package cn.wildfire.chat.kit; + +public interface WfcScheme { + String QR_CODE_PREFIX_PC_SESSION = "wildfirechat://pcsession/"; + String QR_CODE_PREFIX_USER = "wildfirechat://user/"; + String QR_CODE_PREFIX_GROUP = "wildfirechat://group/"; + String QR_CODE_PREFIX_CHANNEL = "wildfirechat://channel/"; +} diff --git a/chat/src/main/java/cn/wildfire/chat/kit/channel/ChannelInfoActivity.java b/chat/src/main/java/cn/wildfire/chat/kit/channel/ChannelInfoActivity.java index e237fc17e..2afe05a9e 100644 --- a/chat/src/main/java/cn/wildfire/chat/kit/channel/ChannelInfoActivity.java +++ b/chat/src/main/java/cn/wildfire/chat/kit/channel/ChannelInfoActivity.java @@ -10,15 +10,16 @@ import android.widget.TextView; import android.widget.Toast; -import com.afollestad.materialdialogs.MaterialDialog; -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.RequestOptions; - import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProviders; + +import com.afollestad.materialdialogs.MaterialDialog; +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; + import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; @@ -65,6 +66,14 @@ public boolean onOptionsItemSelected(MenuItem item) { private void init() { Intent intent = getIntent(); channelInfo = intent.getParcelableExtra("channelInfo"); + channelViewModel = ViewModelProviders.of(this).get(ChannelViewModel.class); + + if (channelInfo == null) { + String channelId = intent.getStringExtra("channelId"); + if (!TextUtils.isEmpty(channelId)) { + channelInfo = channelViewModel.getChannelInfo(channelId, true); + } + } if (channelInfo == null) { finish(); return; @@ -75,7 +84,6 @@ private void init() { channelTextView.setText(channelInfo.name); channelDescTextView.setText(TextUtils.isEmpty(channelInfo.desc) ? "频道主什么也没写" : channelInfo.desc); - channelViewModel = ViewModelProviders.of(this).get(ChannelViewModel.class); UserViewModel userViewModel = ViewModelProviders.of(this).get(UserViewModel.class); if (channelInfo.owner.equals(userViewModel.getUserId())) { diff --git a/chat/src/main/java/cn/wildfire/chat/kit/channel/ChannelViewModel.java b/chat/src/main/java/cn/wildfire/chat/kit/channel/ChannelViewModel.java index 82ac429ba..cd01cbb97 100644 --- a/chat/src/main/java/cn/wildfire/chat/kit/channel/ChannelViewModel.java +++ b/chat/src/main/java/cn/wildfire/chat/kit/channel/ChannelViewModel.java @@ -1,10 +1,11 @@ package cn.wildfire.chat.kit.channel; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + import java.util.ArrayList; import java.util.List; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; import cn.wildfire.chat.kit.common.OperateResult; import cn.wildfire.chat.kit.third.utils.FileUtils; import cn.wildfirechat.message.MessageContentMediaType; @@ -43,7 +44,7 @@ public MutableLiveData> createChannel(String channelId, St ChatManager.Instance().uploadMedia(content, MessageContentMediaType.PORTRAIT.getValue(), new GeneralCallback2() { @Override public void onSuccess(String result) { - ChatManager.Instance().createChannel(channelId, channelName, channelPortrait, desc, extra, new GeneralCallback2() { + ChatManager.Instance().createChannel(channelId, channelName, result, desc, extra, new GeneralCallback2() { @Override public void onSuccess(String result) { resultLiveData.setValue(new OperateResult(result, 0)); diff --git a/chat/src/main/java/cn/wildfire/chat/kit/conversation/ChannelConversationInfoFragment.java b/chat/src/main/java/cn/wildfire/chat/kit/conversation/ChannelConversationInfoFragment.java index 7ea466658..ef285555b 100644 --- a/chat/src/main/java/cn/wildfire/chat/kit/conversation/ChannelConversationInfoFragment.java +++ b/chat/src/main/java/cn/wildfire/chat/kit/conversation/ChannelConversationInfoFragment.java @@ -8,22 +8,25 @@ import android.widget.CompoundButton; import android.widget.ImageView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProviders; + import com.bumptech.glide.Glide; import com.kyleduo.switchbutton.SwitchButton; import com.lqr.optionitemview.OptionItemView; import java.util.Arrays; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProviders; import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; +import cn.wildfire.chat.kit.WfcScheme; import cn.wildfire.chat.kit.channel.ChannelViewModel; import cn.wildfire.chat.kit.conversationlist.ConversationListViewModel; import cn.wildfire.chat.kit.conversationlist.ConversationListViewModelFactory; +import cn.wildfire.chat.kit.qrcode.QRCodeActivity; import cn.wildfirechat.chat.R; import cn.wildfirechat.model.ChannelInfo; import cn.wildfirechat.model.Conversation; @@ -47,6 +50,7 @@ public class ChannelConversationInfoFragment extends Fragment implements Compoun private ConversationInfo conversationInfo; private ConversationViewModel conversationViewModel; private ChannelViewModel channelViewModel; + private ChannelInfo channelInfo; public static ChannelConversationInfoFragment newInstance(ConversationInfo conversationInfo) { ChannelConversationInfoFragment fragment = new ChannelConversationInfoFragment(); @@ -77,7 +81,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c private void init() { conversationViewModel = ViewModelProviders.of(this, new ConversationViewModelFactory(conversationInfo.conversation)).get(ConversationViewModel.class); channelViewModel = ViewModelProviders.of(this).get(ChannelViewModel.class); - ChannelInfo channelInfo = channelViewModel.getChannelInfo(conversationInfo.conversation.target, true); + channelInfo = channelViewModel.getChannelInfo(conversationInfo.conversation.target, true); if (channelInfo != null) { initChannel(channelInfo); @@ -111,6 +115,13 @@ void clearMessage() { conversationViewModel.clearConversationMessage(conversationInfo.conversation); } + @OnClick(R.id.channelQRCodeOptionItemView) + void showChannelQRCode() { + String qrCodeValue = WfcScheme.QR_CODE_PREFIX_CHANNEL + channelInfo.channelId; + Intent intent = QRCodeActivity.buildQRCodeIntent(getActivity(), "频道二维码", channelInfo.portrait, qrCodeValue); + startActivity(intent); + } + @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { diff --git a/chat/src/main/java/cn/wildfire/chat/kit/conversation/GroupConversationInfoFragment.java b/chat/src/main/java/cn/wildfire/chat/kit/conversation/GroupConversationInfoFragment.java index 3fed58b11..9e304341d 100644 --- a/chat/src/main/java/cn/wildfire/chat/kit/conversation/GroupConversationInfoFragment.java +++ b/chat/src/main/java/cn/wildfire/chat/kit/conversation/GroupConversationInfoFragment.java @@ -11,6 +11,14 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProviders; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.afollestad.materialdialogs.MaterialDialog; import com.kyleduo.switchbutton.SwitchButton; import com.lqr.optionitemview.OptionItemView; @@ -20,17 +28,10 @@ import java.util.Collections; import java.util.List; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.Observer; -import androidx.lifecycle.ViewModelProviders; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; -import cn.wildfire.chat.app.Config; +import cn.wildfire.chat.kit.WfcScheme; import cn.wildfire.chat.kit.common.OperateResult; import cn.wildfire.chat.kit.contact.ContactViewModel; import cn.wildfire.chat.kit.conversationlist.ConversationListViewModel; @@ -234,12 +235,11 @@ void clearMessage() { @OnClick(R.id.groupQRCodeOptionItemView) void showGroupQRCode() { - String qrCodeValue = Config.QR_CODE_PREFIX_GROUP + groupInfo.target; + String qrCodeValue = WfcScheme.QR_CODE_PREFIX_GROUP + groupInfo.target; Intent intent = QRCodeActivity.buildQRCodeIntent(getActivity(), "群二维码", groupInfo.portrait, qrCodeValue); startActivity(intent); } - @Override public void onUserMemberClick(UserInfo userInfo) { Intent intent = new Intent(getActivity(), UserInfoActivity.class); diff --git a/chat/src/main/java/cn/wildfire/chat/kit/user/UserInfoFragment.java b/chat/src/main/java/cn/wildfire/chat/kit/user/UserInfoFragment.java index 8fd0826e7..79006388e 100644 --- a/chat/src/main/java/cn/wildfire/chat/kit/user/UserInfoFragment.java +++ b/chat/src/main/java/cn/wildfire/chat/kit/user/UserInfoFragment.java @@ -11,6 +11,12 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModelProviders; + import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.lqr.imagepicker.ImagePicker; @@ -19,15 +25,10 @@ import java.util.ArrayList; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModelProviders; import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; -import cn.wildfire.chat.app.Config; +import cn.wildfire.chat.kit.WfcScheme; import cn.wildfire.chat.kit.WfcUIKit; import cn.wildfire.chat.kit.common.OperateResult; import cn.wildfire.chat.kit.contact.ContactViewModel; @@ -208,7 +209,7 @@ void invite() { @OnClick(R.id.qrCodeOptionItemView) void showMyQRCode() { UserInfo userInfo = userViewModel.getUserInfo(userViewModel.getUserId(), false); - String qrCodeValue = Config.QR_CODE_PREFIX_USER + userInfo.uid; + String qrCodeValue = WfcScheme.QR_CODE_PREFIX_USER + userInfo.uid; startActivity(QRCodeActivity.buildQRCodeIntent(getActivity(), "二维码", userInfo.portrait, qrCodeValue)); } } diff --git a/chat/src/main/res/layout/conversation_info_channel_fragment.xml b/chat/src/main/res/layout/conversation_info_channel_fragment.xml index b20dd0238..4956bb2b9 100644 --- a/chat/src/main/res/layout/conversation_info_channel_fragment.xml +++ b/chat/src/main/res/layout/conversation_info_channel_fragment.xml @@ -57,6 +57,16 @@ app:left_text_size="16sp" app:right_text="channel desc" /> + + "; + this.owner = ""; + } +} diff --git a/client/src/main/java/cn/wildfirechat/model/NullChatRoomInfo.java b/client/src/main/java/cn/wildfirechat/model/NullChatRoomInfo.java new file mode 100644 index 000000000..5c737f212 --- /dev/null +++ b/client/src/main/java/cn/wildfirechat/model/NullChatRoomInfo.java @@ -0,0 +1,8 @@ +package cn.wildfirechat.model; + +public class NullChatRoomInfo extends ChatRoomInfo { + public NullChatRoomInfo(String chatRoomId) { + this.chatRoomId = chatRoomId; + this.title = "<" + chatRoomId + ">"; + } +} \ No newline at end of file diff --git a/client/src/main/java/cn/wildfirechat/model/NullGroupInfo.java b/client/src/main/java/cn/wildfirechat/model/NullGroupInfo.java new file mode 100644 index 000000000..5f1fefce5 --- /dev/null +++ b/client/src/main/java/cn/wildfirechat/model/NullGroupInfo.java @@ -0,0 +1,8 @@ +package cn.wildfirechat.model; + +public class NullGroupInfo extends GroupInfo { + public NullGroupInfo(String groupId) { + this.target = groupId; + this.name = "<" + groupId + ">"; + } +} diff --git a/client/src/main/java/cn/wildfirechat/remote/ChatManager.java b/client/src/main/java/cn/wildfirechat/remote/ChatManager.java index 18aba64a3..6253e000f 100644 --- a/client/src/main/java/cn/wildfirechat/remote/ChatManager.java +++ b/client/src/main/java/cn/wildfirechat/remote/ChatManager.java @@ -65,6 +65,8 @@ import cn.wildfirechat.model.ModifyChannelInfoType; import cn.wildfirechat.model.ModifyGroupInfoType; import cn.wildfirechat.model.ModifyMyInfoEntry; +import cn.wildfirechat.model.NullChannelInfo; +import cn.wildfirechat.model.NullGroupInfo; import cn.wildfirechat.model.NullUserInfo; import cn.wildfirechat.model.UnreadCount; import cn.wildfirechat.model.UserInfo; @@ -660,11 +662,15 @@ public void run() { public @Nullable ChannelInfo getChannelInfo(String channelId, boolean refresh) { if (!checkRemoteService()) { - return null; + return new NullChannelInfo(channelId); } try { - return mClient.getChannelInfo(channelId, refresh); + ChannelInfo channelInfo = mClient.getChannelInfo(channelId, refresh); + if (channelInfo == null) { + channelInfo = new NullChannelInfo(channelId); + } + return channelInfo; } catch (RemoteException e) { e.printStackTrace(); return null; @@ -1973,11 +1979,15 @@ public void run() { public @Nullable GroupInfo getGroupInfo(String groupId, boolean refresh) { if (!checkRemoteService()) { - return null; + return new NullGroupInfo(groupId); } try { - return mClient.getGroupInfo(groupId, refresh); + GroupInfo groupInfo = mClient.getGroupInfo(groupId, refresh); + if (groupInfo == null) { + groupInfo = new NullGroupInfo(groupId); + } + return groupInfo; } catch (RemoteException e) { e.printStackTrace(); return null;