Skip to content

Commit

Permalink
google/accompanist#1162 sample project. Click Screen2 in drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
polivmi1 committed Jul 12, 2022
0 parents commit 3c36dfb
Show file tree
Hide file tree
Showing 37 changed files with 999 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*.iml
.gradle
gradle.properties
/local.properties
/.idea/workspace.xml
/.idea/libraries
/.idea/misc.xml
/.idea/modules.xml
/.idea/gradle.xml
/.idea/jarRepositories.xml
/.idea/navEditor.xml
/.idea/shelf
/app/schemas/**/**
.DS_Store
**/build/**
/captures
**/**/*.apk
/app/production
/fastlane/report.xml
/firebase_app_distribution
/.idea/deploymentTargetDropDown.xml
/bundletool_temp/bundletool.jar
/app/jacoco.exec
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
77 changes: 77 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'com.google.devtools.ksp' version '1.7.0-1.0.6'
}

android {
compileSdk 32

defaultConfig {
applicationId "com.example.sample1162"
minSdk 23
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
//freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion "1.2.0"
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}

applicationVariants.all { variant ->
kotlin.sourceSets {
getByName(variant.name) {
kotlin.srcDir("build/generated/ksp/${variant.name}/kotlin")
}
}
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation 'com.google.android.material:material:1.6.1'
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.material:material:$compose_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
implementation "io.github.raamcosta.compose-destinations:animations-core:1.6.13-beta"
implementation 'com.google.devtools.ksp:symbol-processing-api:1.7.0-1.0.6'
ksp 'io.github.raamcosta.compose-destinations:ksp:1.6.13-beta'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.sample1162

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.sample1162", appContext.packageName)
}
}
29 changes: 29 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.sample1162">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Sample1162"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Sample1162">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
61 changes: 61 additions & 0 deletions app/src/main/java/com/example/sample1162/AppScreenViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.example.sample1162

import android.os.Parcelable
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import java.util.*


open class OEffect {
val id: Long = UUID.randomUUID().mostSignificantBits

override fun toString(): String {
return this.javaClass.name.replaceBeforeLast('$',"").substring(1)
}
}

class AppScreenViewModel : ViewModel() {

private val _state = MutableStateFlow(State())
val state = _state.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), _state.value)

@Parcelize
data class State(
val effects: List<Effect> = emptyList(),
) : Parcelable

@Parcelize
sealed class Effect: OEffect(), Parcelable {
data class Navigate(val route: String) : Effect()
}

sealed class Event {
data class DrawerItemClicked(val route: String) : Event()
data class EffectHandled(val effect: Effect) : Event()
}

fun event(event: Event) {

when (event) {
is Event.DrawerItemClicked -> onDrawerItemClicked(event.route)
is Event.EffectHandled -> onEffectHandled(event.effect.id)
}
}

private fun onEffectHandled(id: Long) {
_state.update {
val effects = it.effects.filterNot { effect -> effect.id == id }
it.copy(effects = effects)
}
}

private fun onDrawerItemClicked(route: String) = viewModelScope.launch {
_state.update { it.copy(effects = it.effects + Effect.Navigate(route = route)) }
}
}
Loading

0 comments on commit 3c36dfb

Please sign in to comment.