diff --git a/app/build.gradle b/app/build.gradle
index f3c0948..502193e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -3,14 +3,14 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
- compileSdkVersion 28
+ compileSdkVersion 29
defaultConfig {
applicationId "com.zeropercenthappy.zphrvitemdecoration"
minSdkVersion 16
- targetSdkVersion 28
+ targetSdkVersion 29
versionCode 1
versionName "1.0"
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+ testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
@@ -23,11 +23,8 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
- implementation "com.android.support:appcompat-v7:$android_support_version"
- implementation "com.android.support:support-v4:$android_support_version"
- implementation "com.android.support:design:$android_support_version"
- implementation "com.android.support:cardview-v7:$android_support_version"
- implementation "com.android.support.constraint:constraint-layout:1.1.3"
+ implementation 'com.google.android.material:material:1.2.1'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
diff --git a/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/GridRVAdapter.java b/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/GridRVAdapter.java
index 58644cf..1daf6d5 100644
--- a/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/GridRVAdapter.java
+++ b/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/GridRVAdapter.java
@@ -1,6 +1,6 @@
package com.zeropercenthappy.zphrvitemdecoration;
-import android.support.v7.widget.RecyclerView;
+import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
diff --git a/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/LinearRVAdapter.java b/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/LinearRVAdapter.java
index cbaecbc..962daad 100644
--- a/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/LinearRVAdapter.java
+++ b/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/LinearRVAdapter.java
@@ -1,6 +1,6 @@
package com.zeropercenthappy.zphrvitemdecoration;
-import android.support.v7.widget.RecyclerView;
+import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
diff --git a/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/MainActivity.java b/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/MainActivity.java
index 0f30ddc..231b676 100644
--- a/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/MainActivity.java
+++ b/app/src/main/java/com/zeropercenthappy/zphrvitemdecoration/MainActivity.java
@@ -2,10 +2,10 @@
import android.graphics.Color;
import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.GridLayoutManager;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 2e49a3e..8c858ea 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,5 +1,5 @@
-
-
-
+
diff --git a/app/src/main/res/layout/item_rv_grid.xml b/app/src/main/res/layout/item_rv_grid.xml
index 18c972a..ff275f7 100644
--- a/app/src/main/res/layout/item_rv_grid.xml
+++ b/app/src/main/res/layout/item_rv_grid.xml
@@ -1,5 +1,5 @@
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/item_rv_linear.xml b/app/src/main/res/layout/item_rv_linear.xml
index 38c4264..f0d2506 100644
--- a/app/src/main/res/layout/item_rv_linear.xml
+++ b/app/src/main/res/layout/item_rv_linear.xml
@@ -1,5 +1,5 @@
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 8953599..5f5ce10 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,14 +2,14 @@
buildscript {
ext.android_support_version = '28.0.0'
- ext.kotlin_version = '1.3.61'
+ ext.kotlin_version = '1.5.21'
ext.anko_version = '0.10.8'
repositories {
google()
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.6.0'
+ classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
diff --git a/gradle.properties b/gradle.properties
index aac7c9b..9e6fce1 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -9,6 +9,8 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
+android.enableJetifier=true
+android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 4363ee3..7e9eb56 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
diff --git a/library/build.gradle b/library/build.gradle
index db7d86b..80a9ba6 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -5,15 +5,15 @@ apply plugin: 'kotlin-android-extensions'
group = 'com.github.zeropercenthappy'
android {
- compileSdkVersion 28
+ compileSdkVersion 29
defaultConfig {
minSdkVersion 14
- targetSdkVersion 28
- versionCode 109
- versionName "1.0.9"
+ targetSdkVersion 29
+ versionCode 110
+ versionName "1.1.0"
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+ testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
@@ -29,18 +29,13 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
- implementation "com.android.support:appcompat-v7:$android_support_version"
- implementation "com.android.support:support-v4:$android_support_version"
- implementation "com.android.support:design:$android_support_version"
- implementation "com.android.support:cardview-v7:$android_support_version"
- implementation "com.android.support.constraint:constraint-layout:1.1.3"
-
+ implementation 'com.google.android.material:material:1.2.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
- classifier = 'sources'
+ getArchiveClassifier().set("sources")
}
artifacts {
diff --git a/library/src/main/java/com/zeropercenthappy/divider/GridLayoutManagerDivider.kt b/library/src/main/java/com/zeropercenthappy/divider/GridLayoutManagerDivider.kt
index 3e5eff1..ebe4c53 100644
--- a/library/src/main/java/com/zeropercenthappy/divider/GridLayoutManagerDivider.kt
+++ b/library/src/main/java/com/zeropercenthappy/divider/GridLayoutManagerDivider.kt
@@ -3,11 +3,10 @@ package com.zeropercenthappy.divider
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
-import android.support.annotation.ColorInt
-import android.support.v7.widget.GridLayoutManager
-import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
+import androidx.annotation.ColorInt
+import androidx.recyclerview.widget.RecyclerView
import kotlin.math.roundToInt
class GridLayoutManagerDivider(
@@ -144,9 +143,14 @@ class GridLayoutManagerDivider(
}
}
- override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
+ override fun getItemOffsets(
+ outRect: Rect,
+ view: View,
+ parent: RecyclerView,
+ state: RecyclerView.State
+ ) {
val layoutManager = parent.layoutManager
- require(layoutManager is GridLayoutManager && layoutManager.orientation == GridLayoutManager.VERTICAL) {
+ require(layoutManager is androidx.recyclerview.widget.GridLayoutManager && layoutManager.orientation == androidx.recyclerview.widget.GridLayoutManager.VERTICAL) {
"GridLayoutManagerDivider can only use with vertical GridLayoutManager"
}
// HeaderView和FooterView不设置偏移量
@@ -223,7 +227,8 @@ class GridLayoutManagerDivider(
} else {
// 中间列
val atColumn = atColumn(position, spanCount)
- leftOffset = ((spanCount + 1f - atColumn) / spanCount * verticalDividerWidth).roundToInt()
+ leftOffset =
+ ((spanCount + 1f - atColumn) / spanCount * verticalDividerWidth).roundToInt()
rightOffset = (atColumn.toFloat() / spanCount * verticalDividerWidth).roundToInt()
}
// 计算完毕
@@ -260,7 +265,8 @@ class GridLayoutManagerDivider(
// 中间行
val atRow = atRow(position, spanCount)
topOffset = ((atRow - 1f) / rowCount * horizontalDividerHeight).roundToInt()
- bottomOffset = (((rowCount - 1f) - (atRow - 1f)) / rowCount * horizontalDividerHeight).roundToInt()
+ bottomOffset =
+ (((rowCount - 1f) - (atRow - 1f)) / rowCount * horizontalDividerHeight).roundToInt()
}
// 左右偏移量
if (isFirstColumn(position, spanCount) && isLastColumn(position, spanCount, total)) {
@@ -279,7 +285,8 @@ class GridLayoutManagerDivider(
// 中间列
val atColumn = atColumn(position, spanCount)
leftOffset = ((atColumn - 1f) / spanCount * verticalDividerWidth).roundToInt()
- rightOffset = (((spanCount - 1f) - (atColumn - 1f)) / spanCount * verticalDividerWidth).roundToInt()
+ rightOffset =
+ (((spanCount - 1f) - (atColumn - 1f)) / spanCount * verticalDividerWidth).roundToInt()
}
// 计算完毕
@@ -369,7 +376,12 @@ class GridLayoutManagerDivider(
* 在真实表格中,判断position(从1开始)是否在最后一列
* @param isCountLastItem 是否将最后一个item不是最后一列来当作最后一列处理
*/
- private fun isLastColumn(position: Int, spanCount: Int, total: Int, isCountLastItem: Boolean = false): Boolean {
+ private fun isLastColumn(
+ position: Int,
+ spanCount: Int,
+ total: Int,
+ isCountLastItem: Boolean = false
+ ): Boolean {
return when {
spanCount == 1 -> {
// 只有一列
@@ -410,7 +422,7 @@ class GridLayoutManagerDivider(
private fun getSpanCount(parent: RecyclerView): Int {
val spanCount: Int
val layoutManager = parent.layoutManager
- spanCount = (layoutManager as GridLayoutManager).spanCount
+ spanCount = (layoutManager as androidx.recyclerview.widget.GridLayoutManager).spanCount
return spanCount
}
diff --git a/library/src/main/java/com/zeropercenthappy/divider/LinearLayoutManagerDivider.kt b/library/src/main/java/com/zeropercenthappy/divider/LinearLayoutManagerDivider.kt
index b4f2b5e..5650f89 100644
--- a/library/src/main/java/com/zeropercenthappy/divider/LinearLayoutManagerDivider.kt
+++ b/library/src/main/java/com/zeropercenthappy/divider/LinearLayoutManagerDivider.kt
@@ -3,11 +3,10 @@ package com.zeropercenthappy.divider
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
-import android.support.annotation.ColorInt
-import android.support.v7.widget.LinearLayoutManager
-import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
+import androidx.annotation.ColorInt
+import androidx.recyclerview.widget.RecyclerView
import kotlin.math.roundToInt
class LinearLayoutManagerDivider(
@@ -27,7 +26,7 @@ class LinearLayoutManagerDivider(
private val headerViewList = arrayListOf()
private val footerViewList = arrayListOf()
private var fullWrap = true
- private var orientation: Int = LinearLayoutManager.VERTICAL
+ private var orientation: Int = androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
init {
paint.isAntiAlias = true
@@ -35,7 +34,11 @@ class LinearLayoutManagerDivider(
paint.color = dividerColor
}
- override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
+ override fun onDraw(
+ canvas: Canvas,
+ parent: RecyclerView,
+ state: RecyclerView.State
+ ) {
if (fullWrap) {
drawFullWrap(canvas, parent)
} else {
@@ -55,7 +58,7 @@ class LinearLayoutManagerDivider(
continue
}
// 绘制分割线
- if (orientation == LinearLayoutManager.VERTICAL) {
+ if (orientation == androidx.recyclerview.widget.LinearLayoutManager.VERTICAL) {
// 上边
canvas.drawRect(
childView.left.toFloat(),
@@ -95,7 +98,11 @@ class LinearLayoutManagerDivider(
/**
* 根据item的偏移量绘制分割线
*/
- private fun drawNotFullWrap(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
+ private fun drawNotFullWrap(
+ canvas: Canvas,
+ parent: RecyclerView,
+ state: RecyclerView.State
+ ) {
for (i in 0 until parent.childCount) {
val childView = parent.getChildAt(i)
// HeaderView和FooterView不处理
@@ -105,10 +112,11 @@ class LinearLayoutManagerDivider(
// 排除HeaderView和FooterView后,计算真实列表中的ChildView数量
val realItemCount = state.itemCount - headerViewList.size - footerViewList.size
// 找到当前ChildView在真实列表中的position(从1数起)
- val positionInLinear = parent.getChildLayoutPosition(childView) + 1 - headerViewList.size
+ val positionInLinear =
+ parent.getChildLayoutPosition(childView) + 1 - headerViewList.size
// 根据偏移量绘制分割线
val offsetRect = getNotFullWrapOffsets(positionInLinear, realItemCount)
- if (orientation == LinearLayoutManager.VERTICAL) {
+ if (orientation == androidx.recyclerview.widget.LinearLayoutManager.VERTICAL) {
// 上边
canvas.drawRect(
childView.left.toFloat(),
@@ -146,9 +154,14 @@ class LinearLayoutManagerDivider(
}
}
- override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
+ override fun getItemOffsets(
+ outRect: Rect,
+ view: View,
+ parent: RecyclerView,
+ state: RecyclerView.State
+ ) {
val layoutManager = parent.layoutManager
- require(layoutManager is LinearLayoutManager) {
+ require(layoutManager is androidx.recyclerview.widget.LinearLayoutManager) {
"LinearLayoutManagerDivider can only use with LinearLayoutManager"
}
orientation = layoutManager.orientation
@@ -190,7 +203,7 @@ class LinearLayoutManagerDivider(
var bottomOffset = 0
// 上下偏移量
if (total == 1) {
- if (orientation == LinearLayoutManager.VERTICAL) {
+ if (orientation == androidx.recyclerview.widget.LinearLayoutManager.VERTICAL) {
// 同时是第一行和最后一行,即只有一行
topOffset = dividerWidth
bottomOffset = dividerWidth
@@ -200,7 +213,7 @@ class LinearLayoutManagerDivider(
rightOffset = dividerWidth
}
} else if (position == 1) {
- if (orientation == LinearLayoutManager.VERTICAL) {
+ if (orientation == androidx.recyclerview.widget.LinearLayoutManager.VERTICAL) {
// 第一行
topOffset = dividerWidth
bottomOffset = (1f / total * dividerWidth).roundToInt()
@@ -211,7 +224,7 @@ class LinearLayoutManagerDivider(
}
} else if (position == total) {
- if (orientation == LinearLayoutManager.VERTICAL) {
+ if (orientation == androidx.recyclerview.widget.LinearLayoutManager.VERTICAL) {
// 最后一行
topOffset = (1f / total * dividerWidth).roundToInt()
bottomOffset = dividerWidth
@@ -221,7 +234,7 @@ class LinearLayoutManagerDivider(
rightOffset = dividerWidth
}
} else {
- if (orientation == LinearLayoutManager.VERTICAL) {
+ if (orientation == androidx.recyclerview.widget.LinearLayoutManager.VERTICAL) {
// 中间行
topOffset = ((total + 1f - position) / total * dividerWidth).roundToInt()
bottomOffset = (position.toFloat() / total * dividerWidth).roundToInt()
@@ -245,7 +258,7 @@ class LinearLayoutManagerDivider(
var topOffset = 0
var rightOffset = 0
var bottomOffset = 0
- if (orientation == LinearLayoutManager.VERTICAL) {
+ if (orientation == androidx.recyclerview.widget.LinearLayoutManager.VERTICAL) {
// 上下偏移量
when {
total == 1 -> {
@@ -266,7 +279,8 @@ class LinearLayoutManagerDivider(
else -> {
// 中间行
topOffset = ((position - 1f) / total * dividerWidth).roundToInt()
- bottomOffset = (((total - 1f) - (position - 1f)) / total * dividerWidth).roundToInt()
+ bottomOffset =
+ (((total - 1f) - (position - 1f)) / total * dividerWidth).roundToInt()
}
}
} else {
@@ -290,7 +304,8 @@ class LinearLayoutManagerDivider(
else -> {
// 中间列
leftOffset = ((position - 1f) / total * dividerWidth).roundToInt()
- rightOffset = (((total - 1f) - (position - 1f)) / total * dividerWidth).roundToInt()
+ rightOffset =
+ (((total - 1f) - (position - 1f)) / total * dividerWidth).roundToInt()
}
}
}