Skip to content

Commit

Permalink
style: ktlint auto correct style for http module
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow authored Nov 22, 2022
1 parent 9a575c1 commit 56a3550
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package net.lifeupapp.lifeup.http

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -21,4 +19,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("net.lifeupapp.lifeup.http", appContext.packageName)
}
}
}
7 changes: 2 additions & 5 deletions http/src/main/java/net/lifeupapp/lifeup/http/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.lifeupapp.lifeup.http


import android.content.Intent
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -86,7 +85,6 @@ class MainActivity : AppCompatActivity() {
}
}


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (!Settings.canDrawOverlays(this)) {
binding.includeOverlayConfig.btn.setOnClickListener {
Expand All @@ -103,7 +101,7 @@ class MainActivity : AppCompatActivity() {
private fun updateLocalIpAddress() {
val localIpAddress =
getIpAddressListInLocalNetwork().filter { !it.startsWith("10.") }.joinToString {
"${it}:13276"
"$it:13276"
}
if (localIpAddress.isNotBlank()) {
binding.ipAddressText.text = getString(R.string.localIpAddressMessage, localIpAddress)
Expand All @@ -115,5 +113,4 @@ class MainActivity : AppCompatActivity() {
binding.tvAboutDesc.movementMethod = android.text.method.LinkMovementMethod.getInstance()
binding.tvAboutDesc.linksClickable = true
}

}
}
2 changes: 1 addition & 1 deletion http/src/main/java/net/lifeupapp/lifeup/http/base/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ lateinit var app: Application

@SuppressLint("StaticFieldLeak")
lateinit var appCtx: Context
private set
private set
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlin.coroutines.CoroutineContext


object AppScope : CoroutineScope {
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO + SupervisorJob() + handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ package net.lifeupapp.lifeup.http.base

import androidx.appcompat.app.AppCompatActivity

class BaseActivity : AppCompatActivity() {

}
class BaseActivity : AppCompatActivity()
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ object ConnectStatusManager {
init {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
connectivityManager.registerDefaultNetworkCallback(object :
ConnectivityManager.NetworkCallback() {
override fun onCapabilitiesChanged(
network: Network,
networkCapabilities: NetworkCapabilities
) {
Log.i("ConnectStatusManager", "onCapabilitiesChanged")
super.onCapabilitiesChanged(network, networkCapabilities)
networkChangedEvent.tryEmit(Unit)
}
})
ConnectivityManager.NetworkCallback() {
override fun onCapabilitiesChanged(
network: Network,
networkCapabilities: NetworkCapabilities
) {
Log.i("ConnectStatusManager", "onCapabilitiesChanged")
super.onCapabilitiesChanged(network, networkCapabilities)
networkChangedEvent.tryEmit(Unit)
}
})
} else {
connectivityManager.registerNetworkCallback(
NetworkRequest.Builder().build(),
Expand All @@ -46,4 +46,4 @@ object ConnectStatusManager {
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.lifeupapp.lifeup.http.service

import android.util.Log
import io.ktor.http.ContentType
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.application.call
Expand All @@ -17,7 +16,6 @@ import io.ktor.server.routing.post
import io.ktor.server.routing.routing
import io.ktor.server.websocket.WebSockets
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -98,17 +96,17 @@ object KtorService : LifeUpService {
+"GET request"
}
p {
+"http://${localAddressIp}:$port/api?url=YOUR_ENCODED_API_URL"
+"http://$localAddressIp:$port/api?url=YOUR_ENCODED_API_URL"
}
p {
+"you can send the get request to call in directly, but you need to encode the API like this: "
}
p {
a(
href = "http://${localAddressIp}:$port/api?url=lifeup%3A%2F%2Fapi%2Freward%3Ftype%3Dcoin%26content%3DCall%20LifeUp%20API%20from%20HTTP%26number%3D1",
href = "http://$localAddressIp:$port/api?url=lifeup%3A%2F%2Fapi%2Freward%3Ftype%3Dcoin%26content%3DCall%20LifeUp%20API%20from%20HTTP%26number%3D1",
target = "_blank"
) {
+"http://${localAddressIp}:$port/api?url=lifeup%3A%2F%2Fapi%2Freward%3Ftype%3Dcoin%26content%3DCall%20LifeUp%20API%20from%20HTTP%26number%3D1"
+"http://$localAddressIp:$port/api?url=lifeup%3A%2F%2Fapi%2Freward%3Ftype%3Dcoin%26content%3DCall%20LifeUp%20API%20from%20HTTP%26number%3D1"
}
}
div()
Expand All @@ -134,7 +132,7 @@ object KtorService : LifeUpService {

get("/api") {
call.request.queryParameters["url"]?.let { url ->
logger.info("Got url: ${url}")
logger.info("Got url: $url")
LifeUpApi.call(appCtx, url)
}
call.respond("success\ncheck your phone!")
Expand Down Expand Up @@ -169,7 +167,6 @@ object KtorService : LifeUpService {
_isRunning.value = LifeUpService.RunningState.NOT_RUNNING
_errorMessage.value = it
}

}
}

Expand All @@ -188,4 +185,4 @@ object KtorService : LifeUpService {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ interface LifeUpService {
fun start()

fun stop()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class ServerNotificationService : Service() {
.setOngoing(true)
.setShowWhen(false)


notificationBuilder.setContentIntent(pendingIntent)
.setContentTitle(getString(R.string.notification_channel_server))
.setSound(null)
Expand Down Expand Up @@ -96,4 +95,4 @@ class ServerNotificationService : Service() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.os.Build
import net.lifeupapp.lifeup.http.R
import net.lifeupapp.lifeup.http.base.appCtx


object NotificationChannels {
const val CHANNEL_NOTIFICATION = "net.lifeupapp.lifeup.http.server"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import android.os.Build

fun compactAndFlagImmutable(flag: Int): Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) flag or PendingIntent.FLAG_IMMUTABLE else flag
}
}
3 changes: 1 addition & 2 deletions http/src/main/java/net/lifeupapp/lifeup/http/utils/Net.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package net.lifeupapp.lifeup.http.utils

import java.net.NetworkInterface


fun getIpAddressInLocalNetwork(): String? {
val localAddresses = getIpAddressListInLocalNetwork()
return localAddresses.firstOrNull()
Expand All @@ -14,7 +13,7 @@ fun getIpAddressListInLocalNetwork(): List<String> {
it.inetAddresses.asSequence()
.filter { inetAddress ->
inetAddress.isSiteLocalAddress && !inetAddress.hostAddress.contains(":") &&
inetAddress.hostAddress != "127.0.0.1"
inetAddress.hostAddress != "127.0.0.1"
}
.map { inetAddress -> inetAddress.hostAddress }
}?.toList() ?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ fun TextView.setHtmlText(stringRes: Int) {
} else {
this.text = Html.fromHtml(context.getString(stringRes))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package net.lifeupapp.lifeup.http

import org.junit.Test

import org.junit.Assert.*
import org.junit.Test

/**
* Example local unit test, which will execute on the development machine (host).
Expand All @@ -14,4 +13,4 @@ class ExampleUnitTest {
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
}

0 comments on commit 56a3550

Please sign in to comment.