package com.carlfolkesson.medicinehandler;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

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

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private RecyclerView.Adapter adapter;

    private List<MedicineItem> medicineItems;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        createRecyclerView();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    /**
     * Creates a RecyclerView containing a name and a number
     */
    private void createRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        medicineItems = new ArrayList<>();

        for(int i = 0; i<10; i++) {
            MedicineItem medicineItem = new MedicineItem(
                    "Medicin " + (i+1),
                    (i+1)
            );
            medicineItems.add(medicineItem);
        }

        adapter = new MedicineAdapter(medicineItems);

        recyclerView.setAdapter(adapter);
    }
}

@@ -680,16 +680,44 @@
 Items;%0A%0A
+    private int index = 4;%0A%0A
     @Ove
@@ -1199,16 +1199,18 @@
         
+/*
 Snackbar
@@ -1329,24 +1329,303 @@
 ull).show();
+*/%0A                MedicineItem medicineItem = new MedicineItem(%0A                        %22Medicin %22 + index,%0A                        index%0A                );%0A                medicineItems.add(medicineItem);%0A                index++;%0A                adapter.notifyDataSetChanged();
 %0A           
@@ -2786,10 +2786,9 @@
 ; i%3C
-10
+3
 ; i+

Make add button add a new medicine