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.
113 lines
3.7 KiB
113 lines
3.7 KiB
package com.community.pocket.ui.main.ui.visitor;
|
|
|
|
import android.os.Build;
|
|
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.RequiresApi;
|
|
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 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;
|
|
|
|
/**
|
|
* 显示备注最大长度
|
|
*/
|
|
private static final int maxLength = 5;
|
|
|
|
/**
|
|
* 初始化数据
|
|
*/
|
|
protected void loadData(List<Visitor> visitors) {
|
|
for (final Visitor visitor : visitors) {
|
|
createTextView(visitor.getName());
|
|
createTextView(DateFormat.format(getString(R.string.dateformat), visitor.getTime()));
|
|
createTextView(visitor.getNotes().length() <= maxLength ? visitor.getNotes() : visitor.getNotes().substring(0, maxLength));
|
|
|
|
Button button = new Button(getContext());
|
|
button.setText(getString(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.getNotes());
|
|
}
|
|
});
|
|
gridLayout.addView(button);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 创建单元格
|
|
*/
|
|
private void createTextView(CharSequence text) {
|
|
TextView textView = new TextView(getContext());
|
|
textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
|
|
textView.setText(text);
|
|
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(String text) {
|
|
View view = View.inflate(getContext(), R.layout.visitor_info, null);
|
|
TextView textView = view.findViewById(R.id.content);
|
|
textView.setText(text);
|
|
textView.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
|
|
Button button = view.findViewById(R.id.close);
|
|
AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext()));
|
|
final AlertDialog alertDialog = alert.setTitle(R.string.notes).setView(view).create();
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
alertDialog.dismiss();
|
|
}
|
|
});
|
|
alertDialog.show();
|
|
}
|
|
}
|
|
|