/*
Swisscom Safe Connect
Copyright (C) 2014 Swisscom
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.swisscom.safeconnect.adapter;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.swisscom.safeconnect.R;
import com.swisscom.safeconnect.model.PlumberIncidentsResponse;
import com.swisscom.safeconnect.model.PlumberIncidentsResponseList;
import java.text.DateFormat;
import java.util.Date;
public class IncidentBlockedUrlAdapter extends ArrayAdapter<PlumberIncidentsResponse> {
public IncidentBlockedUrlAdapter(Context context, int textViewResourceId,
PlumberIncidentsResponseList objects) {
super(context, textViewResourceId, objects.getIncidents());
}
static class ViewHolder {
TextView url;
TextView dateTime;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
PlumberIncidentsResponse incident = getItem(position);
// helps to reuse objects and avoid allocating a memory
if (convertView == null) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
convertView = inflater.inflate(R.layout.item_blocked_url, parent, false);
ViewHolder h = new ViewHolder();
h.url = (TextView) convertView.findViewById(R.id.tv_url);
h.dateTime = (TextView) convertView.findViewById(R.id.tv_date);
convertView.setTag(h);
}
ViewHolder vh = (ViewHolder) convertView.getTag();
vh.url.setText(incident.getUrl());
Date date = new Date(incident.getTimestamp()*1000);
vh.dateTime.setText( DateFormat.getDateInstance().format(date));
return convertView;
}
@Override
public boolean isEnabled(int position) {
return false;
}
}