Object Utils
-
- All Implemented Interfaces:
public class UtilsUtility class that holds miscellaneous Utilities
-
-
Field Summary
Fields Modifier and Type Field Description public final static HandlermainThreadpublic final static ExecutorServicethreadPoolpublic static AppActivityappActivityprivate final ContextappContextprivate final BooleanisDebuggablepublic static WidgetChatListwidgetChatListpublic final static UtilsINSTANCE
-
Method Summary
Modifier and Type Method Description final static UnitlaunchUrl(String url)Launches an URL in the user's preferred Browser final static UnitlaunchUrl(Uri url)Launches an URL in the user's preferred Browser final static UnitjoinSupportServer(Context ctx)Prompt to join the Aliucord support server final static DrawablegetDrawableByAttr(Context context, @AttrRes() Integer attr)Get a drawable by attribute final static <R extends Any> RnestedChildAt(ViewGroup root, Integer indices)Nested childAt. final static UnitlaunchFileExplorer(File folder)Launches the file explorer in the specified folder. final static UnitsetClipboard(CharSequence label, CharSequence text)Sets the clipboard content final static Stringpluralise(Integer amount, String noun)Converts the singular term of the nouninto plural.final static UnitshowToast(String message, Boolean showLonger)Send a toast from any Thread final static UnitshowToast(String message)Send a toast from any Thread final static UnitshowToast(Context _ctx, String message, Boolean showLonger)Send a toast from any Thread final static UnitshowToast(Context _ctx, String message)Send a toast from any Thread final static IntegergetResId(String name, String type)Get resource id from discord package. final static UnitopenPage(Context context, Class<out AppComponent> clazz, Intent intent)final static UnitopenPage(Context context, Class<out AppComponent> clazz)final static UnitopenPageWithProxy(Context context, Fragment fragment)final static CommandChoicecreateCommandChoice(String name, String value)Creates a CommandChoice that can be used inside Command args final static ApplicationCommandOptioncreateCommandOption(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 ApplicationCommandOptioncreateCommandOption(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 ApplicationCommandOptioncreateCommandOption(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 ApplicationCommandOptioncreateCommandOption(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 ApplicationCommandOptioncreateCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required, Boolean default)Creates a CommandOption that can be used for commands final static ApplicationCommandOptioncreateCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes, Boolean required)Creates a CommandOption that can be used for commands final static ApplicationCommandOptioncreateCommandOption(ApplicationCommandType type, String name, String description, Integer descriptionRes)Creates a CommandOption that can be used for commands final static ApplicationCommandOptioncreateCommandOption(ApplicationCommandType type, String name, String description)Creates a CommandOption that can be used for commands final static ApplicationCommandOptioncreateCommandOption(ApplicationCommandType type, String name)Creates a CommandOption that can be used for commands final static ApplicationCommandOptioncreateCommandOption(String name)Creates a CommandOption that can be used for commands final static ApplicationCommandOptioncreateCommandOption(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 UserbuildClyde(String name, String avatarUrl)Builds Clyde User final static CheckedSettingcreateCheckedSetting(Context context, CheckedSetting.ViewType type, CharSequence text, CharSequence subtext)Creates a checkable View. final static DrawabletintToTheme(Drawable drawable)Tints a Drawable to match the user's current theme. final static Unitlog(String msg)Logs a message on debug level. final static UnitopenMediaViewer(String url, String filename)final static UnitpromptRestart(String msg, Integer position)Prompts the user to restart Aliucord final static UnitpromptRestart(String msg)Prompts the user to restart Aliucord final static UnitpromptRestart()Prompts the user to restart Aliucord final static LonggenerateRNNonce()Generates a current snowflake nonce similar to RN or Desktop. final ContextgetAppContext()final BooleanisDebuggable()-
-
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.- Returns:
Resolved drawable
-
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 LinearLayoutinto the much nicer
val layout = Utils.nestedChildAt<LinearLayout>(v, 1, 0, 1)- Parameters:
root- The root that holds the childrenindices- Indices of the children.- Returns:
Child at the specified nested index
-
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
nouninto plural.- Parameters:
amount- Amount of the noun.noun- The noun- Returns:
Pluralised
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(expression = "showToast(message, showLonger)"))@JvmOverloads() final static Unit showToast(Context _ctx, 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
@Deprecated(message = "Use {@link #showToast(String, boolean)}", replaceWith = @ReplaceWith(expression = "showToast(message, showLonger)"))@JvmOverloads() final static Unit showToast(Context _ctx, String message)
Send a toast from any Thread
- Parameters:
message- 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.- Returns:
ID of the resource, or 0 if not found.
-
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- Returns:
CommandChoice
-
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- Returns:
Built Clyde
-
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.- Returns:
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- Returns:
Drawable for chaining
-
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
-
generateRNNonce
final static Long generateRNNonce()
Generates a current snowflake nonce similar to RN or Desktop. The default NonceGenerator uses time in the future, which RN and Desktop do not do.
- Returns:
Snowflake nonce with current timestamp.
-
getAppContext
final Context getAppContext()
-
isDebuggable
final Boolean isDebuggable()
-
-
-
-