Skip to content

Commit

Permalink
Update null safety handling with orEmpty() (#3461)
Browse files Browse the repository at this point in the history
Replaced ?: "" with orEmpty() for improved null safety

Updated all instances of the null-coalescing operator (?: "") with orEmpty() to enhance null safety across the codebase. This change ensures that an empty string is used when a nullable value is null, improving consistency and reducing potential null-related issues.
  • Loading branch information
CodeWithTamim authored Aug 10, 2024
1 parent ae7d9d8 commit f3bfa8c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter<Mai
if (guid != selected) {
mainStorage?.encode(MmkvManager.KEY_SELECTED_SERVER, guid)
if (!TextUtils.isEmpty(selected)) {
notifyItemChanged(mActivity.mainViewModel.getPosition(selected?:""))
notifyItemChanged(mActivity.mainViewModel.getPosition(selected.orEmpty()))
}
notifyItemChanged(mActivity.mainViewModel.getPosition(guid))
if (isRunning) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ScannerActivity : BaseActivity(){

private fun handleResult(result: QRResult) {
if (result is QRResult.QRSuccess ) {
finished(result.content.rawValue?:"")
finished(result.content.rawValue.orEmpty())
} else {
finish()
}
Expand Down Expand Up @@ -110,7 +110,7 @@ class ScannerActivity : BaseActivity(){
try {
val bitmap = BitmapFactory.decodeStream(contentResolver.openInputStream(uri))
val text = QRCodeDecoder.syncDecodeQRCode(bitmap)
finished(text?:"")
finished(text.orEmpty())
} catch (e: Exception) {
e.printStackTrace()
toast(e.message.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class ServerActivity : BaseActivity() {
tlsSetting.alpn?.let {
val alpnIndex = Utils.arrayFind(
alpns,
Utils.removeWhiteSpace(tlsSetting.alpn.joinToString())?:""
Utils.removeWhiteSpace(tlsSetting.alpn.joinToString()).orEmpty()
)
sp_stream_alpn?.setSelection(alpnIndex)
}
Expand Down Expand Up @@ -450,7 +450,7 @@ class ServerActivity : BaseActivity() {
saveStreamSettings(it)
}
if (config.subscriptionId.isEmpty() && !subscriptionId.isNullOrEmpty()) {
config.subscriptionId = subscriptionId?:""
config.subscriptionId = subscriptionId.orEmpty()
}

MmkvManager.encodeServerConfig(editGuid, config)
Expand Down
2 changes: 1 addition & 1 deletion V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object Utils {
* @return
*/
fun getEditable(text: String?): Editable {
return Editable.Factory.getInstance().newEditable(text?:"")
return Editable.Factory.getInstance().newEditable(text.orEmpty())
}

/**
Expand Down

0 comments on commit f3bfa8c

Please sign in to comment.