Skip to content

Instantly share code, notes, and snippets.

@xsahil03x
Created July 15, 2018 11:05
Show Gist options
  • Save xsahil03x/23c354fda1916b7818243382d901729f to your computer and use it in GitHub Desktop.
Save xsahil03x/23c354fda1916b7818243382d901729f to your computer and use it in GitHub Desktop.
Review Recyclerview
<?xml version="1.0" encoding="utf-8"?>
<layout 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"
tools:context=".DetailActivity">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_reviews"
android:layout_width="0dp"
android:layout_height="0dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/review_item" />
</android.support.constraint.ConstraintLayout>
</layout>
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="review"
type="com.magarex.moviemania.Models.Review" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@color/colorAccent" />
<TextView
android:id="@+id/textView9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="@{review.author}"
android:textColor="@android:color/white"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent"
tools:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="2dp"
android:text="@{review.content}"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/textView9"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView9"
app:layout_constraintTop_toBottomOf="@+id/textView9"
tools:text="wasduadasadasdsadasdsadsadasdsadsadasdsadsadassdjkasdnaksjdnsakjdnaskjdnsadkjasndkjasdnkasjdnaskjddasyuhdbasjkdbaskjdbaskjdbaskjdbkasjdbaskjdsjdnaskjdnaskjdasnkjdnsakjdnsakjdnskjdnaskjdnaskjdnaskjdnaskjdnaskjdnaskjdnasjdnasj" />
</android.support.constraint.ConstraintLayout>
</layout>
public class ReviewFragment extends Fragment {
private ReviewAdapter mAdapter;
private static final String MOVIE_ID_KEY = "movie_id";
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
TabBottomSheetReviewBinding mBinding = DataBindingUtil.inflate(inflater, R.layout.tab_bottom_sheet_review, container, false);
mAdapter = new ReviewAdapter(getActivity());
RecyclerView rvReviews = mBinding.rvReviews;
rvReviews.setAdapter(mAdapter);
rvReviews.setLayoutManager(new LinearLayoutManager(getActivity()));
rvReviews.setItemAnimator(new DefaultItemAnimator());
ProjectUtils.getClient()
.create(MovieApi.class)
.getReviews("333339", ProjectUtils.API_KEY)
.enqueue(new Callback<ReviewResponse>() {
@Override
public void onResponse(Call<ReviewResponse> call, Response<ReviewResponse> response) {
Log.d(TAG, "onResponse: " + response.message());
mAdapter.addReviewToList(response.body().getResults());
}
@Override
public void onFailure(Call<ReviewResponse> call, Throwable t) {
Log.d(TAG, "onFailure: " + t.getMessage());
}
});
return mBinding.getRoot();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment