Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisa Wray committed Sep 20, 2016
0 parents commit 4c709d6
Show file tree
Hide file tree
Showing 83 changed files with 3,256 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
@@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
.idea/*
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
23 changes: 23 additions & 0 deletions build.gradle
@@ -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
}
1 change: 1 addition & 0 deletions example/.gitignore
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions example/build.gradle
@@ -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'
}
17 changes: 17 additions & 0 deletions example/proguard-rules.pro
@@ -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 *;
#}
25 changes: 25 additions & 0 deletions example/src/main/AndroidManifest.xml
@@ -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 example/src/main/java/com/genius/groupie/example/ColumnGroup.java
@@ -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();
}
}
@@ -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;
}
}
@@ -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);
}

0 comments on commit 4c709d6

Please sign in to comment.