Use isEmpty() extension functions.

This commit is contained in:
Isira Seneviratne 2023-02-20 05:19:35 +05:30
parent 015e389227
commit 97107fa777
9 changed files with 32 additions and 44 deletions

View File

@ -104,7 +104,7 @@ object PlaylistsHelper {
DatabaseHolder.Database.localPlaylistsDao().addPlaylistVideo(localPlaylistItem)
val playlist = localPlaylist.playlist
if (playlist.thumbnailUrl == "") {
if (playlist.thumbnailUrl.isEmpty()) {
// set the new playlist thumbnail URL
localPlaylistItem.thumbnailUrl?.let {
playlist.thumbnailUrl = it

View File

@ -291,13 +291,12 @@ class MainActivity : BaseActivity() {
}
// prevent malicious navigation when the search view is getting collapsed
if (navController.currentDestination?.id in listOf(
val destIds = listOf(
R.id.searchResultFragment,
R.id.channelFragment,
R.id.playlistFragment
) &&
(newText == null || newText == "")
) {
)
if (navController.currentDestination?.id in destIds && newText.isNullOrEmpty()) {
return false
}

View File

@ -53,8 +53,8 @@ class CreatePlaylistDialog(
binding.createNewPlaylist.setOnClickListener {
// avoid creating the same playlist multiple times by spamming the button
binding.createNewPlaylist.setOnClickListener(null)
val listName = binding.playlistName.text.toString()
if (listName != "") {
val listName = binding.playlistName.text?.toString()
if (!listName.isNullOrEmpty()) {
lifecycleScope.launch {
requireDialog().hide()
val playlistId = withContext(Dispatchers.IO) {

View File

@ -27,8 +27,9 @@ class DeleteAccountDialog(
}
binding.deleteAccountConfirm.setOnClickListener {
if (binding.deletePassword.text.toString() != "") {
deleteAccount(binding.deletePassword.text.toString())
val password = binding.deletePassword.text?.toString()
if (!password.isNullOrEmpty()) {
deleteAccount(password)
} else {
Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show()
}

View File

@ -28,35 +28,30 @@ class LoginDialog(
binding = DialogLoginBinding.inflate(layoutInflater)
binding.login.setOnClickListener {
if (isInsertionValid()) {
signIn(
binding.username.text.toString(),
binding.password.text.toString()
)
val email = binding.username.text?.toString()
val password = binding.password.text?.toString()
if (!email.isNullOrEmpty() && !password.isNullOrEmpty()) {
signIn(email, password)
} else {
Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show()
}
}
binding.register.setOnClickListener {
if (isEmail(binding.username.text.toString())) {
val email = binding.username.text?.toString().orEmpty()
val password = binding.password.text?.toString().orEmpty()
if (isEmail(email)) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.privacy_alert)
.setMessage(R.string.username_email)
.setNegativeButton(R.string.proceed) { _, _ ->
signIn(
binding.username.text.toString(),
binding.password.text.toString(),
true
)
signIn(email, password, true)
}
.setPositiveButton(R.string.cancel, null)
.show()
} else if (isInsertionValid()) {
signIn(
binding.username.text.toString(),
binding.password.text.toString(),
true
)
} else if (email.isNotEmpty() && password.isNotEmpty()) {
signIn(email, password, true)
} else {
Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show()
}
@ -67,10 +62,6 @@ class LoginDialog(
.show()
}
private fun isInsertionValid(): Boolean {
return binding.username.text.toString() != "" && binding.password.text.toString() != ""
}
private fun signIn(username: String, password: String, createNewAccount: Boolean = false) {
val login = Login(username, password)
lifecycleScope.launchWhenCreated {

View File

@ -36,13 +36,10 @@ class RenamePlaylistDialog(
.show()
.apply {
getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener {
val input = binding.input.text.toString()
if (input == "") {
Toast.makeText(
context,
R.string.emptyPlaylistName,
Toast.LENGTH_SHORT
).show()
val input = binding.input.text?.toString()
if (input.isNullOrEmpty()) {
Toast.makeText(context, R.string.emptyPlaylistName, Toast.LENGTH_SHORT)
.show()
return@setOnClickListener
}
if (input == currentPlaylistName) return@setOnClickListener

View File

@ -1270,7 +1270,7 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
private fun setStreamSource() {
val defaultResolution = PlayerHelper.getDefaultResolution(requireContext()).replace("p", "")
if (defaultResolution != "") setPlayerResolution(defaultResolution.toInt())
if (defaultResolution.isNotEmpty()) setPlayerResolution(defaultResolution.toInt())
if (!PreferenceHelper.getBoolean(PreferenceKeys.USE_HLS_OVER_DASH, false) &&
streams.videoStreams.isNotEmpty()

View File

@ -51,7 +51,7 @@ class SearchFragment : Fragment(R.layout.fragment_search) {
// fetch the search or history
binding.historyEmpty.visibility = View.GONE
binding.suggestionsRecycler.visibility = View.VISIBLE
if (query == null || query == "") {
if (query.isNullOrEmpty()) {
showHistory()
} else {
fetchSuggestions(query)
@ -71,7 +71,7 @@ class SearchFragment : Fragment(R.layout.fragment_search) {
response.reversed(),
(activity as MainActivity).searchView
)
if (isAdded && viewModel.searchQuery.value != "") {
if (isAdded && !viewModel.searchQuery.value.isNullOrEmpty()) {
binding.suggestionsRecycler.adapter = suggestionsAdapter
}
}

View File

@ -99,7 +99,7 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
val latestFeedStreamId = videoFeed.firstOrNull()?.url?.toID() ?: return true
// first time notifications are enabled or no new video available
if (lastSeenStreamId == "" || lastSeenStreamId == latestFeedStreamId) {
if (lastSeenStreamId.isEmpty() || lastSeenStreamId == latestFeedStreamId) {
PreferenceHelper.setLatestVideoId(lastSeenStreamId)
return true
}