Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
陈鹏飞 committed Jan 16, 2018
0 parents commit a3ba9b9
Show file tree
Hide file tree
Showing 52 changed files with 1,491 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
20 changes: 20 additions & 0 deletions .idea/gradle.xml

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

33 changes: 33 additions & 0 deletions .idea/misc.xml

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

10 changes: 10 additions & 0 deletions .idea/modules.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.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/.gitignore
@@ -0,0 +1 @@
/build
30 changes: 30 additions & 0 deletions app/build.gradle
@@ -0,0 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "me.free.example"
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 project(':library')
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
@@ -0,0 +1,26 @@
package me.free.example;

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.*;

/**
* Instrumented 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("me.free.example", appContext.getPackageName());
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.free.example">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
70 changes: 70 additions & 0 deletions app/src/main/java/me/free/example/MainActivity.java
@@ -0,0 +1,70 @@
package me.free.example;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import me.free.sticky.StickyItemDecoration;

public class MainActivity extends AppCompatActivity {

RecyclerView recyclerView;

List<Test> testList = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TestAdapter testAdapter = new TestAdapter(this);
recyclerView = (RecyclerView) findViewById(R.id.rv);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new StickyItemDecoration());
recyclerView.setAdapter(testAdapter);

Test test = new Test();
test.content = "测试数据我测试One";
test.viewType = 11;
testList.add(test);

addTestContent();

Test testTwo = new Test();
testTwo.content = "测试Two";
testTwo.viewType = 11;
testList.add(testTwo);

addTestContent();

Test testThree = new Test();
testThree.content = "测试Three";
testThree.viewType = 11;
testList.add(testThree);

addTestContent();

Test testFour = new Test();
testFour.content = "测试Four";
testFour.viewType = 11;
testList.add(testFour);

addTestContent();

testAdapter.testList = testList;
testAdapter.notifyDataSetChanged();
}

private void addTestContent() {
for (int i = 0; i < 10; i++) {
Test test = new Test();
test.content = "测试内容:"+i;
test.viewType = 10;
testList.add(test);
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/me/free/example/Test.java
@@ -0,0 +1,12 @@
package me.free.example;

/**
* Created by lenovo on 2018/1/16.
*/

public class Test {

public String content;

public int viewType;
}
87 changes: 87 additions & 0 deletions app/src/main/java/me/free/example/TestAdapter.java
@@ -0,0 +1,87 @@
package me.free.example;

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

import java.util.ArrayList;
import java.util.List;

/**
* Created by cpf on 2018/1/16.
*/

public class TestAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

public Context context;

public List<Test> testList = new ArrayList<>();

public TestAdapter(Context context) {
this.context = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == 10) {
return new TestOneVH(LayoutInflater.from(context).inflate(R.layout.adapter_test_one, parent, false));
}
return new TestTwoVH(LayoutInflater.from(context).inflate(R.layout.adapter_test_two, parent, false));
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
Test test = testList.get(position);
if (holder instanceof TestOneVH) {
((TestOneVH) holder).bindData(test);
}
if (holder instanceof TestTwoVH) {
((TestTwoVH) holder).bindData(test);
}
}

@Override
public int getItemCount() {
return testList.size();
}

@Override
public int getItemViewType(int position) {
return testList.get(position).viewType;
}


static class TestTwoVH extends RecyclerView.ViewHolder {

TextView mTv;

public TestTwoVH(View itemView) {
super(itemView);
mTv = (TextView) itemView.findViewById(R.id.text);
itemView.setTag(true);
}

public void bindData(Test test) {
mTv.setText(test.content);
}

}

static class TestOneVH extends RecyclerView.ViewHolder {

TextView mTv;

public TestOneVH(View itemView) {
super(itemView);
mTv = (TextView) itemView.findViewById(R.id.text);
itemView.setTag(false);
}

public void bindData(Test test) {
mTv.setText(test.content);
}

}
}

0 comments on commit a3ba9b9

Please sign in to comment.