Custom MediaPicker for Android. support targetSdk 30 & scoped storage. And use registerForActivityResult rather than onActivityResult.

Overview

MoongchiPicker

Google
License API Version

What is MoongchiPicker?

MoongchiPicker is custom media gallery base on Google's Material Design Bottom Sheets. You can fetch image or video easily from camera app or gallery app or just MoongchiPicker. Also you can request permission for fetching media from storage easily. Just give allowPermissionRequest option when use MoongchiPicker. MoongchiPicker support targetSdk 30 & scoped storage. And use registerForActivityResult rather than onActivityResult. MoongchiPicker depends on only one third party library Ucrop.

Setup

Gradle

To get a project into your build:

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Or in setting gradle

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
	    ...
        maven { url "https://jitpack.io" }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.teampetfriends.moongchi-picker:final:1.0.2'
}

Step 3. Enable databinding

Add it in your module.gradle:

plugins {
    ...
    id 'kotlin-kapt'
}

android {
    dataBinding {
        enabled = true
    }
}

Setp 4. Set compileSdkVersion 31

In your module.gradle:

android {
    ...
     compileSdkVersion 31
}

If you're facing :app:checkDebugDuplicateClasses error during build, it's mean latest version not currently available. You should wait about 2~3 hours since latest version released

Demo

  1. Show picker
  2. Request Camera
  3. Request Gallery
  4. Submit media

alt alt
alt alt

MoongchiPicker supports english and korean

How to use

MoongchiPicker must be created on onCreate of activity lifecycle. Because it uses context to load file from storage, and use registerForActivityResult which is must be called before onStart MoongchiPicker can be created in Activity and Fragment.

Due to MoongchiPicker use registerForActivityResult, you have to pass ComponentActivity as argument. And pass fragmentManager as argument for showing MoongchiPickerDialog. And let MoongchiPicker know what media type you want to pick. You don't need to check permission if you give allowPermissionRequest option true to MoongchiPicker. And pass MoongchiPickerListener as argument. That's it.

val moongchiPicker = MoongchiPicker(
    activity = this,
    fragmentManager = supportFragmentManager,
    allowPermissionRequest = true,
    moongchiPickerListener = object : MoongchiPickerListener{
        override fun onSubmitMedia(contentUris: List<Uri>) {
            //Do something you want
        }

        override fun onFailed(t: Throwable) {
            //Do something you want
        }

        //this implementation is optional
        override fun onSelectedMediaCountOverLimit(limit: Int) {
            //Do something you want. For example, show warning dialog
        }

    }
)

binding.iv.setOnClickListener {
    moongchiPicker.show()
}

Or you can use convenient extension method

val moongchiPicker = createMoongchiPicker(
    mediaType = PetMediaType.IMAGE,
    allowPermissionRequest = true,
    moongchiPickerListener = object : MoongchiPickerListener {
        override fun onSubmitMedia(contentUris: List<Uri>) {
            //Do something you want
        }

        override fun onFailed(t: Throwable) {
            //Do something you want
        }

        override fun onSelectedMediaCountOverLimit(limit: Int) {
            //Do something you want. For example, show warning dialog
        }

    })

binding.iv.setOnClickListener {
    moongchiPicker.show()
}

If you want to make users to pick multiple media,

val moongchiPicker = createMoongchiPicker(
    mediaType = PetMediaType.IMAGE,
    allowPermissionRequest = true,
    allowMultiple = true,
    maxMediaCountBuilder = { 5 },
    moongchiPickerListener = object : MoongchiPickerListener {
        override fun onSubmitMedia(contentUris: List<Uri>) {
            //Do something you want
        }

        override fun onFailed(t: Throwable) {
            //Do something you want
        }

        override fun onSelectedMediaCountOverLimit(limit: Int) {
            //Do something you want. For example, show warning dialog
        }

    })

binding.iv.setOnClickListener {
    moongchiPicker.show()
}

If you want to control max visible media items on MoogchiPickerDialog, pass maxVisibleMediaCount to MoongchiPicker or createMoongchiPicker

Contributors

  1. Tim (Android Developer)
  1. Zeeto (Android Developer)

License

This library is licensed under the MIT License:

Copyright (c) 2021 Petfriends

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
You might also like...
Social media app but with new features like translate messages and posts , support video & images as posts  , chat and  notifications , etc...
Social media app but with new features like translate messages and posts , support video & images as posts , chat and notifications , etc...

social-media-app Social media app but with new features like translate messages and posts , support video & images as posts , chat and notifications ,

Let Me Downgrade - Add support for downgrading apps on Android 12 and 13.
Let Me Downgrade - Add support for downgrading apps on Android 12 and 13.

Let Me Downgrade Android's app installation system does not allow users to downgrade to an older version of an app when they already have a newer vers

A handy phone call manager with phonebook, number blocking and multi-SIM support
A handy phone call manager with phonebook, number blocking and multi-SIM support

Simple Dialer A lightweight app for handling your calls, no matter where are you. Comes with a handy call log for easy call initiation. There is a qui

React Native Stone SDK Implementation (Support for both Mobile and POS versions)

react-native-stone-pos Stone Android POS Native Module Installation Stone has a private packageCloud repository, so we need to have your token before

:movie_camera: Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.
:movie_camera: Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.

Popular Movies Stage 1 + Stage 2 Discover the most popular and top rated movies playing. Movies data fetched using themoviedb.org API. ✨ Screenshots M

Sample Project for Android Support Library 23.2
Sample Project for Android Support Library 23.2

SnapShot: Contains features Vector Drawable Animated Vector Drawable AppCompat DayNight theme Bottom Sheets Using BottomSheetDialog in day-night mode.

A demo for Android font typeface support in React Native!
A demo for Android font typeface support in React Native!

A Step-by-step Guide to a Consistent Multi-Platform Font Typeface Experience in React Native Goal Be able to use font typeface modifiers such as fontW

Cql-cds-hooks - HL7 CDS HOOKS Implementation with CQL support

CQL CDS HOOKS HL7 CDS HOOKS implementation with CQL (Clinical Quality Language)

Xposed-based motion simulator with sensor support.

This project is under active development MotionEmulator Android motion simulator with sensor support. Scenarios If you study in universities in China,

Releases(1.1.7)
Owner
펫프렌즈
펫프렌즈
The app has got fullscreen Turkey map via Huawei Map. App selects random province and shows it borders on the map than user will try to guess the provinces name.

Il Bil App Introduction I will introduce you to how to implement Account Kit, Map Kit, Game Service. About the game: The app has got fullscreen Turkey

Gökhan YILMAZ 4 Aug 2, 2022
A blogging mobile application built with Kotlin using MVC design pattern and Take some advantage of Jetpack , View & Data Binding It's a mimic for Tumblr application , But a little prettier than him 😉

A blogging mobile application built with Kotlin using MVC design pattern and Take some advantage of Jetpack , View & Data Binding It's a mimic for Tum

Ahmed Ihab 17 Dec 23, 2022
An app for developers which contains more than 2.4k+ resources , with 1.2k+ free public API documentation

ResourceUp We often spend a lot of time finding good resources to get started with our project right? ResourceUp aims to provide all useful resources

kalp patel 10 Apr 30, 2022
✨ Social network app made with Android Compose, full Kotlin, Firebase Authentication, Storage and Firestore 🚀

Your friends, for real. Share daily random moments with your friends and discover who they really are. ✨ Instant Instant is a social media actually un

Vincent Guillebaud 58 Dec 23, 2022
Android cutout screen support Android P. Android O support huawei, xiaomi, oppo and vivo.

CutoutScreenSupport Android cutout screen support Android P. Android O support huawei, xiaomi, oppo and vivo. Usage whether the mobile phone is cutout

hacket 5 Nov 3, 2022
MEGA Android Client - A fully-featured client to access your Cloud Storage provided by MEGA

A fully-featured client to access your Cloud Storage provided by MEGA. This document will guide you to build the application on a Linux machine with Android Studio.

Mega Limited 1.1k Jan 3, 2023
Sync floder from drive to local storage

GDrive #refrence and steps to upload - https://developers.google.com/drive/api/v3/manage-uploads to download - https://developers.goo

Karn_Rahul 0 Nov 4, 2021
Media Provider Manager - An Xposed module intended to prevent media storage abuse

Media Provider Manager - An Xposed module intended to prevent media storage abuse

null 104 Dec 26, 2022
A collection of custom Android/Kotlin lint checks we use in our Android and Kotlin code bases at Slack.

slack-lints This repository contains a collection of custom Android/Kotlin lint checks we use in our Android and Kotlin code bases at Slack. This repo

Slack 119 Dec 20, 2022
Mole Analysis Use Case for HMS ML Kit Custom Model

Mole Analysis Mole Analysis Use Case for HMS ML Kit Custom Model Introduction What is Melanoma? Melanoma is the most serious among skin cancers becaus

null 15 Aug 23, 2022