You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
5.5 KiB
161 lines
5.5 KiB
package com.community.pocket.ui.main.ui.visitor;
|
|
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.text.format.DateFormat;
|
|
import android.view.Gravity;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.annotation.StringRes;
|
|
import androidx.appcompat.app.AlertDialog;
|
|
import androidx.gridlayout.widget.GridLayout;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.data.model.Visitor;
|
|
import com.community.pocket.ui.BaseFragment;
|
|
import com.community.pocket.util.PropertiesUtil;
|
|
|
|
import org.xutils.view.annotation.ViewInject;
|
|
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* 访客列表通用布局
|
|
*/
|
|
public abstract class VisitorMyVisitor extends BaseFragment {
|
|
//表格布局
|
|
@ViewInject(R.id.table)
|
|
private GridLayout gridLayout;
|
|
|
|
//查询开始时间
|
|
@ViewInject(R.id.start_time)
|
|
protected EditText startTime;
|
|
|
|
//查询结束时间
|
|
@ViewInject(R.id.end_time)
|
|
protected EditText endTime;
|
|
|
|
//表格列
|
|
@ViewInject(R.id.name)
|
|
protected TextView name;
|
|
|
|
@ViewInject(R.id.time)
|
|
protected TextView time;
|
|
|
|
@ViewInject(R.id.tip)
|
|
private TextView tip;
|
|
|
|
/**
|
|
* 显示备注最大长度
|
|
*/
|
|
private static final int maxLength = 5;
|
|
|
|
@Override
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
super.onViewCreated(view, savedInstanceState);
|
|
this.initTip();
|
|
}
|
|
|
|
/**
|
|
* 初始化数据
|
|
*/
|
|
protected <T extends Visitor> void loadData(List<T> visitors) {
|
|
gridLayout.removeAllViews();
|
|
for (final Visitor visitor : visitors) {
|
|
createTextView(visitor.getName());
|
|
createTextView(formatUnix(visitor.getTime()));
|
|
createTextView(visitor.getNotes().length() <= maxLength ? visitor.getNotes() : visitor.getNotes().substring(0, maxLength));
|
|
|
|
switch (visitor.getStatus()) {
|
|
case ok:
|
|
Button button = new Button(getContext());
|
|
button.setText(R.string.show_notes);
|
|
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
|
|
layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
|
|
button.setLayoutParams(layoutParams);
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
@Override
|
|
public void onClick(View v) {
|
|
createAlertNotes(visitor);
|
|
}
|
|
});
|
|
gridLayout.addView(button);
|
|
break;
|
|
case uncheck:
|
|
createTextView(R.string.visitor_uncheck);
|
|
break;
|
|
case fail:
|
|
createTextView(R.string.visitor_check_fail);
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 创建单元格
|
|
*/
|
|
private void createTextView(CharSequence text) {
|
|
TextView textView = new TextView(getContext());
|
|
textView.setText(text);
|
|
createTextView(textView);
|
|
}
|
|
|
|
private void createTextView(@StringRes int resId) {
|
|
TextView textView = new TextView(getContext());
|
|
textView.setText(resId);
|
|
createTextView(textView);
|
|
}
|
|
|
|
private void createTextView(TextView textView) {
|
|
textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
|
|
textView.setBackground(getResources().getDrawable(R.drawable.border));
|
|
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
|
|
layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
|
|
textView.setLayoutParams(layoutParams);
|
|
gridLayout.addView(textView);
|
|
}
|
|
|
|
/**
|
|
* 创建显示备注信息弹窗
|
|
*/
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
private void createAlertNotes(Visitor visitor) {
|
|
View view = View.inflate(getContext(), R.layout.visitor_info, null);
|
|
TextView name = view.findViewById(R.id.name);
|
|
name.setText(getString(R.string.visitor_show_name, visitor.getName()));
|
|
TextView time = view.findViewById(R.id.time);
|
|
time.setText(getString(R.string.visitor_show_time, DateFormat.format(getString(R.string.dateformat_visitor), visitor.getTime())));
|
|
TextView notes = view.findViewById(R.id.notes);
|
|
notes.setText(getString(R.string.visitor_show_notes, visitor.getNotes()));
|
|
TextView admin = view.findViewById(R.id.admin);
|
|
admin.setText(getString(R.string.visitor_show_admin, visitor.getManagerName()));
|
|
Button button = view.findViewById(R.id.close);
|
|
AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext()));
|
|
final AlertDialog alertDialog = alert.setTitle(R.string.visitor_traffic_permit).setView(view).create();
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
alertDialog.dismiss();
|
|
}
|
|
});
|
|
alertDialog.show();
|
|
}
|
|
|
|
//初始化日期提示
|
|
private void initTip() {
|
|
String format = PropertiesUtil.getValue("date.pattern");
|
|
tip.setText(getString(R.string.dateformat_tip, format, DateFormat.format(format, System.currentTimeMillis())));
|
|
}
|
|
}
|
|
|