@@ -0,0 +1,2701 @@
+package io.github.imsmobile.fahrplan.adapter;%0A%0Aimport android.content.Context;%0Aimport android.support.annotation.NonNull;%0Aimport android.util.Log;%0Aimport android.widget.ArrayAdapter;%0Aimport android.widget.Filter;%0Aimport android.widget.Filterable;%0A%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.concurrent.CopyOnWriteArrayList;%0A%0Aimport ch.schoeb.opendatatransport.IOpenTransportRepository;%0Aimport ch.schoeb.opendatatransport.OpenDataTransportException;%0Aimport ch.schoeb.opendatatransport.OpenTransportRepositoryFactory;%0Aimport ch.schoeb.opendatatransport.model.Station;%0Aimport io.github.imsmobile.fahrplan.Constants;%0A%0Apublic class StationAdapter extends ArrayAdapter%3CString%3E implements Filterable %7B%0A%0A    private List%3CString%3E stations;%0A%0A    public StationAdapter(Context context, int textViewResourceId) %7B%0A        super(context, textViewResourceId);%0A    %7D%0A%0A    @Override%0A    public int getCount() %7B%0A        return stations.size();%0A    %7D%0A%0A    @Override%0A    public String getItem(int index) %7B%0A        return stations.get(index);%0A    %7D%0A%0A    @NonNull%0A    @Override%0A    public Filter getFilter() %7B%0A        return new Filter() %7B%0A            @Override%0A            protected FilterResults performFiltering(CharSequence constraint) %7B%0A                FilterResults filterResult = new FilterResults();%0A                if (constraint != null) %7B%0A                    stations = autocomplete(constraint.toString());%0A%0A                    filterResult.values = stations;%0A                    filterResult.count = stations.size();%0A                %7D%0A                return filterResult;%0A            %7D%0A%0A            private List%3CString%3E autocomplete(String query) %7B%0A                IOpenTransportRepository repo = OpenTransportRepositoryFactory.CreateOnlineOpenTransportRepository();%0A                try %7B%0A                    List%3CStation%3E stations = repo.findStations(query).getStations();%0A                    List%3CString%3E stationNames = new CopyOnWriteArrayList%3C%3E();%0A                    for (Station station : stations) %7B%0A                        stationNames.add(station.getName());%0A                    %7D%0A                    return stationNames;%0A                %7D catch (OpenDataTransportException e) %7B%0A                    Log.e(Constants.LOG, e.getMessage(), e);%0A                    return Collections.emptyList();%0A                %7D%0A            %7D%0A%0A            @Override%0A            protected void publishResults(CharSequence constraint, FilterResults results) %7B%0A                if (results != null && results.count %3E 0) %7B%0A                    notifyDataSetChanged();%0A                %7D%0A                else %7B%0A                    notifyDataSetInvalidated();%0A                %7D%0A            %7D%7D;%0A    %7D%0A%0A%0A%7D

Create StationAdapter that dynamically loads stations based on a given input