Utilize TextUtils-adjacent KTX extensions
This commit is contained in:
parent
707bf52d16
commit
4b1d2401f6
13 changed files with 23 additions and 38 deletions
|
@ -18,7 +18,6 @@ import android.content.ClipData
|
|||
import android.content.ClipboardManager
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.MenuItem
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.Toast
|
||||
|
@ -81,7 +80,7 @@ open class BugReportActivity : AbsThemeActivity() {
|
|||
|
||||
initViews()
|
||||
|
||||
if (TextUtils.isEmpty(title)) setTitle(R.string.report_an_issue)
|
||||
if (title.isNullOrEmpty()) setTitle(R.string.report_an_issue)
|
||||
|
||||
deviceInfo = DeviceInfo(this)
|
||||
binding.cardDeviceInfo.airTextDeviceInfo.text = deviceInfo.toString()
|
||||
|
@ -175,14 +174,14 @@ open class BugReportActivity : AbsThemeActivity() {
|
|||
var hasErrors = false
|
||||
|
||||
if (binding.cardReport.optionUseAccount.isChecked) {
|
||||
if (TextUtils.isEmpty(binding.cardReport.inputUsername.text)) {
|
||||
if (binding.cardReport.inputUsername.text.isNullOrEmpty()) {
|
||||
setError(binding.cardReport.inputLayoutUsername, R.string.bug_report_no_username)
|
||||
hasErrors = true
|
||||
} else {
|
||||
removeError(binding.cardReport.inputLayoutUsername)
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(binding.cardReport.inputPassword.text)) {
|
||||
if (binding.cardReport.inputPassword.text.isNullOrEmpty()) {
|
||||
setError(binding.cardReport.inputLayoutPassword, R.string.bug_report_no_password)
|
||||
hasErrors = true
|
||||
} else {
|
||||
|
@ -190,14 +189,14 @@ open class BugReportActivity : AbsThemeActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(binding.cardReport.inputTitle.text)) {
|
||||
if (binding.cardReport.inputTitle.text.isNullOrEmpty()) {
|
||||
setError(binding.cardReport.inputLayoutTitle, R.string.bug_report_no_title)
|
||||
hasErrors = true
|
||||
} else {
|
||||
removeError(binding.cardReport.inputLayoutTitle)
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(binding.cardReport.inputDescription.text)) {
|
||||
if (binding.cardReport.inputDescription.text.isNullOrEmpty()) {
|
||||
setError(binding.cardReport.inputLayoutDescription, R.string.bug_report_no_description)
|
||||
hasErrors = true
|
||||
} else {
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
package code.name.monkey.retromusic.adapter.playlist
|
||||
|
||||
import android.graphics.Color
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
|
@ -80,7 +79,7 @@ class PlaylistAdapter(
|
|||
}
|
||||
|
||||
private fun getPlaylistTitle(playlist: PlaylistEntity): String {
|
||||
return if (TextUtils.isEmpty(playlist.playlistName)) "-" else playlist.playlistName
|
||||
return playlist.playlistName.ifEmpty { "-" }
|
||||
}
|
||||
|
||||
private fun getPlaylistText(playlist: PlaylistWithSongs): String {
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
|
@ -102,7 +101,7 @@ class AppWidgetBig : BaseAppWidget() {
|
|||
val song = service.currentSong
|
||||
|
||||
// Set the titles and artwork
|
||||
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
||||
if (song.title.isEmpty() && song.artistName.isEmpty()) {
|
||||
appWidgetView.setViewVisibility(
|
||||
R.id.media_titles,
|
||||
View.INVISIBLE
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
|
@ -98,7 +97,7 @@ class AppWidgetCard : BaseAppWidget() {
|
|||
val song = service.currentSong
|
||||
|
||||
// Set the titles and artwork
|
||||
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
||||
if (song.title.isEmpty() && song.artistName.isEmpty()) {
|
||||
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
|
||||
} else {
|
||||
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE)
|
||||
|
|
|
@ -21,7 +21,6 @@ import android.content.Intent
|
|||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
|
@ -101,7 +100,7 @@ class AppWidgetClassic : BaseAppWidget() {
|
|||
val song = service.currentSong
|
||||
|
||||
// Set the titles and artwork
|
||||
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
||||
if (song.title.isEmpty() && song.artistName.isEmpty()) {
|
||||
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
|
||||
} else {
|
||||
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE)
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
|
@ -99,7 +98,7 @@ class AppWidgetMD3 : BaseAppWidget() {
|
|||
val song = service.currentSong
|
||||
|
||||
// Set the titles and artwork
|
||||
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
||||
if (song.title.isEmpty() && song.artistName.isEmpty()) {
|
||||
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
|
||||
} else {
|
||||
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE)
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
|
@ -99,10 +98,10 @@ class AppWidgetSmall : BaseAppWidget() {
|
|||
val song = service.currentSong
|
||||
|
||||
// Set the titles and artwork
|
||||
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
||||
if (song.title.isEmpty() && song.artistName.isEmpty()) {
|
||||
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
|
||||
} else {
|
||||
if (TextUtils.isEmpty(song.title) || TextUtils.isEmpty(song.artistName)) {
|
||||
if (song.title.isEmpty() || song.artistName.isEmpty()) {
|
||||
appWidgetView.setTextViewText(R.id.text_separator, "")
|
||||
} else {
|
||||
appWidgetView.setTextViewText(R.id.text_separator, "•")
|
||||
|
|
|
@ -18,7 +18,6 @@ import android.app.PendingIntent
|
|||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import androidx.core.content.ContextCompat
|
||||
|
@ -119,7 +118,7 @@ class AppWidgetText : BaseAppWidget() {
|
|||
val song = service.currentSong
|
||||
|
||||
// Set the titles and artwork
|
||||
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
||||
if (song.title.isEmpty() && song.artistName.isEmpty()) {
|
||||
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
|
||||
} else {
|
||||
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE)
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.content.res.Resources
|
|||
import android.graphics.*
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.TextUtils
|
||||
import android.widget.RemoteViews
|
||||
import androidx.core.content.ContextCompat
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||
|
@ -126,7 +125,7 @@ abstract class BaseAppWidget : AppWidgetProvider() {
|
|||
protected fun getSongArtistAndAlbum(song: Song): String {
|
||||
val builder = StringBuilder()
|
||||
builder.append(song.artistName)
|
||||
if (!TextUtils.isEmpty(song.artistName) && !TextUtils.isEmpty(song.albumName)) {
|
||||
if (song.artistName.isNotEmpty() && song.albumName.isNotEmpty()) {
|
||||
builder.append(" • ")
|
||||
}
|
||||
builder.append(song.albumName)
|
||||
|
|
|
@ -2,7 +2,6 @@ package code.name.monkey.retromusic.fragments.other
|
|||
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
|
@ -92,9 +91,7 @@ class CoverLyricsFragment : AbsMusicServiceFragment(R.layout.fragment_cover_lyri
|
|||
val lrcFile: File? = LyricUtil.getSyncedLyricsFile(song)
|
||||
val data: String = LyricUtil.getStringFromLrc(lrcFile)
|
||||
Lyrics.parse(song,
|
||||
if (!TextUtils.isEmpty(data)) {
|
||||
data
|
||||
} else {
|
||||
data.ifEmpty {
|
||||
// Get Embedded Lyrics
|
||||
LyricUtil.getEmbeddedSyncedLyrics(song.data)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.graphics.Bitmap
|
|||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
|
@ -98,10 +97,10 @@ class UserInfoFragment : Fragment() {
|
|||
|
||||
binding.next.setOnClickListener {
|
||||
val nameString = binding.name.text.toString().trim { it <= ' ' }
|
||||
if (TextUtils.isEmpty(nameString)) {
|
||||
if (nameString.isEmpty()) {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"Umm you're name can't be empty!",
|
||||
"Your name can't be empty!",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
return@setOnClickListener
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.os.Looper
|
|||
import android.text.Layout
|
||||
import android.text.StaticLayout
|
||||
import android.text.TextPaint
|
||||
import android.text.TextUtils
|
||||
import android.text.format.DateUtils
|
||||
import android.util.AttributeSet
|
||||
import android.view.GestureDetector
|
||||
|
@ -208,7 +207,7 @@ class CoverLrcView @JvmOverloads constructor(
|
|||
)
|
||||
mDefaultLabel = ta.getString(R.styleable.LrcView_lrcLabel)
|
||||
mDefaultLabel =
|
||||
if (TextUtils.isEmpty(mDefaultLabel)) context.getString(R.string.empty) else mDefaultLabel
|
||||
if (mDefaultLabel.isNullOrEmpty()) context.getString(R.string.empty) else mDefaultLabel
|
||||
mLrcPadding = ta.getDimension(R.styleable.LrcView_lrcPadding, 0f)
|
||||
mTimelineColor = ta.getColor(
|
||||
R.styleable.LrcView_lrcTimelineColor,
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.net.Uri
|
|||
import android.os.Environment
|
||||
import android.provider.BaseColumns
|
||||
import android.provider.MediaStore
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.FileProvider
|
||||
|
@ -239,10 +238,10 @@ object MusicUtil : KoinComponent {
|
|||
fun getSectionName(mediaTitle: String?): String {
|
||||
var musicMediaTitle = mediaTitle
|
||||
return try {
|
||||
if (TextUtils.isEmpty(musicMediaTitle)) {
|
||||
if (musicMediaTitle.isNullOrEmpty()) {
|
||||
return "-"
|
||||
}
|
||||
musicMediaTitle = musicMediaTitle!!.trim { it <= ' ' }.lowercase()
|
||||
musicMediaTitle = musicMediaTitle.trim { it <= ' ' }.lowercase()
|
||||
if (musicMediaTitle.startsWith("the ")) {
|
||||
musicMediaTitle = musicMediaTitle.substring(4)
|
||||
} else if (musicMediaTitle.startsWith("a ")) {
|
||||
|
@ -320,18 +319,18 @@ object MusicUtil : KoinComponent {
|
|||
}
|
||||
|
||||
fun isArtistNameUnknown(artistName: String?): Boolean {
|
||||
if (TextUtils.isEmpty(artistName)) {
|
||||
if (artistName.isNullOrEmpty()) {
|
||||
return false
|
||||
}
|
||||
if (artistName == Artist.UNKNOWN_ARTIST_DISPLAY_NAME) {
|
||||
return true
|
||||
}
|
||||
val tempName = artistName!!.trim { it <= ' ' }.lowercase()
|
||||
val tempName = artistName.trim { it <= ' ' }.lowercase()
|
||||
return tempName == "unknown" || tempName == "<unknown>"
|
||||
}
|
||||
|
||||
fun isVariousArtists(artistName: String?): Boolean {
|
||||
if (TextUtils.isEmpty(artistName)) {
|
||||
if (artistName.isNullOrEmpty()) {
|
||||
return false
|
||||
}
|
||||
if (artistName == Artist.VARIOUS_ARTISTS_DISPLAY_NAME) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue