Loading app/src/main/java/it/lavermicocca/giacomo/beautifulnotification/HelperMessages.kt +7 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments class HelperMessages{ enum class STATUS { UNKNOWN, TIMEOUT, GARAGE_OPEN, GARAGE_CLOSE } enum class STATUS { UNKNOWN, TIMEOUT, GARAGE_OPEN, GARAGE_CLOSE, BRIGHTNESS } fun Do(messaggio: String) : STATUS{ when(messaggio) Loading @@ -23,6 +23,12 @@ class HelperMessages{ return STATUS.TIMEOUT } } if(messaggio.contains("L.C. : b ")) { return STATUS.BRIGHTNESS } return STATUS.UNKNOWN } } No newline at end of file app/src/main/java/it/lavermicocca/giacomo/beautifulnotification/Sender.kt +38 −46 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import android.widget.Toast import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments import it.lavermicocca.giacomo.beautifulnotification.services.Helper import okhttp3.* import unsigned.Ubyte import java.io.IOException class Sender(val context: Context) { Loading Loading @@ -100,13 +101,13 @@ class Sender(val context: Context) { } //UNO fun SendPinPortone() { Helper.StartForegroundServiceNotification(context, "PORTONE IN APERTURA...", Helper.FULL_ON) fun SendBrightness(brightness: Int) { Helper.StartForegroundServiceNotification(context, "ACCENDO LUCE con INTENSITA : $brightness", Helper.FULL_ON) val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE) val ipServer = prf.getString("ip_server_portone", "192.168.43.176") val url = "http://$ipServer/on" val ipServer = prf.getString("ip_server", "192.168.43.176") val url = "http://$ipServer/brightness/$brightness" val request = okhttp3.Request.Builder() .url(url) Loading @@ -116,8 +117,6 @@ class Sender(val context: Context) { val client = OkHttpClient() Helper.StartForegroundServiceNotification(context, "PORTONE", Helper.FULL_ON) client.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call, e: IOException) { e.printStackTrace() Loading @@ -126,30 +125,33 @@ class Sender(val context: Context) { @Throws(IOException::class) override fun onResponse(call: Call, response: Response) { Helper.StartForegroundServiceNotification(context, "PORTONE APERTO", Helper.FULL_ON) // val networkResp = response.body()!!.string() // var looper = Looper.getMainLooper() // // Handler(looper).post(object :Runnable{ // override fun run() { // //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. // //Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show() // // } // }) val networkResp = response.body()!!.string() var looper = Looper.getMainLooper() Handler(looper).post(object :Runnable{ override fun run() { //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show() if(networkResp.contains(Arguments.PIN, true)) { Log.e("TTAG", "RICHIESTA PIN") SendCheck(false) } } }) } }) } //UNO fun SendGPIO(pin: Int) { fun SendPinPortone() { Helper.StartForegroundServiceNotification(context, "PORTONE IN APERTURA...", Helper.FULL_ON) val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE) val ipServer = prf.getString("ip_server", "192.168.43.176") val url = "http://$ipServer/gpio/$pin" val ipServer = prf.getString("ip_server_portone", "192.168.43.176") val url = "http://$ipServer/on" val request = okhttp3.Request.Builder() .url(url) Loading @@ -159,6 +161,8 @@ class Sender(val context: Context) { val client = OkHttpClient() Helper.StartForegroundServiceNotification(context, "PORTONE", Helper.FULL_ON) client.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call, e: IOException) { e.printStackTrace() Loading @@ -167,30 +171,25 @@ class Sender(val context: Context) { @Throws(IOException::class) override fun onResponse(call: Call, response: Response) { val networkResp = response.body()!!.string() var looper = Looper.getMainLooper() Helper.StartForegroundServiceNotification(context, "PORTONE APERTO", Helper.FULL_ON) // val networkResp = response.body()!!.string() // var looper = Looper.getMainLooper() // // Handler(looper).post(object :Runnable{ // override fun run() { // //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. // //Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show() // // } // }) Handler(looper).post(object :Runnable{ override fun run() { //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show() if(networkResp.contains(Arguments.GPIO, true)) { Log.e("TTAG", "RICHIESTA GPIO") Helper.StartForegroundServiceNotification(context, "PORTONE OPEN", Helper.FULL_ON) } else { Helper.StartForegroundServiceNotification(context, "ERRORE NEI MESSAGGI RADIO", Helper.FULL_ON) } } }) } }) } //DUE fun SendCheck(oneShot:Boolean) { //Thread.sleep(1000); Thread.sleep(1000); val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE) val ipServer = prf.getString("ip_server", "192.168.43.176") Loading @@ -216,7 +215,7 @@ class Sender(val context: Context) { var status:HelperMessages.STATUS = HelperMessages().Do(networkResp) if(status == HelperMessages.STATUS.TIMEOUT) { Helper.StartForegroundServiceNotification(context, "ERRORE DI TIMEOUT", Helper.FULL_ON_STOP_PROGRESS) Helper.StartForegroundServiceNotification(context, "TIMEOUT su CHECK", Helper.FULL_ON_STOP_PROGRESS) } else if(status == HelperMessages.STATUS.GARAGE_CLOSE) { Helper.StartForegroundServiceNotification(context, "GARAGE OPEN", Helper.FULL_ON_STOP_PROGRESS) Loading @@ -224,14 +223,7 @@ class Sender(val context: Context) { else if(status == HelperMessages.STATUS.GARAGE_OPEN) { Helper.StartForegroundServiceNotification(context, "GARAGE CLOSE", Helper.FULL_ON_STOP_PROGRESS) } else { Helper.StartForegroundServiceNotification(context, networkResp, Helper.FULL_OFF) // if(networkResp.contains("L.C. : p : ")) // // else // { // Helper.StartForegroundServiceNotification(context, "ERRORE NEI MESSAGGI RADIO", Helper.FULL_ON_STOP_PROGRESS) // return // } Helper.StartForegroundServiceNotification(context, networkResp, Helper.FULL_ON_STOP_PROGRESS) } if(!oneShot) Loading app/src/main/java/it/lavermicocca/giacomo/beautifulnotification/notifications/GenericNotificationClass.kt +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ class GenericNotificationClass(val service: Service, val text : String, val stat private val notification:Notification private val CHANNEL_ID = "media_playback_channel" enum class STATUS {none, garage, cancello, all, portone, lastCommand} enum class STATUS {none, garage, cancello, all, portone, brightness, lastCommand} init { val ns = Context.NOTIFICATION_SERVICE Loading app/src/main/java/it/lavermicocca/giacomo/beautifulnotification/notifications/SwitchButtonListener.kt +11 −0 Original line number Diff line number Diff line Loading @@ -5,8 +5,15 @@ import android.content.Context import android.content.Intent import android.util.Log import it.lavermicocca.giacomo.beautifulnotification.notifications.GenericNotificationClass import unsigned.Ubyte import unsigned.toUbyte class SwitchButtonListener : BroadcastReceiver() { companion object { var previousBrightness: Int = 250; } override fun onReceive(context: Context, intent: Intent) { var sender = Sender(context) Loading @@ -24,6 +31,10 @@ class SwitchButtonListener : BroadcastReceiver() { GenericNotificationClass.STATUS.portone -> sender.SendPinPortone() //17 GPIO pin locale GenericNotificationClass.STATUS.cancello -> sender.SendPin(17) GenericNotificationClass.STATUS.garage -> sender.SendPin(21) GenericNotificationClass.STATUS.brightness -> sender.SendBrightness(previousBrightness) } previousBrightness += 25 previousBrightness %= 250 } } Loading
app/src/main/java/it/lavermicocca/giacomo/beautifulnotification/HelperMessages.kt +7 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments class HelperMessages{ enum class STATUS { UNKNOWN, TIMEOUT, GARAGE_OPEN, GARAGE_CLOSE } enum class STATUS { UNKNOWN, TIMEOUT, GARAGE_OPEN, GARAGE_CLOSE, BRIGHTNESS } fun Do(messaggio: String) : STATUS{ when(messaggio) Loading @@ -23,6 +23,12 @@ class HelperMessages{ return STATUS.TIMEOUT } } if(messaggio.contains("L.C. : b ")) { return STATUS.BRIGHTNESS } return STATUS.UNKNOWN } } No newline at end of file
app/src/main/java/it/lavermicocca/giacomo/beautifulnotification/Sender.kt +38 −46 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import android.widget.Toast import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments import it.lavermicocca.giacomo.beautifulnotification.services.Helper import okhttp3.* import unsigned.Ubyte import java.io.IOException class Sender(val context: Context) { Loading Loading @@ -100,13 +101,13 @@ class Sender(val context: Context) { } //UNO fun SendPinPortone() { Helper.StartForegroundServiceNotification(context, "PORTONE IN APERTURA...", Helper.FULL_ON) fun SendBrightness(brightness: Int) { Helper.StartForegroundServiceNotification(context, "ACCENDO LUCE con INTENSITA : $brightness", Helper.FULL_ON) val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE) val ipServer = prf.getString("ip_server_portone", "192.168.43.176") val url = "http://$ipServer/on" val ipServer = prf.getString("ip_server", "192.168.43.176") val url = "http://$ipServer/brightness/$brightness" val request = okhttp3.Request.Builder() .url(url) Loading @@ -116,8 +117,6 @@ class Sender(val context: Context) { val client = OkHttpClient() Helper.StartForegroundServiceNotification(context, "PORTONE", Helper.FULL_ON) client.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call, e: IOException) { e.printStackTrace() Loading @@ -126,30 +125,33 @@ class Sender(val context: Context) { @Throws(IOException::class) override fun onResponse(call: Call, response: Response) { Helper.StartForegroundServiceNotification(context, "PORTONE APERTO", Helper.FULL_ON) // val networkResp = response.body()!!.string() // var looper = Looper.getMainLooper() // // Handler(looper).post(object :Runnable{ // override fun run() { // //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. // //Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show() // // } // }) val networkResp = response.body()!!.string() var looper = Looper.getMainLooper() Handler(looper).post(object :Runnable{ override fun run() { //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show() if(networkResp.contains(Arguments.PIN, true)) { Log.e("TTAG", "RICHIESTA PIN") SendCheck(false) } } }) } }) } //UNO fun SendGPIO(pin: Int) { fun SendPinPortone() { Helper.StartForegroundServiceNotification(context, "PORTONE IN APERTURA...", Helper.FULL_ON) val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE) val ipServer = prf.getString("ip_server", "192.168.43.176") val url = "http://$ipServer/gpio/$pin" val ipServer = prf.getString("ip_server_portone", "192.168.43.176") val url = "http://$ipServer/on" val request = okhttp3.Request.Builder() .url(url) Loading @@ -159,6 +161,8 @@ class Sender(val context: Context) { val client = OkHttpClient() Helper.StartForegroundServiceNotification(context, "PORTONE", Helper.FULL_ON) client.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call, e: IOException) { e.printStackTrace() Loading @@ -167,30 +171,25 @@ class Sender(val context: Context) { @Throws(IOException::class) override fun onResponse(call: Call, response: Response) { val networkResp = response.body()!!.string() var looper = Looper.getMainLooper() Helper.StartForegroundServiceNotification(context, "PORTONE APERTO", Helper.FULL_ON) // val networkResp = response.body()!!.string() // var looper = Looper.getMainLooper() // // Handler(looper).post(object :Runnable{ // override fun run() { // //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. // //Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show() // // } // }) Handler(looper).post(object :Runnable{ override fun run() { //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show() if(networkResp.contains(Arguments.GPIO, true)) { Log.e("TTAG", "RICHIESTA GPIO") Helper.StartForegroundServiceNotification(context, "PORTONE OPEN", Helper.FULL_ON) } else { Helper.StartForegroundServiceNotification(context, "ERRORE NEI MESSAGGI RADIO", Helper.FULL_ON) } } }) } }) } //DUE fun SendCheck(oneShot:Boolean) { //Thread.sleep(1000); Thread.sleep(1000); val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE) val ipServer = prf.getString("ip_server", "192.168.43.176") Loading @@ -216,7 +215,7 @@ class Sender(val context: Context) { var status:HelperMessages.STATUS = HelperMessages().Do(networkResp) if(status == HelperMessages.STATUS.TIMEOUT) { Helper.StartForegroundServiceNotification(context, "ERRORE DI TIMEOUT", Helper.FULL_ON_STOP_PROGRESS) Helper.StartForegroundServiceNotification(context, "TIMEOUT su CHECK", Helper.FULL_ON_STOP_PROGRESS) } else if(status == HelperMessages.STATUS.GARAGE_CLOSE) { Helper.StartForegroundServiceNotification(context, "GARAGE OPEN", Helper.FULL_ON_STOP_PROGRESS) Loading @@ -224,14 +223,7 @@ class Sender(val context: Context) { else if(status == HelperMessages.STATUS.GARAGE_OPEN) { Helper.StartForegroundServiceNotification(context, "GARAGE CLOSE", Helper.FULL_ON_STOP_PROGRESS) } else { Helper.StartForegroundServiceNotification(context, networkResp, Helper.FULL_OFF) // if(networkResp.contains("L.C. : p : ")) // // else // { // Helper.StartForegroundServiceNotification(context, "ERRORE NEI MESSAGGI RADIO", Helper.FULL_ON_STOP_PROGRESS) // return // } Helper.StartForegroundServiceNotification(context, networkResp, Helper.FULL_ON_STOP_PROGRESS) } if(!oneShot) Loading
app/src/main/java/it/lavermicocca/giacomo/beautifulnotification/notifications/GenericNotificationClass.kt +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ class GenericNotificationClass(val service: Service, val text : String, val stat private val notification:Notification private val CHANNEL_ID = "media_playback_channel" enum class STATUS {none, garage, cancello, all, portone, lastCommand} enum class STATUS {none, garage, cancello, all, portone, brightness, lastCommand} init { val ns = Context.NOTIFICATION_SERVICE Loading
app/src/main/java/it/lavermicocca/giacomo/beautifulnotification/notifications/SwitchButtonListener.kt +11 −0 Original line number Diff line number Diff line Loading @@ -5,8 +5,15 @@ import android.content.Context import android.content.Intent import android.util.Log import it.lavermicocca.giacomo.beautifulnotification.notifications.GenericNotificationClass import unsigned.Ubyte import unsigned.toUbyte class SwitchButtonListener : BroadcastReceiver() { companion object { var previousBrightness: Int = 250; } override fun onReceive(context: Context, intent: Intent) { var sender = Sender(context) Loading @@ -24,6 +31,10 @@ class SwitchButtonListener : BroadcastReceiver() { GenericNotificationClass.STATUS.portone -> sender.SendPinPortone() //17 GPIO pin locale GenericNotificationClass.STATUS.cancello -> sender.SendPin(17) GenericNotificationClass.STATUS.garage -> sender.SendPin(21) GenericNotificationClass.STATUS.brightness -> sender.SendBrightness(previousBrightness) } previousBrightness += 25 previousBrightness %= 250 } }