├── 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 │ │ │ ├── xml │ │ │ │ ├── backup_rules.xml │ │ │ │ └── data_extraction_rules.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── datepickerapp │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── datepickerapp │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── .idea ├── .name ├── .gitignore ├── compiler.xml ├── misc.xml ├── gradle.xml └── dbnavigator.xml ├── jitpack.yml ├── persian_date_picker ├── .gitignore ├── consumer-rules.pro ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── persian_date_picker │ │ │ ├── RangeDatePicker.kt │ │ │ └── PersianDatePicker.kt │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── persian_date_picker │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── persian_date_picker │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle ├── gradle.properties ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Date picker app -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk11 -------------------------------------------------------------------------------- /persian_date_picker/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /persian_date_picker/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Date picker app 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamad-Sarfi/compose_persian_date_picker/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamad-Sarfi/compose_persian_date_picker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamad-Sarfi/compose_persian_date_picker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamad-Sarfi/compose_persian_date_picker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamad-Sarfi/compose_persian_date_picker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamad-Sarfi/compose_persian_date_picker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamad-Sarfi/compose_persian_date_picker/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/Mohamad-Sarfi/compose_persian_date_picker/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/Mohamad-Sarfi/compose_persian_date_picker/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/Mohamad-Sarfi/compose_persian_date_picker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /persian_date_picker/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamad-Sarfi/compose_persian_date_picker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Sep 20 12:55:19 IRDT 2022 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | } 7 | } 8 | dependencyResolutionManagement { 9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | } 15 | rootProject.name = "Date picker app" 16 | include ':app' 17 | include ':persian_date_picker' 18 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/datepickerapp/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.datepickerapp 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 | } -------------------------------------------------------------------------------- /persian_date_picker/src/test/java/com/example/persian_date_picker/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.persian_date_picker 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/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/xml/backup_rules.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/xml/data_extraction_rules.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 12 | 13 | 19 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /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/androidTest/java/com/example/datepickerapp/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.datepickerapp 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.example.datepickerapp", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /persian_date_picker/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 -------------------------------------------------------------------------------- /persian_date_picker/src/androidTest/java/com/example/persian_date_picker/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.persian_date_picker 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.example.persian_date_picker.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'org.jetbrains.kotlin.android' 4 | } 5 | 6 | android { 7 | namespace 'com.example.datepickerapp' 8 | compileSdk 32 9 | 10 | defaultConfig { 11 | applicationId "com.example.datepickerapp" 12 | minSdk 24 13 | targetSdk 32 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | kotlinOptions { 31 | jvmTarget = '1.8' 32 | } 33 | } 34 | 35 | dependencies { 36 | 37 | implementation 'androidx.core:core-ktx:1.7.0' 38 | implementation 'androidx.appcompat:appcompat:1.5.1' 39 | implementation 'com.google.android.material:material:1.6.1' 40 | testImplementation 'junit:junit:4.13.2' 41 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 42 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 43 | } -------------------------------------------------------------------------------- /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 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | # Enables namespacing of each library's R class so that its R class includes only the 21 | # resources declared in the library itself and none from the library's dependencies, 22 | # thereby reducing the size of the R class for that library 23 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /persian_date_picker/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'org.jetbrains.kotlin.android' 4 | id 'maven-publish' 5 | } 6 | 7 | android { 8 | namespace 'com.example.persian_date_picker' 9 | compileSdk 32 10 | 11 | defaultConfig { 12 | minSdk 23 13 | targetSdk 32 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | consumerProguardFiles "consumer-rules.pro" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | buildFeatures { 27 | compose true 28 | } 29 | composeOptions { 30 | kotlinCompilerExtensionVersion '1.3.1' 31 | } 32 | 33 | 34 | 35 | compileOptions { 36 | sourceCompatibility JavaVersion.VERSION_1_8 37 | targetCompatibility JavaVersion.VERSION_1_8 38 | } 39 | kotlinOptions { 40 | jvmTarget = '1.8' 41 | } 42 | } 43 | 44 | dependencies { 45 | 46 | implementation 'androidx.core:core-ktx:1.7.0' 47 | implementation 'androidx.appcompat:appcompat:1.5.1' 48 | implementation 'com.google.android.material:material:1.6.1' 49 | 50 | implementation 'androidx.compose.ui:ui:1.2.1' 51 | // Tooling support (Previews, etc.) 52 | implementation 'androidx.compose.ui:ui-tooling:1.2.1' 53 | // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.) 54 | implementation 'androidx.compose.foundation:foundation:1.2.1' 55 | // Material Design 56 | implementation 'androidx.compose.material:material:1.2.1' 57 | // Material design icons 58 | implementation 'androidx.compose.material:material-icons-extended:1.2.1' 59 | 60 | implementation "ir.huri:JalaliCalendar:1.3.3" 61 | 62 | testImplementation 'junit:junit:4.13.2' 63 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 64 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 65 | } 66 | afterEvaluate { 67 | publishing { 68 | publications { 69 | release(MavenPublication) { 70 | from components.release 71 | groupId = 'com.github.Mohamad-Sarfi' 72 | artifactId = 'compose_persian_date_picker' 73 | version = 'v0.5.0' 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Compose Persian Date Picker - Alpha Version 3 | 4 | Persian date picker for Compose, Based on Jalali calendar. 5 | This library is designed for Iranians and other Persian speaking communities that utilize Jalali (Persian) calendar rather than Christian calendar which is the default calendar for Googles provided date picker composable in Android. 6 | 7 | The design is based on Material guidlines. All the colors and fonts used in this composable are from Material theme of the app. The colors consist of "primary", "onPrimary", "primaryVariant", "backgound", "onBackground". 8 | The fonts are also predefined fonts in Material theme, namely body1-2, h5-h1 and subtitle1-2. 9 | 10 | In order to customize the composable design you just need to modify your app's theme. 11 | 12 | 13 | 14 | 15 | ## Adding to your project 16 | First add `jitpack.io` to setting.gradle 17 | ```groovy 18 | repositories { 19 | google() 20 | mavenCentral() 21 | maven { url "https://jitpack.io" } 22 | } 23 | ``` 24 | 25 | Then add following line to your module build.gradle file 26 | ```groovy 27 | dependencies{ 28 | ... 29 | implementation 'com.github.Mohamad-Sarfi:compose_persian_date_picker:0.5.0' 30 | } 31 | ``` 32 | 33 | ## Usage Instructions - PersianDatePicker 34 | The composable function "PersianDatePicker" must be called from another @Composable function. 35 | First you have to declare a boolean state named "hideDatePicker" which its value will be set true in "onDismiss" lambda. 36 | 37 | The picked date by user is return in "setDate" lambda. setDate has a Map as parameter which has 3 keys, "day", "month" and "year". Each one can be accessed and stored the way shown below. 38 | 39 | ```kotlin 40 | @Composable 41 | fun MyCompose(){ 42 | 43 | var hideDatePicker = mutableSateOf(true) 44 | 45 | Button( 46 | onClick = {hideDatePicker.value = false} 47 | ) { 48 | Text("انتخاب تاریخ") 49 | } 50 | 51 | if (!hideDatePicker){ 52 | 53 | // ************************************************* 54 | PersianDatePicker( 55 | onDismiss = { hideDatePicker.value = true }, 56 | setDate = { date -> 57 | var day = date["day"] 58 | var month = date["month"] 59 | var year = date["year"] 60 | } 61 | ) 62 | // ************************************************* 63 | 64 | } 65 | 66 | } 67 | ``` 68 | 69 | There are a couple of arbitrary parameters provieded as well in order to customize the composable: 70 | ```kotlin 71 | @Composable 72 | fun MyCompose(){ 73 | 74 | var hideDatePicker = mutableSateOf(false) 75 | 76 | PersianDatePicker( 77 | minYear = 1350, 78 | maxYear = 1430, 79 | positiveButtonTxt= "تایید", 80 | negativeButtonTxt = "لغو, 81 | onDismiss = { hideDatePicker.value = true }, 82 | setDate = { date -> 83 | var day = date["day"] 84 | var month = date["month"] 85 | var year = date["year"] 86 | } 87 | ) 88 | } 89 | ``` 90 | ### Parameters Table 91 | | Parameter | Description | 92 | | --- | --- | 93 | |`onDismiss`| Needs to set the value of a mutable state to `true` to hide the dialog | 94 | | `setDate` | returns a Map as the parameter of the lambda which consists of `it["day"]`, `it["month"]`, `it["year"]` 95 | | `minYear` | sets minimum value of the year, default value is 1350 | 96 | | `maxYear` | sets maximum value of the year, default value is 1420 | 97 | | `positiveButtonTxt` | sets the text for positive button, default value is تایید | 98 | | `negativeButtonTxt` | sets the text for negative button, default value is لغو | 99 | | `shortWeekDays` | decides if week days on top row are shown fully or their first letter is shown. Default value is `false`| 100 | 101 | 102 | ## Usage Instructions - RangeDatePicker 103 | The second composable provided to you in this library is a "Range Date Picker" that lets you pick a date range within a "start date" and "end date". 104 | The overall functionality is almost the same as the `PersianDatePicker` but the setDate lambda argument is a `list` of maps which index `0` is the starting date and index `1` is the end date. 105 | 106 | ```kotlin 107 | @Composable 108 | fun MyCompose(){ 109 | 110 | var hideRangeDatePicker = mutableSateOf(true) 111 | 112 | Button( 113 | onClick = {hideDatePicker.value = false} 114 | ) { 115 | Text("انتخاب بازه زمانی") 116 | } 117 | 118 | if (!hideRangeDatePicker){ 119 | 120 | // ************************************************* 121 | PersianRangeDatePicker( 122 | onDismiss = { hideRangeDatePicker.value = true }, 123 | setDate = { list -> 124 | var startDateMap = list[0] //mapOf("day" to day, "month" to month, "year" to year) 125 | var endDateMap = list[1] //mapOf("day" to day, "month" to month, "year" to year) 126 | } 127 | ) 128 | // ************************************************* 129 | 130 | } 131 | 132 | } 133 | ``` 134 | 135 | If you face any issues or have feedbacks I'd be happy to hear from you `sarfimohamad46@gmail.com` 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /persian_date_picker/src/main/java/com/example/persian_date_picker/RangeDatePicker.kt: -------------------------------------------------------------------------------- 1 | package com.example.composeautomation.ui.datepicker 2 | 3 | 4 | import android.util.Log 5 | import androidx.compose.foundation.BorderStroke 6 | import androidx.compose.foundation.background 7 | import androidx.compose.foundation.clickable 8 | import androidx.compose.foundation.layout.* 9 | import androidx.compose.foundation.lazy.LazyColumn 10 | import androidx.compose.foundation.lazy.grid.GridCells 11 | import androidx.compose.foundation.lazy.grid.LazyVerticalGrid 12 | import androidx.compose.foundation.lazy.grid.items 13 | import androidx.compose.foundation.lazy.items 14 | import androidx.compose.foundation.lazy.rememberLazyListState 15 | import androidx.compose.foundation.shape.RoundedCornerShape 16 | import androidx.compose.material.* 17 | import androidx.compose.material.icons.Icons 18 | import androidx.compose.material.icons.filled.Edit 19 | import androidx.compose.runtime.* 20 | import androidx.compose.ui.Alignment 21 | import androidx.compose.ui.Modifier 22 | import androidx.compose.ui.draw.clip 23 | import androidx.compose.ui.graphics.Color 24 | import androidx.compose.ui.platform.LocalConfiguration 25 | import androidx.compose.ui.unit.dp 26 | import androidx.compose.ui.window.Dialog 27 | import ir.huri.jcal.JalaliCalendar 28 | import kotlinx.coroutines.launch 29 | 30 | @Composable 31 | fun PersianRangeDatePicker( 32 | onDismiss : (Boolean) -> Unit, 33 | setDate : (List>) -> Unit 34 | ){ 35 | val today = JalaliCalendar().day 36 | val month = JalaliCalendar().month 37 | val year = JalaliCalendar().year 38 | var selectedPart by remember { 39 | mutableStateOf("main") 40 | } 41 | var startDate by remember { 42 | mutableStateOf(listOf(year, month, today)) 43 | } 44 | var endDate by remember { 45 | mutableStateOf(listOf(year, month, today)) 46 | } 47 | val width = LocalConfiguration.current.screenWidthDp 48 | 49 | Dialog(onDismissRequest = { onDismiss(true) }) { 50 | Card( 51 | modifier = Modifier 52 | .size(width = width.dp, height = 530.dp) 53 | .padding(5.dp), 54 | shape = RoundedCornerShape(10.dp), 55 | elevation = 4.dp, 56 | backgroundColor = MaterialTheme.colors.background 57 | ) { 58 | Column( 59 | Modifier 60 | .fillMaxSize() 61 | .padding(horizontal = 0.dp), 62 | verticalArrangement = Arrangement.SpaceBetween, 63 | horizontalAlignment = Alignment.CenterHorizontally 64 | ) { 65 | 66 | MainContent( 67 | startDate, 68 | endDate, 69 | selectedPart, 70 | setStartDate = {startDate = it}, 71 | setEndDate = {endDate = it}, 72 | setSelected = {selectedPart = it} 73 | ) 74 | 75 | Row( 76 | Modifier 77 | .fillMaxWidth() 78 | .padding(15.dp) 79 | , 80 | verticalAlignment = Alignment.CenterVertically, 81 | horizontalArrangement = Arrangement.End 82 | ) { 83 | 84 | Text( 85 | text = "لغو", 86 | color = MaterialTheme.colors.primary, 87 | style = MaterialTheme.typography.h5, 88 | modifier = Modifier 89 | .clickable { 90 | onDismiss(true) 91 | } 92 | .padding(horizontal = 10.dp) 93 | ) 94 | Text( 95 | text = "تایید", 96 | color = MaterialTheme.colors.primary, 97 | style = MaterialTheme.typography.h5, 98 | modifier = Modifier 99 | .clickable { 100 | onDismiss(true) 101 | setDate( 102 | listOf( 103 | mapOf( 104 | "day" to startDate[2].toString(), 105 | "month" to startDate[1].toString(), 106 | "year" to startDate[0].toString() 107 | ), 108 | mapOf( 109 | "day" to endDate[2].toString(), 110 | "month" to endDate[1].toString(), 111 | "year" to endDate[0].toString() 112 | ) 113 | ) 114 | ) 115 | } 116 | .padding(horizontal = 15.dp) 117 | ) 118 | 119 | } 120 | } 121 | } 122 | } 123 | } 124 | 125 | @Composable 126 | private fun MainContent( 127 | startDate : List, 128 | endDate : List, 129 | selectedPart : String, 130 | setStartDate : (List) -> Unit, 131 | setEndDate : (List) -> Unit, 132 | setSelected : (String) -> Unit 133 | ){ 134 | val width = LocalConfiguration.current.screenWidthDp 135 | val persianWeekDays = listOf("شنبه","یکشنبه","دوشنبه","سه شنبه","چهارشنبه","پنجشنبه","جمعه", ) 136 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 137 | val weekDay = JalaliCalendar(startDate[0], startDate[1], startDate[2]).dayOfWeek 138 | 139 | 140 | Column( 141 | horizontalAlignment = Alignment.CenterHorizontally, 142 | verticalArrangement = Arrangement.SpaceBetween 143 | ) { 144 | Column() { 145 | Row( 146 | Modifier 147 | .height(45.dp) 148 | .fillMaxWidth() 149 | .background(MaterialTheme.colors.primary) 150 | .padding(vertical = 13.dp, horizontal = 15.dp), 151 | verticalAlignment = Alignment.CenterVertically, 152 | horizontalArrangement = Arrangement.Start 153 | ) { 154 | Icon(Icons.Default.Edit, 155 | contentDescription = null, 156 | tint = MaterialTheme.colors.onPrimary, 157 | modifier = Modifier 158 | .clickable { 159 | 160 | } 161 | ) 162 | } 163 | Row( 164 | modifier = Modifier 165 | .fillMaxWidth() 166 | .background(MaterialTheme.colors.primary) 167 | .padding(vertical = 10.dp, horizontal = 25.dp), 168 | verticalAlignment = Alignment.CenterVertically, 169 | horizontalArrangement = Arrangement.End 170 | ) { 171 | Row( 172 | verticalAlignment = Alignment.CenterVertically, 173 | horizontalArrangement = Arrangement.End 174 | ){ 175 | Text( 176 | text = monthsList[endDate[1]], 177 | style = MaterialTheme.typography.h4, 178 | color = MaterialTheme.colors.onPrimary, 179 | modifier = Modifier 180 | .padding(horizontal = 5.dp) 181 | ) 182 | Text(text = endDate[2].toString(), style = MaterialTheme.typography.h4, color = MaterialTheme.colors.onPrimary) 183 | Text(text = "تا", 184 | style = MaterialTheme.typography.h4, 185 | color = MaterialTheme.colors.onPrimary, 186 | modifier = Modifier.padding(horizontal = 5.dp) 187 | ) 188 | 189 | Text( 190 | text = monthsList[startDate[1]], 191 | style = MaterialTheme.typography.h4, 192 | color = MaterialTheme.colors.onPrimary, 193 | modifier = Modifier 194 | .padding(horizontal = 5.dp) 195 | ) 196 | Text(text = startDate[2].toString(), style = MaterialTheme.typography.h4, color = MaterialTheme.colors.onPrimary) 197 | } 198 | } 199 | 200 | Days( 201 | startDate, 202 | endDate, 203 | setStartDate = {setStartDate(it)} , 204 | setEndDay = {setEndDate(it)} 205 | ) 206 | 207 | } 208 | } 209 | } 210 | 211 | @Composable 212 | private fun Days( 213 | startDate: List, 214 | endDate: List, 215 | setStartDate : (List) -> Unit, 216 | setEndDay : (List) -> Unit, 217 | ){ 218 | 219 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 220 | val weekDays = listOf("شنبه","یکشنبه","دوشنبه","سه شنبه","چهارشنبه","پنجشنبه","جمعه", ) 221 | 222 | var start by remember { 223 | mutableStateOf(false) 224 | } 225 | 226 | var end by remember { 227 | mutableStateOf(false) 228 | } 229 | 230 | var weekDay = JalaliCalendar(startDate[0].toInt(), startDate[1] + 1 , 1).dayOfWeek 231 | 232 | var today = JalaliCalendar().day 233 | val thisMonth = JalaliCalendar().month 234 | 235 | 236 | 237 | val monthRange = mutableListOf() 238 | 239 | for (m in thisMonth - 3 .. thisMonth + 3){ 240 | monthRange.add(m) 241 | } 242 | 243 | var gridState = rememberLazyListState() 244 | val scope = rememberCoroutineScope() 245 | LaunchedEffect(key1 = 1){ 246 | scope.launch { 247 | gridState.scrollToItem(monthRange.indexOf(thisMonth-1)) 248 | } 249 | } 250 | 251 | Column( 252 | Modifier 253 | .fillMaxWidth() 254 | .padding(top = 10.dp)) { 255 | Row( 256 | Modifier 257 | .fillMaxWidth() 258 | .padding(vertical = 2.dp, horizontal = 8.dp), 259 | verticalAlignment = Alignment.CenterVertically, 260 | horizontalArrangement = Arrangement.SpaceEvenly 261 | ) { 262 | weekDays.forEach { 263 | Text(text = it, color = MaterialTheme.colors.primary.copy(.4f), style = MaterialTheme.typography.subtitle2) 264 | } 265 | } 266 | 267 | //val years = listOf(sYear.toInt() - 1, sYear.toInt(), sYear.toInt() + 1) 268 | 269 | LazyColumn( 270 | modifier = Modifier 271 | .fillMaxWidth().height(290.dp), 272 | state = gridState 273 | ){ 274 | items(monthRange){ month -> 275 | 276 | val daysList = daysOfMonth(listOf(startDate[0], month), startDate, endDate) 277 | 278 | Row( 279 | Modifier 280 | .fillMaxWidth() 281 | .padding(horizontal = 30.dp, vertical = 0.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.End) { 282 | Text(text = monthsList[month], style = MaterialTheme.typography.body1, color = MaterialTheme.colors.onBackground.copy(.5f)) 283 | } 284 | LazyVerticalGrid( 285 | columns = GridCells.Fixed(7), 286 | modifier = Modifier 287 | .fillMaxWidth() 288 | .height(290.dp), 289 | contentPadding = PaddingValues(horizontal = 15.dp, vertical = 0.dp), 290 | verticalArrangement = Arrangement.Top, 291 | horizontalArrangement = Arrangement.Center 292 | ){ 293 | items(daysList){ 294 | Surface( 295 | modifier = Modifier 296 | .padding(vertical = 2.dp) 297 | .size(42.dp) 298 | .clip( 299 | decideDayShape( 300 | it, 301 | month, 302 | startDate, 303 | endDate, 304 | ) 305 | ) 306 | .clickable { 307 | setStartEndDates( 308 | it, 309 | month, 310 | startDate, 311 | endDate, 312 | start, 313 | { v -> setStartDate(v) }, 314 | { v -> setEndDay(v) }, 315 | {v -> end = v}, 316 | { v -> start = v } 317 | ) 318 | }, 319 | shape = decideDayShape(it, month, startDate, endDate, ), 320 | color = decideDayColor(it, startDate, endDate, end, month), 321 | border = BorderStroke( 1.dp, color = if (it == today.toString() && startDate[1] == thisMonth) MaterialTheme.colors.primary else Color.Transparent) 322 | ) { 323 | Row(Modifier.fillMaxSize(), 324 | verticalAlignment = Alignment.CenterVertically, 325 | horizontalArrangement = Arrangement.Center) { 326 | Text(text = it, style = MaterialTheme.typography.body1, color = decideDayText(it, startDate, endDate, month)) 327 | } 328 | } 329 | } 330 | } 331 | } 332 | } 333 | } 334 | } 335 | 336 | private fun setStartEndDates( 337 | day: String, 338 | month : Int, 339 | startDate: List, 340 | endDate: List, 341 | start : Boolean, 342 | setStartDate: (List) -> Unit, 343 | setEndDate: (List) -> Unit, 344 | setEndBool : (Boolean) -> Unit, 345 | setStartBool : (Boolean) -> Unit 346 | ){ 347 | if (day != " "){ 348 | if (!start) { 349 | setStartDate(listOf(startDate[0], month , day.toInt())) 350 | setStartBool(true) 351 | } else if (day.toInt() == startDate[2] && month == startDate[1]){ 352 | setStartBool(false) 353 | setEndBool(false) 354 | 355 | } else if (month == startDate[1]) { 356 | if (day.toInt() < startDate[2]){ 357 | setEndDate(startDate) 358 | setStartDate(listOf(startDate[0], month , day.toInt())) 359 | setEndBool(true) 360 | } else { 361 | setEndDate(listOf(startDate[0], month , day.toInt())) 362 | setEndBool(true) 363 | } 364 | } else if (month < startDate[1]){ 365 | setEndDate(startDate) 366 | setStartDate(listOf(startDate[0], month , day.toInt())) 367 | setEndBool(true) 368 | } else { 369 | setEndDate(listOf(startDate[0], month , day.toInt())) 370 | setEndBool(true) 371 | } 372 | } 373 | } 374 | 375 | 376 | private fun calculateFirstDayOffset(date : List) : Int{ 377 | return JalaliCalendar(date[0].toInt(), date[1] + 1 , 1).dayOfWeek 378 | } 379 | 380 | private fun daysOfMonth(date: List, startDate: List, endDate: List) : List{ 381 | var daysList = mutableListOf() 382 | 383 | val weekDay = calculateFirstDayOffset(date) 384 | if (weekDay != 7){ 385 | for (i in 1..weekDay){ 386 | daysList.add(" ") 387 | } 388 | } 389 | 390 | if (startDate[1] < 6){ 391 | for (i in 1..31){ 392 | daysList.add(i.toString()) 393 | } 394 | } else { 395 | for (i in 1..30){ 396 | daysList.add(i.toString()) 397 | } 398 | } 399 | return daysList 400 | } 401 | 402 | @Composable 403 | private fun decideDayColor(day : String, startDate: List, endDate: List, end : Boolean, month : Int) : Color { 404 | 405 | if (day != " "){ 406 | if ((day == startDate[2].toString() && month == startDate[1]) || (day == endDate[2].toString() && month == endDate[1])){ 407 | return MaterialTheme.colors.primary 408 | } else if (isBetweenStartEnd(day, startDate, endDate, month) && end) { 409 | Log.i("TAG_yyy", "Found") 410 | return MaterialTheme.colors.primary.copy(.1f) 411 | } 412 | return Color.Transparent 413 | } 414 | return Color.Transparent 415 | } 416 | 417 | @Composable 418 | private fun decideDayText(day : String, startDate: List, endDate: List, month : Int) : Color { 419 | if (day != " "){ 420 | if ((startDate[2].toString() == day && month == startDate[1]) || (endDate[2].toString() == day && month == endDate[1])){ 421 | return MaterialTheme.colors.onPrimary 422 | } else { 423 | return MaterialTheme.colors.onBackground.copy(.7f) 424 | } 425 | } 426 | return Color.Transparent 427 | } 428 | 429 | private fun decideDayShape(day : String, month: Int, startDate: List, endDate: List) : RoundedCornerShape{ 430 | 431 | val cornerRadius = 13.dp 432 | if (day != " "){ 433 | if (day == startDate[2].toString() && month == startDate[1]){ 434 | return RoundedCornerShape(topStart = cornerRadius, bottomStart = cornerRadius) 435 | } else if (day == endDate[2].toString() && month == endDate[1]) { 436 | return RoundedCornerShape(topEnd = cornerRadius, bottomEnd = cornerRadius) 437 | } else if (isBetweenStartEnd(day, startDate, endDate, month)){ 438 | return RoundedCornerShape(0.dp) 439 | } 440 | return RoundedCornerShape(0.dp) 441 | } 442 | return RoundedCornerShape(0.dp) 443 | } 444 | 445 | private fun isBetweenStartEnd(value : String, startDate: List, endDate: List, currentMonth : Int) : Boolean { 446 | if (value != " "){ 447 | if (currentMonth == startDate[1] && currentMonth == endDate[1]){ 448 | if (value.toInt() > startDate[2] && value.toInt() < endDate[2]){ 449 | return true 450 | } 451 | } else if (currentMonth == startDate[1]){ 452 | if (value.toInt() > startDate[2]){ 453 | return true 454 | } 455 | } else if (currentMonth < endDate[1] && currentMonth > startDate[1]){ 456 | return true 457 | } else if (currentMonth <= endDate[1] && currentMonth > startDate[1]){ 458 | if (value.toInt() < endDate[2]){ 459 | return true 460 | } 461 | } 462 | return false 463 | } 464 | return false 465 | } 466 | 467 | private fun increaseMonth(mMonth: String, mYear: String,setMonth: (String) -> Unit, setYear: (String) -> Unit) { 468 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 469 | if (monthsList.indexOf(mMonth) < 10){ 470 | setMonth(monthsList[monthsList.indexOf(mMonth) + 1]) 471 | } else { 472 | setMonth(monthsList[0]) 473 | setYear((mYear.toInt() + 1).toString()) 474 | } 475 | } 476 | 477 | private fun decreaseMonth(mMonth: String, mYear: String,setMonth: (String) -> Unit, setYear: (String) -> Unit) { 478 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 479 | if (monthsList.indexOf(mMonth) > 0){ 480 | setMonth(monthsList[monthsList.indexOf(mMonth) - 1]) 481 | } else { 482 | setMonth(monthsList[11]) 483 | setYear((mYear.toInt() - 1).toString()) 484 | } 485 | } 486 | -------------------------------------------------------------------------------- /.idea/dbnavigator.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 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | -------------------------------------------------------------------------------- /persian_date_picker/src/main/java/com/example/persian_date_picker/PersianDatePicker.kt: -------------------------------------------------------------------------------- 1 | package com.example.persian_date_picker 2 | 3 | import android.util.Log 4 | import androidx.compose.animation.Crossfade 5 | import androidx.compose.foundation.BorderStroke 6 | import androidx.compose.foundation.ExperimentalFoundationApi 7 | import androidx.compose.foundation.background 8 | import androidx.compose.foundation.clickable 9 | import androidx.compose.foundation.layout.* 10 | import androidx.compose.foundation.lazy.* 11 | import androidx.compose.foundation.lazy.grid.GridCells 12 | import androidx.compose.foundation.lazy.grid.LazyVerticalGrid 13 | import androidx.compose.foundation.lazy.grid.items 14 | import androidx.compose.foundation.shape.CircleShape 15 | import androidx.compose.foundation.shape.RoundedCornerShape 16 | import androidx.compose.foundation.text.KeyboardActions 17 | import androidx.compose.foundation.text.KeyboardOptions 18 | import androidx.compose.material.* 19 | import androidx.compose.material.icons.Icons 20 | import androidx.compose.material.icons.filled.ChevronLeft 21 | import androidx.compose.material.icons.filled.ChevronRight 22 | import androidx.compose.material.icons.filled.Edit 23 | import androidx.compose.runtime.* 24 | import androidx.compose.ui.Alignment 25 | import androidx.compose.ui.Modifier 26 | import androidx.compose.ui.draw.clip 27 | import androidx.compose.ui.focus.FocusDirection 28 | import androidx.compose.ui.graphics.Color 29 | import androidx.compose.ui.platform.LocalConfiguration 30 | import androidx.compose.ui.platform.LocalFocusManager 31 | import androidx.compose.ui.text.font.FontWeight 32 | import androidx.compose.ui.text.input.ImeAction 33 | import androidx.compose.ui.text.input.KeyboardType 34 | import androidx.compose.ui.unit.dp 35 | import androidx.compose.ui.window.Dialog 36 | import androidx.core.text.isDigitsOnly 37 | import ir.huri.jcal.JalaliCalendar 38 | import kotlinx.coroutines.launch 39 | import java.time.Year 40 | 41 | @Composable 42 | fun PersianDatePicker( 43 | onDismiss : (Boolean) -> Unit, 44 | minYear: Int = 1350, 45 | maxYear: Int = 1420, 46 | positiveButtonTxt : String = "تایید", 47 | negativeButtonTxt : String = "لغو", 48 | shortWeekDays: Boolean = false, 49 | setDate : (Map) -> Unit 50 | ){ 51 | 52 | val today = JalaliCalendar().day 53 | val month = JalaliCalendar().month 54 | val year = JalaliCalendar().year 55 | 56 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 57 | 58 | var selectedPart by remember { 59 | mutableStateOf("main") 60 | } 61 | 62 | var mMonth by remember { 63 | mutableStateOf(monthsList[month - 1]) 64 | } 65 | 66 | var mYear by remember { 67 | mutableStateOf(year.toString()) 68 | } 69 | 70 | var mDay by remember { 71 | mutableStateOf(today.toString()) 72 | } 73 | 74 | val width = LocalConfiguration.current.screenWidthDp 75 | val height = LocalConfiguration.current.screenHeightDp * .6 76 | 77 | Dialog( 78 | onDismissRequest = { onDismiss(true) } 79 | ) { 80 | Card( 81 | modifier = Modifier 82 | .size(width = width.dp, height = 530.dp) 83 | .padding(5.dp), 84 | shape = RoundedCornerShape(10.dp), 85 | elevation = 4.dp, 86 | backgroundColor = MaterialTheme.colors.background 87 | ) { 88 | Column( 89 | Modifier 90 | .fillMaxSize() 91 | .padding(horizontal = 0.dp), 92 | verticalArrangement = Arrangement.SpaceBetween, 93 | horizontalAlignment = Alignment.CenterHorizontally 94 | ) { 95 | MainContent( 96 | mMonth, mYear, mDay, 97 | minYear = minYear , 98 | maxYear = maxYear , 99 | shortWeekDays = shortWeekDays, 100 | selectedPart,{mDay = it}, 101 | setMonth = {mMonth = it}, 102 | setYear = {mYear = it} ){selectedPart = it} 103 | 104 | Row( 105 | Modifier 106 | .fillMaxWidth() 107 | .padding(15.dp) 108 | , 109 | verticalAlignment = Alignment.CenterVertically, 110 | horizontalArrangement = Arrangement.End 111 | ) { 112 | 113 | Text( 114 | text = negativeButtonTxt, 115 | color = MaterialTheme.colors.primary, 116 | style = MaterialTheme.typography.h5, 117 | modifier = Modifier 118 | .clickable { 119 | onDismiss(true) 120 | } 121 | .padding(horizontal = 10.dp) 122 | ) 123 | Text( 124 | text = positiveButtonTxt, 125 | color = MaterialTheme.colors.primary, 126 | style = MaterialTheme.typography.h5, 127 | modifier = Modifier 128 | .clickable { 129 | onDismiss(true) 130 | setDate( 131 | mapOf( 132 | "day" to mDay, 133 | "month" to (monthsList.indexOf(mMonth) + 1).toString(), 134 | "year" to mYear 135 | ) 136 | ) 137 | } 138 | .padding(horizontal = 15.dp) 139 | ) 140 | 141 | } 142 | } 143 | 144 | } 145 | } 146 | } 147 | 148 | @Composable 149 | private fun MainContent( 150 | mMonth: String, 151 | mYear : String, 152 | mDay : String, 153 | minYear: Int, 154 | maxYear: Int, 155 | shortWeekDays : Boolean, 156 | selectedPart : String, 157 | setDay : (String) -> Unit, 158 | setMonth: (String) -> Unit, 159 | setYear: (String) -> Unit, 160 | setSelected : (String) -> Unit 161 | ){ 162 | 163 | val width = LocalConfiguration.current.screenWidthDp 164 | val persianWeekDays = listOf("شنبه","یکشنبه","دوشنبه","سه شنبه","چهارشنبه","پنجشنبه","جمعه", ) 165 | 166 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 167 | val weekDay = JalaliCalendar(mYear.toInt(), monthsList.indexOf(mMonth) + 1, mDay.toInt()).dayOfWeek 168 | 169 | var inputFormat by remember { 170 | // manual, selection 171 | mutableStateOf("selection") 172 | } 173 | 174 | Column( 175 | horizontalAlignment = Alignment.CenterHorizontally, 176 | verticalArrangement = Arrangement.SpaceBetween 177 | ) { 178 | Column() { 179 | 180 | Row( 181 | Modifier 182 | .height(30.dp) 183 | .fillMaxWidth() 184 | .background(MaterialTheme.colors.primary) 185 | .padding(vertical = 10.dp, horizontal = 25.dp), 186 | verticalAlignment = Alignment.CenterVertically, 187 | horizontalArrangement = Arrangement.End 188 | ) { 189 | //Text(text = "انتخاب تاریخ", color = MaterialTheme.colors.onPrimary, style = MaterialTheme.typography.body2) 190 | } 191 | 192 | Row( 193 | modifier = Modifier 194 | .fillMaxWidth() 195 | .background(MaterialTheme.colors.primary) 196 | .padding(vertical = 10.dp, horizontal = 25.dp), 197 | verticalAlignment = Alignment.CenterVertically, 198 | horizontalArrangement = Arrangement.SpaceBetween 199 | ) { 200 | Icon( 201 | Icons.Default.Edit, 202 | contentDescription = null, 203 | tint = MaterialTheme.colors.onPrimary, 204 | modifier = Modifier 205 | .clip(CircleShape) 206 | .clickable { 207 | inputFormat = if (inputFormat == "selection") { 208 | "manual" 209 | } else { 210 | "selection" 211 | } 212 | } 213 | ) 214 | Row( 215 | verticalAlignment = Alignment.CenterVertically, 216 | horizontalArrangement = Arrangement.End 217 | ){ 218 | Text( 219 | text = mMonth, 220 | style = MaterialTheme.typography.h5, 221 | color = MaterialTheme.colors.onPrimary, 222 | modifier = Modifier 223 | .padding(horizontal = 5.dp) 224 | .clickable { 225 | setSelected("month") 226 | } 227 | ) 228 | Text(text = mDay, style = MaterialTheme.typography.h5, color = MaterialTheme.colors.onPrimary) 229 | Text(text = persianWeekDays[weekDay - 1] , style = MaterialTheme.typography.h5, color = MaterialTheme.colors.onPrimary, modifier = Modifier.padding(horizontal = 5.dp)) 230 | 231 | } 232 | } 233 | 234 | Row( 235 | Modifier 236 | .fillMaxWidth() 237 | .padding(horizontal = 20.dp, vertical = 13.dp), 238 | verticalAlignment = Alignment.CenterVertically, 239 | horizontalArrangement = Arrangement.SpaceBetween 240 | ) { 241 | Row() { 242 | Text( 243 | text = mYear, 244 | style = MaterialTheme.typography.body1, 245 | color = MaterialTheme.colors.onBackground.copy(.7f), 246 | modifier = Modifier.clickable { 247 | setSelected("year") 248 | } 249 | ) 250 | Text( 251 | text = mMonth, 252 | style = MaterialTheme.typography.body1, 253 | color = MaterialTheme.colors.onBackground.copy(.7f), 254 | modifier = Modifier 255 | .padding(horizontal = 8.dp) 256 | .clickable { 257 | setSelected("month") 258 | } 259 | ) 260 | } 261 | 262 | Row() { 263 | if (selectedPart == "main") { 264 | Icon( 265 | Icons.Default.ChevronLeft, 266 | contentDescription = null, 267 | tint = MaterialTheme.colors.onBackground.copy(.8f), 268 | modifier = Modifier 269 | .padding(horizontal = 5.dp) 270 | .clip(CircleShape) 271 | .clickable { 272 | decreaseMonth( 273 | mMonth, 274 | mYear, 275 | setMonth = { setMonth(it) }, 276 | setYear = { setYear(it) }) 277 | } 278 | ) 279 | 280 | Icon( 281 | Icons.Default.ChevronRight, 282 | contentDescription = null, 283 | tint = MaterialTheme.colors.onBackground.copy(.8f), 284 | modifier = Modifier 285 | .padding(horizontal = 5.dp) 286 | .clip(CircleShape) 287 | .clickable { 288 | increaseMonth( 289 | mMonth, 290 | mYear, 291 | setMonth = { setMonth(it) }, 292 | setYear = { setYear(it) }) 293 | } 294 | ) 295 | } 296 | } 297 | 298 | } 299 | 300 | Crossfade(targetState = inputFormat) { format -> 301 | when(format){ 302 | "selection" -> 303 | Crossfade(selectedPart) { part -> 304 | when(part){ 305 | "main" -> Days(mMonth, mDay, mYear, shortWeekDays,setDay = {setDay(it)}, changeSelectedPart = {}) 306 | "month" -> Months(mMonth,{setSelected("main")} ){setMonth(it)} 307 | "year" -> Years(mYear, minYear, maxYear,setYear = {setYear(it)}, changeSelectedPart = {setSelected("main")}) 308 | else -> Days(mMonth, mDay, mYear,shortWeekDays, setDay = {setDay(it)}, changeSelectedPart = {}) 309 | } 310 | } 311 | "manual" -> ManualDatePick( { setDay(it) }, {setMonth(it)}, {setYear(it)}) 312 | } 313 | } 314 | } 315 | } 316 | } 317 | 318 | @Composable 319 | private fun ManualDatePick( 320 | setDay: (String) -> Unit, 321 | setMonth: (String) -> Unit, 322 | setYear: (String) -> Unit 323 | ){ 324 | 325 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 326 | 327 | var cDay by remember { 328 | mutableStateOf("") 329 | } 330 | 331 | var cMonth by remember { 332 | mutableStateOf("") 333 | } 334 | 335 | var cYear by remember { 336 | mutableStateOf("") 337 | } 338 | 339 | val focusManager = LocalFocusManager.current 340 | 341 | Row( 342 | Modifier.fillMaxWidth().padding(vertical = 35.dp), 343 | verticalAlignment = Alignment.CenterVertically, 344 | horizontalArrangement = Arrangement.SpaceEvenly 345 | ) { 346 | OutlinedTextField( 347 | value = cYear, 348 | onValueChange = { 349 | cYear = it 350 | setManualYear(it){v-> 351 | setYear(it) 352 | } 353 | }, 354 | textStyle = MaterialTheme.typography.h5, 355 | label = { Text(text = "سال")}, 356 | keyboardOptions = KeyboardOptions( 357 | keyboardType = KeyboardType.Number, 358 | imeAction = ImeAction.Done 359 | ), 360 | keyboardActions = KeyboardActions( 361 | onDone = { focusManager.clearFocus()} 362 | ), 363 | singleLine = true, 364 | maxLines = 1, 365 | modifier = Modifier.width(70.dp), 366 | shape = RoundedCornerShape(10.dp) 367 | ) 368 | OutlinedTextField( 369 | value = cMonth, 370 | onValueChange = { 371 | 372 | setManualMonth(it, {cMonth = it}){ v -> 373 | setMonth(monthsList[v.toInt() - 1]) 374 | } 375 | }, 376 | textStyle = MaterialTheme.typography.h5, 377 | label = { Text(text = "ماه")}, 378 | keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Previous), 379 | keyboardActions = KeyboardActions( 380 | onPrevious = { focusManager.moveFocus(FocusDirection.Left)} 381 | ), 382 | singleLine = true, 383 | maxLines = 1, 384 | modifier = Modifier.width(70.dp), 385 | shape = RoundedCornerShape(10.dp) 386 | ) 387 | OutlinedTextField( 388 | value = cDay, 389 | onValueChange = { 390 | cDay = it 391 | setManualDay(it){ v -> 392 | setDay(v) 393 | } }, 394 | textStyle = MaterialTheme.typography.h5, 395 | label = { Text(text = "روز")}, 396 | keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Previous), 397 | keyboardActions = KeyboardActions( 398 | onPrevious = { focusManager.moveFocus(FocusDirection.Left)}, 399 | ), 400 | singleLine = true, 401 | maxLines = 1, 402 | modifier = Modifier.width(60.dp), 403 | shape = RoundedCornerShape(10.dp) 404 | ) 405 | 406 | } 407 | } 408 | 409 | private fun setManualDay(value: String, setDay: (String) -> Unit){ 410 | if (value.isNotEmpty() && value.isDigitsOnly()){ 411 | when{ 412 | value.toInt() < 1 -> setDay("1") 413 | value.toInt() > 31 -> setDay("31") 414 | else -> setDay(value) 415 | } 416 | } 417 | } 418 | 419 | private fun setManualMonth(value: String, setCMonth: (String) -> Unit,setMonth: (String) -> Unit){ 420 | if (value != "" && value.isDigitsOnly()){ 421 | if (value.toInt() in 1..12){ 422 | setCMonth(value) 423 | } 424 | } else { 425 | setMonth(value) 426 | } 427 | 428 | if (value.isNotEmpty() && value.isDigitsOnly()){ 429 | when{ 430 | value.toInt() < 1 -> setMonth("1") 431 | value.toInt() > 12 -> setMonth("12") 432 | else -> setMonth(value) 433 | } 434 | } 435 | } 436 | 437 | private fun setManualYear(value: String, setYear: (String) -> Unit){ 438 | if (value.isNotEmpty() && value.isDigitsOnly()){ 439 | if (value.length == 4){ 440 | setYear(value) 441 | } 442 | } 443 | } 444 | 445 | private fun increaseMonth(mMonth: String, mYear: String,setMonth: (String) -> Unit, setYear: (String) -> Unit) { 446 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 447 | if (monthsList.indexOf(mMonth) < 10){ 448 | setMonth(monthsList[monthsList.indexOf(mMonth) + 1]) 449 | } else { 450 | setMonth(monthsList[0]) 451 | setYear((mYear.toInt() + 1).toString()) 452 | } 453 | } 454 | 455 | private fun decreaseMonth(mMonth: String, mYear: String,setMonth: (String) -> Unit, setYear: (String) -> Unit) { 456 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 457 | if (monthsList.indexOf(mMonth) > 0){ 458 | setMonth(monthsList[monthsList.indexOf(mMonth) - 1]) 459 | } else { 460 | setMonth(monthsList[11]) 461 | setYear((mYear.toInt() - 1).toString()) 462 | } 463 | } 464 | 465 | 466 | @Composable 467 | private fun Months(mMonth : String, setSelected: () -> Unit ,setMonth : (String) -> Unit){ 468 | 469 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 470 | 471 | LazyVerticalGrid( 472 | modifier = Modifier.fillMaxWidth(), 473 | columns = GridCells.Fixed(3), 474 | contentPadding = PaddingValues(16.dp), 475 | verticalArrangement = Arrangement.Center, 476 | horizontalArrangement = Arrangement.Center 477 | ){ 478 | items(monthsList){ 479 | Surface( 480 | modifier = Modifier 481 | .padding(5.dp) 482 | .size(60.dp) 483 | .clip(CircleShape) 484 | .clickable { 485 | setMonth(it) 486 | setSelected() 487 | } 488 | , 489 | shape = CircleShape, 490 | color = if (mMonth == it) MaterialTheme.colors.primary else Color.Transparent, 491 | 492 | ) { 493 | Column( 494 | Modifier.fillMaxSize(), 495 | verticalArrangement = Arrangement.Center, 496 | horizontalAlignment = Alignment.CenterHorizontally 497 | ) { 498 | Text(text = it, color = if (mMonth == it) MaterialTheme.colors.onPrimary else MaterialTheme.colors.primary, style = MaterialTheme.typography.body1) 499 | } 500 | } 501 | } 502 | } 503 | } 504 | 505 | 506 | @Composable 507 | private fun Days(mMonth: String,mDay : String , mYear: String ,shortWeekDays: Boolean, setDay : (String) -> Unit, changeSelectedPart : (String) -> Unit){ 508 | 509 | val monthsList = listOf("فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",) 510 | val weekDays = listOf("شنبه","یکشنبه","دوشنبه","سه شنبه","چهارشنبه","پنجشنبه","جمعه", ) 511 | val persianWeekDaysShort = listOf("ش","ی","د","س","چ","پ","ج",) 512 | 513 | var weekDay = JalaliCalendar(mYear.toInt(), monthsList.indexOf(mMonth) + 1 , 1).dayOfWeek 514 | 515 | var today = JalaliCalendar().day 516 | val thisMonth = JalaliCalendar().month -1 517 | Log.i("TAG_month","$thisMonth") 518 | 519 | var daysList = mutableListOf() 520 | 521 | Log.i("TAG_weekday", "$weekDay") 522 | 523 | if (weekDay != 7){ 524 | for (i in 1..weekDay){ 525 | daysList.add(" ") 526 | } 527 | } 528 | 529 | if (monthsList.indexOf(mMonth) < 6){ 530 | for (i in 1..31){ 531 | daysList.add(i.toString()) 532 | } 533 | } else { 534 | for (i in 1..30){ 535 | daysList.add(i.toString()) 536 | if (mDay.toInt() > 30){ 537 | setDay("30") 538 | } 539 | } 540 | } 541 | Column( 542 | Modifier 543 | .fillMaxWidth() 544 | .padding(top = 10.dp)) { 545 | Row( 546 | Modifier 547 | .fillMaxWidth() 548 | .padding(vertical = 0.dp, horizontal = 25.dp), 549 | verticalAlignment = Alignment.CenterVertically, 550 | horizontalArrangement = Arrangement.SpaceBetween 551 | ) { 552 | if (shortWeekDays){ 553 | persianWeekDaysShort.forEach{ 554 | Text(text = it, color = MaterialTheme.colors.primary.copy(.4f), style = MaterialTheme.typography.subtitle2) 555 | } 556 | } else { 557 | weekDays.forEach{ 558 | Text(text = it, color = MaterialTheme.colors.primary.copy(.4f), style = MaterialTheme.typography.subtitle2) 559 | } 560 | } 561 | } 562 | LazyVerticalGrid( 563 | columns = GridCells.Fixed(7), 564 | modifier = Modifier.fillMaxWidth(), 565 | contentPadding = PaddingValues(horizontal = 15.dp, vertical = 0.dp), 566 | verticalArrangement = Arrangement.Top, 567 | horizontalArrangement = Arrangement.Center 568 | ){ 569 | items(daysList){ 570 | Surface( 571 | modifier = Modifier 572 | .padding(vertical = 1.dp) 573 | .size(45.dp) 574 | .clip(CircleShape) 575 | .clickable { 576 | if (it != " ") { 577 | changeSelectedPart("main") 578 | setDay(it) 579 | } 580 | }, 581 | shape = CircleShape, 582 | color = if (mDay == it) MaterialTheme.colors.primary else Color.Transparent, 583 | border = BorderStroke( 1.dp, color = if (it == today.toString() && monthsList.indexOf(mMonth) == thisMonth) MaterialTheme.colors.primary else Color.Transparent) 584 | ) { 585 | Row(Modifier.fillMaxSize(), 586 | verticalAlignment = Alignment.CenterVertically, 587 | horizontalArrangement = Arrangement.Center) { 588 | Text(text = it, style = MaterialTheme.typography.body1, color = if (mDay == it) MaterialTheme.colors.onPrimary else MaterialTheme.colors.onBackground.copy(.7f)) 589 | } 590 | } 591 | } 592 | } 593 | 594 | } 595 | } 596 | 597 | 598 | @Composable 599 | private fun Years(mYear: String, minYear: Int, maxYear: Int, setYear : (String) -> Unit, changeSelectedPart: (String) -> Unit){ 600 | 601 | var years = mutableListOf() 602 | for (y in maxYear downTo minYear){ 603 | years.add(y) 604 | } 605 | 606 | var gridState = rememberLazyListState() 607 | val scope = rememberCoroutineScope() 608 | LaunchedEffect(key1 = 1){ 609 | scope.launch { 610 | gridState.scrollToItem(28) 611 | } 612 | } 613 | 614 | LazyColumn( 615 | modifier = Modifier.fillMaxSize(), 616 | contentPadding = PaddingValues(18.dp), 617 | verticalArrangement = Arrangement.Center, 618 | horizontalAlignment = Alignment.CenterHorizontally, 619 | state = gridState 620 | ){ 621 | items(years){ 622 | Surface( 623 | modifier = Modifier 624 | .padding(15.dp) 625 | .size(60.dp) 626 | .clip(CircleShape) 627 | .clickable { 628 | changeSelectedPart("main") 629 | setYear(it.toString()) 630 | }, 631 | shape = CircleShape, 632 | color = if (mYear == it.toString()) MaterialTheme.colors.primary else Color.Transparent 633 | ) { 634 | Row(Modifier.fillMaxSize(), 635 | verticalAlignment = Alignment.CenterVertically, 636 | horizontalArrangement = Arrangement.Center) { 637 | Text(text = it.toString(), style = MaterialTheme.typography.h5, color = if (mYear == it.toString()) Color.White else MaterialTheme.colors.primary) 638 | } 639 | } 640 | } 641 | } 642 | 643 | } 644 | 645 | 646 | 647 | --------------------------------------------------------------------------------