mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 07:13:00 +00:00 
			
		
		
		
	+ 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.
This commit is contained in:
		| @@ -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 <http://www.gnu.org/licenses/>. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | 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; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
| @@ -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 <http://www.gnu.org/licenses/>. | ||||||
|  |  */ | ||||||
|  | public class SuggestionListAdapter extends BaseAdapter { | ||||||
|  |  | ||||||
|  |     private final Context context; | ||||||
|  |     private final SuggestionItemViewCreator viewCreator; | ||||||
|  |     private ArrayList<String> 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<String> 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<String> getData(){ | ||||||
|  |         return suggestionList; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										45
									
								
								app/src/main/res/layout/suggestion_item.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								app/src/main/res/layout/suggestion_item.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:card_view="http://schemas.android.com/apk/res-auto" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="wrap_content"> | ||||||
|  |  | ||||||
|  |     <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" | ||||||
|  |         android:id="@+id/card_view" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_gravity="center" | ||||||
|  |         android:layout_marginBottom="@dimen/video_item_search_card_vertical_margin" | ||||||
|  |         android:layout_marginLeft="@dimen/video_item_search_card_horizontal_margin" | ||||||
|  |         android:layout_marginRight="@dimen/video_item_search_card_horizontal_margin" | ||||||
|  |         android:layout_marginTop="@dimen/video_item_search_card_vertical_margin" | ||||||
|  |         android:orientation="vertical" | ||||||
|  |         card_view:cardCornerRadius="@dimen/video_item_search_card_radius"> | ||||||
|  |  | ||||||
|  |         <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:orientation="vertical" | ||||||
|  |             android:padding="@dimen/video_item_search_card_padding"> | ||||||
|  |  | ||||||
|  |             <TextView | ||||||
|  |                 android:id="@+id/suggestionTitle" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:layout_marginBottom="@dimen/video_item_search_duration_margin" | ||||||
|  |                 android:layout_marginEnd="@dimen/video_item_search_duration_margin" | ||||||
|  |                 android:layout_marginRight="@dimen/video_item_search_duration_margin" | ||||||
|  |                 android:paddingBottom="@dimen/video_item_search_duration_vertical_padding" | ||||||
|  |                 android:paddingLeft="@dimen/video_item_search_duration_horizontal_padding" | ||||||
|  |                 android:paddingRight="@dimen/video_item_search_duration_horizontal_padding" | ||||||
|  |                 android:paddingTop="@dimen/video_item_search_duration_vertical_padding" | ||||||
|  |                 android:textAppearance="?android:attr/textAppearanceSmall" | ||||||
|  |                 android:textColor="@color/accentColorYoutube" | ||||||
|  |                 android:textSize="@dimen/video_item_search_title_text_size" /> | ||||||
|  |  | ||||||
|  |         </RelativeLayout> | ||||||
|  |         
 | ||||||
|  |     </android.support.v7.widget.CardView> | ||||||
|  |     
 | ||||||
|  | </LinearLayout> | ||||||
		Reference in New Issue
	
	Block a user
	 Shekhar Sahu
					Shekhar Sahu