Skip to content

Commit

Permalink
GrindrPlus: Add sysinfo command
Browse files Browse the repository at this point in the history
Change-Id: I3e262ec17a3f2bc2f036e04ca26e83317d10fa4a
  • Loading branch information
R0rt1z2 committed Jan 2, 2025
1 parent 063bcec commit 97e20bf
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 38 deletions.
46 changes: 46 additions & 0 deletions app/src/main/java/com/grindrplus/commands/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.widget.Toast
import androidx.appcompat.widget.AppCompatTextView
import com.grindrplus.GrindrPlus
import com.grindrplus.core.Config
import com.grindrplus.core.Utils.getSystemInfo
import com.grindrplus.ui.Utils.copyToClipboard
import java.io.BufferedReader
import java.io.InputStreamReader

Expand Down Expand Up @@ -81,6 +83,50 @@ class Utils(
}
}

@Command("sysinfo", help = "Display system information")
fun sysinfo(args: List<String>) {
GrindrPlus.runOnMainThreadWithCurrentActivity { activity ->
val dialogView = LinearLayout(activity).apply {
orientation = LinearLayout.VERTICAL
setPadding(60, 40, 60, 40)
layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
}

val systemInfo = getSystemInfo(GrindrPlus.context, false)

val textView = AppCompatTextView(activity).apply {
text = systemInfo
textSize = 14f
setTextColor(Color.WHITE)
setPadding(20, 20, 20, 20)
layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
).apply {
setMargins(0, 20, 0, 0)
}
}

dialogView.addView(textView)

AlertDialog.Builder(activity)
.setTitle("System Information")
.setView(dialogView)
.setPositiveButton("Close") { dialog, _ ->
dialog.dismiss()
}
.setNegativeButton("Copy") { _, _ ->
copyToClipboard("System Information", systemInfo)
}
.create()
.show()
}
}


@Command("prefix", help = "Change the command prefix (default: /)")
fun prefix(args: List<String>) {
val prefix = Config.get("command_prefix", "/")
Expand Down
40 changes: 40 additions & 0 deletions app/src/main/java/com/grindrplus/core/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.content.Intent
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.grindrplus.BuildConfig
import com.grindrplus.GrindrPlus
import com.grindrplus.ui.Utils.getId
import com.grindrplus.utils.RetrofitUtils
Expand Down Expand Up @@ -210,4 +211,43 @@ object Utils {
notify(notificationId, notificationBuilder.build())
}
}

fun getSystemInfo(context: Context, shouldAddSeparator: Boolean = true): String {
return buildString {
if (shouldAddSeparator) appendLine("========================================")
appendLine("Android version: ${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})")
appendLine("ABI(s): ${Build.SUPPORTED_ABIS.joinToString(", ")}")
appendLine(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
"Security patch: ${Build.VERSION.SECURITY_PATCH}"
else "Security patch: N/A"
)
appendLine("Device model: ${Build.MODEL} (${Build.MANUFACTURER})")
appendLine(
try {
val grindr = context.packageManager.getPackageInfo("com.grindrapp.android", 0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
"Grindr: ${grindr.versionName} (${grindr.longVersionCode})"
else
"Grindr: ${grindr.versionName} (${grindr.versionCode})"
} catch (e: Exception) {
"Grindr: N/A"
}
)
appendLine(
try {
val lspatch = context.packageManager.getPackageInfo("org.lsposed.lspatch", 0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
"LSPatch: ${lspatch.versionName} (${lspatch.longVersionCode})"
else
"LSPatch: ${lspatch.versionName} (${lspatch.versionCode})"
} catch (e: Exception) {
"LSPatch: N/A"
}
)
appendLine("GrindrPlus: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})")
appendLine("Xposed API: ${Config.get("xposed_version", "N/A") as Int}")
if (shouldAddSeparator) appendLine("========================================")
}
}
}
40 changes: 2 additions & 38 deletions app/src/main/java/com/grindrplus/ui/fragments/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.AppCompatTextView
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.Fragment
import com.grindrplus.BuildConfig
import com.grindrplus.GrindrPlus
import com.grindrplus.core.Config
import com.grindrplus.core.Utils.getSystemInfo
import com.grindrplus.ui.Utils
import com.grindrplus.ui.colors.Colors
import java.io.File
Expand Down Expand Up @@ -270,43 +270,7 @@ class SettingsFragment : Fragment() {
val mimeType = "text/plain"
val logFile = File(context.filesDir, "grindrplus.log")

val info = buildString {
appendLine("========================================")
appendLine("Android version: ${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})")
appendLine("ABI(s): ${Build.SUPPORTED_ABIS.joinToString(", ")}")
appendLine(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
"Security patch: ${Build.VERSION.SECURITY_PATCH}"
else "Security patch: N/A"
)
appendLine("Device model: ${Build.MODEL} (${Build.MANUFACTURER})")
appendLine(
try {
val grindr = context.packageManager.getPackageInfo("com.grindrapp.android", 0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
"Grindr: ${grindr.versionName} (${grindr.longVersionCode})"
else
"Grindr: ${grindr.versionName} (${grindr.versionCode})"
} catch (e: Exception) {
"Grindr: N/A"
}
)
appendLine(
try {
val lspatch = context.packageManager.getPackageInfo("org.lsposed.lspatch", 0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
"LSPatch: ${lspatch.versionName} (${lspatch.longVersionCode})"
else
"LSPatch: ${lspatch.versionName} (${lspatch.versionCode})"
} catch (e: Exception) {
"LSPatch: N/A"
}
)
appendLine("GrindrPlus: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})")
appendLine("Xposed API: ${Config.get("xposed_version", "N/A") as Int}")
appendLine("========================================\n")
}

val info = getSystemInfo(context)
val logContent = logFile.readText()

try {
Expand Down

0 comments on commit 97e20bf

Please sign in to comment.