|
@@ -1,25 +1,221 @@
|
|
|
package com.sunwin.visitorapp.fragment;
|
|
|
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.Spinner;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
+import androidx.annotation.ContentView;
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
+import androidx.appcompat.app.AlertDialog;
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.github.gzuliyujiang.calendarpicker.CalendarPicker;
|
|
|
+import com.github.gzuliyujiang.calendarpicker.OnSingleDatePickListener;
|
|
|
+import com.github.gzuliyujiang.imagepicker.ImagePicker;
|
|
|
+import com.github.gzuliyujiang.imagepicker.PickCallback;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.DatimePicker;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.OptionPicker;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.annotation.DateMode;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.annotation.TimeMode;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.contract.OnDatimePickedListener;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.contract.OnOptionPickedListener;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.contract.OnOptionSelectedListener;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.entity.DateEntity;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.entity.DatimeEntity;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.entity.TimeEntity;
|
|
|
+import com.github.gzuliyujiang.wheelpicker.widget.DatimeWheelLayout;
|
|
|
import com.sunwin.visitorapp.R;
|
|
|
+import com.sunwin.visitorapp.adapter.BaseRecyclerAdapter;
|
|
|
+import com.sunwin.visitorapp.adapter.BaseViewHolder;
|
|
|
+import com.sunwin.visitorapp.db.BlackUserModel;
|
|
|
+import com.sunwin.visitorapp.db.DatabaseManager;
|
|
|
+import com.sunwin.visitorapp.db.UserManagerModel;
|
|
|
+import com.sunwin.visitorapp.utils.FileUtil;
|
|
|
+import com.sunwin.visitorapp.utils.TimeUtils;
|
|
|
+import com.sunwin.visitorapp.utils.ToastUtils;
|
|
|
+
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+import timber.log.Timber;
|
|
|
|
|
|
public class UserManageFr extends Fragment {
|
|
|
|
|
|
private View root;
|
|
|
+ private Context context;
|
|
|
+ private BaseRecyclerAdapter<UserManagerModel> adapter ;
|
|
|
@Nullable
|
|
|
@Override
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
|
if(root==null)root = inflater.inflate(R.layout.fr_user_manage,container,false);
|
|
|
+ context = root.getContext();
|
|
|
+ RecyclerView RecyclerBlackList = root.findViewById(R.id.RecyclerUserManagerList);
|
|
|
+ adapter = new BaseRecyclerAdapter<UserManagerModel>() {
|
|
|
+ @Override
|
|
|
+ protected View getLayoutView(ViewGroup parent, int viewType) {
|
|
|
+ return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_managerlist,parent,false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("UseCompatLoadingForDrawables")
|
|
|
+ @Override
|
|
|
+ public void bind(int position, UserManagerModel data, BaseViewHolder holder, int viewType) {
|
|
|
+ holder.setText(R.id.TextAccount,data.account);
|
|
|
+ holder.setText(R.id.TextName,data.name);
|
|
|
+ holder.setText(R.id.TextStatus,statusLabelList[data.status]);
|
|
|
+ holder.setText(R.id.TextPermission,String.valueOf(data.permission));
|
|
|
+ holder.setText(R.id.TextLastLoginTime,String.valueOf(data.last_login_time));
|
|
|
+ holder.getView(R.id.ButtonEdit).setOnClickListener(v->{
|
|
|
+ createDialog(context,container,data);
|
|
|
+ });
|
|
|
+ holder.getView(R.id.ButtonDelete).setOnClickListener(v->{
|
|
|
+ new AlertDialog.Builder(context).setTitle("提示").setMessage("确定删除吗?").setPositiveButton("确定", (dialog, which) -> {
|
|
|
+ DatabaseManager.getInstance().delete(data);
|
|
|
+ refreshData();
|
|
|
+ }).setNegativeButton("取消",null).create().show();
|
|
|
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+ RecyclerBlackList.setAdapter(adapter);
|
|
|
+ RecyclerBlackList.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false));
|
|
|
+// RecyclerBlackList.addItemDecoration(new RVLinearItemDecoration.Builder(root.getContext()).color(R.color.ColorGray).dashWidth(2).create());
|
|
|
+ refreshData();
|
|
|
+ root.findViewById(R.id.ButtonAdd).setOnClickListener(v->{
|
|
|
+ createDialog(context,container,new UserManagerModel());
|
|
|
+ });
|
|
|
+ EditText EditSearchKey = root.findViewById(R.id.EditSearchKey);
|
|
|
+ root.findViewById(R.id.ButtonSearch).setOnClickListener(v->{
|
|
|
+ search(EditSearchKey.getText().toString().trim());
|
|
|
+ });
|
|
|
return root;
|
|
|
}
|
|
|
+
|
|
|
+ private void refreshData(){
|
|
|
+ adapter.setList(DatabaseManager.getInstance().getQueryAll(UserManagerModel.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void search(String key){
|
|
|
+ adapter.setList(DatabaseManager.getInstance().getQueryByLike(UserManagerModel.class,"name",new String[]{key}));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private final String[] statusLabelList = new String[]{"无效", "有效"};
|
|
|
+ private void createDialog(Context context,ViewGroup parent,UserManagerModel model){
|
|
|
+ View dialog_root = LayoutInflater.from(context).inflate(R.layout.dialog_user_manger,parent,false);
|
|
|
+
|
|
|
+ EditText EditAccount = dialog_root.findViewById(R.id.EditAccount);
|
|
|
+ EditAccount.setText(model.account);
|
|
|
+ EditText EditName = dialog_root.findViewById(R.id.EditName);
|
|
|
+ EditName.setText(model.name);
|
|
|
+ EditText EditPassword = dialog_root.findViewById(R.id.EditPassword);
|
|
|
+ EditPassword.setText(model.password);
|
|
|
+ EditText EditConfirmPassword = dialog_root.findViewById(R.id.EditConfirmPassword);
|
|
|
+ TextView TextStatus = dialog_root.findViewById(R.id.TextStatus);
|
|
|
+ TextStatus.setText(statusLabelList[model.status]);
|
|
|
+ TextStatus.setOnClickListener(v->{
|
|
|
+ OptionPicker picker = new OptionPicker(requireActivity());
|
|
|
+ picker.setData((Object[]) statusLabelList);
|
|
|
+ picker.setDefaultValue(statusLabelList[model.status]);
|
|
|
+ picker.getTitleView().setText("用户状态");
|
|
|
+ picker.setOnOptionPickedListener(new OnOptionPickedListener() {
|
|
|
+ @Override
|
|
|
+ public void onOptionPicked(int position, Object item) {
|
|
|
+ model.status = position;
|
|
|
+ TextStatus.setText((String)item);
|
|
|
+ }
|
|
|
+ });
|
|
|
+// picker.getWheelView().setStyle(R.style.WheelStyleDemo);
|
|
|
+ picker.show();
|
|
|
+ });
|
|
|
+ TextView TextValidTime = dialog_root.findViewById(R.id.TextValidTime);
|
|
|
+ if(model.valid_time<0){
|
|
|
+ TextValidTime.setText("无过期时间");
|
|
|
+ }else {
|
|
|
+ TextValidTime.setText(TimeUtils.stampToTime(model.valid_time));
|
|
|
+ }
|
|
|
+
|
|
|
+ TextValidTime.setOnClickListener(v->{
|
|
|
+ DatimePicker picker = new DatimePicker(requireActivity());
|
|
|
+ final DatimeWheelLayout wheelLayout = picker.getWheelLayout();
|
|
|
+ picker.setOnDatimePickedListener(new OnDatimePickedListener() {
|
|
|
+ @Override
|
|
|
+ public void onDatimePicked(int year, int month, int day, int hour, int minute, int second) {
|
|
|
+// String text = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
|
|
|
+// TextValidTime.setText(text);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.set(Calendar.YEAR,year);
|
|
|
+ calendar.set(Calendar.MONTH,month-1);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH,day);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY,hour);
|
|
|
+ calendar.set(Calendar.MINUTE,minute);
|
|
|
+ model.valid_time = calendar.getTimeInMillis();
|
|
|
+ TextValidTime.setText(TimeUtils.stampToTime(calendar.getTimeInMillis()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(model.valid_time>0){
|
|
|
+ DatimeEntity defaultDatetime = DatimeEntity.now();
|
|
|
+ defaultDatetime.setDate(DateEntity.target(new Date(model.valid_time)));
|
|
|
+ defaultDatetime.setTime(TimeEntity.target(new Date(model.valid_time)));
|
|
|
+ wheelLayout.setDefaultValue(defaultDatetime);
|
|
|
+ }
|
|
|
+ wheelLayout.setDateMode(DateMode.YEAR_MONTH_DAY);
|
|
|
+ wheelLayout.setTimeMode(TimeMode.HOUR_24_NO_SECOND);
|
|
|
+ wheelLayout.setRange(DatimeEntity.now(), DatimeEntity.yearOnFuture(10));
|
|
|
+ wheelLayout.setDateLabel("年", "月", "日");
|
|
|
+ wheelLayout.setTimeLabel("时", "分", "秒");
|
|
|
+ picker.show();
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ AlertDialog dialog = new AlertDialog.Builder(root.getContext()).setTitle("添加账号")
|
|
|
+ .setView(dialog_root)
|
|
|
+ .create();
|
|
|
+ dialog_root.findViewById(R.id.ButtonCancel).setOnClickListener(pv->{
|
|
|
+ dialog.dismiss();
|
|
|
+ });
|
|
|
+ dialog_root.findViewById(R.id.ButtonSure).setOnClickListener(b->{
|
|
|
+
|
|
|
+ if(TextUtils.isEmpty(EditAccount.getText().toString().trim())){
|
|
|
+ ToastUtils.showToast("账号不能为空");return;
|
|
|
+ }
|
|
|
+ if(TextUtils.isEmpty(EditName.getText().toString().trim())){
|
|
|
+ ToastUtils.showToast("名称不能为空");return;
|
|
|
+ }
|
|
|
+ if(TextUtils.isEmpty(EditPassword.getText().toString().trim())){
|
|
|
+ ToastUtils.showToast("密码不能为空");return;
|
|
|
+ }
|
|
|
+ if(!TextUtils.equals(EditPassword.getText().toString().trim(),EditConfirmPassword.getText().toString().trim())){
|
|
|
+ ToastUtils.showToast("两次密码不相同");return;
|
|
|
+ }
|
|
|
+ model.account = EditAccount.getText().toString().trim();
|
|
|
+ model.name = EditName.getText().toString().trim();
|
|
|
+
|
|
|
+ model.password = EditPassword.getText().toString().trim();
|
|
|
+// model.status = TextView.getSelectedItemPosition();
|
|
|
+// model.valid_time = TextValidTime.getText().toString().trim();
|
|
|
+ DatabaseManager.getInstance().insert(model);
|
|
|
+ refreshData();
|
|
|
+ dialog.dismiss();
|
|
|
+ });
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|