|
|
@ -3,6 +3,7 @@ package com.community.pocket.ui.main.ui.visitor; |
|
|
|
import android.os.Build; |
|
|
|
import android.os.Build; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.text.format.DateFormat; |
|
|
|
import android.text.format.DateFormat; |
|
|
|
|
|
|
|
import android.util.TypedValue; |
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.Button; |
|
|
|
import android.widget.Button; |
|
|
@ -14,16 +15,18 @@ import androidx.annotation.Nullable; |
|
|
|
import androidx.annotation.RequiresApi; |
|
|
|
import androidx.annotation.RequiresApi; |
|
|
|
import androidx.annotation.StringRes; |
|
|
|
import androidx.annotation.StringRes; |
|
|
|
import androidx.appcompat.app.AlertDialog; |
|
|
|
import androidx.appcompat.app.AlertDialog; |
|
|
|
|
|
|
|
import androidx.core.widget.NestedScrollView; |
|
|
|
import androidx.gridlayout.widget.GridLayout; |
|
|
|
import androidx.gridlayout.widget.GridLayout; |
|
|
|
|
|
|
|
|
|
|
|
import com.community.pocket.R; |
|
|
|
import com.community.pocket.R; |
|
|
|
|
|
|
|
import com.community.pocket.data.model.Page; |
|
|
|
import com.community.pocket.data.model.Visitor; |
|
|
|
import com.community.pocket.data.model.Visitor; |
|
|
|
import com.community.pocket.ui.BaseFragment; |
|
|
|
import com.community.pocket.ui.BaseFragment; |
|
|
|
import com.community.pocket.util.PropertiesUtil; |
|
|
|
import com.community.pocket.util.PropertiesUtil; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.xutils.view.annotation.Event; |
|
|
|
import org.xutils.view.annotation.ViewInject; |
|
|
|
import org.xutils.view.annotation.ViewInject; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Objects; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -61,16 +64,19 @@ public abstract class VisitorMyVisitor extends BaseFragment { |
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
|
|
|
super.onViewCreated(view, savedInstanceState); |
|
|
|
super.onViewCreated(view, savedInstanceState); |
|
|
|
this.initTip(); |
|
|
|
this.initTip(); |
|
|
|
|
|
|
|
this.loadMore(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 初始化数据 |
|
|
|
* 初始化数据 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected <T extends Visitor> void loadData(List<T> visitors) { |
|
|
|
protected <T extends Visitor> void loadData(Page<T> visitors) { |
|
|
|
gridLayout.removeAllViews(); |
|
|
|
if (visitors.getCurrentPage() == 1 && !visitors.isEmpty()) { |
|
|
|
for (final Visitor visitor : visitors) { |
|
|
|
gridLayout.removeViews(4, gridLayout.getChildCount() - 4); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (final Visitor visitor : visitors.getList()) { |
|
|
|
createTextView(visitor.getName()); |
|
|
|
createTextView(visitor.getName()); |
|
|
|
createTextView(formatUnix(visitor.getTime())); |
|
|
|
createTextView(DateFormat.format(getString(R.string.dateformat_visitor), visitor.getTime())); |
|
|
|
createTextView(visitor.getNotes().length() <= maxLength ? visitor.getNotes() : visitor.getNotes().substring(0, maxLength)); |
|
|
|
createTextView(visitor.getNotes().length() <= maxLength ? visitor.getNotes() : visitor.getNotes().substring(0, maxLength)); |
|
|
|
|
|
|
|
|
|
|
|
switch (visitor.getStatus()) { |
|
|
|
switch (visitor.getStatus()) { |
|
|
@ -80,13 +86,7 @@ public abstract class VisitorMyVisitor extends BaseFragment { |
|
|
|
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); |
|
|
|
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); |
|
|
|
layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); |
|
|
|
layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); |
|
|
|
button.setLayoutParams(layoutParams); |
|
|
|
button.setLayoutParams(layoutParams); |
|
|
|
button.setOnClickListener(new View.OnClickListener() { |
|
|
|
button.setOnClickListener(v -> createAlertNotes(visitor)); |
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT) |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
|
|
createAlertNotes(visitor); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
gridLayout.addView(button); |
|
|
|
gridLayout.addView(button); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case uncheck: |
|
|
|
case uncheck: |
|
|
@ -102,6 +102,25 @@ public abstract class VisitorMyVisitor extends BaseFragment { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 加载更多数据 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected abstract Long getCurrentPage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract VisitorLoad getViewModel(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void load(Long page) { |
|
|
|
|
|
|
|
getViewModel().loadMy(startTime.getText().toString(), endTime.getText().toString(), page); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void loadMore() { |
|
|
|
|
|
|
|
VisitorFragment visitorFragment = getParentFragment(VisitorFragment.class); |
|
|
|
|
|
|
|
visitorFragment.getScrollView().setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> { |
|
|
|
|
|
|
|
if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) { |
|
|
|
|
|
|
|
load(this.getCurrentPage() + 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 创建单元格 |
|
|
|
* 创建单元格 |
|
|
@ -124,6 +143,7 @@ public abstract class VisitorMyVisitor extends BaseFragment { |
|
|
|
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); |
|
|
|
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); |
|
|
|
layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); |
|
|
|
layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); |
|
|
|
textView.setLayoutParams(layoutParams); |
|
|
|
textView.setLayoutParams(layoutParams); |
|
|
|
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); |
|
|
|
gridLayout.addView(textView); |
|
|
|
gridLayout.addView(textView); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -144,12 +164,7 @@ public abstract class VisitorMyVisitor extends BaseFragment { |
|
|
|
Button button = view.findViewById(R.id.close); |
|
|
|
Button button = view.findViewById(R.id.close); |
|
|
|
AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); |
|
|
|
AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); |
|
|
|
final AlertDialog alertDialog = alert.setTitle(R.string.visitor_traffic_permit).setView(view).create(); |
|
|
|
final AlertDialog alertDialog = alert.setTitle(R.string.visitor_traffic_permit).setView(view).create(); |
|
|
|
button.setOnClickListener(new View.OnClickListener() { |
|
|
|
button.setOnClickListener(v -> alertDialog.dismiss()); |
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
|
|
alertDialog.dismiss(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
alertDialog.show(); |
|
|
|
alertDialog.show(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -158,4 +173,13 @@ public abstract class VisitorMyVisitor extends BaseFragment { |
|
|
|
String format = PropertiesUtil.getValue("date.pattern"); |
|
|
|
String format = PropertiesUtil.getValue("date.pattern"); |
|
|
|
tip.setText(getString(R.string.dateformat_tip, format, DateFormat.format(format, System.currentTimeMillis()))); |
|
|
|
tip.setText(getString(R.string.dateformat_tip, format, DateFormat.format(format, System.currentTimeMillis()))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 查询访客数据 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Event(R.id.query) |
|
|
|
|
|
|
|
private void query(View view) { |
|
|
|
|
|
|
|
load(1L); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|