Skip to content

Commit

Permalink
Merge pull request #12 from AlanCheen/develop
Browse files Browse the repository at this point in the history
release 0.7.0
  • Loading branch information
AlanCheen authored Jan 2, 2019
2 parents d6ceee0 + 291a1ff commit b5bf980
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 101 deletions.
30 changes: 15 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ PRs welcome.
- Reference issues and pull requests liberally after the first line
- When only changing documentation, include [ci skip] in the commit title
- Consider starting the commit message with an applicable emoji:
- 🎨 :art: when improving the format/structure of the code
- 🐎 :racehorse: when improving performance
- 🚱 :non-potable_water: when plugging memory leaks
- 📝 :memo: when writing docs
- 🐧 :penguin: when fixing something on Linux
- 🍎 :apple: when fixing something on macOS
- 🏁 :checkered_flag: when fixing something on Windows
- 🐛 :bug: when fixing a bug
- 🔥 :fire: when removing code or files
- 💚 :green_heart: when fixing the CI build
-:white_check_mark: when adding tests
- 🔒 :lock: when dealing with security
- ⬆️ :arrow_up: when upgrading dependencies
- ⬇️ :arrow_down: when downgrading dependencies
- 👕 :shirt: when removing linter warnings
- 🎨 `:art:` when improving the format/structure of the code
- 🐎 `:racehorse:` when improving performance
- 🚱 `:non-potable_water:` when plugging memory leaks
- 📝 `:memo:` when writing docs
- 🐧 `:penguin:` when fixing something on Linux
- 🍎 `:apple:` when fixing something on macOS
- 🏁 `:checkered_flag:` when fixing something on Windows
- 🐛 `:bug:` when fixing a bug
- 🔥 `:fire:` when removing code or files
- 💚 `:green_heart:` when fixing the CI build
-`:white_check_mark:` when adding tests
- 🔒 `:lock:` when dealing with security
- ⬆️ `:arrow_up:` when upgrading dependencies
- ⬇️ `:arrow_down:` when downgrading dependencies
- 👕 `:shirt:` when removing linter warnings
58 changes: 10 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[![Download](https://api.bintray.com/packages/alancheen/maven/flap/images/download.svg?version=0.6.0)](https://bintray.com/alancheen/maven/flap/0.6.0/link) [![Build Status](https://travis-ci.org/AlanCheen/Flap.svg?branch=master)](https://travis-ci.org/AlanCheen/Flap) ![RecyclerView](https://img.shields.io/badge/RecyclerView-28.0.0-brightgreen.svg) ![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat) [![license](https://img.shields.io/github/license/AlanCheen/Flap.svg)](./LICENSE)

**WARNING: Flap is still under development.**
**[WIP]WARNING: Flap is still under development.**

Flap is a library that makes `RecyclerView.Adapter` more easier to use , especially when you have to support lots of different type ViewHolders.
`Flap` is a library that makes `RecyclerView.Adapter` more easier to use , especially when you have to support lots of different type ViewHolders.

Flap can save your day by keeping you from writing boilerplate codes.

Expand All @@ -25,8 +25,6 @@ dependencies {

#### Step 1 : Create a model class :

A model class can be a POJO or Java Bean.

```java
public class SimpleTextModel {

Expand Down Expand Up @@ -77,13 +75,13 @@ public class SimpleTextItem extends FlapItem<SimpleTextModel> {



#### Step 3 : Register the `FlapItemFactory` and create your `FlapAdapter`
#### Step 3 : Register `FlapItemFactory` and create your `FlapAdapter`

Create your `FlapAdapter` and register the `SimpleTextItemFactory` that we already created , setup the models :

```java
//register your ItemFactory to Flap
Flap.getDefault().register(SimpleTextModel.class, new SimpleTextItem.SimpleTextItemFactory());
Flap.getDefault().register(new SimpleTextItem.SimpleTextItemFactory());

FlapAdapter adapter = new FlapAdapter();

Expand All @@ -101,7 +99,8 @@ recyclerView.setAdapter(adapter);

Yeah , you are good to go!

![](art/flap-simple-showcase.png)
<div align=center><img width="360" height="640" src="art/flap-simple-showcase.png"/></div>


## More Feature

Expand Down Expand Up @@ -132,20 +131,15 @@ Releated methods :

Check [Releases](https://github.com/AlanCheen/Flap/releases) for details.


## Todo List
## Feature List

- Support AsyncListDiffer
- Support Lifecycle

## Contribution

Any feedback would be helpful , thanks.



## Contact Me

Any feedback could be helpful , thanks.

I'm Fitz , an Engineer working at Alibaba living in China .

Follow me on :
Expand All @@ -156,36 +150,4 @@ Follow me on :
- [简书](https://www.jianshu.com/u/ec59bd61433a)
- [掘金](https://juejin.im/user/558cc8dae4b0de86abc9cfda)

Feel free to contact me.



## Apps are using Flap

Contact me if you are using Flap in your App.



## Thanks

I'm using [StefMa/bintray-release](https://github.com/StefMa/bintray-release) to publish Flap to jCenter.



## License

```
Copyright 2018 程序亦非猿
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.
```
Feel free to contact me.
44 changes: 44 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/BaseFlapItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.yifeiyuan.flapdev;

import android.support.annotation.NonNull;
import android.view.View;

import java.util.List;

import me.yifeiyuan.flap.FlapAdapter;
import me.yifeiyuan.flap.FlapItem;

/**
* Created by 程序亦非猿 on 2018/12/29.
*/
public class BaseFlapItem<T> extends FlapItem<T> {

public BaseFlapItem(final View itemView) {
super(itemView);
}

@Override
protected void onBind(@NonNull final T model, @NonNull final FlapAdapter adapter, @NonNull final List<Object> payloads) {

}

@Override
protected void onViewAttachedToWindow(final FlapAdapter flapAdapter) {
super.onViewAttachedToWindow(flapAdapter);
}

@Override
protected void onViewDetachedFromWindow(final FlapAdapter flapAdapter) {
super.onViewDetachedFromWindow(flapAdapter);
}

@Override
protected void onViewRecycled(final FlapAdapter flapAdapter) {
super.onViewRecycled(flapAdapter);
}

@Override
protected boolean onFailedToRecycleView(final FlapAdapter flapAdapter) {
return super.onFailedToRecycleView(flapAdapter);
}
}
6 changes: 2 additions & 4 deletions app/src/main/java/me/yifeiyuan/flapdev/FlapApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import me.yifeiyuan.flap.Flap;
import me.yifeiyuan.flapdev.simpleimage.SimpleImageItem;
import me.yifeiyuan.flapdev.simpleimage.SimpleImageModel;
import me.yifeiyuan.flapdev.simpletext.SimpleTextItem;
import me.yifeiyuan.flapdev.simpletext.SimpleTextModel;

/**
* Flap
Expand All @@ -23,8 +21,8 @@ public void onCreate() {

long t1 = System.currentTimeMillis();

Flap.getDefault().register(SimpleTextModel.class, new SimpleTextItem.SimpleTextItemFactory());
Flap.getDefault().register(SimpleImageModel.class, new SimpleImageItem.SimpleImageItemFactory());
Flap.getDefault().register(new SimpleTextItem.SimpleTextItemFactory());
Flap.getDefault().register(new SimpleImageItem.SimpleImageItemFactory());

long t2 = System.currentTimeMillis();

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'

//https://github.com/StefMa/bintray-release
classpath "guru.stefma.bintrayrelease:bintrayrelease:1.1.1"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion flap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {

apply plugin: "guru.stefma.bintrayrelease"

version = "0.6.0"
version = "0.7.0"
group = "me.yifeiyuan.flap"
androidArtifact {
artifactId = "flap"
Expand Down
25 changes: 22 additions & 3 deletions flap/src/main/java/me/yifeiyuan/flap/Flap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.ViewGroup;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -46,17 +47,30 @@ private Flap(int typeCount) {
}

@Override
public ItemFactoryManager register(@NonNull final Class<?> modelClazz, @NonNull final FlapItemFactory itemFactory) {
public ItemFactoryManager register(@NonNull final FlapItemFactory itemFactory) {
Class<?> modelClazz = getModelClassFromItemFactory(itemFactory);
itemFactories.put(modelClazz, itemFactory);
return this;
}

@Override
public ItemFactoryManager unregister(@NonNull final Class<?> modelClazz) {
public ItemFactoryManager unregister(@NonNull final FlapItemFactory itemFactory) {
Class<?> modelClazz = getModelClassFromItemFactory(itemFactory);
itemFactories.remove(modelClazz);
return this;
}

@Override
public ItemFactoryManager clearAll() {
itemFactories.clear();
factoryMapping.clear();
return this;
}

private Class<?> getModelClassFromItemFactory(final FlapItemFactory itemFactory) {
return (Class<?>) ReflectUtils.getTypes(itemFactory)[0];
}

@SuppressWarnings("unchecked")
@Override
public int getItemViewType(@NonNull final Object model) {
Expand Down Expand Up @@ -89,13 +103,18 @@ public FlapItem onCreateViewHolder(@NonNull final LayoutInflater inflater, @NonN
FlapDebug.throwIfDebugging(e);
}
}
//In case that we get a null view holder , create a default one ,so won't crash the app
if (vh == null) {
vh = onCreateDefaultViewHolder(inflater, parent, viewType);
}
return vh;
}

@SuppressWarnings("unchecked")
@Override
public void onBindViewHolder(@NonNull final FlapItem holder, final Object model, @NonNull final FlapAdapter flapAdapter, @NonNull final List<Object> payloads) {
holder.bind(model, flapAdapter, payloads);
}

@NonNull
@Override
public FlapItem onCreateDefaultViewHolder(@NonNull final LayoutInflater inflater, @NonNull final ViewGroup parent, final int viewType) {
Expand Down
26 changes: 20 additions & 6 deletions flap/src/main/java/me/yifeiyuan/flap/FlapAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class FlapAdapter extends RecyclerView.Adapter<FlapItem> {

@NonNull
private Flap flap = Flap.getDefault();
private final Flap flap = Flap.getDefault();

private LifecycleOwner lifecycleOwner;

Expand All @@ -42,7 +42,7 @@ public final void onBindViewHolder(@NonNull final FlapItem holder, final int pos
@Override
public void onBindViewHolder(@NonNull final FlapItem holder, final int position, @NonNull final List<Object> payloads) {
attachLifecycleOwnerIfNeed(holder);
holder.bind(getModel(position), this, payloads);
flap.onBindViewHolder(holder, getModel(position), this, payloads);
}

/**
Expand Down Expand Up @@ -77,17 +77,31 @@ public void onAttachedToRecyclerView(@NonNull final RecyclerView recyclerView) {
@Override
public void onViewAttachedToWindow(@NonNull FlapItem holder) {
super.onViewAttachedToWindow(holder);
holder.onViewAttachedToWindow();
holder.onViewAttachedToWindow(this);
}

@Override
public void onViewDetachedFromWindow(@NonNull FlapItem holder) {
super.onViewDetachedFromWindow(holder);
holder.onViewDetachedFromWindow();
holder.onViewDetachedFromWindow(this);
}

@Override
public void onViewRecycled(@NonNull final FlapItem holder) {
super.onViewRecycled(holder);
holder.onViewRecycled(this);
}

@Override
public boolean onFailedToRecycleView(@NonNull final FlapItem holder) {
if (holder.onFailedToRecycleView(this)) {
return true;
}
return super.onFailedToRecycleView(holder);
}

public FlapAdapter setLifecycleOwner(@NonNull final LifecycleOwner lifecycleOwner) {
checkNotNull(lifecycleOwner);
checkNotNull(lifecycleOwner, "lifecycleOwner can't be null.");
this.lifecycleOwner = lifecycleOwner;
return this;
}
Expand All @@ -102,7 +116,7 @@ private Object getModel(final int position) {
}

public void setModels(@NonNull List<?> models) {
checkNotNull(models);
checkNotNull(models, "models can't be null here");
this.models = models;
}

Expand Down
20 changes: 20 additions & 0 deletions flap/src/main/java/me/yifeiyuan/flap/FlapAdapterDelegate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package me.yifeiyuan.flap;

import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.List;

/**
* Created by 程序亦非猿 on 2019/1/2.
*/
interface FlapAdapterDelegate {

int getItemViewType(@NonNull Object model);

@NonNull
FlapItem onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, int viewType);

void onBindViewHolder(@NonNull final FlapItem holder, Object model, @NonNull FlapAdapter flapAdapter, @NonNull List<Object> payloads);
}
3 changes: 3 additions & 0 deletions flap/src/main/java/me/yifeiyuan/flap/FlapDebug.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
/**
* Flap
* Created by 程序亦非猿 on 2018/12/13.
*
* Debug helper for Flap.
*
*/
final class FlapDebug {

Expand Down
Loading

0 comments on commit b5bf980

Please sign in to comment.