Skip to content

Commit

Permalink
amogus
Browse files Browse the repository at this point in the history
  • Loading branch information
literalEval committed Jan 21, 2023
1 parent d066b94 commit d05621f
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 10 deletions.
15 changes: 15 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:allowBackup="true"
Expand All @@ -18,6 +19,20 @@
android:theme="@style/Theme.Lomgger"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".SusActivity"
android:exported="false">
<!-- android:theme="@android:style/Theme.NoDisplay">-->
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>

<service
android:name=".SusService"
android:enabled="true"
android:exported="true"></service>

<activity
android:name=".SusServices"
android:exported="true"
Expand Down
25 changes: 19 additions & 6 deletions app/src/main/java/org/cheems/lomgger/AmogusTileService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.graphics.drawable.Icon
import android.net.wifi.WifiManager
import android.os.Build
import android.os.IBinder
import android.preference.PreferenceManager
Expand All @@ -26,7 +27,7 @@ class AmogusTileService : TileService() {
private lateinit var susServices: SusServices

override fun onBind(intent: Intent?): IBinder? {
println("amogus\n\n\namogus\n\n\namogus\n\n\namogus")
println("amogus\n\n\namogus tile bind\n\n\namogus tile bind\n\n\namogus tile bind")
return super.onBind(intent)
}

Expand All @@ -46,7 +47,7 @@ class AmogusTileService : TileService() {
}
}

else {
else if (qsTile.state == Tile.STATE_INACTIVE) {
val res = GlobalScope.launch {
susServices.tryLogin()
}
Expand Down Expand Up @@ -81,10 +82,18 @@ class AmogusTileService : TileService() {
susServices = SusServices()
susServices.loadCreds(applicationContext)

qsTile.label = "Fetching"
qsTile.state = Tile.STATE_UNAVAILABLE

if (!susServices.isSetup) {
qsTile.label = "Setup"
} else if (!getWifiStatus()) {
qsTile.label = "WiFi Off"
} else {
qsTile.label = "Checking"
getLoginStatus()
}

qsTile.updateTile()
getLoginStatus()
}

override fun onStopListening() {
Expand All @@ -93,11 +102,15 @@ class AmogusTileService : TileService() {
// Called when the tile is no longer visible
}

fun getLoginStatus() {
private fun getWifiStatus(): Boolean {
val wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
return wifiManager.isWifiEnabled
}

private fun getLoginStatus() {
val res = GlobalScope.async {
try {
return@async susServices.getLoginStatus()
// return@async true
} catch (e: Error) {
println(e)
return@async false
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/org/cheems/lomgger/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.cheems.lomgger

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
Expand All @@ -17,7 +16,6 @@ import androidx.compose.material.icons.rounded.PlayArrow
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -28,7 +26,6 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.get
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.cheems.lomgger.ui.theme.LoggerChanTheme
Expand Down Expand Up @@ -158,8 +155,12 @@ class MainActivity : ComponentActivity() {
userTextState.value.text,
passTextState.value.text,
)
}
)

// amogusViewModel.getLoginStatus()
AmogusButton(
onClick = {
amogusViewModel.tryConnectWifi()
}
)
}
Expand Down
45 changes: 45 additions & 0 deletions app/src/main/java/org/cheems/lomgger/SusActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.cheems.lomgger

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.wifi.WifiManager
import android.os.Build
import android.os.Bundle
import android.provider.Settings

class SusActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
tryConnectWifi()
}

private fun tryConnectWifi() {
val wifiManager = getSystemService(Context.WIFI_SERVICE) as WifiManager

if(!wifiManager.isWifiEnabled) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val wifiIntent = Intent(Settings.Panel.ACTION_WIFI)
startActivityForResult(wifiIntent, 1)
} else {
val wifiIntent = Intent(Settings.ACTION_WIFI_SETTINGS)
startActivityForResult(wifiIntent, 1)
}

// return false
}

// return true
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

println("Activity $requestCode resulted $resultCode with data $data")
finishActivity(0)
}

fun tryToggleWifi() {

}
}
14 changes: 14 additions & 0 deletions app/src/main/java/org/cheems/lomgger/SusService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.cheems.lomgger

import android.app.Service
import android.content.Intent
import android.os.IBinder

class SusService : Service() {

override fun onBind(intent: Intent): IBinder {
TODO("Return the communication channel to the service.")


}
}
11 changes: 11 additions & 0 deletions app/src/main/java/org/cheems/lomgger/SusServices.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.net.Uri
import android.net.wifi.WifiManager
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.core.content.ContextCompat.startActivity
import kotlinx.coroutines.Dispatchers
Expand All @@ -27,6 +28,7 @@ class SusServices {
private var authToken: String? = null
private var logginIn: Boolean = false
private var loggingOut: Boolean = false
var isSetup: Boolean = false

fun saveCreds(context: Context, usr: String, pass: String): Boolean {
this.usr = usr
Expand All @@ -48,6 +50,8 @@ class SusServices {
this.usr = sharedPreference.getString("usr", null)
this.pass = sharedPreference.getString("pass", null)

isSetup = usr != null && usr!!.isNotEmpty() && pass != null && pass!!.isNotEmpty()
println("Is Setup ? $isSetup")
return arrayOf(usr, pass)
}

Expand All @@ -65,6 +69,9 @@ class SusServices {
}

fun tryConnectWifi(context: Context) {
// tryToggleWifi(context)
// return

if (tryToggleWifi(context) && tryConnectToNetwork()) {
GlobalScope.launch {
tryLogout()
Expand Down Expand Up @@ -105,6 +112,10 @@ class SusServices {
private fun tryToggleWifi(context: Context): Boolean {
// TODO: Implement startActivityForResult properly

// val intent = Intent(context, SusActivity::class.java)
// startActivity(context, intent, null)
// return true

val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager

if(!wifiManager.isWifiEnabled) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
<string name="image_view_item_transform_content_description">Represents an image view in the
item
</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>

0 comments on commit d05621f

Please sign in to comment.