Skip to content

Commit

Permalink
Differentiate draft posts and polls (#613)
Browse files Browse the repository at this point in the history
* Add color and text notes to differentiate draft posts/polls

* Change note to constant

* Do same for color.
  • Loading branch information
meiron03 authored Apr 21, 2024
1 parent 8ddc9b1 commit 51013a5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.net.Uri
Expand Down Expand Up @@ -44,6 +45,8 @@ import com.pennapps.labs.pennmobile.classes.NewsCell
import com.pennapps.labs.pennmobile.classes.PollCell
import com.pennapps.labs.pennmobile.classes.PostCell
import com.pennapps.labs.pennmobile.classes.GSRCell
import com.pennapps.labs.pennmobile.classes.Poll
import com.pennapps.labs.pennmobile.classes.Post
import com.pennapps.labs.pennmobile.components.sneaker.Utils.convertToDp
import com.pennapps.labs.pennmobile.utils.Utils
import eightbitlab.com.blurview.RenderScriptBlur
Expand Down Expand Up @@ -91,6 +94,9 @@ class HomeAdapter(private val dataModel: HomepageDataModel) :
private const val POST = 7
private const val FEATURE = 8
private const val POLL = 9

private const val DRAFT_NOTE = " (NOTE: THIS IS A DRAFT THAT USERS CANNOT SEE)"
private const val DRAFT_COLOR = "#ffb300"
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
Expand Down Expand Up @@ -348,8 +354,18 @@ class HomeAdapter(private val dataModel: HomepageDataModel) :

private fun bindPostCell(holder: ViewHolder, cell: PostCell) {
val post = cell.post

// if the post is a draft, then change the color and add a note
if (cell.post.status == Post.DRAFT) {
holder.itemView.home_post_title.setTextColor(Color.parseColor(DRAFT_COLOR))

val draftSubtitle = post.subtitle + DRAFT_NOTE
holder.itemView.home_post_subtitle.text = draftSubtitle
} else {
holder.itemView.home_post_subtitle.text = post.subtitle
}

holder.itemView.home_post_title.text = post.title
holder.itemView.home_post_subtitle.text = post.subtitle
holder.itemView.home_post_source.text = "Penn Labs" //post?.clubCode?.capitalize()
val time = post.startDate?.substring(5, 7) + " / " +
post.startDate?.substring(8, 10) + " - " +
Expand All @@ -371,7 +387,14 @@ class HomeAdapter(private val dataModel: HomepageDataModel) :
mActivity.runOnUiThread {
// Change all the components to match the accent color palette
vibrantSwatch?.titleTextColor?.let {
holder.itemView.home_post_title.setTextColor(ColorUtils.setAlphaComponent(it, 150))
if (cell.post.status != Post.DRAFT) {
holder.itemView.home_post_title.setTextColor(
ColorUtils.setAlphaComponent(
it,
150
)
)
}
holder.itemView.home_post_subtitle.setTextColor(it)
holder.itemView.home_post_timestamp.setTextColor(it)
holder.itemView.home_post_source.setTextColor(it)
Expand Down Expand Up @@ -423,7 +446,16 @@ class HomeAdapter(private val dataModel: HomepageDataModel) :

private fun bindPollCell(holder: ViewHolder, cell: PollCell, position: Int) {
val poll = cell.poll
holder.itemView.home_card_title?.text = poll.question

// if the post is a draft, then change the color and add a note
if (poll.status == Poll.DRAFT) {
holder.itemView.home_card_title.setTextColor(Color.parseColor(DRAFT_COLOR))
val draftQuestion = poll.question + DRAFT_NOTE
holder.itemView.home_card_title?.text = draftQuestion
} else {
holder.itemView.home_card_title?.text = poll.question
}

holder.itemView.home_card_subtitle_2?.text = "${poll.totalVotes} Votes"
if(poll.clubCode != null) {
holder.itemView.home_card_subtitle?.text = "POLL FROM ${poll.clubCode}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

class Poll {
companion object {
const val DRAFT = "DRAFT"
}

@SerializedName("id")
@Expose
Expand Down Expand Up @@ -41,6 +44,10 @@ class Poll {
@Expose
val options : List<PollOption> = ArrayList()

@SerializedName("status")
@Expose
internal val status : String? = null

@Expose
var totalVotes : Int = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import com.google.gson.annotations.SerializedName
* Data model for custom posts on homepage
*/
class Post {
companion object {
const val DRAFT = "DRAFT"
}

@SerializedName("id")
@Expose
Expand Down Expand Up @@ -45,7 +48,6 @@ class Post {
@Expose
internal val expireDate : String? = null


@SerializedName("club_comment")
@Expose
internal val club_comment : String? = null
Expand All @@ -67,7 +69,6 @@ class Post {
clubCode + ""
}
override fun equals(other: Any?) : Boolean {
Log.i("CellUpdates", "fuck")
// note: target_populations is not included because it's unused and structural
return when (other) {
is Post -> {
Expand Down

0 comments on commit 51013a5

Please sign in to comment.