-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance UI & add apps search feature
- Loading branch information
1 parent
e3fec0f
commit ca8fb29
Showing
135 changed files
with
1,209 additions
and
671 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 37 additions & 12 deletions
49
app/src/main/java/com/ismartcoding/plain/receivers/PlugInControlReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,47 @@ | ||
package com.ismartcoding.plain.receivers | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.IntentFilter | ||
import com.ismartcoding.lib.channel.sendEvent | ||
import com.ismartcoding.lib.helpers.CoroutinesHelper.coIO | ||
import com.ismartcoding.lib.isTPlus | ||
import com.ismartcoding.lib.logcat.LogCat | ||
import com.ismartcoding.plain.data.preference.KeepAwakePreference | ||
import com.ismartcoding.plain.features.AcquireWakeLockEvent | ||
import com.ismartcoding.plain.features.ReleaseWakeLockEvent | ||
|
||
object PlugInControlReceiver { | ||
private const val ACTION_USB_STATE = "android.hardware.usb.action.USB_STATE" | ||
class PlugInControlReceiver : BroadcastReceiver() { | ||
override fun onReceive(context: Context, intent: Intent) { | ||
val action = intent.action | ||
if (action == Intent.ACTION_POWER_CONNECTED) { | ||
LogCat.d("ACTION_POWER_CONNECTED") | ||
sendEvent(AcquireWakeLockEvent()) | ||
} else if (action == Intent.ACTION_POWER_DISCONNECTED) { | ||
LogCat.d("ACTION_POWER_DISCONNECTED") | ||
coIO { | ||
val keepAwake = KeepAwakePreference.getAsync(context) | ||
if (!keepAwake) { | ||
sendEvent(ReleaseWakeLockEvent()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun isUSBConnected(context: Context): Boolean { | ||
val intent = if (isTPlus()) { | ||
context.registerReceiver( | ||
null, | ||
IntentFilter(ACTION_USB_STATE), | ||
Context.RECEIVER_NOT_EXPORTED, | ||
) | ||
} else { | ||
context.registerReceiver(null, IntentFilter(ACTION_USB_STATE)) | ||
companion object { | ||
private const val ACTION_USB_STATE = "android.hardware.usb.action.USB_STATE" | ||
fun isUSBConnected(context: Context): Boolean { | ||
val intent = if (isTPlus()) { | ||
context.registerReceiver( | ||
null, | ||
IntentFilter(ACTION_USB_STATE), | ||
Context.RECEIVER_NOT_EXPORTED, | ||
) | ||
} else { | ||
context.registerReceiver(null, IntentFilter(ACTION_USB_STATE)) | ||
} | ||
return intent?.extras?.getBoolean("connected") == true | ||
} | ||
return intent?.extras?.getBoolean("connected") == true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.