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

fix: deprecated context calls #524

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all 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,6 +5,7 @@ import android.graphics.drawable.VectorDrawable
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import org.fossasia.badgemagic.R
import org.fossasia.badgemagic.data.DrawableInfo
Expand All @@ -23,7 +24,7 @@ class DrawableItemHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
else if (drawableInfo.image is BitmapDrawable)
image.setImageBitmap(ImageUtils.trim(drawableInfo.image.bitmap, 80))

image.setColorFilter(itemView.context.resources.getColor(android.R.color.black))
image.setColorFilter(ContextCompat.getColor(itemView.context, android.R.color.black))

card.setOnClickListener {
listener?.onSelected(drawableInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import org.fossasia.badgemagic.R
import org.fossasia.badgemagic.data.ModeInfo
Expand All @@ -25,14 +26,14 @@ class ModeItemHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

when (itemPosition == modeSelectedPosition) {
true -> {
card.background = itemView.context.resources.getDrawable(R.color.colorAccent)
title.setTextColor(itemView.context.resources.getColor(android.R.color.white))
image.setColorFilter(itemView.context.resources.getColor(android.R.color.white))
card.background = ContextCompat.getDrawable(itemView.context, R.color.colorAccent)
title.setTextColor(ContextCompat.getColor(itemView.context, android.R.color.white))
image.setColorFilter(ContextCompat.getColor(itemView.context, android.R.color.white))
}
false -> {
card.background = itemView.context.resources.getDrawable(android.R.color.transparent)
title.setTextColor(itemView.context.resources.getColor(android.R.color.black))
image.setColorFilter(itemView.context.resources.getColor(android.R.color.black))
card.background = ContextCompat.getDrawable(itemView.context, android.R.color.transparent)
title.setTextColor(ContextCompat.getColor(itemView.context, android.R.color.black))
image.setColorFilter(ContextCompat.getColor(itemView.context, android.R.color.black))
}
}

Expand Down
37 changes: 19 additions & 18 deletions app/src/main/java/org/fossasia/badgemagic/adapter/SaveAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.Chip
import org.fossasia.badgemagic.R
Expand Down Expand Up @@ -71,32 +72,32 @@ class SaveAdapter(private val context: Context?, private val list: List<ConfigIn
text.text = item.fileName.substring(0, item.fileName.lastIndexOf("."))

card.background = when {
selectedPosition != -1 && selectedPosition == adapterPosition -> context?.resources?.getDrawable(R.color.colorAccent)
else -> context?.resources?.getDrawable(android.R.color.transparent)
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getDrawable(itemView.context, R.color.colorAccent)
else -> ContextCompat.getDrawable(itemView.context, android.R.color.transparent)
}
text.setTextColor(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> context?.resources?.getColor(android.R.color.white) as Int
else -> context?.resources?.getColor(android.R.color.black) as Int
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)
playPause.setColorFilter(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> context.resources.getColor(android.R.color.white)
else -> context.resources.getColor(android.R.color.black)
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)
editButton.setColorFilter(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> context.resources.getColor(android.R.color.white)
else -> context.resources.getColor(android.R.color.black)
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)
options.setColorFilter(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> context.resources.getColor(android.R.color.white)
else -> context.resources.getColor(android.R.color.black)
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)

val badge: BadgeConfig? = MoshiUtils.getAdapter().fromJson(item.badgeJSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SavedClipartsViewHolder(private val binding: RecyclerItemSavedClipartBindi
binding.bitmap = bitmap
}

fun getBindingView() = binding.root
private fun getBindingView() = binding.root
fun getDeleteButton(): AppCompatImageView = getBindingView().findViewById(R.id.button_delete)
fun getEditButton(): AppCompatImageView = getBindingView().findViewById(R.id.button_edit)
}