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

Commit

Permalink
feat: swipe-controls (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow578 authored Jul 5, 2022
1 parent a1ecb48 commit 4e27c9f
Show file tree
Hide file tree
Showing 27 changed files with 835 additions and 925 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'

android {
compileSdkVersion 32
Expand Down
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
}
}
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 }
}
}
}
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)
}
Loading

0 comments on commit 4e27c9f

Please sign in to comment.