Theme scripting reference
Lua scripts for ListViews will generally implement a newView
and bindView
function.
You can change the script filename, and newView
and bindView
function names in the manifest.json
file.
manifest_json["scripts"][SCRIPT_NAME]
is the JSON path to the script
JSON object in the manifest.
newView
function name. Defaults to "newView"
.bindView
function name. Defaults to "bindView"
.Hint Change these properties to combine scripts into fewer files, or to reuse a script for different screens.
manifest_json["scripts"]["posts_thread"]["file"]
= "thread_item.lua"
manifest_json["scripts"]["posts_comment"]["file"]
= "profile_comment_item.lua"
TODO
manifest_json["scripts"]["profile_thread"]["file"]
= "profile_thread_item.lua"
manifest_json["scripts"]["profile_comment"]["file"]
= "profile_comment_item.lua"
manifest_json["scripts"]["profile_header"]["file"]
= "profile_header.lua"
TODO
manifest_json["scripts"]["inbox_message"]["file"]
= "inbox_message_item.lua"
manifest_json["scripts"]["inbox_comment"]["file"]
= "inbox_comment_item.lua"
TODO
The Builder
object builds Views. It's generally provided as an argument to the newView
function.
FrameLayout
with optional View id. Views created between here and Builder:endViewGroup()
will be children of the FrameLayout
.idStringOrInteger
can be used to refer to the FrameLayout
later.idStringOrInteger
of 0
or nil
is same as no id.FrameLayout
LinearLayout
with optional View id. Views created between here and Builder:endViewGroup()
will be children of the LinearLayout
.LinearLayout
later.LinearLayout
ViewGroup
(e.g., FrameLayout
).Builder:endViewGroup()
.View
and adds it to the current ViewGroup
.View
can be useful for spacing. It's uncommonly used.View
TextView
and adds it to the current ViewGroup
.TextView
ImageView
and adds it to the current ViewGroup
.ImageView
ProgressBar
and adds it to the current ViewGroup
.ProgressBar
ProgressBar
with style ?android:attr/progressBarStyleSmall and adds it to the current ViewGroup
.ProgressBar
Button
and adds it to the current ViewGroup
.Button
Button
with style ?android:attr/buttonStyleSmall and adds it to the current ViewGroup
.Button
ImageButton
and adds it to the current ViewGroup
.ImageButton
ImageButton
with style ?android:attr/buttonStyleSmall and adds it to the current ViewGroup
.ImageButton
Holder
is generally provided as an argument to the bindView
function. It's used to gain access to the View
s that the Builder
created in newView
.
View
with this id.
Generally passed as an argument to bindView
. See https://github.com/reddit/reddit/wiki/JSON
Thing
, when accessed via the Lua API, is read-only.
Look You should look at the javadocs for Things for the supported properties.
ListItem
is generally provided as an argument to the bindView
function. It provides functionality surrounding the list item, in relation to the ListView
and ListAdapter
that contain it.
true
or false
depending if it's the currently-checked position.ListView
on screen.pixels
pixels from the top of the ListView
.These are wrappers for the Android View classes.
You create Views with Builder
and access them later with Holder
.
Look You should look at the javadocs for Views.
Note Global constants are all referenced by redditisfun.CONSTANTNAME
, e.g., redditisfun.TEXT_SIZE_LARGE
TEXT_SIZE_LARGE
is generally 4sp larger than TEXT_SIZE_MEDIUM
.TEXT_SIZE_SMALL
is generally 4sp smaller than TEXT_SIZE_MEDIUM
.Note Global helper classes are referenced by redditisfun.ClassName
, e.g., redditisfun.Fonts
.
TextView:setTypeface(typefaceName)
.typefaceName
is any identifier you want.fontPath
is the relative path to the font file in your theme folder.Fonts:registerNormal("Roboto", "fonts/Roboto-Regular.ttf")
Fonts:registerBold("Roboto", "fonts/Roboto-Bold.ttf")
Fonts:registerItalic("Roboto", "fonts/Roboto-Italic.ttf")
Fonts:registerBoldItalic("Roboto", "fonts/Roboto-BoldItalic.ttf")
originalCharSequence
which may be a regular String.colorString
is "#RRGGBB"
or "#AARRGGBB"
or color names.colorString
formats from android.graphics.Color.parseColor().colorString
is "#RRGGBB"
or "#AARRGGBB"
or color names.styleName
is one of: "normal"
, "bold"
, "italic"
, "bold|italic"
textSize
is either a String like "12sp"
, or a pixel integer value (not recommended) like 20
.view
on screen.View:setOnLongClick()
.upvote_button:setOnLongClick(function(v) Toasts:showHintShort("Upvote the comment", v) end)
Comments list
Script files
manifest_json["scripts"]["comments_thread"]["file"]
="thread_op.lua"
manifest_json["scripts"]["comments_comment"]["file"]
="comment_item.lua"
onClick callbacks
TODO