Git Product home page Git Product logo

cwksclibandroid's Introduction

CwkscLibAndroid

PermissionRequestUtil

// For request permission one time only.
fun request(
    activity: ActivityResultCaller,
    permission: String,
    callback: (name: String, result: Boolean) -> Unit = { _, _ -> },
)

// For request permission multiple time.
fun request(
    activity: ActivityResultCaller,
    vararg permissions: String,
    callback: (map: Map<String, Boolean>) -> Unit = { },
)

Example:

PermissionRequestUtil.request(this, Manifest.permission.CAMERA)

PermissionRequestUtil.request(this,
    Manifest.permission.CAMERA,
    Manifest.permission.RECORD_AUDIO,
    Manifest.permission.READ_EXTERNAL_STORAGE,
    Manifest.permission.WRITE_EXTERNAL_STORAGE
)

SimpleRecyclerViewAdapter

Use with RecyclerView

data class SimpleRecyclerViewAdapter<CustomDataBinding : ViewDataBinding, ItemModel>(
    private val layoutId: Int,
    val onBindView: OnBindViewScope<CustomDataBinding, ItemModel>.() -> CustomDataBinding.() -> Unit = { { } },
)

activity_simple_recycler_view_adapter_demo.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".SimpleRecyclerViewAdapterDemoActivity">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</layout>

activity_simple_recycler_view_adapter_demo_item.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

    </data>

    <com.google.android.material.chip.Chip
        android:id="@+id/chip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</layout>

Example:

val adapter = SimpleRecyclerViewAdapter</*CustomBinding*/, /*ItemModel*/>(/*layoutId*/) {{
    // On binding view
}}
adapter.items = /* data */
rv.adapter = adapter
rv.layoutManager = /* LayoutManager */
val adapter = SimpleRecyclerViewAdapter<
    ActivitySimpleRecyclerViewAdapterDemoItemBinding, 
    String
>(R.layout.activity_simple_recycler_view_adapter_demo_item) {{
    chip.text = itemModel
}}
adapter.items = mutableListOf("Hello World", "meow")
rv.adapter = adapter
rv.layoutManager = LinearLayoutManager(this@SimpleRecyclerViewAdapterDemoActivity)

cwksclibandroid's People

Contributors

cwksc avatar

Stargazers

 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.