-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Vanilla groupie is now in module library (com.xwray.groupie) and groupie with databinding is now in module library-databinding (com.xwray.groupie.databinding). Items that use data binding should now extend BindableItem. A fun side effect of this rewrite is that you can mix and match regular Items and BindableItems (maybe in case you want to do a gradual rewrite of an existing RecyclerView?)
- Loading branch information
Showing
131 changed files
with
1,865 additions
and
506 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
File renamed without changes.
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,36 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion '25.0.2' | ||
defaultConfig { | ||
applicationId "com.xwray.groupie.example.databinding" | ||
minSdkVersion 17 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
vectorDrawables.useSupportLibrary true | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
} | ||
} | ||
dataBinding { | ||
enabled = true | ||
} | ||
|
||
lintOptions { | ||
abortOnError false | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(':library-databinding') | ||
compile project(':example-shared') | ||
compile 'com.android.support:appcompat-v7:25.3.1' | ||
compile 'com.android.support:design:25.3.1' | ||
compile 'com.android.support:cardview-v7:25.3.1' | ||
compile 'com.android.support:support-vector-drawable:25.3.1' | ||
compile 'com.android.support:animated-vector-drawable:25.3.1' | ||
} |
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.databinding" | ||
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> |
51 changes: 51 additions & 0 deletions
51
example-databinding/src/main/java/com/xwray/groupie/example/databinding/ColumnGroup.java
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 @@ | ||
package com.xwray.groupie.example.databinding; | ||
|
||
import com.xwray.groupie.Group; | ||
import com.xwray.groupie.GroupDataObserver; | ||
import com.xwray.groupie.Item; | ||
import com.xwray.groupie.databinding.BindableItem; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A simple, non-editable, non-nested group of Items which displays a list as vertical columns. | ||
*/ | ||
public class ColumnGroup implements Group { | ||
|
||
private List<BindableItem> items = new ArrayList<>(); | ||
|
||
public ColumnGroup(List<? extends BindableItem> items) { | ||
for (int i = 0; i < items.size(); i++) { | ||
// Rearrange items so that the adapter appears to arrange them in vertical columns | ||
int index; | ||
if (i % 2 == 0) { | ||
index = i / 2; | ||
} else { | ||
index = (i - 1) / 2 + (int) (items.size() / 2f); | ||
// 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 | ||
if (items.size() % 2 == 1) index++; | ||
} | ||
BindableItem trackItem = items.get(index); | ||
this.items.add(trackItem); | ||
} | ||
} | ||
|
||
public void setGroupDataObserver(GroupDataObserver groupDataObserver) { | ||
// no real need to do anything here | ||
} | ||
|
||
public BindableItem getItem(int position) { | ||
return items.get(position); | ||
} | ||
|
||
@Override | ||
public int getPosition(Item item) { | ||
return items.indexOf(item); | ||
} | ||
|
||
@Override public int getItemCount() { | ||
return items.size(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...databinding/src/main/java/com/xwray/groupie/example/databinding/ExpandableHeaderItem.java
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.databinding; | ||
|
||
import android.graphics.drawable.Animatable; | ||
import android.support.annotation.StringRes; | ||
import android.view.View; | ||
|
||
import com.xwray.groupie.ExpandableGroup; | ||
import com.xwray.groupie.ExpandableItem; | ||
import com.xwray.groupie.example.databinding.databinding.ItemHeaderBinding; | ||
import com.xwray.groupie.example.databinding.item.HeaderItem; | ||
|
||
public class ExpandableHeaderItem extends HeaderItem implements ExpandableItem { | ||
|
||
private ExpandableGroup expandableGroup; | ||
|
||
public ExpandableHeaderItem(@StringRes int titleStringResId, @StringRes int subtitleResId) { | ||
super(titleStringResId, subtitleResId); | ||
} | ||
|
||
@Override public void bind(final ItemHeaderBinding viewBinding, int position) { | ||
super.bind(viewBinding, position); | ||
|
||
// Initial icon state -- not animated. | ||
viewBinding.icon.setVisibility(View.VISIBLE); | ||
viewBinding.icon.setImageResource(expandableGroup.isExpanded() ? R.drawable.collapse : R.drawable.expand); | ||
viewBinding.icon.setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View view) { | ||
expandableGroup.onToggleExpanded(); | ||
bindIcon(viewBinding); | ||
} | ||
}); | ||
} | ||
|
||
private void bindIcon(ItemHeaderBinding viewBinding) { | ||
viewBinding.icon.setVisibility(View.VISIBLE); | ||
viewBinding.icon.setImageResource(expandableGroup.isExpanded() ? R.drawable.collapse_animated : R.drawable.expand_animated); | ||
Animatable drawable = (Animatable) viewBinding.icon.getDrawable(); | ||
drawable.start(); | ||
} | ||
|
||
@Override public void setExpandableGroup(ExpandableGroup onToggleListener) { | ||
this.expandableGroup = onToggleListener; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...databinding/src/main/java/com/xwray/groupie/example/databinding/HeaderItemDecoration.java
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.databinding; | ||
|
||
import android.support.annotation.ColorInt; | ||
import android.support.annotation.LayoutRes; | ||
|
||
public class HeaderItemDecoration extends com.xwray.groupie.example.core.decoration.HeaderItemDecoration { | ||
public HeaderItemDecoration(@ColorInt int background, int sidePaddingPixels) { | ||
super(background, sidePaddingPixels, R.layout.item_header); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...-databinding/src/main/java/com/xwray/groupie/example/databinding/InsetItemDecoration.java
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.databinding; | ||
|
||
import android.support.annotation.ColorInt; | ||
import android.support.annotation.Dimension; | ||
|
||
public class InsetItemDecoration extends com.xwray.groupie.example.core.decoration.InsetItemDecoration { | ||
public InsetItemDecoration(@ColorInt int backgroundColor, @Dimension int padding) { | ||
super(backgroundColor, padding, MainActivity.INSET_TYPE_KEY, MainActivity.INSET); | ||
} | ||
} |
Oops, something went wrong.