15 |
--------------------------------------------------------------------------------
/fastadapter/src/main/res/layout/kau_iitem_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/values/strings_mediapicker.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | No items found
4 | No items have been selected
5 | Blurrable ImageView
6 | No items loaded
7 |
8 | No camera found
9 | Please install a camera app and try again.
10 |
11 | Failed to create a temporary file.
12 |
13 | Select Media
14 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: allanwang # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/searchview/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/searchview/README.md:
--------------------------------------------------------------------------------
1 | # KAU :searchview
2 |
3 | KAU contains a fully functional SearchView that can be added programmatically with one line.
4 | It contains a `bindSearchView` extension functions for both activities and viewgroups.
5 |
6 | 
7 |
8 | The searchview is:
9 | * Fully themable - set the foreground or background color to style every portion, from text colors to backgrounds to ripples
10 | * Complete - binding the search view to a menu id will set the menu icon (if not previously set) and attach all the necessary listeners
11 | * Configurable - modify any portion of the inner Config class when binding the search view
12 | * Debouncable - specify a time interval to throttle your queries; see [debouncing](../core#debounce)
13 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelperExtras.java:
--------------------------------------------------------------------------------
1 | package ca.allanwang.kau.swipe;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by Allan Wang on 2017-07-05.
7 | *
8 | * Collection of addition methods added into ViewDragHelper that weren't in the original
9 | */
10 |
11 | interface ViewDragHelperExtras {
12 |
13 | /**
14 | * Sets the new size of a given edge
15 | * Any touch within this range will be defined to have started from an edge
16 | *
17 | * @param size the new size in px
18 | */
19 | void setEdgeSize(int size);
20 |
21 | void setMaxVelocity(float maxVel);
22 |
23 | float getMaxVelocity();
24 |
25 | void setSensitivity(Context context, float sensitivity);
26 |
27 | float getSensitivity();
28 |
29 | int STATE_JUDGING = 3;
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/.idea/copyright/Apache.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/kotlin/Utils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kotlin
17 |
18 | /** Created by Allan Wang on 07/04/18. */
19 | inline fun javaClass(): Class = T::class.java
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /crowdin.properties
3 | /local.properties
4 | .DS_Store
5 | /build
6 | /captures
7 | .externalNativeBuild
8 | **/public.xml
9 |
10 | # Intellij
11 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
12 | *.iml
13 | .idea/**/workspace.xml
14 | .idea/**/tasks.xml
15 | .idea/**/usage.statistics.xml
16 | .idea/**/dictionaries
17 | .idea/**/shelf
18 | .idea/**/contentModel.xml
19 | .idea/**/dataSources/
20 | .idea/**/dataSources.ids
21 | .idea/**/dataSources.local.xml
22 | .idea/**/sqlDataSources.xml
23 | .idea/**/dynamic.xml
24 | .idea/**/uiDesigner.xml
25 | .idea/**/dbnavigator.xml
26 | .idea/**/gradle.xml
27 | .idea/**/libraries
28 | .idea/**/assetWizardSettings.xml
29 | .idea/**/caches
30 | .idea/modules.xml
31 | .idea/modules
32 | .idea/vcs.xml
33 | .idea/compiler.xml
34 | .idea/misc.xml
35 | .idea/codeStyles/Project.xml
--------------------------------------------------------------------------------
/fastadapter-viewbinding/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
22 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/kotlin/LazyUi.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Allan Wang
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 | package ca.allanwang.kau.kotlin
17 |
18 | /** Shortcut for unsynchronized lazy block */
19 | fun lazyUi(initializer: () -> T): Lazy = lazy(LazyThreadSafetyMode.NONE, initializer)
20 |
--------------------------------------------------------------------------------
/favicon/safari-pinned-tab.svg:
--------------------------------------------------------------------------------
1 |
2 |
4 |
18 |
--------------------------------------------------------------------------------
/core-ui/src/main/res-public/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/fastadapter/README.md:
--------------------------------------------------------------------------------
1 | # KAU :fastadapter
2 |
3 | Collection of kotlin bindings and custom IItems for [Fast Adapter](https://github.com/mikepenz/FastAdapter)
4 |
5 | ## KauIItems
6 |
7 | Abstract base that extends `AbstractIItems` and contains the arguments `(layoutRes, ViewHolder lambda, idRes)` in that order.
8 | Those variables are used to override the default abstract functions.
9 | If a layout is only used for one item, it may also be used as the id, which you may leave blank in this case.
10 | The ViewHolder lambda is typically of the form `::ViewHolder`
11 | Where you will have a nested class `ViewHolder(v: View) : RecyclerView.ViewHolder(v)`
12 |
13 | ## IItem Templates
14 |
15 | * CardIItem - generic all encompassing card item with a title, description, imageview, and button.
16 | All items except for the title are optional.
17 | * HeaderIItem - simple title container with a big top margin
--------------------------------------------------------------------------------
/core/src/main/res-public/transition-v21/kau_exit_slide_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/core/src/main/res-public/transition-v21/kau_exit_slide_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/core/src/main/res-public/transition-v21/kau_exit_slide_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/core/src/main/res-public/transition-v21/kau_exit_slide_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/core/src/main/res-public/transition-v21/kau_enter_slide_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/core/src/main/res-public/transition-v21/kau_enter_slide_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout-v21/kau_activity_image_picker_overlay.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
--------------------------------------------------------------------------------
/core/src/androidTest/kotlin/ca/allanwang/kau/Utils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Allan Wang
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 | package ca.allanwang.kau
17 |
18 | import android.content.Context
19 | import androidx.test.platform.app.InstrumentationRegistry
20 |
21 | val context: Context
22 | get() = InstrumentationRegistry.getInstrumentation().context
23 |
--------------------------------------------------------------------------------
/core/src/main/res-public/transition-v21/kau_enter_slide_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/core/src/main/res-public/transition-v21/kau_enter_slide_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.sample
17 |
18 | import android.app.Application
19 | import dagger.hilt.android.HiltAndroidApp
20 |
21 | /** Created by Allan Wang on 2017-06-08. */
22 | @HiltAndroidApp class SampleApp : Application()
23 |
--------------------------------------------------------------------------------
/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefItemActions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Allan Wang
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 | package ca.allanwang.kau.kpref.activity
17 |
18 | /** Applicable actions */
19 | interface KPrefItemActions {
20 | /** Attempts to reload current item by identifying it with its titleId */
21 | fun reloadSelf()
22 | }
23 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.utils
17 |
18 | import androidx.fragment.app.Fragment
19 |
20 | /** Created by Allan Wang on 2017-07-02. */
21 | fun T.withArguments(vararg params: Pair): T {
22 | arguments = bundleOf(*params)
23 | return this
24 | }
25 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/permission_checkbox.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
22 |
23 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/utils/NotificationUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.utils
17 |
18 | import android.content.Context
19 | import androidx.core.app.NotificationManagerCompat
20 |
21 | /** Created by Allan Wang on 2017-08-04. */
22 | fun Context.cancelNotification(notifId: Int) = NotificationManagerCompat.from(this).cancel(notifId)
23 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.utils
17 |
18 | import java.io.File
19 | import java.io.InputStream
20 |
21 | /** Created by Allan Wang on 2017-08-04. */
22 | fun File.copyFromInputStream(inputStream: InputStream) =
23 | inputStream.use { input -> outputStream().use { output -> input.copyTo(output) } }
24 |
--------------------------------------------------------------------------------
/kpref-activity/src/main/res-public/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
31 |
32 |
--------------------------------------------------------------------------------
/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/BaseTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Allan Wang
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 | package ca.allanwang.kau.sample.test
17 |
18 | import dagger.hilt.android.testing.HiltAndroidRule
19 | import kotlin.test.BeforeTest
20 | import org.junit.Rule
21 |
22 | abstract class BaseTest {
23 | @Suppress("LeakingThis") @get:Rule val hiltRule: HiltAndroidRule = HiltAndroidRule(this)
24 |
25 | @BeforeTest
26 | fun before() {
27 | hiltRule.inject()
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/core/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/about/src/main/kotlin/ca/allanwang/kau/about/AboutBinder.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.about
17 |
18 | import android.content.Context
19 | import ca.allanwang.kau.utils.startActivity
20 | import ca.allanwang.kau.utils.withSceneTransitionAnimation
21 |
22 | /** Created by Allan Wang on 2017-07-22. */
23 |
24 | /** About activity launcher */
25 | inline fun Context.kauLaunchAbout() =
26 | startActivity(bundleBuilder = { withSceneTransitionAnimation(this@kauLaunchAbout) })
27 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.logging
17 |
18 | import ca.allanwang.kau.BuildConfig
19 |
20 | /**
21 | * Created by Allan Wang on 2017-06-19.
22 | *
23 | * Internal KAU logger
24 | */
25 | object KL : KauLogger("KAU", { BuildConfig.DEBUG }) {
26 |
27 | /** Logger with searchable tag and thread info */
28 | inline fun test(message: () -> Any?) {
29 | if (BuildConfig.DEBUG) d { "Test1234 ${Thread.currentThread().name} ${message()}" }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/searchview/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2dp
4 | 4dp
5 | 1dp
6 | 12dp
7 | 4dp
8 | 46dp
9 | 56dp
10 | 56dp
11 | 24dp
12 | 16dp
13 | 8dp
14 | 1dp
15 | 2dp
16 | 24dp
17 | 24dp
18 | 16sp
19 | 12sp
20 | 14sp
21 |
22 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeListener.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.swipe
17 |
18 | interface SwipeListener {
19 | /**
20 | * Invoked as the page is scrolled Percent is capped at 1.0, even if there is a slight overscroll
21 | * for the pages
22 | */
23 | fun onScroll(percent: Float, px: Int, edgeFlag: Int)
24 |
25 | /** Invoked when page first consumes the scroll events */
26 | fun onEdgeTouch()
27 |
28 | /** Invoked when scroll percent over the threshold for the first time */
29 | fun onScrollToClose(edgeFlag: Int)
30 | }
31 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/kau.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
16 |
20 |
24 |
28 |
--------------------------------------------------------------------------------
/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KClick.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kpref.activity
17 |
18 | import android.content.Context
19 | import android.view.View
20 | import ca.allanwang.kau.kpref.activity.items.KPrefItemBase
21 |
22 | /** Created by Allan Wang on 10/12/17. */
23 | interface KClick {
24 |
25 | val context: Context
26 | /** Base view container from ViewHolder */
27 | val itemView: View
28 |
29 | /** Optional inner view which differs per element */
30 | val innerView: View?
31 |
32 | /** The item holding the data */
33 | val item: KPrefItemBase
34 | }
35 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
16 |
17 |
21 |
22 |
25 |
26 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/kau_blurred_imageview.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
20 |
21 |
30 |
31 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/utils/AnimHolder.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.utils
17 |
18 | import android.os.Build
19 | import androidx.annotation.RequiresApi
20 | import ca.allanwang.kau.kotlin.lazyInterpolator
21 |
22 | /**
23 | * Created by Allan Wang on 2017-06-28.
24 | *
25 | * Holder for a bunch of common animators/interpolators used throughout this library
26 | */
27 | object AnimHolder {
28 |
29 | @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
30 | val fastOutSlowInInterpolator = lazyInterpolator(android.R.interpolator.fast_out_linear_in)
31 | val decelerateInterpolator = lazyInterpolator(android.R.interpolator.decelerate_cubic)
32 | }
33 |
--------------------------------------------------------------------------------
/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/PrefFactoryTestModule.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Allan Wang
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 | package ca.allanwang.kau.sample.test
17 |
18 | import ca.allanwang.kau.kpref.KPrefFactory
19 | import ca.allanwang.kau.kpref.KPrefFactoryInMemory
20 | import ca.allanwang.kau.sample.PrefFactoryModule
21 | import dagger.Module
22 | import dagger.Provides
23 | import dagger.hilt.components.SingletonComponent
24 | import dagger.hilt.testing.TestInstallIn
25 |
26 | @Module
27 | @TestInstallIn(components = [SingletonComponent::class], replaces = [PrefFactoryModule::class])
28 | object PrefFactoryTestModule {
29 | @Provides fun factory(): KPrefFactory = KPrefFactoryInMemory
30 | }
31 |
--------------------------------------------------------------------------------
/core/src/main/res/layout/kau_changelog_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
21 |
22 |
29 |
30 |
--------------------------------------------------------------------------------
/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.mediapicker
17 |
18 | import android.view.View
19 | import com.bumptech.glide.Glide
20 | import com.bumptech.glide.RequestManager
21 |
22 | /**
23 | * Created by Allan Wang on 29/08/2017.
24 | *
25 | * Basic helper to fetch the [RequestManager] from the activity if it exists, before creating
26 | * another one
27 | */
28 | internal interface GlideContract {
29 | fun glide(v: View): RequestManager
30 | }
31 |
32 | internal class GlideDelegate : GlideContract {
33 | override fun glide(v: View) = ((v.context as? MediaPickerCore<*>)?.glide ?: Glide.with(v))!!
34 | }
35 |
--------------------------------------------------------------------------------
/core-ui/src/main/res-public/layout/kau_recycler_detached_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
15 |
16 |
17 |
18 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/utils/DrawableUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.utils
17 |
18 | import android.content.res.ColorStateList
19 | import android.graphics.drawable.Drawable
20 | import androidx.annotation.ColorInt
21 | import androidx.core.graphics.drawable.DrawableCompat
22 |
23 | /** Wrap the color into a state and tint the drawable */
24 | fun Drawable.tint(@ColorInt color: Int): Drawable = tint(ColorStateList.valueOf(color))
25 |
26 | /** Tint the drawable with a given color state list */
27 | fun Drawable.tint(state: ColorStateList): Drawable {
28 | val drawable = DrawableCompat.wrap(mutate())
29 | DrawableCompat.setTintList(drawable, state)
30 | return drawable
31 | }
32 |
--------------------------------------------------------------------------------
/about/src/main/res/layout/kau_activity_about.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/about/src/main/res/layout/kau_about_section_libraries.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/utils/EspressoUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.sample.utils
17 |
18 | import org.hamcrest.BaseMatcher
19 | import org.hamcrest.Description
20 | import org.hamcrest.Matcher
21 |
22 | fun index(index: Int, matcher: Matcher): Matcher =
23 | object : BaseMatcher() {
24 |
25 | var current = 0
26 |
27 | override fun describeTo(description: Description) {
28 | description.appendText("Should return item at index $index")
29 | }
30 |
31 | override fun matches(item: Any?): Boolean {
32 | println("AA")
33 | return matcher.matches(item) && current++ == index
34 | }
35 | }
36 |
37 | fun first(matcher: Matcher): Matcher = index(0, matcher)
38 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefFactory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Allan Wang
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 | package ca.allanwang.kau.kpref
17 |
18 | import android.content.Context
19 |
20 | interface KPrefFactory {
21 | fun createBuilder(preferenceName: String): KPrefBuilder
22 | }
23 |
24 | /** Default factory for Android preferences */
25 | class KPrefFactoryAndroid(context: Context) : KPrefFactory {
26 |
27 | val context: Context = context.applicationContext
28 |
29 | override fun createBuilder(preferenceName: String): KPrefBuilder =
30 | KPrefBuilderAndroid(context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE))
31 | }
32 |
33 | object KPrefFactoryInMemory : KPrefFactory {
34 | override fun createBuilder(preferenceName: String): KPrefBuilder = KPrefBuilderInMemory
35 | }
36 |
--------------------------------------------------------------------------------
/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.searchview
17 |
18 | import android.view.MenuItem
19 |
20 | /**
21 | * Created by Allan Wang on 2017-11-12.
22 | *
23 | * Interface to help facilitate searchview binding and actions
24 | */
25 | interface SearchViewHolder {
26 |
27 | var searchView: SearchView?
28 |
29 | fun searchViewBindIfNull(binder: () -> SearchView) {
30 | if (searchView == null) searchView = binder()
31 | }
32 |
33 | fun searchViewOnBackPress() = searchView?.onBackPressed() ?: false
34 |
35 | fun searchViewUnBind(replacementMenuItemClickListener: ((item: MenuItem) -> Boolean)? = null) {
36 | searchView?.unBind(replacementMenuItemClickListener)
37 | searchView = null
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kpref.activity.items
17 |
18 | import ca.allanwang.kau.kpref.activity.R
19 |
20 | /**
21 | * Created by Allan Wang on 2017-06-07.
22 | *
23 | * Header preference This view just holds a title and is not clickable. It is styled using the
24 | * accent color
25 | */
26 | open class KPrefHeader(builder: CoreContract) : KPrefItemCore(builder) {
27 |
28 | override val layoutRes: Int
29 | get() = R.layout.kau_pref_header
30 |
31 | override fun bindView(holder: ViewHolder, payloads: List) {
32 | super.bindView(holder, payloads)
33 | withAccentColor(holder.title::setTextColor)
34 | }
35 |
36 | override val type: Int
37 | get() = R.id.kau_item_pref_header
38 | }
39 |
--------------------------------------------------------------------------------
/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaType.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.mediapicker
17 |
18 | import android.net.Uri
19 | import android.provider.MediaStore
20 | import com.bumptech.glide.load.engine.DiskCacheStrategy
21 |
22 | /** Created by Allan Wang on 2017-07-30. */
23 | enum class MediaType(
24 | val cacheStrategy: DiskCacheStrategy,
25 | val mimeType: String,
26 | val captureType: String,
27 | val contentUri: Uri
28 | ) {
29 | IMAGE(
30 | DiskCacheStrategy.AUTOMATIC,
31 | "image/*",
32 | MediaStore.ACTION_IMAGE_CAPTURE,
33 | MediaStore.Images.Media.EXTERNAL_CONTENT_URI
34 | ),
35 | VIDEO(
36 | DiskCacheStrategy.AUTOMATIC,
37 | "video/*",
38 | MediaStore.ACTION_VIDEO_CAPTURE,
39 | MediaStore.Video.Media.EXTERNAL_CONTENT_URI
40 | )
41 | }
42 |
--------------------------------------------------------------------------------
/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/MeasuredImageView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.ui.views
17 |
18 | import android.content.Context
19 | import android.util.AttributeSet
20 | import androidx.appcompat.widget.AppCompatImageView
21 |
22 | /** Created by Allan Wang on 2017-07-14. */
23 | class MeasuredImageView
24 | @JvmOverloads
25 | constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
26 | AppCompatImageView(context, attrs, defStyleAttr), MeasureSpecContract by MeasureSpecDelegate() {
27 |
28 | init {
29 | initAttrs(context, attrs)
30 | }
31 |
32 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
33 | val result = onMeasure(this, widthMeasureSpec, heightMeasureSpec)
34 | super.onMeasure(result.first, result.second)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/about/src/main/res/layout/kau_iitem_faq.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
27 |
28 |
29 |
30 |
36 |
37 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/utils/Const.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.utils
17 |
18 | import androidx.customview.widget.ViewDragHelper
19 |
20 | /** Created by Allan Wang on 2017-06-08. */
21 | const val ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android"
22 |
23 | const val KAU_LEFT = ViewDragHelper.EDGE_LEFT
24 | const val KAU_RIGHT = ViewDragHelper.EDGE_RIGHT
25 | const val KAU_TOP = ViewDragHelper.EDGE_TOP
26 | const val KAU_BOTTOM = ViewDragHelper.EDGE_BOTTOM
27 | const val KAU_HORIZONTAL = KAU_LEFT or KAU_RIGHT
28 | const val KAU_VERTICAL = KAU_TOP or KAU_BOTTOM
29 | const val KAU_ALL = KAU_HORIZONTAL or KAU_VERTICAL
30 |
31 | const val KAU_COLLAPSED = 0
32 | const val KAU_COLLAPSING = 1
33 | const val KAU_EXPANDING = 2
34 | const val KAU_EXPANDED = 3
35 |
36 | const val KAU_ELLIPSIS = '\u2026'
37 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.utils
17 |
18 | import android.content.Context
19 | import android.graphics.Color
20 | import android.graphics.drawable.Drawable
21 | import androidx.annotation.ColorInt
22 | import com.mikepenz.iconics.IconicsDrawable
23 | import com.mikepenz.iconics.dsl.iconicsDrawable
24 | import com.mikepenz.iconics.typeface.IIcon
25 |
26 | /** Created by Allan Wang on 2017-05-29. */
27 | @KauUtils
28 | fun IIcon.toDrawable(
29 | c: Context,
30 | sizeDp: Int = 24,
31 | @ColorInt color: Int = Color.WHITE,
32 | builder: IconicsDrawable.() -> Unit = {}
33 | ): Drawable =
34 | c.iconicsDrawable(this) {
35 | this.color = colorInt(color)
36 | if (sizeDp > 0) {
37 | size = sizeDp(sizeDp)
38 | }
39 | }
40 | .apply(builder)
41 |
--------------------------------------------------------------------------------
/core-ui/README.md:
--------------------------------------------------------------------------------
1 | # KAU :core-ui
2 |
3 | Holds a collection of generic UIs.
4 | This submodule takes heavy influence from [Plaid](https://github.com/nickbutcher/plaid), a beautiful showcase for Material Design.
5 |
6 | ## BoundedCardView
7 |
8 | Extends a CardView and provides `maxHeight` and `maxHeightPercentage` attributes.
9 | These values are judged once the view it attached and can be helpful to limit the size with respect to its parent.
10 |
11 | One example is in KAU's `:searchview`, where the search results will always allow some space below it for the user to tap and exit.
12 |
13 | ## CutoutView
14 |
15 | > Courtesy of Plaid
16 |
17 | Given a background and a text/vector, will "erase" the text/vector from the background.
18 | This can be seen in effect in KAU's `:about` submodule.
19 |
20 | ## ElasticDragDismissFrameLayout
21 |
22 | > Courtesy of Plaid
23 |
24 | When scrolling vertically, this frame will allow for overscrolling and will pull the layout out of view and exit if a threshold is reached.
25 | Note that Activities with this frame must be translucent. `@style/Kau.Translucent` can be used as a base.
26 |
27 | ## InkPageIndicator
28 |
29 | > Courtesy of Plaid
30 |
31 | A beautiful viewpager indicator
32 |
33 | 
34 |
35 | ## TextSlider
36 |
37 | An animated and themable Text Switcher. Specify its direction and set a new text value and it will slide it into view.
--------------------------------------------------------------------------------
/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.iitems
17 |
18 | import android.view.View
19 | import androidx.annotation.LayoutRes
20 | import androidx.recyclerview.widget.RecyclerView
21 | import com.mikepenz.fastadapter.items.AbstractItem
22 |
23 | /**
24 | * Created by Allan Wang on 2017-07-03.
25 | *
26 | * Kotlin implementation of the [AbstractItem] to make things shorter If only one iitem type extends
27 | * the given [layoutRes], you may use it as the type and not worry about another id
28 | */
29 | open class KauIItem(
30 | @param:LayoutRes override val layoutRes: Int,
31 | private val viewHolder: (v: View) -> VH,
32 | override val type: Int = layoutRes
33 | ) : AbstractItem() {
34 | final override fun getViewHolder(v: View): VH = viewHolder(v)
35 | }
36 |
--------------------------------------------------------------------------------
/about/src/main/res/values/strings_about_kau.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Allan Wang
4 | https://www.allanwang.ca/dev/
5 | @string/kau_version_code
6 | KAU
7 |
8 |
11 | KAU aims to make many common functions executable in one line. It adds numerous extensions to match Kotlin\'s DSL,
12 | and supports completely customizable view groups that are usable in any app project.
13 | ]]>
14 |
15 | https://allanwang.github.io/KAU/
16 | true
17 | https://github.com/AllanWang/KAU
18 | ca.allanwang.kau
19 | apache_2_0
20 |
--------------------------------------------------------------------------------
/core-ui/src/main/res-public/layout/kau_recycler_textslider.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
22 |
23 |
24 |
25 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kotlin
17 |
18 | /** Created by Allan Wang on 2017-08-05. */
19 |
20 | /**
21 | * Replica of [java.util.Vector.removeIf] in Java Since we don't have access to the internals of our
22 | * extended class, We will simply iterate and remove when the filter returns {@code false}
23 | */
24 | inline fun > C.kauRemoveIf(filter: (item: T) -> Boolean): C {
25 | val iter = iterator()
26 | while (iter.hasNext()) {
27 | if (filter(iter.next())) {
28 | iter.remove()
29 | }
30 | }
31 | return this
32 | }
33 |
34 | /** Returns the first element tha matches the predicate, or null if no match is found */
35 | inline fun Iterator.firstOrNull(predicate: (T) -> Boolean): T? {
36 | while (hasNext()) {
37 | val data = next()
38 | if (predicate(data)) {
39 | return data
40 | }
41 | }
42 | return null
43 | }
44 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.adapters
17 |
18 | import com.mikepenz.fastadapter.FastAdapter
19 | import com.mikepenz.fastadapter.GenericItem
20 | import com.mikepenz.fastadapter.IAdapter
21 | import com.mikepenz.fastadapter.select.SelectExtension
22 |
23 | /** Created by Allan Wang on 2017-11-08. */
24 |
25 | /** Add kotlin's generic syntax to better support out types */
26 | fun fastAdapter(vararg adapter: IAdapter): FastAdapter =
27 | FastAdapter.with(adapter.toList())
28 |
29 | /** Returns selection size, or -1 if selection is disabled */
30 | inline val IAdapter.selectionSize: Int
31 | get() = fastAdapter?.getExtension>()?.selections?.size ?: -1
32 |
33 | inline val IAdapter.selectedItems: Set
34 | get() = fastAdapter?.getExtension>()?.selectedItems ?: emptySet()
35 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/ui/SimpleRippleDrawable.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.ui
17 |
18 | import android.content.res.ColorStateList
19 | import android.graphics.drawable.ColorDrawable
20 | import android.graphics.drawable.RippleDrawable
21 | import android.os.Build
22 | import androidx.annotation.ColorInt
23 | import androidx.annotation.RequiresApi
24 | import ca.allanwang.kau.utils.adjustAlpha
25 |
26 | /**
27 | * Created by Allan Wang on 2017-06-24.
28 | *
29 | * Tries to mimic a standard ripple, given the foreground and background colors
30 | */
31 | @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
32 | fun createSimpleRippleDrawable(
33 | @ColorInt foregroundColor: Int,
34 | @ColorInt backgroundColor: Int
35 | ): RippleDrawable {
36 | val states = ColorStateList(arrayOf(intArrayOf()), intArrayOf(foregroundColor))
37 | val content = ColorDrawable(backgroundColor)
38 | val mask = ColorDrawable(foregroundColor.adjustAlpha(0.16f))
39 | return RippleDrawable(states, content, mask)
40 | }
41 |
--------------------------------------------------------------------------------
/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.sample
17 |
18 | import ca.allanwang.kau.about.AboutActivityBase
19 | import ca.allanwang.kau.adapters.FastItemThemedAdapter
20 | import ca.allanwang.kau.iitems.CardIItem
21 | import com.mikepenz.fastadapter.GenericItem
22 |
23 | /** Created by Allan Wang on 2017-06-27. */
24 | class AboutActivity : AboutActivityBase(R.string::class.java) {
25 |
26 | override fun Configs.buildConfigs() {
27 | cutoutDrawableRes = R.drawable.kau
28 | textColor = 0xde000000.toInt()
29 | backgroundColor = 0xfffafafa.toInt()
30 | accentColor = 0xff00838F.toInt()
31 | cutoutForeground = 0xff18FFFF.toInt()
32 | faqXmlRes = R.xml.kau_faq
33 | faqParseNewLine = false
34 | }
35 |
36 | override fun postInflateMainPage(adapter: FastItemThemedAdapter) {
37 | adapter.add(
38 | CardIItem {
39 | title = "About KAU"
40 | descRes = R.string.about_kau
41 | }
42 | )
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.permissions
17 |
18 | import android.content.pm.PackageManager
19 |
20 | /**
21 | * Created by Allan Wang on 2017-07-03.
22 | *
23 | * Pending permission collector
24 | */
25 | class PermissionResult(
26 | permissions: Array,
27 | val callback: (granted: Boolean, deniedPerm: String?) -> Unit
28 | ) {
29 | val permissions = mutableSetOf(*permissions)
30 |
31 | /**
32 | * Called from the manager whenever a permission has changed Returns true if result is completed,
33 | * false otherwise
34 | */
35 | fun onResult(permission: String, result: Int): Boolean {
36 | if (result != PackageManager.PERMISSION_GRANTED) {
37 | callback(false, permission)
38 | permissions.clear()
39 | return true
40 | }
41 | permissions.remove(permission)
42 | if (permissions.isNotEmpty()) {
43 | return false
44 | }
45 | callback(true, null)
46 | return true
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kpref.activity.items
17 |
18 | import ca.allanwang.kau.kpref.activity.GlobalOptions
19 | import ca.allanwang.kau.kpref.activity.KClick
20 | import ca.allanwang.kau.kpref.activity.R
21 |
22 | /**
23 | * Created by Allan Wang on 2017-06-14.
24 | *
25 | * Just text with the core options. Extends base preference but has an empty getter and setter
26 | * Useful replacement of [KPrefText] when nothing is displayed on the right side, and when the
27 | * preference is completely handled by the click
28 | */
29 | open class KPrefPlainText(open val builder: KPrefPlainTextBuilder) : KPrefItemBase(builder) {
30 |
31 | override fun KClick.defaultOnClick() = Unit
32 |
33 | class KPrefPlainTextBuilder(globalOptions: GlobalOptions, titleId: Int) :
34 | BaseContract by BaseBuilder(globalOptions, titleId, {}, {})
35 |
36 | override val type: Int
37 | get() = R.id.kau_item_pref_plain_text
38 | }
39 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.utils
17 |
18 | import android.graphics.Rect
19 | import android.view.View
20 | import androidx.recyclerview.widget.RecyclerView
21 |
22 | /** Created by Allan Wang on 2017-07-11. */
23 | fun RecyclerView.withMarginDecoration(sizeDp: Int, edgeFlags: Int) {
24 | addItemDecoration(MarginItemDecoration(sizeDp, edgeFlags))
25 | }
26 |
27 | class MarginItemDecoration(sizeDp: Int, val edgeFlags: Int) : RecyclerView.ItemDecoration() {
28 |
29 | private val sizePx = sizeDp.dpToPx
30 |
31 | override fun getItemOffsets(
32 | outRect: Rect,
33 | view: View,
34 | parent: RecyclerView,
35 | state: RecyclerView.State
36 | ) {
37 | super.getItemOffsets(outRect, view, parent, state)
38 | if (edgeFlags and KAU_LEFT > 0) outRect.left += sizePx
39 | if (edgeFlags and KAU_TOP > 0) outRect.top += sizePx
40 | if (edgeFlags and KAU_RIGHT > 0) outRect.right += sizePx
41 | if (edgeFlags and KAU_BOTTOM > 0) outRect.bottom += sizePx
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/core/src/test/kotlin/ca/allanwang/kau/kotlin/LazyResettableTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kotlin
17 |
18 | import kotlin.test.assertEquals
19 | import kotlin.test.assertNotEquals
20 | import org.junit.Before
21 | import org.junit.Test
22 |
23 | /**
24 | * Created by Allan Wang on 2017-07-29.
25 | *
26 | * Test code for [LazyResettable]
27 | */
28 | class LazyResettableTest {
29 |
30 | lateinit var registry: LazyResettableRegistry
31 |
32 | @Before
33 | fun init() {
34 | registry = LazyResettableRegistry()
35 | }
36 |
37 | @Test
38 | fun basic() {
39 | val timeDelegate = lazyResettable { System.currentTimeMillis() }
40 | val time: Long by timeDelegate
41 | registry.add(timeDelegate)
42 | val t1 = time
43 | Thread.sleep(5)
44 | val t2 = time
45 | registry.invalidateAll()
46 | Thread.sleep(5)
47 | val t3 = time
48 | assertEquals(t1, t2, "Lazy resettable not returning same value after second call")
49 | assertNotEquals(t1, t3, "Lazy resettable not invalidated by registry")
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - '*'
7 | - '!l10n_dev'
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - name: Checkout
16 | uses: actions/checkout@v2
17 | with:
18 | fetch-depth: 100
19 |
20 | - name: Fetch all tags
21 | run: git fetch origin +refs/tags/*:refs/tags/*
22 |
23 | - name: Set up JDK 11
24 | uses: actions/setup-java@v2
25 | with:
26 | java-version: '11'
27 | java-package: jdk
28 | distribution: 'adopt'
29 | cache: gradle
30 |
31 | - name: Validate gradle wrapper
32 | uses: gradle/wrapper-validation-action@v1
33 |
34 | - name: Decrypt secret
35 | if: ${{ false }}
36 | run: |
37 | gpg -d --passphrase "${{ secrets.KAU_TAR_SECRET }}" --batch "files/kau_github.tar.gpg" > "files/kau_github.tar"
38 | tar xvf files/kau_github.tar -C files
39 |
40 | - name: Checkout Gradle Build Cache
41 | if: ${{ steps.self_hosted.outputs.FLAG != 'self-hosted' }}
42 | uses: actions/cache@v2
43 | with:
44 | path: |
45 | ~/.gradle/caches
46 | ~/.gradle/wrapper
47 | !~/.gradle/wrapper/dists/**/gradle*.zip
48 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
49 | restore-keys: |
50 | gradle-${{ runner.os }}-
51 |
52 | - name: Grant execute permission for gradlew
53 | run: chmod +x gradlew
54 |
55 | - name: Android Git Version
56 | run: ./gradlew --quiet androidGitVersion
57 |
58 | - name: Check and Test
59 | run: ./gradlew spotlessCheck lintRelease testReleaseUnitTest
60 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.utils
17 |
18 | import android.content.Context
19 | import android.graphics.Typeface
20 |
21 | /** Created by Allan Wang on 2017-06-28. */
22 | object FontUtils {
23 |
24 | private val sTypefaceCache: MutableMap = mutableMapOf()
25 |
26 | fun get(context: Context, font: String): Typeface {
27 | synchronized(sTypefaceCache) {
28 | if (!sTypefaceCache.containsKey(font)) {
29 | val tf = Typeface.createFromAsset(context.applicationContext.assets, "fonts/$font.ttf")
30 | sTypefaceCache.put(font, tf)
31 | }
32 | return sTypefaceCache.get(font)
33 | ?: throw IllegalArgumentException(
34 | "Font error; typeface does not exist at assets/fonts$font.ttf"
35 | )
36 | }
37 | }
38 |
39 | fun getName(typeface: Typeface): String? =
40 | sTypefaceCache.entries.firstOrNull { it.value == typeface }?.key
41 | }
42 |
43 | fun Context.getFont(font: String) = FontUtils.get(this, font)
44 |
45 | fun Context.getFontName(typeface: Typeface) = FontUtils.getName(typeface)
46 |
--------------------------------------------------------------------------------
/about/src/main/kotlin/ca/allanwang/kau/about/CollapsibleTextView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.about
17 |
18 | import android.content.Context
19 | import android.content.res.Configuration
20 | import android.util.AttributeSet
21 | import androidx.appcompat.widget.AppCompatTextView
22 | import ca.allanwang.kau.ui.views.CollapsibleView
23 | import ca.allanwang.kau.ui.views.CollapsibleViewDelegate
24 |
25 | /** Created by Allan Wang on 2017-08-02. */
26 | class CollapsibleTextView
27 | @JvmOverloads
28 | constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
29 | AppCompatTextView(context, attrs, defStyleAttr), CollapsibleView by CollapsibleViewDelegate() {
30 |
31 | init {
32 | initCollapsible(this)
33 | }
34 |
35 | override fun onConfigurationChanged(newConfig: Configuration?) {
36 | resetCollapsibleAnimation()
37 | super.onConfigurationChanged(newConfig)
38 | }
39 |
40 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
41 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
42 | val result = getCollapsibleDimension()
43 | setMeasuredDimension(result.first, result.second)
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/core-ui/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/about/README.md:
--------------------------------------------------------------------------------
1 | # KAU :about
2 |
3 | Most apps could not be possible without the collective efforts of other developers and their libraries.
4 | It's always nice to give credit where credit is due, but it's not always at the top of ones agenda.
5 | About Activity aims to fix that by preparing a beautiful overlay activity that does just that.
6 |
7 | 
8 |
9 | The overlay is heavily based off of the about section in [Plaid](https://github.com/nickbutcher/plaid),
10 | and adds on the power of [About Libraries](https://github.com/mikepenz/AboutLibraries) to automatically find the dependencies.
11 |
12 | This activity can be easily added by extending `AboutActivityBase`.
13 | Everything is already prepared, but you can modify the theme or other components through the config DSL or through the open functions.
14 |
15 | If you wish to add custom panels, you will need to implement `AboutPanelContract`.
16 | The most common usage is with a recyclerview, so there is a simplified class `AboutPanelRecycler` that you may extend as well.
17 | Note that the viewpager by default will keep all panels in memory, so it's best to not have too many pages with expensive interactions.
18 |
19 | You may easily launch the activity through the binder:
20 | ```
21 | Activity.kauLaunchAbout()
22 | ```
23 | where `T` extends `AboutActivityBase`
24 |
25 | Be sure to include the activity in your Manifest and have it extend `Kau.About`, or any other style that achieves the same look.
26 |
27 | ## Proguard
28 |
29 | Without auto detection, KAU about will retain the classes containing the lib strings by default.
30 | If you use proguard with auto detect, make sure to retain all R classes to make it possible
31 |
32 | ```
33 | -keep class .R
34 | -keep class **.R$* {
35 | ;
36 | }
37 | ```
--------------------------------------------------------------------------------
/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kpref.activity.items
17 |
18 | import android.widget.CheckBox
19 | import androidx.appcompat.widget.AppCompatCheckBox
20 | import ca.allanwang.kau.kpref.activity.KClick
21 | import ca.allanwang.kau.kpref.activity.R
22 | import ca.allanwang.kau.utils.tint
23 |
24 | /**
25 | * Created by Allan Wang on 2017-06-07.
26 | *
27 | * Checkbox preference When clicked, will toggle the preference and the apply the result to the
28 | * checkbox
29 | */
30 | open class KPrefCheckbox(builder: BaseContract) : KPrefItemBase(builder) {
31 |
32 | override fun KClick.defaultOnClick() {
33 | pref = !pref
34 | (innerView as AppCompatCheckBox).isChecked = pref
35 | }
36 |
37 | override fun bindView(holder: ViewHolder, payloads: List) {
38 | super.bindView(holder, payloads)
39 | val checkbox = holder.bindInnerView(R.layout.kau_pref_checkbox)
40 | withAccentColor(checkbox::tint)
41 | checkbox.isChecked = pref
42 | checkbox.jumpDrawablesToCurrentState() // Cancel the animation
43 | }
44 |
45 | override val type: Int
46 | get() = R.id.kau_item_pref_checkbox
47 | }
48 |
--------------------------------------------------------------------------------
/core/src/main/res-public/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 24dp
6 | 16dp
7 |
8 | 16dp
9 | 8dp
10 | 16dp
11 | 1dip
12 | 100dp
13 |
14 | 112dp
15 | 168dp
16 |
17 | 8dp
18 | 4dp
19 | 32dp
20 | 48dp
21 | 64dp
22 | 8dp
23 | 16dp
24 | 24dp
25 | 56dp
26 | 28dp
27 | 112sp
28 |
29 |
30 | 40dp
31 | 48dp
32 | 4dp
33 | 12dp
34 | 20dp
35 |
36 |
--------------------------------------------------------------------------------
/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.xml
17 |
18 | import android.content.Context
19 | import androidx.test.core.app.ApplicationProvider
20 | import androidx.test.ext.junit.runners.AndroidJUnit4
21 | import androidx.test.filters.MediumTest
22 | import ca.allanwang.kau.test.R
23 | import kotlin.test.assertEquals
24 | import org.junit.Test
25 | import org.junit.runner.RunWith
26 |
27 | /** Created by Allan Wang on 2017-08-01. */
28 | @RunWith(AndroidJUnit4::class)
29 | @MediumTest
30 | class FaqTest {
31 |
32 | val context: Context
33 | get() = ApplicationProvider.getApplicationContext()
34 |
35 | @Test
36 | fun simpleTest() {
37 | val data = context.kauParseFaq(R.xml.test_faq, false)
38 | assertEquals(2, data.size, "FAQ size is incorrect")
39 | assertEquals(
40 | "This is a question",
41 | data.first().question.toString(),
42 | "First question does not match"
43 | )
44 | assertEquals("This is an answer", data.first().answer.toString(), "First answer does not match")
45 | assertEquals(
46 | "This is another question",
47 | data.last().question.toString(),
48 | "Second question does not match"
49 | )
50 | assertEquals(
51 | "This is another answer",
52 | data.last().answer.toString(),
53 | "Second answer does not match"
54 | )
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kotlin
17 |
18 | import kotlin.test.assertEquals
19 | import org.junit.Test
20 |
21 | /**
22 | * Created by Allan Wang on 2017-08-05.
23 | *
24 | * Test code for [kauRemoveIf]
25 | */
26 | class StreamsTest {
27 |
28 | @Test
29 | fun basic() {
30 | val items = mutableListOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
31 | items.kauRemoveIf { it % 2 == 0 }
32 | assertEquals(listOf(1, 3, 5, 7, 9), items)
33 | }
34 |
35 | @Test
36 | fun objectReference() {
37 | data class Potato(val id: Int)
38 |
39 | val thePotato = Potato(9)
40 | val items = mutableListOf()
41 | val result = mutableListOf()
42 | for (i in 0..11) {
43 | val potato = Potato(i)
44 | items.add(potato)
45 | result.add(potato)
46 | }
47 | items.add(3, thePotato)
48 | assertEquals(result.size + 1, items.size, "Invalid list addition")
49 | assertEquals(2, items.filter { it.id == 9 }.size, "Invalid number of potatoes with id 9")
50 | items.kauRemoveIf { it === thePotato } // removal by reference
51 | assertEquals(result.size, items.size, "Invalid list size after removal")
52 | assertEquals(result, items)
53 | items.kauRemoveIf { it == thePotato } // removal by equality
54 | assertEquals(result.size - 1, items.size, "Invalid list removal based on equality")
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kpref.activity.items
17 |
18 | import android.view.View
19 | import ca.allanwang.kau.kpref.activity.GlobalOptions
20 | import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder
21 | import ca.allanwang.kau.kpref.activity.R
22 |
23 | /**
24 | * Created by Allan Wang on 2017-06-14.
25 | *
26 | * Sub item preference When clicked, will navigate to a new set of preferences and add the old list
27 | * to a stack
28 | */
29 | open class KPrefSubItems(open val builder: KPrefSubItemsContract) : KPrefItemCore(builder) {
30 |
31 | override fun onClick(itemView: View) {
32 | builder.globalOptions.showNextPrefs(builder.titleFun(), builder.itemBuilder)
33 | }
34 |
35 | override val layoutRes: Int
36 | get() = R.layout.kau_pref_core
37 |
38 | /** Extension of the base contract with an optional text getter */
39 | interface KPrefSubItemsContract : CoreContract {
40 | val itemBuilder: KPrefAdapterBuilder.() -> Unit
41 | }
42 |
43 | /** Default implementation of [KPrefTextContract] */
44 | class KPrefSubItemsBuilder(
45 | globalOptions: GlobalOptions,
46 | titleId: Int,
47 | override val itemBuilder: KPrefAdapterBuilder.() -> Unit
48 | ) : KPrefSubItemsContract, CoreContract by CoreBuilder(globalOptions, titleId)
49 |
50 | override val type: Int
51 | get() = R.id.kau_item_pref_sub_item
52 | }
53 |
--------------------------------------------------------------------------------
/adapter/src/main/kotlin/ca/allanwang/kau/animators/AnimatorInterfaces.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.animators
17 |
18 | import android.view.View
19 | import android.view.ViewPropertyAnimator
20 | import androidx.recyclerview.widget.RecyclerView
21 |
22 | /** Created by Allan Wang on 2017-07-11. */
23 | class KauAnimatorException(message: String) : RuntimeException(message)
24 |
25 | interface KauAnimatorAdd {
26 | fun animationPrepare(holder: RecyclerView.ViewHolder): View.() -> Unit
27 | fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit
28 | fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit
29 | fun getDelay(remove: Long, move: Long, change: Long): Long
30 | var itemDelayFactor: Float
31 | }
32 |
33 | interface KauAnimatorRemove {
34 | fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit
35 | fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit
36 | fun getDelay(remove: Long, move: Long, change: Long): Long
37 | var itemDelayFactor: Float
38 | }
39 |
40 | interface KauAnimatorChange {
41 | fun changeOldAnimation(
42 | holder: RecyclerView.ViewHolder,
43 | changeInfo: BaseItemAnimator.ChangeInfo
44 | ): ViewPropertyAnimator.() -> Unit
45 |
46 | fun changeNewAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit
47 | fun changeAnimationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit
48 | }
49 |
--------------------------------------------------------------------------------
/sample/src/main/kotlin/ca/allanwang/kau/sample/MediaPicker.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.sample
17 |
18 | import android.content.Context
19 | import android.net.Uri
20 | import androidx.core.content.FileProvider
21 | import ca.allanwang.kau.mediapicker.MediaActionCamera
22 | import ca.allanwang.kau.mediapicker.MediaActionGallery
23 | import ca.allanwang.kau.mediapicker.MediaPickerActivityBase
24 | import ca.allanwang.kau.mediapicker.MediaPickerActivityOverlayBase
25 | import ca.allanwang.kau.mediapicker.MediaType
26 | import ca.allanwang.kau.mediapicker.createMediaFile
27 | import java.io.File
28 |
29 | /** Created by Allan Wang on 2017-07-23. */
30 | private fun actions(multiple: Boolean) =
31 | listOf(
32 | object : MediaActionCamera() {
33 |
34 | override fun createFile(context: Context): File = createMediaFile("KAU", ".jpg")
35 |
36 | override fun createUri(context: Context, file: File): Uri =
37 | FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file)
38 | },
39 | MediaActionGallery(multiple)
40 | )
41 |
42 | class ImagePickerActivity : MediaPickerActivityBase(MediaType.IMAGE, actions(true))
43 |
44 | class ImagePickerActivityOverlay : MediaPickerActivityOverlayBase(MediaType.IMAGE, actions(false))
45 |
46 | class VideoPickerActivity : MediaPickerActivityBase(MediaType.VIDEO, actions(true))
47 |
48 | class VideoPickerActivityOverlay : MediaPickerActivityOverlayBase(MediaType.VIDEO, actions(false))
49 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings_sample.xml:
--------------------------------------------------------------------------------
1 |
2 | This is a header
3 | This is a description
4 | Checkbox 1
5 | Checkbox 2
6 | Checkbox 3
7 | I am dependent on checkbox 2
8 | Text Color
9 | Accent Color
10 | Background Color
11 | This selector allows custom colors
12 | This selector does not allow custom colors
13 | This selector allows for custom colors with alpha values
14 | Text Pref
15 | Saves the text
16 | Seekbar
17 | Time Pref
18 | AM PM version
19 | 24h version
20 | Sub Item Pref
21 | Press this to view the next subset of preferences
22 | your.email@here.com
23 | Your subject
24 | Swipe Showcase
25 | Image Showcase
26 | Video Overlay Showcase
27 | Adapter Showcase
28 | KAU (Kotlin Android Utils) is a collection of common extension functions and complex UIs that can be used in almost all apps. It is meant to implement the shared components, so you can focus on what makes your app unique.
29 | Long Prefs
30 |
31 |
--------------------------------------------------------------------------------
/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.about
17 |
18 | import android.view.View
19 | import androidx.recyclerview.widget.RecyclerView
20 | import ca.allanwang.kau.adapters.ThemableIItem
21 | import ca.allanwang.kau.adapters.ThemableIItemDelegate
22 | import ca.allanwang.kau.iitems.KauIItem
23 | import ca.allanwang.kau.ui.views.CutoutView
24 |
25 | /**
26 | * Created by Allan Wang on 2017-06-28.
27 | *
28 | * Just a cutout item with some defaults in [R.layout.kau_iitem_cutout]
29 | */
30 | class CutoutIItem(val config: CutoutView.() -> Unit = {}) :
31 | KauIItem(R.layout.kau_iitem_cutout, ::ViewHolder, R.id.kau_item_cutout),
32 | ThemableIItem by ThemableIItemDelegate() {
33 |
34 | override var isSelectable: Boolean
35 | get() = false
36 | set(_) {}
37 |
38 | override fun bindView(holder: ViewHolder, payloads: List) {
39 | super.bindView(holder, payloads)
40 | with(holder) {
41 | if (accentColor != null && themeEnabled) cutout.foregroundColor = accentColor!!
42 | cutout.config()
43 | }
44 | }
45 |
46 | override fun unbindView(holder: ViewHolder) {
47 | super.unbindView(holder)
48 | with(holder) {
49 | cutout.drawable = null
50 | cutout.text = "Text" // back to default
51 | }
52 | }
53 |
54 | class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
55 | val cutout: CutoutView = v.findViewById(R.id.kau_cutout)
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/kpref-activity/src/main/res/layout/kau_pref_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
17 |
25 |
26 |
34 |
35 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Allan Wang
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 | package ca.allanwang.kau.kotlin
17 |
18 | import kotlin.test.assertEquals
19 | import org.junit.Ignore
20 | import org.junit.Test
21 |
22 | /** Created by Allan Wang on 2017-08-05. */
23 | class DebounceTest {
24 |
25 | @Test
26 | fun basic() {
27 | var i = 0
28 | val debounce = debounce(20) { i++ }
29 | assertEquals(0, i, "i should start as 0")
30 | (1..5).forEach { debounce() }
31 | Thread.sleep(50)
32 | assertEquals(1, i, "Debouncing did not cancel previous requests")
33 | }
34 |
35 | @Test
36 | fun basicExtension() {
37 | var i = 0
38 | val increment: () -> Unit = { i++ }
39 | (1..5).forEach { increment() }
40 | assertEquals(5, i, "i should be 5")
41 | val debounce = increment.debounce(50)
42 | (6..10).forEach { debounce() }
43 | assertEquals(5, i, "i should not have changed")
44 | Thread.sleep(100)
45 | assertEquals(6, i, "i should increment to 6")
46 | }
47 |
48 | @Test
49 | @Ignore("Pending fix")
50 | fun multipleDebounces() {
51 | var i = 0
52 | val debounce = debounce(20) { i += it }
53 | debounce(1) // ignore -> i = 0
54 | Thread.sleep(10)
55 | assertEquals(0, i)
56 | debounce(2) // accept -> i = 2
57 | Thread.sleep(30)
58 | assertEquals(2, i)
59 | debounce(4) // ignore -> i = 2
60 | Thread.sleep(10)
61 | assertEquals(2, i)
62 | debounce(8) // accept -> i = 10
63 | Thread.sleep(30)
64 | assertEquals(10, i)
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/core/src/test/kotlin/ca/allanwang/kau/kotlin/CoroutineTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Allan Wang
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 | package ca.allanwang.kau.kotlin
17 |
18 | import kotlin.test.assertEquals
19 | import kotlin.test.fail
20 | import kotlinx.coroutines.CancellationException
21 | import kotlinx.coroutines.Dispatchers
22 | import kotlinx.coroutines.Job
23 | import kotlinx.coroutines.runBlocking
24 | import kotlinx.coroutines.withContext
25 | import org.junit.Test
26 |
27 | /** Tests geared towards coroutines */
28 | class CoroutineTest {
29 |
30 | /** If a job is cancelled, then a switch to a new context will not run */
31 | @Test
32 | fun implicitCancellationBefore() {
33 | val job = Job()
34 | var id = 0
35 | try {
36 | runBlocking(job) {
37 | id++
38 | job.cancel()
39 | withContext(Dispatchers.IO) { fail("Context switch should not be reached") }
40 | }
41 | } catch (ignore: CancellationException) {} finally {
42 | assertEquals(1, id, "Launcher never executed")
43 | }
44 | }
45 |
46 | /** If a job is cancelled, then a switch from a new context will not run */
47 | @Test
48 | fun implicitCancellationAfter() {
49 | val job = Job()
50 | var id = 0
51 | try {
52 | runBlocking(job) {
53 | withContext(Dispatchers.IO) {
54 | id++
55 | job.cancel()
56 | }
57 | fail("Post context switch should not be reached")
58 | }
59 | } catch (ignore: CancellationException) {} finally {
60 | assertEquals(1, id, "Context switch never executed")
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------