Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lisa Wray
committed
Sep 20, 2016
0 parents
commit 4c709d6
Showing
83 changed files
with
3,256 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
.idea/* | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
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,23 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.2.0-rc2' | ||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
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,31 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.1" | ||
defaultConfig { | ||
applicationId "com.genius.groupie.example" | ||
minSdkVersion 17 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
vectorDrawables.useSupportLibrary true | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
dataBinding { | ||
enabled = true | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(":groupie") | ||
compile 'com.android.support:appcompat-v7:24.2.1' | ||
compile 'com.android.support:design:24.2.1' | ||
compile 'com.android.support:cardview-v7:24.2.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,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/lisawray/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
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,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.genius.groupie.example" | ||
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> | ||
<activity | ||
android:name=".SettingsActivity" | ||
android:label="@string/title_activity_settings" | ||
android:theme="@style/SettingsTheme"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
48 changes: 48 additions & 0 deletions
48
example/src/main/java/com/genius/groupie/example/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,48 @@ | ||
package com.genius.groupie.example; | ||
|
||
import com.genius.groupie.Group; | ||
import com.genius.groupie.Item; | ||
|
||
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<Item> items = new ArrayList<>(); | ||
|
||
public ColumnGroup(List<? extends Item> 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++; | ||
} | ||
Item trackItem = items.get(index); | ||
this.items.add(trackItem); | ||
} | ||
} | ||
|
||
public void setGroupDataObserver(GroupDataObserver groupDataObserver) { | ||
// no real need to do anything here | ||
} | ||
|
||
public Item getItem(int position) { | ||
return items.get(position); | ||
} | ||
|
||
public int getPosition(Item item) { | ||
return items.indexOf(item); | ||
} | ||
|
||
@Override public int getItemCount() { | ||
return items.size(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
example/src/main/java/com/genius/groupie/example/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,39 @@ | ||
package com.genius.groupie.example; | ||
|
||
import android.support.annotation.StringRes; | ||
import android.view.View; | ||
|
||
import com.genius.groupie.ExpandableGroup; | ||
import com.genius.groupie.ExpandableItem; | ||
import com.genius.groupie.example.databinding.ItemHeaderBinding; | ||
import com.genius.groupie.example.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); | ||
bindIcon(viewBinding); | ||
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 : R.drawable.expand); | ||
} | ||
|
||
@Override public void setExpandableGroup(ExpandableGroup onToggleListener) { | ||
this.expandableGroup = onToggleListener; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
example/src/main/java/com/genius/groupie/example/InfiniteScrollListener.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,47 @@ | ||
package com.genius.groupie.example; | ||
|
||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
public abstract class InfiniteScrollListener extends RecyclerView.OnScrollListener { | ||
|
||
private int previousTotal = 0; // The total number of items in the dataset after the last load | ||
private boolean loading = true; // True if we are still waiting for the last set of data to load. | ||
private final int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more. | ||
private int firstVisibleItem, visibleItemCount, totalItemCount; | ||
private int current_page = 0; | ||
private LinearLayoutManager linearLayoutManager; | ||
|
||
public InfiniteScrollListener(LinearLayoutManager linearLayoutManager) { | ||
this.linearLayoutManager = linearLayoutManager; | ||
} | ||
|
||
public void setLinearLayoutManager(LinearLayoutManager linearLayoutManager) { | ||
this.linearLayoutManager = linearLayoutManager; | ||
} | ||
|
||
@Override | ||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | ||
super.onScrolled(recyclerView, dx, dy); | ||
|
||
visibleItemCount = recyclerView.getChildCount(); | ||
totalItemCount = linearLayoutManager.getItemCount(); | ||
firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition(); | ||
|
||
if (loading) { | ||
if (totalItemCount > previousTotal || totalItemCount == 0) { | ||
loading = false; | ||
previousTotal = totalItemCount; | ||
} | ||
} | ||
|
||
// End has been reached | ||
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) { | ||
current_page++; | ||
onLoadMore(current_page); | ||
loading = true; | ||
} | ||
} | ||
|
||
public abstract void onLoadMore(int current_page); | ||
} |
Oops, something went wrong.