Commit 7807c7fa authored by sshivam95's avatar sshivam95

Venter: Change the styling of ComplaintDetailsFragment as per the theme....

Venter: Change the styling of ComplaintDetailsFragment as per the theme. Migrate Up Vote button. Hide the Tab layout
parent 05af78d5
......@@ -45,16 +45,18 @@ public class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
private Context context;
private LayoutInflater inflater;
private String sessionId, userId;
private Activity activity;
Activity activity;
private TextView textViewCommentLabel;
private List<Venter.Comment> commentList = new ArrayList<>();
public CommentRecyclerViewAdapter(Activity activity, Context context, String sessionId, String userId) {
public CommentRecyclerViewAdapter(Activity activity, Context context, String sessionId, String userId, TextView textViewCommentLabel) {
this.context = context;
this.sessionId = sessionId;
this.userId = userId;
inflater = LayoutInflater.from(context);
this.activity = activity;
this.textViewCommentLabel = textViewCommentLabel;
}
public class CommentsViewHolder extends RecyclerView.ViewHolder {
......
......@@ -17,23 +17,25 @@ public class ComplaintDetailsPagerAdapter extends FragmentPagerAdapter {
Venter.Complaint detailedComplaint;
Context context;
String sessionid, complaintid, userid;
int voteCount;
public ComplaintDetailsPagerAdapter(FragmentManager fm, Venter.Complaint detailedComplaint, Context context, String sessionid, String complaintid, String userid) {
public ComplaintDetailsPagerAdapter(FragmentManager fm, Venter.Complaint detailedComplaint, Context context, String sessionid, String complaintid, String userid, int voteCount) {
super(fm);
this.context = context;
this.detailedComplaint = detailedComplaint;
this.sessionid = sessionid;
this.complaintid = complaintid;
this.userid = userid;
this.voteCount = voteCount;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return DetailedComplaintFragment.getInstance(sessionid, complaintid, userid);
return DetailedComplaintFragment.getInstance(sessionid, complaintid, userid, voteCount);
default:
return DetailedComplaintFragment.getInstance(sessionid, complaintid, userid);
return DetailedComplaintFragment.getInstance(sessionid, complaintid, userid, voteCount);
}
}
......
......@@ -36,14 +36,13 @@ import retrofit2.Response;
public class ComplaintDetailsFragment extends Fragment {
private static final String TAG = ComplaintDetailsFragment.class.getSimpleName();
Button buttonVoteUp;
TabLayout slidingTabLayout;
ViewPager viewPager;
View mview;
private String complaintId, sessionID, userId;
private ComplaintDetailsPagerAdapter complaintDetailsPagerAdapter;
private int voteCount;
CircleIndicator circleIndicator;
private int voteCount = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
......@@ -56,7 +55,6 @@ public class ComplaintDetailsFragment extends Fragment {
getResources().getDisplayMetrics().heightPixels / 2);
imageViewHolder.setLayoutParams(layoutParams);
buttonVoteUp = view.findViewById(R.id.buttonVoteUp);
slidingTabLayout = view.findViewById(R.id.sliding_tab_layout);
circleIndicator = view.findViewById(R.id.indicator);
this.mview = view;
......@@ -67,13 +65,6 @@ public class ComplaintDetailsFragment extends Fragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
buttonVoteUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
upVote();
}
});
Bundle bundle = getArguments();
complaintId = bundle.getString("id");
sessionID = bundle.getString("sessionId");
......@@ -85,30 +76,6 @@ public class ComplaintDetailsFragment extends Fragment {
}
}
private void upVote() {
if (voteCount == 0) {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.upVote("sessionid=" + sessionID, complaintId).enqueue(new Callback<Venter.Complaint>() {
@Override
public void onResponse(Call<Venter.Complaint> call, Response<Venter.Complaint> response) {
if (response.isSuccessful()) {
Venter.Complaint complaint = response.body();
initTabViews(complaint);
Toast.makeText(getActivity().getApplicationContext(), "You have Up Voted this complaint", Toast.LENGTH_SHORT).show();
voteCount++;
}
}
@Override
public void onFailure(Call<Venter.Complaint> call, Throwable t) {
Log.i(TAG, "failure in up vote: " + t.toString());
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(), "You have already UpVoted this complaint", Toast.LENGTH_SHORT).show();
}
}
private void callServerToGetDetailedComplaint() {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
......@@ -157,18 +124,13 @@ public class ComplaintDetailsFragment extends Fragment {
}
private void initTabViews(final Venter.Complaint detailedComplaint) {
try {
buttonVoteUp.setText("UpVote");
} catch (Exception e) {
e.printStackTrace();
}
try {
if (detailedComplaint != null) {
viewPager = mview.findViewById(R.id.tab_viewpager_details);
if (viewPager != null) {
Log.i(TAG, "viewPager != null");
complaintDetailsPagerAdapter = new ComplaintDetailsPagerAdapter(getChildFragmentManager(), detailedComplaint, getContext(), sessionID, complaintId, userId);
complaintDetailsPagerAdapter = new ComplaintDetailsPagerAdapter(getChildFragmentManager(), detailedComplaint, getContext(), sessionID, complaintId, userId, voteCount);
viewPager.setAdapter(complaintDetailsPagerAdapter);
slidingTabLayout.setupWithViewPager(viewPager);
......@@ -189,8 +151,9 @@ public class ComplaintDetailsFragment extends Fragment {
int mActionBarSize = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
// Replace second parameter to mActionBarSize after adding "Relevant Complaints"
AppBarLayout.LayoutParams layoutParams = new AppBarLayout.LayoutParams(AppBarLayout.LayoutParams.MATCH_PARENT,
mActionBarSize);
0);
slidingTabLayout.setLayoutParams(layoutParams);
slidingTabLayout.setTabMode(TabLayout.MODE_FIXED);
......@@ -223,17 +186,8 @@ public class ComplaintDetailsFragment extends Fragment {
"android:switcher:" + R.id.tab_viewpager_details + ":0"
);
Log.i(TAG, "detailedComplaintFragment: " + detailedComplaint);
/*For Relevant Complaint Fragment
* RelevantComplaintFragment relevantComplaintFragment = (RelevantComplaintFragment) getSupportFragmentManager().findFragmentByTag(
"android:switcher:" + R.id.tab_viewpager + ":1");
*/
if (detailedComplaintFragment != null) {
Log.i(TAG, "detailedComplinatFragment != null");
if (detailedComplaintFragment != null)
detailedComplaintFragment.setDetailedComplaint(detailedComplaint);
}
}
}
} catch (Exception e) {
......
......@@ -10,6 +10,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
......@@ -65,16 +66,19 @@ public class DetailedComplaintFragment extends Fragment {
private ImageButton imageButtonSend;
private CircleImageView circleImageViewCommentUserImage;
private RecyclerView recyclerViewComments;
private Button buttonVoteUp;
private static String sId, cId, uId;
private CommentRecyclerViewAdapter commentListAdapter;
private List<Venter.Comment> commentList;
private static int voteCount;
public static DetailedComplaintFragment getInstance(String sessionid, String complaintid, String userid) {
public static DetailedComplaintFragment getInstance(String sessionid, String complaintid, String userid, int vCount) {
sId = sessionid;
cId = complaintid;
uId = userid;
voteCount = vCount;
return new DetailedComplaintFragment();
}
......@@ -93,6 +97,7 @@ public class DetailedComplaintFragment extends Fragment {
imageButtonSend = view.findViewById(R.id.send_comment);
circleImageViewCommentUserImage = view.findViewById(R.id.comment_user_image);
Picasso.get().load(R.drawable.baseline_account_circle_black_36).into(circleImageViewCommentUserImage);
buttonVoteUp = view.findViewById(R.id.buttonVoteUp);
}
......@@ -105,7 +110,7 @@ public class DetailedComplaintFragment extends Fragment {
commentList = new ArrayList<>();
initialiseViews(view);
commentListAdapter = new CommentRecyclerViewAdapter(getActivity(), getContext(), sId, uId);
commentListAdapter = new CommentRecyclerViewAdapter(getActivity(), getContext(), sId, uId, textViewCommentLabel);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
recyclerViewComments.setLayoutManager(linearLayoutManager);
recyclerViewComments.setHasFixedSize(true);
......@@ -131,6 +136,14 @@ public class DetailedComplaintFragment extends Fragment {
}
}
});
buttonVoteUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
upVote();
}
});
return view;
}
......@@ -160,6 +173,7 @@ public class DetailedComplaintFragment extends Fragment {
commentListAdapter.setCommentList(commentList);
commentListAdapter.notifyItemInserted(commentList.indexOf(newComment));
commentListAdapter.notifyItemRangeChanged(0, commentListAdapter.getItemCount());
textViewCommentLabel.setText("Comments (" + commentList.size() + ")");
recyclerViewComments.post(new Runnable() {
@Override
public void run() {
......@@ -175,6 +189,7 @@ public class DetailedComplaintFragment extends Fragment {
private void populateViews() {
try {
buttonVoteUp.setText("UpVote");
textViewUserName.setText(detailedComplaint.getComplaintCreatedBy().getUserName());
String time = DateTimeUtil.getDate(detailedComplaint.getComplaintReportDate().toString());
Log.i(TAG, " time: " + time);
......@@ -192,8 +207,8 @@ public class DetailedComplaintFragment extends Fragment {
textViewStatus.setBackgroundTintList(ColorStateList.valueOf(getContext().getResources().getColor(R.color.colorGreen)));
textViewStatus.setTextColor(getContext().getResources().getColor(R.color.secondaryTextColor));
}
textViewCommentLabel.setText("COMMENTS");
textViewVoteUpLabel.setText("UP VOTES");
textViewCommentLabel.setText("Comments (" + detailedComplaint.getComment().size() + ")");
textViewVoteUpLabel.setText("Up Votes (" + detailedComplaint.getUsersUpVoted().size() + ")");
addVotesToView(detailedComplaint);
addCommentsToView(detailedComplaint);
} catch (Exception e) {
......@@ -232,6 +247,30 @@ public class DetailedComplaintFragment extends Fragment {
commentListAdapter.notifyDataSetChanged();
}
private void upVote() {
if (voteCount == 0) {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.upVote("sessionid=" + sId, cId).enqueue(new Callback<Venter.Complaint>() {
@Override
public void onResponse(Call<Venter.Complaint> call, Response<Venter.Complaint> response) {
if (response.isSuccessful()) {
Venter.Complaint complaint = response.body();
addVotesToView(complaint);
Toast.makeText(getActivity().getApplicationContext(), "You have Up Voted this complaint", Toast.LENGTH_SHORT).show();
voteCount++;
}
}
@Override
public void onFailure(Call<Venter.Complaint> call, Throwable t) {
Log.i(TAG, "failure in up vote: " + t.toString());
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(), "You have already UpVoted this complaint", Toast.LENGTH_SHORT).show();
}
}
public void addVotesToView(Venter.Complaint detailedComplaint) {
layoutVotes.removeAllViews();
for (User users : detailedComplaint.getUsersUpVoted()) {
......@@ -246,6 +285,7 @@ public class DetailedComplaintFragment extends Fragment {
textViewName.setText(users.getUserName());
layoutVotes.addView(voteView);
}
textViewVoteUpLabel.setText("Up Votes (" + detailedComplaint.getUsersUpVoted().size() + ")");
}
@Override
......
......@@ -239,6 +239,7 @@ public class FileComplaintFragment extends Fragment {
} else {
buttonSubmit.setVisibility(View.INVISIBLE);
buttonSubmit.setVisibility(View.GONE);
linearLayoutAnalyse.setPadding(0, 0, 0, 0);
}
}
});
......
......@@ -71,25 +71,6 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="2"
android:layout_gravity="bottom">
<Button
android:id="@+id/buttonVoteUp"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textColor="@color/secondaryTextColor"
android:background="@color/colorSecondary"
android:text="Upvote"
android:layout_weight="2"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
......@@ -10,8 +10,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp"
android:paddingBottom="60dp">
android:paddingTop="10dp">
<LinearLayout
android:layout_width="match_parent"
......@@ -42,11 +41,11 @@
android:id="@+id/textViewStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/customborder"
android:paddingHorizontal="10dp"
android:text="STATUS"
android:textSize="16sp"
android:textStyle="bold"
android:background="@drawable/customborder"/>
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
......@@ -95,16 +94,14 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TAGS"
android:text="Tags"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
android:textSize="16sp" />
</LinearLayout>
......@@ -143,17 +140,14 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:padding="10dp">
<TextView
android:id="@+id/comment_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="COMMENTS"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
android:textSize="16sp" />
</LinearLayout>
......@@ -174,26 +168,42 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
android:orientation="horizontal"
android:paddingHorizontal="10dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/comment_user_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:scaleType="centerCrop" />
<EditText
android:id="@+id/edit_comment"
android:layout_width="match_parent"
android:layout_height="match_parent"
<android.support.design.widget.TextInputLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:hint="@string/enter_comment" />
android:paddingHorizontal="10dp"
app:hintTextAppearance="@style/edit_text_hint_apperarance">
<EditText
android:id="@+id/edit_comment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:hint="Enter Comment"
android:inputType="textMultiLine"
android:textColor="@android:color/black"
android:textColorHint="#4a4a4a"
android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
<ImageButton
android:id="@+id/send_comment"
android:layout_width="wrap_content"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:srcCompat="@android:drawable/ic_menu_send" />
</LinearLayout>
......@@ -209,17 +219,14 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:padding="10dp">
<TextView
android:id="@+id/up_vote_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VoteUp"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
android:textSize="16sp" />
</LinearLayout>
......@@ -233,9 +240,25 @@
</LinearLayout>
<View
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp" />
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="2">
<Button
android:id="@+id/buttonVoteUp"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="2"
android:background="@color/colorSecondary"
android:text="Upvote"
android:textColor="@color/secondaryTextColor" />
</LinearLayout>
</LinearLayout>
......
......@@ -144,6 +144,7 @@
android:textColor="@android:color/black"
android:textColorHint="#4a4a4a"
android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
</FrameLayout>
......
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