package bernhardwebstudio.shadowtravelor.adapter;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import bernhardwebstudio.shadowtravelor.R;
import bernhardwebstudio.shadowtravelor.data.ProfileDay;

/**
 * Created by Benedict on 16.09.2017.
 */

public class RowAdapter extends ArrayAdapter<ProfileDay> {

    private String[] weekdays = {"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"};

    private ArrayList<ProfileDay> profileDays = new ArrayList<ProfileDay>();
    private Context context;
    private int resource;

    public RowAdapter(@NonNull Context context, @LayoutRes int resource) {
        super(context, resource);
        this.context = context;
        this.resource = resource;
    }

    public RowAdapter(@NonNull Context context, @LayoutRes int resource, @IdRes int textViewResourceId) {
        super(context, resource, textViewResourceId);
        this.context = context;
        this.resource = resource;

    }

    public RowAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull ArrayList<ProfileDay> objects) {
        super(context, resource, objects);
        profileDays = objects;
        this.context = context;
        this.resource = resource;
    }

    public RowAdapter(@NonNull Context context, @LayoutRes int resource, @IdRes int textViewResourceId, @NonNull ArrayList<ProfileDay> objects) {
        super(context, resource, textViewResourceId, objects);
        this.context = context;
        this.resource = resource;
        this.profileDays = objects;
    }

    @Override
    public void add(ProfileDay pd){
        profileDays.add(pd);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            LayoutInflater inflater = LayoutInflater.from(getContext());
            convertView = inflater.inflate(resource, parent, false);
        }
        TextView day = (TextView) convertView.findViewById(R.id.day_text_label);
        ListView pdl = (ListView) convertView.findViewById(R.id.profile_detail_list);

        ProfileDay pd = profileDays.get(position);
        day.setText(weekdays[pd.getWeekday()].toString());

        ArrayAdapter<String> profileAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1);
        for(int i=0; i<pd.getRoute().size(); i++){


            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(pd.getRoute().get(i).getTime().getTimeInMillis());

            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            int minute = calendar.get(Calendar.MINUTE);

            profileAdapter.add(hour + ":" + minute + " - " + pd.getRoute().get(i).getLocation().getLatitude());
        }
        pdl.setAdapter(profileAdapter);
        return convertView;
    }
}

@@ -725,84 +725,81 @@
  %7B%22S
-onntag
+unday
 %22, %22Mon
-tag
+day
 %22, %22
-Dienstag%22, %22Mittwoch%22, %22Donnerstag
+Tuesday%22, %22Wednesday%22, %22Thursday
 %22, %22Fr
-eitag
+iday
 %22, %22Sa
-mstag
+turday
 %22%7D;%0A
@@ -3002,17 +3002,16 @@
 INUTE);%0A
-%0A
         
@@ -3018,50 +3018,219 @@
     
-profileAdapter.add(hour + %22:%22 + minute + %22
+String time = hour + %22:%22;%0A            if(minute%3C10)%7B%0A                time = time + %220%22 + minute;%0A            %7Delse%7B%0A                time = time + minute;%0A            %7D%0A            profileAdapter.add(time + %22 Uhr
  - %22

fix merge conflict