Adds removing a monster from the dashboard via long press.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.majinnaibu.monstercards.utils;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
/**
|
||||
* Centralized helper for managing Snackbar notifications and durations across the app.
|
||||
*/
|
||||
public class SnackbarHelper {
|
||||
// Configurable default durations in milliseconds
|
||||
public static int DEFAULT_SHORT_DURATION = 2500; // 2.5 seconds
|
||||
public static int DEFAULT_LONG_DURATION = 4000; // 4.0 seconds (e.g. for Undo or action messages)
|
||||
|
||||
public static Snackbar makeShort(@NonNull View view, @StringRes int resId) {
|
||||
return make(view, view.getContext().getString(resId), DEFAULT_SHORT_DURATION);
|
||||
}
|
||||
|
||||
public static Snackbar makeShort(@NonNull View view, @NonNull CharSequence message) {
|
||||
return make(view, message, DEFAULT_SHORT_DURATION);
|
||||
}
|
||||
|
||||
public static Snackbar makeLong(@NonNull View view, @StringRes int resId) {
|
||||
return make(view, view.getContext().getString(resId), DEFAULT_LONG_DURATION);
|
||||
}
|
||||
|
||||
public static Snackbar makeLong(@NonNull View view, @NonNull CharSequence message) {
|
||||
return make(view, message, DEFAULT_LONG_DURATION);
|
||||
}
|
||||
|
||||
public static Snackbar make(@NonNull View view, @NonNull CharSequence message, int durationMs) {
|
||||
return Snackbar.make(view, message, durationMs);
|
||||
}
|
||||
|
||||
public static void showShort(@NonNull View view, @StringRes int resId) {
|
||||
makeShort(view, resId).show();
|
||||
}
|
||||
|
||||
public static void showShort(@NonNull View view, @NonNull CharSequence message) {
|
||||
makeShort(view, message).show();
|
||||
}
|
||||
|
||||
public static void showLong(@NonNull View view, @StringRes int resId) {
|
||||
makeLong(view, resId).show();
|
||||
}
|
||||
|
||||
public static void showLong(@NonNull View view, @NonNull CharSequence message) {
|
||||
makeLong(view, message).show();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.majinnaibu.monstercards.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
/**
|
||||
* Centralized helper for managing Toast notifications and durations across the app.
|
||||
*/
|
||||
public class ToastHelper {
|
||||
// Configurable default durations
|
||||
public static int DEFAULT_SHORT_DURATION = Toast.LENGTH_SHORT; // ~2.0 seconds
|
||||
public static int DEFAULT_LONG_DURATION = Toast.LENGTH_LONG; // ~3.5 seconds
|
||||
|
||||
private static Toast sCurrentToast;
|
||||
|
||||
public static void showShort(@NonNull Context context, @StringRes int resId) {
|
||||
show(context, context.getString(resId), DEFAULT_SHORT_DURATION);
|
||||
}
|
||||
|
||||
public static void showShort(@NonNull Context context, @NonNull String message) {
|
||||
show(context, message, DEFAULT_SHORT_DURATION);
|
||||
}
|
||||
|
||||
public static void showLong(@NonNull Context context, @StringRes int resId) {
|
||||
show(context, context.getString(resId), DEFAULT_LONG_DURATION);
|
||||
}
|
||||
|
||||
public static void showLong(@NonNull Context context, @NonNull String message) {
|
||||
show(context, message, DEFAULT_LONG_DURATION);
|
||||
}
|
||||
|
||||
public static void show(@NonNull Context context, @NonNull String message, int duration) {
|
||||
if (sCurrentToast != null) {
|
||||
sCurrentToast.cancel();
|
||||
}
|
||||
sCurrentToast = Toast.makeText(context.getApplicationContext(), message, duration);
|
||||
sCurrentToast.show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user