mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 19:14:04 +08:00
Divide dialog utils
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.termux.shared.interact;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.termux.shared.R;
|
||||
|
||||
public class MessageDialogUtils {
|
||||
|
||||
/**
|
||||
* Show a message in a dialog
|
||||
*
|
||||
* @param context The {@link Context} to use to start the dialog. An {@link Activity} {@link Context}
|
||||
* must be passed, otherwise exceptions will be thrown.
|
||||
* @param titleText The title text of the dialog.
|
||||
* @param messageText The message text of the dialog.
|
||||
* @param onDismiss The {@link DialogInterface.OnDismissListener} to run when dialog is dismissed.
|
||||
*/
|
||||
public static void showMessage(Context context, String titleText, String messageText, final DialogInterface.OnDismissListener onDismiss) {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Theme_AppCompat_Light_Dialog)
|
||||
.setPositiveButton(android.R.string.ok, null);
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
|
||||
View view = inflater.inflate(R.layout.dialog_show_message, null);
|
||||
if (view != null) {
|
||||
builder.setView(view);
|
||||
|
||||
TextView titleView = view.findViewById(R.id.dialog_title);
|
||||
if (titleView != null)
|
||||
titleView.setText(titleText);
|
||||
|
||||
TextView messageView = view.findViewById(R.id.dialog_message);
|
||||
if (messageView != null)
|
||||
messageView.setText(messageText);
|
||||
}
|
||||
|
||||
if (onDismiss != null)
|
||||
builder.setOnDismissListener(onDismiss);
|
||||
|
||||
builder.show();
|
||||
}
|
||||
|
||||
public static void exitAppWithErrorMessage(Context context, String titleText, String messageText) {
|
||||
showMessage(context, titleText, messageText, dialog -> System.exit(0));
|
||||
}
|
||||
|
||||
}
|
@@ -16,7 +16,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.termux.shared.R;
|
||||
|
||||
public final class DialogUtils {
|
||||
public final class TextInputDialogUtils {
|
||||
|
||||
public interface TextSetListener {
|
||||
void onTextSet(String text);
|
||||
@@ -75,42 +75,4 @@ public final class DialogUtils {
|
||||
dialogHolder[0].show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a message in a dialog
|
||||
*
|
||||
* @param context The {@link Context} to use to start the dialog. An {@link Activity} {@link Context}
|
||||
* must be passed, otherwise exceptions will be thrown.
|
||||
* @param titleText The title text of the dialog.
|
||||
* @param messageText The message text of the dialog.
|
||||
* @param onDismiss The {@link DialogInterface.OnDismissListener} to run when dialog is dismissed.
|
||||
*/
|
||||
public static void showMessage(Context context, String titleText, String messageText, final DialogInterface.OnDismissListener onDismiss) {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Theme_AppCompat_Light_Dialog)
|
||||
.setPositiveButton(android.R.string.ok, null);
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
|
||||
View view = inflater.inflate(R.layout.dialog_show_message, null);
|
||||
if (view != null) {
|
||||
builder.setView(view);
|
||||
|
||||
TextView titleView = view.findViewById(R.id.dialog_title);
|
||||
if (titleView != null)
|
||||
titleView.setText(titleText);
|
||||
|
||||
TextView messageView = view.findViewById(R.id.dialog_message);
|
||||
if (messageView != null)
|
||||
messageView.setText(messageText);
|
||||
}
|
||||
|
||||
if (onDismiss != null)
|
||||
builder.setOnDismissListener(onDismiss);
|
||||
|
||||
builder.show();
|
||||
}
|
||||
|
||||
public static void exitAppWithErrorMessage(Context context, String titleText, String messageText) {
|
||||
showMessage(context, titleText, messageText, dialog -> System.exit(0));
|
||||
}
|
||||
|
||||
}
|
@@ -9,7 +9,7 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.termux.shared.R;
|
||||
import com.termux.shared.data.DataUtils;
|
||||
import com.termux.shared.interact.DialogUtils;
|
||||
import com.termux.shared.interact.MessageDialogUtils;
|
||||
import com.termux.shared.logger.Logger;
|
||||
import com.termux.shared.termux.TermuxConstants;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class PackageUtils {
|
||||
String errorMessage = context.getString(R.string.error_get_package_context_failed_message,
|
||||
packageName, TermuxConstants.TERMUX_GITHUB_REPO_URL);
|
||||
Logger.logError(LOG_TAG, errorMessage);
|
||||
DialogUtils.exitAppWithErrorMessage(context,
|
||||
MessageDialogUtils.exitAppWithErrorMessage(context,
|
||||
context.getString(R.string.error_get_package_context_failed_title),
|
||||
errorMessage);
|
||||
}
|
||||
|
Reference in New Issue
Block a user