-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setting for external display override
- Closes #34 - Requires further testing - Should work on supported Retroid devices
- Loading branch information
1 parent
66a9fc7
commit c051961
Showing
5 changed files
with
316 additions
and
11 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
76 changes: 76 additions & 0 deletions
76
app/src/main/java/de/langerhans/odintools/tools/VideoOutputReceiver.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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package de.langerhans.odintools.tools | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Handler | ||
import android.os.Looper | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import de.langerhans.odintools.data.SharedPrefsRepo | ||
import de.langerhans.odintools.models.ControllerStyle | ||
import de.langerhans.odintools.models.L2R2Style | ||
import de.langerhans.odintools.service.ForegroundAppWatcherService.Companion.OVERRIDE_DELAY | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class VideoOutputReceiver : BroadcastReceiver() { | ||
|
||
private var overrideEnabled = false | ||
private var savedControllerStyle: ControllerStyle? = null | ||
private var savedL2R2Style: L2R2Style? = null | ||
|
||
@Inject | ||
lateinit var executor: ShellExecutor | ||
|
||
@Inject | ||
lateinit var prefs: SharedPrefsRepo | ||
|
||
private fun handleEvent(connected: Boolean?) { | ||
if (connected == true && !overrideEnabled) { | ||
// Save default styles | ||
savedControllerStyle = ControllerStyle.getStyle(executor) | ||
savedL2R2Style = L2R2Style.getStyle(executor) | ||
|
||
// Apply style profile | ||
ControllerStyle.getById(prefs.videoOutputControllerStyle).takeIf { | ||
it != ControllerStyle.Unknown | ||
}?.enable(executor) | ||
L2R2Style.getById(prefs.videoOutputL2R2Style).takeIf { | ||
it != L2R2Style.Unknown | ||
}?.enable(executor) | ||
|
||
overrideEnabled = true | ||
} else if (connected == false && overrideEnabled) { | ||
// Reset to defaults | ||
savedControllerStyle?.enable(executor) | ||
savedL2R2Style?.enable(executor) | ||
|
||
overrideEnabled = false | ||
} | ||
} | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
if (intent.action !in ALLOWED_INTENTS) { | ||
return | ||
} | ||
|
||
val connected = intent.extras?.getBoolean("is_connected") | ||
|
||
if (prefs.overrideDelay) { | ||
Handler(Looper.getMainLooper()).postDelayed({ handleEvent(connected) }, OVERRIDE_DELAY) | ||
} else { | ||
handleEvent(connected) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val ACTION_DP_STATUS_CHANGED = "com.retrostation.action.DP_STATUS_CHANGED" | ||
private const val ACTION_HDMI_STATUS_CHANGED = "com.retrostation.action.HDMI_STATUS_CHANGED" | ||
private const val ACTION_HDMI_OR_DP_STATUS_CHANGED = "com.retrostation.action.HDMI_OR_DP_STATUS_CHANGED" | ||
val ALLOWED_INTENTS = listOf( | ||
ACTION_DP_STATUS_CHANGED, | ||
ACTION_HDMI_STATUS_CHANGED, | ||
ACTION_HDMI_OR_DP_STATUS_CHANGED, | ||
) | ||
} | ||
} |
Oops, something went wrong.