Skip to content

Commit

Permalink
Merge pull request #30 from AlanCheen/ann
Browse files Browse the repository at this point in the history
Support Android Annotation Processor COOL!!!
  • Loading branch information
程序亦非猿 authored Mar 25, 2019
2 parents 112bf3d + 1ce1267 commit 94a1951
Show file tree
Hide file tree
Showing 34 changed files with 486 additions and 53 deletions.
19 changes: 19 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ recyclerView.setAdapter(adapter);
- [x] 支持设置全局的 RecycledViewPool;
- [x] 支持 Lifecycle;

## FAQ

一、如何设置 `FlapItem` 的点击事件?

答:Flap并没有提供一个全局的点击事件处理方法,而是推荐在 FlapItem 的 onBind 方法里给 itemView 设置 onClick 事件,这样更清晰。

二、我想在 `FlapItem` 里用 context 怎么办?

答:`FlapItem` 有个字段 `context` 你可以直接访问使用。


## 贡献
Expand All @@ -196,7 +205,17 @@ recyclerView.setAdapter(adapter);
- 发现 有需要的功能 `Flap` 不具有? 提 [issue](https://github.com/AlanCheen/Flap/issues) 告诉我!
- 任何意见和建议都可以提喔~

## 贡献者列表

感谢以下人员对 `Flap` 提供的帮助:

- [dreamkong](https://github.com/dreamkong)
- [Fitz](https://github.com/finalrose7)
- [Halouyao](https://github.com/doooyao)
- [码小猪](https://www.hchstudio.cn/)
- [大脑好饿](http://www.imliujun.com/)
- [zhousysu](https://github.com/zhousysu)
- [阿呆](http://blogyudan.online/)

## 联系关注我

Expand Down
6 changes: 6 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation 'com.android.support:recyclerview-v7:28.0.0'

implementation project(':flap')
implementation project(':flap-annotations')

annotationProcessor project(':flap-compiler')

}
17 changes: 12 additions & 5 deletions app/src/main/java/me/yifeiyuan/flapdev/FlapApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import android.util.Log;

import me.yifeiyuan.flap.Flap;
import me.yifeiyuan.flap.apt.factories.AnnItemFactory;
import me.yifeiyuan.flap.apt.factories.GenericFlapItemFactory;
import me.yifeiyuan.flap.apt.factories.SimpleImageItemFactory;
import me.yifeiyuan.flap.apt.factories.SimpleTextItemFactory;
import me.yifeiyuan.flapdev.customviewtype.CustomViewTypeItem;
import me.yifeiyuan.flapdev.simpleimage.SimpleImageItem;
import me.yifeiyuan.flapdev.simpletext.SimpleTextItem;

/**
* Flap
Expand All @@ -26,15 +28,20 @@ private void initFlap() {
Flap.setDebug(true);

long t1 = System.currentTimeMillis();
//Factories created by apt
Flap.getDefault().register(new SimpleTextItemFactory());
Flap.getDefault().register(new SimpleImageItemFactory());
Flap.getDefault().register(new GenericFlapItemFactory());

Flap.getDefault().register(new SimpleTextItem.Factory());
Flap.getDefault().register(new SimpleImageItem.Factory());
//自定义 layoutId ; custom layoutId
Flap.getDefault().register(new CustomViewTypeItem.Factory());

long t2 = System.currentTimeMillis();

Flap.getDefault().register(new AnnItemFactory());

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

Flap.getDefault().getFlapItemPool().setMaxRecycledViews(new SimpleImageItem.Factory().getItemViewType(null), 8);
// 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 @@ -9,8 +9,10 @@

import me.yifeiyuan.flap.FlapAdapter;
import me.yifeiyuan.flapdev.customviewtype.CustomModel;
import me.yifeiyuan.flapdev.generictest.GenericModel;
import me.yifeiyuan.flapdev.simpleimage.SimpleImageModel;
import me.yifeiyuan.flapdev.simpletext.SimpleTextModel;
import me.yifeiyuan.flapdev.testann.AnnModel;

public class MainActivity extends AppCompatActivity {

Expand Down Expand Up @@ -68,6 +70,9 @@ private List<Object> mockModels() {
models.add(new SimpleImageModel());

models.add(new CustomModel());
models.add(new GenericModel());

models.add(new AnnModel());

return models;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
package me.yifeiyuan.flapdev;
package me.yifeiyuan.flapdev.base;

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 abstract class BaseFlapItem<T extends BaseModel> 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);
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/base/BaseModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.yifeiyuan.flapdev.base;

/**
* Created by 程序亦非猿 on 2019/1/29.
*/
public class BaseModel {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
public class CustomViewTypeItem extends FlapItem<CustomModel> {

private static final int CUSTOM_ITEM_VIEW_TYPE = 466;

public CustomViewTypeItem(final View itemView) {
super(itemView);
}
Expand All @@ -26,7 +28,7 @@ protected void onBind(@NonNull final CustomModel model, @NonNull final FlapAdapt

}

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

@NonNull
@Override
Expand All @@ -36,7 +38,7 @@ public CustomViewTypeItem onCreateViewHolder(@NonNull final LayoutInflater infla

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

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

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

import java.util.List;

import me.yifeiyuan.flap.FlapAdapter;
import me.yifeiyuan.flap.annotations.Flap;
import me.yifeiyuan.flapdev.R;
import me.yifeiyuan.flapdev.base.BaseFlapItem;

/**
* Created by 程序亦非猿 on 2019/1/29.
*/

@Flap(layoutId = R.layout.flap_item_generic_type)
public class GenericFlapItem extends BaseFlapItem<GenericModel> {

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

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

}

// public static class Factory extends LayoutItemFactory<GenericModel, GenericFlapItem> {
// @Override
// protected int getLayoutResId(final GenericModel model) {
// return R.layout.flap_item_generic_type;
// }
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package me.yifeiyuan.flapdev.generictest;

import me.yifeiyuan.flapdev.base.BaseModel;

/**
* Created by 程序亦非猿 on 2019/1/29.
*/
public class GenericModel extends BaseModel {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

import me.yifeiyuan.flap.FlapAdapter;
import me.yifeiyuan.flap.FlapItem;
import me.yifeiyuan.flap.LayoutItemFactory;
import me.yifeiyuan.flap.annotations.Flap;
import me.yifeiyuan.flapdev.R;

/**
* Created by 程序亦非猿 on 2018/12/4.
*/
@Flap(layoutId = R.layout.flap_item_simple_image)
public class SimpleImageItem extends FlapItem<SimpleImageModel> {

public SimpleImageItem(final View itemView) {
Expand All @@ -24,12 +25,12 @@ protected void onBind(@NonNull final SimpleImageModel model, @NonNull final Flap

}

public static class Factory extends LayoutItemFactory<SimpleImageModel, SimpleImageItem> {

@Override
protected int getLayoutResId(final SimpleImageModel model) {
return R.layout.flap_item_simple_image;
}
}
// public static class Factory extends LayoutItemFactory<SimpleImageModel, SimpleImageItem> {
//
// @Override
// protected int getLayoutResId(final SimpleImageModel model) {
// return R.layout.flap_item_simple_image;
// }
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

import me.yifeiyuan.flap.FlapAdapter;
import me.yifeiyuan.flap.FlapItem;
import me.yifeiyuan.flap.LayoutItemFactory;
import me.yifeiyuan.flap.annotations.Flap;
import me.yifeiyuan.flapdev.R;

/**
* Created by 程序亦非猿 on 2018/12/4.
*/
@Flap(layoutId = R.layout.flap_item_simple_text)
public class SimpleTextItem extends FlapItem<SimpleTextModel> {

private static final String TAG = "SimpleTextItem";
Expand All @@ -32,12 +33,12 @@ protected void onBind(@NonNull final SimpleTextModel model, @NonNull final FlapA
tvContent.setText(model.content);
}

public static class Factory extends LayoutItemFactory<SimpleTextModel, SimpleTextItem> {

@Override
protected int getLayoutResId(final SimpleTextModel model) {
return R.layout.flap_item_simple_text;
}
}
// public static class Factory extends LayoutItemFactory<SimpleTextModel, SimpleTextItem> {
//
// @Override
// protected int getLayoutResId(final SimpleTextModel model) {
// return R.layout.flap_item_simple_text;
// }
// }

}
41 changes: 41 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/testann/AnnItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package me.yifeiyuan.flapdev.testann;

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

import java.util.List;

import me.yifeiyuan.flap.FlapAdapter;
import me.yifeiyuan.flap.FlapItem;
import me.yifeiyuan.flap.annotations.Flap;
import me.yifeiyuan.flapdev.R;

/**
* Created by 程序亦非猿 on 2019-03-22.
*/

@Flap(layoutId = R.layout.flap_item_ann)
public class AnnItem extends FlapItem<AnnModel> {

private static final String TAG = "SimpleTextItem";

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

@Override
protected void onBind(@NonNull final AnnModel model, @NonNull final FlapAdapter adapter, @NonNull final List<Object> payloads) {
Log.d(TAG, "onBind: " + getAdapterPosition());
}

// public static class Factory extends LayoutItemFactory<AnnModel, AnnItem> {
//
// @Override
// protected int getLayoutResId(final AnnModel model) {
// return R.layout.flap_item_simple_text;
// }
//
// }

}
9 changes: 9 additions & 0 deletions app/src/main/java/me/yifeiyuan/flapdev/testann/AnnModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package me.yifeiyuan.flapdev.testann;

import me.yifeiyuan.flapdev.base.BaseModel;

/**
* Created by 程序亦非猿 on 2019-03-22.
*/
public class AnnModel extends BaseModel {
}
17 changes: 17 additions & 0 deletions app/src/main/res/layout/flap_item_ann.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp">

<TextView
android:id="@+id/tv_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="16sp"
android:singleLine="true"
android:gravity="center"
android:text="Android Annotation Processor"
/>
</FrameLayout>
19 changes: 19 additions & 0 deletions app/src/main/res/layout/flap_item_generic_type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@android:color/holo_green_dark">

<TextView
android:id="@+id/tv_"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:singleLine="true"
android:text="Generic Type"
android:textColor="@android:color/white"
android:textSize="16sp"
/>

</FrameLayout>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.2.1'
//https://github.com/StefMa/bintray-release
classpath "guru.stefma.bintrayrelease:bintrayrelease:1.1.1"
classpath 'com.novoda:bintray-release:0.9'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
1 change: 1 addition & 0 deletions flap-annotations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit 94a1951

Please sign in to comment.