Add grid view and list adapter

This commit is contained in:
neslihanturan 2018-01-10 01:04:27 +03:00
parent 48c7a0372e
commit b0cd6a9a47
5 changed files with 194 additions and 4 deletions

View file

@ -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;
}
}

View file

@ -1,12 +1,16 @@
package fr.free.nrw.commons.featured; package fr.free.nrw.commons.featured;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.widget.GridView;
import java.util.ArrayList;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.AuthenticatedActivity; import fr.free.nrw.commons.auth.AuthenticatedActivity;
import fr.free.nrw.commons.contributions.ContributionsListFragment;
import fr.free.nrw.commons.media.MediaDetailPagerFragment; import fr.free.nrw.commons.media.MediaDetailPagerFragment;
/** /**
@ -17,7 +21,7 @@ public class FeaturedImagesActivity
extends AuthenticatedActivity extends AuthenticatedActivity
implements FragmentManager.OnBackStackChangedListener { implements FragmentManager.OnBackStackChangedListener {
private FeaturedImagesListFragment featuredImagesList; private FeaturedImagesListFragment featuredImagesListFragment;
private MediaDetailPagerFragment mediaDetails; private MediaDetailPagerFragment mediaDetails;
@Override @Override
@ -39,7 +43,7 @@ public class FeaturedImagesActivity
// Activity can call methods in the fragment by acquiring a // Activity can call methods in the fragment by acquiring a
// reference to the Fragment from FragmentManager, using findFragmentById() // reference to the Fragment from FragmentManager, using findFragmentById()
FragmentManager supportFragmentManager = getSupportFragmentManager(); FragmentManager supportFragmentManager = getSupportFragmentManager();
featuredImagesList = (FeaturedImagesListFragment)supportFragmentManager featuredImagesListFragment = (FeaturedImagesListFragment)supportFragmentManager
.findFragmentById(R.id.featuedListFragment); .findFragmentById(R.id.featuedListFragment);
supportFragmentManager.addOnBackStackChangedListener(this); supportFragmentManager.addOnBackStackChangedListener(this);

View file

@ -1,10 +1,16 @@
package fr.free.nrw.commons.featured; package fr.free.nrw.commons.featured;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.GridView;
import java.util.ArrayList;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import dagger.android.support.DaggerFragment; import dagger.android.support.DaggerFragment;
@ -18,11 +24,32 @@ import static android.view.View.GONE;
*/ */
public class FeaturedImagesListFragment extends DaggerFragment { public class FeaturedImagesListFragment extends DaggerFragment {
private GridView gridView;
private MockGridViewAdapter gridAdapter;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 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); ButterKnife.bind(this, v);
return 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;
}
} }

View file

@ -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;
}
}

View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:paddingBottom="0dp"
>
<TextView
android:id="@+id/featuredImagesSequenceNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="98sp"
android:textColor="#33FFFFFF"
android:typeface="serif"
android:layout_gravity="end|bottom"
/>
<ImageView
android:id="@+id/featuredImageView"
android:layout_width="match_parent"
android:layout_height="240dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:background="#AA000000"
android:orientation="vertical"
android:padding="@dimen/small_gap"
>
<ProgressBar
android:id="@+id/featuredProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/ProgressBar"
android:indeterminateOnly="false"
android:max="100"
android:visibility="gone"
/>
<TextView
android:id="@+id/featuredImageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFFFF"
style="?android:textAppearanceLarge"
android:maxLines="1"
android:ellipsize="end"
/>
<TextView
android:id="@+id/featuredImageAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFFFF"
style="?android:textAppearanceMedium"
android:maxLines="1"
android:ellipsize="end"
/>
</LinearLayout>
</FrameLayout>