NetGuard/app/src/main/java/eu/faircode/netguard/AccessAdapter.java

76 lines
2.6 KiB
Java
Raw Normal View History

package eu.faircode.netguard;
2016-01-30 13:26:30 +00:00
/*
This file is part of NetGuard.
NetGuard is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NetGuard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
Copyright 2015-2016 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
2016-01-30 13:26:30 +00:00
import android.widget.ImageView;
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;
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");
}
@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));
long time = cursor.getLong(colTime);
2016-01-30 11:46:00 +00:00
int block = cursor.getInt(colBlock);
// Get views
TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
2016-01-30 13:26:30 +00:00
ImageView ivBlock = (ImageView) view.findViewById(R.id.ivBlock);
2016-01-27 12:09:08 +00:00
final TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
// Set values
2016-01-30 19:44:58 +00:00
tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
2016-01-30 13:26:30 +00:00
if (block < 0)
ivBlock.setImageDrawable(null);
else
ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
2016-01-30 11:46:00 +00:00
tvDest.setText(daddr + (dport > 0 ? ":" + dport : ""));
}
}