Skip to content

Commit

Permalink
Added Bottom Sheet Configuration Creation Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur3486 committed Mar 12, 2019
1 parent 7098877 commit a0233cd
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 16 deletions.
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":9,"versionName":"1.0.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":10,"versionName":"1.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
8 changes: 4 additions & 4 deletions app/src/main/java/com/arthurivanets/demo/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.arthurivanets.bottomsheets.BaseBottomSheet
import com.arthurivanets.bottomsheets.BottomSheet
import com.arthurivanets.bottomsheets.ktx.actionPickerConfig
import com.arthurivanets.bottomsheets.ktx.showActionPickerBottomSheet
import com.arthurivanets.bottomsheets.ktx.showCustomActionPickerBottomSheet
import com.arthurivanets.bottomsheets.sheets.config.Config
import com.arthurivanets.bottomsheets.sheets.listeners.OnItemSelectedListener
import com.arthurivanets.demo.R
import com.arthurivanets.demo.adapters.persons.PersonItem
Expand Down Expand Up @@ -77,9 +77,9 @@ class MainActivity : AppCompatActivity() {

bottomSheet = showActionPickerBottomSheet(
options = ConfirmationActionsProvider.getGeneralDeletionConfirmationActionOptions(this),
config = Config.Builder(this)
.title(getString(R.string.confirmation_title_item_deletion))
.build(),
config = actionPickerConfig {
title(getString(R.string.confirmation_title_item_deletion))
},
onItemSelectedListener = OnItemSelectedListener {
shortToast(it.title.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public final boolean isDismissableOnTouchOutside() {



public static final class Builder implements BaseConfigBuilder<Builder, Config> {
public static final class Builder implements BaseConfigBuilder<Builder, BaseConfig> {

private float dimAmount;
private float sheetCornerRadius;
Expand Down Expand Up @@ -238,7 +238,7 @@ public final Builder dismissOnTouchOutside(boolean dismissOnTouchOutside) {

@NonNull
@Override
public final Config build() {
public final BaseConfig build() {
return new Config(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.arthurivanets.bottomsheets.sheets.CustomActionPickerBottomSheet
import com.arthurivanets.bottomsheets.sheets.adapters.actionpicker.ActionItem
import com.arthurivanets.bottomsheets.sheets.adapters.actionpicker.BaseActionItem
import com.arthurivanets.bottomsheets.sheets.config.ActionPickerConfig
import com.arthurivanets.bottomsheets.sheets.config.Config
import com.arthurivanets.bottomsheets.sheets.listeners.OnItemSelectedListener
import com.arthurivanets.bottomsheets.sheets.model.Option

Expand All @@ -42,7 +41,7 @@ fun Fragment.showActionPickerBottomSheet(options : List<Option>,

return showActionPickerBottomSheet(
options = options,
config = Config.Builder(this.activity!!).build(),
config = actionPickerConfig(),
onItemSelectedListener = onItemSelectedListener
)
}
Expand Down Expand Up @@ -77,7 +76,7 @@ fun Fragment.showActionPickerBottomSheet(options : List<Option>,
*/
@JvmOverloads
fun Activity.showActionPickerBottomSheet(options : List<Option>,
config : ActionPickerConfig = Config.Builder(this).build(),
config : ActionPickerConfig = actionPickerConfig(),
onItemSelectedListener : OnItemSelectedListener<Option>) : ActionPickerBottomSheet {
return ActionPickerBottomSheet.init(
this,
Expand All @@ -103,7 +102,7 @@ fun <T : BaseActionItem<*, *, *>> Fragment.showCustomActionPickerBottomSheet(ite

return showCustomActionPickerBottomSheet(
items = items,
config = Config.Builder(this.activity!!).build(),
config = actionPickerConfig(),
onItemSelectedListener = onItemSelectedListener
)
}
Expand Down Expand Up @@ -140,7 +139,7 @@ fun <T : BaseActionItem<*, *, *>> Fragment.showCustomActionPickerBottomSheet(ite
*/
@JvmOverloads
fun <T : BaseActionItem<*, *, *>> Activity.showCustomActionPickerBottomSheet(items : List<T>,
config : ActionPickerConfig = Config.Builder(this).build(),
config : ActionPickerConfig = actionPickerConfig(),
onItemSelectedListener : OnItemSelectedListener<T>) : CustomActionPickerBottomSheet<T> {
return CustomActionPickerBottomSheet.init(
this,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2019 Arthur Ivanets, [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:JvmName("ConfigUtils")

package com.arthurivanets.bottomsheets.ktx

import android.content.Context
import androidx.fragment.app.Fragment
import com.arthurivanets.bottomsheets.config.BaseConfig
import com.arthurivanets.bottomsheets.config.BaseConfigBuilder
import com.arthurivanets.bottomsheets.sheets.config.ActionPickerConfig
import com.arthurivanets.bottomsheets.sheets.config.ActionPickerConfigBuilder
import com.arthurivanets.bottomsheets.sheets.config.Config


/**
* Used to build a configuration for the [com.arthurivanets.bottomsheets.BaseBottomSheet].
*
* @param builder configuration builder
*/
inline fun Fragment.baseConfig(crossinline builder : BaseConfigBuilder<out BaseConfigBuilder<*, *>, BaseConfig>.() -> Unit = {}) : BaseConfig {
assertAttachedToContext()
return context!!.baseConfig(builder)
}


/**
* Used to build a configuration for the [com.arthurivanets.bottomsheets.BaseBottomSheet].
*
* @param builder configuration builder
*/
inline fun Context.baseConfig(crossinline builder : BaseConfigBuilder<out BaseConfigBuilder<*, *>, BaseConfig>.() -> Unit = {}) : BaseConfig {
return com.arthurivanets.bottomsheets.config.Config.Builder(this)
.also { builder(it) }
.build()
}


/**
* Used to build a configuration for the Action Picker Bottom Sheet.
*
* @param builder configuration builder
*/
inline fun Fragment.actionPickerConfig(crossinline builder : ActionPickerConfigBuilder<out ActionPickerConfigBuilder<*, *>, ActionPickerConfig>.() -> Unit = {}) : ActionPickerConfig {
assertAttachedToContext()
return context!!.actionPickerConfig(builder)
}


/**
* Used to build a configuration for the Action Picker Bottom Sheet.
*
* @param builder configuration builder
*/
inline fun Context.actionPickerConfig(crossinline builder : ActionPickerConfigBuilder<out ActionPickerConfigBuilder<*, *>, ActionPickerConfig>.() -> Unit = {}) : ActionPickerConfig {
return Config.Builder(this)
.also { builder(it) }
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public final boolean isDismissableOnTouchOutside() {



public static final class Builder implements ActionPickerConfigBuilder<Builder, Config> {
public static final class Builder implements ActionPickerConfigBuilder<Builder, ActionPickerConfig> {

private float dimAmount;
private float sheetCornerRadius;
Expand Down Expand Up @@ -299,7 +299,7 @@ public final Builder dismissOnTouchOutside(boolean dismissOnTouchOutside) {

@NonNull
@Override
public final Config build() {
public final ActionPickerConfig build() {
return new Config(this);
}

Expand Down
4 changes: 2 additions & 2 deletions common/constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ project.ext {
releaseRepoName = "maven"
releaseUserOrg = "arthurlabs"
releaseGroupId = "com.arthurivanets.bottomsheet"
releaseVersion = "1.0.1"
releaseVersionCode = 10
releaseVersion = "1.0.2"
releaseVersionCode = 11
releaseWebsite = "https://github.com/arthur3486/bottomsheet"
releaseLicense = ["Apache-2.0"]

Expand Down

0 comments on commit a0233cd

Please sign in to comment.