Skip to content

Commit

Permalink
Refactoring UI models module (#2428)
Browse files Browse the repository at this point in the history
* create audio-ui-model module
  • Loading branch information
niting1112 authored Oct 18, 2024
1 parent b84e513 commit bde87db
Show file tree
Hide file tree
Showing 48 changed files with 811 additions and 508 deletions.
55 changes: 55 additions & 0 deletions media/audio-ui-model/api/current.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Signature format: 4.0
package com.google.android.horologist.audio.ui {

public final class VolumeUiState {
ctor public VolumeUiState(optional int current, optional int max, optional int min);
method public int component1();
method public int component2();
method public int component3();
method public com.google.android.horologist.audio.ui.VolumeUiState copy(int current, int max, int min);
method public int getCurrent();
method public int getMax();
method public int getMin();
method public boolean isMax();
method public boolean isMin();
property public final int current;
property public final boolean isMax;
property public final boolean isMin;
property public final int max;
property public final int min;
}

@com.google.android.horologist.annotations.ExperimentalHorologistApi public class VolumeViewModel extends androidx.lifecycle.ViewModel {
ctor public VolumeViewModel(com.google.android.horologist.audio.VolumeRepository volumeRepository, com.google.android.horologist.audio.AudioOutputRepository audioOutputRepository, optional kotlin.jvm.functions.Function0<kotlin.Unit> onCleared, android.os.Vibrator vibrator);
method public final void decreaseVolume();
method public final void decreaseVolumeWithHaptics();
method public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.AudioOutput> getAudioOutput();
method public final kotlinx.coroutines.flow.Flow<kotlin.Unit> getDisplayIndicatorEvents();
method public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.ui.VolumeUiState> getVolumeUiState();
method public final void increaseVolume();
method public final void increaseVolumeWithHaptics();
method public final void launchOutputSelection();
method public final void onVolumeChangeByScroll(float pixels);
method public final void setVolume(int volume);
property public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.AudioOutput> audioOutput;
property public final kotlinx.coroutines.flow.Flow<kotlin.Unit> displayIndicatorEvents;
property public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.ui.VolumeUiState> volumeUiState;
field public static final com.google.android.horologist.audio.ui.VolumeViewModel.Companion Companion;
}

@com.google.android.horologist.annotations.ExperimentalHorologistApi public static final class VolumeViewModel.Companion {
method public androidx.lifecycle.ViewModelProvider.Factory getFactory();
property public final androidx.lifecycle.ViewModelProvider.Factory Factory;
}

}

package com.google.android.horologist.audio.ui.mapper {

public final class VolumeUiStateMapper {
method public com.google.android.horologist.audio.ui.VolumeUiState map(com.google.android.horologist.audio.VolumeState volumeState);
field public static final com.google.android.horologist.audio.ui.mapper.VolumeUiStateMapper INSTANCE;
}

}

106 changes: 106 additions & 0 deletions media/audio-ui-model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("com.android.library")
alias(libs.plugins.dokka)
alias(libs.plugins.metalavaGradle)
kotlin("android")
alias(libs.plugins.roborazzi)
alias(libs.plugins.compose.compiler)
}

android {
compileSdk = 35

defaultConfig {
minSdk = 26
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

buildFeatures {
buildConfig = false
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.majorVersion
freeCompilerArgs = freeCompilerArgs + "-opt-in=com.google.android.horologist.annotations.ExperimentalHorologistApi"
}

packaging {
resources {
excludes +=
listOf(
"/META-INF/AL2.0",
"/META-INF/LGPL2.1",
)
}
}

testOptions {
unitTests {
isIncludeAndroidResources = true
}
animationsDisabled = true
}

sourceSets.getByName("main") {
assets.srcDir("src/main/assets")
}

lint {
disable += listOf("MissingTranslation", "ExtraTranslation")
checkReleaseBuilds = false
textReport = true
}

namespace = "com.google.android.horologist.audio.ui.model"
}

project.tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
// Workaround for https://youtrack.jetbrains.com/issue/KT-37652
if (!this.name.endsWith("TestKotlin") && !this.name.startsWith("compileDebug")) {
compilerOptions {
freeCompilerArgs.add("-Xexplicit-api=strict")
}
}
}

metalava {
sourcePaths.setFrom("src/main")
filename.set("api/current.api")
reportLintsAsErrors.set(true)
}

dependencies {
api(projects.media.audio)
implementation(libs.androidx.lifecycle.viewmodel.compose)
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTaskPartial>().configureEach {
dokkaSourceSets {
configureEach {
moduleName.set("media-audio-ui-model")
}
}
}

apply(plugin = "com.vanniktech.maven.publish")
9 changes: 9 additions & 0 deletions media/audio-ui-model/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.google.android.horologist.audio.ui.model">

<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.VIBRATE" />

<uses-sdk android:minSdkVersion="26" tools:ignore="GradleOverrides" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
50 changes: 0 additions & 50 deletions media/audio-ui/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,6 @@ package com.google.android.horologist.audio.ui {
method @androidx.compose.runtime.Composable public static void VolumeWithLabelScreen(kotlin.jvm.functions.Function0<com.google.android.horologist.audio.ui.VolumeUiState> volume, kotlin.jvm.functions.Function0<kotlin.Unit> increaseVolume, kotlin.jvm.functions.Function0<kotlin.Unit> decreaseVolume, optional androidx.compose.ui.Modifier modifier, optional kotlin.jvm.functions.Function0<kotlin.Unit> increaseIcon, optional kotlin.jvm.functions.Function0<kotlin.Unit> decreaseIcon, optional boolean showVolumeIndicator, optional long volumeColor);
}

public final class VolumeUiState {
ctor public VolumeUiState(optional int current, optional int max, optional int min);
method public int component1();
method public int component2();
method public int component3();
method public com.google.android.horologist.audio.ui.VolumeUiState copy(int current, int max, int min);
method public int getCurrent();
method public int getMax();
method public int getMin();
method public boolean isMax();
method public boolean isMin();
property public final int current;
property public final boolean isMax;
property public final boolean isMin;
property public final int max;
property public final int min;
}

@com.google.android.horologist.annotations.ExperimentalHorologistApi public class VolumeViewModel extends androidx.lifecycle.ViewModel {
ctor public VolumeViewModel(com.google.android.horologist.audio.VolumeRepository volumeRepository, com.google.android.horologist.audio.AudioOutputRepository audioOutputRepository, optional kotlin.jvm.functions.Function0<kotlin.Unit> onCleared, android.os.Vibrator vibrator);
method public final void decreaseVolume();
method public final void decreaseVolumeWithHaptics();
method public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.AudioOutput> getAudioOutput();
method public final kotlinx.coroutines.flow.Flow<kotlin.Unit> getDisplayIndicatorEvents();
method public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.ui.VolumeUiState> getVolumeUiState();
method public final void increaseVolume();
method public final void increaseVolumeWithHaptics();
method public final void launchOutputSelection();
method public final void onVolumeChangeByScroll(float pixels);
method public final void setVolume(int volume);
property public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.AudioOutput> audioOutput;
property public final kotlinx.coroutines.flow.Flow<kotlin.Unit> displayIndicatorEvents;
property public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.ui.VolumeUiState> volumeUiState;
field public static final com.google.android.horologist.audio.ui.VolumeViewModel.Companion Companion;
}

@com.google.android.horologist.annotations.ExperimentalHorologistApi public static final class VolumeViewModel.Companion {
method public androidx.lifecycle.ViewModelProvider.Factory getFactory();
property public final androidx.lifecycle.ViewModelProvider.Factory Factory;
}

}

package com.google.android.horologist.audio.ui.components {
Expand Down Expand Up @@ -137,12 +96,3 @@ package com.google.android.horologist.audio.ui.components.animated {

}

package com.google.android.horologist.audio.ui.mapper {

public final class VolumeUiStateMapper {
method public com.google.android.horologist.audio.ui.VolumeUiState map(com.google.android.horologist.audio.VolumeState volumeState);
field public static final com.google.android.horologist.audio.ui.mapper.VolumeUiStateMapper INSTANCE;
}

}

1 change: 1 addition & 0 deletions media/audio-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ dependencies {
implementation(projects.composeLayout)
implementation(projects.composeMaterial)
implementation(project(":composables"))
implementation(projects.media.audioUiModel)
debugImplementation(projects.logo)

api(libs.wearcompose.material)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions media/sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ dependencies {

implementation(libs.moshi.adapters)
implementation(libs.moshi.kotlin)
implementation(projects.media.audioUiModel)
implementation(projects.media.uiModel)
testImplementation(projects.media.audioUiModel)
ksp(libs.moshi.kotlin.codegen)
implementation(libs.kotlinx.serialization.core)

Expand Down
2 changes: 2 additions & 0 deletions media/sample/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
# Keep all classes annotated with @Serializable
-keep @kotlinx.serialization.Serializable class ** { *; }
Loading

0 comments on commit bde87db

Please sign in to comment.