package erica.beakon.Pages;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.GenericTypeIndicator;
import com.google.firebase.database.ValueEventListener;

import java.lang.reflect.GenericSignatureFormatError;
import java.util.ArrayList;

import erica.beakon.Adapters.FirebaseHandler;
import erica.beakon.Adapters.UserPreferencesAdapter;
import erica.beakon.MainActivity;
import erica.beakon.Objects.User;
import erica.beakon.R;

/**
 * Created by mafaldaborges on 11/17/16.
 */
public class UserPreferencesPage extends android.support.v4.app.Fragment {


    UserPreferencesAdapter userPreferencesAdapter;
    ArrayList<String> hashtagList;
    User currentUser;




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_user_preferences_page, container, false);
        view.setBackgroundColor(Color.parseColor("#ffffff"));


        final MainActivity activity = (MainActivity) getActivity();
        currentUser = activity.currentUser;

        hashtagList = new ArrayList<String>();


        final ListView lv = (ListView) view.findViewById(R.id.listView);
        userPreferencesAdapter = new UserPreferencesAdapter(getActivity(),hashtagList);
        lv.setAdapter(userPreferencesAdapter);

        activity.firebaseHandler.getHashtagsfromUser(currentUser, new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot.getValue() != null){
                    hashtagList.clear();
                    ArrayList<Object> list = dataSnapshot.getValue(new GenericTypeIndicator<ArrayList<Object>>() {
                        @Override
                        public String toString() {
                            return super.toString();
                        }
                    });
                    for(Object hash : list) {
                        hashtagList.add(hash.toString());
                        userPreferencesAdapter.notifyDataSetChanged();
                    }
                    currentUser.setHashtagList(hashtagList);
                }
            }
            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

        ImageButton addButton = (ImageButton) view.findViewById(R.id.add_user_preference);
        final EditText newInterest = (EditText) view.findViewById(R.id.user_preferences_new);

        addButton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                String inputText = newInterest.getText().toString();
                newInterest.getText().clear();
                currentUser.addHashtag(inputText);
                activity.firebaseHandler.updateUser(currentUser);
                userPreferencesAdapter.notifyDataSetChanged();

            }
        });

        return view;
    }
}

@@ -51,16 +51,48 @@
 agment;%0A
+import android.content.Context;%0A
 import a
@@ -110,24 +110,24 @@
 hics.Color;%0A
-
 import andro
@@ -258,16 +258,68 @@
 wGroup;%0A
+import android.view.inputmethod.InputMethodManager;%0A
 import a
@@ -1599,25 +1599,24 @@
 ffffff%22));%0A%0A
-%0A
         fina
@@ -1764,17 +1764,16 @@
 ng%3E();%0A%0A
-%0A
         
@@ -3506,16 +3506,16 @@
 tUser);%0A
-
         
@@ -3566,24 +3566,344 @@
 Changed();%0A%0A
+                View view = getActivity().getCurrentFocus();%0A                if (view != null) %7B%0A                    InputMethodManager imm = (InputMethodManager)(getActivity()).getSystemService(Context.INPUT_METHOD_SERVICE);%0A                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);%0A                %7D%0A%0A
             

Merge Conflict