Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit 4e27c9f

Browse files
authored
feat: swipe-controls (#50)
1 parent a1ecb48 commit 4e27c9f

27 files changed

Lines changed: 835 additions & 925 deletions

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'org.jetbrains.kotlin.android'
23

34
android {
45
compileSdkVersion 32
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package app.revanced.integrations.fenster
2+
3+
import app.revanced.integrations.settings.SettingsEnum
4+
5+
/**
6+
* controls fenster feature enablement
7+
*/
8+
object FensterEnablement {
9+
10+
/**
11+
* should fenster be enabled? (global setting)
12+
*/
13+
val shouldEnableFenster: Boolean
14+
get() {
15+
return shouldEnableFensterVolumeControl || shouldEnableFensterBrightnessControl
16+
}
17+
18+
/**
19+
* should swipe controls for volume be enabled?
20+
*/
21+
val shouldEnableFensterVolumeControl: Boolean
22+
get() {
23+
return SettingsEnum.ENABLE_SWIPE_VOLUME_BOOLEAN.boolean
24+
}
25+
26+
/**
27+
* should swipe controls for volume be enabled?
28+
*/
29+
val shouldEnableFensterBrightnessControl: Boolean
30+
get() {
31+
return SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.boolean
32+
}
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package app.revanced.integrations.fenster
2+
3+
/**
4+
* WatchWhile player types
5+
*/
6+
@Suppress("unused")
7+
enum class WatchWhilePlayerType {
8+
NONE,
9+
HIDDEN,
10+
WATCH_WHILE_MINIMIZED,
11+
WATCH_WHILE_MAXIMIZED,
12+
WATCH_WHILE_FULLSCREEN,
13+
WATCH_WHILE_SLIDING_MAXIMIZED_FULLSCREEN,
14+
WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED,
15+
WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED,
16+
WATCH_WHILE_SLIDING_FULLSCREEN_DISMISSED,
17+
INLINE_MINIMAL,
18+
VIRTUAL_REALITY_FULLSCREEN,
19+
WATCH_WHILE_PICTURE_IN_PICTURE;
20+
21+
companion object {
22+
@JvmStatic
23+
fun safeParseFromString(name: String): WatchWhilePlayerType? {
24+
return values().firstOrNull { it.name == name }
25+
}
26+
}
27+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package app.revanced.integrations.fenster.controllers
2+
3+
import android.content.Context
4+
import android.media.AudioManager
5+
import android.os.Build
6+
import app.revanced.integrations.fenster.util.clamp
7+
import app.revanced.integrations.utils.LogHelper
8+
import kotlin.properties.Delegates
9+
10+
/**
11+
* controller to adjust the device volume level
12+
*
13+
* @param context the context to bind the audio service in
14+
* @param targetStream the stream that is being controlled. Must be one of the STREAM_* constants in [AudioManager]
15+
*/
16+
class AudioVolumeController(
17+
context: Context,
18+
private val targetStream: Int = AudioManager.STREAM_MUSIC
19+
) {
20+
21+
/**
22+
* audio service connection
23+
*/
24+
private lateinit var audioManager: AudioManager
25+
private var minimumVolumeIndex by Delegates.notNull<Int>()
26+
private var maximumVolumeIndex by Delegates.notNull<Int>()
27+
28+
init {
29+
// bind audio service
30+
val mgr = context.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
31+
if (mgr == null) {
32+
LogHelper.debug(this.javaClass, "failed to acquire AUDIO_SERVICE")
33+
} else {
34+
audioManager = mgr
35+
maximumVolumeIndex = audioManager.getStreamMaxVolume(targetStream)
36+
minimumVolumeIndex =
37+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) audioManager.getStreamMinVolume(
38+
targetStream
39+
) else 0
40+
}
41+
}
42+
43+
/**
44+
* the current volume, ranging from 0.0 to [maxVolume]
45+
*/
46+
var volume: Int
47+
get() {
48+
// check if initialized correctly
49+
if (!this::audioManager.isInitialized) return 0
50+
51+
// get current volume
52+
return currentVolumeIndex - minimumVolumeIndex
53+
}
54+
set(value) {
55+
// check if initialized correctly
56+
if (!this::audioManager.isInitialized) return
57+
58+
// set new volume
59+
currentVolumeIndex =
60+
(value + minimumVolumeIndex).clamp(minimumVolumeIndex, maximumVolumeIndex)
61+
}
62+
63+
/**
64+
* the maximum possible volume
65+
*/
66+
val maxVolume: Int
67+
get() = maximumVolumeIndex - minimumVolumeIndex
68+
69+
/**
70+
* the current volume index of the target stream
71+
*/
72+
private var currentVolumeIndex: Int
73+
get() = audioManager.getStreamVolume(targetStream)
74+
set(value) = audioManager.setStreamVolume(targetStream, value, 0)
75+
}

0 commit comments

Comments
 (0)