|
@@ -2,19 +2,14 @@ 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;
|
|
@@ -22,11 +17,6 @@ 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;
|
|
@@ -38,19 +28,22 @@ 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.github.gzuliyujiang.wheelpicker.widget.OptionWheelLayout;
|
|
|
+import com.github.gzuliyujiang.wheelview.contract.WheelFormatter;
|
|
|
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.RoleModel;
|
|
|
import com.sunwin.visitorapp.db.UserManagerModel;
|
|
|
-import com.sunwin.visitorapp.utils.FileUtil;
|
|
|
+import com.sunwin.visitorapp.manage.RunDataManage;
|
|
|
+import com.sunwin.visitorapp.utils.GsonUtil;
|
|
|
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 java.util.List;
|
|
|
|
|
|
import timber.log.Timber;
|
|
|
|
|
@@ -78,7 +71,8 @@ public class UserManageFr extends Fragment {
|
|
|
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));
|
|
|
+ RoleModel role = DatabaseManager.getInstance().getQueryById(RoleModel.class,data.role_id);
|
|
|
+ holder.setText(R.id.TextPermission,role!=null?role.name:"暂无");
|
|
|
holder.setText(R.id.TextLastLoginTime,String.valueOf(data.last_login_time));
|
|
|
holder.getView(R.id.ButtonEdit).setOnClickListener(v->{
|
|
|
createDialog(context,container,data);
|
|
@@ -88,7 +82,6 @@ public class UserManageFr extends Fragment {
|
|
|
DatabaseManager.getInstance().delete(data);
|
|
|
refreshData();
|
|
|
}).setNegativeButton("取消",null).create().show();
|
|
|
-
|
|
|
});
|
|
|
|
|
|
}
|
|
@@ -112,7 +105,7 @@ public class UserManageFr extends Fragment {
|
|
|
}
|
|
|
|
|
|
private void search(String key){
|
|
|
- adapter.setList(DatabaseManager.getInstance().getQueryByLike(UserManagerModel.class,"name",new String[]{key}));
|
|
|
+ adapter.setList(DatabaseManager.getInstance().getQueryByWhere(UserManagerModel.class,"name",key));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -127,7 +120,34 @@ public class UserManageFr extends Fragment {
|
|
|
EditText EditPassword = dialog_root.findViewById(R.id.EditPassword);
|
|
|
EditPassword.setText(model.password);
|
|
|
EditText EditConfirmPassword = dialog_root.findViewById(R.id.EditConfirmPassword);
|
|
|
+ EditConfirmPassword.setText(model.password);
|
|
|
+ TextView TextRole = dialog_root.findViewById(R.id.TextRole);
|
|
|
+ List<RoleModel> roleModels = DatabaseManager.getInstance().getQueryAll(RoleModel.class);
|
|
|
+ RoleModel userRole = DatabaseManager.getInstance().getQueryById(RoleModel.class,model.role_id);
|
|
|
+ if(userRole!=null){
|
|
|
+ TextRole.setText(userRole.name);
|
|
|
+ TextRole.setTag(userRole.id);
|
|
|
+ }
|
|
|
+ TextRole.setOnClickListener(v->{
|
|
|
+ OptionPicker picker = new OptionPicker(requireActivity());
|
|
|
+ picker.setData((Object[]) roleModels.toArray());
|
|
|
+
|
|
|
+ picker.setDefaultValue(userRole);
|
|
|
+ picker.getTitleView().setText("用户角色");
|
|
|
+ picker.getWheelLayout().getWheelView().setFormatter(item -> ((RoleModel)item).name);
|
|
|
+
|
|
|
+
|
|
|
+ picker.setOnOptionPickedListener((position, item) -> {
|
|
|
+// model.status = position;
|
|
|
+ RoleModel roleModel = (RoleModel) item;
|
|
|
+ TextRole.setTag(roleModel.id);
|
|
|
+ TextRole.setText(roleModel.name);
|
|
|
+ });
|
|
|
+// picker.getWheelView().setStyle(R.style.WheelStyleDemo);
|
|
|
+ picker.show();
|
|
|
+ });
|
|
|
TextView TextStatus = dialog_root.findViewById(R.id.TextStatus);
|
|
|
+ TextStatus.setTag(model.status);
|
|
|
TextStatus.setText(statusLabelList[model.status]);
|
|
|
TextStatus.setOnClickListener(v->{
|
|
|
OptionPicker picker = new OptionPicker(requireActivity());
|
|
@@ -137,7 +157,8 @@ public class UserManageFr extends Fragment {
|
|
|
picker.setOnOptionPickedListener(new OnOptionPickedListener() {
|
|
|
@Override
|
|
|
public void onOptionPicked(int position, Object item) {
|
|
|
- model.status = position;
|
|
|
+
|
|
|
+ TextStatus.setTag(position);
|
|
|
TextStatus.setText((String)item);
|
|
|
}
|
|
|
});
|
|
@@ -148,6 +169,7 @@ public class UserManageFr extends Fragment {
|
|
|
if(model.valid_time<0){
|
|
|
TextValidTime.setText("无过期时间");
|
|
|
}else {
|
|
|
+ TextValidTime.setTag(model.valid_time);
|
|
|
TextValidTime.setText(TimeUtils.stampToTime(model.valid_time));
|
|
|
}
|
|
|
|
|
@@ -165,7 +187,8 @@ public class UserManageFr extends Fragment {
|
|
|
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.setTag(calendar.getTimeInMillis());
|
|
|
TextValidTime.setText(TimeUtils.stampToTime(calendar.getTimeInMillis()));
|
|
|
}
|
|
|
});
|
|
@@ -206,11 +229,18 @@ public class UserManageFr extends Fragment {
|
|
|
}
|
|
|
model.account = EditAccount.getText().toString().trim();
|
|
|
model.name = EditName.getText().toString().trim();
|
|
|
-
|
|
|
model.password = EditPassword.getText().toString().trim();
|
|
|
+ if( TextRole.getTag()!=null)model.role_id = (long) TextRole.getTag();
|
|
|
+ if( TextStatus.getTag()!=null)model.status = (int) TextStatus.getTag();
|
|
|
+ if( TextValidTime.getTag()!=null)model.valid_time = (long) TextValidTime.getTag();
|
|
|
+
|
|
|
// model.status = TextView.getSelectedItemPosition();
|
|
|
// model.valid_time = TextValidTime.getText().toString().trim();
|
|
|
- DatabaseManager.getInstance().insert(model);
|
|
|
+ Timber.e(GsonUtil.toJson(model));
|
|
|
+ DatabaseManager.getInstance().save(model);
|
|
|
+ if(RunDataManage.GetLoginUser()!=null&&RunDataManage.GetLoginUser().id==model.id){
|
|
|
+ RunDataManage.RefreshLoginUser();
|
|
|
+ }
|
|
|
refreshData();
|
|
|
dialog.dismiss();
|
|
|
});
|