Added PSA feature that allows for delivering a message or a link to users

This commit is contained in:
Deniz Düzgören
2019-08-06 17:08:43 +02:00
parent f9cac0b123
commit 52db4b20bb
3 changed files with 79 additions and 48 deletions
@@ -1,11 +1,15 @@
package com.denizd.substitutionplan
import android.content.ActivityNotFoundException
import android.net.Uri
import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.card.MaterialCardView
@@ -34,15 +38,35 @@ class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapter<CardAd
override fun onBindViewHolder(holder: CardViewHolder, position: Int) {
val currentItem = mSubst[position]
val prefs = PreferenceManager.getDefaultSharedPreferences(holder.mImageView.context)
var psa = false
holder.mImageView.setImageResource(currentItem.icon)
holder.mGroup.text = currentItem.group
holder.mDate.text = currentItem.date
holder.mTime.text = currentItem.time
holder.mCourse.text = currentItem.course
holder.mRoom.text = currentItem.room
holder.mAdditional.text = currentItem.additional
if (currentItem.date.isNotEmpty() && currentItem.date.substring(0, 3) == "psa") {
psa = true
holder.mDate.text = ""
holder.mImageView.setImageResource(R.drawable.ic_idea)
holder.mCard.setCardBackgroundColor(ContextCompat.getColor(holder.mImageView.context, R.color.colorAccent))
if (currentItem.date.substring(3, 7) == "http") {
holder.mCard.setOnClickListener {
try {
CustomTabsIntent.Builder().build().launchUrl(holder.mCard.context,
Uri.parse(currentItem.date.substring(3)))
} catch (e: ActivityNotFoundException) {
Toast.makeText(holder.mCard.context, holder.mCard.context.getString(R.string.chromeCompatibleNotFound), Toast.LENGTH_LONG).show()
}
}
}
} else {
holder.mDate.text = currentItem.date
}
if (!psa) {
try {
colorCheck = holder.mCourse.text.toString().toLowerCase().substring(0, 3)
colour = when (colorCheck) {
@@ -85,18 +109,22 @@ class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapter<CardAd
colour = 0
}
}
if (colour != 0) {
holder.mCard.setCardBackgroundColor(ContextCompat.getColor(holder.mCourse.context, colour))
} else {
holder.mCard.setCardBackgroundColor(ContextCompat.getColor(holder.mCourse.context, R.color.colorBackgroundLight))
}
}
val textColor = when (colour) {
val textColor = if (psa) {
R.color.colorBackground
} else {
when (colour) {
R.color.bgPureWhite -> R.color.colorTextDark
R.color.bgPureBlack -> R.color.colorTextLight
else -> R.color.colorText
}
}
holder.mImageView.setColorFilter(ContextCompat.getColor(holder.mImageView.context, textColor))
holder.mGroup.setTextColor(ContextCompat.getColor(holder.mImageView.context, textColor))
holder.mDate.setTextColor(ContextCompat.getColor(holder.mImageView.context, textColor))
@@ -21,7 +21,9 @@ class PersonalPlanFragment : PlanFragment() {
persPlanEmpty = true
recyclerView.visibility = View.VISIBLE
for (i in 0 until it.size) {
if ((prefs.getString("courses", "") ?: "").isEmpty() && (prefs.getString("classes", "") ?: "").isNotEmpty()) {
if (it[i].date.isNotEmpty() && it[i].date.substring(0, 3) == "psa") {
planCardList.add(it[i])
} else if ((prefs.getString("courses", "") ?: "").isEmpty() && (prefs.getString("classes", "") ?: "").isNotEmpty()) {
if (it[i].group.isNotEmpty() && it[i].group != "") {
if ((prefs.getString("classes", "") ?: "").contains(it[i].group) || it[i].group.contains((prefs.getString("classes", "") ?: "").toString())) {
planCardList.add(it[i])
@@ -45,7 +47,7 @@ class PersonalPlanFragment : PlanFragment() {
handler.postDelayed({
if (persPlanEmpty) {
recyclerView.visibility = View.GONE
// recyclerView.visibility = View.GONE
smileydown.visibility = View.VISIBLE
smileydowntext.visibility = View.VISIBLE
linearsmiley.visibility = View.VISIBLE
+2 -1
View File
@@ -37,7 +37,8 @@
app:layout_anchor="@+id/smileydown"
android:layout_gravity="bottom|center_horizontal"
android:textColor="@color/colorHint"
android:visibility="gone"/>
android:visibility="gone"
android:layout_marginBottom="16dp"/>
</LinearLayout>