-
Notifications
You must be signed in to change notification settings - Fork 19
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
Color downloaded torrents differently #58
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ package org.equeim.tremotesf.ui.torrentslistfragment | |
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.content.res.ColorStateList | ||
import android.os.Build | ||
import android.text.TextUtils | ||
import android.view.LayoutInflater | ||
import android.view.Menu | ||
|
@@ -125,7 +127,16 @@ class TorrentsAdapter(private val fragment: TorrentsListFragment) : | |
} | ||
etaTextView.text = FormatUtils.formatDuration(context, torrent.eta) | ||
|
||
progressBar.progress = (torrent.percentDone * 100).toInt() | ||
val progress = (torrent.percentDone * 100).toInt() | ||
progressBar.progress = progress | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
progressBar.progressTintList = if (progress == 100) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK minimum API here is L, not M. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the other hand, I think I'm ready to drop Android 4.x support. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is what Android Studio told me... 🤷♂️ 😅 Happy to change it if you'd like.
So should I leave it as is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it was for getColor() call, which indeed requires API 23. Luckily, there is ContextCompat.getColor() which handles this for us.
I already raised minSdkVersion to 21, so with ContextCompat.getColor() we can just drop version check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, we need to call |
||
ColorStateList.valueOf(context.getColor(R.color.color_downloaded_torrents)) | ||
} else { | ||
ColorStateList.valueOf(context.getColor(R.color.color_primary)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just use null here, to reset progressTintList. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe not.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that Android sets default tint with primary color so we indeed need to restore it. |
||
} | ||
} | ||
|
||
downloadSpeedTextView.text = context.getString( | ||
R.string.download_speed_string, | ||
FormatUtils.formatByteSpeed( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
Torrent.isFinished
is better suited for this check.