Skip to content

Commit

Permalink
null object and channel qrcode.
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Apr 21, 2019
1 parent 643399f commit c70a675
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 52 deletions.
4 changes: 0 additions & 4 deletions chat/src/main/java/cn/wildfire/chat/app/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
29 changes: 20 additions & 9 deletions chat/src/main/java/cn/wildfire/chat/app/main/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions chat/src/main/java/cn/wildfire/chat/app/main/MeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions chat/src/main/java/cn/wildfire/chat/kit/WfcScheme.java
Original file line number Diff line number Diff line change
@@ -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/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,7 +44,7 @@ public MutableLiveData<OperateResult<String>> 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<String>(result, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
}
10 changes: 10 additions & 0 deletions chat/src/main/res/layout/conversation_info_channel_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
app:left_text_size="16sp"
app:right_text="channel desc" />

<com.lqr.optionitemview.OptionItemView
android:id="@+id/channelQRCodeOptionItemView"
style="@style/OptionItem"
android:background="@drawable/selector_option_item"
app:left_text="二维码"
app:left_text_color="@color/black0"
app:left_text_margin_left="@dimen/option_item_margin_left"
app:left_text_size="16sp"
app:right_src="@mipmap/qr_code" />

</LinearLayout>

<LinearLayout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cn.wildfirechat.model;

public class NullChannelInfo extends ChannelInfo {
public NullChannelInfo(String channelId) {
this.channelId = channelId;
this.name = "<" + channelId + ">";
this.owner = "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cn.wildfirechat.model;

public class NullChatRoomInfo extends ChatRoomInfo {
public NullChatRoomInfo(String chatRoomId) {
this.chatRoomId = chatRoomId;
this.title = "<" + chatRoomId + ">";
}
}
8 changes: 8 additions & 0 deletions client/src/main/java/cn/wildfirechat/model/NullGroupInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cn.wildfirechat.model;

public class NullGroupInfo extends GroupInfo {
public NullGroupInfo(String groupId) {
this.target = groupId;
this.name = "<" + groupId + ">";
}
}
Loading

0 comments on commit c70a675

Please sign in to comment.