Skip to content

Commit 77a92e9

Browse files
committed
Replace usages of deprecated getColor() API in ImagesFragment
1 parent 7d9f238 commit 77a92e9

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

app/src/main/java/ai/elimu/content_provider/ui/image/ImagesFragment.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import android.util.Log
1515
import android.view.LayoutInflater
1616
import android.view.View
1717
import android.view.ViewGroup
18+
import androidx.core.content.ContextCompat
1819
import androidx.fragment.app.Fragment
1920
import androidx.lifecycle.ViewModelProvider
2021
import com.google.android.material.snackbar.Snackbar
@@ -78,10 +79,13 @@ class ImagesFragment : Fragment() {
7879
processResponseBody(imageGsons)
7980
}
8081
} else {
81-
// Handle error
82-
Snackbar.make(binding.textImages, response.toString(), Snackbar.LENGTH_LONG)
83-
.setBackgroundTint(resources.getColor(R.color.deep_orange_darken_4))
84-
.show()
82+
context?.let { context ->
83+
// Handle error
84+
Snackbar.make(binding.textImages, response.toString(), Snackbar.LENGTH_LONG)
85+
.setBackgroundTint(ContextCompat.getColor(context, R.color.deep_orange_darken_4))
86+
.show()
87+
}
88+
8589
binding.progressBarImages.visibility = View.GONE
8690
}
8791
}
@@ -91,10 +95,13 @@ class ImagesFragment : Fragment() {
9195

9296
Log.e(TAG, "t.getCause():", t.cause)
9397

94-
// Handle error
95-
Snackbar.make(binding.textImages, t.cause.toString(), Snackbar.LENGTH_LONG)
96-
.setBackgroundTint(resources.getColor(R.color.deep_orange_darken_4))
97-
.show()
98+
context?.let { context ->
99+
// Handle error
100+
Snackbar.make(binding.textImages, t.cause.toString(), Snackbar.LENGTH_LONG)
101+
.setBackgroundTint(ContextCompat.getColor(context, R.color.deep_orange_darken_4))
102+
.show()
103+
}
104+
98105
binding.progressBarImages.visibility = View.GONE
99106
}
100107
})

0 commit comments

Comments
 (0)