update
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.shayu.onetoone.activity.message;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@@ -13,15 +15,28 @@ 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.bean.AvatarBean;
|
||||
import com.shayu.onetoone.bean.GreetBean;
|
||||
import com.shayu.onetoone.manager.OTONetManager;
|
||||
import com.shayu.onetoone.manager.RouteManager;
|
||||
import com.yunbao.common.interfaces.OnItemClickListener;
|
||||
import com.yunbao.common.bean.HttpCallbackModel;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.http.base.HttpCallback;
|
||||
import com.yunbao.common.interfaces.ImageResultCallback;
|
||||
import com.yunbao.common.utils.ProcessImageUtil;
|
||||
import com.yunbao.common.utils.StringUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 打招呼设置界面
|
||||
*/
|
||||
@Route(path = RouteManager.ACTIVITY_MSG_MORE_CONFIG_ACTIVITY)
|
||||
public class MsgMoreConfigActivity extends AbsOTOActivity {
|
||||
List<GreetBean> deleteList = new ArrayList<>();
|
||||
RecyclerView recyclerView;
|
||||
MsgGreetConfigAdapter adapter;
|
||||
SwitchCompat msgSwitch;
|
||||
@@ -29,6 +44,8 @@ public class MsgMoreConfigActivity extends AbsOTOActivity {
|
||||
View editLayout;
|
||||
Button cancel, apply;
|
||||
|
||||
ProcessImageUtil imageUtil;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_msg_config;
|
||||
@@ -37,6 +54,7 @@ public class MsgMoreConfigActivity extends AbsOTOActivity {
|
||||
@Override
|
||||
protected void main(Bundle savedInstanceState) {
|
||||
setTitle("打招呼設置");
|
||||
imageUtil = new ProcessImageUtil(this);
|
||||
recyclerView = findViewById(R.id.msg_recyclerView);
|
||||
msgSwitch = findViewById(R.id.msg_switch);
|
||||
add = findViewById(R.id.add_msg);
|
||||
@@ -47,21 +65,148 @@ public class MsgMoreConfigActivity extends AbsOTOActivity {
|
||||
adapter = new MsgGreetConfigAdapter(this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
||||
recyclerView.setAdapter(adapter);
|
||||
adapter.setDeleteListener((size, position) -> {
|
||||
if (size >= 10) {
|
||||
adapter.setDeleteListener((bean, position) -> {
|
||||
if (position >= 10) {
|
||||
add.setVisibility(View.GONE);
|
||||
} else {
|
||||
add.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (!StringUtil.isEmpty(bean.getId())) {
|
||||
deleteList.add(bean);
|
||||
}
|
||||
});
|
||||
add.setOnClickListener(v -> {
|
||||
adapter.addItem(new MsgGreetConfigBean());
|
||||
adapter.addItem(new GreetBean());
|
||||
if (adapter.getItemCount() >= 10) {
|
||||
add.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
msgSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> editLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE));
|
||||
msgSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
editLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
OTONetManager.getInstance(mContext)
|
||||
.setGreetConfigGreet(isChecked, null);
|
||||
});
|
||||
apply.setOnClickListener(v -> {
|
||||
adapter.notifyDataSetChanged();
|
||||
new Handler(Looper.getMainLooper()).postDelayed(this::save,100);
|
||||
});
|
||||
cancel.setOnClickListener(v -> clearGreet());
|
||||
recyclerView.setOnClickListener(v -> adapter.notifyDataSetChanged());
|
||||
findViewById(R.id.upload_img).setOnClickListener(v -> {
|
||||
imageUtil.getImageByAlumb();
|
||||
});
|
||||
initData();
|
||||
imageUtil.setImageResultCallback(new ImageResultCallback() {
|
||||
@Override
|
||||
public void beforeCamera() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(File file) {
|
||||
OTONetManager.getInstance(mContext)
|
||||
.updateFile(file, new HttpCallback<AvatarBean>() {
|
||||
@Override
|
||||
public void onSuccess(AvatarBean data) {
|
||||
System.out.println("头像地址:" + data);
|
||||
OTONetManager.getInstance(mContext)
|
||||
.addMessageMoreGreetConfig(data.getAvatar(), "2", new HttpCallback<HttpCallbackModel>() {
|
||||
@Override
|
||||
public void onSuccess(HttpCallbackModel upload) {
|
||||
if (upload.getCode() == 0) {
|
||||
ImgLoader.display(mContext, data.getAvatar(), (ImageView) findViewById(R.id.imageView5));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void clearGreet() {
|
||||
OTONetManager.getInstance(mContext)
|
||||
.cleanMoreGreetConfig(new HttpCallback<HttpCallbackModel>() {
|
||||
@Override
|
||||
public void onSuccess(HttpCallbackModel data) {
|
||||
ToastUtil.show(data.getMsg());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
ToastUtil.show(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void save() {
|
||||
if (!msgSwitch.isChecked()) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
for (GreetBean bean : adapter.getNotEmptyList()) {
|
||||
if (StringUtil.isEmpty(bean.getId())) {
|
||||
addGreet(bean);
|
||||
} else if (bean.isEdit()) {
|
||||
editGreet(bean);
|
||||
}
|
||||
}
|
||||
for (GreetBean bean : deleteList) {
|
||||
OTONetManager.getInstance(mContext).removeMoreGreetConfig(bean.getId(), null);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void addGreet(GreetBean bean) {
|
||||
OTONetManager.getInstance(mContext)
|
||||
.addMessageMoreGreetConfig(bean.getContent(), bean.getType() + "", null);
|
||||
}
|
||||
|
||||
private void editGreet(GreetBean bean) {
|
||||
OTONetManager.getInstance(mContext)
|
||||
.setMoreGreetConfig(bean.getId(), bean.getContent(), bean.getType() + "", null);
|
||||
}
|
||||
|
||||
|
||||
private void initData() {
|
||||
OTONetManager.getInstance(mContext)
|
||||
.getMessageMoreGreetConfig(new HttpCallback<List<GreetBean>>() {
|
||||
@Override
|
||||
public void onSuccess(List<GreetBean> data) {
|
||||
adapter.setList(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
OTONetManager.getInstance(mContext)
|
||||
.getGreetConfigStatus(new HttpCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(Boolean data) {
|
||||
msgSwitch.setChecked(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user