@@ -13,34 +13,32 @@ import com.google.android.material.textfield.TextInputEditText
1313import com.google.android.material.textfield.TextInputLayout
1414
1515/* *
16- * MIT License
16+ * MIT License
1717 *
18- * Copyright (c) 2023 Raphael Ebner
18+ * Copyright (c) 2024 Raphael Ebner
1919 *
20- * Permission is hereby granted, free of charge, to any person obtaining a copy
21- * of this software and associated documentation files (the "Software"), to deal
22- * in the Software without restriction, including without limitation the rights
23- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24- * copies of the Software, and to permit persons to whom the Software is
25- * furnished to do so, subject to the following conditions:
20+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
21+ * associated documentation files (the "Software"), to deal in the Software without restriction,
22+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
23+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
24+ * furnished to do so, subject to the following conditions:
2625 *
27- * The above copyright notice and this permission notice shall be included in all
28- * copies or substantial portions of the Software.
26+ * The above copyright notice and this permission notice shall be included in all copies or
27+ * substantial portions of the Software.
2928 *
30- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36- * SOFTWARE.
29+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
30+ * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
32+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3734 */
3835class ActivityAddEditFruit : AppCompatActivity () {
3936
4037 companion object {
4138 const val EXTRA_ID = " de.raphaelebner.roomdatabasebackup.sample.EXTRA_ID"
4239 const val EXTRA_NAME = " de.raphaelebner.roomdatabasebackup.sample.EXTRA_NAME"
43- const val EXTRA_DELETE_FRUIT = " de.raphaelebner.roomdatabasebackup.sample.EXTRA_DELETE_FRUIT"
40+ const val EXTRA_DELETE_FRUIT =
41+ " de.raphaelebner.roomdatabasebackup.sample.EXTRA_DELETE_FRUIT"
4442 }
4543
4644 private lateinit var tietFruit: TextInputEditText
@@ -72,12 +70,10 @@ class ActivityAddEditFruit : AppCompatActivity() {
7270 title = " New Fruit"
7371 }
7472
75- // Remove the error message, if user starts typing
76- tietFruit.addTextChangedListener {
77- tilFruit.error = " "
78- }
73+ // Remove the error message, if user starts typing
74+ tietFruit.addTextChangedListener { tilFruit.error = " " }
7975
80- // Delete Fruit
76+ // Delete Fruit
8177 btnDelete.setOnClickListener {
8278 if (intent.hasExtra(EXTRA_ID )) {
8379 deleteFruit = true
@@ -86,15 +82,15 @@ class ActivityAddEditFruit : AppCompatActivity() {
8682 onBackPressedDispatcher.onBackPressed()
8783 }
8884 }
89-
9085 }
9186
92-
9387 /* ---------------------Save current entries, and go back--------------------------*/
9488 private fun saveFruit () {
9589
9690 /* ---------------------If EditText is empty--------------------------*/
97- if (TextUtils .isEmpty(tietFruit.text.toString()) || TextUtils .getTrimmedLength(tietFruit.text.toString()) == 0 ) {
91+ if (TextUtils .isEmpty(tietFruit.text.toString()) ||
92+ TextUtils .getTrimmedLength(tietFruit.text.toString()) == 0
93+ ) {
9894 tilFruit.error = " Fruit name is missing!"
9995 return
10096 }
@@ -110,7 +106,6 @@ class ActivityAddEditFruit : AppCompatActivity() {
110106 }
111107 setResult(Activity .RESULT_OK , data)
112108 finish()
113-
114109 }
115110
116111 override fun onCreateOptionsMenu (menu : Menu ): Boolean {
@@ -121,20 +116,17 @@ class ActivityAddEditFruit : AppCompatActivity() {
121116
122117 override fun onOptionsItemSelected (item : MenuItem ): Boolean {
123118 return when (item.itemId) {
124- // Save Button
119+ // Save Button
125120 R .id.nav_save -> {
126121 saveFruit()
127122 true
128123 }
129- // Back Button
124+ // Back Button
130125 android.R .id.home -> {
131126 onBackPressedDispatcher.onBackPressed()
132127 true
133-
134128 }
135129 else -> super .onOptionsItemSelected(item)
136130 }
137131 }
138-
139-
140132}
0 commit comments