Skip to content

Commit

Permalink
feat: support inject RecyclerView #10
Browse files Browse the repository at this point in the history
  • Loading branch information
nukc committed Nov 15, 2017
1 parent 4161e5b commit d2497ae
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ StateView is an invisible, zero-sized View that can be used to lazily inflate lo
add the dependency to your build.gradle:

```groovy
compile 'com.github.nukc.stateview:library:1.3.2'
compile 'com.github.nukc.stateview:library:1.3.3'
// animator providers
compile 'com.github.nukc.stateview:animations:1.0.1'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ StateView 一个轻量级的控件, 继承自 `View`, 吸收了 `ViewStub` 的


```groovy
compile 'com.github.nukc.stateview:library:1.3.2'
compile 'com.github.nukc.stateview:library:1.3.3'
// animator providers
compile 'com.github.nukc.stateview:animations:1.0.1'
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3'
testCompile 'junit:junit:4.12'
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<activity android:name=".CustomActivity" />
<activity android:name=".RefreshActivity" />
<activity android:name=".InjectViewActivity" />
<activity android:name=".AnimatorActivity"></activity>
<activity android:name=".AnimatorActivity" />
<activity android:name=".InjectRvActivity"></activity>
</application>

</manifest>
58 changes: 58 additions & 0 deletions app/src/main/java/com/github/nukc/sample/InjectRvActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.github.nukc.sample;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class InjectRvActivity extends BaseActivity {

@Override
protected int setContentView() {
return R.layout.activity_inject_rv;
}

@Override
protected View injectTarget() {
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new SampleAdapter(20));
return recyclerView;
}

private static class SampleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

private int mCount;

public SampleAdapter(int count) {
mCount = count;
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample, parent, false);
return new SampleHolder(view);
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
((SampleHolder) holder).mTextView.setText(position + "");
}

@Override
public int getItemCount() {
return mCount;
}

static class SampleHolder extends RecyclerView.ViewHolder {
TextView mTextView;

public SampleHolder(View itemView) {
super(itemView);
mTextView = (TextView) itemView.findViewById(R.id.text);
}
}
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/github/nukc/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,12 @@ public void onClick(View v) {
startActivity(new Intent(MainActivity.this, AnimatorActivity.class));
}
});

findViewById(R.id.btn_recycler_view).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, InjectRvActivity.class));
}
});
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_inject_rv.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.github.nukc.sample.InjectRvActivity">

</android.support.v7.widget.RecyclerView>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Animation View"/>

<Button
android:id="@+id/btn_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Inject RecyclerView"/>
</LinearLayout>
17 changes: 17 additions & 0 deletions app/src/main/res/layout/item_sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
tools:text="1" />

</LinearLayout>
2 changes: 1 addition & 1 deletion bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def siteUrl = 'https://github.com/nukc/StateView' // 项目的主页
def gitUrl = 'https://github.com/nukc/StateView.git' // Git仓库的url

group = "com.github.nukc.stateview"
version = "1.3.2"
version = "1.3.3"

install {
repositories.mavenInstaller {
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 20
versionName "1.3.2"
versionCode 21
versionName "1.3.3"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public static StateView inject(@NonNull ViewGroup parent, boolean hasActionBar)
if (parent instanceof LinearLayout ||
parent instanceof ScrollView ||
parent instanceof AdapterView ||
(parent instanceof ScrollingView && parent instanceof NestedScrollingChild) ||
(parent instanceof NestedScrollingParent && parent instanceof NestedScrollingChild)) {
ViewParent viewParent = parent.getParent();
if (viewParent == null) {
Expand Down

0 comments on commit d2497ae

Please sign in to comment.