package fr.nelaupe.spreedsheet;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import org.fluttercode.datafactory.impl.DataFactory;

import fr.nelaupe.spreadsheetlib.OnItemClickListener;
import fr.nelaupe.spreadsheetlib.SpreadSheetAdaptor;
import fr.nelaupe.spreadsheetlib.SpreadSheetCell;
import fr.nelaupe.spreadsheetlib.SpreadSheetData;
import fr.nelaupe.spreadsheetlib.SpreadSheetView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SpreadSheetView spreadSheetView = (SpreadSheetView) findViewById(R.id.spread_sheet);

        initSpreadSheet(spreadSheetView);
//        initSpreadSheetWithAdaptor(spreadSheetView);

        spreadSheetView.invalidate();
    }

    private class Test extends SpreadSheetData {

    }

    // Simple but not flexible. Create only text row.
    private void initSpreadSheet(SpreadSheetView spreadSheetView) {
        for (int i = 0; i < 30; i++) {
            spreadSheetView.add(generateDummyData(i));
        }
    }

    private void initSpreadSheetWithAdaptor(SpreadSheetView spreadSheetView ) {
        CustomCellAdaptor cellAdaptor = new CustomCellAdaptor();
        for (int i = 0; i < 30; i++) {
            cellAdaptor.add(generateDummyData(i));
        }

        cellAdaptor.setOnItemClickListener(new OnItemClickListener<Data>() {
            @Override
            public void onItemClick(Data item) {

            }
        });

        spreadSheetView.setAdaptor(cellAdaptor);
    }

    private Data generateDummyData(int i) {
        DataFactory df = new DataFactory();

        Data data = new Data(Comparators.class);
        data.column1 = i;
        data.column2 = df.getFirstName();
        data.column3 = df.getLastName();
        data.column4 = df.getCity();
        data.column5 = df.getBusinessName();
        data.column6 = df.getBirthDate().toString();
        data.column7 = df.getEmailAddress();
        data.column8 = i % 3 == 0;

        return  data;
    }


    private class CustomCellAdaptor extends SpreadSheetAdaptor<Data> {

        @Override
        public View getView(SpreadSheetCell cell, Object object) {
            if(object.getClass().equals(Boolean.class)) {
                return inflateCheckbox((Boolean) object);
            } else {
                return inflateTextView(object.toString());
            }
        }
    }

    private View inflateTextView(String text) {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.cell_textview, null, false);

        TextView textView = (TextView) view.findViewById(R.id.text);
        textView.setText(text);

        return view;
    }

    private View inflateCheckbox(Boolean bool){
        CheckBox checkBox = new CheckBox(MainActivity.this);
        checkBox.setChecked(bool);
        checkBox.setEnabled(false);
        return checkBox;
    }

}

@@ -455,58 +455,8 @@
 ll;%0A
-import fr.nelaupe.spreadsheetlib.SpreadSheetData;%0A
 impo
@@ -953,65 +953,8 @@
  %7D%0A%0A
-    private class Test extends SpreadSheetData %7B%0A%0A    %7D%0A%0A
     

Clean test