Code Monkey home page Code Monkey logo

recyclerpickerdialog's Introduction

RecyclerPickerDialog

Android Arsenal

A FragmentDialog implemented with RecyclerView that can accept Single or Multiple selections

Installation

RecyclerPickerDialog is distributed through Maven Central and Jitpack.

implementation 'com.github.guilhe:recycler-picker-dialog:${LATEST_VERSION}'

Maven Central

Usage

Selection types

enum class SelectionType { SINGLE, MULTIPLE }

Selector types

enum class SelectorType { CHECK_BOX, RADIO_BUTTON, SWITCH }

Custom fields (and default values)

var title = ""
var showSearchBar = false
var inputHint = ""
var buttonText: String = "Ok"
var resetValuesOnShow = true
var dismissKeyboardOnSelection = true
var dismissOnSelection = false
var isChoiceMandatory = false
var data: ArrayList<Item> = arrayListOf()
@AnimRes var itemsLayoutAnimator: Int? = null
var dialogHeight: Int = ViewGroup.LayoutParams.MATCH_PARENT
var lifecycleOwner: LifecycleOwner? = null

Avoid Memory Leaks

Just add the following line to avoid memory leak if not dismissed before activity or fragment are destroyed:

picker.newInstance(/* setup... */).apply { lifecycleOwner = this@MainActivity }

Themes

Sample A Sample B Sample C Sample D

To override default theme just create yours by simply extending it and replacing desired color values:

<style name="DialogA" parent="RecyclerPickerDialogTheme">
    <item name="colorPrimary">@color/red</item>
    <item name="recyclerPickerDialogCornerRadius">20dp</item>
</style>

Attributes

You can override the following attributes:

<resources>
    <style name="RecyclerPickerDialogTheme" parent="Theme.MaterialComponents.Light.Dialog">
        <item name="colorPrimary"/>
        <item name="colorOnPrimary"/>
        <item name="colorSecondary"/>
     
        <item name="android:textColorPrimary"/>
        <item name="android:textColorSecondary"/>

        <item name="colorAccent"/>
        <item name="android:colorEdgeEffect"/>
        <item name="recyclerPickerDialogCornerRadius"/>
    </style>
</resources>

Where:

  • colorPrimary > Title and Button background color
  • colorOnPrimary > Title and Button text color
  • colorSecondary > Dialog and Row background color
  • colorEdgeEffect > RecyclerView edge color
  • textColorPrimary > Search and Row text color
  • textColorSecondary > Search hint and icon color; Horizontal Lines color
  • colorSurface > CheckBox, RadioButton and Switch unchecked color
  • colorOnSurface > Button background when disabled (note overrides colorSurface)
  • colorAccent > CheckBox, RadioButton and Switch checked color; Hint cursor color
  • recyclerPickerDialogCornerRadius > Dialog corners radius

Creating new instance:

val picker = 
    RecyclerPickerDialogFragment
        .newInstance(
            type = SelectionType.SINGLE, //default
            selector = SelectorType.CHECK_BOX, //default
            theme = R.style.RecyclerPickerDialogTheme, //default
            onItemsPicked = { selected -> /* selected items or empty */ }
        )
        .apply {
            /* configure custom fields */ 
        }

Show it when desired:

picker.show(supportFragmentManager, "MyPickerDialogFragment")

Try out the sample app to see it working!

Dependencies

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

LICENSE

Copyright (c) 2020-present GuilhE

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.

recyclerpickerdialog's People

Contributors

guilhe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.