Skip to content

Commit

Permalink
支持AndroidX对应版本
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed Jul 8, 2019
1 parent 988a389 commit 29c02c3
Show file tree
Hide file tree
Showing 37 changed files with 189 additions and 151 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
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.

35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ Base是针对于Android开发封装好一些常用的基类,主要包括通用
```
### Gradle:
```gradle
//---------- AndroidX 版本
//base
implementation 'com.king.base:base:3.2.1-androidx'
//base-adapter
implementation 'com.king.base:adapter:3.2.1-androidx'
//base-util
implementation 'com.king.base:util:3.2.1-androidx'
//---------- Android 版本
//base
implementation 'com.king.base:base:3.2.1'
Expand All @@ -65,6 +76,8 @@ implementation 'com.king.base:adapter:3.2.1'
//base-util
implementation 'com.king.base:util:3.2.1'
```
### Lvy:
```lvy
Expand Down Expand Up @@ -96,20 +109,33 @@ allprojects {

### 引入的库:
```gradle
//---------- AndroidX 版本
//base
compileOnly 'com.android.support:appcompat-v7:28.0.0'
compileOnly 'com.king.base:util:3.2.1'
compileOnly 'androidx.appcompat:appcompat:1.0.0+'
compileOnly 'com.king.base:util:3.2.1-androidx'
//base-adapter
compileOnly 'androidx.appcompat:appcompat:1.0.0+'
compileOnly 'androidx.recyclerview:recyclerview:1.0.0+'
//base-util
compileOnly 'androidx.appcompat:appcompat:1.0.0+'
```

```gradle
//---------- Android 版本
//base
compileOnly 'com.android.support:appcompat-v7:28.0.0'
compileOnly 'com.king.base:util:3.2.1'
//base-adapter
compileOnly 'com.android.support:appcompat-v7:28.0.0'
compileOnly 'com.android.support:recyclerview-v7:28.0.0'
```
```gradle
//base-util
compileOnly 'com.android.support:appcompat-v7:28.0.0'
```


Expand Down Expand Up @@ -322,6 +348,7 @@ public class TestDialogFragment extends BaseDialogFragment {

#### v3.2.1:2019-7-1
* 优化部分细节,为迁移AndroidX版本做准备
* 支持AndroidX对应版本

#### v3.2.0:2019-5-28
* 统一版本,方便维护
Expand Down
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
targetSdkVersion build_versions.targetSdk
versionCode app_version.versionCode
versionName app_version.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}
buildTypes {
Expand All @@ -34,7 +34,6 @@ dependencies {
implementation deps.support.appcompat
implementation deps.support.recyclerview
implementation deps.support.constraintlayout
implementation deps.superswiperefreshlayout

implementation project(':base')
implementation project(':base-adapter')
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":11,"versionName":"3.2.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":12,"versionName":"3.2.1-androidx","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.king.base.app;

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 androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import static org.junit.Assert.*;

/**
Expand Down
22 changes: 8 additions & 14 deletions app/src/main/java/com/king/base/app/fragment/ListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.king.base.BaseFragment;
import com.king.base.adapter.HolderRecyclerAdapter;
import com.king.base.app.R;
import com.king.base.app.adapter.ListAdapter;
import com.king.view.superswiperefreshlayout.SuperSwipeRefreshLayout;

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

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

/**
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/

public class ListFragment extends BaseFragment{

private SuperSwipeRefreshLayout ssrl;
private SwipeRefreshLayout srl;

private ListView listView;

Expand All @@ -43,23 +42,18 @@ public static ListFragment newInstance() {

@Override
public void initUI() {
ssrl = findViewById(R.id.ssrl);
srl = findViewById(R.id.srl);
listView = findViewById(R.id.listView);

initListData();
adapter = new ListAdapter(getContext(),listData);

listView.setAdapter(adapter);

ssrl.setOnRefreshListener(new SuperSwipeRefreshLayout.OnRefreshListener() {
srl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh(SuperSwipeRefreshLayout.Direction direction) {
if(direction == SuperSwipeRefreshLayout.Direction.TOP){
pullRefresh();
}else{
loadMoreRefresh();

}
public void onRefresh() {
pullRefresh();
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
Expand Down Expand Up @@ -88,7 +82,7 @@ private void initListData(){

private void refreshView(){
adapter.notifyDataSetChanged();
ssrl.setRefreshing(false);
srl.setRefreshing(false);
}

private void pullRefresh(){
Expand Down
29 changes: 13 additions & 16 deletions app/src/main/java/com/king/base/app/fragment/RecyclerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.king.base.BaseFragment;
import com.king.base.adapter.HolderRecyclerAdapter;
import com.king.base.adapter.divider.DividerItemDecoration;
import com.king.base.app.R;
import com.king.base.app.adapter.RecyclerViewAdapter;
import com.king.view.superswiperefreshlayout.SuperSwipeRefreshLayout;

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

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

/**
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/

public class RecyclerFragment extends BaseFragment {

private SuperSwipeRefreshLayout ssrl;
private SwipeRefreshLayout srl;

private RecyclerView recyclerView;

Expand All @@ -43,27 +44,23 @@ public static RecyclerFragment newInstance() {

@Override
public void initUI() {
ssrl = findViewById(R.id.ssrl);
srl = findViewById(R.id.srl);
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));

initListData();
adapter = new RecyclerViewAdapter(getContext(),listData);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL,false));
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);

ssrl.setOnRefreshListener(new SuperSwipeRefreshLayout.OnRefreshListener() {
srl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh(SuperSwipeRefreshLayout.Direction direction) {
if(direction == SuperSwipeRefreshLayout.Direction.TOP){
pullRefresh();
}else{
loadMoreRefresh();

}
public void onRefresh() {
pullRefresh();
}
});

adapter.setOnItemClickListener(new HolderRecyclerAdapter.OnItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Expand Down Expand Up @@ -91,7 +88,7 @@ private void initListData(){

private void refreshView(){
adapter.notifyDataSetChanged();
ssrl.setRefreshing(false);
srl.setRefreshing(false);
}

private void pullRefresh(){
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
Expand All @@ -15,6 +15,7 @@
android:textSize="20sp"
android:text="Base"
android:background="@color/colorPrimary"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.0"
Expand Down Expand Up @@ -57,4 +58,4 @@
</LinearLayout>


</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
9 changes: 4 additions & 5 deletions app/src/main/res/layout/fragment_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
android:textSize="20sp"
android:text="ListView"
android:background="@color/colorPrimary"/>
<com.king.view.superswiperefreshlayout.SuperSwipeRefreshLayout
android:id="@+id/ssrl"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/srl"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:direction="both">
android:layout_height="match_parent">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.king.view.superswiperefreshlayout.SuperSwipeRefreshLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
11 changes: 5 additions & 6 deletions app/src/main/res/layout/fragment_recycler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
android:textSize="20sp"
android:text="RecyclerView"
android:background="@color/colorPrimary"/>
<com.king.view.superswiperefreshlayout.SuperSwipeRefreshLayout
android:id="@+id/ssrl"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/srl"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:direction="both">
<android.support.v7.widget.RecyclerView
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.king.view.superswiperefreshlayout.SuperSwipeRefreshLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
2 changes: 1 addition & 1 deletion base-adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
versionCode app_version.versionCode
versionName app_version.baseAdapter

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

}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.king.base.adapter;

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 androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import static org.junit.Assert.*;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import java.util.List;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import androidx.annotation.LayoutRes;

/**
* 抽象适配器(实现部分父类方法、免去一些通用的代码)
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
Expand Down Expand Up @@ -79,7 +80,7 @@ public LayoutInflater getLayoutInflater(){
return layoutInflater;
}

public View inflate(@LayoutRes int layoutId,ViewGroup parent,boolean attachToRoot){
public View inflate(@LayoutRes int layoutId, ViewGroup parent, boolean attachToRoot){
return layoutInflater.inflate(layoutId,parent,attachToRoot);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.king.base.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -14,6 +13,8 @@
import java.lang.reflect.Type;
import java.util.List;

import androidx.annotation.LayoutRes;

/**
* ListView通用适配器
* 在HolderRecyclerAdapter基础之上将H:ViewHolder实例化,通过ViewHolder子类根据控件的id得到对应控件,来进行相关的数据绑定操作
Expand Down
Loading

0 comments on commit 29c02c3

Please sign in to comment.