Skip to content

Commit a83e56d

Browse files
committed
refactor: reformat old code to follow cleaner style
1 parent 29aba4b commit a83e56d

File tree

33 files changed

+194
-522
lines changed

33 files changed

+194
-522
lines changed

plugin/AccountSwitcher/src/main/kotlin/AccountSwitcher.kt

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ import accountswitcher.settings.PluginSettings
44
import android.content.Context
55
import com.aliucord.Utils
66
import com.aliucord.annotations.AliucordPlugin
7-
import com.aliucord.api.PatcherAPI
87
import com.aliucord.api.SettingsAPI
98
import com.aliucord.entities.Plugin
10-
import com.aliucord.patcher.after
119
import com.aliucord.patcher.instead
1210
import com.discord.utilities.rest.RestAPI
1311
import com.discord.widgets.settings.WidgetSettings
14-
import de.robv.android.xposed.XC_MethodHook
15-
import kotlin.properties.ReadOnlyProperty
1612

1713
@Suppress("MISSING_DEPENDENCY_SUPERCLASS")
1814
@AliucordPlugin
@@ -25,7 +21,6 @@ class AccountSwitcher : Plugin() {
2521
lateinit var mSettings: SettingsAPI
2622
}
2723

28-
@Suppress("SetTextI18n")
2924
override fun start(context: Context) {
3025
mSettings = settings
3126

@@ -64,39 +59,4 @@ class AccountSwitcher : Plugin() {
6459
}
6560

6661
override fun stop(context: Context) = patcher.unpatchAll()
67-
}
68-
69-
open class Arguments {
70-
var rawArguments: List<Any> = emptyList()
71-
var argumentClasses: Array<Class<*>> = arrayOf()
72-
73-
private var size: Int = 0
74-
75-
fun <T> argument(clazz: Class<T>): ReadOnlyProperty<Any?, T> {
76-
argumentClasses += clazz
77-
78-
val greg = ReadOnlyProperty<Any?, T> { _, _ ->
79-
@Suppress("UNCHECKED_CAST")
80-
rawArguments.getOrNull(argumentClasses.lastIndex) as T
81-
}
82-
83-
return greg
84-
}
85-
}
86-
87-
class TestArgs : Arguments() {
88-
val test by argument(String::class.java)
89-
}
90-
91-
inline fun <reified T : Any, reified R> PatcherAPI.a(
92-
method: String,
93-
arguments: () -> R,
94-
crossinline body: T.(param: XC_MethodHook.MethodHookParam, args: R) -> Unit
95-
): Runnable where R : Arguments {
96-
val args = arguments()
97-
98-
return after<T>(method, paramTypes = args.argumentClasses) {
99-
args.rawArguments = it.args.asList()
100-
body(it, args)
101-
}
10262
}

plugin/AccountSwitcher/src/main/kotlin/accountswitcher/SwitcherPage.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.lytefast.flexinput.R
1919

2020
@Suppress("MISSING_DEPENDENCY_SUPERCLASS")
2121
class SwitcherPage(private val accounts: ArrayList<Account>) : SettingsPage() {
22-
@Suppress("SetTextI18n")
2322
override fun onViewBound(view: View) {
2423
super.onViewBound(view)
2524

@@ -54,10 +53,7 @@ class SwitcherPage(private val accounts: ArrayList<Account>) : SettingsPage() {
5453
Button(ctx).apply {
5554
text = "Log Out"
5655
setBackgroundColor(
57-
view.resources.getColor(
58-
R.c.uikit_btn_bg_color_selector_red,
59-
view.context.theme
60-
)
56+
view.resources.getColor(R.c.uikit_btn_bg_color_selector_red, view.context.theme)
6157
)
6258
setOnClickListener { StoreStream.getAuthentication().setAuthed(null) }
6359
}

plugin/AccountSwitcher/src/main/kotlin/accountswitcher/settings/AccountAdapter.kt

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ class AccountAdapter(
3535
if (it) saveAccounts()
3636
}
3737

38-
fun removeAccount(token: String) = accounts
39-
.removeIf {
40-
it.token == token
41-
}.also { if (it) saveAccounts() }
38+
fun removeAccount(token: String) = accounts.removeIf {
39+
it.token == token
40+
}.also { if (it) saveAccounts() }
4241

4342
override fun getItemCount() = accounts.size
4443

@@ -50,30 +49,24 @@ class AccountAdapter(
5049
isSettings = isSettings
5150
)
5251

53-
@Suppress("SetTextI18n")
54-
override fun onBindViewHolder(holder: AccountViewHolder, position: Int): Unit =
55-
accounts[position].let { account ->
56-
Utils.threadPool.execute {
57-
val user = StoreStream.getUsers().users[account.id] ?: RestAPI.api
58-
.userGet(account.id)
59-
.await()
60-
.first
61-
?.let { user -> CoreUser(user) }
62-
63-
holder.name.text = if (user == null) {
64-
"Failed to load user"
65-
} else {
66-
UserUtils.INSTANCE.getUserNameWithDiscriminator(
67-
user,
68-
null,
69-
null
70-
)
71-
}
72-
holder.userId.text = "ID: ${user?.id ?: "Unknown"}"
73-
74-
IconUtils.setIcon(holder.avatar, user)
52+
override fun onBindViewHolder(holder: AccountViewHolder, position: Int): Unit = accounts[position].let { account ->
53+
Utils.threadPool.execute {
54+
val user = StoreStream.getUsers().users[account.id] ?: RestAPI.api
55+
.userGet(account.id)
56+
.await()
57+
.first
58+
?.let(::CoreUser)
59+
60+
holder.name.text = if (user == null) {
61+
"Failed to load user"
62+
} else {
63+
UserUtils.INSTANCE.getUserNameWithDiscriminator(user, null, null)
7564
}
65+
holder.userId.text = "ID: ${user?.id ?: "Unknown"}"
66+
67+
IconUtils.setIcon(holder.avatar, user)
7668
}
69+
}
7770

7871
fun onEdit(position: Int) {
7972
AccountDialog(this, getAccounts()[position])

plugin/AccountSwitcher/src/main/kotlin/accountswitcher/settings/AccountDialog.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ private const val TOKEN_REGEX =
1717
"""(mfa\.[a-z0-9_-]{20,})|([a-z0-9_-]{23,28}\.[a-z0-9_-]{6,7}\.([a-z0-9_-]{27,38}))"""
1818

1919
@Suppress("MISSING_DEPENDENCY_SUPERCLASS")
20-
class AccountDialog(private val adapter: AccountAdapter, private val account: Account? = null) :
21-
InputDialog() {
20+
class AccountDialog(private val adapter: AccountAdapter, private val account: Account? = null) : InputDialog() {
2221
private val token = account?.token
2322

2423
private val buttonStates = arrayOf(

plugin/AccountSwitcher/src/main/kotlin/accountswitcher/settings/PluginSettings.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import com.lytefast.flexinput.R
2525

2626
@Suppress("MISSING_DEPENDENCY_SUPERCLASS")
2727
class PluginSettings(private val settings: SettingsAPI) : SettingsPage() {
28-
@Suppress("SetTextI18n")
2928
override fun onViewBound(view: View) {
3029
super.onViewBound(view)
3130

@@ -93,15 +92,11 @@ class PluginSettings(private val settings: SettingsAPI) : SettingsPage() {
9392
text = "Add Current Account"
9493
setOnClickListener {
9594
when {
96-
getAccounts().any { it.token == token } -> Utils.showToast(
97-
"Account already added"
98-
)
99-
95+
getAccounts().any { it.token == token } -> Utils.showToast("Account already added")
10096
token != null -> {
10197
accountAdapter.addAccount(token, StoreStream.getUsers().me.id)
10298
Utils.showToast("Added current account")
10399
}
104-
105100
else -> Utils.showToast("Failed to fetch token")
106101
}
107102

plugin/BetterMediaViewer/src/main/kotlin/bettermediaviewer/Patches.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ import java.util.concurrent.TimeUnit
3939
object Patches {
4040
private var settings: SettingsAPI = PluginManager.plugins["BetterMediaViewer"]?.settings!!
4141

42+
// Add a mute button to the media player
43+
fun PatcherAPI.patchMuteButton() {
44+
}
45+
4246
fun PatcherAPI.patchWidget() {
4347
val downloadManager = Utils.appContext
4448
.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
@@ -106,12 +110,9 @@ object Patches {
106110
WindowInsetsControllerCompat(Utils.appActivity.window, binding.root).hide(
107111
when (settings.getInt("immersiveModeType", 0)) {
108112
0 -> WindowInsetsCompat.Type.statusBars()
109-
110113
1 -> WindowInsetsCompat.Type.navigationBars()
111-
112114
2 -> WindowInsetsCompat.Type.statusBars() or
113115
WindowInsetsCompat.Type.statusBars()
114-
115116
else -> return@after
116117
}
117118
)
@@ -126,7 +127,7 @@ object Patches {
126127
binding.root
127128
.findViewById<AppBarLayout>(R.f.action_bar_toolbar_layout)
128129
.layoutParams as FrameLayout.LayoutParams
129-
).gravity = Gravity.BOTTOM
130+
).gravity = Gravity.BOTTOM
130131
}
131132
}
132133
}
@@ -152,12 +153,9 @@ object Patches {
152153
ObservableExtensionsKt.ui(timer, this, null),
153154
WidgetMedia::class.java,
154155
null,
155-
`WidgetMedia$showControls$1`(
156-
this
157-
),
156+
`WidgetMedia$showControls$1`(this),
158157
null,
159-
{
160-
},
158+
{},
161159
{ },
162160
`WidgetMedia$showControls$2`(this)
163161
)
@@ -203,7 +201,7 @@ object Patches {
203201
(
204202
widgetMedia.toolbarHeight.toFloat() /
205203
widgetMedia.playerControlsHeight.toFloat()
206-
)
204+
)
207205
}
208206
}
209207
}

plugin/BetterMediaViewer/src/main/kotlin/bettermediaviewer/PluginSettings.kt

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@ import java.io.File
2727
class PluginSettings(private val settings: SettingsAPI) : SettingsPage() {
2828
private var launcher: ActivityResultLauncher<Intent>? = null
2929

30-
@Suppress("SetTextI18n")
3130
override fun onViewBound(view: View) {
3231
super.onViewBound(view)
3332

3433
val ctx = requireContext()
3534

36-
fun createCheckedSetting(
37-
title: String,
38-
subtitle: String,
39-
setting: String,
40-
defValue: Boolean
41-
): CheckedSetting {
35+
fun createCheckedSetting(title: String, subtitle: String, setting: String, defValue: Boolean): CheckedSetting {
4236
return Utils
4337
.createCheckedSetting(
4438
ctx,
@@ -73,16 +67,14 @@ class PluginSettings(private val settings: SettingsAPI) : SettingsPage() {
7367
progress = controlsTimeout - offset
7468
12.dp.let { setPadding(it, 0, it, 0) }
7569
setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
76-
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) =
77-
with((progress / 100) * 100) {
78-
seekBar.progress = this
79-
currentTimeout.text = "${this + offset} ms"
80-
}
70+
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) = with((progress / 100) * 100) {
71+
seekBar.progress = this
72+
currentTimeout.text = "${this + offset} ms"
73+
}
8174

8275
override fun onStartTrackingTouch(seekBar: SeekBar) {}
8376

84-
override fun onStopTrackingTouch(seekBar: SeekBar) =
85-
settings.setInt("controlsTimeout", seekBar.progress + offset)
77+
override fun onStopTrackingTouch(seekBar: SeekBar) = settings.setInt("controlsTimeout", seekBar.progress + offset)
8678
})
8779
}
8880
val timeoutSection = LinearLayout(ctx, null, 0, R.i.UiKit_Settings_Item).apply {

plugin/ChannelInvites/src/main/kotlin/ChannelInvites.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import android.content.Context
32
import android.view.View
43
import android.widget.LinearLayout
@@ -17,7 +16,6 @@ import com.lytefast.flexinput.R
1716
@Suppress("MISSING_DEPENDENCY_SUPERCLASS")
1817
@AliucordPlugin
1918
class ChannelInvites : Plugin() {
20-
@Suppress("SetTextI18n")
2119
override fun start(c: Context) {
2220
val invitesLayoutId = View.generateViewId()
2321
val scrollViewId = Utils.getResId("scroll_view", "id")
@@ -27,10 +25,7 @@ class ChannelInvites : Plugin() {
2725
WidgetTextChannelSettings.Model::class.java
2826
) {
2927
val root = WidgetTextChannelSettings.`access$getBinding$p`(this).root
30-
val content = root
31-
.findViewById<NestedScrollView>(
32-
scrollViewId
33-
).getChildAt(0) as LinearLayout
28+
val content = root.findViewById<NestedScrollView>(scrollViewId).getChildAt(0) as LinearLayout
3429

3530
if (content.findViewById<LinearLayout>(invitesLayoutId) != null) return@after
3631

@@ -55,12 +50,7 @@ class ChannelInvites : Plugin() {
5550
)!!
5651
.mutate()
5752
.apply {
58-
setTint(
59-
ColorCompat.getThemedColor(
60-
context,
61-
R.b.colorInteractiveNormal
62-
)
63-
)
53+
setTint(ColorCompat.getThemedColor(context, R.b.colorInteractiveNormal))
6454
}
6555

6656
text = "Invites"

plugin/ChannelInvites/src/main/kotlin/channelinvites/InvitesPage.kt

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import com.discord.widgets.servers.settings.invites.WidgetServerSettingsInstantI
2121
import com.google.gson.stream.JsonReader
2222

2323
@Suppress("MISSING_DEPENDENCY_SUPERCLASS")
24-
class InvitesPage(private val channel: Channel) :
25-
AppFragment(Utils.getResId("widget_server_settings_instant_invites", "layout")) {
24+
class InvitesPage(private val channel: Channel) : AppFragment(Utils.getResId("widget_server_settings_instant_invites", "layout")) {
2625
private val viewFlipperId = Utils.getResId(
2726
"server_settings_instant_invites_view_flipper",
2827
"id"
@@ -49,16 +48,9 @@ class InvitesPage(private val channel: Channel) :
4948
.execute()
5049
.text()
5150

52-
val invites = InboundGatewayGsonParser.fromJson(
53-
JsonReader(json.reader()),
54-
Array<ModelInvite>::class.java
55-
)
51+
val invites = InboundGatewayGsonParser.fromJson(JsonReader(json.reader()), Array<ModelInvite>::class.java)
5652
val inviteItems = invites.map { modelInvite ->
57-
WidgetServerSettingsInstantInvites.Model.InviteItem(
58-
modelInvite,
59-
channel.guildId,
60-
null
61-
)
53+
WidgetServerSettingsInstantInvites.Model.InviteItem(modelInvite, channel.guildId, null)
6254
}
6355

6456
Utils.mainThread.post {
@@ -69,21 +61,14 @@ class InvitesPage(private val channel: Channel) :
6961
invitesRecycler.run {
7062
adapter = WidgetServerSettingsInstantInvites.Adapter(this).also { adapter ->
7163
val onInviteSelectedListener = { modelInvite: ModelInvite ->
72-
WidgetServerSettingsInstantInvitesActions.create(
73-
parentFragmentManager,
74-
modelInvite.code
75-
)
64+
WidgetServerSettingsInstantInvitesActions.create(parentFragmentManager, modelInvite.code)
7665
}
7766

7867
val onInviteExpiredListener = { modelInvite: ModelInvite ->
7968
StoreStream.getInstantInvites().onInviteRemoved(modelInvite)
8069
}
8170

82-
adapter.configure(
83-
inviteItems,
84-
onInviteSelectedListener,
85-
onInviteExpiredListener
86-
)
71+
adapter.configure(inviteItems, onInviteSelectedListener, onInviteExpiredListener)
8772
}
8873
layoutManager = LinearLayoutManager(context)
8974
}

0 commit comments

Comments
 (0)