Skip to content

Commit

Permalink
Merge pull request #18 from AlanCheen/develop
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
AlanCheen authored Jan 18, 2019
2 parents 5069ea0 + acdd5f2 commit b764777
Show file tree
Hide file tree
Showing 22 changed files with 222 additions and 95 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Flap

[![Download](https://api.bintray.com/packages/alancheen/maven/flap/images/download.svg?version=1.0.0)](https://bintray.com/alancheen/maven/flap/1.0.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) [![Author](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E7%A8%8B%E5%BA%8F%E4%BA%A6%E9%9D%9E%E7%8C%BF-blue.svg)](https://github.com/AlanCheen) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/AlanCheen/Flap/pulls)
[![Download](https://api.bintray.com/packages/alancheen/maven/flap/images/download.svg?version=1.1.0)](https://bintray.com/alancheen/maven/flap/1.1.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) [![Author](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E7%A8%8B%E5%BA%8F%E4%BA%A6%E9%9D%9E%E7%8C%BF-blue.svg)](https://github.com/AlanCheen) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/AlanCheen/Flap/pulls)

[中文指南看这里(点我点我)](./README_CN.md)

Expand Down Expand Up @@ -101,7 +101,7 @@ NOTE: Just register Factory one time is enough , so you can register your Factor

Yeah , you are good to go!

<div align=center><img width="360" height="640" src="art/flap-simple-showcase.png"/></div>
<div align=center><img width="360" height="640" src="assets/flap-simple-showcase.png"/></div>


## More Advanced Features
Expand Down
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Flap


[![Download](https://api.bintray.com/packages/alancheen/maven/flap/images/download.svg?version=1.0.0)](https://bintray.com/alancheen/maven/flap/1.0.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) [![Author](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E7%A8%8B%E5%BA%8F%E4%BA%A6%E9%9D%9E%E7%8C%BF-blue.svg)](https://github.com/AlanCheen) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/AlanCheen/Flap/pulls)
[![Download](https://api.bintray.com/packages/alancheen/maven/flap/images/download.svg?version=1.1.0)](https://bintray.com/alancheen/maven/flap/1.1.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) [![Author](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E7%A8%8B%E5%BA%8F%E4%BA%A6%E9%9D%9E%E7%8C%BF-blue.svg)](https://github.com/AlanCheen) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/AlanCheen/Flap/pulls)

## Flap 介绍

Expand Down Expand Up @@ -202,5 +202,5 @@ AsyncListDiffer 能够非常高效的刷新数据的能力, `Flap` 内部提

也非常欢迎关注我的公众号啦:

<p style="text-align: center;"><img alt="" src="https://cdn.nlark.com/yuque/0/2019/jpeg/138547/1546863515827-bd9dabf9-3e4b-4ea1-910f-e2f549b981cd.jpeg#align=left&display=inline&height=215&linkTarget=_blank&originHeight=430&originWidth=430&size=0&width=215" style="max-width: 250px; width: 215px;" /></p>
<div align=center><img width="215" height="215" src="assets/public-wechat.jpeg"/></div>

8 changes: 7 additions & 1 deletion app/src/main/java/me/yifeiyuan/flapdev/FlapApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.util.Log;

import me.yifeiyuan.flap.Flap;
import me.yifeiyuan.flapdev.customviewtype.CustomViewTypeItem;
import me.yifeiyuan.flapdev.simpleimage.SimpleImageItem;
import me.yifeiyuan.flapdev.simpletext.SimpleTextItem;

Expand All @@ -16,19 +17,24 @@ public class FlapApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
initFlap();
}

private void initFlap() {

//only setDebug(true) when you are testing
Flap.setDebug(true);

long t1 = System.currentTimeMillis();

Flap.getDefault().register(new SimpleTextItem.Factory());
Flap.getDefault().register(new SimpleImageItem.Factory());
Flap.getDefault().register(new CustomViewTypeItem.Factory());

long t2 = System.currentTimeMillis();

Log.e("Flap", "Init Flap time cost :" + (t2 - t1));

Flap.getDefault().getFlapItemPool().setMaxRecycledViews(new SimpleImageItem.Factory().getItemViewType(null), 8);

}
}
5 changes: 5 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;

import me.yifeiyuan.flap.FlapAdapter;
import me.yifeiyuan.flapdev.customviewtype.CustomModel;
import me.yifeiyuan.flapdev.simpleimage.SimpleImageModel;
import me.yifeiyuan.flapdev.simpletext.SimpleTextModel;

Expand Down Expand Up @@ -64,6 +65,10 @@ private List<Object> mockModels() {
models.add(new SimpleTextModel("Java"));
models.add(new SimpleTextModel("Kotlin"));

models.add(new SimpleImageModel());

models.add(new CustomModel());

return models;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.yifeiyuan.flapdev.customviewtype;

/**
* Created by 程序亦非猿 on 2019/1/18.
*/
public class CustomModel {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.yifeiyuan.flapdev.customviewtype;

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

import java.util.List;

import me.yifeiyuan.flap.FlapAdapter;
import me.yifeiyuan.flap.FlapItem;
import me.yifeiyuan.flap.internal.FlapItemFactory;
import me.yifeiyuan.flapdev.R;

/**
* Created by 程序亦非猿 on 2019/1/18.
*/
public class CustomViewTypeItem extends FlapItem<CustomModel> {

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

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

}

public static class Factory implements FlapItemFactory<CustomModel, CustomViewTypeItem> {

@NonNull
@Override
public CustomViewTypeItem onCreateViewHolder(@NonNull final LayoutInflater inflater, @NonNull final ViewGroup parent, final int viewType) {
return new CustomViewTypeItem(inflater.inflate(R.layout.flap_item_custom_type, parent, false));
}

@Override
public int getItemViewType(final CustomModel model) {
return 3333;
}
}

}
23 changes: 23 additions & 0 deletions app/src/main/res/layout/flap_item_custom_type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ff00ff"
android:orientation="horizontal"
android:layout_marginBottom="4dp"
>

<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingLeft="16dp"
android:singleLine="true"
android:text="Custom View Type Item"
android:textColor="@android:color/white"
android:textSize="16sp"
/>

</LinearLayout>
File renamed without changes
Binary file added assets/public-wechat.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 = "1.0.0"
version = "1.1.0"
group = "me.yifeiyuan.flap"
androidArtifact {
artifactId = "flap"
Expand Down
24 changes: 0 additions & 24 deletions flap/src/main/java/me/yifeiyuan/flap/DefaultFlapItem.java

This file was deleted.

36 changes: 19 additions & 17 deletions flap/src/main/java/me/yifeiyuan/flap/Flap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
import android.support.annotation.NonNull;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import me.yifeiyuan.flap.exceptions.ItemFactoryNotFoundException;
import me.yifeiyuan.flap.internal.DefaultFlapItem;
import me.yifeiyuan.flap.internal.FlapItemFactory;

/**
* Created by 程序亦非猿
*/
public final class Flap implements IFlap {

private static final String TAG = "Flap";

private static final int DEFAULT_ITEM_TYPE = -66666;

static final int DEFAULT_ITEM_TYPE_COUNT = 32;

private final Map<Class<?>, FlapItemFactory> itemFactories;
private final SparseArray<FlapItemFactory> factoryMapping;

private final FlapItemPool GLOBAL_POOL = new FlapItemPool();

private final DefaultFlapItem.Factory DEFAULT = new DefaultFlapItem.Factory();

private static volatile Flap sInstance;

public static Flap getDefault() {
Expand Down Expand Up @@ -87,7 +90,7 @@ public int getItemViewType(@NonNull final Object model) {
} else {
FlapDebug.throwIfDebugging(new ItemFactoryNotFoundException("Can't find the ItemFactory for : " + modelClazz + " , please register first!"));
}
return DEFAULT_ITEM_TYPE;
return DEFAULT.getItemViewType(model);
}

@NonNull
Expand All @@ -97,7 +100,7 @@ public FlapItem onCreateViewHolder(@NonNull final LayoutInflater inflater, @NonN
FlapItem vh = null;

FlapItemFactory factory = factoryMapping.get(viewType);
if (null != factory) {
if (factory != null) {
try {
vh = factory.onCreateViewHolder(inflater, parent, viewType);
} catch (Exception e) {
Expand All @@ -106,36 +109,35 @@ public FlapItem onCreateViewHolder(@NonNull final LayoutInflater inflater, @NonN
}
}
if (vh == null) {
vh = onCreateDefaultViewHolder(inflater, parent, viewType);
vh = DEFAULT.onCreateViewHolder(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);
public void onBindViewHolder(@NonNull final FlapItem flapItem, final Object model, @NonNull final FlapAdapter flapAdapter, @NonNull final List<Object> payloads) {
flapItem.bind(model, flapAdapter, payloads);
}

@Override
public void onViewAttachedToWindow(@NonNull final FlapItem holder, @NonNull final FlapAdapter flapAdapter) {
holder.onViewAttachedToWindow(flapAdapter);
public void onViewAttachedToWindow(@NonNull final FlapItem flapItem, @NonNull final FlapAdapter flapAdapter) {
flapItem.onViewAttachedToWindow(flapAdapter);
}

@Override
public void onViewDetachedFromWindow(@NonNull final FlapItem holder, @NonNull final FlapAdapter flapAdapter) {
holder.onViewDetachedFromWindow(flapAdapter);
public void onViewDetachedFromWindow(@NonNull final FlapItem flapItem, @NonNull final FlapAdapter flapAdapter) {
flapItem.onViewDetachedFromWindow(flapAdapter);
}

@Override
public void onViewRecycled(@NonNull final FlapItem holder, @NonNull final FlapAdapter flapAdapter) {
holder.onViewRecycled(flapAdapter);
public void onViewRecycled(@NonNull final FlapItem flapItem, @NonNull final FlapAdapter flapAdapter) {
flapItem.onViewRecycled(flapAdapter);
}

@NonNull
@Override
public FlapItem onCreateDefaultViewHolder(@NonNull final LayoutInflater inflater, @NonNull final ViewGroup parent, final int viewType) {
return new DefaultFlapItem(new View(parent.getContext()));
public boolean onFailedToRecycleView(@NonNull final FlapItem flapItem, @NonNull final FlapAdapter flapAdapter) {
return flapItem.onFailedToRecycleView(flapAdapter);
}

public static void setDebug(final boolean isDebugging) {
Expand Down
5 changes: 1 addition & 4 deletions flap/src/main/java/me/yifeiyuan/flap/FlapAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ public void onViewRecycled(@NonNull final FlapItem holder) {

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

public FlapAdapter setLifecycleOwner(@NonNull final LifecycleOwner lifecycleOwner) {
Expand Down
10 changes: 6 additions & 4 deletions flap/src/main/java/me/yifeiyuan/flap/FlapAdapterDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ interface FlapAdapterDelegate {
@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);
void onBindViewHolder(@NonNull final FlapItem flapItem, Object model, @NonNull FlapAdapter flapAdapter, @NonNull List<Object> payloads);

void onViewAttachedToWindow(@NonNull FlapItem holder,@NonNull FlapAdapter flapAdapter);
void onViewAttachedToWindow(@NonNull FlapItem flapItem, @NonNull FlapAdapter flapAdapter);

void onViewDetachedFromWindow(@NonNull FlapItem holder,@NonNull FlapAdapter flapAdapter);
void onViewDetachedFromWindow(@NonNull FlapItem flapItem, @NonNull FlapAdapter flapAdapter);

void onViewRecycled(@NonNull FlapItem holder,@NonNull FlapAdapter flapAdapter);
void onViewRecycled(@NonNull FlapItem flapItem, @NonNull FlapAdapter flapAdapter);

boolean onFailedToRecycleView(@NonNull FlapItem flapItem, @NonNull FlapAdapter flapAdapter);
}
18 changes: 0 additions & 18 deletions flap/src/main/java/me/yifeiyuan/flap/FlapItemFactory.java

This file was deleted.

8 changes: 0 additions & 8 deletions flap/src/main/java/me/yifeiyuan/flap/IFlap.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package me.yifeiyuan.flap;

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

/**
* Created by 程序亦非猿
*
* IFlap is the core interface that define what Flap can do and how Flap works.
*/
interface IFlap extends ItemFactoryManager, FlapAdapterDelegate {

@SuppressWarnings("unused")
@NonNull
FlapItem onCreateDefaultViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, int viewType);

}
2 changes: 2 additions & 0 deletions flap/src/main/java/me/yifeiyuan/flap/ItemFactoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.support.annotation.NonNull;

import me.yifeiyuan.flap.internal.FlapItemFactory;

/**
* Created by 程序亦非猿
*
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions flap/src/main/java/me/yifeiyuan/flap/LayoutItemFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.HashMap;
import java.util.Map;

import me.yifeiyuan.flap.internal.FlapItemFactory;

import static me.yifeiyuan.flap.Flap.DEFAULT_ITEM_TYPE_COUNT;

/**
Expand Down
Loading

0 comments on commit b764777

Please sign in to comment.