You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.6 KiB
Kotlin
44 lines
1.6 KiB
Kotlin
package com.cyb3rko.techniklogger
|
|
|
|
import android.content.Intent
|
|
import android.content.SharedPreferences
|
|
import androidx.core.content.ContextCompat.startActivity
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
|
import com.afollestad.materialdialogs.input.getInputField
|
|
import com.afollestad.materialdialogs.input.input
|
|
|
|
internal const val CURRENT_YEAR = "current_year"
|
|
internal const val CURRENT_YEAR_NAME = "current_year_name"
|
|
internal const val COLUMN_JAHR = "jahr"
|
|
internal const val COLUMN_JAHR_NAME = "name"
|
|
internal const val COLUMN_TECHNIKER_NAME = "name"
|
|
internal const val SHARED_PREFERENCE = "Safe"
|
|
|
|
internal fun showNameDialog(
|
|
activity: MainActivity,
|
|
sharedPref: SharedPreferences,
|
|
sharedPrefEditor: SharedPreferences.Editor
|
|
) {
|
|
val currentName = sharedPref.getString(COLUMN_TECHNIKER_NAME, "")
|
|
|
|
MaterialDialog(activity)
|
|
.cancelable(false)
|
|
.title(0, "Bitte gib deinen Namen ein")
|
|
.show {
|
|
input(hint = "Dein Name", prefill = currentName, waitForPositiveButton = false) { dialog, inputName ->
|
|
try {
|
|
if (!inputName[0].isUpperCase()) {
|
|
dialog.getInputField().error = "Der Anfangsbuchstabe sollte groß sein"
|
|
}
|
|
} catch (ignored: IndexOutOfBoundsException) {
|
|
}
|
|
|
|
positiveButton(0, "Speichern") {
|
|
sharedPrefEditor.putString("name", inputName.toString()).commit()
|
|
activity.finish()
|
|
startActivity(activity, Intent(activity, MainActivity::class.java), null)
|
|
}
|
|
}
|
|
}
|
|
}
|