Skip to content

Commit

Permalink
Publish
Browse files Browse the repository at this point in the history
  • Loading branch information
TellH committed Jan 22, 2017
1 parent c773605 commit d09b7b8
Show file tree
Hide file tree
Showing 26 changed files with 150 additions and 17 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Expand Up @@ -29,4 +29,5 @@ dependencies {
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
compile project(':stickyheaderview-rv')
}
@@ -1,5 +1,8 @@
package tellh.com.recyclerstickyheaderview;

import tellh.com.stickyheaderview_rv.adapter.DataBean;
import tellh.com.stickyheaderview_rv.adapter.StickyHeaderViewAdapter;

/**
* Created by tlh on 2017/1/22 :)
*/
Expand Down
Expand Up @@ -3,6 +3,9 @@
import android.view.View;
import android.widget.TextView;

import tellh.com.stickyheaderview_rv.adapter.StickyHeaderViewAdapter;
import tellh.com.stickyheaderview_rv.adapter.ViewBinder;

/**
* Created by tlh on 2017/1/22 :)
*/
Expand Down
Expand Up @@ -14,6 +14,9 @@
import java.util.Comparator;
import java.util.List;

import tellh.com.stickyheaderview_rv.adapter.DataBean;
import tellh.com.stickyheaderview_rv.adapter.StickyHeaderViewAdapter;

public class MainActivity extends AppCompatActivity {
private RecyclerView rv;
private StickyHeaderViewAdapter adapter;
Expand Down
@@ -1,5 +1,8 @@
package tellh.com.recyclerstickyheaderview;

import tellh.com.stickyheaderview_rv.adapter.DataBean;
import tellh.com.stickyheaderview_rv.adapter.StickyHeaderViewAdapter;

public class User extends DataBean {
private String login;
private int id;
Expand Down Expand Up @@ -49,7 +52,7 @@ public void setShouldSticky(boolean shouldSticky) {
}

@Override
protected boolean shouldSticky() {
public boolean shouldSticky() {
return shouldSticky;
}

Expand Down
Expand Up @@ -6,6 +6,9 @@

import com.squareup.picasso.Picasso;

import tellh.com.stickyheaderview_rv.adapter.StickyHeaderViewAdapter;
import tellh.com.stickyheaderview_rv.adapter.ViewBinder;

/**
* Created by tlh on 2017/1/22 :)
*/
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Expand Up @@ -5,7 +5,7 @@
android:layout_height="match_parent"
tools:context="tellh.com.recyclerstickyheaderview.MainActivity">

<tellh.com.recyclerstickyheaderview.StickyHeaderView
<tellh.com.stickyheaderview_rv.StickyHeaderView
android:id="@+id/stickyHeaderView"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand All @@ -16,5 +16,5 @@
android:layout_height="match_parent"
android:background="@android:color/white"
android:scrollbars="vertical" />
</tellh.com.recyclerstickyheaderview.StickyHeaderView>
</tellh.com.stickyheaderview_rv.StickyHeaderView>
</FrameLayout>
3 changes: 3 additions & 0 deletions build.gradle
Expand Up @@ -9,6 +9,9 @@ buildscript {

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

// JitPack
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
@@ -1 +1 @@
include ':app'
include ':app', ':stickyheaderview-rv'
1 change: 1 addition & 0 deletions stickyheaderview-rv/.gitignore
@@ -0,0 +1 @@
/build
35 changes: 35 additions & 0 deletions stickyheaderview-rv/build.gradle
@@ -0,0 +1,35 @@
apply plugin: 'com.android.library'
// JitPack
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.TellH'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile "com.android.support:recyclerview-v7:25.1.0"
testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions stickyheaderview-rv/proguard-rules.pro
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\AndroidSDK\AndroidStudio/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
@@ -0,0 +1,26 @@
package tellh.com.stickyheaderview_rv;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("tellh.com.stickyheaderview_rv.test", appContext.getPackageName());
}
}
9 changes: 9 additions & 0 deletions stickyheaderview-rv/src/main/AndroidManifest.xml
@@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tellh.com.stickyheaderview_rv">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
@@ -1,4 +1,4 @@
package tellh.com.recyclerstickyheaderview;
package tellh.com.stickyheaderview_rv;

import android.content.Context;
import android.graphics.Color;
Expand All @@ -14,14 +14,18 @@
import java.util.List;
import java.util.Stack;

import tellh.com.stickyheaderview_rv.adapter.DataBean;
import tellh.com.stickyheaderview_rv.adapter.StickyHeaderViewAdapter;
import tellh.com.stickyheaderview_rv.adapter.ViewBinder;

/**
* Created by tlh on 2017/1/21 :)
*/

public class StickyHeaderView extends FrameLayout {
private static final String TAG = "StickyHeaderView";
private FrameLayout mHeaderContainer;
private boolean hasInit = false;
private FrameLayout mHeaderContainer;
private RecyclerView mRecyclerView;
private int mHeaderHeight = -1;
private StickyHeaderViewAdapter adapter;
Expand Down Expand Up @@ -77,7 +81,7 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
return;
List<DataBean> displayList = adapter.getDisplayList();
if (stickyHeaderPositionStack.isEmpty())
stickyHeaderPositionStack.push(findFirstVisibleStickyHeaderPosition(adapter.displayList, 0));
stickyHeaderPositionStack.push(findFirstVisibleStickyHeaderPosition(displayList, 0));
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
int firstVisibleStickyHeaderPosition = findFirstVisibleStickyHeaderPosition(displayList, firstVisibleItemPosition);
int currentStickyHeaderPosition = stickyHeaderPositionStack.peek();
Expand All @@ -91,14 +95,14 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (firstVisibleStickyHeader == null)
return;
int headerTop = firstVisibleStickyHeader.getTop();
if (headerTop > 0 && headerTop <= mHeaderHeight) {
if (headerTop > 0 && headerTop <= mHeaderHeight) { //吸顶正在更替的状态
mHeaderContainer.setY(-(mHeaderHeight - headerTop));
if (firstVisibleStickyHeaderPosition == currentStickyHeaderPosition) {
stickyHeaderPositionStack.pop();
if (!stickyHeaderPositionStack.isEmpty())
updateHeaderView(stickyHeaderPositionStack.peek());
}
} else if (headerTop <= 0) {
} else if (headerTop <= 0) { //吸顶稳定在最上方的状态
mHeaderContainer.setY(0);
updateHeaderView(firstVisibleItemPosition);
}
Expand Down
@@ -1,4 +1,4 @@
package tellh.com.recyclerstickyheaderview;
package tellh.com.stickyheaderview_rv.adapter;

import android.support.v4.util.SparseArrayCompat;

Expand All @@ -13,7 +13,7 @@ public final IViewBinder provideViewBinder(StickyHeaderViewAdapter adapter, Spar
return viewBinder;
}

protected boolean shouldSticky() {
public boolean shouldSticky() {
return false;
}
}
@@ -1,4 +1,4 @@
package tellh.com.recyclerstickyheaderview;
package tellh.com.stickyheaderview_rv.adapter;

import android.view.View;

Expand Down
@@ -1,4 +1,4 @@
package tellh.com.recyclerstickyheaderview;
package tellh.com.stickyheaderview_rv.adapter;

import android.support.v4.util.SparseArrayCompat;

Expand Down
@@ -1,4 +1,4 @@
package tellh.com.recyclerstickyheaderview;
package tellh.com.stickyheaderview_rv.adapter;

public interface LayoutItemType {
int getItemLayoutId(StickyHeaderViewAdapter adapter);
Expand Down
@@ -1,4 +1,4 @@
package tellh.com.recyclerstickyheaderview;
package tellh.com.stickyheaderview_rv.adapter;

import android.support.annotation.LayoutRes;
import android.support.v4.util.SparseArrayCompat;
Expand Down
@@ -1,4 +1,4 @@
package tellh.com.recyclerstickyheaderview;
package tellh.com.stickyheaderview_rv.adapter;

import android.support.annotation.IdRes;
import android.support.v7.widget.RecyclerView;
Expand Down
3 changes: 3 additions & 0 deletions stickyheaderview-rv/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">StickyHeaderView-rv</string>
</resources>
@@ -0,0 +1,17 @@
package tellh.com.stickyheaderview_rv;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}

0 comments on commit d09b7b8

Please sign in to comment.