package ca.antonious.viewcelladapter.sections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import ca.antonious.viewcelladapter.viewcells.AbstractViewCell;
import ca.antonious.viewcelladapter.viewcells.GenericViewCell;
import ca.antonious.viewcelladapter.viewcells.GenericViewCellFactory;

/**
 * Created by George on 2016-12-19.
 */

public class HomogeneousSection<TModel, TViewCell extends GenericViewCell<?, TModel>> extends AbstractSection {
    private GenericViewCellFactory<TModel, TViewCell> viewCellFactory;
    private List<TViewCell> viewCells;

    public HomogeneousSection(GenericViewCellFactory<TModel, TViewCell> viewCellFactory) {
        this.viewCellFactory = viewCellFactory;
        this.viewCells = new ArrayList<>();
    }

    public void add(TModel model) {
        this.viewCells.add(viewCellFactory.createViewCell(model));
    }

    public void addAll(Collection<? extends TModel> models) {
        this.viewCells.addAll(viewCellFactory.createAllViewCells(models));
    }

    public void setAll(Collection<? extends TModel> models) {
        this.viewCells.clear();
        this.viewCells.addAll(viewCellFactory.createAllViewCells(models));
    }

    public void prependAll(Collection<? extends TModel> models) {
        List<TViewCell> newList = new ArrayList<>();
        newList.addAll(viewCellFactory.createAllViewCells(models));
        newList.addAll(this.viewCells);

        this.viewCells.clear();
        this.viewCells.addAll(newList);
    }

    public void clear() {
        viewCells.clear();
    }

    @Override
    public AbstractViewCell get(int position) {
        return viewCells.get(position);
    }

    @Override
    public void remove(int position) {
        viewCells.remove(position);
    }

    @Override
    public int getItemCount() {
        return viewCells.size();
    }
}

@@ -98,16 +98,75 @@
 ection;%0A
+import java.util.Collections;%0Aimport java.util.Comparator;%0A
 import j
@@ -180,16 +180,16 @@
 l.List;%0A
-
 %0Aimport 
@@ -603,24 +603,80 @@
 ellFactory;%0A
+    private Comparator%3C? super TModel%3E modelComparator;%0A
     private 
@@ -992,24 +992,49 @@
 ll(model));%0A
+        sortViewCells();%0A
     %7D%0A%0A    p
@@ -1157,32 +1157,57 @@
 Cells(models));%0A
+        sortViewCells();%0A
     %7D%0A%0A    publi
@@ -1362,24 +1362,49 @@
 s(models));%0A
+        sortViewCells();%0A
     %7D%0A%0A    p
@@ -1697,16 +1697,42 @@
 ewList);
+%0A%0A        sortViewCells();
 %0A    %7D%0A%0A
@@ -1753,24 +1753,24 @@
 d clear() %7B%0A
-
         view
@@ -1783,32 +1783,671 @@
 clear();%0A    %7D%0A%0A
+    public void setModelComparator(Comparator%3C? super TModel%3E modelComparator) %7B%0A        this.modelComparator = modelComparator;%0A        sortViewCells();%0A    %7D%0A%0A    public boolean isSortingEnabled() %7B%0A        return modelComparator != null;%0A    %7D%0A%0A    private void sortViewCells() %7B%0A        if (isSortingEnabled()) %7B%0A            Collections.sort(viewCells, new Comparator%3CTViewCell%3E() %7B%0A                @Override%0A                public int compare(TViewCell viewCell1, TViewCell viewCell2) %7B%0A                    return modelComparator.compare(viewCell1.getModel(), viewCell2.getModel());%0A                %7D%0A            %7D);%0A        %7D%0A    %7D%0A%0A
     @Override%0A  

Provide way to sort data in a HomogenousSection