├── .editorconfig ├── .github ├── ci-gradle.properties └── workflows │ ├── build.yml │ └── gradle-wrapper-validation.yml ├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── paulrybitskyi │ │ └── commons │ │ └── sample │ │ └── MainActivity.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle.kts ├── buildSrc ├── .gitignore ├── build.gradle.kts └── src │ └── main │ └── java │ ├── Dependencies.kt │ ├── Plugins.kt │ └── ProjectExtensions.kt ├── checksum.sh ├── commons-device-info ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── paulrybitskyi │ └── commons │ └── device │ └── info │ ├── ContextExtensions.kt │ └── model │ ├── DeviceInfo.kt │ ├── ProductInfo.kt │ └── screen │ ├── ScreenDensity.kt │ ├── ScreenDensityGroup.kt │ ├── ScreenDimension.kt │ ├── ScreenMetrics.kt │ ├── ScreenScalingFactors.kt │ └── ScreenSizeCategory.kt ├── commons-ktx ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── paulrybitskyi │ └── commons │ └── ktx │ ├── ActivityExtensions.kt │ ├── AlarmManagerExtensions.kt │ ├── BitmapExtensions.kt │ ├── BundleExtensions.kt │ ├── ContextExtensions.kt │ ├── DialogExtensions.kt │ ├── DrawableExtensions.kt │ ├── FileExtensions.kt │ ├── FragmentExtensions.kt │ ├── FragmentManagerExtensions.kt │ ├── IntentExtensions.kt │ ├── ListExtensions.kt │ ├── LiveDataExtensions.kt │ ├── MapExtensions.kt │ ├── NumberExtensions.kt │ ├── PackageManagerExtensions.kt │ ├── SpannableExtensions.kt │ ├── StringExtensions.kt │ ├── TypedArrayExtensions.kt │ ├── ViewExtensions.kt │ ├── ViewGroupExtensions.kt │ ├── ViewPropertyAnimatorExtensions.kt │ ├── WindowExtensions.kt │ ├── WindowInsetsExtensions.kt │ ├── drawing │ ├── CanvasExtensions.kt │ ├── FontMetricsExtensions.kt │ ├── PaintExtensions.kt │ ├── PathExtensions.kt │ └── RectExtensions.kt │ └── views │ ├── CheckBoxExtensions.kt │ ├── EditTextExtensions.kt │ ├── ImageViewExtensions.kt │ ├── MenuExtensions.kt │ ├── MotionLayoutExtensions.kt │ ├── NestedScrollViewExtensions.kt │ ├── ProgressBarExtensions.kt │ ├── ScrollViewExtensions.kt │ ├── SeekBarExtensions.kt │ ├── SwitchCompatExtensions.kt │ ├── TextViewExtensions.kt │ ├── ViewPager2Extensions.kt │ └── ViewPagerExtensions.kt ├── commons-listeners ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── paulrybitskyi │ └── commons │ └── listeners │ ├── QueryListener.kt │ ├── adapters │ ├── ActivityLifecycleCallbacksAdapter.kt │ ├── AnimationListenerAdapter.kt │ ├── OnSeekBarChangeListenerAdapter.kt │ └── TextWatcherAdapter.kt │ ├── gestures │ ├── GestureCallbackAdapter.kt │ └── GestureListener.kt │ └── utils │ └── EditTextExtensions.kt ├── commons-material ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── paulrybitskyi │ └── commons │ └── material │ ├── OnTabSelectedListenerAdapter.kt │ └── utils │ ├── BottomNavViewExtensions.kt │ ├── CardViewExtensions.kt │ ├── ChipDrawableExtensions.kt │ ├── MaterialCardViewExtensions.kt │ └── TabLayoutExtensions.kt ├── commons-navigation ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── paulrybitskyi │ └── commons │ └── navigation │ ├── FragmentExtensions.kt │ └── NavControllerExtensions.kt ├── commons-network ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── paulrybitskyi │ └── commons │ └── network │ ├── ContextExtensions.kt │ ├── model │ ├── NetworkInfo.kt │ └── NetworkType.kt │ └── utils │ ├── NetworkCallback.kt │ ├── NetworkListener.kt │ └── NetworkTypeProvider.kt ├── commons-recyclerview ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── paulrybitskyi │ └── commons │ └── recyclerview │ ├── RecyclerViewScrollListener.kt │ ├── decorators │ ├── GridSpacingItemDecorator.kt │ └── spacing │ │ ├── SpacingItemDecorator.kt │ │ └── policies │ │ ├── FirstItemExclusionPolicy.kt │ │ └── LastItemExclusionPolicy.kt │ └── utils │ └── RecyclerViewExtensions.kt ├── commons-widgets ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── paulrybitskyi │ │ └── commons │ │ └── widgets │ │ ├── AdvancedEditText.kt │ │ ├── AdvancedViewPager.kt │ │ ├── InfoView.kt │ │ └── toolbar │ │ ├── ButtonInfo.kt │ │ ├── TitleGravity.kt │ │ ├── Toolbar.kt │ │ └── configs │ │ ├── ButtonConfig.kt │ │ └── TitleConfig.kt │ └── res │ ├── layout │ ├── view_info.xml │ └── view_toolbar.xml │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── commons-window-anims ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── paulrybitskyi │ │ └── commons │ │ └── window │ │ └── anims │ │ ├── ActivityExtensions.kt │ │ └── WindowAnimations.kt │ └── res │ ├── anim │ ├── fade_in_animation.xml │ ├── fade_out_animation.xml │ ├── horizontal_sliding_window_a_enter_animation.xml │ ├── horizontal_sliding_window_a_exit_animation.xml │ ├── horizontal_sliding_window_b_enter_animation.xml │ ├── horizontal_sliding_window_b_exit_animation.xml │ ├── kitkat_scaling_window_a_enter_animation.xml │ ├── kitkat_scaling_window_a_exit_animation.xml │ ├── kitkat_scaling_window_b_enter_animation.xml │ ├── kitkat_scaling_window_b_exit_animation.xml │ ├── no_window_animation.xml │ ├── overshoot_scaling_window_a_enter_animation.xml │ ├── overshoot_scaling_window_a_exit_animation.xml │ ├── overshoot_scaling_window_b_enter_animation.xml │ ├── overshoot_scaling_window_b_exit_animation.xml │ ├── sliding_animation_decelerate_interpolator.xml │ ├── vertical_sliding_window_a_enter_animation.xml │ ├── vertical_sliding_window_a_exit_animation.xml │ ├── vertical_sliding_window_b_enter_animation.xml │ └── vertical_sliding_window_b_exit_animation.xml │ └── values │ └── integers.xml ├── commons ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── paulrybitskyi │ └── commons │ ├── SdkInfo.kt │ └── utils │ ├── DelegateUtils.kt │ └── ViewBindingUtils.kt ├── config └── detekt │ └── detekt.yml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── hooks └── pre-push ├── publishing.gradle.kts └── settings.gradle.kts /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset = utf-8 3 | indent_size = unset 4 | indent_style = space 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | max_line_length = 120 8 | 9 | [*.yml] 10 | indent_size = 2 11 | -------------------------------------------------------------------------------- /.github/ci-gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | org.gradle.daemon=false 18 | org.gradle.parallel=true 19 | org.gradle.jvmargs=-Xmx5120m 20 | org.gradle.workers.max=2 21 | 22 | # https://stackoverflow.com/questions/50138863/why-does-my-kotlin-gradle-build-die-with-exit-code-137 23 | kotlin.compiler.execution.strategy=in-process 24 | -------------------------------------------------------------------------------- /.github/workflows/gradle-wrapper-validation.yml: -------------------------------------------------------------------------------- 1 | name: Gradle Wrapper Validation 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | validation: 11 | name: Gradle Wrapper Validation 12 | runs-on: ubuntu-latest 13 | if: ${{ !contains(github.event.head_commit.message, '[ci skip]') }} 14 | 15 | steps: 16 | - name: Checkout Repo 17 | uses: actions/checkout@v2 18 | 19 | - name: Validate Gradle Wrapper 20 | uses: gradle/wrapper-validation-action@v1 21 | -------------------------------------------------------------------------------- /.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 | .idea 16 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidApplication() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | applicationId = appConfig.applicationId 27 | minSdk = appConfig.minSdkVersion 28 | targetSdk = appConfig.targetSdkVersion 29 | 30 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 31 | } 32 | 33 | buildTypes { 34 | getByName("release") { 35 | isMinifyEnabled = false 36 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 37 | } 38 | } 39 | 40 | compileOptions { 41 | sourceCompatibility = appConfig.javaCompatibilityVersion 42 | targetCompatibility = appConfig.javaCompatibilityVersion 43 | } 44 | 45 | kotlinOptions { 46 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 47 | } 48 | } 49 | 50 | dependencies { 51 | implementation(project(deps.local.commons)) 52 | implementation(project(deps.local.commonsKtx)) 53 | implementation(project(deps.local.commonsWindowAnims)) 54 | implementation(project(deps.local.commonsRecyclerView)) 55 | implementation(project(deps.local.commonsMaterial)) 56 | implementation(project(deps.local.commonsNavigation)) 57 | implementation(project(deps.local.commonsDeviceInfo)) 58 | implementation(project(deps.local.commonsNetwork)) 59 | implementation(project(deps.local.commonsWidgets)) 60 | implementation(project(deps.local.commonsListeners)) 61 | 62 | implementation(deps.appCompat) 63 | implementation(deps.constraintLayout) 64 | } 65 | 66 | val installGitHook by tasks.registering(Copy::class) { 67 | from(File(rootProject.rootDir, "hooks/pre-push")) 68 | into(File(rootProject.rootDir, ".git/hooks/")) 69 | // https://github.com/gradle/kotlin-dsl-samples/issues/1412 70 | fileMode = 0b111101101 // -rwxr-xr-x 71 | } 72 | 73 | tasks.getByPath(":app:preBuild").dependsOn(installGitHook) 74 | -------------------------------------------------------------------------------- /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/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | 21 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/paulrybitskyi/commons/sample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.sample 18 | 19 | import androidx.appcompat.app.AppCompatActivity 20 | 21 | internal class MainActivity : AppCompatActivity(R.layout.activity_main) 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 26 | 27 | 36 | 37 | -------------------------------------------------------------------------------- /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/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | #6200EE 22 | #3700B3 23 | #03DAC5 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | AndroidCommons 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 24 | 25 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import io.gitlab.arturbosch.detekt.Detekt 18 | 19 | plugins { 20 | detekt() 21 | ktlint() 22 | gradleVersions() 23 | dokka() 24 | } 25 | 26 | buildscript { 27 | repositories { 28 | mavenCentral() 29 | google() 30 | gradlePluginPortal() 31 | } 32 | 33 | dependencies { 34 | classpath(deps.plugins.androidGradle) 35 | classpath(deps.plugins.kotlinGradle) 36 | classpath(deps.plugins.gradleVersions) 37 | classpath(deps.plugins.dokka) 38 | } 39 | } 40 | 41 | detekt { 42 | parallel = true 43 | buildUponDefaultConfig = true 44 | config = files("config/detekt/detekt.yml") 45 | } 46 | 47 | tasks.withType().configureEach { 48 | reports.html.required.set(true) 49 | } 50 | 51 | allprojects { 52 | apply(plugin = PLUGIN_DETEKT) 53 | apply(plugin = PLUGIN_KTLINT) 54 | 55 | repositories { 56 | mavenCentral() 57 | google() 58 | } 59 | 60 | configure { 61 | android.set(true) 62 | outputToConsole.set(true) 63 | reporters { 64 | reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.HTML) 65 | } 66 | } 67 | } 68 | 69 | val clean by tasks.registering(Delete::class) { 70 | delete(buildDir) 71 | } 72 | -------------------------------------------------------------------------------- /buildSrc/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | `kotlin-dsl` 19 | } 20 | 21 | repositories { 22 | mavenCentral() 23 | google() 24 | } 25 | 26 | dependencies { 27 | implementation("com.android.tools.build:gradle:7.2.2") 28 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0") 29 | } 30 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/Plugins.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import org.gradle.kotlin.dsl.version 18 | import org.gradle.plugin.use.PluginDependenciesSpec 19 | import org.gradle.plugin.use.PluginDependencySpec 20 | 21 | const val PLUGIN_DETEKT = "io.gitlab.arturbosch.detekt" 22 | const val PLUGIN_KTLINT = "org.jlleitschuh.gradle.ktlint" 23 | const val PLUGIN_GRADLE_VERSIONS = "com.github.ben-manes.versions" 24 | const val PLUGIN_DOKKA = "org.jetbrains.dokka" 25 | const val PLUGIN_ANDROID_APPLICATION = "com.android.application" 26 | const val PLUGIN_ANDROID_LIBRARY = "com.android.library" 27 | const val PLUGIN_KOTLIN = "kotlin" 28 | const val PLUGIN_KOTLIN_ANDROID = "kotlin-android" 29 | const val PLUGIN_MAVEN_PUBLISH = "maven-publish" 30 | const val PLUGIN_SIGNING = "org.gradle.signing" 31 | 32 | fun PluginDependenciesSpec.detekt(): PluginDependencySpec { 33 | return (id(PLUGIN_DETEKT) version versions.detektPlugin) 34 | } 35 | 36 | fun PluginDependenciesSpec.ktlint(): PluginDependencySpec { 37 | return (id(PLUGIN_KTLINT) version versions.ktlintPlugin) 38 | } 39 | 40 | fun PluginDependenciesSpec.gradleVersions(): PluginDependencySpec { 41 | return (id(PLUGIN_GRADLE_VERSIONS) version versions.gradleVersionsPlugin) 42 | } 43 | 44 | fun PluginDependenciesSpec.dokka(): PluginDependencySpec { 45 | return (id(PLUGIN_DOKKA) version versions.dokkaPlugin) 46 | } 47 | 48 | fun PluginDependenciesSpec.androidApplication(): PluginDependencySpec { 49 | return id(PLUGIN_ANDROID_APPLICATION) 50 | } 51 | 52 | fun PluginDependenciesSpec.androidLibrary(): PluginDependencySpec { 53 | return id(PLUGIN_ANDROID_LIBRARY) 54 | } 55 | 56 | fun PluginDependenciesSpec.kotlin(): PluginDependencySpec { 57 | return id(PLUGIN_KOTLIN) 58 | } 59 | 60 | fun PluginDependenciesSpec.kotlinAndroid(): PluginDependencySpec { 61 | return id(PLUGIN_KOTLIN_ANDROID) 62 | } 63 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/ProjectExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import org.gradle.api.Project 18 | 19 | @Suppress("UNCHECKED_CAST") 20 | fun Project.property(key: String, default: T): T { 21 | return ((properties[key] as? T) ?: default) 22 | } 23 | -------------------------------------------------------------------------------- /checksum.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | RESULT_FILE=$1 3 | 4 | if [ -f $RESULT_FILE ]; then 5 | rm $RESULT_FILE 6 | fi 7 | touch $RESULT_FILE 8 | 9 | checksum_file() { 10 | echo $(openssl md5 $1 | awk '{print $2}') 11 | } 12 | 13 | FILES=() 14 | while read -r -d ''; do 15 | FILES+=("$REPLY") 16 | done < <(find . -type f \( -name "build.gradle*" -o -name "Dependencies.kt" -o -name "gradle-wrapper.properties" \) -print0) 17 | 18 | # Loop through files and append MD5 to result file 19 | for FILE in ${FILES[@]}; do 20 | echo $(checksum_file $FILE) >> $RESULT_FILE 21 | done 22 | # Now sort the file so that it is 23 | sort $RESULT_FILE -o $RESULT_FILE -------------------------------------------------------------------------------- /commons-device-info/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons-device-info/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | compileOptions { 40 | sourceCompatibility = appConfig.javaCompatibilityVersion 41 | targetCompatibility = appConfig.javaCompatibilityVersion 42 | } 43 | 44 | kotlinOptions { 45 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 46 | } 47 | } 48 | 49 | dependencies { 50 | implementation(project(deps.local.commonsKtx)) 51 | } 52 | 53 | publishingConfig.artifactName = publishingConfig.commonsDeviceInfoArtifactName 54 | publishingConfig.artifactVersion = publishingConfig.commonsDeviceInfoArtifactVersion 55 | 56 | apply(from = "../publishing.gradle.kts") 57 | -------------------------------------------------------------------------------- /commons-device-info/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 -------------------------------------------------------------------------------- /commons-device-info/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons-device-info/src/main/java/com/paulrybitskyi/commons/device/info/model/DeviceInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.device.info.model 18 | 19 | import com.paulrybitskyi.commons.device.info.model.screen.ScreenMetrics 20 | 21 | data class DeviceInfo( 22 | val productInfo: ProductInfo, 23 | val screenMetrics: ScreenMetrics 24 | ) 25 | -------------------------------------------------------------------------------- /commons-device-info/src/main/java/com/paulrybitskyi/commons/device/info/model/ProductInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.device.info.model 18 | 19 | data class ProductInfo( 20 | val modelName: String, 21 | val productName: String, 22 | val manufacturerName: String 23 | ) { 24 | 25 | val name: String 26 | get() = "$modelName $productName $manufacturerName" 27 | } 28 | -------------------------------------------------------------------------------- /commons-device-info/src/main/java/com/paulrybitskyi/commons/device/info/model/screen/ScreenDensityGroup.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.device.info.model.screen 18 | 19 | enum class ScreenDensityGroup(val title: String) { 20 | 21 | UNDEFINED("Undefined"), 22 | 23 | LOW("Low"), 24 | MEDIUM("Medium"), 25 | TV("TV"), 26 | HIGH("High"), 27 | XHIGH("XHigh"), 28 | XXHIGH("XXHigh"), 29 | XXXHIGH("XXXHigh") 30 | } 31 | -------------------------------------------------------------------------------- /commons-device-info/src/main/java/com/paulrybitskyi/commons/device/info/model/screen/ScreenDimension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.device.info.model.screen 18 | 19 | data class ScreenDimension( 20 | val sizeInPixels: Int, 21 | val sizeInDp: Float 22 | ) 23 | -------------------------------------------------------------------------------- /commons-device-info/src/main/java/com/paulrybitskyi/commons/device/info/model/screen/ScreenMetrics.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.device.info.model.screen 18 | 19 | data class ScreenMetrics( 20 | val width: ScreenDimension, 21 | val height: ScreenDimension, 22 | val sizeCategory: ScreenSizeCategory, 23 | val density: ScreenDensity, 24 | val scalingFactors: ScreenScalingFactors, 25 | val smallestWidthInDp: Int 26 | ) 27 | -------------------------------------------------------------------------------- /commons-device-info/src/main/java/com/paulrybitskyi/commons/device/info/model/screen/ScreenScalingFactors.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.device.info.model.screen 18 | 19 | data class ScreenScalingFactors( 20 | val pixelScalingFactor: Float, 21 | val textPixelScalingFactor: Float 22 | ) 23 | -------------------------------------------------------------------------------- /commons-device-info/src/main/java/com/paulrybitskyi/commons/device/info/model/screen/ScreenSizeCategory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.device.info.model.screen 18 | 19 | import android.content.res.Configuration 20 | 21 | enum class ScreenSizeCategory( 22 | val layoutSize: Int, 23 | val title: String 24 | ) { 25 | 26 | UNDEFINED( 27 | layoutSize = Configuration.SCREENLAYOUT_SIZE_UNDEFINED, 28 | title = "Undefined" 29 | ), 30 | SMALL( 31 | layoutSize = Configuration.SCREENLAYOUT_SIZE_SMALL, 32 | title = "Small" 33 | ), 34 | NORMAL( 35 | layoutSize = Configuration.SCREENLAYOUT_SIZE_NORMAL, 36 | title = "Normal" 37 | ), 38 | LARGE( 39 | layoutSize = Configuration.SCREENLAYOUT_SIZE_LARGE, 40 | title = "Large" 41 | ), 42 | XLARGE( 43 | layoutSize = Configuration.SCREENLAYOUT_SIZE_XLARGE, 44 | title = "XLarge" 45 | ); 46 | 47 | companion object { 48 | 49 | @JvmName("forLayoutSize") 50 | @JvmStatic 51 | internal fun Int.asScreenSizeCategory(): ScreenSizeCategory { 52 | return values().find { it.layoutSize == this } 53 | ?: UNDEFINED 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /commons-ktx/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons-ktx/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | compileOptions { 40 | sourceCompatibility = appConfig.javaCompatibilityVersion 41 | targetCompatibility = appConfig.javaCompatibilityVersion 42 | } 43 | 44 | kotlinOptions { 45 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 46 | } 47 | } 48 | 49 | dependencies { 50 | implementation(project(deps.local.commons)) 51 | 52 | implementation(deps.appCompat) 53 | implementation(deps.coreKtx) 54 | implementation(deps.fragmentKtx) 55 | implementation(deps.constraintLayout) 56 | implementation(deps.viewPager2) 57 | } 58 | 59 | publishingConfig.artifactName = publishingConfig.commonsKtxArtifactName 60 | publishingConfig.artifactVersion = publishingConfig.commonsKtxArtifactVersion 61 | 62 | apply(from = "../publishing.gradle.kts") 63 | -------------------------------------------------------------------------------- /commons-ktx/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 -------------------------------------------------------------------------------- /commons-ktx/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/ActivityExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ActivityUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.annotation.SuppressLint 22 | import android.app.Activity 23 | import android.app.ActivityManager 24 | import android.graphics.BitmapFactory 25 | import androidx.annotation.ColorInt 26 | import androidx.annotation.DrawableRes 27 | import com.paulrybitskyi.commons.SdkInfo 28 | 29 | @get:ColorInt 30 | var Activity.statusBarColor: Int 31 | set(@ColorInt value) { window.statusBarColor = value } 32 | get() = window.statusBarColor 33 | 34 | @get:ColorInt 35 | var Activity.navigationBarColor: Int 36 | set(@ColorInt value) { window.navigationBarColor = value } 37 | get() = window.navigationBarColor 38 | 39 | fun Activity.makeScreenAlwaysAwake() { 40 | window.makeScreenAlwaysAwake() 41 | } 42 | 43 | fun Activity.makeScreenSleepable() { 44 | window.makeScreenSleepable() 45 | } 46 | 47 | fun Activity.setScreenAlwaysAwake(isScreenAlwaysAwake: Boolean) { 48 | window.setScreenAlwaysAwake(isScreenAlwaysAwake) 49 | } 50 | 51 | fun Activity.setSoftInputMode(mode: Int) { 52 | window.setSoftInputMode(mode) 53 | } 54 | 55 | @Suppress("DEPRECATION") 56 | @SuppressLint("NewApi") 57 | fun Activity.setTaskDescription( 58 | label: String, 59 | @DrawableRes iconId: Int, 60 | @ColorInt primaryColor: Int 61 | ) { 62 | setTaskDescription( 63 | if (SdkInfo.IS_AT_LEAST_PIE) { 64 | ActivityManager.TaskDescription(label, iconId, primaryColor) 65 | } else { 66 | ActivityManager.TaskDescription( 67 | label, 68 | BitmapFactory.decodeResource(resources, iconId), 69 | primaryColor 70 | ) 71 | } 72 | ) 73 | } 74 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/AlarmManagerExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("AlarmManagerUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.annotation.SuppressLint 22 | import android.app.AlarmManager 23 | import android.app.PendingIntent 24 | import com.paulrybitskyi.commons.SdkInfo 25 | 26 | @SuppressLint("NewApi") 27 | fun AlarmManager.setAlarm(triggerAtMillis: Long, pendingIntent: PendingIntent) { 28 | if (SdkInfo.IS_AT_LEAST_MARSHMALLOW) { 29 | setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent) 30 | } else if (SdkInfo.IS_AT_LEAST_KITKAT && !SdkInfo.IS_AT_LEAST_MARSHMALLOW) { 31 | setExact(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent) 32 | } else { 33 | set(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/BitmapExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("BitmapUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.graphics.Bitmap 22 | import android.graphics.Color 23 | 24 | val Bitmap.centerX: Float 25 | get() = (width / 2f) 26 | 27 | val Bitmap.centerY: Float 28 | get() = (height / 2f) 29 | 30 | /** 31 | * Checks whether the bitmap has any transparent pixels. 32 | * 33 | * Note: It is not desirable to invoke this method on the 34 | * main thread since it may take some time to finish. 35 | */ 36 | fun Bitmap.hasTransparentPixels(): Boolean { 37 | for (x in 0 until width) { 38 | for (y in 0 until height) { 39 | if (getPixel(x, y) == Color.TRANSPARENT) { 40 | return true 41 | } 42 | } 43 | } 44 | 45 | return false 46 | } 47 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/BundleExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("BundleUtils") 18 | @file:Suppress("UNCHECKED_CAST") 19 | 20 | package com.paulrybitskyi.commons.ktx 21 | 22 | import android.os.Bundle 23 | import android.os.Parcelable 24 | 25 | fun Bundle.getBundle(key: String, default: Bundle): Bundle { 26 | return (getBundle(key) ?: default) 27 | } 28 | 29 | fun Bundle.getBundleOrThrow(key: String): Bundle { 30 | return checkNotNull(getBundle(key)) { 31 | "The bundle does not contain a bundle value with the key: $key." 32 | } 33 | } 34 | 35 | fun Bundle.getSerializable(key: String, default: T): T { 36 | return ((getSerializable(key) as? T) ?: default) 37 | } 38 | 39 | fun Bundle.getSerializableOrThrow(key: String): T { 40 | return checkNotNull(getSerializable(key) as? T) { 41 | "The bundle does not contain a serializable value with the key: $key." 42 | } 43 | } 44 | 45 | fun Bundle.getParcelable(key: String, default: T): T { 46 | return (getParcelable(key) ?: default) 47 | } 48 | 49 | fun Bundle.getParcelableOrThrow(key: String): T { 50 | return checkNotNull(getParcelable(key)) { 51 | "The bundle does not contain a parcelable value with the key: $key." 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/DialogExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("DialogUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.app.Dialog 22 | import android.graphics.drawable.Drawable 23 | import android.widget.Toast 24 | import androidx.annotation.ColorInt 25 | import androidx.annotation.ColorRes 26 | import androidx.annotation.DimenRes 27 | import androidx.annotation.DrawableRes 28 | 29 | fun Dialog.getCompatColor(@ColorRes colorId: Int): Int { 30 | return context.getCompatColor(colorId) 31 | } 32 | 33 | fun Dialog.getDimensionPixelSize(@DimenRes dimenId: Int): Int { 34 | return context.getDimensionPixelSize(dimenId) 35 | } 36 | 37 | fun Dialog.getDimension(@DimenRes dimenId: Int): Float { 38 | return context.getDimension(dimenId) 39 | } 40 | 41 | fun Dialog.getCompatDrawable(@DrawableRes drawableId: Int): Drawable? { 42 | return context.getCompatDrawable(drawableId) 43 | } 44 | 45 | fun Dialog.getColoredDrawable(@DrawableRes drawableId: Int, @ColorInt color: Int): Drawable? { 46 | return context.getColoredDrawable(drawableId, color) 47 | } 48 | 49 | fun Dialog.showShortToast(message: CharSequence): Toast { 50 | return context.showShortToast(message) 51 | } 52 | 53 | fun Dialog.showLongToast(message: CharSequence): Toast { 54 | return context.showLongToast(message) 55 | } 56 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/FileExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("FileUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.os.FileObserver 22 | import com.paulrybitskyi.commons.SdkInfo 23 | import java.io.File 24 | 25 | @Suppress("DEPRECATION") 26 | inline fun File.newFileObserver( 27 | events: Int = FileObserver.ALL_EVENTS, 28 | crossinline onEventListener: (Int, String?) -> Unit 29 | ): FileObserver { 30 | return if (SdkInfo.IS_AT_LEAST_10) { 31 | object : FileObserver(this, events) { 32 | override fun onEvent(event: Int, path: String?) = onEventListener(event, path) 33 | } 34 | } else { 35 | object : FileObserver(this.absolutePath, events) { 36 | override fun onEvent(event: Int, path: String?) = onEventListener(event, path) 37 | } 38 | } 39 | } 40 | 41 | fun File.fileList(): List { 42 | if (!isDirectory) return emptyList() 43 | 44 | return (listFiles()?.toList() ?: emptyList()) 45 | } 46 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/FragmentManagerExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("FragmentManagerUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import androidx.fragment.app.Fragment 22 | import androidx.fragment.app.FragmentManager 23 | 24 | val FragmentManager.visibleFragment: Fragment? 25 | get() = fragments.firstOrNull { it.isVisible } 26 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/ListExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ListUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | inline fun List.indexOfFirstOrNull(predicate: (T) -> Boolean): Int? { 22 | for ((index, item) in withIndex()) { 23 | if (predicate(item)) return index 24 | } 25 | 26 | return null 27 | } 28 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/LiveDataExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("LiveDataUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import androidx.lifecycle.LiveData 22 | 23 | val LiveData.nonNullValue: T 24 | get() = checkNotNull(value) 25 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/MapExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("MapUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | fun Map.get(key: K, default: V): V { 22 | return if (containsKey(key)) { 23 | (get(key) ?: default) 24 | } else { 25 | default 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/PackageManagerExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("PackageManagerUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.annotation.SuppressLint 22 | import android.content.Intent 23 | import android.content.pm.PackageManager 24 | import android.net.Uri 25 | 26 | /** 27 | * Tries to figure out a package name of a native application that 28 | * is able to open the given url. 29 | * 30 | * Note: Due to [Android 11 package visibility changes](https://g.co/dev/packagevisibility), this 31 | * method does not work on Android 11 and above. 32 | * 33 | * @param url The given url 34 | * 35 | * @return The package name of a native application or null. 36 | */ 37 | @SuppressLint("QueryPermissionsNeeded") 38 | fun PackageManager.getNativeAppPackageForUrl(url: String): String? { 39 | val genericAppsIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.example.com")) 40 | val resolvedGenericApps = queryIntentActivities(genericAppsIntent, 0).map { 41 | it.activityInfo.packageName 42 | } 43 | 44 | val specializedAppsIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) 45 | val resolvedSpecializedApps = queryIntentActivities(specializedAppsIntent, 0).map { 46 | it.activityInfo.packageName 47 | } 48 | 49 | return resolvedSpecializedApps 50 | .subtract(resolvedGenericApps) 51 | .firstOrNull() 52 | } 53 | 54 | /** 55 | * Checks if the given url can be opened by a native application on the device. 56 | * 57 | * Note: Due to [Android 11 package visibility changes](https://g.co/dev/packagevisibility), this 58 | * method does not work on Android 11 and above. 59 | * 60 | * @param url The url to check 61 | * 62 | * @return true if the url can be opened by a native app; false otherwise 63 | */ 64 | fun PackageManager.canUrlBeOpenedByNativeApp(url: String): Boolean { 65 | return (getNativeAppPackageForUrl(url) != null) 66 | } 67 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/SpannableExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("SpannableUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.text.Spannable 22 | 23 | operator fun Spannable.set( 24 | start: Int, 25 | end: Int, 26 | span: Any 27 | ) { 28 | setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) 29 | } 30 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/StringExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("StringUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.graphics.Color 22 | import java.util.Locale 23 | 24 | val String.isColor: Boolean 25 | get() = try { 26 | Color.parseColor(this) 27 | true 28 | } catch (ignore: Throwable) { 29 | false 30 | } 31 | 32 | /** 33 | * Truncates the string to the specified limit with the option 34 | * to ellipsize the ending of the string. 35 | * 36 | * @param characterLimit The number of characters to truncate 37 | * @param ellipsize Whether to ellipsize the ending or not 38 | * 39 | * @return The truncated string 40 | */ 41 | fun String.truncate(characterLimit: Int, ellipsize: Boolean = true): String { 42 | if (isBlank() || (length <= characterLimit)) { 43 | return this 44 | } 45 | 46 | return (substring(0, characterLimit) + (if (ellipsize) "…" else "")) 47 | } 48 | 49 | /** 50 | * Capitalizes the first letter of the string. 51 | * 52 | * @param locale The current locale 53 | * 54 | * @return The capitalized string 55 | */ 56 | fun String.capitalize(locale: Locale): String { 57 | if (isBlank()) { 58 | return this 59 | } 60 | 61 | return substring(0, 1).uppercase(locale) + substring(1) 62 | } 63 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/TypedArrayExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("TypedArrayUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.annotation.SuppressLint 22 | import android.content.Context 23 | import android.content.res.ColorStateList 24 | import android.content.res.TypedArray 25 | import android.graphics.Typeface 26 | import android.graphics.drawable.Drawable 27 | import androidx.annotation.StyleableRes 28 | import androidx.core.content.res.ResourcesCompat 29 | import com.paulrybitskyi.commons.SdkInfo 30 | 31 | fun TypedArray.getString(@StyleableRes index: Int, default: CharSequence = ""): CharSequence { 32 | return (getString(index) ?: default) 33 | } 34 | 35 | fun TypedArray.getDrawable(@StyleableRes index: Int, default: Drawable? = null): Drawable? { 36 | return (getDrawable(index) ?: default) 37 | } 38 | 39 | @SuppressLint("NewApi") 40 | fun TypedArray.getFont( 41 | context: Context, 42 | @StyleableRes index: Int, 43 | default: Typeface 44 | ): Typeface { 45 | return if (SdkInfo.IS_AT_LEAST_OREO) { 46 | (getFont(index) ?: default) 47 | } else { 48 | getResourceId(index, -1) 49 | .takeIf { it != -1 } 50 | ?.let { ResourcesCompat.getFont(context, it) } 51 | ?: default 52 | } 53 | } 54 | 55 | fun TypedArray.getColorStateList(@StyleableRes index: Int, default: ColorStateList): ColorStateList { 56 | return (getColorStateList(index) ?: default) 57 | } 58 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/ViewGroupExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ViewGroupUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.view.ViewGroup 22 | import androidx.annotation.Px 23 | 24 | val ViewGroup.MarginLayoutParams.horizontalMargin: Int 25 | get() = (marginStart + marginEnd) 26 | 27 | val ViewGroup.MarginLayoutParams.verticalMargin: Int 28 | get() = (topMargin + bottomMargin) 29 | 30 | fun ViewGroup.MarginLayoutParams.setHorizontalMargin(@Px margin: Int) { 31 | marginStart = margin 32 | marginEnd = margin 33 | } 34 | 35 | fun ViewGroup.MarginLayoutParams.setVerticalMargin(@Px margin: Int) { 36 | topMargin = margin 37 | bottomMargin = margin 38 | } 39 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/ViewPropertyAnimatorExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ViewPropertyAnimatorUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.animation.Animator 22 | import android.view.ViewPropertyAnimator 23 | 24 | fun ViewPropertyAnimator.scale(value: Float): ViewPropertyAnimator { 25 | scaleX(value) 26 | scaleY(value) 27 | 28 | return this 29 | } 30 | 31 | fun ViewPropertyAnimator.scaleBy(value: Float): ViewPropertyAnimator { 32 | scaleXBy(value) 33 | scaleYBy(value) 34 | 35 | return this 36 | } 37 | 38 | inline fun ViewPropertyAnimator.setListener( 39 | crossinline onEnd: (animator: Animator) -> Unit = {}, 40 | crossinline onStart: (animator: Animator) -> Unit = {}, 41 | crossinline onCancel: (animator: Animator) -> Unit = {}, 42 | crossinline onRepeat: (animator: Animator) -> Unit = {} 43 | ): ViewPropertyAnimator { 44 | return object : Animator.AnimatorListener { 45 | override fun onAnimationRepeat(animator: Animator) = onRepeat(animator) 46 | override fun onAnimationEnd(animator: Animator) = onEnd(animator) 47 | override fun onAnimationCancel(animator: Animator) = onCancel(animator) 48 | override fun onAnimationStart(animator: Animator) = onStart(animator) 49 | } 50 | .let(::setListener) 51 | } 52 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/WindowExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("WindowUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx 20 | 21 | import android.view.Window 22 | import android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND 23 | import android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 24 | 25 | var Window.isBackgroundDimmingEnabled: Boolean 26 | set(value) { 27 | if (value) { 28 | addFlags(FLAG_DIM_BEHIND) 29 | } else { 30 | clearFlags(FLAG_DIM_BEHIND) 31 | } 32 | } 33 | get() = ((attributes.flags and FLAG_DIM_BEHIND) == FLAG_DIM_BEHIND) 34 | 35 | fun Window.makeScreenAlwaysAwake() { 36 | addFlags(FLAG_KEEP_SCREEN_ON) 37 | } 38 | 39 | fun Window.makeScreenSleepable() { 40 | clearFlags(FLAG_KEEP_SCREEN_ON) 41 | } 42 | 43 | fun Window.setScreenAlwaysAwake(isScreenAlwaysAwake: Boolean) { 44 | if (isScreenAlwaysAwake) { 45 | makeScreenAlwaysAwake() 46 | } else { 47 | makeScreenSleepable() 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/drawing/CanvasExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("CanvasUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.drawing 20 | 21 | import android.annotation.SuppressLint 22 | import android.graphics.Canvas 23 | import android.graphics.Path 24 | import android.graphics.Region 25 | import com.paulrybitskyi.commons.SdkInfo 26 | 27 | @Suppress("DEPRECATION") 28 | @SuppressLint("NewApi") 29 | fun Canvas.clipOutPathCompat(path: Path) { 30 | if (SdkInfo.IS_AT_LEAST_OREO) { 31 | clipOutPath(path) 32 | } else { 33 | clipPath(path, Region.Op.DIFFERENCE) 34 | } 35 | } 36 | 37 | @Suppress("DEPRECATION") 38 | @SuppressLint("NewApi") 39 | fun Canvas.clipPathCompat(path: Path) { 40 | if (SdkInfo.IS_AT_LEAST_OREO) { 41 | clipPath(path) 42 | } else { 43 | clipPath(path, Region.Op.INTERSECT) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/drawing/FontMetricsExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("FontMetricsUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.drawing 20 | 21 | import android.graphics.Paint 22 | 23 | val Paint.FontMetrics.recommendedHeight: Float 24 | get() = (descent - ascent) 25 | 26 | val Paint.FontMetrics.maximumHeight: Float 27 | get() = (bottom - top) 28 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/drawing/PaintExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("PaintUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.drawing 20 | 21 | import android.graphics.Paint 22 | import android.graphics.Rect 23 | 24 | fun Paint.getTextBounds(text: String, rect: Rect) { 25 | getTextBounds(text, 0, text.length, rect) 26 | } 27 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/drawing/PathExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("PathUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.drawing 20 | 21 | import android.graphics.Path 22 | import android.graphics.PointF 23 | 24 | fun Path.moveTo(point: PointF) { 25 | moveTo(point.x, point.y) 26 | } 27 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/drawing/RectExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("RectUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.drawing 20 | 21 | import android.graphics.Rect 22 | import android.graphics.RectF 23 | 24 | val Rect.halfWidth: Int 25 | get() = (width() / 2) 26 | 27 | val Rect.halfHeight: Int 28 | get() = (height() / 2) 29 | 30 | val RectF.halfWidth: Float 31 | get() = (width() / 2f) 32 | 33 | val RectF.halfHeight: Float 34 | get() = (height() / 2f) 35 | 36 | fun Rect.setBounds( 37 | left: Int = this.left, 38 | top: Int = this.top, 39 | right: Int = this.right, 40 | bottom: Int = this.bottom 41 | ) { 42 | set(left, top, right, bottom) 43 | } 44 | 45 | fun RectF.setBounds( 46 | left: Float = this.left, 47 | top: Float = this.top, 48 | right: Float = this.right, 49 | bottom: Float = this.bottom 50 | ) { 51 | set(left, top, right, bottom) 52 | } 53 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/CheckBoxExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("CheckBoxUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import androidx.annotation.ColorInt 22 | import androidx.appcompat.widget.AppCompatCheckBox 23 | import androidx.core.widget.CompoundButtonCompat 24 | import com.paulrybitskyi.commons.ktx.toColorStateList 25 | 26 | fun AppCompatCheckBox.setColor(@ColorInt color: Int) { 27 | CompoundButtonCompat.setButtonTintList(this, color.toColorStateList()) 28 | } 29 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/ImageViewExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ImageViewUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import android.widget.ImageView 22 | import androidx.annotation.ColorInt 23 | import com.paulrybitskyi.commons.ktx.setColor 24 | 25 | fun ImageView.setColor(@ColorInt color: Int) { 26 | if (drawable != null) { 27 | setImageDrawable(drawable?.setColor(color)) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/MenuExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("MenuUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import android.graphics.drawable.Drawable 22 | import android.view.Menu 23 | import android.view.MenuItem 24 | 25 | fun Menu.addItem( 26 | id: Int, 27 | title: CharSequence, 28 | icon: Drawable, 29 | groupId: Int = Menu.NONE, 30 | order: Int = Menu.NONE 31 | ): MenuItem { 32 | return add(groupId, id, order, title) 33 | .apply { this.icon = icon } 34 | } 35 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/MotionLayoutExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("MotionLayoutUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import androidx.constraintlayout.motion.widget.MotionLayout 22 | import androidx.constraintlayout.widget.ConstraintSet 23 | 24 | inline fun MotionLayout.updateConstraintSets(action: (Int, ConstraintSet) -> Unit) { 25 | for (constraintSetId in constraintSetIds) { 26 | updateState( 27 | constraintSetId, 28 | getConstraintSet(constraintSetId).also { action(constraintSetId, it) } 29 | ) 30 | } 31 | } 32 | 33 | inline fun MotionLayout.addTransitionListener( 34 | crossinline onTransitionStarted: (startId: Int, endId: Int) -> Unit = { _, _ -> }, 35 | crossinline onTransitionChange: (startId: Int, endId: Int, progress: Float) -> Unit = { _, _, _ -> }, 36 | crossinline onTransitionCompleted: (currentId: Int) -> Unit = {}, 37 | crossinline onTransitionTrigger: (triggerId: Int, positive: Boolean, progress: Float) -> Unit = { _, _, _ -> } 38 | ): MotionLayout.TransitionListener { 39 | return object : MotionLayout.TransitionListener { 40 | 41 | override fun onTransitionStarted(ml: MotionLayout, startId: Int, endId: Int) { 42 | onTransitionStarted(startId, endId) 43 | } 44 | 45 | override fun onTransitionChange(ml: MotionLayout, startId: Int, endId: Int, progress: Float) { 46 | onTransitionChange(startId, endId, progress) 47 | } 48 | 49 | override fun onTransitionCompleted(ml: MotionLayout, currentId: Int) { 50 | onTransitionCompleted(currentId) 51 | } 52 | 53 | override fun onTransitionTrigger( 54 | ml: MotionLayout, 55 | triggerId: Int, 56 | positive: Boolean, 57 | progress: Float 58 | ) { 59 | onTransitionTrigger(triggerId, positive, progress) 60 | } 61 | } 62 | .also(::addTransitionListener) 63 | } 64 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/NestedScrollViewExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("NestedScrollViewUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import android.view.View 22 | import androidx.core.widget.NestedScrollView 23 | import com.paulrybitskyi.commons.ktx.postAction 24 | 25 | fun NestedScrollView.scrollToTop() { 26 | postAction { fullScroll(View.FOCUS_UP) } 27 | } 28 | 29 | fun NestedScrollView.scrollToBottom() { 30 | postAction { fullScroll(View.FOCUS_DOWN) } 31 | } 32 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/ProgressBarExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ProgressBarUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import android.widget.ProgressBar 22 | import androidx.annotation.ColorInt 23 | import com.paulrybitskyi.commons.ktx.setColor 24 | 25 | fun ProgressBar.setColor(@ColorInt color: Int) { 26 | indeterminateDrawable = indeterminateDrawable?.setColor(color) 27 | } 28 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/ScrollViewExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ScrollViewUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import android.view.View 22 | import android.widget.ScrollView 23 | 24 | fun ScrollView.scrollToTop() { 25 | post { fullScroll(View.FOCUS_UP) } 26 | } 27 | 28 | fun ScrollView.scrollToBottom() { 29 | post { fullScroll(View.FOCUS_DOWN) } 30 | } 31 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/SeekBarExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("SeekBarUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import android.widget.SeekBar 22 | import androidx.annotation.ColorInt 23 | import com.paulrybitskyi.commons.ktx.setColor 24 | import com.paulrybitskyi.commons.ktx.toColorStateList 25 | 26 | fun SeekBar.setThumbColor(@ColorInt color: Int) { 27 | thumb.setColor(color) 28 | } 29 | 30 | fun SeekBar.setPrimaryProgressColor(@ColorInt color: Int) { 31 | progressTintList = color.toColorStateList() 32 | } 33 | 34 | fun SeekBar.setSecondaryProgressColor(@ColorInt color: Int) { 35 | progressBackgroundTintList = color.toColorStateList() 36 | } 37 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/SwitchCompatExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("SwitchCompatUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import android.content.res.ColorStateList 22 | import androidx.annotation.ColorInt 23 | import androidx.appcompat.widget.SwitchCompat 24 | import androidx.core.graphics.drawable.DrawableCompat 25 | import com.paulrybitskyi.commons.ktx.withHalfAlpha 26 | 27 | fun SwitchCompat.setColor(@ColorInt color: Int) { 28 | setColors(color, color, color, color) 29 | } 30 | 31 | fun SwitchCompat.setColors( 32 | @ColorInt deactivatedPointerColor: Int, 33 | @ColorInt activatedPointerColor: Int, 34 | @ColorInt deactivatedBackgroundColor: Int, 35 | @ColorInt activatedBackgroundColor: Int 36 | ) { 37 | val switchStates: Array = arrayOf( 38 | intArrayOf(-android.R.attr.state_checked), 39 | intArrayOf(android.R.attr.state_checked) 40 | ) 41 | 42 | val switchThumbDrawableColors = intArrayOf( 43 | deactivatedPointerColor, 44 | activatedPointerColor 45 | ) 46 | 47 | val switchTrackDrawableColors = intArrayOf( 48 | deactivatedBackgroundColor.withHalfAlpha(), 49 | activatedBackgroundColor.withHalfAlpha() 50 | ) 51 | 52 | DrawableCompat.setTintList( 53 | DrawableCompat.wrap(thumbDrawable), 54 | ColorStateList(switchStates, switchThumbDrawableColors) 55 | ) 56 | 57 | DrawableCompat.setTintList( 58 | DrawableCompat.wrap(trackDrawable), 59 | ColorStateList(switchStates, switchTrackDrawableColors) 60 | ) 61 | } 62 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/ViewPager2Extensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ViewPager2Utils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import androidx.core.view.children 22 | import androidx.recyclerview.widget.RecyclerView 23 | import androidx.viewpager2.widget.ViewPager2 24 | 25 | val ViewPager2.recyclerView: RecyclerView? 26 | get() = (children.firstOrNull() as? RecyclerView) 27 | 28 | inline fun ViewPager2.registerOnPageChangeCallback( 29 | crossinline onPageSelected: (position: Int) -> Unit = {}, 30 | crossinline onPageScrollStateChanged: (state: Int) -> Unit = {}, 31 | crossinline onPageScrolled: ( 32 | position: Int, 33 | positionOffset: Float, 34 | positionOffsetPixels: Int 35 | ) -> Unit = { _, _, _ -> } 36 | ): ViewPager2.OnPageChangeCallback { 37 | return object : ViewPager2.OnPageChangeCallback() { 38 | 39 | override fun onPageSelected(position: Int) = onPageSelected(position) 40 | override fun onPageScrollStateChanged(state: Int) = onPageScrollStateChanged(state) 41 | override fun onPageScrolled( 42 | position: Int, 43 | positionOffset: Float, 44 | positionOffsetPixels: Int 45 | ) { 46 | onPageScrolled(position, positionOffset, positionOffsetPixels) 47 | } 48 | } 49 | .also(::registerOnPageChangeCallback) 50 | } 51 | -------------------------------------------------------------------------------- /commons-ktx/src/main/java/com/paulrybitskyi/commons/ktx/views/ViewPagerExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ViewPagerUtils") 18 | 19 | package com.paulrybitskyi.commons.ktx.views 20 | 21 | import androidx.viewpager.widget.ViewPager 22 | 23 | inline fun ViewPager.addOnPageChangeListener( 24 | crossinline onPageSelected: (position: Int) -> Unit = {}, 25 | crossinline onPageScrollStateChanged: (state: Int) -> Unit = {}, 26 | crossinline onPageScrolled: ( 27 | position: Int, 28 | positionOffset: Float, 29 | positionOffsetPixels: Int 30 | ) -> Unit = { _, _, _ -> } 31 | ): ViewPager.OnPageChangeListener { 32 | return object : ViewPager.OnPageChangeListener { 33 | 34 | override fun onPageSelected(position: Int) = onPageSelected(position) 35 | override fun onPageScrollStateChanged(state: Int) = onPageScrollStateChanged(state) 36 | override fun onPageScrolled( 37 | position: Int, 38 | positionOffset: Float, 39 | positionOffsetPixels: Int 40 | ) { 41 | onPageScrolled(position, positionOffset, positionOffsetPixels) 42 | } 43 | } 44 | .also(::addOnPageChangeListener) 45 | } 46 | -------------------------------------------------------------------------------- /commons-listeners/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons-listeners/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | compileOptions { 40 | sourceCompatibility = appConfig.javaCompatibilityVersion 41 | targetCompatibility = appConfig.javaCompatibilityVersion 42 | } 43 | 44 | kotlinOptions { 45 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 46 | } 47 | } 48 | 49 | publishingConfig.artifactName = publishingConfig.commonsListenersArtifactName 50 | publishingConfig.artifactVersion = publishingConfig.commonsListenersArtifactVersion 51 | 52 | apply(from = "../publishing.gradle.kts") 53 | -------------------------------------------------------------------------------- /commons-listeners/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 -------------------------------------------------------------------------------- /commons-listeners/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons-listeners/src/main/java/com/paulrybitskyi/commons/listeners/QueryListener.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.listeners 18 | 19 | import com.paulrybitskyi.commons.listeners.adapters.TextWatcherAdapter 20 | 21 | /** 22 | * An implementation of the TextWatcher listener that provides 23 | * a callback to get notified when the query is entered and removed. 24 | */ 25 | class QueryListener(private val callback: Callback) : TextWatcherAdapter { 26 | 27 | override fun onTextChanged(text: CharSequence, start: Int, before: Int, count: Int) { 28 | if (text.isNotEmpty()) { 29 | callback.onQueryEntered(text.toString()) 30 | } else { 31 | callback.onQueryRemoved() 32 | } 33 | } 34 | 35 | /** 36 | * A helper callback to get notified when a query is entered or removed. 37 | */ 38 | interface Callback { 39 | 40 | /** 41 | * Gets called whenever a character is entered. 42 | * 43 | * @param query The query entered 44 | */ 45 | fun onQueryEntered(query: String) 46 | 47 | /** 48 | * Gets called whenever a query is removed. 49 | */ 50 | fun onQueryRemoved() 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /commons-listeners/src/main/java/com/paulrybitskyi/commons/listeners/adapters/ActivityLifecycleCallbacksAdapter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.listeners.adapters 18 | 19 | import android.app.Activity 20 | import android.app.Application 21 | import android.os.Bundle 22 | 23 | interface ActivityLifecycleCallbacksAdapter : Application.ActivityLifecycleCallbacks { 24 | override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {} 25 | override fun onActivityStarted(activity: Activity) {} 26 | override fun onActivityResumed(activity: Activity) {} 27 | override fun onActivityPaused(activity: Activity) {} 28 | override fun onActivityStopped(activity: Activity) {} 29 | override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {} 30 | override fun onActivityDestroyed(activity: Activity) {} 31 | } 32 | -------------------------------------------------------------------------------- /commons-listeners/src/main/java/com/paulrybitskyi/commons/listeners/adapters/AnimationListenerAdapter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.listeners.adapters 18 | 19 | import android.view.animation.Animation 20 | 21 | interface AnimationListenerAdapter : Animation.AnimationListener { 22 | override fun onAnimationStart(animation: Animation) {} 23 | override fun onAnimationRepeat(animation: Animation) {} 24 | override fun onAnimationEnd(animation: Animation) {} 25 | } 26 | -------------------------------------------------------------------------------- /commons-listeners/src/main/java/com/paulrybitskyi/commons/listeners/adapters/OnSeekBarChangeListenerAdapter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.listeners.adapters 18 | 19 | import android.widget.SeekBar 20 | 21 | interface OnSeekBarChangeListenerAdapter : SeekBar.OnSeekBarChangeListener { 22 | override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {} 23 | override fun onStartTrackingTouch(seekBar: SeekBar) {} 24 | override fun onStopTrackingTouch(seekBar: SeekBar) {} 25 | } 26 | -------------------------------------------------------------------------------- /commons-listeners/src/main/java/com/paulrybitskyi/commons/listeners/adapters/TextWatcherAdapter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.listeners.adapters 18 | 19 | import android.text.Editable 20 | import android.text.TextWatcher 21 | 22 | interface TextWatcherAdapter : TextWatcher { 23 | override fun beforeTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {} 24 | override fun onTextChanged(text: CharSequence, start: Int, before: Int, count: Int) {} 25 | override fun afterTextChanged(editable: Editable) {} 26 | } 27 | -------------------------------------------------------------------------------- /commons-listeners/src/main/java/com/paulrybitskyi/commons/listeners/gestures/GestureCallbackAdapter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.listeners.gestures 18 | 19 | import android.view.MotionEvent 20 | 21 | class GestureCallbackAdapter : GestureListener.Callback { 22 | 23 | override fun onSingleTap(motionEvent: MotionEvent) {} 24 | 25 | override fun onDoubleTap(motionEvent: MotionEvent) {} 26 | 27 | override fun onFling(startEvent: MotionEvent, endEvent: MotionEvent) {} 28 | 29 | override fun onSwipedToLeft(startEvent: MotionEvent, endEvent: MotionEvent) {} 30 | 31 | override fun onSwipedToRight(startEvent: MotionEvent, endEvent: MotionEvent) {} 32 | 33 | override fun onSwipedToTop(startEvent: MotionEvent, endEvent: MotionEvent) {} 34 | 35 | override fun onSwipedToBottom(startEvent: MotionEvent, endEvent: MotionEvent) {} 36 | } 37 | -------------------------------------------------------------------------------- /commons-listeners/src/main/java/com/paulrybitskyi/commons/listeners/utils/EditTextExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("EditTextUtils") 18 | 19 | package com.paulrybitskyi.commons.listeners.utils 20 | 21 | import android.text.TextWatcher 22 | import android.widget.EditText 23 | import com.paulrybitskyi.commons.listeners.QueryListener 24 | 25 | inline fun EditText.addQueryListener( 26 | crossinline onQueryEntered: (String) -> Unit = {}, 27 | crossinline onQueryRemoved: () -> Unit = {} 28 | ): TextWatcher { 29 | val callback = object : QueryListener.Callback { 30 | 31 | override fun onQueryEntered(query: String) = onQueryEntered(query) 32 | override fun onQueryRemoved() = onQueryRemoved() 33 | } 34 | 35 | return QueryListener(callback) 36 | } 37 | -------------------------------------------------------------------------------- /commons-material/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons-material/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | compileOptions { 40 | sourceCompatibility = appConfig.javaCompatibilityVersion 41 | targetCompatibility = appConfig.javaCompatibilityVersion 42 | } 43 | 44 | kotlinOptions { 45 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 46 | } 47 | } 48 | 49 | dependencies { 50 | implementation(project(deps.local.commonsKtx)) 51 | 52 | implementation(deps.materialComponents) 53 | } 54 | 55 | publishingConfig.artifactName = publishingConfig.commonsMaterialArtifactName 56 | publishingConfig.artifactVersion = publishingConfig.commonsMaterialArtifactVersion 57 | 58 | apply(from = "../publishing.gradle.kts") 59 | -------------------------------------------------------------------------------- /commons-material/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 -------------------------------------------------------------------------------- /commons-material/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons-material/src/main/java/com/paulrybitskyi/commons/material/OnTabSelectedListenerAdapter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.material 18 | 19 | import com.google.android.material.tabs.TabLayout 20 | 21 | interface OnTabSelectedListenerAdapter : TabLayout.OnTabSelectedListener { 22 | override fun onTabSelected(tab: TabLayout.Tab) {} 23 | override fun onTabReselected(tab: TabLayout.Tab) {} 24 | override fun onTabUnselected(tab: TabLayout.Tab) {} 25 | } 26 | -------------------------------------------------------------------------------- /commons-material/src/main/java/com/paulrybitskyi/commons/material/utils/BottomNavViewExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("BottomNavViewUtils") 18 | 19 | package com.paulrybitskyi.commons.material.utils 20 | 21 | import android.content.res.ColorStateList 22 | import androidx.annotation.ColorInt 23 | import com.google.android.material.bottomnavigation.BottomNavigationView 24 | 25 | fun BottomNavigationView.setItemColors( 26 | @ColorInt unselectedStateColor: Int, 27 | @ColorInt selectedStateColor: Int 28 | ) { 29 | ColorStateList( 30 | arrayOf( 31 | intArrayOf(-android.R.attr.state_checked), 32 | intArrayOf() 33 | ), 34 | intArrayOf( 35 | unselectedStateColor, 36 | selectedStateColor 37 | ) 38 | ).also { 39 | itemTextColor = it 40 | itemIconTintList = it 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /commons-material/src/main/java/com/paulrybitskyi/commons/material/utils/CardViewExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("CardViewUtils") 18 | 19 | package com.paulrybitskyi.commons.material.utils 20 | 21 | import androidx.annotation.ColorInt 22 | import com.google.android.material.card.MaterialCardView 23 | import com.paulrybitskyi.commons.ktx.toColorStateList 24 | 25 | fun MaterialCardView.setRippleColor(@ColorInt color: Int) { 26 | rippleColor = color.toColorStateList() 27 | } 28 | -------------------------------------------------------------------------------- /commons-material/src/main/java/com/paulrybitskyi/commons/material/utils/ChipDrawableExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ChipDrawableUtils") 18 | 19 | package com.paulrybitskyi.commons.material.utils 20 | 21 | import androidx.annotation.ColorInt 22 | import com.google.android.material.chip.ChipDrawable 23 | import com.paulrybitskyi.commons.ktx.toColorStateList 24 | 25 | fun ChipDrawable.setChipBackgroundColor(@ColorInt color: Int) { 26 | chipBackgroundColor = color.toColorStateList() 27 | } 28 | 29 | fun ChipDrawable.setChipIconColor(@ColorInt color: Int) { 30 | chipIconTint = color.toColorStateList() 31 | } 32 | 33 | fun ChipDrawable.setChipBackgroundCornerRadius(radius: Float) { 34 | shapeAppearanceModel = shapeAppearanceModel.withCornerSize(radius) 35 | } 36 | -------------------------------------------------------------------------------- /commons-material/src/main/java/com/paulrybitskyi/commons/material/utils/MaterialCardViewExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("MaterialCardViewUtils") 18 | 19 | package com.paulrybitskyi.commons.material.utils 20 | 21 | import androidx.annotation.Px 22 | import com.google.android.material.card.MaterialCardView 23 | 24 | var MaterialCardView.contentLeftPadding: Int 25 | set(value) { updateContentPadding(leftPadding = value) } 26 | get() = contentPaddingLeft 27 | 28 | var MaterialCardView.contentTopPadding: Int 29 | set(value) { updateContentPadding(topPadding = value) } 30 | get() = contentPaddingTop 31 | 32 | var MaterialCardView.contentRightPadding: Int 33 | set(value) { updateContentPadding(rightPadding = value) } 34 | get() = contentPaddingRight 35 | 36 | var MaterialCardView.contentBottomPadding: Int 37 | set(value) { updateContentPadding(bottomPadding = value) } 38 | get() = contentPaddingBottom 39 | 40 | fun MaterialCardView.updateContentPadding( 41 | @Px leftPadding: Int = this.contentPaddingLeft, 42 | @Px topPadding: Int = this.contentPaddingTop, 43 | @Px rightPadding: Int = this.contentPaddingRight, 44 | @Px bottomPadding: Int = this.contentPaddingBottom 45 | ) { 46 | setContentPadding(leftPadding, topPadding, rightPadding, bottomPadding) 47 | } 48 | -------------------------------------------------------------------------------- /commons-material/src/main/java/com/paulrybitskyi/commons/material/utils/TabLayoutExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("TabLayoutUtils") 18 | 19 | package com.paulrybitskyi.commons.material.utils 20 | 21 | import com.google.android.material.tabs.TabLayout 22 | 23 | inline fun TabLayout.addOnTabSelectedListener( 24 | crossinline onTabSelected: (TabLayout.Tab) -> Unit = {}, 25 | crossinline onTabReselected: (TabLayout.Tab) -> Unit = {}, 26 | crossinline onTabUnselected: (TabLayout.Tab) -> Unit = {} 27 | ): TabLayout.OnTabSelectedListener { 28 | return object : TabLayout.OnTabSelectedListener { 29 | override fun onTabSelected(tab: TabLayout.Tab) = onTabSelected(tab) 30 | override fun onTabReselected(tab: TabLayout.Tab) = onTabReselected(tab) 31 | override fun onTabUnselected(tab: TabLayout.Tab) = onTabUnselected(tab) 32 | } 33 | .also(::addOnTabSelectedListener) 34 | } 35 | -------------------------------------------------------------------------------- /commons-navigation/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons-navigation/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | compileOptions { 40 | sourceCompatibility = appConfig.javaCompatibilityVersion 41 | targetCompatibility = appConfig.javaCompatibilityVersion 42 | } 43 | 44 | kotlinOptions { 45 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 46 | } 47 | } 48 | 49 | dependencies { 50 | implementation(deps.navigation) 51 | } 52 | 53 | publishingConfig.artifactName = publishingConfig.commonsNavigationArtifactName 54 | publishingConfig.artifactVersion = publishingConfig.commonsNavigationArtifactVersion 55 | 56 | apply(from = "../publishing.gradle.kts") 57 | -------------------------------------------------------------------------------- /commons-navigation/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 -------------------------------------------------------------------------------- /commons-navigation/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons-navigation/src/main/java/com/paulrybitskyi/commons/navigation/FragmentExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("FragmentUtils") 18 | 19 | package com.paulrybitskyi.commons.navigation 20 | 21 | import androidx.fragment.app.Fragment 22 | import androidx.navigation.NavController 23 | import androidx.navigation.fragment.findNavController 24 | 25 | val Fragment.navController: NavController 26 | get() = findNavController() 27 | -------------------------------------------------------------------------------- /commons-navigation/src/main/java/com/paulrybitskyi/commons/navigation/NavControllerExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("NavControllerUtils") 18 | 19 | package com.paulrybitskyi.commons.navigation 20 | 21 | import android.os.Bundle 22 | import androidx.annotation.IdRes 23 | import androidx.navigation.NavController 24 | 25 | fun NavController.containsDestination(@IdRes destinationId: Int): Boolean { 26 | return try { 27 | getBackStackEntry(destinationId) 28 | true 29 | } catch (ignore: Exception) { 30 | false 31 | } 32 | } 33 | 34 | fun NavController.containsAnyDestination(@IdRes destinationIds: List): Boolean { 35 | return destinationIds.any { containsDestination(it) } 36 | } 37 | 38 | fun NavController.getDestinationArgs(@IdRes destinationId: Int): Bundle? { 39 | return try { 40 | getBackStackEntry(destinationId).arguments 41 | } catch (ignore: Exception) { 42 | null 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /commons-network/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons-network/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | compileOptions { 40 | sourceCompatibility = appConfig.javaCompatibilityVersion 41 | targetCompatibility = appConfig.javaCompatibilityVersion 42 | } 43 | 44 | kotlinOptions { 45 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 46 | } 47 | } 48 | 49 | dependencies { 50 | implementation(project(deps.local.commons)) 51 | implementation(project(deps.local.commonsKtx)) 52 | 53 | implementation(deps.appCompat) 54 | } 55 | 56 | publishingConfig.artifactName = publishingConfig.commonsNetworkArtifactName 57 | publishingConfig.artifactVersion = publishingConfig.commonsNetworkArtifactVersion 58 | 59 | apply(from = "../publishing.gradle.kts") 60 | -------------------------------------------------------------------------------- /commons-network/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 -------------------------------------------------------------------------------- /commons-network/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons-network/src/main/java/com/paulrybitskyi/commons/network/model/NetworkInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.network.model 18 | 19 | data class NetworkInfo( 20 | val isConnectedToNetwork: Boolean, 21 | val isNetworkConnectionMetered: Boolean, 22 | val activeNetworkType: NetworkType 23 | ) 24 | -------------------------------------------------------------------------------- /commons-network/src/main/java/com/paulrybitskyi/commons/network/model/NetworkType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.network.model 18 | 19 | enum class NetworkType(val title: String) { 20 | 21 | UNDEFINED("Undefined"), 22 | 23 | WIFI("Wi-Fi"), 24 | CELLULAR("Cellular"), 25 | ETHERNET("Ethernet") 26 | } 27 | -------------------------------------------------------------------------------- /commons-network/src/main/java/com/paulrybitskyi/commons/network/utils/NetworkCallback.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.network.utils 18 | 19 | import android.net.ConnectivityManager 20 | import android.net.Network 21 | import com.paulrybitskyi.commons.network.model.NetworkType 22 | import java.util.concurrent.ConcurrentHashMap 23 | 24 | class NetworkCallback( 25 | private val networkTypeProvider: NetworkTypeProvider, 26 | private val listener: NetworkListener 27 | ) : ConnectivityManager.NetworkCallback() { 28 | 29 | private val Network.id: String 30 | get() = toString() 31 | 32 | private val activeNetworksMap = ConcurrentHashMap() 33 | 34 | override fun onAvailable(network: Network) { 35 | super.onAvailable(network) 36 | 37 | networkTypeProvider.getNetworkType(network) 38 | .also { activeNetworksMap[network.id] = it } 39 | .also { listener.onNetworkConnected(it) } 40 | } 41 | 42 | override fun onLost(network: Network) { 43 | super.onLost(network) 44 | 45 | (activeNetworksMap.remove(network.id) ?: NetworkType.UNDEFINED) 46 | .also { listener.onNetworkDisconnected(it) } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /commons-network/src/main/java/com/paulrybitskyi/commons/network/utils/NetworkListener.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.network.utils 18 | 19 | import com.paulrybitskyi.commons.network.model.NetworkType 20 | 21 | interface NetworkListener { 22 | fun onNetworkConnected(networkType: NetworkType) 23 | fun onNetworkDisconnected(networkType: NetworkType) 24 | } 25 | -------------------------------------------------------------------------------- /commons-recyclerview/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons-recyclerview/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | compileOptions { 40 | sourceCompatibility = appConfig.javaCompatibilityVersion 41 | targetCompatibility = appConfig.javaCompatibilityVersion 42 | } 43 | 44 | kotlinOptions { 45 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 46 | } 47 | } 48 | 49 | dependencies { 50 | implementation(project(deps.local.commonsKtx)) 51 | 52 | implementation(deps.recyclerView) 53 | } 54 | 55 | publishingConfig.artifactName = publishingConfig.commonsRecyclerViewArtifactName 56 | publishingConfig.artifactVersion = publishingConfig.commonsRecyclerViewArtifactVersion 57 | 58 | apply(from = "../publishing.gradle.kts") 59 | -------------------------------------------------------------------------------- /commons-recyclerview/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 -------------------------------------------------------------------------------- /commons-recyclerview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons-recyclerview/src/main/java/com/paulrybitskyi/commons/recyclerview/decorators/GridSpacingItemDecorator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.recyclerview.decorators 18 | 19 | import android.graphics.Rect 20 | import android.view.View 21 | import androidx.recyclerview.widget.RecyclerView 22 | 23 | class GridSpacingItemDecorator( 24 | private val spacing: Int, 25 | private val spanCount: Int, 26 | private val includeEdge: Boolean 27 | ) : RecyclerView.ItemDecoration() { 28 | 29 | override fun getItemOffsets( 30 | outRect: Rect, 31 | view: View, 32 | parent: RecyclerView, 33 | state: RecyclerView.State 34 | ) { 35 | val position = parent.getChildAdapterPosition(view) 36 | val column = (position % spanCount) 37 | 38 | if (includeEdge) { 39 | outRect.left = (spacing - (column * spacing / spanCount)) 40 | outRect.right = ((column + 1) * spacing / spanCount) 41 | 42 | if (position < spanCount) { 43 | outRect.top = spacing 44 | } 45 | 46 | outRect.bottom = spacing 47 | } else { 48 | outRect.left = ((column * spacing) / spanCount) 49 | outRect.right = (spacing - ((column + 1) * spacing / spanCount)) 50 | 51 | if (position >= spanCount) { 52 | outRect.top = spacing 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /commons-recyclerview/src/main/java/com/paulrybitskyi/commons/recyclerview/decorators/spacing/policies/FirstItemExclusionPolicy.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.recyclerview.decorators.spacing.policies 18 | 19 | import android.view.View 20 | import androidx.recyclerview.widget.RecyclerView 21 | import com.paulrybitskyi.commons.recyclerview.decorators.spacing.SpacingItemDecorator 22 | 23 | class FirstItemExclusionPolicy : SpacingItemDecorator.ItemExclusionPolicy { 24 | 25 | override fun shouldExclude(view: View, parent: RecyclerView): Boolean { 26 | return (parent.getChildAdapterPosition(view) == 0) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /commons-recyclerview/src/main/java/com/paulrybitskyi/commons/recyclerview/decorators/spacing/policies/LastItemExclusionPolicy.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.recyclerview.decorators.spacing.policies 18 | 19 | import android.view.View 20 | import androidx.recyclerview.widget.RecyclerView 21 | import com.paulrybitskyi.commons.recyclerview.decorators.spacing.SpacingItemDecorator 22 | 23 | class LastItemExclusionPolicy : SpacingItemDecorator.ItemExclusionPolicy { 24 | 25 | override fun shouldExclude(view: View, parent: RecyclerView): Boolean { 26 | return (parent.getChildAdapterPosition(view) == ((parent.adapter?.itemCount ?: 0) - 1)) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /commons-widgets/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons-widgets/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | buildFeatures { 40 | viewBinding = true 41 | } 42 | 43 | compileOptions { 44 | sourceCompatibility = appConfig.javaCompatibilityVersion 45 | targetCompatibility = appConfig.javaCompatibilityVersion 46 | } 47 | 48 | kotlinOptions { 49 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 50 | } 51 | } 52 | 53 | dependencies { 54 | implementation(project(deps.local.commons)) 55 | implementation(project(deps.local.commonsKtx)) 56 | 57 | implementation(deps.appCompat) 58 | implementation(deps.coreKtx) 59 | } 60 | 61 | publishingConfig.artifactName = publishingConfig.commonsWidgetsArtifactName 62 | publishingConfig.artifactVersion = publishingConfig.commonsWidgetsArtifactVersion 63 | 64 | apply(from = "../publishing.gradle.kts") 65 | -------------------------------------------------------------------------------- /commons-widgets/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 -------------------------------------------------------------------------------- /commons-widgets/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons-widgets/src/main/java/com/paulrybitskyi/commons/widgets/AdvancedViewPager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.widgets 18 | 19 | import android.content.Context 20 | import android.util.AttributeSet 21 | import android.view.MotionEvent 22 | import androidx.viewpager.widget.ViewPager 23 | 24 | class AdvancedViewPager @JvmOverloads constructor( 25 | context: Context, 26 | attrs: AttributeSet? = null 27 | ) : ViewPager(context, attrs) { 28 | 29 | var isSwipingEnabled = true 30 | 31 | fun enableSwiping() { 32 | isSwipingEnabled = true 33 | } 34 | 35 | fun disableSwiping() { 36 | isSwipingEnabled = false 37 | } 38 | 39 | override fun onTouchEvent(event: MotionEvent): Boolean { 40 | return (isSwipingEnabled && super.onTouchEvent(event)) 41 | } 42 | 43 | override fun onInterceptTouchEvent(event: MotionEvent): Boolean { 44 | return (isSwipingEnabled && super.onInterceptTouchEvent(event)) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /commons-widgets/src/main/java/com/paulrybitskyi/commons/widgets/toolbar/ButtonInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.widgets.toolbar 18 | 19 | import android.widget.FrameLayout 20 | import android.widget.ImageView 21 | 22 | internal class ButtonInfo( 23 | val containerView: FrameLayout, 24 | val iconView: ImageView 25 | ) 26 | -------------------------------------------------------------------------------- /commons-widgets/src/main/java/com/paulrybitskyi/commons/widgets/toolbar/TitleGravity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.widgets.toolbar 18 | 19 | import android.view.Gravity 20 | 21 | enum class TitleGravity( 22 | internal val id: Int, 23 | internal val gravity: Int 24 | ) { 25 | 26 | LEFT( 27 | id = 1, 28 | gravity = Gravity.START 29 | ), 30 | CENTER( 31 | id = 2, 32 | gravity = Gravity.CENTER 33 | ), 34 | RIGHT( 35 | id = 3, 36 | gravity = Gravity.END 37 | ); 38 | 39 | companion object { 40 | 41 | @JvmName("forId") 42 | @JvmStatic 43 | internal fun Int.asTitleGravity(): TitleGravity { 44 | return values().find { it.id == this } 45 | ?: throw IllegalArgumentException("Could not find the title gravity for the specified ID: $this.") 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /commons-widgets/src/main/java/com/paulrybitskyi/commons/widgets/toolbar/configs/ButtonConfig.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.widgets.toolbar.configs 18 | 19 | data class ButtonConfig( 20 | val buttonContainerSize: Int, 21 | val buttonIconSize: Int, 22 | val buttonIconPadding: Int 23 | ) 24 | -------------------------------------------------------------------------------- /commons-widgets/src/main/java/com/paulrybitskyi/commons/widgets/toolbar/configs/TitleConfig.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.widgets.toolbar.configs 18 | 19 | data class TitleConfig( 20 | val horizontalPaddingWithoutIcon: Int, 21 | val horizontalPaddingWithIcon: Int 22 | ) 23 | -------------------------------------------------------------------------------- /commons-widgets/src/main/res/layout/view_info.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 27 | 28 | 34 | 35 | 47 | 48 | 60 | 61 | -------------------------------------------------------------------------------- /commons-widgets/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | -------------------------------------------------------------------------------- /commons-widgets/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | #000000 22 | #000000 23 | #000000 24 | 25 | @android:color/white 26 | #000000 27 | #10000000 28 | #000000 29 | #000000 30 | 31 | -------------------------------------------------------------------------------- /commons-widgets/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | 100dp 22 | 5dp 23 | 18sp 24 | 4dp 25 | 5dp 26 | 17sp 27 | 4dp 28 | 29 | 56dp 30 | 4dp 31 | @dimen/toolbar_height 32 | 28dp 33 | 2dp 34 | 16dp 35 | 20dp 36 | 18sp 37 | 38 | -------------------------------------------------------------------------------- /commons-widgets/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | sans-serif-medium 22 | 23 | -------------------------------------------------------------------------------- /commons-widgets/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | 27 | 28 | -------------------------------------------------------------------------------- /commons-window-anims/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons-window-anims/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | compileOptions { 40 | sourceCompatibility = appConfig.javaCompatibilityVersion 41 | targetCompatibility = appConfig.javaCompatibilityVersion 42 | } 43 | 44 | kotlinOptions { 45 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 46 | } 47 | } 48 | 49 | publishingConfig.artifactName = publishingConfig.commonsWindowAnimsArtifactName 50 | publishingConfig.artifactVersion = publishingConfig.commonsWindowAnimsArtifactVersion 51 | 52 | apply(from = "../publishing.gradle.kts") 53 | -------------------------------------------------------------------------------- /commons-window-anims/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 -------------------------------------------------------------------------------- /commons-window-anims/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/java/com/paulrybitskyi/commons/window/anims/ActivityExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("ActivityUtils") 18 | 19 | package com.paulrybitskyi.commons.window.anims 20 | 21 | import android.app.Activity 22 | 23 | /** 24 | * Overrides the animations of the entering window. 25 | * 26 | * @param windowAnimations The animations to use for the entering window 27 | */ 28 | fun Activity.overrideEnterTransition(windowAnimations: WindowAnimations) { 29 | if (windowAnimations.id == WindowAnimations.DEFAULT_ANIMATIONS.id) { 30 | return 31 | } 32 | 33 | overridePendingTransition( 34 | windowAnimations.windowBEnterAnimation, 35 | windowAnimations.windowAExitAnimation 36 | ) 37 | } 38 | 39 | /** 40 | * Overrides the animations of the exiting window. 41 | * 42 | * @param windowAnimations The animations to use for the exiting window 43 | */ 44 | fun Activity.overrideExitTransition(windowAnimations: WindowAnimations) { 45 | if (windowAnimations.id == WindowAnimations.DEFAULT_ANIMATIONS.id) { 46 | return 47 | } 48 | 49 | overridePendingTransition( 50 | windowAnimations.windowAEnterAnimation, 51 | windowAnimations.windowBExitAnimation 52 | ) 53 | } 54 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/fade_in_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 29 | 30 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/fade_out_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 29 | 30 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/horizontal_sliding_window_a_enter_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 28 | 29 | 34 | 35 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/horizontal_sliding_window_a_exit_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 28 | 29 | 34 | 35 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/horizontal_sliding_window_b_enter_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 29 | 30 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/horizontal_sliding_window_b_exit_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 29 | 30 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/kitkat_scaling_window_a_enter_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 24 | 25 | 33 | 34 | 38 | 39 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/kitkat_scaling_window_a_exit_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 24 | 25 | 33 | 34 | 38 | 39 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/kitkat_scaling_window_b_enter_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 24 | 25 | 33 | 34 | 38 | 39 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/kitkat_scaling_window_b_exit_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 24 | 25 | 33 | 34 | 38 | 39 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/no_window_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 22 | 23 | 28 | 29 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/overshoot_scaling_window_a_enter_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 33 | 34 | 39 | 40 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/overshoot_scaling_window_a_exit_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 33 | 34 | 39 | 40 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/overshoot_scaling_window_b_enter_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 33 | 34 | 39 | 40 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/overshoot_scaling_window_b_exit_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 33 | 34 | 39 | 40 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/sliding_animation_decelerate_interpolator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/vertical_sliding_window_a_enter_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 22 | 23 | 28 | 29 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/vertical_sliding_window_a_exit_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 22 | 23 | 28 | 29 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/vertical_sliding_window_b_enter_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 22 | 23 | 28 | 29 | -------------------------------------------------------------------------------- /commons-window-anims/src/main/res/anim/vertical_sliding_window_b_exit_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 22 | 23 | 28 | 29 | -------------------------------------------------------------------------------- /commons/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /commons/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | androidLibrary() 19 | kotlinAndroid() 20 | } 21 | 22 | android { 23 | compileSdk = appConfig.compileSdkVersion 24 | 25 | defaultConfig { 26 | minSdk = appConfig.minSdkVersion 27 | targetSdk = appConfig.targetSdkVersion 28 | 29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | 32 | buildTypes { 33 | getByName("release") { 34 | isMinifyEnabled = false 35 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 36 | } 37 | } 38 | 39 | buildFeatures { 40 | viewBinding = true 41 | } 42 | 43 | compileOptions { 44 | sourceCompatibility = appConfig.javaCompatibilityVersion 45 | targetCompatibility = appConfig.javaCompatibilityVersion 46 | } 47 | 48 | kotlinOptions { 49 | jvmTarget = appConfig.kotlinCompatibilityVersion.toString() 50 | } 51 | } 52 | 53 | dependencies { 54 | implementation(deps.appCompat) 55 | implementation(deps.lifecycleCommonJava8) 56 | implementation(deps.lifecycleViewModel) 57 | } 58 | 59 | publishingConfig.artifactName = publishingConfig.commonsCoreArtifactName 60 | publishingConfig.artifactVersion = publishingConfig.commonsCoreArtifactVersion 61 | 62 | apply(from = "../publishing.gradle.kts") 63 | -------------------------------------------------------------------------------- /commons/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 -------------------------------------------------------------------------------- /commons/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /commons/src/main/java/com/paulrybitskyi/commons/SdkInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons 18 | 19 | import android.os.Build 20 | 21 | object SdkInfo { 22 | 23 | @JvmField val SDK_VERSION = Build.VERSION.SDK_INT 24 | 25 | @JvmField val IS_AT_LEAST_KITKAT = (SDK_VERSION >= Build.VERSION_CODES.KITKAT) 26 | @JvmField val IS_AT_LEAST_LOLLIPOP = (SDK_VERSION >= Build.VERSION_CODES.LOLLIPOP) 27 | @JvmField val IS_AT_LEAST_LOLLIPOP_MR1 = (SDK_VERSION >= Build.VERSION_CODES.LOLLIPOP_MR1) 28 | @JvmField val IS_AT_LEAST_MARSHMALLOW = (SDK_VERSION >= Build.VERSION_CODES.M) 29 | @JvmField val IS_AT_LEAST_NOUGAT = (SDK_VERSION >= Build.VERSION_CODES.N) 30 | @JvmField val IS_AT_LEAST_NOUGAT_MR1 = (SDK_VERSION >= Build.VERSION_CODES.N_MR1) 31 | @JvmField val IS_AT_LEAST_OREO = (SDK_VERSION >= Build.VERSION_CODES.O) 32 | @JvmField val IS_AT_LEAST_OREO_MR1 = (SDK_VERSION >= Build.VERSION_CODES.O_MR1) 33 | @JvmField val IS_AT_LEAST_PIE = (SDK_VERSION >= Build.VERSION_CODES.P) 34 | @JvmField val IS_AT_LEAST_10 = (SDK_VERSION >= Build.VERSION_CODES.Q) 35 | @JvmField val IS_AT_LEAST_11 = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) 36 | } 37 | -------------------------------------------------------------------------------- /commons/src/main/java/com/paulrybitskyi/commons/utils/DelegateUtils.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.utils 18 | 19 | import kotlin.properties.Delegates 20 | import kotlin.properties.ReadWriteProperty 21 | 22 | fun observeChanges( 23 | initialValue: T, 24 | onChange: (oldValue: T, newValue: T) -> Unit 25 | ): ReadWriteProperty { 26 | return Delegates.observable(initialValue) { _, oldValue, newValue -> 27 | onChange(oldValue, newValue) 28 | } 29 | } 30 | 31 | fun vetoable( 32 | initialValue: T, 33 | onChange: (oldValue: T, newValue: T) -> Boolean 34 | ): ReadWriteProperty { 35 | return Delegates.vetoable(initialValue) { _, oldValue, newValue -> 36 | onChange(oldValue, newValue) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /commons/src/main/java/com/paulrybitskyi/commons/utils/ViewBindingUtils.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Paul Rybitskyi, oss@paulrybitskyi.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.paulrybitskyi.commons.utils 18 | 19 | import android.view.LayoutInflater 20 | import android.view.View 21 | import androidx.appcompat.app.AppCompatActivity 22 | import androidx.fragment.app.Fragment 23 | import androidx.lifecycle.DefaultLifecycleObserver 24 | import androidx.lifecycle.Lifecycle 25 | import androidx.lifecycle.LifecycleOwner 26 | import androidx.viewbinding.ViewBinding 27 | import kotlin.properties.ReadOnlyProperty 28 | import kotlin.reflect.KProperty 29 | 30 | inline fun AppCompatActivity.viewBinding( 31 | crossinline bindingInflater: (LayoutInflater) -> T 32 | ): Lazy { 33 | return lazy(LazyThreadSafetyMode.NONE) { 34 | bindingInflater(layoutInflater) 35 | } 36 | } 37 | 38 | fun Fragment.viewBinding( 39 | viewBindingFactory: (View) -> T 40 | ): FragmentViewBindingDelegate { 41 | return FragmentViewBindingDelegate(this, viewBindingFactory) 42 | } 43 | 44 | class FragmentViewBindingDelegate( 45 | private val fragment: Fragment, 46 | private val viewBindingFactory: (View) -> T 47 | ) : ReadOnlyProperty { 48 | 49 | private var binding: T? = null 50 | 51 | init { 52 | // Keeping a view reference up until Fragment's onDestroy is called 53 | // to prevent its recreation when the back stack changes 54 | fragment.lifecycle.addObserver(object : DefaultLifecycleObserver { 55 | 56 | override fun onDestroy(owner: LifecycleOwner) { 57 | binding = null 58 | } 59 | }) 60 | } 61 | 62 | override fun getValue(thisRef: Fragment, property: KProperty<*>): T { 63 | if (binding != null) { 64 | return checkNotNull(binding) 65 | } 66 | 67 | val lifecycle = fragment.viewLifecycleOwner.lifecycle 68 | 69 | if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) { 70 | throw IllegalStateException("Could not retrieve a view binding when the fragment is not initialized.") 71 | } 72 | 73 | return viewBindingFactory(thisRef.requireView()) 74 | .also { binding = it } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /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 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 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars885/android-commons/80ff7fc27640132e74ae415fbf5115b410dda3a0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Aug 08 00:19:51 EEST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /hooks/pre-push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Running Git Pre-Push Hook" 4 | 5 | ###################################### 6 | 7 | echo "Running Android Lint" 8 | ./gradlew lint 9 | RESULT_LINT=$? 10 | if [ $RESULT_LINT -ne 0 ] 11 | then 12 | exit 1 13 | fi 14 | 15 | ###################################### 16 | 17 | echo "Running Detekt" 18 | ./gradlew detekt --continue 19 | RESULT_DETEKT=$? 20 | if [ $RESULT_DETEKT -ne 0 ] 21 | then 22 | exit 1 23 | fi 24 | 25 | ###################################### 26 | 27 | echo "Running Ktlint" 28 | ./gradlew ktlintCheck --continue 29 | RESULT_KTLINT=$? 30 | if [ $RESULT_KTLINT -ne 0 ] 31 | then 32 | exit 1 33 | fi 34 | 35 | ###################################### 36 | 37 | echo "Static Analysis Checks Completed Successfully" 38 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "AndroidCommons" 2 | 3 | include(":app") 4 | include(":commons") 5 | include(":commons-ktx") 6 | include(":commons-window-anims") 7 | include(":commons-recyclerview") 8 | include(":commons-material") 9 | include(":commons-navigation") 10 | include(":commons-device-info") 11 | include(":commons-network") 12 | include(":commons-widgets") 13 | include(":commons-listeners") 14 | --------------------------------------------------------------------------------