Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading Data from the Firebase Database
- Loading branch information
1 parent
660a4df
commit c69233e
Showing
6 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/main/java/com/dragosholban/myinstagramapp/ImageAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,68 @@ | |||
package com.dragosholban.myinstagramapp; | |||
|
|||
import android.support.v7.widget.RecyclerView; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.Button; | |||
import android.widget.ImageView; | |||
import android.widget.TextView; | |||
|
|||
import com.squareup.picasso.Picasso; | |||
|
|||
import java.util.ArrayList; | |||
|
|||
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> { | |||
private ArrayList<Image> mDataset; | |||
private FeedActivity mActivity; | |||
|
|||
public static class ViewHolder extends RecyclerView.ViewHolder { | |||
public TextView mTextView; | |||
public ImageView mImageView; | |||
public Button mLikeButton; | |||
|
|||
public ViewHolder(View v) { | |||
super(v); | |||
mTextView = v.findViewById(R.id.textView2); | |||
mImageView = v.findViewById(R.id.imageView); | |||
mLikeButton = v.findViewById(R.id.likeButton); | |||
} | |||
} | |||
|
|||
public ImageAdapter(ArrayList<Image> myDataset, FeedActivity activity) { | |||
mDataset = myDataset; | |||
mActivity = activity; | |||
} | |||
|
|||
// Create new views (invoked by the layout manager) | |||
@Override | |||
public ImageAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |||
// create a new view | |||
View v = LayoutInflater.from(parent.getContext()) | |||
.inflate(R.layout.image_view, parent, false); | |||
|
|||
ViewHolder vh = new ViewHolder(v); | |||
return vh; | |||
} | |||
|
|||
// Replace the contents of a view (invoked by the layout manager) | |||
@Override | |||
public void onBindViewHolder(ViewHolder holder, final int position) { | |||
final Image image = (Image) mDataset.get(position); | |||
if (image.user != null) { | |||
holder.mTextView.setText(image.user.displayName); | |||
} | |||
Picasso.get().load(image.downloadUrl).into(holder.mImageView); | |||
} | |||
|
|||
// Return the size of your dataset (invoked by the layout manager) | |||
@Override | |||
public int getItemCount() { | |||
return mDataset.size(); | |||
} | |||
|
|||
public void addImage(Image image) { | |||
mDataset.add(0, image); | |||
notifyDataSetChanged(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,52 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<android.support.constraint.ConstraintLayout | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:app="http://schemas.android.com/apk/res-auto" | |||
xmlns:tools="http://schemas.android.com/tools" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content"> | |||
|
|||
<ImageView | |||
android:id="@+id/imageView" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginBottom="8dp" | |||
android:layout_marginEnd="8dp" | |||
android:layout_marginLeft="8dp" | |||
android:layout_marginRight="8dp" | |||
android:layout_marginStart="8dp" | |||
android:layout_marginTop="8dp" | |||
app:layout_constraintBottom_toTopOf="@+id/textView2" | |||
app:layout_constraintEnd_toEndOf="parent" | |||
app:layout_constraintStart_toStartOf="parent" | |||
app:layout_constraintTop_toTopOf="parent" | |||
android:adjustViewBounds="true" /> | |||
|
|||
<TextView | |||
android:id="@+id/textView2" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_marginBottom="8dp" | |||
android:layout_marginEnd="8dp" | |||
android:layout_marginLeft="8dp" | |||
android:layout_marginRight="8dp" | |||
android:layout_marginStart="8dp" | |||
app:layout_constraintBottom_toBottomOf="parent" | |||
app:layout_constraintEnd_toStartOf="@id/likeButton" | |||
app:layout_constraintStart_toStartOf="parent" /> | |||
|
|||
<Button | |||
android:id="@+id/likeButton" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginBottom="8dp" | |||
android:layout_marginEnd="8dp" | |||
android:layout_marginLeft="8dp" | |||
android:layout_marginRight="8dp" | |||
android:layout_marginStart="8dp" | |||
android:text="Like" | |||
app:layout_constraintBottom_toBottomOf="parent" | |||
app:layout_constraintEnd_toEndOf="parent" | |||
app:layout_constraintStart_toEndOf="@id/textView2" /> | |||
|
|||
</android.support.constraint.ConstraintLayout> |