From f707f528ea60798fbb4aff353f283b19f388d7d3 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Wed, 30 Mar 2022 16:17:23 +0530 Subject: [PATCH 1/2] restricted to add empty number into field --- .../QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt index 8f55c1413..6bd0b0dcf 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt @@ -21,6 +21,7 @@ package com.moez.QKSMS.feature.settings.autodelete import android.app.Activity import android.content.DialogInterface import android.view.LayoutInflater +import android.widget.Toast import androidx.appcompat.app.AlertDialog import com.moez.QKSMS.R import kotlinx.android.synthetic.main.settings_auto_delete_dialog.view.* @@ -36,7 +37,11 @@ class AutoDeleteDialog(context: Activity, listener: (Int) -> Unit) : AlertDialog setButton(DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.button_cancel)) { _, _ -> } setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.settings_auto_delete_never)) { _, _ -> listener(0) } setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.button_save)) { _, _ -> - listener(layout.field.text.toString().toIntOrNull() ?: 0) + if (!layout.field.text.toString().isEmpty()) { + listener(layout.field.text.toString().toIntOrNull() ?: 0) + } else { + Toast.makeText(context, "Not able to add empty number ! please try again", Toast.LENGTH_LONG).show() + } } } -- GitLab From 0f619feac0997f9963b3e95948e2002c755655f0 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Wed, 30 Mar 2022 16:29:01 +0530 Subject: [PATCH 2/2] refine code --- .../QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt | 4 ++-- presentation/src/main/res/values/strings.xml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt index 6bd0b0dcf..d5b0913b5 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt @@ -37,10 +37,10 @@ class AutoDeleteDialog(context: Activity, listener: (Int) -> Unit) : AlertDialog setButton(DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.button_cancel)) { _, _ -> } setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.settings_auto_delete_never)) { _, _ -> listener(0) } setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.button_save)) { _, _ -> - if (!layout.field.text.toString().isEmpty()) { + if (!layout.field.text.toString().trim().isEmpty()) { listener(layout.field.text.toString().toIntOrNull() ?: 0) } else { - Toast.makeText(context, "Not able to add empty number ! please try again", Toast.LENGTH_LONG).show() + Toast.makeText(context, context.getString(R.string.not_able_to_add_empty_number), Toast.LENGTH_LONG).show() } } } diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 3eba897cb..c799aff39 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -502,4 +502,5 @@ Share some love and rate us on Google Play! OKAY! DISMISS + Not able to add empty number ! please try again -- GitLab