package com.cliabhach.emptyhusk;

import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.v4.util.CircularArray;
import android.view.View;

import com.cliabhach.indicator.CutoutViewIndicator;
import com.cliabhach.indicator.CutoutViewLayoutParams;

/**
 * Little onClickListener for toggling through a range of different
 * indicator styles.
 *
 * @author Philip Cohn-Cort (Fuzz)
 */
class SwitchIndicatorsListener implements View.OnClickListener {
    @NonNull
    protected final CutoutViewIndicator cvi;

    @NonNull
    CircularArray<CutoutViewLayoutParams> storage = new CircularArray<>();

    public SwitchIndicatorsListener(@NonNull CutoutViewIndicator cvi) {
        this.cvi = cvi;

        CutoutViewLayoutParams rectangles = cvi.generateDefaultLayoutParams();
        rectangles.indicatorDrawableId = R.drawable.rectangle_accent;
        rectangles.cellBackgroundId = R.drawable.rectangle_secondary;
        rectangles.perpendicularLength = cvi.getResources().getDimensionPixelSize(R.dimen.rectangle_transverse);
        rectangles.cellLength = cvi.getResources().getDimensionPixelOffset(R.dimen.rectangle_length);
        storage.addLast(rectangles);

        CutoutViewLayoutParams circles = cvi.generateDefaultLayoutParams();
        circles.indicatorDrawableId = R.drawable.circle_accent;
        circles.cellBackgroundId = R.drawable.circle_secondary;
        int circleDiameter = cvi.getResources().getDimensionPixelSize(R.dimen.circle_diameter);
        circles.perpendicularLength = circleDiameter;
        circles.cellLength = circleDiameter;
        storage.addFirst(circles);
    }

    @CallSuper
    @Override
    public void onClick(View v) {
        cvi.setAllChildParamsTo(nextParams());
    }

    @NonNull
    private CutoutViewLayoutParams nextParams() {
        CutoutViewLayoutParams layoutParams = storage.popFirst();
        storage.addLast(layoutParams);
        return new CutoutViewLayoutParams(layoutParams);
    }
}

@@ -772,23 +772,20 @@
 tParams 
-rectang
+circ
 les = cv
@@ -821,31 +821,28 @@
 ();%0A        
-rectang
+circ
 les.indicato
@@ -866,23 +866,20 @@
 rawable.
-rectang
+circ
 le_accen
@@ -881,39 +881,36 @@
 accent;%0A        
-rectang
+circ
 les.cellBackgrou
@@ -927,23 +927,20 @@
 rawable.
-rectang
+circ
 le_secon
@@ -957,38 +957,26 @@
     
-rectangles.perpendicularLength
+int circleDiameter
  = c
@@ -1027,170 +1027,257 @@
 men.
-rectangle_transverse);%0A        rectangles.cellLength = cvi.getResources().get
+circle_diameter);%0A        circles.perpendicularLength = circle
 Di
+a
 me
-nsionPixelOffset(R.dimen.rectangle_length);%0A        storage.addLast(rectangles);%0A
+ter;%0A        circles.cellLength = circleDiameter;%0A        storage.addFirst(circles);%0A%0A        // The rectangle params should be at the end of the array when this constructor returns.
 %0A   
@@ -1296,36 +1296,39 @@
 iewLayoutParams 
-circ
+rectang
 les = cvi.genera
@@ -1352,36 +1352,39 @@
 rams();%0A        
-circ
+rectang
 les.indicatorDra
@@ -1396,36 +1396,39 @@
 Id = R.drawable.
-circ
+rectang
 le_accent;%0A     
@@ -1422,36 +1422,39 @@
 accent;%0A        
-circ
+rectang
 les.cellBackgrou
@@ -1463,36 +1463,39 @@
 Id = R.drawable.
-circ
+rectang
 le_secondary;%0A  
@@ -1500,34 +1500,46 @@
         
-int circleDiameter
+rectangles.perpendicularLength
  = cvi.g
@@ -1586,123 +1586,131 @@
 men.
-circle_diameter);%0A        circles.perpendicularLength = circleDiameter;%0A        ci
+rectangle_transverse);%0A        rectangles.cellLength = cvi.getResou
 rc
-l
 es
-.cellLength = circleDiameter
+().getDimensionPixelOffset(R.dimen.rectangle_length)
 ;%0A  
@@ -1722,34 +1722,36 @@
  storage.add
-First(circ
+Last(rectang
 les);%0A    %7D%0A

Reorder parameters in SwitchIndicatorsListener