update
This commit is contained in:
@@ -1,10 +1,76 @@
|
||||
package com.shayu.onetoone;
|
||||
|
||||
import androidx.multidex.MultiDexApplication;
|
||||
|
||||
public class AppContext extends MultiDexApplication {
|
||||
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Process;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.facebook.FacebookSdk;
|
||||
import com.shayu.onetoone.activity.fragments.message.ChatMessageFragment;
|
||||
import com.shayu.onetoone.activity.message.ChatActivity;
|
||||
import com.shayu.onetoone.utils.NeverCrashUtils;
|
||||
import com.yunbao.common.BuildConfig;
|
||||
import com.yunbao.common.CommonAppContext;
|
||||
import com.yunbao.common.manager.imrongcloud.InstructorSendRewardProvider;
|
||||
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
|
||||
import com.yunbao.common.utils.AppManager;
|
||||
|
||||
import io.rong.imkit.RongIM;
|
||||
import io.rong.imkit.config.RongConfigCenter;
|
||||
import io.rong.imkit.utils.RouteUtils;
|
||||
import io.rong.imlib.IMLibRTCClient;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.model.Message;
|
||||
|
||||
public class AppContext extends CommonAppContext {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
NeverCrashUtils.getInstance()
|
||||
.setDebugMode(BuildConfig.DEBUG)
|
||||
.setMainCrashHandler((t, e) -> {
|
||||
Log.e("ApplicationError", "主线程异常");//此处log只是展示,当debug为true时,主类内部log会打印异常信息
|
||||
e.printStackTrace();
|
||||
AppManager.runDebugCode(() -> {
|
||||
//闪退后finish所有Activity并且杀死进程
|
||||
Process.killProcess(Process.myPid());
|
||||
System.exit(0);
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
throw new RuntimeException(e);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
})
|
||||
.setUncaughtCrashHandler((t, e) -> {
|
||||
Log.e("ApplicationError", "子线程异常");//此处log只是展示,当debug为true时,主类内部log会打印异常信息
|
||||
e.printStackTrace();
|
||||
})
|
||||
.register(this);
|
||||
FacebookSdk.setApplicationId("126035687816994");
|
||||
ARouter.openLog();
|
||||
ARouter.openDebug();
|
||||
ARouter.printStackTrace();
|
||||
ARouter.init(this);
|
||||
|
||||
String appKey = "pvxdm17jpd3hr";
|
||||
boolean enablePush = true;
|
||||
RongIM.init(this, appKey, enablePush);
|
||||
|
||||
RongcloudIMManager.initRongIM(this);
|
||||
RongConfigCenter.conversationConfig().addMessageProvider(new InstructorSendRewardProvider(getApplicationContext()));
|
||||
RongcloudIMManager.addRongcloudIMOnReceiveMessageListener(new RongIMClient.OnReceiveMessageWrapperListener() {
|
||||
@Override
|
||||
public boolean onReceived(Message message, int left, boolean hasPackage, boolean offline) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
RouteUtils.registerActivity(RouteUtils.RongActivityType.ConversationActivity, ChatActivity.class);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.shayu.onetoone.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
|
||||
public abstract class AbsOTOActivity extends AppCompatActivity {
|
||||
public Context mContext;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getLayoutId());
|
||||
mContext = this;
|
||||
main(savedInstanceState);
|
||||
View view=findViewById(R.id.btn_back);
|
||||
if(view!=null){
|
||||
view.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int getLayoutId();
|
||||
|
||||
protected abstract void main(Bundle savedInstanceState);
|
||||
|
||||
public void setTitle(String title) {
|
||||
TextView view = findViewById(R.id.title);
|
||||
if (view != null) {
|
||||
view.setText(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.shayu.onetoone.activity;
|
||||
|
||||
import static com.yunbao.common.CommonAppContext.home_zdy_img_cn;
|
||||
import static com.yunbao.common.CommonAppContext.home_zdy_img_us;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.blankj.utilcode.util.DeviceUtils;
|
||||
import com.blankj.utilcode.util.GsonUtils;
|
||||
import com.lzy.okgo.model.Response;
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.manager.RouteManager;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.CommonAppContext;
|
||||
import com.yunbao.common.bean.IMLoginModel;
|
||||
import com.yunbao.common.bean.UserBean;
|
||||
import com.yunbao.common.event.UpdateTablePointMe;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.http.HttpClient;
|
||||
import com.yunbao.common.http.JsonBean;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.manager.NoviceInstructorManager;
|
||||
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
|
||||
import com.yunbao.common.utils.SpUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LauncherActivity extends AbsOTOActivity {
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_launcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void main(Bundle savedInstanceState) {
|
||||
//临时用的登录代码,将就下
|
||||
HttpClient.getInstance().get("Login.userLogin", "setLoginInfo")
|
||||
.params("user_login", "95001")
|
||||
.params("user_pass", "123")
|
||||
.params("pushid", "")
|
||||
.params("lastlogindevice", "Android")
|
||||
.params("uuid_Device", DeviceUtils.getUniqueDeviceId())
|
||||
.execute(new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if (code == 0 && info.length > 0) {
|
||||
JSONObject obj = JSON.parseObject(info[0]);
|
||||
String uid = obj.getString("id");
|
||||
String token = obj.getString("token");
|
||||
// mFirstLogin = obj.getIntValue("first_login") == 1;
|
||||
// mShowInvite = obj.getIntValue("isagent") == 1;
|
||||
CommonAppConfig.getInstance().setLoginInfo(uid, token, true);
|
||||
//设置登录信息
|
||||
IMLoginModel model = GsonUtils.fromJson(info[0], IMLoginModel.class);
|
||||
IMLoginManager.get(mContext).setupLoginUser(model);
|
||||
connectRongCloud();
|
||||
} else {
|
||||
ToastUtil.show(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void connectRongCloud() {
|
||||
HttpClient.getInstance().get("User.getBaseInfos", "getBaseInfo")
|
||||
.execute(new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if (code == 0 && info.length > 0) {
|
||||
IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).upDataUserInfo(info[0]);
|
||||
JSONObject obj = JSON.parseObject(info[0]);
|
||||
UserBean bean = JSON.toJavaObject(obj, UserBean.class);
|
||||
bean.setMedalName(obj.getString("medal_name"));
|
||||
bean.setMedalLevel(obj.getIntValue("medal_level"));
|
||||
CommonAppConfig.getInstance().setUserBean(bean);
|
||||
CommonAppConfig.getInstance().setUserItemList(obj.getString("list"));
|
||||
bean.seUserInfoComplete(obj.getIntValue("user_info_complete"));
|
||||
SpUtil.getInstance().setStringValue(SpUtil.USER_INFO, info[0]);
|
||||
|
||||
|
||||
//融云连接服务器
|
||||
RongcloudIMManager.connectIM(mContext);
|
||||
HttpClient.getInstance().post("Home.getRandJoinAnchor", "Home.getRandJoinAnchor")
|
||||
.execute(new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.toString(info));
|
||||
RouteManager.forwardMainActivity();
|
||||
finish();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<JsonBean> response) {
|
||||
super.onError(response);
|
||||
String message = response.message();
|
||||
System.out.println(">>>>>" + message);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,24 @@
|
||||
package com.shayu.onetoone.activitys;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
package com.shayu.onetoone.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.angcyo.tablayout.DslTabLayout;
|
||||
import com.angcyo.tablayout.DslTabLayoutConfig;
|
||||
import com.angcyo.tablayout.delegate2.ViewPager2Delegate;
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.activitys.fragments.BaseFragment;
|
||||
import com.shayu.onetoone.activitys.fragments.DynamicFragment;
|
||||
import com.shayu.onetoone.activitys.fragments.FriendsFragment;
|
||||
import com.shayu.onetoone.activitys.fragments.MessageFragment;
|
||||
import com.shayu.onetoone.activitys.fragments.MyFragment;
|
||||
import com.shayu.onetoone.activity.fragments.BaseFragment;
|
||||
import com.shayu.onetoone.activity.fragments.DynamicFragment;
|
||||
import com.shayu.onetoone.activity.fragments.FriendsFragment;
|
||||
import com.shayu.onetoone.activity.fragments.MessageFragment;
|
||||
import com.shayu.onetoone.activity.fragments.MyFragment;
|
||||
import com.shayu.onetoone.manager.RouteManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -26,16 +27,14 @@ import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.jvm.functions.Function4;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
@Route(path = RouteManager.ACTIVITY_MAIN)
|
||||
public class MainActivity extends AbsOTOActivity {
|
||||
List<BaseFragment> fragments = new ArrayList<>();
|
||||
private ViewPager2 viewPager;
|
||||
private DslTabLayout dslTabLayout;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
protected void main(Bundle savedInstanceState) {
|
||||
fragments.add(new FriendsFragment());
|
||||
fragments.add(new DynamicFragment());
|
||||
fragments.add(new MessageFragment());
|
||||
@@ -56,8 +55,29 @@ public class MainActivity extends AppCompatActivity {
|
||||
return fragments.size();
|
||||
}
|
||||
});
|
||||
|
||||
viewPager.setUserInputEnabled(false);
|
||||
ViewPager2Delegate.Companion.install(viewPager, dslTabLayout, false);
|
||||
|
||||
dslTabLayout.configTabLayoutConfig(new Function1<DslTabLayoutConfig, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(DslTabLayoutConfig dslTabLayoutConfig) {
|
||||
dslTabLayoutConfig.setOnSelectItemView(new Function4<View, Integer, Boolean, Boolean, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(View itemView, Integer index, Boolean select, Boolean fromUse) {
|
||||
if (select) {
|
||||
viewPager.setCurrentItem(index);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.shayu.onetoone.activity.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
public Context mContext;
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View itemView = createView(inflater, container, savedInstanceState);
|
||||
this.mContext = getContext();
|
||||
initView(itemView);
|
||||
return itemView;
|
||||
}
|
||||
|
||||
public abstract void initView(View itemView);
|
||||
|
||||
public abstract View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.shayu.onetoone.activity.fragments;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
|
||||
public class DynamicFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
public void initView(View itemView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_dynamic, container, false);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.shayu.onetoone.activitys.fragments;
|
||||
package com.shayu.onetoone.activity.fragments;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
@@ -6,15 +6,16 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
|
||||
public class FriendsFragment extends BaseFragment {
|
||||
@Nullable
|
||||
@Override
|
||||
public void initView(View itemView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_friends, container, false);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.shayu.onetoone.activitys.fragments;
|
||||
package com.shayu.onetoone.activity.fragments;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
@@ -7,7 +7,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
@@ -15,9 +14,11 @@ import androidx.viewpager2.widget.ViewPager2;
|
||||
import com.angcyo.tablayout.DslTabLayout;
|
||||
import com.angcyo.tablayout.DslTabLayoutConfig;
|
||||
import com.angcyo.tablayout.delegate2.ViewPager2Delegate;
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.activitys.message.MsgFriendFragment;
|
||||
import com.shayu.onetoone.activitys.message.MsgMessageFragment;
|
||||
import com.shayu.onetoone.activity.fragments.message.MsgFriendFragment;
|
||||
import com.shayu.onetoone.activity.fragments.message.MsgMessageFragment;
|
||||
import com.shayu.onetoone.dialog.MsgMoreDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -26,20 +27,24 @@ import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.jvm.functions.Function4;
|
||||
|
||||
public class MessageFragment extends BaseFragment {
|
||||
public class MessageFragment extends BaseFragment implements View.OnClickListener {
|
||||
List<BaseFragment> fragments = new ArrayList<>();
|
||||
View more;
|
||||
XPopup.Builder moreXPopup;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_msg, container, false);
|
||||
initView(view);
|
||||
return view;
|
||||
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_msg, container, false);
|
||||
}
|
||||
|
||||
private void initView(View itemView) {
|
||||
@Override
|
||||
public void initView(View itemView) {
|
||||
ViewPager2 viewPager2 = itemView.findViewById(R.id.viewPager);
|
||||
DslTabLayout tabLayout = itemView.findViewById(R.id.dslTabLayout);
|
||||
more = itemView.findViewById(R.id.more);
|
||||
more.setOnClickListener(this);
|
||||
moreXPopup = new XPopup.Builder(getContext()).watchView(more);
|
||||
viewPager2.setUserInputEnabled(false);
|
||||
//绑定ViewPager2到tabLayout
|
||||
ViewPager2Delegate.Companion.install(viewPager2, tabLayout, false);
|
||||
|
||||
@@ -74,4 +79,17 @@ public class MessageFragment extends BaseFragment {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showMoreDialog() {
|
||||
moreXPopup.asCustom(new MsgMoreDialog(mContext)).show();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
if (id == R.id.more) {
|
||||
showMoreDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.shayu.onetoone.activity.fragments;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
|
||||
public class MyFragment extends BaseFragment {
|
||||
@Override
|
||||
public void initView(View itemView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.activity_msg_config, container, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.shayu.onetoone.activity.fragments.message;
|
||||
|
||||
import static io.rong.imkit.conversation.extension.component.inputpanel.InputPanel.InputStyle.STYLE_CONTAINER_EXTENSION;
|
||||
import static io.rong.imkit.conversation.extension.component.inputpanel.InputPanel.InputStyle.STYLE_SWITCH_CONTAINER_EXTENSION;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import io.rong.imkit.IMCenter;
|
||||
import io.rong.imkit.conversation.ConversationFragment;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.Message;
|
||||
import io.rong.message.TextMessage;
|
||||
|
||||
public class ChatMessageFragment extends ConversationFragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE;
|
||||
String targetId = "user1";
|
||||
Message.SentStatus sentStatus = Message.SentStatus.SENT;
|
||||
TextMessage content = TextMessage.obtain("这里是消息内容");
|
||||
long sentTime = System.currentTimeMillis();
|
||||
IMCenter.getInstance().insertOutgoingMessage(conversationType, targetId, sentStatus, content, sentTime, new RongIMClient.ResultCallback<Message>() {
|
||||
@Override
|
||||
public void onSuccess(Message message) {
|
||||
ToastUtil.show("消息发送成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(RongIMClient.ErrorCode e) {
|
||||
ToastUtil.show("消息发送失败:"+e.msg);
|
||||
Log.i("聊天", "onError: "+e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.shayu.onetoone.activity.fragments.message;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.activity.fragments.BaseFragment;
|
||||
|
||||
public class MsgFriendFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
public void initView(View itemView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_msg_friend, container, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.shayu.onetoone.activity.fragments.message;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.activity.fragments.BaseFragment;
|
||||
import com.shayu.onetoone.adapter.MsgMessageRecyclerViewAdapter;
|
||||
import com.shayu.onetoone.bean.MsgMessageBean;
|
||||
import com.shayu.onetoone.manager.RouteManager;
|
||||
import com.yanzhenjie.recyclerview.OnItemClickListener;
|
||||
import com.yanzhenjie.recyclerview.OnItemMenuClickListener;
|
||||
import com.yanzhenjie.recyclerview.SwipeMenuBridge;
|
||||
import com.yanzhenjie.recyclerview.SwipeMenuCreator;
|
||||
import com.yanzhenjie.recyclerview.SwipeMenuItem;
|
||||
import com.yanzhenjie.recyclerview.SwipeRecyclerView;
|
||||
import com.yunbao.common.utils.DpUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.imkit.utils.RouteUtils;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.ConversationIdentifier;
|
||||
|
||||
public class MsgMessageFragment extends BaseFragment {
|
||||
SwipeRecyclerView recyclerView;
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
ConstraintLayout netError;
|
||||
MsgMessageRecyclerViewAdapter adapter;
|
||||
List<MsgMessageBean> list;
|
||||
|
||||
@Override
|
||||
public void initView(View itemView) {
|
||||
recyclerView = itemView.findViewById(R.id.recyclerView);
|
||||
swipeRefreshLayout = itemView.findViewById(R.id.swipeRefreshLayout);
|
||||
netError = itemView.findViewById(R.id.net_error);
|
||||
adapter = new MsgMessageRecyclerViewAdapter(getContext());
|
||||
list = new ArrayList<>();
|
||||
initData();
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
|
||||
recyclerView.setSwipeMenuCreator(initSwipeMenuCreator());
|
||||
initMoreListener();
|
||||
initRefreshListener();
|
||||
recyclerView.setOnItemMenuClickListener(new OnItemMenuClickListener() {
|
||||
@Override
|
||||
public void onItemClick(SwipeMenuBridge menuBridge, int adapterPosition) {
|
||||
menuBridge.closeMenu();
|
||||
if (menuBridge.getPosition() == 0) {
|
||||
ToastUtil.showDebug("置顶:" + adapter.getList().get(adapterPosition).getNickname());
|
||||
} else {
|
||||
ToastUtil.showDebug("删除:" + adapter.getList().get(adapterPosition).getNickname());
|
||||
adapter.getList().remove(adapterPosition);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
recyclerView.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(View view, int i) {
|
||||
RouteManager.forwardMsgChatActivity();
|
||||
}
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
adapter.setList(list);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_msg_message, container, false);
|
||||
}
|
||||
|
||||
private SwipeMenuCreator initSwipeMenuCreator() {
|
||||
SwipeMenuCreator creator = (leftMenu, rightMenu, position) -> {
|
||||
SwipeMenuItem top = new SwipeMenuItem(getContext());
|
||||
SwipeMenuItem del = new SwipeMenuItem(getContext());
|
||||
top.setBackgroundColor(Color.parseColor("#D9D9D9"));
|
||||
del.setBackgroundColor(Color.parseColor("#FE5268"));
|
||||
top.setText("置顶");
|
||||
del.setText("删除");
|
||||
top.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
top.setWidth(DpUtil.dp2px(71));
|
||||
del.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
del.setWidth(DpUtil.dp2px(71));
|
||||
|
||||
rightMenu.addMenuItem(top);
|
||||
rightMenu.addMenuItem(del);
|
||||
|
||||
};
|
||||
return creator;
|
||||
}
|
||||
|
||||
private void initMoreListener() {
|
||||
SwipeRecyclerView.LoadMoreListener moreListener = new SwipeRecyclerView.LoadMoreListener() {
|
||||
@Override
|
||||
public void onLoadMore() {
|
||||
List<MsgMessageBean> tmp =
|
||||
new ArrayList<>(list);
|
||||
initData();
|
||||
tmp.addAll(list);
|
||||
adapter.setList(tmp);
|
||||
list = new ArrayList<>(tmp);
|
||||
recyclerView.loadMoreFinish(false, true);
|
||||
}
|
||||
};
|
||||
recyclerView.setLoadMoreListener(moreListener);
|
||||
}
|
||||
|
||||
private void initRefreshListener() {
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
initData();
|
||||
adapter.setList(list);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
list = new ArrayList<>();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
MsgMessageBean bean = new MsgMessageBean();
|
||||
bean.setId(i);
|
||||
bean.setNickname("名字" + i);
|
||||
bean.setContent("内容" + i);
|
||||
bean.setTime("时间:" + i);
|
||||
if (i % 5 == 0) {
|
||||
bean.setNotRead(true);
|
||||
bean.setNotReadNum(i);
|
||||
}
|
||||
if (i % 2 == 0) {
|
||||
bean.setAvatar("https://downs.yaoulive.com/%E4%BA%A4%E5%8F%89%2015%403x.png");
|
||||
} else {
|
||||
bean.setAvatar("https://downs.yaoulive.com/%E4%BA%A4%E5%8F%89%2014%403x.png");
|
||||
}
|
||||
list.add(bean);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.shayu.onetoone.activity.message;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.activity.AbsOTOActivity;
|
||||
import com.shayu.onetoone.activity.fragments.message.ChatMessageFragment;
|
||||
import com.shayu.onetoone.manager.RouteManager;
|
||||
|
||||
import io.rong.imkit.conversation.ConversationFragment;
|
||||
|
||||
@Route(path = RouteManager.ACTIVITY_MSG_CHAT)
|
||||
public class ChatActivity extends AbsOTOActivity {
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_msg_chat;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void main(Bundle savedInstanceState) {
|
||||
ConversationFragment conversationFragment = new ChatMessageFragment();
|
||||
FragmentManager manager = getSupportFragmentManager();
|
||||
FragmentTransaction transaction = manager.beginTransaction();
|
||||
transaction.replace(R.id.container, conversationFragment);
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.shayu.onetoone.activity.message;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.activity.AbsOTOActivity;
|
||||
import com.shayu.onetoone.adapter.MsgGreetConfigAdapter;
|
||||
import com.shayu.onetoone.bean.MsgGreetConfigBean;
|
||||
import com.shayu.onetoone.manager.RouteManager;
|
||||
import com.yunbao.common.interfaces.OnItemClickListener;
|
||||
|
||||
@Route(path = RouteManager.ACTIVITY_MSG_MORE_CONFIG_ACTIVITY)
|
||||
public class MsgMoreConfigActivity extends AbsOTOActivity {
|
||||
RecyclerView recyclerView;
|
||||
MsgGreetConfigAdapter adapter;
|
||||
SwitchCompat msgSwitch;
|
||||
View add;
|
||||
View editLayout;
|
||||
Button cancel, apply;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_msg_config;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void main(Bundle savedInstanceState) {
|
||||
setTitle("打招呼設置");
|
||||
recyclerView = findViewById(R.id.msg_recyclerView);
|
||||
msgSwitch = findViewById(R.id.msg_switch);
|
||||
add = findViewById(R.id.add_msg);
|
||||
cancel = findViewById(R.id.btn_cancel);
|
||||
apply = findViewById(R.id.btn_apply);
|
||||
editLayout = findViewById(R.id.edit_layout);
|
||||
|
||||
adapter = new MsgGreetConfigAdapter(this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
||||
recyclerView.setAdapter(adapter);
|
||||
adapter.setDeleteListener((size, position) -> {
|
||||
if (size >= 10) {
|
||||
add.setVisibility(View.GONE);
|
||||
} else {
|
||||
add.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
add.setOnClickListener(v -> {
|
||||
adapter.addItem(new MsgGreetConfigBean());
|
||||
if (adapter.getItemCount() >= 10) {
|
||||
add.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
msgSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> editLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.shayu.onetoone.activitys;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
|
||||
public class LauncherActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_launcher);
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.shayu.onetoone.activitys.fragments;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class BaseFragment extends Fragment {
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.shayu.onetoone.activitys.fragments;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
|
||||
public class DynamicFragment extends BaseFragment {
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_dynamic, container, false);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.shayu.onetoone.activitys.fragments;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
|
||||
public class MyFragment extends BaseFragment {
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_my, container, false);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.shayu.onetoone.activitys.message;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.activitys.fragments.BaseFragment;
|
||||
|
||||
public class MsgFriendFragment extends BaseFragment {
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_msg_friend,container,false);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.shayu.onetoone.activitys.message;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.activitys.fragments.BaseFragment;
|
||||
|
||||
public class MsgMessageFragment extends BaseFragment {
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_msg_message, container, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.shayu.onetoone.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.bean.MsgGreetConfigBean;
|
||||
import com.yunbao.common.interfaces.OnItemClickListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MsgGreetConfigAdapter extends RecyclerView.Adapter<MsgGreetConfigAdapter.ViewHolder> {
|
||||
List<MsgGreetConfigBean> mList;
|
||||
Context mContext;
|
||||
OnItemClickListener<Integer> deleteListener;
|
||||
|
||||
public MsgGreetConfigAdapter(Context mContext) {
|
||||
this.mContext = mContext;
|
||||
this.mList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setList(List<MsgGreetConfigBean> mList) {
|
||||
this.mList = mList;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setDeleteListener(OnItemClickListener<Integer> deleteListener) {
|
||||
this.deleteListener = deleteListener;
|
||||
}
|
||||
|
||||
public List<MsgGreetConfigBean> getNotEmptyList() {
|
||||
List<MsgGreetConfigBean> tmp = new ArrayList<>();
|
||||
for (MsgGreetConfigBean bean : mList) {
|
||||
if (bean.getContent() != null) {
|
||||
tmp.add(bean);
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
||||
return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_msg_greet_config, viewGroup, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
|
||||
viewHolder.setData(mList.get(i), i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
|
||||
public void addItem(MsgGreetConfigBean msgGreetConfigBean) {
|
||||
mList.add(msgGreetConfigBean);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private EditText editText;
|
||||
private View edit;
|
||||
private View del;
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
editText = itemView.findViewById(R.id.editTextText);
|
||||
edit = itemView.findViewById(R.id.edit);
|
||||
del = itemView.findViewById(R.id.del);
|
||||
editText.setEnabled(false);
|
||||
}
|
||||
|
||||
public void setData(MsgGreetConfigBean bean, int position) {
|
||||
del.setOnClickListener(v -> {
|
||||
mList.remove(position);
|
||||
if (deleteListener != null) {
|
||||
deleteListener.onItemClick(mList.size(), position);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
edit.setOnClickListener(v -> {
|
||||
editText.setEnabled(true);
|
||||
editText.requestFocus();
|
||||
});
|
||||
if (bean.getContent() == null) {
|
||||
editText.setEnabled(true);
|
||||
editText.setText("");
|
||||
} else {
|
||||
editText.setText(bean.getContent());
|
||||
editText.setEnabled(false);
|
||||
}
|
||||
|
||||
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
Log.i("编辑", "onFocusChange: " + hasFocus);
|
||||
if (!hasFocus && editText.getText().toString().length() > 0) {
|
||||
mList.get(position).setContent(editText.getText().toString());
|
||||
editText.setEnabled(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.shayu.onetoone.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.bean.MsgMessageBean;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MsgMessageRecyclerViewAdapter extends RecyclerView.Adapter<MsgMessageRecyclerViewAdapter.ViewHolder> {
|
||||
List<MsgMessageBean> list;
|
||||
Context mContext;
|
||||
|
||||
public MsgMessageRecyclerViewAdapter(Context mContext) {
|
||||
this.mContext = mContext;
|
||||
}
|
||||
|
||||
public void setList(List<MsgMessageBean> list) {
|
||||
this.list = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public List<MsgMessageBean> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_msg_message, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
holder.setData(list.get(position), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView avatar;
|
||||
TextView name;
|
||||
TextView content;
|
||||
TextView time;
|
||||
TextView read;
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
avatar = itemView.findViewById(R.id.msg_message_avatar);
|
||||
name = itemView.findViewById(R.id.msg_message_title);
|
||||
content = itemView.findViewById(R.id.msg_message_content);
|
||||
time = itemView.findViewById(R.id.msg_message_content_time);
|
||||
read = itemView.findViewById(R.id.msg_message_content_not_read);
|
||||
}
|
||||
|
||||
public void setData(MsgMessageBean bean, int position) {
|
||||
if (bean.isNotRead()) {
|
||||
read.setVisibility(View.VISIBLE);
|
||||
read.setText(bean.getNotReadNum() + "");
|
||||
} else {
|
||||
read.setVisibility(View.GONE);
|
||||
}
|
||||
ImgLoader.display(mContext, bean.getAvatar(), avatar);
|
||||
name.setText(bean.getNickname());
|
||||
content.setText(bean.getContent());
|
||||
time.setText(String.format("·%s", bean.getTime()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.shayu.onetoone.bean;
|
||||
|
||||
import com.yunbao.common.bean.BaseModel;
|
||||
|
||||
public class MsgGreetConfigBean extends BaseModel {
|
||||
private int id;
|
||||
private String content;
|
||||
|
||||
public MsgGreetConfigBean(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public MsgGreetConfigBean() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MsgGreetConfigBean{" +
|
||||
"id=" + id +
|
||||
", content='" + content + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.shayu.onetoone.bean;
|
||||
|
||||
import com.yunbao.common.bean.BaseModel;
|
||||
|
||||
public class MsgMessageBean extends BaseModel {
|
||||
private int id;
|
||||
private String avatar;
|
||||
private String nickname;
|
||||
private String content;
|
||||
private String time;
|
||||
private boolean isNotRead;//是否有未读
|
||||
private int notReadNum;//未读数量
|
||||
|
||||
public MsgMessageBean() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public boolean isNotRead() {
|
||||
return isNotRead;
|
||||
}
|
||||
|
||||
public void setNotRead(boolean notRead) {
|
||||
isNotRead = notRead;
|
||||
}
|
||||
|
||||
public int getNotReadNum() {
|
||||
return notReadNum;
|
||||
}
|
||||
|
||||
public void setNotReadNum(int notReadNum) {
|
||||
this.notReadNum = notReadNum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MsgMessageBean{" +
|
||||
"id=" + id +
|
||||
", avatar='" + avatar + '\'' +
|
||||
", nickname='" + nickname + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
", time='" + time + '\'' +
|
||||
", isNotRead=" + isNotRead +
|
||||
", notReadNum=" + notReadNum +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.shayu.onetoone.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.lxj.xpopup.core.AttachPopupView;
|
||||
import com.shayu.onetoone.R;
|
||||
import com.shayu.onetoone.manager.RouteManager;
|
||||
|
||||
public class MsgMoreDialog extends AttachPopupView implements View.OnClickListener {
|
||||
View config, read;
|
||||
|
||||
public MsgMoreDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getImplLayoutId() {
|
||||
return R.layout.dialog_msg_more;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate() {
|
||||
super.onCreate();
|
||||
config = findViewById(R.id.ll_config);
|
||||
read = findViewById(R.id.ll_read);
|
||||
config.setOnClickListener(this);
|
||||
read.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
if (id == R.id.ll_config) {
|
||||
RouteManager.forwardMsgMoreConfigActivity();
|
||||
} else if (id == R.id.ll_read) {
|
||||
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.shayu.onetoone.manager;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
|
||||
/**
|
||||
* 路由跳转Activity
|
||||
*/
|
||||
public class RouteManager {
|
||||
public static final String ACTIVITY_MAIN = "/activity/MainActivity";
|
||||
public static final String ACTIVITY_MSG_MORE_CONFIG_ACTIVITY = "/activity/MsgMoreConfigActivity";
|
||||
public static final String ACTIVITY_MSG_CHAT = "/activity/ChatActivity";
|
||||
|
||||
|
||||
public static void forwardMainActivity() {
|
||||
ARouter.getInstance().build(ACTIVITY_MAIN)
|
||||
.navigation();
|
||||
}
|
||||
|
||||
public static void forwardMsgMoreConfigActivity() {
|
||||
ARouter.getInstance().build(ACTIVITY_MSG_MORE_CONFIG_ACTIVITY)
|
||||
.navigation();
|
||||
}
|
||||
|
||||
public static void forwardMsgChatActivity() {
|
||||
ARouter.getInstance().build(ACTIVITY_MSG_CHAT)
|
||||
.navigation();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.shayu.onetoone.utils;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.yunbao.common.bean.CrashSaveBean;
|
||||
import com.yunbao.common.utils.AppManager;
|
||||
import com.yunbao.common.utils.FileUtil;
|
||||
import com.yunbao.common.utils.SpUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @ClassName NeverCrashUtils
|
||||
* @Description 全局捕获异常
|
||||
*/
|
||||
public class NeverCrashUtils {
|
||||
|
||||
private final static String TAG = NeverCrashUtils.class.getSimpleName();
|
||||
private final static NeverCrashUtils INSTANCE = new NeverCrashUtils();
|
||||
|
||||
private boolean debugMode;
|
||||
private MainCrashHandler mainCrashHandler;
|
||||
private UncaughtCrashHandler uncaughtCrashHandler;
|
||||
|
||||
private NeverCrashUtils() {
|
||||
}
|
||||
|
||||
public static NeverCrashUtils getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private synchronized MainCrashHandler getMainCrashHandler() {
|
||||
if (null == mainCrashHandler) {
|
||||
mainCrashHandler = (t, e) -> {
|
||||
};
|
||||
}
|
||||
return mainCrashHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主线程发生异常时的回调,可用于打印日志文件
|
||||
* <p>
|
||||
* 注意跨线程操作的可能
|
||||
*/
|
||||
public NeverCrashUtils setMainCrashHandler(MainCrashHandler mainCrashHandler) {
|
||||
this.mainCrashHandler = mainCrashHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
private synchronized UncaughtCrashHandler getUncaughtCrashHandler() {
|
||||
if (null == uncaughtCrashHandler) {
|
||||
uncaughtCrashHandler = (t, e) -> {
|
||||
};
|
||||
}
|
||||
return uncaughtCrashHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 子线程发生异常时的回调,可用于打印日志文件
|
||||
* <p>
|
||||
* 注意跨线程操作的可能
|
||||
*/
|
||||
public NeverCrashUtils setUncaughtCrashHandler(UncaughtCrashHandler uncaughtCrashHandler) {
|
||||
this.uncaughtCrashHandler = uncaughtCrashHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean isDebugMode() {
|
||||
return debugMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* debug模式,会打印log日志,且toast提醒发生异常,反之则都没有
|
||||
*/
|
||||
public NeverCrashUtils setDebugMode(boolean debugMode) {
|
||||
this.debugMode = debugMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成监听异常的注册
|
||||
*
|
||||
* @param application application
|
||||
*/
|
||||
private boolean errorWhile = true;
|
||||
|
||||
public void register(Application application) {
|
||||
//主线程异常拦截
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
while (errorWhile) {
|
||||
try {
|
||||
Looper.loop();
|
||||
} catch (Throwable e) {
|
||||
if (isDebugMode()) {
|
||||
Log.e(TAG, "未捕获的主线程异常行为", e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
AppManager.runDebugCode(() -> Toast.makeText(application, "发生闪退:" + e.getMessage(), Toast.LENGTH_SHORT).show());
|
||||
FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()), throwableToString(e), "error.log");
|
||||
getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e);
|
||||
AppManager.runDebugCode(() -> errorWhile = false);
|
||||
// return;
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
//子线程异常拦截
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
||||
if (isDebugMode()) {
|
||||
Log.e(TAG, "未捕获的子线程异常行为", e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
Toast.makeText(application, "发生闪退", Toast.LENGTH_SHORT).show();
|
||||
FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()),throwableToString(e),"error.log");
|
||||
getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e);
|
||||
getUncaughtCrashHandler().uncaughtException(t, e);
|
||||
|
||||
});*/
|
||||
}
|
||||
|
||||
public interface MainCrashHandler {
|
||||
void mainException(Thread t, Throwable e);
|
||||
}
|
||||
|
||||
public interface UncaughtCrashHandler {
|
||||
void uncaughtException(Thread t, Throwable e);
|
||||
}
|
||||
|
||||
private static String throwableToString(Throwable e) {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("time=" + System.currentTimeMillis() + "\n");
|
||||
writer.write("AndroidVersion=" + Build.VERSION.SDK_INT + "\n");
|
||||
writer.write("AndroidName=" + Build.VERSION.RELEASE + "\n");
|
||||
writer.write("PhoneName=" + Build.BRAND + "\n");
|
||||
writer.write("Phone=" + Build.MODEL + "\n");
|
||||
writer.write("CPU=" + Arrays.toString(Build.SUPPORTED_ABIS) + "\n");
|
||||
writer.write("runTime=" + (System.currentTimeMillis() - CrashSaveBean.getInstance().getStartTime()) + "\n");
|
||||
writer.write("enterRoom=" + CrashSaveBean.getInstance().getEnterRoom() + "\n");
|
||||
writer.write("slidingRoom=" + CrashSaveBean.getInstance().getSlidingRoom() + "\n");
|
||||
writer.write("playSvga=" + CrashSaveBean.getInstance().getPlaySvga() + "\n");
|
||||
writer.write("ActivitySize=" + CrashSaveBean.getInstance().getActivitySize() + "\n");
|
||||
writer.write("UserData=" + SpUtil.getInstance().getStringValue(SpUtil.USER_INFO) + "\n");
|
||||
writer.write("[ERROR]");
|
||||
PrintWriter printWriter = new PrintWriter(writer);
|
||||
e.printStackTrace(printWriter);
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user