• Stars
    star
    1,199
  • Rank 39,044 (Top 0.8 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🚀RxJava2 and RxJava3 external support. Android flexible picture selector, provides the support for theme of Zhihu and WeChat (灵活的Android图片选择器,提供了知乎和微信主题的支持).

RxImagePicker

English Documentation | 中文文档

(RxJava3) (RxJava2)

Support for RxJava2. Flexible picture selector of Android, provides the support for theme of Zhihu and WeChat.

Zhihu: Famous Online Q&A Community APP in China.
WeChat: Most Used Instant Messaging Social Networking App in China.

Introduction

Purpose of RxImagePicker: Let developers realize the demand of selecting picture in the development of Android in a simple and flexible way.

RxImagePicker is a reactive picture selector for Android, which converts your selection requirements of picture into an interface for configuration and displays any UI theme in Activity or Fragment.

Support

  • Android Camera Photograph
  • Android photo album picture selection
  • Returns data in the format of reactive data stream ( such as Observable/Flowable/Single/Maybe )
  • AndroidX support ( after v2.3.0 )

Support of UI

  • System Picture Selector
  • [Optional] Theme Picture Selector of Zhihu
  • [Optional] Theme Picture Selector of WeChat ()
  • [Optional] Custom UI Picture Selector

Screenshots

Selection and result display of system picture:

Theme of Zhihu

Theme of WeChat

UI Test

Basic Usage

The following code will show you how to use photo album or camera at the Android system-level :

1.Add the following depending on the file of build.gradle:

// The most basic architecture, only provides the default
// picture selector and photographing function of system.

implementation 'com.github.qingmei2:rximagepicker:${last_version}'

// Provide the basic components of custom UI picture selector
// and this dependency needs to be added to the requirements of the custom UI
implementation 'com.github.qingmei2:rximagepicker_support:${last_version}'


// If you need additional UI support, choose to rely on the corresponding UI extension library

// Zhihu picture selector
implementation 'com.github.qingmei2:rximagepicker_support_zhihu:${last_version}'

// WeChat picture selector
implementation 'com.github.qingmei2:rximagepicker_support_wechat:${last_version}'

If your project not migrate to androidx, please use version 2.2.0.

2.Interface Configuration

Declare an interface and carry out the following configuration:

public interface MyImagePicker {

    @Gallery    // open gallery
    Observable<Result> openGallery(Context context);

    @Camera     // take photos
    Observable<Result> openCamera(Context context);
}

3.Instantiate and use it

Instantiate the interface in your Activity or Fragment to open the default album and camera screen of system:

RxImagePicker
        .create(MyImagePicker.class)
        .openGallery(this)
        .subscribe(new Consumer<Result>() {
            @Override
            public void accept(Result result) throws Exception {
                // do something, ex:
                Uri uri = result.getUri();
                GlideApp.with(this)
                         .load(uri)
                         .into(ivPickedImage);
            }
        });

Support UI theme Usage

1.Add the following depending on the file of build.gradle:

// Zhihu picture selector
implementation 'com.github.qingmei2:rximagepicker_support_zhihu:${last_version}'

2.Interface Configuration

Declare an interface and carry out the following configuration:

interface ZhihuImagePicker {

    // normal style
    @Gallery(componentClazz = ZhihuImagePickerActivity::class,
            openAsFragment = false)
    fun openGalleryAsNormal(context: Context,
                            config: ICustomPickerConfiguration): Observable<Result>

    // dracula style                        
    @Gallery(componentClazz = ZhihuImagePickerActivity::class,
            openAsFragment = false)
    fun openGalleryAsDracula(context: Context,
                             config: ICustomPickerConfiguration): Observable<Result>

    // take photo                         
    @Camera
    fun openCamera(context: Context): Observable<Result>
}

3.Instantiate and use it

val rxImagePicker: ZhihuImagePicker = RxImagePicker
                .create(ZhihuImagePicker::class.java)

rxImagePicker.openGalleryAsNormal(this,
                ZhihuConfigurationBuilder(MimeType.ofImage(), false)
                        .maxSelectable(9)
                        .countable(true)
                        .spanCount(4)
                        .theme(R.style.Zhihu_Normal)
                        .build())
               .subscribe {
                    Glide.with(this@ZhihuActivity)
                            .load(it.uri)
                            .into(imageView)
                }

see sample for more informations.

Advanced Usage

1. Action Annotation

RxImagePicker provides two action annovation, respectively @Gallery and @Camera.

@Camera will declare the way annovated by the annovation Open the camera to take a photo.

Please note, each method of the interface must add an action annotation to declare the corresponding action. If the method is not configured with @Gallery or @Camera, RxImagePicker will throw an Exception at runtime.

@Gallery

@Gallery will open the photo album to choose picture.

It has three parameters:

  • componentClazz:KClass<*> The class object of UI component, opens SystemGalleryPickerView::class—— the system Gallery by default.

  • openAsFragment:Boolean Whether UI component is displayed as Fragment in some parts of Activity is true by default.

  • containerViewId: Int If UI needs to be displayed as Fragment in ViewGroup, the id corresponding to the ViewGroup needs to be assigned to it.

At present UI component only supports two kinds: FragmentActivity or Fragment(support-v4).

Taking turning on the system camera for example, its principle is to instantiate an invisible Fragment in the current Activity, and Fragment opens the system photo album through Intent and processes the returned data through the method of onActivityResult(). The code is as the following:

interface SystemImagePicker {

    @Gallery   // by default,componentClazz:KClass = SystemGalleryPickerView::class,openAsFragment:Boolean=true
    fun openGallery(context: Context): Observable<Result>
}

When need to custom UI, taking Zhihu theme as an example, we will configure ZhihuImagePickerActivity::class to componentClazz and set the value of openAsFragment to false:

interface ZhihuImagePicker {

    @Gallery(componentClazz = ZhihuImagePickerActivity::class,
            openAsFragment = false)
    fun openGalleryAsNormal(context: Context,
                            config: ICustomPickerConfiguration): Observable<Result>

    @Gallery(componentClazz = ZhihuImagePickerActivity::class,
            openAsFragment = false)
    fun openGalleryAsDracula(context: Context,
                             config: ICustomPickerConfiguration): Observable<Result>

    @Camera
    fun openCamera(context: Context): Observable<Result>
}

For more information, please refer to the ZhihuActivity in sample.

At the same time, when UI needs to be displayed as Fragment, RxImagePicker needs to be informed of the id of the ViewGroup control so that RxImagePicker can be correctly displayed in the corresponding ViewGroup.

@Camera

@Camera will declare the way annotated by the annotation open the camera to take photo.

Please note, @Camera only provides the function of calling the system camera to take a photo at present. Although this annotation provides the same API as @Gallery, there is no sense to configure them at present.

2.ICustomPickerView

ICustomPickerView is an underneath interface, it is used for:

    1. Show the picture selector interface
    1. Obtain selection results of users
interface ICustomPickerView {

    fun display(fragmentActivity: FragmentActivity,
                @IdRes viewContainer: Int,
                configuration: ICustomPickerConfiguration?)

    fun pickImage(): Observable<Result>
}

It has several classic implementation classes, for example, ImagePickerDisplayer when open the corresponding activity through configuration;

3.Context: necessary parameters.

Each interface method of RxImagePicker must be configured with a Context as parameters. If the method does not have any parameters, it will throw out NullPointerException:

${method.name} requires just one instance of type: Context, but none.

This is understandable. Starting the UI component of a picture selector must depend on the instance of Context.

Note, This Context must be a FragmentActivity, not Application or others, or else throw out the abnormity of IllegalArgumentException!

4.ICustomPickerConfiguration: optional parameters

ICustomPickerConfiguration interface, similar to a tag. RxImagePicker will treat it as the configuration class.

As for opening the system photo album or system camera, it makes no sense to configure, but it must be configured for custom UI ( such as WeChat theme and Zhihu theme ).

The basic components of RxImagePicker do not provide the implementation class, please refer to SelectionSpec if any questions.

2.5 Complete full custom UI

Though RxImagePicker provides the UI style of WeChat picture selector and Zhihu picture selector, two sets of models are still not enough to cover more and more sophisticated UI demands of APP.

RxImagePicker provides enough degree of freedom interface to provide private customized UI for developers. Whether a new Activity is created or displayed in a ViewGroup container at present, it is enough.

The above WeChat theme and Zhihu theme are based on its to implement. Please refer to the source code for detailed implementation.

Another author's libraries using RxJava:

License

The RxImagePicker:MIT License

Copyright (c) 2018 qingmei2

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.

More Repositories

1

MVVM-Architecture

The practice of MVVM + Jetpack architecture in Android.
Kotlin
1,831
star
2

blogs

📝 The Android programing blogs(简体中文).
1,035
star
3

RxWeaver

🐤 一种基于RxJava2实现全局Error处理的实现方式。
Kotlin
269
star
4

MVI-Architecture

The practice of MVI + Jetpack architecture in Android.
Kotlin
175
star
5

MvpArchitecture-Android

[DEPRECATED] The MVP Architecture in the Android.
Java
113
star
6

FlutterGitHubApp

Flutter开发跨平台Github客户端,适用于Android和iOS。
Dart
102
star
7

Sample_dagger2

The guide of the Dagger2 and dagger.android usage in Android.
Java
98
star
8

SamplePaging

Kotlin
69
star
9

QrCodeScannerView-Android

[Deprecated(已废弃)] The Library simple and easy for scanning QrCode
Java
67
star
10

SlideBottomLayout-Android

【已废弃】该Repo已废弃,请使用Android原生的BottomSheet实现该功能.
Java
50
star
11

MVVM-Rhine-Template

Code generation template for MVVM-Rhine.
FreeMarker
45
star
12

Samples-Android

日常案例的练手代码仓库
Java
42
star
13

OpenGL-demo

Kotlin
38
star
14

MvvmApp-Android

[DEPRECATED] Mvvm+DataBinding study demo
Java
30
star
15

MultiTypeBindings

[DEPRECATED]零代码实现RecyclerView的Adapter
Java
28
star
16

Sample_AndroidTest

The Sample that how to use the AndroidTest in developing. (Espresso+Mockito+Robolectric)
Java
27
star
17

SampleNavigation

Google官方架构组件Navigation使用Sample
Kotlin
26
star
18

ShanbayAutoReader

扇贝阅读app自动阅读脚本
Groovy
12
star
19

RxFamilyUsage-Android

Also is your family if you love rx
Java
8
star
20

NotificationUtil

兼容Android8.0的通知Util
Kotlin
8
star
21

MVI-Rhine-Template

Code generation template for MVI-Rhine.
FreeMarker
7
star
22

RxDialog

Deprecated(已废弃)
Kotlin
6
star
23

MaterialDesignPictures

MD风格的图片,收集起来以作他用。
4
star
24

DslViewPagerAdapter

A simple implementation of ViewPager.
Kotlin
3
star
25

RxSchedulers

[DEPRECATED] The schedulers tools for RxJava2 in Android.
Kotlin
3
star
26

HenCoderPractice

HenCoder自定义View学习练习题库
Kotlin
3
star
27

KodeinSample

依赖注入工具Kodein使用Sample
Kotlin
2
star
28

GroovyJourney

Groovy学习代码
Groovy
2
star
29

qingmei2-blogs-art

Using Github as my image hosting service.
2
star
30

SampleWorkManager

Kotlin
1
star
31

my-unity-study-demo

The Unity learning project.
C#
1
star
32

LeetCodeJourney

目标,让家里的《算法导论》不再吃灰
Java
1
star
33

Data-Structure

Data-Structure Practice
C
1
star
34

BasicRxJavaSampleKotlin

Google官方BasicRxJavaSampleKotlin的代码,照着写学习:
Kotlin
1
star