From 052adec0ad48b39ec3dcc93e709a8e6447be4c12 Mon Sep 17 00:00:00 2001 From: wingio Date: Mon, 22 May 2023 20:37:58 -0400 Subject: [PATCH] Sessions v1.0.2 --- Sessions/build.gradle.kts | 9 ++++----- .../java/xyz/wingio/plugins/sessions/Adapter.kt | 6 ++++++ .../java/xyz/wingio/plugins/sessions/Session.kt | 4 +++- .../xyz/wingio/plugins/sessions/SessionCard.kt | 15 +++++++++++++++ .../xyz/wingio/plugins/sessions/SessionsPage.kt | 4 +++- .../main/java/xyz/wingio/plugins/utils/Utils.kt | 14 ++++++++++++++ 6 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 Sessions/src/main/java/xyz/wingio/plugins/utils/Utils.kt diff --git a/Sessions/build.gradle.kts b/Sessions/build.gradle.kts index 0e857b5..91a540e 100644 --- a/Sessions/build.gradle.kts +++ b/Sessions/build.gradle.kts @@ -1,12 +1,11 @@ -version = "1.0.1" +version = "1.0.2" description = "View and manage login sessions" aliucord.changelog.set( """ - Fixed {fixed marginTop} + Added {added marginTop} ====================== - - * Updated model to prevent crashing for some people - * Fix log out button being pushed off screen for some people + + * Added timestamps to session cards """.trimIndent() ) \ No newline at end of file diff --git a/Sessions/src/main/java/xyz/wingio/plugins/sessions/Adapter.kt b/Sessions/src/main/java/xyz/wingio/plugins/sessions/Adapter.kt index 06f14db..47904ae 100644 --- a/Sessions/src/main/java/xyz/wingio/plugins/sessions/Adapter.kt +++ b/Sessions/src/main/java/xyz/wingio/plugins/sessions/Adapter.kt @@ -12,6 +12,9 @@ import androidx.recyclerview.widget.RecyclerView import com.aliucord.PluginManager import com.aliucord.plugins.R import com.discord.utilities.color.ColorCompat +import com.discord.utilities.time.ClockFactory +import com.discord.utilities.time.TimeUtils +import xyz.wingio.plugins.utils.Utils class Adapter(var data: MutableList) : RecyclerView.Adapter() { @@ -40,6 +43,9 @@ class Adapter(var data: MutableList) : holder.item.title = "${session.clientInfo.os ?: "Unknown"} ${if(session.clientInfo.platform != null) " ยท ${session.clientInfo.platform}" else ""}" holder.item.location = session.clientInfo.location ?: "Unknown Location" + holder.item.timestamp.visibility = View.VISIBLE + holder.item.timestampText = Utils.getTimestampString(session.approxLastUsedTime.g()) + holder.item.isMobile = mobileOsList.contains(session.clientInfo.os ?: "Unknown") } diff --git a/Sessions/src/main/java/xyz/wingio/plugins/sessions/Session.kt b/Sessions/src/main/java/xyz/wingio/plugins/sessions/Session.kt index 7b6d4b4..a7548fa 100644 --- a/Sessions/src/main/java/xyz/wingio/plugins/sessions/Session.kt +++ b/Sessions/src/main/java/xyz/wingio/plugins/sessions/Session.kt @@ -1,8 +1,10 @@ package xyz.wingio.plugins.sessions +import com.discord.api.utcdatetime.UtcDateTime + data class Session ( val idHash: String, - val approxLastUsedTime: String, + val approxLastUsedTime: UtcDateTime, val clientInfo: ClientInfo ) diff --git a/Sessions/src/main/java/xyz/wingio/plugins/sessions/SessionCard.kt b/Sessions/src/main/java/xyz/wingio/plugins/sessions/SessionCard.kt index 651ca61..4dbe2ec 100644 --- a/Sessions/src/main/java/xyz/wingio/plugins/sessions/SessionCard.kt +++ b/Sessions/src/main/java/xyz/wingio/plugins/sessions/SessionCard.kt @@ -19,6 +19,7 @@ import com.lytefast.flexinput.R class SessionCard(ctx: Context) : LinearLayout(ctx) { val name = TextView(ctx) val description = TextView(ctx) + val timestamp = TextView(ctx) val icon = ImageView(ctx) val logOutBtn = ImageButton(ctx) @@ -82,8 +83,18 @@ class SessionCard(ctx: Context) : LinearLayout(ctx) { setTextColor(ColorCompat.getThemedColor(ctx, R.b.colorInteractiveNormal)) } + timestamp.apply { + textSize = 14f + typeface = ResourcesCompat.getFont(ctx, Constants.Fonts.whitney_medium) + isSingleLine = true + layoutParams = params + visibility = View.GONE + setTextColor(ColorCompat.getThemedColor(ctx, R.b.colorInteractiveNormal)) + } + addView(name) addView(description) + addView(timestamp) this@SessionCard.addView(this) } @@ -111,6 +122,10 @@ class SessionCard(ctx: Context) : LinearLayout(ctx) { set(value) { name.text = value } get() = name.text + var timestampText: CharSequence + set(value) { timestamp.text = value } + get() = timestamp.text + var location: CharSequence set(value) { description.text = value } get() = description.text diff --git a/Sessions/src/main/java/xyz/wingio/plugins/sessions/SessionsPage.kt b/Sessions/src/main/java/xyz/wingio/plugins/sessions/SessionsPage.kt index c278118..43df8ae 100644 --- a/Sessions/src/main/java/xyz/wingio/plugins/sessions/SessionsPage.kt +++ b/Sessions/src/main/java/xyz/wingio/plugins/sessions/SessionsPage.kt @@ -18,6 +18,8 @@ import com.aliucord.fragments.SettingsPage import com.aliucord.utils.DimenUtils.dp import com.aliucord.views.DangerButton import com.aliucord.utils.RxUtils.subscribe +import com.discord.utilities.time.ClockFactory +import com.discord.utilities.time.TimeUtils import xyz.wingio.plugins.Sessions @@ -152,7 +154,7 @@ class SessionsPage: SettingsPage() { } private fun configureSessionsList(sessions: List) { - adapter.updateData(sessions) + adapter.updateData(sessions.sortedByDescending { it.approxLastUsedTime }) otherSessionsTitle.visibility = if(sessions.isEmpty()) View.GONE else View.VISIBLE logOutAllBtn.visibility = if(sessions.isEmpty()) View.GONE else View.VISIBLE } diff --git a/Sessions/src/main/java/xyz/wingio/plugins/utils/Utils.kt b/Sessions/src/main/java/xyz/wingio/plugins/utils/Utils.kt new file mode 100644 index 0000000..4f38b67 --- /dev/null +++ b/Sessions/src/main/java/xyz/wingio/plugins/utils/Utils.kt @@ -0,0 +1,14 @@ +package xyz.wingio.plugins.utils + +import android.text.format.DateUtils + +object Utils { + + fun getTimestampString(millis: Long): CharSequence = DateUtils.getRelativeTimeSpanString( + /* time = */ millis, + /* now = */ System.currentTimeMillis(), + /* minResolution = */ 0L, + /* flags = */ DateUtils.FORMAT_ABBREV_TIME + ) + +} \ No newline at end of file