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) DatabaseHolder.Database.localPlaylistsDao().addPlaylistVideo(localPlaylistItem)
val playlist = localPlaylist.playlist val playlist = localPlaylist.playlist
if (playlist.thumbnailUrl == "") { if (playlist.thumbnailUrl.isEmpty()) {
// set the new playlist thumbnail URL // set the new playlist thumbnail URL
localPlaylistItem.thumbnailUrl?.let { localPlaylistItem.thumbnailUrl?.let {
playlist.thumbnailUrl = it playlist.thumbnailUrl = it

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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