diff --git a/app/src/main/java/com/example/bondoman/activities/AddTransaction.kt b/app/src/main/java/com/example/bondoman/activities/AddTransaction.kt index d5a5ce4b27a44ffb30b4c4b08c6277c4ff525f6b..a24e6a61de3d485a303898f373660cc02cf06211 100644 --- a/app/src/main/java/com/example/bondoman/activities/AddTransaction.kt +++ b/app/src/main/java/com/example/bondoman/activities/AddTransaction.kt @@ -16,6 +16,7 @@ import android.widget.ArrayAdapter import android.widget.Button import android.widget.EditText import android.widget.Spinner +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat @@ -78,22 +79,35 @@ class AddTransaction : AppCompatActivity() { val submitButton : Button = findViewById(R.id.buttonSubmit) locationText = findViewById(R.id.editTextLocation) submitButton.setOnClickListener { - val title = editTextTitle.text.toString() - val category = spinnerCategory.selectedItem.toString() - val amount = editTextAmount.text.toString().toFloatOrNull() ?: 0f - val location = editTextLocation.text.toString() - - val replyIntent = Intent() - if (title.isEmpty()) { - setResult(Activity.RESULT_CANCELED, replyIntent) + if (editTextTitle.text.toString() != "") { + val title = editTextTitle.text.toString() + val category = spinnerCategory.selectedItem.toString() + val amount = editTextAmount.text.toString().toFloatOrNull() ?: 0f + val location = editTextLocation.text.toString() + + if (amount > 0f) { + val replyIntent = Intent() + if (title.isEmpty()) { + setResult(Activity.RESULT_CANCELED, replyIntent) + } else { + replyIntent.putExtra(TITLE, title) + replyIntent.putExtra(TYPE, category) + replyIntent.putExtra(AMOUNT, amount) + replyIntent.putExtra(LOCATION, location) + setResult(Activity.RESULT_OK, replyIntent) + } + finish() + } else { + Toast.makeText(this, + "Price should be greater than 0", + Toast.LENGTH_SHORT).show() + } + } else { - replyIntent.putExtra(TITLE, title) - replyIntent.putExtra(TYPE, category) - replyIntent.putExtra(AMOUNT, amount) - replyIntent.putExtra(LOCATION, location) - setResult(Activity.RESULT_OK, replyIntent) + Toast.makeText(this, + "Name cannot be empty", + Toast.LENGTH_SHORT).show() } - finish() } getLastLocation() } diff --git a/app/src/main/java/com/example/bondoman/activities/EditTransaction.kt b/app/src/main/java/com/example/bondoman/activities/EditTransaction.kt index ca10024840556fb159f2170f8efe56d482afa613..ddedc0e5d73b5ef908a861e6ef3f516ec20a9860 100644 --- a/app/src/main/java/com/example/bondoman/activities/EditTransaction.kt +++ b/app/src/main/java/com/example/bondoman/activities/EditTransaction.kt @@ -11,6 +11,7 @@ import android.util.Log import android.widget.Button import android.widget.EditText import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.bondoman.R import com.example.bondoman.services.TokenCheckService @@ -73,18 +74,31 @@ class EditTransaction() : AppCompatActivity() { val submitButton : Button = findViewById(R.id.buttonSubmit) submitButton.setOnClickListener{ - val replyIntent = Intent() - replyIntent.putExtra("command", "update") - if (false) { - setResult(Activity.RESULT_CANCELED, replyIntent) + if (title.text.toString() != "") { + val replyIntent = Intent() + replyIntent.putExtra("command", "update") + if (amount.text.toString().toFloat() > 0) { + if (false) { + setResult(Activity.RESULT_CANCELED, replyIntent) + } else { + replyIntent.putExtra("id", intentData?.getStringExtra("id")) + replyIntent.putExtra("title", title.text.toString()) + replyIntent.putExtra("amount", amount.text.toString()) + replyIntent.putExtra("location", location.text.toString()) + setResult(Activity.RESULT_OK, replyIntent) + } + finish() + } else { + Toast.makeText(this, + "Price should be greater than 0", + Toast.LENGTH_SHORT).show() + } } else { - replyIntent.putExtra("id", intentData?.getStringExtra("id")) - replyIntent.putExtra("title", title.text.toString()) - replyIntent.putExtra("amount", amount.text.toString()) - replyIntent.putExtra("location", location.text.toString()) - setResult(Activity.RESULT_OK, replyIntent) + Toast.makeText(this, + "Name cannot be empty", + Toast.LENGTH_SHORT).show() } - finish() + } seeLocationText.setOnClickListener { seeLocation()