/** * @file AdminLoginPrompt.kt * @brief Dialog that gates admin-only actions behind AdminAuth's password check. */ package com.example.jnicpp.bowling import android.content.Context import android.text.InputType import android.widget.EditText import android.widget.Toast import androidx.appcompat.app.AlertDialog import com.example.jnicpp.R /** * @brief Shows the admin-login dialog used to gate [ParameterEditorActivity]. * * Pulled out of [BowlingCameraActivity] so that Activity stays limited to * wiring user actions into this rather than holding dialog-building and * password-checking logic itself -- same reasoning as * [StepCounterUiController]. */ object AdminLoginPrompt { /** * @brief Prompts for the admin password and invokes [onSuccess] only * if it matches [AdminAuth]'s admin password; otherwise shows a * "staying in normal user mode" toast and does nothing further. * @param context Used to build the dialog and its toast. * @param onSuccess Invoked once the entered password is confirmed correct. */ fun show(context: Context, onSuccess: () -> Unit) { val passwordInput = EditText(context).apply { inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD hint = context.getString(R.string.admin_password_hint) } val paddingPx = (16 * context.resources.displayMetrics.density).toInt() passwordInput.setPadding(paddingPx, paddingPx, paddingPx, paddingPx) AlertDialog.Builder(context) .setTitle(R.string.admin_login_title) .setMessage(R.string.admin_login_message) .setView(passwordInput) .setPositiveButton(R.string.admin_login_confirm) { _, _ -> if (AdminAuth.isAdminPassword(passwordInput.text.toString())) { onSuccess() } else { Toast.makeText(context, R.string.admin_login_failed, Toast.LENGTH_SHORT).show() } } .setNegativeButton(R.string.admin_login_cancel, null) .show() } }