convert EventsAdapter to kotlin
This commit is contained in:
parent
5ac4a95531
commit
475dff59d8
|
@ -1,78 +0,0 @@
|
|||
package com.simplemobiletools.calendar.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.simplemobiletools.calendar.Formatter;
|
||||
import com.simplemobiletools.calendar.R;
|
||||
import com.simplemobiletools.calendar.models.Event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class EventsAdapter extends BaseAdapter {
|
||||
private final List<Event> mEvents;
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public EventsAdapter(Context context, List<Event> events) {
|
||||
mEvents = events;
|
||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
convertView = mInflater.inflate(R.layout.event_item, parent, false);
|
||||
viewHolder = new ViewHolder(convertView);
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
final Event event = mEvents.get(position);
|
||||
viewHolder.eventTitle.setText(event.getTitle());
|
||||
viewHolder.eventDescription.setText(event.getDescription());
|
||||
viewHolder.eventStart.setText(Formatter.getTime(event.getStartTS()));
|
||||
|
||||
if (event.getStartTS() == event.getEndTS()) {
|
||||
viewHolder.eventEnd.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
viewHolder.eventEnd.setText(Formatter.getTime(event.getEndTS()));
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mEvents.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mEvents.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static class ViewHolder {
|
||||
@BindView(R.id.event_item_title) TextView eventTitle;
|
||||
@BindView(R.id.event_item_description) TextView eventDescription;
|
||||
@BindView(R.id.event_item_start) TextView eventStart;
|
||||
@BindView(R.id.event_item_end) TextView eventEnd;
|
||||
|
||||
public ViewHolder(View view) {
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.simplemobiletools.calendar.adapters
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.BaseAdapter
|
||||
import com.simplemobiletools.calendar.Formatter
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import kotlinx.android.synthetic.main.event_item.view.*
|
||||
|
||||
class EventsAdapter(context: Context, private val mEvents: List<Event>) : BaseAdapter() {
|
||||
private val mInflater: LayoutInflater
|
||||
|
||||
init {
|
||||
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
}
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
var view = convertView
|
||||
val viewHolder: ViewHolder
|
||||
if (view == null) {
|
||||
view = mInflater.inflate(R.layout.event_item, parent, false)
|
||||
viewHolder = ViewHolder(view)
|
||||
view!!.tag = viewHolder
|
||||
} else {
|
||||
viewHolder = view.tag as ViewHolder
|
||||
}
|
||||
|
||||
val event = mEvents[position]
|
||||
viewHolder.title.text = event.title
|
||||
viewHolder.description.text = event.description
|
||||
viewHolder.start.text = Formatter.getTime(event.startTS)
|
||||
|
||||
if (event.startTS == event.endTS) {
|
||||
viewHolder.end.visibility = View.INVISIBLE
|
||||
} else {
|
||||
viewHolder.end.text = Formatter.getTime(event.endTS)
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return mEvents.size
|
||||
}
|
||||
|
||||
override fun getItem(position: Int): Any {
|
||||
return mEvents[position]
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return 0
|
||||
}
|
||||
|
||||
class ViewHolder(view: View) {
|
||||
val title = view.event_item_title
|
||||
val description = view.event_item_description
|
||||
val start = view.event_item_start
|
||||
val end = view.event_item_end
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue