mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Add grid view and list adapter
This commit is contained in:
		
							parent
							
								
									48c7a0372e
								
							
						
					
					
						commit
						b0cd6a9a47
					
				
					 5 changed files with 194 additions and 4 deletions
				
			
		|  | @ -0,0 +1,43 @@ | |||
| package fr.free.nrw.commons.featured; | ||||
| 
 | ||||
| import android.graphics.Bitmap; | ||||
| 
 | ||||
| /** | ||||
|  * Created by root on 09.01.2018. | ||||
|  */ | ||||
| 
 | ||||
| public class FeaturedImage { | ||||
|     private Bitmap image; | ||||
|     private String author; | ||||
|     private String fileName; | ||||
| 
 | ||||
|     public FeaturedImage(Bitmap image, String author, String fileName) { | ||||
|         this.image = image; | ||||
|         this.author = author; | ||||
|         this.fileName = fileName; | ||||
|     } | ||||
| 
 | ||||
|     public Bitmap getImage() { | ||||
|         return image; | ||||
|     } | ||||
| 
 | ||||
|     public void setImage(Bitmap image) { | ||||
|         this.image = image; | ||||
|     } | ||||
| 
 | ||||
|     public String getAuthor() { | ||||
|         return author; | ||||
|     } | ||||
| 
 | ||||
|     public void setAuthor(String author) { | ||||
|         this.author = author; | ||||
|     } | ||||
| 
 | ||||
|     public String getFileName() { | ||||
|         return fileName; | ||||
|     } | ||||
| 
 | ||||
|     public void setFileName(String fileName) { | ||||
|         this.fileName = fileName; | ||||
|     } | ||||
| } | ||||
|  | @ -1,12 +1,16 @@ | |||
| package fr.free.nrw.commons.featured; | ||||
| 
 | ||||
| import android.graphics.Bitmap; | ||||
| import android.graphics.BitmapFactory; | ||||
| import android.os.Bundle; | ||||
| import android.support.v4.app.FragmentManager; | ||||
| import android.widget.GridView; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import butterknife.ButterKnife; | ||||
| import fr.free.nrw.commons.R; | ||||
| import fr.free.nrw.commons.auth.AuthenticatedActivity; | ||||
| import fr.free.nrw.commons.contributions.ContributionsListFragment; | ||||
| import fr.free.nrw.commons.media.MediaDetailPagerFragment; | ||||
| 
 | ||||
| /** | ||||
|  | @ -17,7 +21,7 @@ public class FeaturedImagesActivity | |||
|         extends AuthenticatedActivity | ||||
|         implements FragmentManager.OnBackStackChangedListener { | ||||
| 
 | ||||
|     private FeaturedImagesListFragment featuredImagesList; | ||||
|     private FeaturedImagesListFragment featuredImagesListFragment; | ||||
|     private MediaDetailPagerFragment mediaDetails; | ||||
| 
 | ||||
|     @Override | ||||
|  | @ -39,7 +43,7 @@ public class FeaturedImagesActivity | |||
|         // Activity can call methods in the fragment by acquiring a | ||||
|         // reference to the Fragment from FragmentManager, using findFragmentById() | ||||
|         FragmentManager supportFragmentManager = getSupportFragmentManager(); | ||||
|         featuredImagesList = (FeaturedImagesListFragment)supportFragmentManager | ||||
|         featuredImagesListFragment = (FeaturedImagesListFragment)supportFragmentManager | ||||
|                 .findFragmentById(R.id.featuedListFragment); | ||||
| 
 | ||||
|         supportFragmentManager.addOnBackStackChangedListener(this); | ||||
|  |  | |||
|  | @ -1,10 +1,16 @@ | |||
| package fr.free.nrw.commons.featured; | ||||
| 
 | ||||
| import android.graphics.Bitmap; | ||||
| import android.graphics.BitmapFactory; | ||||
| import android.os.Bundle; | ||||
| import android.support.annotation.Nullable; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.AdapterView; | ||||
| import android.widget.GridView; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import butterknife.ButterKnife; | ||||
| import dagger.android.support.DaggerFragment; | ||||
|  | @ -18,11 +24,32 @@ import static android.view.View.GONE; | |||
|  */ | ||||
| 
 | ||||
| public class FeaturedImagesListFragment extends DaggerFragment { | ||||
|     private GridView gridView; | ||||
|     private MockGridViewAdapter gridAdapter; | ||||
| 
 | ||||
|     @Override | ||||
|     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||||
|         View v = inflater.inflate(R.layout.fragment_contributions, container, false); | ||||
|         View v = inflater.inflate(R.layout.fragment_featured_images, container, false); | ||||
|         ButterKnife.bind(this, v); | ||||
|         return v; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||||
|         super.onViewCreated(view, savedInstanceState); | ||||
| 
 | ||||
|         gridView = (GridView) getView().findViewById(R.id.featuredImagesList); | ||||
|         gridAdapter = new MockGridViewAdapter(this.getContext(), R.layout.layout_featured_images, getMockFeaturedImages()); | ||||
|         gridView.setAdapter(gridAdapter); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private ArrayList<FeaturedImage> getMockFeaturedImages(){ | ||||
|         ArrayList<FeaturedImage> featuredImages = new ArrayList<>(); | ||||
|         for (int i=0; i<10; i++){ | ||||
|             Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.commons_logo_large); | ||||
|             featuredImages.add(new FeaturedImage(bitmap, "username: test", "test file name")); | ||||
|         } | ||||
|         return featuredImages; | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,50 @@ | |||
| package fr.free.nrw.commons.featured; | ||||
| 
 | ||||
| import android.app.Activity; | ||||
| import android.content.Context; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.ArrayAdapter; | ||||
| import android.widget.ImageView; | ||||
| import android.widget.TextView; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import fr.free.nrw.commons.R; | ||||
| 
 | ||||
| /** | ||||
|  * Created by root on 09.01.2018. | ||||
|  */ | ||||
| 
 | ||||
| public class MockGridViewAdapter extends ArrayAdapter { | ||||
|     private Context context; | ||||
|     private int layoutResourceId; | ||||
|     private ArrayList<FeaturedImage> data = new ArrayList(); | ||||
| 
 | ||||
|     public MockGridViewAdapter(Context context, int layoutResourceId, ArrayList<FeaturedImage> data) { | ||||
|         super(context, layoutResourceId, data); | ||||
|         this.layoutResourceId = layoutResourceId; | ||||
|         this.context = context; | ||||
|         this.data = data; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public View getView(int position, View convertView, ViewGroup parent) { | ||||
| 
 | ||||
|         if (convertView == null) { | ||||
|             LayoutInflater inflater = ((Activity) context).getLayoutInflater(); | ||||
|             convertView = inflater.inflate(R.layout.layout_featured_images, null); | ||||
|         } | ||||
| 
 | ||||
|         FeaturedImage item = data.get(position); | ||||
|         ImageView imageView = (ImageView) convertView.findViewById(R.id.featuredImageView); | ||||
|         TextView fileName = (TextView) convertView.findViewById(R.id.featuredImageTitle); | ||||
|         TextView author = (TextView) convertView.findViewById(R.id.featuredImageAuthor); | ||||
|         fileName.setText("Test file name"); | ||||
|         author.setText("Uploaded by: Test user name"); | ||||
|         imageView.setImageBitmap(item.getImage()); | ||||
|         return convertView; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 neslihanturan
						neslihanturan