package com.bw.yuekaofuxi;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.bw.yuekaofuxi.TianJiaHaoYou.view.TinJiaAcuity;
import com.bw.yuekaofuxi.fg.TongXin;
import com.bw.yuekaofuxi.fg.WoDe;
import com.bw.yuekaofuxi.fg.ZhuYe;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;
import java.util.ArrayList;
import java.util.List;
@Route(path = "/app/MainActivity")
public class MainActivity extends AppCompatActivity {
private Toolbar too;
private TextView nameText;
private ImageView jia;
private ViewPager vip;
private BottomNavigationView bot;
private Vip vips;
private List<Fragment>fragmentList=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
too = (Toolbar) findViewById(R.id.too);
nameText = (TextView) findViewById(R.id.nameText);
jia = (ImageView) findViewById(R.id.jia);
vip = (ViewPager) findViewById(R.id.vip);
bot = (BottomNavigationView) findViewById(R.id.bot);
fragmentList.add(new ZhuYe());
fragmentList.add(new TongXin());
fragmentList.add(new WoDe());
vips=new Vip(getSupportFragmentManager(),fragmentList);
vip.setAdapter(vips);
jia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupMenu popupMenu=new PopupMenu(MainActivity.this,jia);
popupMenu.inflate(R.menu.menut);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
//Toast.makeText(MainActivity.this, "你点击了", Toast.LENGTH_SHORT).show();
switch (menuItem.getItemId()){
case R.id.menut1:
Intent intent1=new Intent(MainActivity.this, TinJiaAcuity.class);
startActivity(intent1);
// case R.id.menut2:
// Intent intent2=new Intent();
// startActivity(intent2);
// case R.id.menut3:
// Intent intent3=new Intent();
// startActivity(intent3);
// case R.id.menut4:
// Intent intent4=new Intent();
// startActivity(intent4);
}
return false;
}
});
popupMenu.show();
}
});
bot.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.menu1:
vip.setCurrentItem(0);
break;
case R.id.menu2:
vip.setCurrentItem(1);
break;
case R.id.menu3:
vip.setCurrentItem(2);
break;
}
return true;
}
});
vip.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
switch (position){
case 0:
nameText.setText("IM通信");
break;
case 1:
nameText.setText("联系人");
break;
case 2:
nameText.setText("我的");
break;
}
}
@Override
public void onPageSelected(int position) {
switch (position){
case 0:
bot.setSelectedItemId(R.id.menu1);
break;
case 1:
bot.setSelectedItemId(R.id.menu2);
break;
case 2:
bot.setSelectedItemId(R.id.menu3);
break;
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
}
package com.bw.yuekaofuxi;
import android.app.Application;
import com.alibaba.android.arouter.launcher.ARouter;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMOptions;
import com.hyphenate.easeui.EaseIM;
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
ARouter.openDebug();
ARouter.openLog();
ARouter.init(this);//注意!!!init放在后面
EMOptions options = new EMOptions();
options.setAppKey("1189230630161249#bw");
if(EaseIM.getInstance().init(this, options)){
//在做打包混淆时,关闭 debug 模式,避免消耗不必要的资源
EMClient.getInstance().setDebugMode(true);
//EaseIM 初始化成功之后再调用注册消息监听的代码 ...
}
}
}
package com.bw.yuekaofuxi;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import java.util.List;
public class Vip extends FragmentPagerAdapter {
private List<Fragment>fragmentList;
public Vip(@NonNull FragmentManager fm, List<Fragment> fragmentList) {
super(fm);
this.fragmentList = fragmentList;
}
@NonNull
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return fragmentList.size();
}
}
package com.bw.yuekaofuxi.fg;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bw.yuekaofuxi.LiaoTian.ChatAcivity;
import com.bw.yuekaofuxi.R;
import com.hyphenate.EMValueCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMConversation;
import com.hyphenate.easeui.modules.contact.EaseContactListFragment;
import com.hyphenate.easeui.modules.conversation.EaseConversationListFragment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class TongXin extends EaseContactListFragment {
private List<String>usetname=new ArrayList<>();
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
EMClient.getInstance().contactManager().aysncGetAllContactsFromServer(new EMValueCallBack<List<String>>() {
@Override
public void onSuccess(List<String> value) {
Collections.sort(value);
usetname.addAll(value);
}
@Override
public void onError(int error, String errorMsg) {
}
});
}
@Override
public void onItemClick(View view, int position) {
super.onItemClick(view, position);
String ids=usetname.get(position);
Intent intent=new Intent(getActivity(), ChatAcivity.class);
Bundle bundle = new Bundle();
bundle.putString("conversationId",ids);
bundle.putInt("chatType",1);
intent.putExtras(bundle);
getActivity().startActivity(intent);
}
}
package com.bw.yuekaofuxi.fg;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bw.yuekaofuxi.R;
import com.hyphenate.chat.EMClient;
public class WoDe extends Fragment {
private Button BtnLogin;
private Button TuiChuLogin;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fragment_wo_de, container, false);
BtnLogin = (Button) inflate.findViewById(R.id.BtnLogin);
TuiChuLogin = (Button)inflate. findViewById(R.id.TuiChuLogin);
BtnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ARouter.getInstance().build("/app/Login").navigation();
}
});
TuiChuLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EMClient.getInstance().logout(true);
}
});
return inflate;
}
}
package com.bw.yuekaofuxi.fg;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bw.yuekaofuxi.LiaoTian.ChatAcivity;
import com.bw.yuekaofuxi.R;
import com.hyphenate.chat.EMConversation;
import com.hyphenate.easeui.modules.conversation.EaseConversationListFragment;
public class ZhuYe extends EaseConversationListFragment {
@Override
public void onItemClick(View view, int position) {
super.onItemClick(view, position);
String conversationId=
((EMConversation)this.conversationListLayout.getItem(position).getInfo()).conversationId();
int chatType=0;
switch (((EMConversation)this.conversationListLayout.getItem(position).getInfo()).getType()){
case Chat:
chatType=1;
break;
case GroupChat:
chatType=2;
break;
}
Intent intent=new Intent(getActivity(), ChatAcivity.class);
Bundle bundle = new Bundle();
bundle.putString("conversationId",conversationId);
bundle.putInt("chatType",chatType);
intent.putExtras(bundle);
getActivity().startActivity(intent);
}
}
package com.bw.yuekaofuxi.LiaoTian;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.bw.yuekaofuxi.R;
import com.hyphenate.easeui.modules.chat.EaseChatFragment;
public class ChatAcivity extends AppCompatActivity {
private ChatFragment chatFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat_fragment);
chatFragment =new ChatFragment();
//pass parameters to chat fragment
chatFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction().add(R.id.container, chatFragment).commit();
}
}
package com.bw.rikao7_5.mvp.view.huanxin;
import android.content.Intent;
import android.view.View;
import android.widget.Toast;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bw.rikao7_5.R;
import com.hyphenate.easeui.modules.chat.EaseChatFragment;
import com.hyphenate.easeui.modules.chat.interfaces.IChatExtendMenu;
public class ChatFragment extends EaseChatFragment {
@Override
public void initView() {
super.initView();
IChatExtendMenu chatExtendMenu=chatLayout.getChatInputMenu().getChatExtendMenu();
chatExtendMenu.registerMenuItem("转账", R.drawable.baseline_payment_24,333);
}
@Override
public void onChatExtendMenuItemClick(View view, int itemId) {
super.onChatExtendMenuItemClick(view, itemId);
if(itemId==333){
Toast.makeText(mContext, "点击支付宝支付", Toast.LENGTH_SHORT).show();
ARouter.getInstance().build("/app/ZhiFuBao")
.navigation();
}
}
}
package com.bw.yuekaofuxi.login.presenrte;
public interface Ic {
interface P{
void Login(String usetanem,String password);
}
interface LoginView{
void Geng();
void Bai(String errr);
void username();
void password();
}
}
package com.bw.yuekaofuxi.login.presenrte;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
public class LoginPresenter implements Ic.P{
private Ic.LoginView view;
public LoginPresenter(Ic.LoginView view) {
this.view = view;
}
@Override
public void Login(String usetanem, String password) {
if(usetanem.length()>3){
if(password.length()>3){
LoginCheng(usetanem,password);
}else {
view.password();
}
}else {
view.username();
}
}
private void LoginCheng(String usetanem, String password) {
EMClient.getInstance().logout(true);
EMClient.getInstance().login(usetanem, password, new EMCallBack() {
@Override
public void onSuccess() {
view.Geng();
}
@Override
public void onError(int code, String error) {
view.Bai(error);
}
});
}
}
package com.bw.yuekaofuxi.login.view;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bw.yuekaofuxi.R;
import com.bw.yuekaofuxi.login.presenrte.Ic;
import com.bw.yuekaofuxi.login.presenrte.LoginPresenter;
@Route(path = "/app/Login")
public class Login extends AppCompatActivity implements Ic.LoginView {
private EditText edusername;
private EditText edpassword;
private Button LoginBtn;
private TextView ZhuCe;
private LoginPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
edusername = (EditText) findViewById(R.id.edusername);
edpassword = (EditText) findViewById(R.id.edpassword);
LoginBtn = (Button) findViewById(R.id.LoginBtn);
ZhuCe = (TextView) findViewById(R.id.ZhuCe);
presenter=new LoginPresenter(this);
LoginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = edusername.getText().toString();
String passrword = edpassword.getText().toString();
presenter.Login(name,passrword);
}
});
ZhuCe.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ARouter.getInstance().build("/app/ZhuCe").navigation();
}
});
}
@Override
public void Geng() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(Login.this, "登录成功", Toast.LENGTH_SHORT).show();
}
});
ARouter.getInstance().build("/app/MainActivity").navigation();
}
@Override
public void Bai(String errr) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(Login.this, "登录失败", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void username() {
Toast.makeText(this, "账号错误", Toast.LENGTH_SHORT).show();
}
@Override
public void password() {
Toast.makeText(this, "密码错误", Toast.LENGTH_SHORT).show();
}
}
package com.bw.yuekaofuxi.TianJiaHaoYou.presenter;
public class Ic {
public interface P{
void search(String usernaem,String reason);
}
public interface View{
void Cheng();
void Bai(String error);
}
}
package com.bw.yuekaofuxi.TianJiaHaoYou.presenter;
import com.bw.yuekaofuxi.TianJiaHaoYou.view.TinJiaAcuity;
import com.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.HyphenateException;
public class Presemter implements Ic.P{
private Ic.View view;
public Presemter(TinJiaAcuity view) {
this.view = view;
}
@Override
public void search(String usernaem, String reason) {
if(usernaem.length()>3){
try {
EMClient.getInstance().contactManager().addContact(usernaem, reason);
EMClient.getInstance().contactManager().acceptInvitation(usernaem);
view.Cheng();
} catch (HyphenateException e) {
view.Bai(e.getMessage());
// throw new RuntimeException(e);
}
}
}
}
package com.bw.yuekaofuxi.TianJiaHaoYou.view;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.bw.yuekaofuxi.R;
import com.bw.yuekaofuxi.TianJiaHaoYou.presenter.Ic;
import com.bw.yuekaofuxi.TianJiaHaoYou.presenter.Presemter;
public class TinJiaAcuity extends AppCompatActivity implements Ic.View {
private EditText edname;
private EditText ed;
private Button Btn112;
private Presemter presemter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tian_jiaa_civity);
edname = (EditText) findViewById(R.id.edname);
ed = (EditText) findViewById(R.id.ed);
Btn112 = (Button) findViewById(R.id.Btn112);
presemter=new Presemter(this);
Btn112.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
search(edname.getText().toString(),ed.getText().toString());
}
});
}
private void search(String toString, String toString1) {
presemter.search(toString, toString1);
}
@Override
public void Cheng() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(TinJiaAcuity.this, "添加成功", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void Bai(String error) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(TinJiaAcuity.this, "添加失败", Toast.LENGTH_SHORT).show();
}
});
}
}
package com.bw.yuekaofuxi.ZhuCe.presenter;
public interface Ic {
interface P{
void ZhuCe(String username,String password,String quepassword);
}
interface ZhuCeView{
void Cheng();
void Bai();
void Bais(String error);
void username();
void password();
void quepassword();
}
}
package com.bw.yuekaofuxi.ZhuCe.presenter;
import android.os.Handler;
import com.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.HyphenateException;
public class ZhuCePresenter implements Ic.P{
private Ic.ZhuCeView view;
private Handler handler;
public ZhuCePresenter(Ic.ZhuCeView view) {
this.view = view;
}
@Override
public void ZhuCe(String username, String password, String quepassword) {
if(username.length()>3){
if(password.length()>3){
if(quepassword.length()>3){
ZhuCeCheng(username,password);
}else {
view.quepassword();
}
}else {
view.password();
}
}else {
view.username();
}
}
private void ZhuCeCheng(String username, String password) {
handler=new Handler();
new Thread(new Runnable() {
@Override
public void run() {
try {
EMClient.getInstance().createAccount(username,password);
handler.post(new Runnable() {
@Override
public void run() {
view.Cheng();
}
});
} catch (HyphenateException e) {
handler.post(new Runnable() {
@Override
public void run() {
if(e.getErrorCode()==203){
view.Bai();
}else {
view.Bais(e.getMessage());
}
}
});
}
}
}).start();
}
}
package com.bw.yuekaofuxi.ZhuCe.view;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bw.yuekaofuxi.R;
import com.bw.yuekaofuxi.ZhuCe.presenter.Ic;
import com.bw.yuekaofuxi.ZhuCe.presenter.ZhuCePresenter;
@Route(path = "/app/ZhuCe")
public class ZhuCe extends AppCompatActivity implements Ic.ZhuCeView {
private EditText edusername;
private EditText edpassword;
private EditText edquepassword;
private Button ZhuCeBtn;
private ZhuCePresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zhu_ce);
edusername = (EditText) findViewById(R.id.edusername);
edpassword = (EditText) findViewById(R.id.edpassword);
edquepassword = (EditText) findViewById(R.id.edquepassword);
ZhuCeBtn = (Button) findViewById(R.id.ZhuCeBtn);
presenter=new ZhuCePresenter(this);
ZhuCeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = edusername.getText().toString();
String password = edpassword.getText().toString();
String quepassword = edquepassword.getText().toString();
presenter.ZhuCe(name,password,quepassword);
}
});
}
@Override
public void Cheng() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(ZhuCe.this, "注册成功", Toast.LENGTH_SHORT).show();
}
});
ARouter.getInstance().build("/app/Login").navigation();
}
@Override
public void Bai() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(ZhuCe.this, "注册失败", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void Bais(String error) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(ZhuCe.this, "注册失败"+error, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void username() {
Toast.makeText(this, "账号错误", Toast.LENGTH_SHORT).show();
}
@Override
public void password() {
Toast.makeText(this, "密码错误", Toast.LENGTH_SHORT).show();
}
@Override
public void quepassword() {
Toast.makeText(this, "确认密码错误", Toast.LENGTH_SHORT).show();
}
}
package com.bw.yuekaofuxi.HuYing.presenter;
public class Ic {
public interface P{
void PanLogin();
}
public interface View{
void Cheng();
void ShiBai();
}
}
package com.bw.yuekaofuxi.HuYing.presenter;
import android.widget.EditText;
import com.hyphenate.chat.EMClient;
public class Presenter implements Ic.P{
private Ic.View view;
public Presenter(Ic.View view) {
this.view = view;
}
@Override
public void PanLogin() {
if(isLogin()){
view.Cheng();
}else {
view.ShiBai();
}
}
private boolean isLogin() {
return EMClient.getInstance().isLoggedInBefore();
}
}
package com.bw.yuekaofuxi.HuYing.view;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.bw.yuekaofuxi.HuYing.presenter.Ic;
import com.bw.yuekaofuxi.HuYing.presenter.Presenter;
import com.bw.yuekaofuxi.MainActivity;
import com.bw.yuekaofuxi.R;
import com.bw.yuekaofuxi.login.view.Login;
public class HuanYing extends AppCompatActivity implements Ic.View {
private Button Btn;
private Presenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_huan_ying);
Btn = (Button) findViewById(R.id.Btn);
presenter=new Presenter(this);
Btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
presenter.PanLogin();
}
});
}
@Override
public void Cheng() {
Intent intent=new Intent(this, MainActivity.class);
startActivity(intent);
}
@Override
public void ShiBai() {
Intent intent=new Intent(this, Login.class);
startActivity(intent);
}
}