forked from lisawray/groupie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Create groupie-viewbinding module - Create example-viewbinding module - Update AGP and viewbinding version to 3.6.1 - Update README - Deprecate all classes in library-databinding
- Loading branch information
Showing
37 changed files
with
1,136 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,51 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
android { | ||
compileSdkVersion rootProject.sdkVersion | ||
|
||
defaultConfig { | ||
applicationId "com.xwray.groupie.example.viewbinding" | ||
minSdkVersion rootProject.minimumSdkVersion | ||
targetSdkVersion rootProject.sdkVersion | ||
versionCode 1 | ||
versionName "1.0" | ||
vectorDrawables.useSupportLibrary true | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
} | ||
} | ||
|
||
dataBinding { | ||
enabled = true | ||
} | ||
|
||
viewBinding { | ||
enabled = true | ||
} | ||
|
||
lintOptions { | ||
abortOnError false | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(':library-viewbinding') | ||
implementation project(':example-shared') | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation "androidx.core:core-ktx:1.2.0" | ||
implementation "androidx.appcompat:appcompat:1.1.0" | ||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0" | ||
implementation "com.google.android.material:material:1.1.0" | ||
implementation "androidx.cardview:cardview:1.0.0" | ||
implementation "androidx.vectordrawable:vectordrawable:1.1.0" | ||
implementation "androidx.vectordrawable:vectordrawable-animated:1.1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.xwray.groupie.example.viewbinding" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
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> |
63 changes: 63 additions & 0 deletions
63
example-viewbinding/src/main/java/com/xwray/groupie/example/viewbinding/CarouselGroup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,63 @@ | ||
package com.xwray.groupie.example.viewbinding | ||
|
||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver | ||
import androidx.recyclerview.widget.RecyclerView.ItemDecoration | ||
import com.xwray.groupie.Group | ||
import com.xwray.groupie.GroupAdapter | ||
import com.xwray.groupie.GroupDataObserver | ||
import com.xwray.groupie.GroupieViewHolder | ||
import com.xwray.groupie.Item | ||
import com.xwray.groupie.example.viewbinding.item.CarouselItem | ||
|
||
/** | ||
* A group that contains a single carousel item and is empty when the carousel is empty | ||
*/ | ||
class CarouselGroup( | ||
itemDecoration: ItemDecoration, | ||
adapter: GroupAdapter<GroupieViewHolder> | ||
) : Group { | ||
|
||
private var isEmpty = true | ||
private val adapter: RecyclerView.Adapter<*> | ||
private var groupDataObserver: GroupDataObserver? = null | ||
private val carouselItem: CarouselItem | ||
|
||
init { | ||
this.adapter = adapter | ||
carouselItem = CarouselItem(itemDecoration, adapter) | ||
isEmpty = adapter.itemCount == 0 | ||
adapter.registerAdapterDataObserver(object : AdapterDataObserver() { | ||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { | ||
val empty = adapter.itemCount == 0 | ||
if (empty && !isEmpty) { | ||
isEmpty = empty | ||
groupDataObserver?.onItemRemoved(carouselItem, 0) | ||
} | ||
} | ||
|
||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { | ||
val empty = adapter.itemCount == 0 | ||
if (isEmpty && !empty) { | ||
isEmpty = empty | ||
groupDataObserver?.onItemInserted(carouselItem, 0) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
override fun getItemCount(): Int = if (isEmpty) 0 else 1 | ||
|
||
override fun getItem(position: Int): Item<*> = | ||
if (position == 0 && !isEmpty) carouselItem else throw IndexOutOfBoundsException() | ||
|
||
override fun getPosition(item: Item<*>): Int = if (item === carouselItem && !isEmpty) 0 else -1 | ||
|
||
override fun registerGroupDataObserver(groupDataObserver: GroupDataObserver) { | ||
this.groupDataObserver = groupDataObserver | ||
} | ||
|
||
override fun unregisterGroupDataObserver(groupDataObserver: GroupDataObserver) { | ||
this.groupDataObserver = null | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
example-viewbinding/src/main/java/com/xwray/groupie/example/viewbinding/ColumnGroup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,44 @@ | ||
package com.xwray.groupie.example.viewbinding | ||
|
||
import com.xwray.groupie.Group | ||
import com.xwray.groupie.GroupDataObserver | ||
import com.xwray.groupie.Item | ||
import com.xwray.groupie.viewbinding.BindableItem | ||
import java.util.* | ||
|
||
/** | ||
* A simple, non-editable, non-nested group of Items which displays a list as vertical columns. | ||
*/ | ||
class ColumnGroup(items: List<BindableItem<*>>) : Group { | ||
|
||
private val items: ArrayList<BindableItem<*>> = ArrayList() | ||
|
||
init { | ||
for (i in items.indices) { | ||
// Rearrange items so that the adapter appears to arrange them in vertical columns | ||
val index = if (i % 2 == 0) { | ||
i / 2 | ||
} else { | ||
// If columns are uneven, we'll put an extra one at the end of the first column, | ||
// meaning the second column's indices will all be increased by 1 | ||
(i - 1) / 2 (items.size / 2f).toInt() if (items.size % 2 == 1) 1 else 0 | ||
} | ||
val trackItem = items[index] | ||
this.items.add(trackItem) | ||
} | ||
} | ||
|
||
override fun registerGroupDataObserver(groupDataObserver: GroupDataObserver) { | ||
// no real need to do anything here | ||
} | ||
|
||
override fun unregisterGroupDataObserver(groupDataObserver: GroupDataObserver) { | ||
// no real need to do anything here | ||
} | ||
|
||
override fun getItem(position: Int): BindableItem<*> = items[position] | ||
|
||
override fun getPosition(item: Item<*>): Int = items.indexOf(item) | ||
|
||
override fun getItemCount(): Int = items.size | ||
} |
40 changes: 40 additions & 0 deletions
40
...e-viewbinding/src/main/java/com/xwray/groupie/example/viewbinding/ExpandableHeaderItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,40 @@ | ||
package com.xwray.groupie.example.viewbinding | ||
|
||
import android.graphics.drawable.Animatable | ||
import android.view.View | ||
import androidx.annotation.StringRes | ||
import com.xwray.groupie.ExpandableGroup | ||
import com.xwray.groupie.ExpandableItem | ||
import com.xwray.groupie.example.viewbinding.databinding.ItemHeaderBinding | ||
import com.xwray.groupie.example.viewbinding.item.HeaderItem | ||
|
||
class ExpandableHeaderItem( | ||
@StringRes titleStringResId: Int, | ||
@StringRes subtitleResId: Int | ||
) : HeaderItem(titleStringResId, subtitleResId), ExpandableItem { | ||
|
||
private var expandableGroup: ExpandableGroup? = null | ||
|
||
override fun bind(viewBinding: ItemHeaderBinding, position: Int) { | ||
super.bind(viewBinding, position) | ||
|
||
// Initial icon state -- not animated. | ||
viewBinding.icon.visibility = View.VISIBLE | ||
viewBinding.icon.setImageResource(if (expandableGroup!!.isExpanded) R.drawable.collapse else R.drawable.expand) | ||
viewBinding.icon.setOnClickListener { | ||
expandableGroup!!.onToggleExpanded() | ||
bindIcon(viewBinding) | ||
} | ||
} | ||
|
||
private fun bindIcon(viewBinding: ItemHeaderBinding) { | ||
viewBinding.icon.visibility = View.VISIBLE | ||
viewBinding.icon.setImageResource(if (expandableGroup!!.isExpanded) R.drawable.collapse_animated else R.drawable.expand_animated) | ||
val drawable = viewBinding.icon.drawable as Animatable | ||
drawable.start() | ||
} | ||
|
||
override fun setExpandableGroup(onToggleListener: ExpandableGroup) { | ||
expandableGroup = onToggleListener | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...e-viewbinding/src/main/java/com/xwray/groupie/example/viewbinding/HeaderItemDecoration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,9 @@ | ||
package com.xwray.groupie.example.viewbinding | ||
|
||
import androidx.annotation.ColorInt | ||
import com.xwray.groupie.example.core.decoration.HeaderItemDecoration | ||
|
||
class HeaderItemDecoration( | ||
@ColorInt background: Int, | ||
sidePaddingPixels: Int | ||
) : HeaderItemDecoration(background, sidePaddingPixels, R.layout.item_header) |
10 changes: 10 additions & 0 deletions
10
...le-viewbinding/src/main/java/com/xwray/groupie/example/viewbinding/InsetItemDecoration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,10 @@ | ||
package com.xwray.groupie.example.viewbinding | ||
|
||
import androidx.annotation.ColorInt | ||
import androidx.annotation.Dimension | ||
import com.xwray.groupie.example.core.decoration.InsetItemDecoration | ||
|
||
class InsetItemDecoration( | ||
@ColorInt backgroundColor: Int, | ||
@Dimension padding: Int | ||
) : InsetItemDecoration(backgroundColor, padding, INSET_TYPE_KEY, INSET) |
Oops, something went wrong.