2016-01-27 10:59:16 +00:00
|
|
|
package eu.faircode.netguard;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CursorAdapter;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
public class AccessAdapter extends CursorAdapter {
|
|
|
|
private static String TAG = "NetGuard.Access";
|
|
|
|
|
|
|
|
private int colDaddr;
|
|
|
|
private int colDPort;
|
|
|
|
private int colTime;
|
2016-01-30 11:46:00 +00:00
|
|
|
private int colBlock;
|
2016-01-27 10:59:16 +00:00
|
|
|
|
|
|
|
public AccessAdapter(Context context, Cursor cursor) {
|
|
|
|
super(context, cursor, 0);
|
|
|
|
colDaddr = cursor.getColumnIndex("daddr");
|
|
|
|
colDPort = cursor.getColumnIndex("dport");
|
|
|
|
colTime = cursor.getColumnIndex("time");
|
2016-01-30 11:46:00 +00:00
|
|
|
colBlock = cursor.getColumnIndex("block");
|
2016-01-27 10:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
|
|
return LayoutInflater.from(context).inflate(R.layout.access, parent, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void bindView(final View view, final Context context, final Cursor cursor) {
|
|
|
|
// Get values
|
2016-01-30 09:59:19 +00:00
|
|
|
String daddr = cursor.getString(colDaddr);
|
|
|
|
int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
|
2016-01-27 10:59:16 +00:00
|
|
|
long time = cursor.getLong(colTime);
|
2016-01-30 11:46:00 +00:00
|
|
|
int block = cursor.getInt(colBlock);
|
2016-01-27 10:59:16 +00:00
|
|
|
|
|
|
|
// Get views
|
|
|
|
TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
|
2016-01-30 11:46:00 +00:00
|
|
|
CheckBox cbBlock = (CheckBox) view.findViewById(R.id.cbBlock);
|
2016-01-27 12:09:08 +00:00
|
|
|
final TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
|
2016-01-27 10:59:16 +00:00
|
|
|
|
|
|
|
// Set values
|
|
|
|
tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));
|
2016-01-30 11:46:00 +00:00
|
|
|
cbBlock.setVisibility(block < 0 ? View.INVISIBLE : View.VISIBLE);
|
|
|
|
cbBlock.setChecked(block > 0);
|
|
|
|
tvDest.setText(daddr + (dport > 0 ? ":" + dport : ""));
|
2016-01-27 10:59:16 +00:00
|
|
|
}
|
|
|
|
}
|