<commit_before>package com.example.kaveon14.workoutbuddy.Fragments.MainFragments;
//TODO delete un-needed onCreate methods
import android.app.SearchManager;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.example.kaveon14.workoutbuddy.DataBase.Data.SubWorkout;
import com.example.kaveon14.workoutbuddy.DataBase.DatabaseManagment.DataBaseContract;
import com.example.kaveon14.workoutbuddy.DataBase.WorkoutExercise;
import com.example.kaveon14.workoutbuddy.DataBase.TableManagers.WorkoutStatsTable;
import com.example.kaveon14.workoutbuddy.Fragments.SubFragments.FullWorkoutStatsFragment;
import com.example.kaveon14.workoutbuddy.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
// use floating action button to reset list
import static android.content.Context.SEARCH_SERVICE;
//possily create binary search tree to speedup matching searched item times
public class WorkoutStatsFragment extends Fragment {

    private List<SubWorkout> subWorkoutList;
    private Menu menu;
    private View root;
    private RecyclerAdapter recyclerAdapter;

    public WorkoutStatsFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        root = inflater.inflate(R.layout.fragment_workout_stats, container, false);
        new MyAsyncTask().execute(subWorkoutList);
        setSearchViewOnClick();
        return root;
    }

    @Override
    public void onDetach() {
        super.onDetach();
        resetFloatingActionButton();
    }

    private void resetFloatingActionButton() {
        FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
        if(fab != null) {
            fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //do nothing
                }
            });
        }
    }

    public void setMenu(Menu menu) {
        this.menu = menu;
    }

    private void setRecycleView(View root,RecyclerAdapter adapter) {
        RecyclerView.LayoutManager manager = new GridLayoutManager(getContext(),2);
        RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.workoutStatsRecycleView);
        recyclerView.setItemViewCacheSize(12);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
        if (subWorkoutList.size()==0) {
            TextView textView = (TextView) root.findViewById(R.id.noWorkoutStats);
            textView.setVisibility(View.VISIBLE);
        }

    }

    private void setSearchViewOnClick() {
        SearchView searchView =
                (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
        SearchManager searchManager = (SearchManager) getActivity().getSystemService(SEARCH_SERVICE);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                WorkoutStatsTable table = new WorkoutStatsTable(getContext());
                loadSearchedItems(table.searchTable(query));
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
    }

    private void setListViewOnClick(ListView listView) {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                showFullWorkoutStatsFragment(subWorkoutList.get(position).getWorkoutData());
            }
        });
    }

    private void showFullWorkoutStatsFragment(List<WorkoutExercise> workoutData) {
        FullWorkoutStatsFragment fw = new FullWorkoutStatsFragment();
        fw.setWorkoutData(workoutData);
        getFragmentManager().beginTransaction()
                .hide(this)
                .add(R.id.fullWorkoutStats_fragment,fw)
                .addToBackStack(null)
                .commit();
    }
    //redo
    public List<SubWorkout> loadSearchedItems(Map<String,List<String>> queriedData) {
        List<SubWorkout> list = new ArrayList<>();
        if(queriedData!=null) {
            List<String> mainWorkoutNames = queriedData.get(DataBaseContract.WorkoutData.COLUMN_MAINWORKOUT);
            List<String> subWorkoutNames = queriedData.get(DataBaseContract.WorkoutData.COLUMN_SUBWORKOUT);
            List<String> dates = queriedData.get(DataBaseContract.WorkoutData.COLUMN_DATE);

            for (int x = 0; x < mainWorkoutNames.size(); x++) {
                String mainWorkoutName = mainWorkoutNames.get(x);
                String subWorkoutName = subWorkoutNames.get(x);
                String date = dates.get(x);

                for (int i = 0; i < subWorkoutList.size(); i++) {
                    SubWorkout subWorkout = subWorkoutList.get(i);
                    String mainName = subWorkout.getMainWorkoutName();
                    String subName = subWorkout.getSubWorkoutName();
                    String dateSubWorkoutList = subWorkout.getDate();

                    if(mainWorkoutName.equals(mainName) && subWorkoutName.equals(subName)
                            && date.equals(dateSubWorkoutList)) {
                        list.add(subWorkout);
                    }
                }
            }
        }

        return list;
    }

    private class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.CustomViewHolder> {

        private List<SubWorkout> subWorkoutList;

        public RecyclerAdapter(List<SubWorkout> subWorkoutList) {
            this.subWorkoutList = subWorkoutList;
        }

        @Override
        public int getItemCount() {
            return (null != subWorkoutList ? subWorkoutList.size() : 0);
        }

        @Override
        public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup,int i) {
            View view = LayoutInflater.from(viewGroup.getContext())
                    .inflate(R.layout.workout_card_view,null);
            return new CustomViewHolder(view);
        }

        @Override
        public void onBindViewHolder(CustomViewHolder customViewHolder,int i) {
            SubWorkout subWorkout = subWorkoutList.get(i);
            customViewHolder.dateView.setText(customViewHolder.dateView.getText()+" "+
            getParsedDate(subWorkout.getDate()));<commit_msg>coverted search query for recyclerview in workoutStats fragment<commit_after>package com.example.kaveon14.workoutbuddy.Fragments.MainFragments;
//TODO delete un-needed onCreate methods
import android.app.SearchManager;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.example.kaveon14.workoutbuddy.DataBase.Data.SubWorkout;
import com.example.kaveon14.workoutbuddy.DataBase.DatabaseManagment.DataBaseContract;
import com.example.kaveon14.workoutbuddy.DataBase.WorkoutExercise;
import com.example.kaveon14.workoutbuddy.DataBase.TableManagers.WorkoutStatsTable;
import com.example.kaveon14.workoutbuddy.Fragments.SubFragments.FullWorkoutStatsFragment;
import com.example.kaveon14.workoutbuddy.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
// use floating action button to reset list
import static android.content.Context.SEARCH_SERVICE;
//possily create binary search tree to speedup matching searched item times
public class WorkoutStatsFragment extends Fragment {

    private List<SubWorkout> subWorkoutList;
    private Menu menu;
    private View root;
    private RecyclerAdapter recyclerAdapter;
    private RecyclerView recyclerView;

    public WorkoutStatsFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        root = inflater.inflate(R.layout.fragment_workout_stats, container, false);
        new MyAsyncTask().execute(subWorkoutList);
        setSearchViewOnClick();
        return root;
    }

    @Override
    public void onDetach() {
        super.onDetach();
        resetFloatingActionButton();
    }

    private void resetFloatingActionButton() {
        FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
        if(fab != null) {
            fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //do nothing
                }
            });
        }
    }

    public void setMenu(Menu menu) {
        this.menu = menu;
    }

    private void setRecycleView(View root,RecyclerAdapter adapter) {
        RecyclerView.LayoutManager manager = new GridLayoutManager(getContext(),2);
        recyclerView = (RecyclerView) root.findViewById(R.id.workoutStatsRecycleView);
        recyclerView.setItemViewCacheSize(12);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
        if (subWorkoutList.size()==0) {
            TextView textView = (TextView) root.findViewById(R.id.noWorkoutStats);
            textView.setVisibility(View.VISIBLE);
        }

    }

    private void setSearchViewOnClick() {
        SearchView searchView =
                (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
        SearchManager searchManager = (SearchManager) getActivity().getSystemService(SEARCH_SERVICE);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                WorkoutStatsTable table = new WorkoutStatsTable(getContext());
                loadSearchedItems(table.searchTable(query));
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
    }

    private void setListViewOnClick(ListView listView) {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                showFullWorkoutStatsFragment(subWorkoutList.get(position).getWorkoutData());
            }
        });
    }

    private void showFullWorkoutStatsFragment(List<WorkoutExercise> workoutData) {
        FullWorkoutStatsFragment fw = new FullWorkoutStatsFragment();
        fw.setWorkoutData(workoutData);
        getFragmentManager().beginTransaction()
                .hide(this)
                .add(R.id.fullWorkoutStats_fragment,fw)
                .addToBackStack(null)
                .commit();
    }
    //redo for better big o
    public List<SubWorkout> loadSearchedItems(Map<String,List<String>> queriedData) {
        List<SubWorkout> list = new ArrayList<>();
        if(queriedData!=null) {
            List<String> mainWorkoutNames = queriedData.get(DataBaseContract.WorkoutData.COLUMN_MAINWORKOUT);
            List<String> subWorkoutNames = queriedData.get(DataBaseContract.WorkoutData.COLUMN_SUBWORKOUT);
            List<String> dates = queriedData.get(DataBaseContract.WorkoutData.COLUMN_DATE);

            for (int x = 0; x < mainWorkoutNames.size(); x++) {
                String mainWorkoutName = mainWorkoutNames.get(x);
                String subWorkoutName = subWorkoutNames.get(x);
                String date = dates.get(x);

                for (int i = 0; i < subWorkoutList.size(); i++) {
                    SubWorkout subWorkout = subWorkoutList.get(i);
                    String mainName = subWorkout.getMainWorkoutName();
                    String subName = subWorkout.getSubWorkoutName();
                    String dateSubWorkoutList = subWorkout.getDate();

                    if(mainWorkoutName.equals(mainName) && subWorkoutName.equals(subName)
                            && date.equals(dateSubWorkoutList)) {
                        list.add(subWorkout);
                    }
                }
            }
        }
        recyclerView.setAdapter(new RecyclerAdapter(list));
        return list;
    }

    private class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.CustomViewHolder> {

        private List<SubWorkout> subWorkoutList;

        public RecyclerAdapter(List<SubWorkout> subWorkoutList) {
            this.subWorkoutList = subWorkoutList;
        }

        @Override
        public int getItemCount() {
            return (null != subWorkoutList ? subWorkoutList.size() : 0);
        }

        @Override
        public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup,int i) {
            View view = LayoutInflater.from(viewGroup.getContext())
                    .inflate(R.layout.workout_card_view,null);
            return new CustomViewHolder(view);
        }

        @Override
        public void onBindViewHolder(CustomViewHolder customViewHolder,int i) {
            SubWorkout subWorkout = subWorkoutList.get(i);
            customViewHolder.dateView.setText(customViewHolder.dateView.getText()+" "+
            getParsedDate(subWorkout.getDate()));
{'fraction_non_alphanumeric': 0.08807712486883526, 'fraction_numerical': 0.003541448058761805, 'mean_word_length': 2.8008474576271185, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2149676', 'n_tokens_mistral': 4237, 'n_tokens_neox': 4066, 'n_words': 734}