1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
package dev.equestria.pluralwear.pluralkt.fulltypes
import android.graphics.Bitmap
import android.util.Log
import com.squareup.picasso.Picasso
import dev.equestria.pluralwear.pluralkt.types.PkColor
import dev.equestria.pluralwear.pluralkt.types.PkFronter
import dev.equestria.pluralwear.pluralkt.types.PkGroup
import dev.equestria.pluralwear.pluralkt.types.PkId
import dev.equestria.pluralwear.pluralkt.types.PkMember
import dev.equestria.pluralwear.pluralkt.types.PkSystem
import dev.equestria.pluralwear.pluralkt.types.PkSystemPrivacy
import dev.equestria.pluralwear.pluralkt.types.PkSystemSettings
import dev.equestria.pluralwear.pluralkt.types.PkType
import dev.equestria.pluralwear.pluralkt.types.PkUuid
import dev.equestria.pluralwear.presentation.CircleTransform
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import java.util.UUID
import kotlin.concurrent.thread
/*
A PkFullSystem is a system which contains all the relevant information
that a program may need to know about a System.
This includes full member data, full group data, switches, and so on.
*/
class PkFullSystem(
system: PkSystem?, systemSettings: PkSystemSettings?, systemMembers: Array<PkMember>?, systemGroups: Array<PkGroup>?, systemFronter: PkFronter?
) : PkType {
// Basic system stuff
val id: PkId
val uuid: PkUuid
val created: Instant
var name: String? = null
var description: String? = null
var tag: String? = null
var pronouns: String? = null
var avatarUrl: String? = null
var avatar: Bitmap? = null
var bannerUrl: String? = null
var banner: Bitmap? = null
var color: PkColor? = null
var privacy: PkSystemPrivacy? = null
var webhookUrl: String? = null
// Custom stuff
val settings: PkSystemSettings?
var members: MutableList<PkFullMember>? = mutableListOf()
var groups: MutableList<PkFullGroup>? = mutableListOf()
var front: PkFullFronter?
init {
id = system?.id ?: ""
uuid = system?.uuid ?: PkUuid(UUID(0,0))
created = system?.created ?: Clock.System.now()
name = system?.name
description = system?.description
tag = system?.tag
pronouns = system?.pronouns
avatarUrl = system?.avatarUrl
bannerUrl = system?.banner
color = system?.color
privacy = system?.privacy
webhookUrl = system?.webhookUrl
settings = systemSettings
front = systemFronter?.let { PkFullFronter(it) }
if (systemMembers != null) {
systemMembers.forEach {
members?.add(PkFullMember(it))
}
}
if (systemGroups != null) {
systemGroups.forEach {
groups?.add(PkFullGroup(it))
}
}
thread {
// Process avatar and banner
avatar = try {
if (avatarUrl != null)
Picasso.get().load(avatarUrl).transform(CircleTransform()).get()
else
null
} catch(ex: Exception) {
// It doesn't matter what happened, we just couldn't load it.
Log.w("PluralWear", "Couldn't load system avatar:\nName: " + this.name + "\nURL: " + this.avatarUrl + "\nReason: " + ex.message)
null
}
banner = try {
if (bannerUrl != null)
Picasso.get().load(bannerUrl).get()
else
null
} catch(ex: Exception) {
// It doesn't matter what happened, we just couldn't load it.
Log.w("PluralWear", "Couldn't load system banner:\nName: " + this.name + "\nURL: " + this.bannerUrl + "\nReason: " + ex.message)
null
}
}
}
override fun toString(): String = "PluralKit System"
}
|