1.Contracts
public interface DetailContracts {
interface View extends BaseView<Presenter>{
/**
* 是否可以进行短信、电话、语音电话
*
*/
void showChatEnable();
/**
* 显示头像
* @param phone
*/
void showPhoto(String phone);
void showPhone(String phone);
/**
* 归属地
*/
void showLocation(String phone);
interface Presenter extends BasePresenter{
/**
* 数据加载
* @param
*/
void handleStartUPData(String phoneNum);
/**
* 获取手机号码
* @return
*/
String getPhoneNum();
/**
* 释放
*/
void release();
/**
* 是否可点击
* @return
*/
Boolean isClick();
//资源文件
int[] getColorId();
int[] getNetCallDrawId();
int[] getLocalCallDrawId();
int[] getMessageDrawId();
}
}
2.activity
public class DetailActivity extends BaseActivity implements DetailContracts.View {
@BindView(R.id.profile_photo)
ImageView simpleDraweeView; //头像
@BindView(R.id.profile_name)
TextView profile_name; //姓名
@BindView(R.id.tv_phone_address)
TextView tv_phone_address; //号码归属地
@BindView(R.id.tv_phone_number)
TextView tv_phone_number; //号码
@BindView(R.id.ll_netcall)
TextView ll_netcall; //网络电话
@BindView(R.id.ll_localcall)
TextView ll_localcall; //普通电话
@BindView(R.id.ll_message)
TextView ll_message; //网络电话
public static String PHONE = "STRANGER_PHONE";
private StrangerDetailContracts.Presenter mPresenter;
private String phoneNum;
@OnClick({R.id.ll_message,R.id.ll_localcall,R.id.ll_netcall,R.id.left_back_btn})
public void onClick(View view) {
switch (view.getId()) {
case R.id.ll_message:
//发送消息,第一个号码的联系人
MessageDetailActivity.show(this, mPresenter.getPhoneNum(), "");
break;
case R.id.ll_localcall:
CallRecordsUtils.normalCall(this,mPresenter.getPhoneNum());
break;
case R.id.ll_netcall:
CallRecordsUtils.voiceCall(this, mPresenter.getPhoneNum());
break;
case R.id.left_back_btn:
this.finish();
break;
default:
break;
}
}
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stranger_detail);
StatusBarCompat.setStatusBarColor(this, this.getResources().getColor( R.color.statusbar_blue));
}
@Override
protected void findViews() {
}
@Override
protected void init() {
StatusBarCompat.setStatusBarColor(this, ContextCompat.getColor(this, R.color.statusbar_blue));
phoneNum = getIntent().getStringExtra(PHONE);
mPresenter = new StrangerDetailPresenterImpl(this);
mPresenter.start();
}
@Override
protected void onResume() {
super.onResume();
mPresenter.handleStartUPData(phoneNum);
}
@Override
protected void onDestroy() {
super.onDestroy();
mPresenter.release();
}
public static void show(Context context, String phone){
Intent intent = new Intent(context, StrangerDetailActivity.class);
Bundle bundle = new Bundle();
bundle.putString(PHONE, phone);
intent.putExtras(bundle);
context.startActivity(intent);
}
@Override
public void showChatEnable() {
showClick(ll_netcall,mPresenter.getNetCallDrawId(),mPresenter.getColorId());
showClick(ll_message,mPresenter.getMessageDrawId(),mPresenter.getColorId());
showClick(ll_localcall,mPresenter.getLocalCallDrawId(),mPresenter.getColorId());
}
@Override
public void showPhoto(String phone) {
GlidePhotoLoader.getInstance(this).loadProfilePhotoFromNet(this, simpleDraweeView, phone,true); //加载头像
}
@Override
public void showPhone(String phone) {
if(!TextUtils.isEmpty(phone)) {
tv_phone_number.setText(phone);
profile_name.setText(phone);
}
}
@Override
public void showLocation(String phone) {
String phoneNum= PhoneNumUtilsEx.getMinMatchNumber(phone);
String location = PhoneNumLocationUtil.getPhoneAddress(this, phoneNum);
//归属地
if(TextUtils.isEmpty(location)){
tv_phone_address.setText("手机");
}else{
tv_phone_address.setText(location);
}
}
@Override
public void showCapture(final Boolean cap) {
this.runOnUiThread(new Runnable() {
@Override
public void run() {
if(cap){
iv_capable.setVisibility(View.VISIBLE);
showNetCallClick(true);
}else {
iv_capable.setVisibility(View.GONE);
showNetCallClick(false);
}
}
});
}
public void showClick(TextView tx, int[] drawId,int[] colorId) {
if(mPresenter.isClick()){
Drawable image = getResources().getDrawable(drawId[0]);
image.setBounds(0, 0, image.getMinimumWidth(), image.getMinimumHeight());
tx.setTextColor(getResources().getColor(colorId[0]));
tx.setCompoundDrawables(null,image,null,null);
tx.setEnabled(true);
}else {
Drawable image = getResources().getDrawable(drawId[1]);
image.setBounds(0, 0, image.getMinimumWidth(), image.getMinimumHeight());
tx.setTextColor(getResources().getColor(colorId[1]));
tx.setCompoundDrawables(null,image,null,null);
tx.setEnabled(false);
}
}
public void showNetCallClick(boolean isClick) {
if(isClick){
Drawable image = getResources().getDrawable(mPresenter.getNetCallDrawId()[0]);
image.setBounds(0, 0, image.getMinimumWidth(), image.getMinimumHeight());
ll_netcall.setTextColor(getResources().getColor(mPresenter.getColorId()[0]));
ll_netcall.setCompoundDrawables(null,image,null,null);
ll_netcall.setEnabled(true);
}else {
Drawable image = getResources().getDrawable(mPresenter.getNetCallDrawId()[1]);
image.setBounds(0, 0, image.getMinimumWidth(), image.getMinimumHeight());
ll_netcall.setTextColor(getResources().getColor(mPresenter.getColorId()[1]));
ll_netcall.setCompoundDrawables(null,image,null,null);
ll_netcall.setEnabled(false);
}
}
}
}
3.Presenter
public class DetailPresenterImpl implements DetailContracts.Presenter
{
private String TAG=StrangerDetailPresenterImpl.this.getClass().getSimpleName();
private StrangerDetailContracts.View mView;
private String phoneNum;
private Boolean isClick=true; //是否可点击
private int[] messageDrawId=new int[2];
private int[] localCallDrawId=new int[2];
private int[] netCallDrawId=new int[2];
private int[] colorId=new int[2];
@Override
public void handleStartUPData(String phoneNum) {
this.phoneNum=phoneNum;
mView.showPhoto(phoneNum);
mView.showLocation(phoneNum);
mView.showPhone(phoneNum);
if(!TextUtils.isEmpty(phoneNum)) {
isClick=true;
}
else {
isClick=false;
}
mView.showChatEnable();
checkCap(phoneNum);
}
public StrangerDetailPresenterImpl(StrangerDetailContracts.View view){
this.mView=view;
}
@Override
public void start() {
RcsCapQueryUtil.getInstance().addRcsCapCallback(this);
messageDrawId[0]= R.drawable.contacts_chat;
messageDrawId[1]=R.drawable.contacts_chat_disabled;
localCallDrawId[0]=R.drawable.contacts_call;
localCallDrawId[1]=R.drawable.contacts_call_disabled;
netCallDrawId[0]=R.drawable.contacts_ip;
netCallDrawId[1]=R.drawable.contacts_ip_disabled;
colorId[0]=R.color.detail_ll_normal;
colorId[1]=R.color.detail_ll_disable;
}
@Override
public String getPhoneNum(){
return phoneNum;
}
@Override
public void release() {
RcsCapQueryUtil.getInstance().removeRcsCapCallback(this);
}
@Override
public void checkCap(String phoneNum) {
if(!TextUtils.isEmpty(phoneNum) ){
String cap = RcsCapQueryUtil.getInstance().getRcsCap(phoneNum);
if (!TextUtils.isEmpty(cap)) {
mView.showCapture(true);
} else
mView.showCapture(false);
RcsCapQueryUtil.getInstance().queryRcsCap(phoneNum);
}else
mView.showCapture(false);
}
@Override
public Boolean isClick() {
return isClick;
}
@Override
public void rcsCapFinished(String uri, String cap) {
LogF.e(TAG, "rcsCapFinished-------uri:" + uri + ",cap:" + cap+"phone:"+phoneNum);
String tmpUri= PhoneNumUtilsEx.getMinMatchNumber(uri);
String tmpPhone=PhoneNumUtilsEx.getMinMatchNumber(phoneNum);
if(tmpUri.equals(tmpPhone)) {
if (!TextUtils.isEmpty(cap))
mView.showCapture(true);
else
mView.showCapture(false);
}
}
public int[] getMessageDrawId() {
return messageDrawId;
}
public int[] getLocalCallDrawId() {
return localCallDrawId;
}
public int[] getNetCallDrawId() {
return netCallDrawId;
}
public int[] getColorId() {
return colorId;
}
}