Unverified Commit 24b0860b authored by Vitalii Koshura's avatar Vitalii Koshura Committed by GitHub

Merge pull request #4004 from Isira-Seneviratne/Use_ContextCompat_getColor

[Android] Use ContextCompat.getColor().
parents 8e460cb4 2934ee8b
......@@ -46,10 +46,7 @@ import edu.berkeley.boinc.client.IMonitor
import edu.berkeley.boinc.client.Monitor
import edu.berkeley.boinc.databinding.MainBinding
import edu.berkeley.boinc.ui.eventlog.EventLogActivity
import edu.berkeley.boinc.utils.Logging
import edu.berkeley.boinc.utils.RUN_MODE_AUTO
import edu.berkeley.boinc.utils.RUN_MODE_NEVER
import edu.berkeley.boinc.utils.writeClientModeAsync
import edu.berkeley.boinc.utils.*
import kotlinx.coroutines.launch
class BOINCActivity : AppCompatActivity() {
......@@ -131,6 +128,7 @@ class BOINCActivity : AppCompatActivity() {
invalidateOptionsMenu()
}
}
mDrawerToggle.drawerArrowDrawable.color = getColorCompat(R.color.white)
binding.drawerLayout.addDrawerListener(mDrawerToggle)
// pre-select fragment
......
......@@ -25,7 +25,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.RecyclerView
import edu.berkeley.boinc.BOINCActivity
import edu.berkeley.boinc.R
......@@ -153,21 +152,19 @@ class TaskRecyclerViewAdapter(
holder.abortButton.tag = RpcClient.RESULT_ABORT // tag on button specified operation triggered in iconClickListener
holder.abortButton.visibility = View.VISIBLE
holder.requestProgressBar.visibility = View.GONE
val theme = fragment.requireActivity().theme
val context = fragment.requireContext()
// checking what suspendResume button should be shown
when {
item.result.isSuspendedViaGUI -> { // show play
holder.suspendResumeButton.visibility = View.VISIBLE
holder.suspendResumeButton.setBackgroundColor(ResourcesCompat.getColor(fragment.resources,
R.color.dark_green, theme))
holder.suspendResumeButton.setBackgroundColor(context.getColorCompat(R.color.dark_green))
holder.suspendResumeButton.setImageResource(R.drawable.ic_baseline_play_arrow_white)
holder.suspendResumeButton.tag = RpcClient.RESULT_RESUME // tag on button specified operation triggered in iconClickListener
}
item.determineState() == PROCESS_EXECUTING -> { // show pause
holder.suspendResumeButton.visibility = View.VISIBLE
holder.suspendResumeButton.setBackgroundColor(ResourcesCompat.getColor(fragment.resources,
R.color.dark_green, theme))
holder.suspendResumeButton.setBackgroundColor(context.getColorCompat(R.color.dark_green))
holder.suspendResumeButton.setImageResource(R.drawable.ic_baseline_pause_white)
holder.suspendResumeButton.tag = RpcClient.RESULT_SUSPEND // tag on button specified operation triggered in iconClickListener
}
......
......@@ -25,9 +25,11 @@ import android.graphics.Bitmap
import android.net.ConnectivityManager
import android.os.Build
import android.os.RemoteException
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import edu.berkeley.boinc.BOINCActivity
import edu.berkeley.boinc.R
......@@ -113,3 +115,6 @@ fun Context.translateRPCReason(reason: Int) = when (reason) {
inline fun Long.secondsToLocalDateTime(
zoneId: ZoneId = ZoneId.systemDefault()
): LocalDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(this), zoneId)
@Suppress("NOTHING_TO_INLINE")
inline fun Context.getColorCompat(@ColorRes colorId: Int) = ContextCompat.getColor(this, colorId)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment