fix gradle
This commit is contained in:
@@ -1,16 +1,33 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
}
|
||||
|
||||
android { namespace = "com.bozz.kosssh"; compileSdk = 37
|
||||
defaultConfig { applicationId = "com.bozz.kosssh"; minSdk = 26; targetSdk = 35; versionCode = 1; versionName = "1.0.0" }
|
||||
buildToolsVersion = "35.0.0"
|
||||
android {
|
||||
namespace = "com.bozz.kosssh"
|
||||
compileSdk = 37
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.bozz.kosssh"
|
||||
minSdk = 26
|
||||
targetSdk = 37
|
||||
versionCode = 2
|
||||
versionName = "1.1.0"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
packaging {
|
||||
resources.excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||||
}
|
||||
buildToolsVersion = "37.0.0"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.15.0")
|
||||
implementation("androidx.appcompat:appcompat:1.7.0")
|
||||
implementation("com.google.android.material:material:1.12.0")
|
||||
implementation("androidx.core:core-ktx:1.17.0")
|
||||
implementation("androidx.appcompat:appcompat:1.7.1")
|
||||
implementation("com.google.android.material:material:1.13.0")
|
||||
implementation("com.github.mwiede:jsch:0.2.23")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" />
|
||||
<application android:theme="@style/Theme.KosSSHMobile" android:label="KosSSH Mobile" android:allowBackup="true" android:supportsRtl="true">
|
||||
<activity android:name=".ui.MainActivity" android:screenOrientation="unspecified" android:exported="true">
|
||||
<intent-filter>
|
||||
|
||||
@@ -3,12 +3,17 @@ package com.bozz.kosssh.terminal
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.text.InputType
|
||||
import android.util.AttributeSet
|
||||
import android.view.*
|
||||
import android.view.inputmethod.*
|
||||
import java.util.ArrayDeque
|
||||
import kotlin.math.max
|
||||
|
||||
class TerminalView(context: Context) : View(context) {
|
||||
class TerminalView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : View(context, attrs, defStyleAttr) {
|
||||
private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { typeface = Typeface.MONOSPACE }
|
||||
private val lines = ArrayDeque<MutableList<Cell>>()
|
||||
private var current = mutableListOf<Cell>()
|
||||
@@ -154,5 +159,6 @@ class TerminalView(context: Context) : View(context) {
|
||||
}
|
||||
|
||||
fun sendCtrl(letter: Char) { send(byteArrayOf((letter.uppercaseChar().code - 64).toByte())) }
|
||||
private fun send(s: String) { sender?.invoke(s.toByteArray(Charsets.UTF_8)) }
|
||||
private fun send(s: String) { send(s.toByteArray(Charsets.UTF_8)) }
|
||||
private fun send(data: ByteArray) { sender?.invoke(data) }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.bozz.kosssh.ui
|
||||
|
||||
import android.app.*
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
@@ -10,6 +12,9 @@ import com.bozz.kosssh.ssh.SshClient
|
||||
import com.bozz.kosssh.terminal.TerminalView
|
||||
|
||||
class MainActivity : Activity() {
|
||||
companion object {
|
||||
private const val REQUEST_LOCAL_NETWORK = 3701
|
||||
}
|
||||
private lateinit var terminal: TerminalView
|
||||
private val ssh = SshClient()
|
||||
private lateinit var status: TextView
|
||||
@@ -38,9 +43,43 @@ class MainActivity : Activity() {
|
||||
val pass = findViewById<EditText>(R.id.password).text.toString()
|
||||
if (host.isEmpty() || user.isEmpty()) { Toast.makeText(this,"Host dan username wajib diisi",Toast.LENGTH_SHORT).show(); return }
|
||||
terminal.clear()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 37 &&
|
||||
checkSelfPermission(android.Manifest.permission.ACCESS_LOCAL_NETWORK) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
requestPermissions(
|
||||
arrayOf(android.Manifest.permission.ACCESS_LOCAL_NETWORK),
|
||||
REQUEST_LOCAL_NETWORK
|
||||
)
|
||||
pendingConnection = ConnectionRequest(host, port, user, pass)
|
||||
status.text = "Menunggu izin jaringan lokal…"
|
||||
return
|
||||
}
|
||||
|
||||
startSsh(host, port, user, pass)
|
||||
}
|
||||
|
||||
private data class ConnectionRequest(val host: String, val port: Int, val user: String, val pass: String)
|
||||
private var pendingConnection: ConnectionRequest? = null
|
||||
|
||||
private fun startSsh(host: String, port: Int, user: String, pass: String) {
|
||||
ssh.connect(host, port, user, pass, { data -> runOnUiThread { terminal.feed(data) } }, { s -> runOnUiThread { status.text = s } })
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
if (requestCode == REQUEST_LOCAL_NETWORK) {
|
||||
val request = pendingConnection
|
||||
pendingConnection = null
|
||||
if (grantResults.firstOrNull() == PackageManager.PERMISSION_GRANTED && request != null) {
|
||||
startSsh(request.host, request.port, request.user, request.pass)
|
||||
} else {
|
||||
status.text = "Izin jaringan lokal ditolak"
|
||||
Toast.makeText(this, "KosSSH membutuhkan izin jaringan lokal untuk koneksi SSH LAN.", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showCtrlDialog() {
|
||||
val letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
AlertDialog.Builder(this).setTitle("CTRL + …").setItems(letters.map { "Ctrl + $it" }.toTypedArray()) { _, which -> terminal.sendCtrl(letters[which]) }.show()
|
||||
|
||||
Reference in New Issue
Block a user