Object Utils
-
- All Implemented Interfaces:
public class Utils
Utility class that holds miscellaneous Utilities
-
-
Field Summary
Fields Modifier and Type Field Description public final static Handler
mainThread
public final static ExecutorService
threadPool
public static AppActivity
appActivity
private final static Context
appContext
private final static Boolean
isDebuggable
public static WidgetChatList
widgetChatList
public final static Utils
INSTANCE
-
Method Summary
Modifier and Type Method Description final static Unit
launchUrl(String url)
Launches an URL in the user's preferred Browser final static Unit
launchUrl(Uri url)
Launches an URL in the user's preferred Browser final static Unit
joinSupportServer(Context ctx)
Prompt to join the Aliucord support server final static Drawable
getDrawableByAttr(Context context, @AttrRes() Integer attr)
Get a drawable by attribute final static <R extends Any> R
nestedChildAt(ViewGroup root, Integer indices)
Nested childAt. final static Unit
launchFileExplorer(File folder)
Launches the file explorer in the specified folder. final static Unit
setClipboard(CharSequence label, CharSequence text)
Sets the clipboard content final static String
pluralise(Integer amount, String noun)
Converts the singular term of the noun
into plural.final static Unit
showToast(String message, Boolean showLonger)
Send a toast from any Thread final static Unit
showToast(String message)
Send a toast from any Thread final static Unit
showToast(Context ctx, String message, Boolean showLonger)
Send a toast from any Thread final static Unit
showToast(Context ctx, String message)
Send a toast from any Thread final static Integer
getResId(String name, String type)
Get resource id from discord package. final static Unit
openPage(Context context, Class<out AppComponent> clazz, Intent intent)
final static Unit
openPage(Context context, Class<out AppComponent> clazz)
final static Unit
openPageWithProxy(Context context, Fragment fragment)
final static CommandChoice
createCommandChoice(String name, String value)
Creates a CommandChoice that can be used inside Command args final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes, List<CommandChoice> choices, List<ApplicationCommandOption> subCommandOptions, Boolean autocomplete)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes, List<CommandChoice> choices, List<ApplicationCommandOption> subCommandOptions)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes, List<CommandChoice> choices)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name, String description)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(String name)
Creates a CommandOption that can be used for commands final static ApplicationCommandOption
createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes, List<CommandChoice> choices, List<ApplicationCommandOption> subCommandOptions, Boolean autocomplete, Number minValue, Number maxValue)
Creates a CommandOption that can be used for commands final static User
buildClyde(String name, String avatarUrl)
Builds Clyde User final static CheckedSetting
createCheckedSetting(Context context, CheckedSetting.ViewType type, CharSequence text, CharSequence subtext)
Creates a checkable View. final static Drawable
tintToTheme(Drawable drawable)
Tints a Drawable to match the user's current theme. final static Unit
log(String msg)
Logs a message on debug level. final static Unit
openMediaViewer(String url, String filename)
final static Unit
promptRestart(String msg, Integer position)
Prompts the user to restart Aliucord final static Unit
promptRestart(String msg)
Prompts the user to restart Aliucord final static Unit
promptRestart()
Prompts the user to restart Aliucord final static Context
getAppContext()
final static Boolean
isDebuggable()
-
-
Method Detail
-
launchUrl
final static Unit launchUrl(String url)
Launches an URL in the user's preferred Browser
- Parameters:
url
- The url to launch
-
launchUrl
final static Unit launchUrl(Uri url)
Launches an URL in the user's preferred Browser
- Parameters:
url
- The url to launch
-
joinSupportServer
final static Unit joinSupportServer(Context ctx)
Prompt to join the Aliucord support server
- Parameters:
ctx
- Context
-
getDrawableByAttr
final static Drawable getDrawableByAttr(Context context, @AttrRes() Integer attr)
Get a drawable by attribute
- Parameters:
context
- Contextattr
- The attribute id, e.g.
-
nestedChildAt
final static <R extends Any> R nestedChildAt(ViewGroup root, Integer indices)
Nested childAt. Used to turn nightmares like
val layout = ((v.getChildAt(1) as ViewGroup).getChildAt(0) as ViewGroup).getChildAt(1) as LinearLayout
into the much nicer
val layout = Utils.nestedChildAt<LinearLayout>(v, 1, 0, 1)
- Parameters:
root
- The root that holds the childrenindices
- Indices of the children.
-
launchFileExplorer
final static Unit launchFileExplorer(File folder)
Launches the file explorer in the specified folder. May not work on all Roms, will show an error with advice in that case.
- Parameters:
folder
- The folder to launch
-
setClipboard
final static Unit setClipboard(CharSequence label, CharSequence text)
Sets the clipboard content
- Parameters:
label
- User-visible label for the clip datatext
- The actual text
-
pluralise
final static String pluralise(Integer amount, String noun)
Converts the singular term of the
noun
into plural.- Parameters:
amount
- Amount of the noun.noun
- The noun
-
showToast
@JvmOverloads() final static Unit showToast(String message, Boolean showLonger)
Send a toast from any Thread
- Parameters:
message
- Message to show.showLonger
- Whether to show toast for an extended period of time.
-
showToast
@JvmOverloads() final static Unit showToast(String message)
Send a toast from any Thread
- Parameters:
message
- Message to show.
-
showToast
@Deprecated(message = "Use {@link #showToast(String, boolean)}", replaceWith = @ReplaceWith(imports = {}, expression = "showToast(message, showLonger)"))@JvmOverloads() final static Unit showToast(Context ctx, String message, Boolean showLonger)
Send a toast from any Thread
- Parameters:
ctx
- Contextmessage
- Message to show.showLonger
- Whether to show toast for an extended period of time.
-
showToast
@Deprecated(message = "Use {@link #showToast(String, boolean)}", replaceWith = @ReplaceWith(imports = {}, expression = "showToast(message, showLonger)"))@JvmOverloads() final static Unit showToast(Context ctx, String message)
Send a toast from any Thread
- Parameters:
ctx
- Contextmessage
- Message to show.
-
getResId
final static Integer getResId(String name, String type)
Get resource id from discord package.
- Parameters:
name
- Name of the resource.type
- Type of the resource.
-
openPageWithProxy
final static Unit openPageWithProxy(Context context, Fragment fragment)
-
createCommandChoice
final static CommandChoice createCommandChoice(String name, String value)
Creates a CommandChoice that can be used inside Command args
- Parameters:
name
- The name of the choicevalue
- The value representing this choice
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes, List<CommandChoice> choices, List<ApplicationCommandOption> subCommandOptions, Boolean autocomplete)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argumentdescription
- The description of this argumentdescriptionRes
- Optional ID of a string resource that will be used as descriptionrequired
- Whether this option is requireddefault
- Whether this option is the default selection (I think so at least I'm not 100% sure lol)channelTypes
- Channel types this command is enabled inchoices
- List of choices the user may pick fromsubCommandOptions
- List of command options if this argument is of typeautocomplete
- Whether autocomplete is enabled
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes, List<CommandChoice> choices, List<ApplicationCommandOption> subCommandOptions)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argumentdescription
- The description of this argumentdescriptionRes
- Optional ID of a string resource that will be used as descriptionrequired
- Whether this option is requireddefault
- Whether this option is the default selection (I think so at least I'm not 100% sure lol)channelTypes
- Channel types this command is enabled inchoices
- List of choices the user may pick fromsubCommandOptions
- List of command options if this argument is of type
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes, List<CommandChoice> choices)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argumentdescription
- The description of this argumentdescriptionRes
- Optional ID of a string resource that will be used as descriptionrequired
- Whether this option is requireddefault
- Whether this option is the default selection (I think so at least I'm not 100% sure lol)channelTypes
- Channel types this command is enabled inchoices
- List of choices the user may pick from
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argumentdescription
- The description of this argumentdescriptionRes
- Optional ID of a string resource that will be used as descriptionrequired
- Whether this option is requireddefault
- Whether this option is the default selection (I think so at least I'm not 100% sure lol)channelTypes
- Channel types this command is enabled in
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argumentdescription
- The description of this argumentdescriptionRes
- Optional ID of a string resource that will be used as descriptionrequired
- Whether this option is requireddefault
- Whether this option is the default selection (I think so at least I'm not 100% sure lol)
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argumentdescription
- The description of this argumentdescriptionRes
- Optional ID of a string resource that will be used as descriptionrequired
- Whether this option is required
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argumentdescription
- The description of this argumentdescriptionRes
- Optional ID of a string resource that will be used as description
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name, String description)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argumentdescription
- The description of this argument
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argument
-
createCommandOption
@JvmOverloads() final static ApplicationCommandOption createCommandOption(String name)
Creates a CommandOption that can be used for commands
- Parameters:
name
- The name of this argument
-
createCommandOption
final static ApplicationCommandOption createCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default, List<Integer> channelTypes, List<CommandChoice> choices, List<ApplicationCommandOption> subCommandOptions, Boolean autocomplete, Number minValue, Number maxValue)
Creates a CommandOption that can be used for commands
- Parameters:
type
- The type of this argumentname
- The name of this argumentdescription
- The description of this argumentdescriptionRes
- Optional ID of a string resource that will be used as descriptionrequired
- Whether this option is requireddefault
- Whether this option is the default selection (I think so at least I'm not 100% sure lol)channelTypes
- Channel types this command is enabled inchoices
- List of choices the user may pick fromsubCommandOptions
- List of command options if this argument is of typeautocomplete
- Whether autocomplete is enabledminValue
- minValue for number type optionsmaxValue
- maxValue for number type options
-
buildClyde
final static User buildClyde(String name, String avatarUrl)
Builds Clyde User
- Parameters:
name
- Name of useravatarUrl
- Avatar URL of user
-
createCheckedSetting
final static CheckedSetting createCheckedSetting(Context context, CheckedSetting.ViewType type, CharSequence text, CharSequence subtext)
Creates a checkable View.
- Parameters:
context
- Contexttype
- CheckedSetting.ViewType of the checkable item.text
- Title of the checkable item.subtext
- Summary of the checkable item.
-
tintToTheme
final static Drawable tintToTheme(Drawable drawable)
Tints a Drawable to match the user's current theme. More specifically, tints the drawable to R.c.primary_light_600 if the user is using light theme, R.c.primary_dark_300 otherwise
Make sure you call Drawable.mutate first or the drawable will change in the entire app.
- Parameters:
drawable
- Drawable
-
log
@Deprecated(message = "Please stop abusing this method to log random junk then forget about it. It does not tell which plugin is logging stuff, so it is very hard to debug. Make your own Logger instance") final static Unit log(String msg)
Logs a message on debug level.
- Parameters:
msg
- Message to log.
-
openMediaViewer
final static Unit openMediaViewer(String url, String filename)
-
promptRestart
@JvmOverloads() final static Unit promptRestart(String msg, Integer position)
Prompts the user to restart Aliucord
- Parameters:
msg
- Messageposition
- position, see Gravity
-
promptRestart
@JvmOverloads() final static Unit promptRestart(String msg)
Prompts the user to restart Aliucord
- Parameters:
msg
- Message
-
promptRestart
@JvmOverloads() final static Unit promptRestart()
Prompts the user to restart Aliucord
-
getAppContext
final static Context getAppContext()
-
isDebuggable
final static Boolean isDebuggable()
-
-
-
-