Skip to content

Commit

Permalink
Migrate to AndroidX;
Browse files Browse the repository at this point in the history
Release 1.1.0;
  • Loading branch information
zeropercenthappy committed Jul 17, 2021
1 parent 32d5b79 commit 2b326a9
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 64 deletions.
13 changes: 5 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 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 Down Expand Up @@ -60,7 +60,7 @@
app:layout_constraintStart_toEndOf="@id/btn_minus"
app:layout_constraintTop_toBottomOf="@id/btn_grid_full_wrap" />

<android.support.v7.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="0dp"
android:layout_height="0dp"
Expand All @@ -69,4 +69,4 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_add" />
</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/item_rv_grid.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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -13,4 +13,4 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/item_rv_linear.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"
android:layout_width="match_parent"
android:layout_height="50dp"
Expand All @@ -14,4 +14,4 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 7 additions & 12 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

}

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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不设置偏移量
Expand Down Expand Up @@ -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()
}
// 计算完毕
Expand Down Expand Up @@ -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)) {
Expand All @@ -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()
}

// 计算完毕
Expand Down Expand Up @@ -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 -> {
// 只有一列
Expand Down Expand Up @@ -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
}

Expand Down
Loading

0 comments on commit 2b326a9

Please sign in to comment.