From 24cd478bbf0f7dac15259386fbf8498488b9da4b Mon Sep 17 00:00:00 2001 From: Shekhar Sahu Date: Thu, 17 Dec 2015 15:50:54 +0530 Subject: [PATCH] + Ceated new suggestion list item layout file 'suggestion_ite.xml'. + Created new List Adapter file (SuggestionListAdapet.java) & (SuggestionItemViewCreater.java) to handle suggestion list row item information. --- .../newpipe/SuggestionItemViewCreator.java | 55 ++++++++++++ .../schabi/newpipe/SuggestionListAdapter.java | 87 +++++++++++++++++++ app/src/main/res/layout/suggestion_item.xml | 45 ++++++++++ 3 files changed, 187 insertions(+) create mode 100644 app/src/main/java/org/schabi/newpipe/SuggestionItemViewCreator.java create mode 100644 app/src/main/java/org/schabi/newpipe/SuggestionListAdapter.java create mode 100644 app/src/main/res/layout/suggestion_item.xml diff --git a/app/src/main/java/org/schabi/newpipe/SuggestionItemViewCreator.java b/app/src/main/java/org/schabi/newpipe/SuggestionItemViewCreator.java new file mode 100644 index 000000000..707affa98 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/SuggestionItemViewCreator.java @@ -0,0 +1,55 @@ +package org.schabi.newpipe; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +/** + * Created by shekhar on 10/12/15. + * + * SuggestionItemViewCreator.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + +public class SuggestionItemViewCreator { + private final LayoutInflater inflater; + + public SuggestionItemViewCreator(LayoutInflater inflater) { + this.inflater = inflater; + } + + public View getViewByVideoInfoItem(View convertView, ViewGroup parent, String suggestion) { + ViewHolder holder; + if(convertView == null) { + convertView = inflater.inflate(R.layout.suggestion_item, parent, false); + holder = new ViewHolder(); + holder.suggestionTitle = (TextView) convertView.findViewById(R.id.suggestionTitle); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } + + holder.suggestionTitle.setText(suggestion); + + return convertView; + } + + private class ViewHolder { + public TextView suggestionTitle; + } + +} + diff --git a/app/src/main/java/org/schabi/newpipe/SuggestionListAdapter.java b/app/src/main/java/org/schabi/newpipe/SuggestionListAdapter.java new file mode 100644 index 000000000..9689e7a82 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/SuggestionListAdapter.java @@ -0,0 +1,87 @@ +package org.schabi.newpipe; + +import android.content.Context; +import android.support.v4.content.ContextCompat; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ListView; + +import java.util.ArrayList; + +/** + * Created by shekhar on 10/12/15. + * + * SuggestionItemViewCreator.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ +public class SuggestionListAdapter extends BaseAdapter { + + private final Context context; + private final SuggestionItemViewCreator viewCreator; + private ArrayList suggestionList = new ArrayList<>(); + private final ListView listView; + + public SuggestionListAdapter(Context context, VideoItemListFragment suggestionListFragment) { + viewCreator = new SuggestionItemViewCreator(LayoutInflater.from(context)); + this.listView = suggestionListFragment.getListView(); + this.listView.setDivider(null); + this.listView.setDividerHeight(0); + this.context = context; + } + + public void addSuggestionList(ArrayList suggestionList) { + this.suggestionList.addAll(suggestionList); + notifyDataSetChanged(); + } + + public void clearSuggestionList() { + suggestionList = new ArrayList<>(); + notifyDataSetChanged(); + } + + @Override + public int getCount() { + return suggestionList.size(); + } + + @Override + public Object getItem(int position) { + return suggestionList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + convertView = viewCreator.getViewByVideoInfoItem(convertView, parent, suggestionList.get(position)); + + if(listView.isItemChecked(position)) { + convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.primaryColorYoutube)); + } else { + convertView.setBackgroundColor(0); + } + + return convertView; + } + + public ArrayList getData(){ + return suggestionList; + } +} diff --git a/app/src/main/res/layout/suggestion_item.xml b/app/src/main/res/layout/suggestion_item.xml new file mode 100644 index 000000000..665a0f415 --- /dev/null +++ b/app/src/main/res/layout/suggestion_item.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + 
 + + 
 +