Block the possibility to give an empty report name

blinds
Laurent 5 years ago
parent 53465356d9
commit 25e5119822
  1. 14
      app/src/main/java/net/pokeranalytics/android/ui/fragment/report/AbstractReportFragment.kt
  2. 2
      app/src/main/res/values-fr/strings.xml
  3. 1
      app/src/main/res/values/strings.xml

@ -5,8 +5,10 @@ import android.text.InputType
import android.view.View import android.view.View
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.EditText import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.Report import net.pokeranalytics.android.calculus.Report
import net.pokeranalytics.android.calculus.Stat import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
@ -80,8 +82,12 @@ abstract class AbstractReportFragment : DataManagerFragment() {
builder.setView(view) builder.setView(view)
// Add action buttons // Add action buttons
.setPositiveButton(net.pokeranalytics.android.R.string.save) { dialog, _ -> .setPositiveButton(net.pokeranalytics.android.R.string.save) { dialog, _ ->
saveReport(nameEditText.text.toString()) try {
dialog.dismiss() saveReport(nameEditText.text.toString())
dialog.dismiss()
} catch (e: Exception) {
Toast.makeText(requireContext(), e.localizedMessage, Toast.LENGTH_SHORT).show()
}
} }
.setNegativeButton(net.pokeranalytics.android.R.string.cancel) { dialog, _ -> .setNegativeButton(net.pokeranalytics.android.R.string.cancel) { dialog, _ ->
dialog.cancel() dialog.cancel()
@ -109,6 +115,10 @@ abstract class AbstractReportFragment : DataManagerFragment() {
private fun saveReport(name: String) { private fun saveReport(name: String) {
if (name.isEmpty()) {
throw PAIllegalStateException(getString(R.string.report_name_cannot_be_empty))
}
this.reportViewModel.title = name this.reportViewModel.title = name
val rs = this.model.item as ReportSetup val rs = this.model.item as ReportSetup
getRealm().executeTransaction { realm -> getRealm().executeTransaction { realm ->

@ -770,4 +770,6 @@
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string> <string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string> <string name="good_for_you">Good for you!</string>
<string name="report_name_cannot_be_empty">Veuillez donner un nom au rapport</string>
</resources> </resources>

@ -817,5 +817,6 @@
<string name="estimated">estimated</string> <string name="estimated">estimated</string>
<string name="dhph_explanation">You can change the DHPH (Dealt Hands Per Hour) values here. It corresponds to the total number of hands all players receives at a table in one hour. Example: Your local 10-max game deals 25 hands per hour, enter 10 x 25 = 250.</string> <string name="dhph_explanation">You can change the DHPH (Dealt Hands Per Hour) values here. It corresponds to the total number of hands all players receives at a table in one hour. Example: Your local 10-max game deals 25 hands per hour, enter 10 x 25 = 250.</string>
<string name="dealt_hands_per_hour">Dealt hands per hour</string> <string name="dealt_hands_per_hour">Dealt hands per hour</string>
<string name="report_name_cannot_be_empty">You need to give a name to the report</string>
</resources> </resources>

Loading…
Cancel
Save