Skip to content

Commit

Permalink
Sessions v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
wingio committed May 23, 2023
1 parent f99288a commit 052adec
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
9 changes: 4 additions & 5 deletions Sessions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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()
)
6 changes: 6 additions & 0 deletions Sessions/src/main/java/xyz/wingio/plugins/sessions/Adapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Session>) :
RecyclerView.Adapter<Adapter.ViewHolder?>() {
Expand Down Expand Up @@ -40,6 +43,9 @@ class Adapter(var data: MutableList<Session>) :
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")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
)

Expand Down
15 changes: 15 additions & 0 deletions Sessions/src/main/java/xyz/wingio/plugins/sessions/SessionCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -152,7 +154,7 @@ class SessionsPage: SettingsPage() {
}

private fun configureSessionsList(sessions: List<Session>) {
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
}
Expand Down
14 changes: 14 additions & 0 deletions Sessions/src/main/java/xyz/wingio/plugins/utils/Utils.kt
Original file line number Diff line number Diff line change
@@ -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
)

}

0 comments on commit 052adec

Please sign in to comment.