Skip to content

Commit

Permalink
Discord betas
Browse files Browse the repository at this point in the history
  • Loading branch information
rweichler committed May 18, 2019
1 parent 729afa3 commit d913994
Show file tree
Hide file tree
Showing 14 changed files with 410 additions and 155 deletions.
17 changes: 17 additions & 0 deletions app/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,31 @@ window:setRootViewController(VIEWCONTROLLER(function(m)
Page.update = require 'page.update'
Page.forum = require 'page.forum'
Page.discord = require 'page.discord'
Page.settings = require 'page.settings'

nav.items = {{
Page.update,
Page.eqe,
Page.history,
Page.forum,
Page.discord,
Page.settings,
}}
function ADD_NAV_PAGE(page, insert_after)
if insert_after then
local idx
for i,v in ipairs(nav.items[1]) do
if v == insert_after then
idx = i
end
end
assert(idx, 'page not found')
table.insert(nav.items[1], idx + 1, page)
else
table.insert(nav.items[1], page)
end
nav:refresh()
end
local super = nav.cell.mnew
function nav.cell.mnew(_)
local m = super(_)
Expand Down
3 changes: 2 additions & 1 deletion app/md.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ local function parse(md, last)
if f then
return f(md, last and md:next() == ffi.NULL)
else
return rtf.new('<IDK>')
-- TODO implement quoting
return rtf.new('')
end
end

Expand Down
200 changes: 115 additions & 85 deletions app/page/forum/threads/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,102 +152,132 @@ return function(forum, push, loadicon)
function tbl.cell.onselect(_, section, row)
end

local item

function list_threads(cb)
load_fail:start_load(m:view():frame().size)
HTTP(BASE_URL..'/api/forum/view_forum?id='..forum.id, {convert = 'json'}, function(info, status, headers)
if info and status == 200 and not info.error then
tbl.items[1] = info.threads
function tbl.cell.onshow(_, m, section, row)
if loading then return end
local thread = tbl.items[section][row]
--m:textLabel():setText(thread.title)
--m:detailTextLabel():setText('By '..thread.author_username..', '..thread.num_replies..' replies')
--m:imageView():setImage(thread.icon)

local self = objc.getref(m)
self.thread = thread

self.title:setFrame(title_frame)
self.title:setText(thread.title)
self.title:sizeToFit()

self.username:setFrame{{min_height, self.title:frame().origin.y + self.title:frame().size.height + mid},{0,0}}
self.username:setText(thread.author_username)
self.username:sizeToFit()

self.avatar:setImage(thread.icon)

local w = min_height - pad*2
local h = min_height/2.5
self.alienblue:setFrame{{m:frame().size.width - w - pad, (m:frame().size.height - h)/2}, {w, h}}

self.replies:setText(thread.num_replies < 1000 and tostring(thread.num_replies) or string.format('%.1fk', math.floor(thread.num_replies/100)/10))
self.replies:setFrame(self.alienblue:frame())

self.time:setText(relative_time(os.time() - thread.last_post_date, true))
self.time:sizeToFit()
local frame = self.alienblue:frame()
frame.origin.y = frame.origin.y - self.time:frame().size.height
frame.size.height = self.time:frame().size.height
self.time:setFrame(frame)

local frame = self.avatar_button.m:frame()
frame.size.height = m:frame().size.height
self.avatar_button.m:setFrame(frame)
self.avatar_button.parent = self

local frame = self.mid_button.m:frame()
frame.size.height = m:frame().size.height
self.mid_button.m:setFrame(frame)
self.mid_button.parent = self

local frame = self.last_button.m:frame()
frame.size.height = m:frame().size.height
self.last_button.m:setFrame(frame)
self.last_button.parent = self
end
function tbl.cell.getheight(_, section, row)
local thread = tbl.items[section][row]
if not heights[row] then
local frame = height_label:frame()
height_label:setFrame(title_frame)
height_label:setText(thread.title)
height_label:sizeToFit()

username_height_label:setText(thread.author_username)
username_height_label:sizeToFit()

heights[row] = math.max(min_height, pad*2 + mid + height_label:frame().size.height + username_height_label:frame().size.height)
end
return heights[row]
end
if cb then
cb()
else
tbl:refresh()
end
loading = false
for i,v in ipairs(info.threads) do
if v.author_avatar then
loadicon(BASE_URL..'/res/dynamic/avatar/'..v.author_username..'-icon.png', function(icon)
v.icon = icon
local rows = objc.toobj{objc.NSIndexPath:indexPathForRow_inSection(i - 1, 0)}
tbl.m:reloadRowsAtIndexPaths_withRowAnimation(rows, UITableViewRowAnimationNone)
end)
end
end
tbl.m:setHidden(false)
load_fail:stop()
load_fail.m:removeFromSuperview()
else
if not(info and status == 200) or (info and info.error) then
local msg
if info then
msg = info.error or 'Got HTTP error code: '..status
else
msg = status
end
load_fail:set_message(msg, m:view():frame().size)
return
end

if not item then
local negativeSpace = objc.UIBarButtonItem:alloc():initWithBarButtonSystemItem_target_action(UIBarButtonSystemItemFixedSpace, nil, nil)
negativeSpace:setWidth(-16)

local button = new_nav_button(0, 0, IMG('ios7-compose-outline.png'))
item = objc.UIBarButtonItem:alloc():initWithCustomView(button.m)
m:navigationItem():setRightBarButtonItems{negativeSpace, item}

local function cb(post)
list_threads()
end

function button.ontoggle()
if LOGIN then
require 'vc.post_thread'(m, forum, cb)
else
local nav = require 'vc.login'(function(login)
if login then
LOG_IN(login)
require 'vc.post_thread'(m, forum, cb)
end
end)
m:presentModalViewController_animated(nav, true)
end
end
end

tbl.items[1] = info.threads
function tbl.cell.onshow(_, m, section, row)
if loading then return end
local thread = tbl.items[section][row]
--m:textLabel():setText(thread.title)
--m:detailTextLabel():setText('By '..thread.author_username..', '..thread.num_replies..' replies')
--m:imageView():setImage(thread.icon)

local self = objc.getref(m)
self.thread = thread

self.title:setFrame(title_frame)
self.title:setText(thread.title)
self.title:sizeToFit()

self.username:setFrame{{min_height, self.title:frame().origin.y + self.title:frame().size.height + mid},{0,0}}
self.username:setText(thread.author_username)
self.username:sizeToFit()

self.avatar:setImage(thread.icon)

local w = min_height - pad*2
local h = min_height/2.5
self.alienblue:setFrame{{m:frame().size.width - w - pad, (m:frame().size.height - h)/2}, {w, h}}

self.replies:setText(thread.num_replies < 1000 and tostring(thread.num_replies) or string.format('%.1fk', math.floor(thread.num_replies/100)/10))
self.replies:setFrame(self.alienblue:frame())

self.time:setText(relative_time(os.time() - thread.last_post_date, true))
self.time:sizeToFit()
local frame = self.alienblue:frame()
frame.origin.y = frame.origin.y - self.time:frame().size.height
frame.size.height = self.time:frame().size.height
self.time:setFrame(frame)

local frame = self.avatar_button.m:frame()
frame.size.height = m:frame().size.height
self.avatar_button.m:setFrame(frame)
self.avatar_button.parent = self

local frame = self.mid_button.m:frame()
frame.size.height = m:frame().size.height
self.mid_button.m:setFrame(frame)
self.mid_button.parent = self

local frame = self.last_button.m:frame()
frame.size.height = m:frame().size.height
self.last_button.m:setFrame(frame)
self.last_button.parent = self
end
function tbl.cell.getheight(_, section, row)
local thread = tbl.items[section][row]
if not heights[row] then
local frame = height_label:frame()
height_label:setFrame(title_frame)
height_label:setText(thread.title)
height_label:sizeToFit()

username_height_label:setText(thread.author_username)
username_height_label:sizeToFit()

heights[row] = math.max(min_height, pad*2 + mid + height_label:frame().size.height + username_height_label:frame().size.height)
end
return heights[row]
end
if cb then
cb()
else
tbl:refresh()
end
loading = false
for i,v in ipairs(info.threads) do
if v.author_avatar then
loadicon(BASE_URL..'/res/dynamic/avatar/'..v.author_username..'-icon.png', function(icon)
v.icon = icon
local rows = objc.toobj{objc.NSIndexPath:indexPathForRow_inSection(i - 1, 0)}
tbl.m:reloadRowsAtIndexPaths_withRowAnimation(rows, UITableViewRowAnimationNone)
end)
end
end
tbl.m:setHidden(false)
load_fail:stop()
load_fail.m:removeFromSuperview()
end)
end
list_threads()
Expand Down
77 changes: 77 additions & 0 deletions app/page/settings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
local page = {}
page.title = 'Settings'
page.icon = IMG('ios7-cog-outline.png', PAGE_ICON_COLOR):retain()
page.hide_nav_button = true

function page:init()
local function push(f, title)
self.nav:pushViewController_animated(VIEWCONTROLLER(f, title), true)
end

local vc = VIEWCONTROLLER(function(m)
local target = ns.target:new()
target.onaction = function()
TOGGLE_NAV()
end

local nav_button = new_nav_button(0, 0)
nav_button.ontoggle = TOGGLE_NAV

local item = objc.UIBarButtonItem:alloc():initWithCustomView(nav_button.m)
m:navigationItem():setLeftBarButtonItem(item)

local tbl = ui.table:new()
local items = {
{
title = 'Enable mediaserverd hook',
subtitle = 'When disabled, audio will not be processed. Basically the equivalent of disabling in iCleaner.',
cb = function(enabled)
if enabled == nil then
return IPC('return GET_ENABLED()') == 'true'
else
IPC('SET_ENABLED('..tostring(enabled)..')')
end
end,
},

}
tbl.section = {#items}
tbl.m:setFrame(m:view():bounds())
local super = tbl.cell.mnew
function tbl.cell.mnew(_)
local m = super(_)
local switch = objc.UISwitch:alloc():init()
m:setAccessoryView(switch)

local self = objc.getref(m)
local target = ns.target:new()
function target.onaction()
if not self.item then return end
local on = objc.weirdbool(switch:isOn())
self.item.cb(on)
end
switch:addTarget_action_forControlEvents(target.m, target.sel, UIControlEventValueChanged)

return m
end
function tbl.cell.onshow(_, m, section, row)
local self = objc.getref(m)
local item = items[row]
m:textLabel():setText(item.title)
m:detailTextLabel():setText(item.subtitle)
m:accessoryView():setOn(item.cb())

self.item = item
end

m:view():addSubview(tbl.m)

end, page.title)
self.nav = objc.UINavigationController:alloc():initWithRootViewController(vc)

self.nav:navigationBar():setBarTintColor(objc.EQEMainView:themeColor())
self.nav:navigationBar():setTintColor(objc.UIColor:whiteColor())
self.nav:navigationBar():setTitleTextAttributes{[C.NSForegroundColorAttributeName] = objc.UIColor:whiteColor()}
self.view = self.nav:view()
end
return page
1 change: 1 addition & 0 deletions app/page/update.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local function check_update(cb, idx)
convert = 'json',
uri_args = {
current = current_version,
git_commit = require('config.default.git_commit'),
},
}, function(json, status, headers)
if not json and check_urls[idx + 1] then
Expand Down
2 changes: 2 additions & 0 deletions app/vc/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ return function(cb)

local y = NAV_HEIGHT + STATUS_BAR_HEIGHT + vpad
local username = objc.UITextField:alloc():initWithFrame{{hpad, y}, {m:view():frame().size.width - hpad*2, 44}}
username:setKeyboardAppearance(UIKeyboardAppearanceDark)
-- username:setAutocorrectionType(UITextAutocorrectionTypeNo)
-- TODO ^ figure out why this method isnt exposed
username:setBackgroundColor(COLOR(0xffffff0d))
Expand All @@ -34,6 +35,7 @@ return function(cb)

y = y + username:frame().size.height + vpad
local password = objc.UITextField:alloc():initWithFrame{{hpad, y}, {m:view():frame().size.width - hpad*2, 44}}
password:setKeyboardAppearance(UIKeyboardAppearanceDark)
password:setSecureTextEntry(true)
password:setBackgroundColor(COLOR(0xffffff0d))
password:setTextColor(objc.UIColor:whiteColor())
Expand Down
6 changes: 4 additions & 2 deletions app/vc/post_reply.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ return function(m, thread, cb, body)
m:setAutomaticallyAdjustsScrollViewInsets(false)

local y = NAV_HEIGHT + STATUS_BAR_HEIGHT
local textview = objc.UITextView:alloc():initWithFrame{{0, y},{m:view():frame().size.width, m:view():frame().size.height - y}}

local textview = objc.EQETextView:alloc():initWithFrame{{0, y},{m:view():frame().size.width, m:view():frame().size.height - y}}
textview:setFont(objc.UIFont:fontWithName_size('HelveticaNeue-Light', 16))
textview:setPlaceholder('Write your reply here...')
textview:setBackgroundColor(objc.UIColor:clearColor())
textview:setTextColor(objc.UIColor:whiteColor())
textview:setText(body)
Expand Down Expand Up @@ -54,6 +54,8 @@ return function(m, thread, cb, body)
if status == 200 then
m:dismissModalViewControllerAnimated(true)
cb(json)
elseif json.error then
C.alert_display_c(json.error, 'Okay', nil, nil)
end
end)
end
Expand Down
Loading

0 comments on commit d913994

Please sign in to comment.