Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Order feedback by date #2261

Merged
merged 16 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_feedback.rvAllFeedback
import kotlinx.android.synthetic.main.activity_feedback.*

import org.fossasia.susi.ai.R
import org.fossasia.susi.ai.rest.responses.susi.Feedback
import org.fossasia.susi.ai.rest.responses.susi.GetSkillFeedbackResponse
import org.fossasia.susi.ai.skills.feedback.adapters.recycleradapters.AllReviewsAdapter
/**
Expand All @@ -21,13 +21,14 @@ class FeedbackActivity : AppCompatActivity() {
val actionBar = supportActionBar
actionBar?.setDisplayHomeAsUpEnabled(true)
val feedbackResponse: GetSkillFeedbackResponse? = intent.extras.get("feedbackResponse") as GetSkillFeedbackResponse
val arrangedFeedbackList: ArrayList<Feedback> = intent.extras.get("arrangedFeedbackList") as ArrayList<Feedback>
if (feedbackResponse != null) {
title = feedbackResponse.skillName.capitalize() + " " + getString(R.string.reviews)
if (!feedbackResponse.feedbackList.isNullOrEmpty()) {
if (!arrangedFeedbackList.isEmpty()) {
val layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
rvAllFeedback.setHasFixedSize(true)
rvAllFeedback.layoutManager = layoutManager
rvAllFeedback.adapter = AllReviewsAdapter(this, feedbackResponse.feedbackList)
rvAllFeedback.adapter = AllReviewsAdapter(this, arrangedFeedbackList)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import org.fossasia.susi.ai.R
import org.fossasia.susi.ai.helper.Constant
import org.fossasia.susi.ai.helper.PrefManager
import org.fossasia.susi.ai.helper.Utils
import org.fossasia.susi.ai.rest.responses.susi.Feedback
import org.fossasia.susi.ai.rest.responses.susi.GetSkillFeedbackResponse
import org.fossasia.susi.ai.skills.feedback.FeedbackActivity
import org.fossasia.susi.ai.skills.skilldetails.adapters.viewholders.FeedbackViewHolder
import timber.log.Timber

/**
*
Expand All @@ -26,6 +30,7 @@ class FeedbackAdapter(
RecyclerView.Adapter<FeedbackViewHolder>(), FeedbackViewHolder.ClickListener {

private val clickListener: FeedbackViewHolder.ClickListener = this
private val arrangedFeedbackList: ArrayList<Feedback> = ArrayList()

@NonNull
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedbackViewHolder {
Expand All @@ -35,6 +40,7 @@ class FeedbackAdapter(
}

override fun getItemCount(): Int {
arrangeFeedbacks()
if (feedbackResponse.feedbackList.isNotEmpty()) {
if (feedbackResponse.feedbackList.size > 4) {
return 4
Expand All @@ -44,28 +50,45 @@ class FeedbackAdapter(
return 0
}

private fun arrangeFeedbacks() {
arrangedFeedbackList.clear()
feedbackResponse.feedbackList.forEach { item ->
if (item.email == PrefManager.getStringSet(Constant.SAVED_EMAIL)?.iterator()?.next()) {
arrangedFeedbackList.add(item)
}
}

var reverseResponse = feedbackResponse.feedbackList.asReversed()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you reassigning this? I told you last time to check before submitting PRs for review

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

reverseResponse.forEach { item ->
if (item.email != PrefManager.getStringSet(Constant.SAVED_EMAIL)?.iterator()?.next()) {
arrangedFeedbackList.add(item)
}
}
Timber.d("Arranged the feedback")
}

@NonNull
override fun onBindViewHolder(holder: FeedbackViewHolder, position: Int) {
if (feedbackResponse.feedbackList.isNotEmpty()) {
if (feedbackResponse.feedbackList[position] != null) {
if (arrangedFeedbackList.isNotEmpty()) {
if (arrangedFeedbackList[position] != null) {
if (position < 3) {
if (feedbackResponse.feedbackList[position].email != null &&
!TextUtils.isEmpty(feedbackResponse.feedbackList[position].email)) {
Utils.setAvatar(context, feedbackResponse.feedbackList.get(position).avatar, holder.avatar)
Utils.setUsername(feedbackResponse.feedbackList.get(position), holder.feedbackEmail)
if (arrangedFeedbackList[position].email != null &&
!TextUtils.isEmpty(arrangedFeedbackList[position].email)) {
Utils.setAvatar(context, arrangedFeedbackList.get(position).avatar, holder.avatar)
Utils.setUsername(arrangedFeedbackList.get(position), holder.feedbackEmail)
}
if (feedbackResponse.feedbackList[position].timestamp != null &&
!TextUtils.isEmpty(feedbackResponse.feedbackList[position].timestamp)) {
val date: String? = getDate(feedbackResponse.feedbackList[position].timestamp)
if (arrangedFeedbackList[position].timestamp != null &&
!TextUtils.isEmpty(arrangedFeedbackList[position].timestamp)) {
val date: String? = getDate(arrangedFeedbackList[position].timestamp)
if (date != null) {
holder.feedbackDate.text = date
} else {
holder.feedbackDate.text = ""
}
}
if (feedbackResponse.feedbackList[position].feedback != null &&
!TextUtils.isEmpty(feedbackResponse.feedbackList[position].feedback)) {
holder.feedback.text = feedbackResponse.feedbackList[position].feedback
if (arrangedFeedbackList[position].feedback != null &&
!TextUtils.isEmpty(arrangedFeedbackList[position].feedback)) {
holder.feedback.text = arrangedFeedbackList[position].feedback
}
}
}
Expand All @@ -92,6 +115,7 @@ class FeedbackAdapter(
if (context is Activity) context.overridePendingTransition(R.anim.trans_right_in, R.anim.trans_right_out)
val intent = Intent(context, FeedbackActivity::class.java)
intent.putExtra("feedbackResponse", feedbackResponse)
intent.putExtra("arrangedFeedbackList", arrangedFeedbackList)
context.startActivity(intent)
}
}