Commit 07985ffc authored by Varun Patil's avatar Varun Patil

fix(venter): Get rid of Upvotes Adapter

parent 05fa6282
package app.insti.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List;
import app.insti.R;
import app.insti.Utils;
import app.insti.api.model.User;
import de.hdodenhof.circleimageview.CircleImageView;
public class UpVotesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final String TAG = CommentsAdapter.class.getSimpleName();
private LayoutInflater inflater;
private Fragment fragment;
private List<User> userList = new ArrayList<>();
public UpVotesAdapter(Fragment fragment, Context context) {
inflater = LayoutInflater.from(context);
this.fragment = fragment;
}
public class UpVotesViewHolder extends RecyclerView.ViewHolder {
private CardView cardView;
private CircleImageView circleImageView;
private TextView textViewName;
UpVotesViewHolder(View itemView) {
super(itemView);
cardView = itemView.findViewById(R.id.cardViewUpVote);
textViewName = itemView.findViewById(R.id.textViewUserUpVoteName);
circleImageView = itemView.findViewById(R.id.circleImageViewUserUpVoteImage);
cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Utils.openUserFragment(userList.get(getAdapterPosition()), fragment.getActivity());
}
});
}
private void bindHolder(final int position) {
final User user = userList.get(position);
try {
String profileUrl = user.getUserProfilePictureUrl();
Log.i(TAG, "PROFILE URL: " + profileUrl);
Picasso.get().load(profileUrl).placeholder(R.drawable.user_placeholder).into(circleImageView);
textViewName.setText(user.getUserName());
} catch (Exception e) {
e.printStackTrace();
}
}
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = inflater.inflate(R.layout.vote_up_card, viewGroup, false);
return new UpVotesViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
if (viewHolder instanceof UpVotesViewHolder) {
((UpVotesViewHolder) viewHolder).bindHolder(i);
}
}
@Override
public int getItemCount() {
return userList.size();
}
public void setUpVoteList(List<User> userList) {
this.userList = userList;
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@ import android.content.res.ColorStateList;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
......@@ -17,7 +16,6 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
......@@ -40,7 +38,7 @@ import app.insti.Utils;
import app.insti.activity.MainActivity;
import app.insti.adapter.CommentsAdapter;
import app.insti.adapter.ImageViewPagerAdapter;
import app.insti.adapter.UpVotesAdapter;
import app.insti.adapter.UserAdapter;
import app.insti.api.RetrofitInterface;
import app.insti.api.model.User;
import app.insti.api.model.Venter;
......@@ -82,12 +80,10 @@ public class ComplaintDetailsFragment extends Fragment {
private static String cId, uId, uProfileUrl;
private CommentsAdapter commentListAdapter;
private UpVotesAdapter upVotesAdapter;
private UserAdapter upVotesAdapter;
private List<Venter.Comment> commentList;
private List<User> upVotesList;
private List<User> upVotesList = new ArrayList<>();
private LinearLayout linearLayoutTags;
private ScrollView layoutUpVotes;
private NestedScrollView nestedScrollView;
private CircleIndicator circleIndicator;
public static ComplaintDetailsFragment getInstance(String complaintid, String userid, String userProfileUrl) {
......@@ -105,18 +101,15 @@ public class ComplaintDetailsFragment extends Fragment {
commentList = new ArrayList<>();
initialiseViews(view);
upVotesList = new ArrayList<>();
commentListAdapter = new CommentsAdapter(getActivity(), uId, this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
upVotesAdapter = new UpVotesAdapter(this, getContext());
upVotesAdapter = new UserAdapter(upVotesList, this);
recyclerViewComments.setLayoutManager(linearLayoutManager);
recyclerViewUpVotes.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerViewComments.setHasFixedSize(true);
recyclerViewUpVotes.setHasFixedSize(true);
recyclerViewComments.setAdapter(commentListAdapter);
recyclerViewUpVotes.setAdapter(upVotesAdapter);
upVotesAdapter.setUpVoteList(upVotesList);
upVotesAdapter.notifyDataSetChanged();
mMapView = view.findViewById(R.id.google_map);
mMapView.onCreate(savedInstanceState);
......@@ -166,7 +159,6 @@ public class ComplaintDetailsFragment extends Fragment {
}
private void initialiseViews(View view) {
nestedScrollView = view.findViewById(R.id.nestedScrollViewComplaintDetail);
circleImageViewCreatorImage = view.findViewById(R.id.circleImageViewCreatorImage);
linearLayoutSuggestions = view.findViewById(R.id.linearLayoutSuggestions);
linearLayoutLocationDetails = view.findViewById(R.id.linearLayoutLocationDetails);
......@@ -319,7 +311,6 @@ public class ComplaintDetailsFragment extends Fragment {
Venter.Complaint complaint = response.body();
detailedComplaint.setVoteCount(1);
addVotesToView(complaint);
onUpvote();
}
}
......@@ -412,20 +403,11 @@ public class ComplaintDetailsFragment extends Fragment {
for (User users : detailedComplaint.getUsersUpVoted()) {
upVotesList.add(users);
}
upVotesAdapter.setUpVoteList(upVotesList);
upVotesAdapter.setList(upVotesList);
upVotesAdapter.notifyDataSetChanged();
textViewVoteUpLabel.setText("Up Votes (" + detailedComplaint.getUsersUpVoted().size() + ")");
}
private void onUpvote(){
layoutUpVotes.post(new Runnable() {
@Override
public void run() {
nestedScrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
private void addTagsToView(Venter.Complaint detailedComplaint) {
for (Venter.TagUri tagUri : detailedComplaint.getTags()) {
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardViewUpVote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_margin="5dp"
android:padding="10dp"
app:cardUseCompatPadding="true"
app:cardBackgroundColor="@color/colorWhite"
app:cardCornerRadius="0dp">>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="4dp"
android:paddingLeft="18dp"
android:paddingRight="10dp"
android:paddingTop="4dp">
<LinearLayout
android:id="@+id/layoutUpVote"
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/circleImageViewUserUpVoteImage"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="3"
android:orientation="vertical">
<TextView
android:id="@+id/textViewUserUpVoteName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User Name"
android:textColor="@android:color/black"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment