├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── themes.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── halilibo
│ │ │ │ └── schedulecalendar
│ │ │ │ ├── CalendarApplication.kt
│ │ │ │ ├── ui
│ │ │ │ └── theme
│ │ │ │ │ ├── Shape.kt
│ │ │ │ │ ├── Type.kt
│ │ │ │ │ ├── Theme.kt
│ │ │ │ │ └── Color.kt
│ │ │ │ ├── MainActivity.kt
│ │ │ │ ├── ScheduleCalendarState.kt
│ │ │ │ └── ScheduleCalendar.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── halilibo
│ │ │ └── schedulecalendar
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── halilibo
│ │ └── schedulecalendar
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle.kts
├── .idea
├── .name
├── .gitignore
├── compiler.xml
├── vcs.xml
├── deploymentTargetDropDown.xml
├── gradle.xml
├── misc.xml
├── jarRepositories.xml
└── inspectionProfiles
│ └── Project_Default.xml
├── assets
└── demo.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── settings.gradle.kts
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | ScheduleCalendar
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/assets/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/assets/demo.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Schedule Calendar Demo
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/halilozercan/compose-schedule-calendar/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Apr 29 22:38:48 TRT 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Schedule Calendar
2 |
3 | This is a demo project that showcases a horizontally laid out calendar that shows events in a timeline fashion.
4 | It is not a library, just a reference implementation for curious developers.
5 |
6 | 
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | dependencyResolutionManagement {
2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3 | repositories {
4 | google()
5 | mavenCentral()
6 | jcenter() // Warning: this repository is going to shut down soon
7 | }
8 | }
9 | rootProject.name = "ScheduleCalendar"
10 | include(":app")
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/halilibo/schedulecalendar/CalendarApplication.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar
2 |
3 | import android.app.Application
4 | import com.jakewharton.threetenabp.AndroidThreeTen
5 |
6 |
7 | class CalendarApplication : Application() {
8 | override fun onCreate() {
9 | super.onCreate()
10 | AndroidThreeTen.init(this)
11 | }
12 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/halilibo/schedulecalendar/ui/theme/Shape.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar.ui.theme
2 |
3 | import androidx.compose.foundation.shape.RoundedCornerShape
4 | import androidx.compose.material.Shapes
5 | import androidx.compose.ui.unit.dp
6 |
7 | val Shapes = Shapes(
8 | small = RoundedCornerShape(4.dp),
9 | medium = RoundedCornerShape(4.dp),
10 | large = RoundedCornerShape(0.dp)
11 | )
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/halilibo/schedulecalendar/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/halilibo/schedulecalendar/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.halilibo.schedulecalendar", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/halilibo/schedulecalendar/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar.ui.theme
2 |
3 | import androidx.compose.material.Typography
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.FontFamily
6 | import androidx.compose.ui.text.font.FontWeight
7 | import androidx.compose.ui.unit.sp
8 |
9 | // Set of Material typography styles to start with
10 | val Typography = Typography(
11 | body1 = TextStyle(
12 | fontFamily = FontFamily.Default,
13 | fontWeight = FontWeight.Normal,
14 | fontSize = 16.sp
15 | )
16 | /* Other default text styles to override
17 | button = TextStyle(
18 | fontFamily = FontFamily.Default,
19 | fontWeight = FontWeight.W500,
20 | fontSize = 14.sp
21 | ),
22 | caption = TextStyle(
23 | fontFamily = FontFamily.Default,
24 | fontWeight = FontWeight.Normal,
25 | fontSize = 12.sp
26 | )
27 | */
28 | )
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/halilibo/schedulecalendar/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar.ui.theme
2 |
3 | import androidx.compose.foundation.isSystemInDarkTheme
4 | import androidx.compose.material.MaterialTheme
5 | import androidx.compose.material.darkColors
6 | import androidx.compose.material.lightColors
7 | import androidx.compose.runtime.Composable
8 |
9 | private val DarkColorPalette = darkColors(
10 | primary = B400,
11 | primaryVariant = B400,
12 | secondary = N800,
13 | background = DN20,
14 | surface = DN40,
15 | onPrimary = N20,
16 | onSecondary = N0,
17 | onBackground = DN800,
18 | )
19 |
20 | private val LightColorPalette = lightColors(
21 | primary = B400,
22 | primaryVariant = B400,
23 | secondary = N800,
24 | background = N30,
25 | surface = N0,
26 | onPrimary = N20,
27 | onSecondary = N0,
28 | onBackground = N800,
29 | )
30 |
31 |
32 | @Composable
33 | fun ScheduleCalendarTheme(
34 | darkTheme: Boolean = isSystemInDarkTheme(),
35 | content: @Composable() () -> Unit
36 | ) {
37 | val colors = if (darkTheme) {
38 | DarkColorPalette
39 | } else {
40 | LightColorPalette
41 | }
42 |
43 | MaterialTheme(
44 | colors = colors,
45 | typography = Typography,
46 | shapes = Shapes,
47 | content = content
48 | )
49 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.application")
3 | id("kotlin-android")
4 | }
5 |
6 | android {
7 | compileSdk = 30
8 | buildToolsVersion = "30.0.3"
9 |
10 | defaultConfig {
11 | applicationId = "com.halilibo.schedulecalendar"
12 | minSdk = 23
13 | targetSdk = 30
14 | versionCode = 1
15 | versionName = "1.0"
16 |
17 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18 | vectorDrawables {
19 | useSupportLibrary = true
20 | }
21 | }
22 |
23 | buildTypes {
24 | release {
25 | isMinifyEnabled = false
26 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
27 | }
28 | }
29 | compileOptions {
30 | sourceCompatibility = JavaVersion.VERSION_1_8
31 | targetCompatibility = JavaVersion.VERSION_1_8
32 | }
33 | kotlinOptions {
34 | jvmTarget = "1.8"
35 | useIR = true
36 | }
37 | buildFeatures {
38 | compose = true
39 | }
40 | composeOptions {
41 | kotlinCompilerExtensionVersion = rootProject.extra["compose_version"] as String
42 | kotlinCompilerVersion = "1.4.32"
43 | }
44 | }
45 |
46 | dependencies {
47 | implementation("androidx.core:core-ktx:1.5.0")
48 | implementation("androidx.appcompat:appcompat:1.3.0")
49 | implementation("com.google.android.material:material:1.3.0")
50 | implementation("androidx.compose.ui:ui:${rootProject.extra["compose_version"]}")
51 | implementation("androidx.compose.material:material:${rootProject.extra["compose_version"]}")
52 | implementation("androidx.compose.ui:ui-tooling:${rootProject.extra["compose_version"]}")
53 | implementation("androidx.compose.material:material-icons-extended:${rootProject.extra["compose_version"]}")
54 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
55 | implementation("androidx.activity:activity-compose:1.3.0-alpha08")
56 | implementation("com.google.accompanist:accompanist-pager:0.10.0")
57 | implementation("com.jakewharton.threetenabp:threetenabp:1.3.1")
58 | testImplementation("junit:junit:4.+")
59 | androidTestImplementation("androidx.test.ext:junit:1.1.2")
60 | androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
61 | androidTestImplementation("androidx.compose.ui:ui-test-junit4:${rootProject.extra["compose_version"]}")
62 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/halilibo/schedulecalendar/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar.ui.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val Purple200 = Color(0xFFBB86FC)
6 | val Purple500 = Color(0xFF6200EE)
7 | val Purple700 = Color(0xFF3700B3)
8 | val Teal200 = Color(0xFF03DAC5)
9 |
10 |
11 | val B100 = Color(0xFF4C9AFF)
12 | val B200 = Color(0xFF2684FF)
13 | val B300 = Color(0xFF0065FF)
14 | val B300_85 = Color(0x550065FF)
15 | val B400 = Color(0xFF0052CC)
16 | val B50 = Color(0xFFDEEBFF)
17 | val B500 = Color(0xFF0747A6)
18 | val B75 = Color(0xFFB3D4FF)
19 | val DN0 = Color(0xFF090a0b)
20 | val DN0a = Color(0x00090a0b)
21 | val DN10 = Color(0xFF101213)
22 | val DN100 = Color(0xFF5a697c)
23 | val DN100a = Color(0xBA090a0b)
24 | val DN10a = Color(0x0F090a0b)
25 | val DN20 = Color(0xFF17191c)
26 | val DN200 = Color(0xFF65758b)
27 | val DN200a = Color(0xC7090a0b)
28 | val DN20a = Color(0x24090a0b)
29 | val DN30 = Color(0xFF202328)
30 | val DN300 = Color(0xFF718298)
31 | val DN300a = Color(0xCF090a0b)
32 | val DN30a = Color(0x2E090a0b)
33 | val DN40 = Color(0xFF262b31)
34 | val DN400 = Color(0xFF8392a5)
35 | val DN400a = Color(0xD9090a0b)
36 | val DN40a = Color(0x4A090a0b)
37 | val DN50 = Color(0xFF2f353d)
38 | val DN500 = Color(0xFF929fb0)
39 | val DN500a = Color(0xE3090a0b)
40 | val DN50a = Color(0x5C090a0b)
41 | val DN60 = Color(0xFF373f49)
42 | val DN600 = Color(0xFFa3aebd)
43 | val DN600a = Color(0xEb090a0b)
44 | val DN60a = Color(0x66090a0b)
45 | val DN70 = Color(0xFF3f4855)
46 | val DN700 = Color(0xFFb5bec9)
47 | val DN700a = Color(0xF2090a0b)
48 | val DN70a = Color(0x78090a0b)
49 | val DN80 = Color(0xFF475262)
50 | val DN800 = Color(0xFFc7ced6)
51 | val DN800a = Color(0xF7090a0b)
52 | val DN80a = Color(0x87090a0b)
53 | val DN90 = Color(0xFF515f70)
54 | val DN900 = Color(0xFFd9dde3)
55 | val DN900a = Color(0xFF090a0b)
56 | val DN90a = Color(0xA1090a0b)
57 | val G100 = Color(0xFF79F2C0)
58 | val G200 = Color(0xFF57D9A3)
59 | val G300 = Color(0xFF36B37E)
60 | val G400 = Color(0xFF00875A)
61 | val G50 = Color(0xFFE3FCEF)
62 | val G500 = Color(0xFF006644)
63 | val G75 = Color(0xFFABF5D1)
64 | val N0 = Color(0xFFffffff)
65 | val N0a = Color(0x00091E42)
66 | val N10 = Color(0xFFFAFBFC)
67 | val N100 = Color(0xFF7A869A)
68 | val N100a = Color(0xA3091E42)
69 | val N10a = Color(0x05091E42)
70 | val N20 = Color(0xFFF4F5F7)
71 | val N200 = Color(0xFF6B778C)
72 | val N200a = Color(0x99091E42)
73 | val N20a = Color(0x0A091E42)
74 | val N30 = Color(0xFFEBECF0)
75 | val N300 = Color(0xFF5E6C84)
76 | val N300a = Color(0xA8091E42)
77 | val N30a = Color(0x14091E42)
78 | val N40 = Color(0xFFDFE1E6)
79 | val N400 = Color(0xFF505F79)
80 | val N400a = Color(0xB5091E42)
81 | val N40a = Color(0x21091E42)
82 | val N50 = Color(0xFFC1C7D0)
83 | val N500 = Color(0xFF42526E)
84 | val N500a = Color(0xC4091E42)
85 | val N50a = Color(0x40091E42)
86 | val N60 = Color(0xFFB3BAC5)
87 | val N600 = Color(0xFF344563)
88 | val N600a = Color(0xD1091E42)
89 | val N60a = Color(0x4F091E42)
90 | val N70 = Color(0xFFA5ADBA)
91 | val N700 = Color(0xFF253858)
92 | val N700a = Color(0xE3091E42)
93 | val N70a = Color(0x5C091E42)
94 | val N80 = Color(0xFF97A0AF)
95 | val N800 = Color(0xFF172B4D)
96 | val N800a = Color(0xF2091E42)
97 | val N80a = Color(0x6B091E42)
98 | val N90 = Color(0xFF8993A4)
99 | val N900 = Color(0xFF091E42)
100 | val N900a = Color(0xFF091E42)
101 | val N90a = Color(0x7A091E42)
102 | val P100 = Color(0xFF998DD9)
103 | val P200 = Color(0xFF8777D9)
104 | val P300 = Color(0xFF6554C0)
105 | val P400 = Color(0xFF5243AA)
106 | val P50 = Color(0xFFEAE6FF)
107 | val P500 = Color(0xFF403294)
108 | val P75 = Color(0xFFC0B6F2)
109 | val R100 = Color(0xFFFF8F73)
110 | val R200 = Color(0xFFFF7452)
111 | val R300 = Color(0xFFFF5630)
112 | val R400 = Color(0xFFDE350B)
113 | val R50 = Color(0xFFFFEBE6)
114 | val R500 = Color(0xFFBF2600)
115 | val R75 = Color(0xFFFFBDAD)
116 | val T100 = Color(0xFF79E2F2)
117 | val T200 = Color(0xFF00C7E5)
118 | val T300 = Color(0xFF00B8D9)
119 | val T400 = Color(0xFF00A3BF)
120 | val T50 = Color(0xFFE6FCFF)
121 | val T500 = Color(0xFF008DA6)
122 | val T75 = Color(0xFFB3F5FF)
123 | val Y100 = Color(0xFFFFE380)
124 | val Y200 = Color(0xFFFFC400)
125 | val Y300 = Color(0xFFFFAB00)
126 | val Y400 = Color(0xFFFF991F)
127 | val Y50 = Color(0xFFFFFAE6)
128 | val Y500 = Color(0xFFFF8B00)
129 | val Y75 = Color(0xFFFFF0B3)
--------------------------------------------------------------------------------
/app/src/main/java/com/halilibo/schedulecalendar/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import androidx.compose.animation.ExperimentalAnimationApi
7 | import androidx.compose.foundation.layout.*
8 | import androidx.compose.material.Icon
9 | import androidx.compose.material.IconButton
10 | import androidx.compose.material.Scaffold
11 | import androidx.compose.material.Surface
12 | import androidx.compose.material.icons.Icons
13 | import androidx.compose.material.icons.filled.HideImage
14 | import androidx.compose.material.icons.filled.ZoomIn
15 | import androidx.compose.material.icons.filled.ZoomOut
16 | import androidx.compose.runtime.Composable
17 | import androidx.compose.runtime.mutableStateOf
18 | import androidx.compose.runtime.remember
19 | import androidx.compose.ui.Modifier
20 | import androidx.compose.ui.tooling.preview.Preview
21 | import androidx.compose.ui.unit.dp
22 | import com.halilibo.schedulecalendar.ui.theme.*
23 | import org.threeten.bp.LocalDateTime
24 |
25 | class MainActivity : ComponentActivity() {
26 | @OptIn(ExperimentalAnimationApi::class)
27 | override fun onCreate(savedInstanceState: Bundle?) {
28 | super.onCreate(savedInstanceState)
29 | setContent {
30 | ScheduleCalendarTheme {
31 | Scaffold {
32 | Surface {
33 | ScheduleCalendarDemo()
34 | }
35 | }
36 | }
37 | }
38 | }
39 | }
40 |
41 | @Composable
42 | fun ScheduleCalendarDemo() {
43 | val viewSpan = remember { mutableStateOf(48 * 3600L) }
44 | val eventTimesVisible = remember { mutableStateOf(true) }
45 | Column(modifier = Modifier.fillMaxHeight()) {
46 | Row {
47 | IconButton(onClick = {
48 | viewSpan.value = (viewSpan.value * 2).coerceAtMost(96 * 3600)
49 | }) {
50 | Icon(imageVector = Icons.Default.ZoomOut, contentDescription = "increase")
51 | }
52 | Spacer(modifier = Modifier.width(8.dp))
53 | IconButton(onClick = {
54 | viewSpan.value = (viewSpan.value / 2).coerceAtLeast(3 * 3600)
55 | }) {
56 | Icon(imageVector = Icons.Default.ZoomIn, contentDescription = "decrease")
57 | }
58 | Spacer(modifier = Modifier.width(8.dp))
59 | IconButton(onClick = {
60 | eventTimesVisible.value = !(eventTimesVisible.value)
61 | }) {
62 | Icon(imageVector = Icons.Default.HideImage, contentDescription = "decrease")
63 | }
64 | }
65 |
66 | val calendarState = rememberScheduleCalendarState()
67 |
68 | Spacer(modifier = Modifier.height(8.dp))
69 |
70 | ScheduleCalendar(
71 | state = calendarState,
72 | now = LocalDateTime.now().plusHours(8),
73 | eventTimesVisible = eventTimesVisible.value,
74 | sections = listOf(
75 | CalendarSection(
76 | "Platform Schedule",
77 | events = listOf(
78 | CalendarEvent(
79 | startDate = LocalDateTime.now().minusHours(6),
80 | endDate = LocalDateTime.now().plusHours(12),
81 | name = "Halil Ozercan",
82 | description = "",
83 | color = R500
84 | ),
85 | CalendarEvent(
86 | startDate = LocalDateTime.now().plusHours(24),
87 | endDate = LocalDateTime.now().plusHours(48),
88 | name = "And Ani Calik",
89 | description = "",
90 | color = G500
91 | )
92 | )
93 | ),
94 | CalendarSection(
95 | "Compose Schedule",
96 | events = listOf(
97 | CalendarEvent(
98 | startDate = LocalDateTime.now().plusHours(6),
99 | endDate = LocalDateTime.now().plusHours(12),
100 | name = "Halil Ozercan",
101 | description = "",
102 | color = Y500
103 | ),
104 | CalendarEvent(
105 | startDate = LocalDateTime.now().plusHours(17),
106 | endDate = LocalDateTime.now().plusHours(27),
107 | name = "Taha Kirca",
108 | description = "",
109 | color = B400
110 | )
111 | )
112 | )
113 | ),
114 | viewSpan = viewSpan.value
115 | )
116 | }
117 | }
118 |
119 | @Preview(showBackground = true)
120 | @Composable
121 | fun DefaultPreview() {
122 | ScheduleCalendarTheme {
123 | ScheduleCalendarDemo()
124 | }
125 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/halilibo/schedulecalendar/ScheduleCalendarState.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar
2 |
3 | import androidx.compose.animation.core.*
4 | import androidx.compose.foundation.gestures.FlingBehavior
5 | import androidx.compose.foundation.gestures.ScrollScope
6 | import androidx.compose.foundation.gestures.ScrollableState
7 | import androidx.compose.runtime.*
8 | import kotlinx.coroutines.CoroutineScope
9 | import kotlinx.coroutines.launch
10 | import org.threeten.bp.LocalDateTime
11 | import org.threeten.bp.temporal.ChronoUnit
12 | import kotlin.math.abs
13 | import kotlin.math.roundToLong
14 |
15 | @Composable
16 | fun rememberScheduleCalendarState(
17 | referenceDateTime: LocalDateTime = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS),
18 | onDateTimeSelected: (LocalDateTime) -> Unit = {}
19 | ): ScheduleCalendarState {
20 | val coroutineScope = rememberCoroutineScope()
21 | return remember(coroutineScope) {
22 | ScheduleCalendarState(
23 | referenceDateTime = referenceDateTime,
24 | onDateTimeSelected = onDateTimeSelected,
25 | coroutineScope = coroutineScope,
26 | )
27 | }
28 | }
29 |
30 | class ScheduleCalendarState(
31 | referenceDateTime: LocalDateTime,
32 | private val onDateTimeSelected: (LocalDateTime) -> Unit,
33 | private val coroutineScope: CoroutineScope
34 | ) {
35 | val startDateTime: LocalDateTime by derivedStateOf {
36 | referenceDateTime.plusSeconds(secondsOffset.value)
37 | }
38 |
39 | val endDateTime: LocalDateTime by derivedStateOf {
40 | startDateTime.plusSeconds(this.viewSpanSeconds.value)
41 | }
42 |
43 | private val viewSpanSeconds = Animatable(ChronoUnit.DAYS.duration.seconds, LongToVector)
44 | private val secondsOffset = Animatable(0L, LongToVector)
45 | private val width = mutableStateOf(1)
46 |
47 | internal fun updateView(newViewSpanSeconds: Long, newWidth: Int) {
48 | this.width.value = newWidth
49 | val currentViewSpanSeconds = viewSpanSeconds.value
50 | coroutineScope.launch {
51 | viewSpanSeconds.animateTo(newViewSpanSeconds)
52 | }
53 | coroutineScope.launch {
54 | if (newViewSpanSeconds != currentViewSpanSeconds) {
55 | updateAnchors(newViewSpanSeconds)
56 | }
57 | }
58 | }
59 |
60 | internal val scrollableState = ScrollableState {
61 | coroutineScope.launch {
62 | secondsOffset.snapTo(secondsOffset.value - it.toSeconds())
63 | }
64 | it
65 | }
66 |
67 | private val secondsInPx by derivedStateOf {
68 | this.viewSpanSeconds.value.toFloat() / width.value.toFloat()
69 | }
70 |
71 | private fun Float.toSeconds(): Long {
72 | return (this * secondsInPx).roundToLong()
73 | }
74 |
75 | private fun Long.toPx(): Float {
76 | return this / secondsInPx
77 | }
78 |
79 | internal val scrollFlingBehavior = object : FlingBehavior {
80 | val decay = exponentialDecay(frictionMultiplier = 2f)
81 | override suspend fun ScrollScope.performFling(initialVelocity: Float): Float {
82 | val endPosition = decay.calculateTargetValue(0f, -initialVelocity)
83 | flingToNearestAnchor(secondsOffset.value.toPx() + endPosition)
84 | return 0f
85 | }
86 | }
87 |
88 | internal val visibleHours by derivedStateOf {
89 | val startHour = startDateTime.truncatedTo(ChronoUnit.HOURS)
90 | val endHour = endDateTime.truncatedTo(ChronoUnit.HOURS).plusHours(1)
91 |
92 | if (anchorRangeSeconds == 24 * 3600L) {
93 | emptyList()
94 | } else {
95 | startHour.between(endHour) { plusHours(1L) }.filter {
96 | it.hour % (anchorRangeSeconds / 3600) == 0L && it.hour != 0
97 | }.toList()
98 | }
99 | }
100 |
101 | private var anchorRangeSeconds by mutableStateOf(Long.MAX_VALUE)
102 | private var anchorRangePx by mutableStateOf(Float.MAX_VALUE)
103 | private suspend fun updateAnchors(viewSpanInSeconds: Long) {
104 | anchorRangeSeconds = if (viewSpanInSeconds > 24 * 3600) {
105 | 24 * 3600
106 | } else if (viewSpanInSeconds <= 24 * 3600 && viewSpanInSeconds > 12 * 3600) {
107 | 6 * 3600
108 | } else if (viewSpanInSeconds <= 12 * 3600 && viewSpanInSeconds > 6 * 3600) {
109 | 3 * 3600
110 | } else if (viewSpanInSeconds <= 6 * 3600 && viewSpanInSeconds > 3 * 3600) {
111 | 2 * 3600
112 | } else {
113 | 3600
114 | }
115 | anchorRangePx = anchorRangeSeconds.toPx()
116 | flingToNearestAnchor(secondsOffset.value.toPx())
117 | }
118 |
119 | private suspend fun flingToNearestAnchor(target: Float) {
120 | val nearestAnchor = target - (target.absRem(anchorRangePx))
121 | val nearestAnchor2 = nearestAnchor + anchorRangePx
122 |
123 | val newAnchoredPosition = (abs(target - nearestAnchor) to abs(target - nearestAnchor2)).let {
124 | if (it.first > it.second) nearestAnchor2 else nearestAnchor
125 | }
126 | secondsOffset.animateTo(newAnchoredPosition.toSeconds())
127 | onDateTimeSelected(startDateTime)
128 | }
129 |
130 | internal fun offsetFraction(localDateTime: LocalDateTime): Float {
131 | return ChronoUnit.SECONDS.between(startDateTime, localDateTime).toFloat() / (viewSpanSeconds.value).toFloat()
132 | }
133 |
134 | internal fun widthAndOffsetForEvent(
135 | start: LocalDateTime, end: LocalDateTime, totalWidth: Int
136 | ): Pair {
137 | val startOffsetPercent = offsetFraction(start).coerceIn(0f, 1f)
138 | val endOffsetPercent = offsetFraction(end).coerceIn(0f, 1f)
139 |
140 | val width = ((endOffsetPercent - startOffsetPercent) * totalWidth).toInt() + 1
141 | val offsetX = (startOffsetPercent * totalWidth).toInt()
142 | return width to offsetX
143 | }
144 | }
145 |
146 | private val LongToVector: TwoWayConverter =
147 | TwoWayConverter({ AnimationVector1D(it.toFloat()) }, { it.value.toLong() })
148 |
149 | private fun Float.absRem(modular: Float): Float {
150 | return ((this % modular) + modular) % modular
151 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/halilibo/schedulecalendar/ScheduleCalendar.kt:
--------------------------------------------------------------------------------
1 | package com.halilibo.schedulecalendar
2 |
3 | import androidx.compose.animation.AnimatedVisibility
4 | import androidx.compose.animation.ExperimentalAnimationApi
5 | import androidx.compose.animation.animateContentSize
6 | import androidx.compose.animation.core.*
7 | import androidx.compose.foundation.Canvas
8 | import androidx.compose.foundation.background
9 | import androidx.compose.foundation.clickable
10 | import androidx.compose.foundation.gestures.*
11 | import androidx.compose.foundation.layout.*
12 | import androidx.compose.foundation.shape.RoundedCornerShape
13 | import androidx.compose.material.*
14 | import androidx.compose.runtime.*
15 | import androidx.compose.ui.Modifier
16 | import androidx.compose.ui.draw.clip
17 | import androidx.compose.ui.geometry.Offset
18 | import androidx.compose.ui.graphics.Color
19 | import androidx.compose.ui.graphics.PathEffect
20 | import androidx.compose.ui.layout.Layout
21 | import androidx.compose.ui.layout.Measurable
22 | import androidx.compose.ui.layout.ParentDataModifier
23 | import androidx.compose.ui.platform.LocalDensity
24 | import androidx.compose.ui.text.font.FontWeight
25 | import androidx.compose.ui.text.font.FontWeight.Companion.W500
26 | import androidx.compose.ui.text.style.TextAlign
27 | import androidx.compose.ui.text.style.TextOverflow
28 | import androidx.compose.ui.unit.Density
29 | import androidx.compose.ui.unit.IntOffset
30 | import androidx.compose.ui.unit.dp
31 | import androidx.compose.ui.unit.sp
32 | import com.halilibo.schedulecalendar.ui.theme.G500
33 | import org.threeten.bp.LocalDateTime
34 | import org.threeten.bp.format.DateTimeFormatter
35 | import org.threeten.bp.temporal.ChronoUnit
36 | import java.util.*
37 |
38 |
39 | @Composable
40 | fun ScheduleCalendar(
41 | state: ScheduleCalendarState,
42 | modifier: Modifier = Modifier,
43 | viewSpan: Long = 48 * 3600L, // in seconds
44 | sections: List = emptyList(),
45 | now: LocalDateTime = LocalDateTime.now(),
46 | eventTimesVisible: Boolean = true
47 | ) = BoxWithConstraints(
48 | modifier
49 | .fillMaxWidth()
50 | .scrollable(
51 | state.scrollableState,
52 | Orientation.Horizontal,
53 | flingBehavior = state.scrollFlingBehavior
54 | )
55 | ) {
56 | state.updateView(viewSpan, constraints.maxWidth)
57 |
58 | Column {
59 | DaysRow(
60 | state = state,
61 | modifier = Modifier
62 | .fillMaxWidth()
63 | .padding(vertical = 8.dp)
64 | )
65 |
66 | HoursRow(state)
67 |
68 | Box(modifier = Modifier.fillMaxWidth()) {
69 | Column {
70 | sections.forEach {
71 | CalendarSectionRow(
72 | section = it,
73 | state = state,
74 | eventTimesVisible = eventTimesVisible
75 | )
76 | }
77 | }
78 |
79 | // hour dividers
80 | Canvas(modifier = Modifier.matchParentSize()) {
81 | state.visibleHours.forEach { localDateTime ->
82 | val offsetPercent = state.offsetFraction(localDateTime)
83 | drawLine(
84 | color = Color.Gray,
85 | strokeWidth = 2f,
86 | start = Offset(offsetPercent * size.width, 0f),
87 | end = Offset(offsetPercent * size.width, size.height),
88 | pathEffect = PathEffect.dashPathEffect(
89 | intervals = floatArrayOf(10f, 20f),
90 | phase = 5f
91 | )
92 | )
93 | }
94 | }
95 | }
96 | }
97 |
98 | DayDividers(
99 | state = state,
100 | modifier = Modifier.matchParentSize()
101 | )
102 |
103 | // "now" indicator
104 | Canvas(modifier = Modifier.matchParentSize()) {
105 | val offsetPercent = state.offsetFraction(now)
106 | drawLine(
107 | color = Color.Magenta,
108 | strokeWidth = 6f,
109 | start = Offset(offsetPercent * size.width, 0f),
110 | end = Offset(offsetPercent * size.width, size.height)
111 | )
112 | drawCircle(
113 | Color.Magenta,
114 | center = Offset(offsetPercent * size.width, 12f),
115 | radius = 12f
116 | )
117 | }
118 | }
119 |
120 | @OptIn(ExperimentalAnimationApi::class)
121 | @Composable
122 | fun CalendarSectionRow(
123 | section: CalendarSection,
124 | state: ScheduleCalendarState,
125 | eventTimesVisible: Boolean
126 | ) {
127 | Column(Modifier.animateContentSize()) {
128 | val eventMap = section.events.map { event ->
129 | Triple(
130 | event,
131 | event.startDate.isAfter(state.startDateTime) && event.startDate.isBefore(state.endDateTime),
132 | event.endDate.isAfter(state.startDateTime) && event.endDate.isBefore(state.endDateTime),
133 | )
134 | }.filter { (event, startHit, endHit) ->
135 | startHit || endHit || (event.startDate.isBefore(state.startDateTime) && event.endDate.isAfter(state.endDateTime))
136 | }
137 |
138 | Text(
139 | text = section.name,
140 | fontSize = 12.sp,
141 | fontWeight = W500,
142 | modifier = Modifier.padding(4.dp)
143 | )
144 | if (eventMap.isNotEmpty()) {
145 | BoxWithConstraints(Modifier.fillMaxWidth()) {
146 | eventMap.forEach { (event, startHit, endHit) ->
147 | val (width, offsetX) = state.widthAndOffsetForEvent(
148 | start = event.startDate,
149 | end = event.endDate,
150 | totalWidth = constraints.maxWidth
151 | )
152 |
153 | val shape = when {
154 | startHit && endHit -> RoundedCornerShape(4.dp)
155 | startHit -> RoundedCornerShape(
156 | topStart = 4.dp,
157 | bottomStart = 4.dp
158 | )
159 | endHit -> RoundedCornerShape(
160 | topEnd = 4.dp,
161 | bottomEnd = 4.dp
162 | )
163 | else -> RoundedCornerShape(4.dp)
164 | }
165 |
166 | Column(modifier = Modifier
167 | .padding(vertical = 8.dp)
168 | .width(with(LocalDensity.current) { width.toDp() })
169 | .offset { IntOffset(offsetX, 0) }
170 | .background(event.color, shape = shape)
171 | .clip(shape)
172 | .clickable { }
173 | .padding(4.dp)
174 | ) {
175 | Text(
176 | text = event.name,
177 | color = Color.White,
178 | maxLines = 1,
179 | overflow = TextOverflow.Ellipsis,
180 | textAlign = TextAlign.Center,
181 | modifier = Modifier.fillMaxWidth()
182 | )
183 | AnimatedVisibility(visible = eventTimesVisible) {
184 | Text(
185 | text = event.startDate.format(DateTimeFormatter.ofPattern("HH:mm")) + " - " +
186 | event.endDate.format(DateTimeFormatter.ofPattern("HH:mm")),
187 | fontSize = 12.sp,
188 | color = Color.White,
189 | maxLines = 1,
190 | overflow = TextOverflow.Ellipsis,
191 | textAlign = TextAlign.Center,
192 | modifier = Modifier.fillMaxWidth()
193 | )
194 | }
195 | }
196 | }
197 | }
198 | }
199 | }
200 | }
201 |
202 | @Composable
203 | internal fun DaysRow(
204 | state: ScheduleCalendarState,
205 | modifier: Modifier = Modifier
206 | ) {
207 | BoxWithConstraints(modifier = modifier) {
208 | (state.startDateTime daysBetween state.endDateTime).forEach { localDateTime ->
209 | val (width, offsetX) = state.widthAndOffsetForEvent(
210 | start = localDateTime,
211 | end = localDateTime.plusDays(1),
212 | totalWidth = constraints.maxWidth
213 | )
214 | Column(modifier = Modifier
215 | .width(with(LocalDensity.current) { width.toDp() })
216 | .offset { IntOffset(offsetX, 0) }
217 | .padding(horizontal = 8.dp)
218 | ) {
219 | Text(
220 | text = localDateTime.format(DateTimeFormatter.ofPattern("MMM, dd")),
221 | fontWeight = FontWeight.Bold,
222 | textAlign = TextAlign.Center,
223 | maxLines = 1,
224 | overflow = TextOverflow.Clip,
225 | modifier = Modifier.fillMaxWidth()
226 | )
227 | }
228 | }
229 | }
230 | }
231 |
232 | @OptIn(ExperimentalAnimationApi::class)
233 | @Composable
234 | internal fun HoursRow(
235 | state: ScheduleCalendarState
236 | ) {
237 | AnimatedVisibility(visible = state.visibleHours.isNotEmpty()) {
238 | Layout(
239 | content = {
240 | state.visibleHours.forEach { localDateTime ->
241 | Text(
242 | localDateTime.format(DateTimeFormatter.ofPattern("hh a")),
243 | fontSize = 12.sp,
244 | modifier = Modifier.then(
245 | LocalDateTimeData(localDateTime)
246 | )
247 | )
248 | }
249 | }
250 | ) { measurables, constraints ->
251 | val placeables = measurables.map { it.measure(constraints) to it.localDateTime }
252 |
253 | val width = constraints.maxWidth
254 | val height = if (placeables.isNotEmpty()) { placeables.maxOf { it.first.height } } else { 0 }
255 | layout(width, height) {
256 | placeables.forEach { (placeable, localDateTime) ->
257 | val origin = state.offsetFraction(localDateTime) * width
258 | val x = origin.toInt() - placeable.width / 2
259 | placeable.placeRelative(x.coerceAtLeast(0), 0)
260 | }
261 | }
262 | }
263 | }
264 | }
265 |
266 | @Composable
267 | fun DayDividers(
268 | state: ScheduleCalendarState,
269 | modifier: Modifier = Modifier
270 | ) {
271 | Canvas(modifier = modifier) {
272 | (state.startDateTime daysBetween state.endDateTime).forEach { localDateTime ->
273 | val offsetPercent = state.offsetFraction(localDateTime)
274 | drawLine(
275 | color = Color.Gray,
276 | strokeWidth = 4f,
277 | start = Offset(offsetPercent * size.width, 0f),
278 | end = Offset(offsetPercent * size.width, size.height),
279 | pathEffect = PathEffect.dashPathEffect(
280 | intervals = floatArrayOf(10f, 20f),
281 | phase = 5f
282 | )
283 | )
284 | }
285 | }
286 | }
287 |
288 | data class CalendarSection(
289 | val name: String,
290 | val events: List
291 | )
292 |
293 | data class CalendarEvent(
294 | val startDate: LocalDateTime,
295 | val endDate: LocalDateTime,
296 | val name: String = "",
297 | val description: String = "",
298 | val color: Color = G500
299 | )
300 |
301 | private data class LocalDateTimeData(
302 | val localDateTime: LocalDateTime,
303 | ) : ParentDataModifier {
304 | override fun Density.modifyParentData(parentData: Any?) = this@LocalDateTimeData
305 | }
306 |
307 | private val Measurable.localDateTime: LocalDateTime
308 | get() = (parentData as? LocalDateTimeData)?.localDateTime ?: error("No LocalDateTime for measurable $this")
309 |
310 | fun LocalDateTime.between(
311 | target: LocalDateTime,
312 | increment: LocalDateTime.() -> LocalDateTime
313 | ): Sequence {
314 | return generateSequence(
315 | seed = this,
316 | nextFunction = {
317 | val next = it.increment()
318 | if (next.isBefore(target)) next else null
319 | }
320 | )
321 | }
322 |
323 | infix fun LocalDateTime.daysBetween(target: LocalDateTime): Sequence {
324 | val start = truncatedTo(ChronoUnit.DAYS)
325 | return start.between(target.truncatedTo(ChronoUnit.DAYS).plusDays(1)) {
326 | plusDays(1)
327 | }
328 | }
--------------------------------------------------------------------------------