This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
835 additions
and
925 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
33 changes: 33 additions & 0 deletions
33
app/src/main/java/app/revanced/integrations/fenster/FensterEnablement.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,33 @@ | ||
package app.revanced.integrations.fenster | ||
|
||
import app.revanced.integrations.settings.SettingsEnum | ||
|
||
/** | ||
* controls fenster feature enablement | ||
*/ | ||
object FensterEnablement { | ||
|
||
/** | ||
* should fenster be enabled? (global setting) | ||
*/ | ||
val shouldEnableFenster: Boolean | ||
get() { | ||
return shouldEnableFensterVolumeControl || shouldEnableFensterBrightnessControl | ||
} | ||
|
||
/** | ||
* should swipe controls for volume be enabled? | ||
*/ | ||
val shouldEnableFensterVolumeControl: Boolean | ||
get() { | ||
return SettingsEnum.ENABLE_SWIPE_VOLUME_BOOLEAN.boolean | ||
} | ||
|
||
/** | ||
* should swipe controls for volume be enabled? | ||
*/ | ||
val shouldEnableFensterBrightnessControl: Boolean | ||
get() { | ||
return SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.boolean | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/app/revanced/integrations/fenster/WatchWhilePlayerType.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,27 @@ | ||
package app.revanced.integrations.fenster | ||
|
||
/** | ||
* WatchWhile player types | ||
*/ | ||
@Suppress("unused") | ||
enum class WatchWhilePlayerType { | ||
NONE, | ||
HIDDEN, | ||
WATCH_WHILE_MINIMIZED, | ||
WATCH_WHILE_MAXIMIZED, | ||
WATCH_WHILE_FULLSCREEN, | ||
WATCH_WHILE_SLIDING_MAXIMIZED_FULLSCREEN, | ||
WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED, | ||
WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED, | ||
WATCH_WHILE_SLIDING_FULLSCREEN_DISMISSED, | ||
INLINE_MINIMAL, | ||
VIRTUAL_REALITY_FULLSCREEN, | ||
WATCH_WHILE_PICTURE_IN_PICTURE; | ||
|
||
companion object { | ||
@JvmStatic | ||
fun safeParseFromString(name: String): WatchWhilePlayerType? { | ||
return values().firstOrNull { it.name == name } | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
app/src/main/java/app/revanced/integrations/fenster/controllers/AudioVolumeController.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,75 @@ | ||
package app.revanced.integrations.fenster.controllers | ||
|
||
import android.content.Context | ||
import android.media.AudioManager | ||
import android.os.Build | ||
import app.revanced.integrations.fenster.util.clamp | ||
import app.revanced.integrations.utils.LogHelper | ||
import kotlin.properties.Delegates | ||
|
||
/** | ||
* controller to adjust the device volume level | ||
* | ||
* @param context the context to bind the audio service in | ||
* @param targetStream the stream that is being controlled. Must be one of the STREAM_* constants in [AudioManager] | ||
*/ | ||
class AudioVolumeController( | ||
context: Context, | ||
private val targetStream: Int = AudioManager.STREAM_MUSIC | ||
) { | ||
|
||
/** | ||
* audio service connection | ||
*/ | ||
private lateinit var audioManager: AudioManager | ||
private var minimumVolumeIndex by Delegates.notNull<Int>() | ||
private var maximumVolumeIndex by Delegates.notNull<Int>() | ||
|
||
init { | ||
// bind audio service | ||
val mgr = context.getSystemService(Context.AUDIO_SERVICE) as? AudioManager | ||
if (mgr == null) { | ||
LogHelper.debug(this.javaClass, "failed to acquire AUDIO_SERVICE") | ||
} else { | ||
audioManager = mgr | ||
maximumVolumeIndex = audioManager.getStreamMaxVolume(targetStream) | ||
minimumVolumeIndex = | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) audioManager.getStreamMinVolume( | ||
targetStream | ||
) else 0 | ||
} | ||
} | ||
|
||
/** | ||
* the current volume, ranging from 0.0 to [maxVolume] | ||
*/ | ||
var volume: Int | ||
get() { | ||
// check if initialized correctly | ||
if (!this::audioManager.isInitialized) return 0 | ||
|
||
// get current volume | ||
return currentVolumeIndex - minimumVolumeIndex | ||
} | ||
set(value) { | ||
// check if initialized correctly | ||
if (!this::audioManager.isInitialized) return | ||
|
||
// set new volume | ||
currentVolumeIndex = | ||
(value + minimumVolumeIndex).clamp(minimumVolumeIndex, maximumVolumeIndex) | ||
} | ||
|
||
/** | ||
* the maximum possible volume | ||
*/ | ||
val maxVolume: Int | ||
get() = maximumVolumeIndex - minimumVolumeIndex | ||
|
||
/** | ||
* the current volume index of the target stream | ||
*/ | ||
private var currentVolumeIndex: Int | ||
get() = audioManager.getStreamVolume(targetStream) | ||
set(value) = audioManager.setStreamVolume(targetStream, value, 0) | ||
} |
Oops, something went wrong.