package com.test.smartnotes;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.test.smartnotes.database.DBAdapter;

public class ListNotesActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        DBAdapter.init(this);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_notes);
        Toolbar toolbar = (Toolbar) findViewById(R.id.list_notes_toolbar);
        setSupportActionBar(toolbar);

        ListView listView = (ListView)findViewById(R.id.notes_listView);
        ListNotesAdapter listNotesAdapter = new ListNotesAdapter(this, DBAdapter.getAllNoteData());
        listView.setAdapter(listNotesAdapter);
        registerForContextMenu(listView);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
            Log.d("Clicked item id", "itemClick: position = " + position + ", id = " + id);
            Intent intent = new Intent(ListNotesActivity.this, ViewNoteActivity.class);
            intent.putExtra("id", (int) id);
            startActivity(intent);
            }
        });

    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
                                    ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.view_note_menu, menu);
    }

    public void RemoveNoteDialog (final String id) {
        DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which){
                    case DialogInterface.BUTTON_POSITIVE:
                        DBAdapter.deleteNoteData(id);
                        dialog.dismiss();
                        refreshListView();
                        break;

                    case DialogInterface.BUTTON_NEGATIVE:
                        dialog.dismiss();
                        break;
                }
            }
        };

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.are_you_sure)
                .setPositiveButton(R.string.option_yes, dialogClickListener)
                .setNegativeButton(R.string.option_no, dialogClickListener).show();
    }

    private void refreshListView () {
        // Most likely not the best way to solve the refresh task but it works
        ListView listView = (ListView)findViewById(R.id.notes_listView);
        ListNotesAdapter listNotesAdapter = new ListNotesAdapter(this, DBAdapter.getAllNoteData());
        listView.setAdapter(listNotesAdapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.list_notes_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        switch (item.getItemId()) {
            case R.id.action_edit_note:
//                Intent intent = new Intent(ListNotesActivity.this, EditNoteActivity.class);
//                intent.putExtra("id", info.id);
//                startActivity(intent);
                return true;
            case R.id.action_remove_note:
                RemoveNoteDialog(String.valueOf(info.id));
                return true;
            default:
                return super.onContextItemSelected(item);
        }
    }

}

@@ -3495,32 +3495,512 @@
 u(menu);%0A    %7D%0A%0A
+    @Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        switch (item.getItemId()) %7B%0A            case R.id.action_create_note:%0A                startActivity(new Intent(ListNotesActivity.this, CreateNoteActivity.class));%0A                return true;%0A            case R.id.action_show_map:%0A                // place for map displaying%0A                return true;%0A            default:%0A                return super.onOptionsItemSelected(item);%0A        %7D%0A    %7D%0A%0A
     @Override%0A  

Add CreateNote Activity intent