Skip to content

Commit

Permalink
basic list view working, need to touch up the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
teddywilson committed Jul 6, 2017
1 parent 10acb26 commit 6efecca
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<activity
android:name=".RecyclerActivity"
android:screenOrientation="portrait"/>

<activity
android:name=".ListViewActivity"
android:screenOrientation="portrait" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Spruce
*
* Copyright (c) 2017 WillowTree, Inc.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package com.willowtreeapps.spurceexampleapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.willowtreeapps.spurceexampleapp.fragments.ListViewFragment;

public class ListViewActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.list_view_fragment);

FragmentManager fm = getSupportFragmentManager();
Fragment listViewFragment = fm.findFragmentById(R.id.list_view_fragment);
if (listViewFragment == null) {
listViewFragment = ListViewFragment.newInstance();
fm.beginTransaction()
.replace(R.id.list_view_fragment, listViewFragment)
.commit();
}

Toolbar toolBar = (Toolbar) findViewById(R.id.list_view_tool_bar);
setSupportActionBar(toolBar);

if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(R.string.list_view_name);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.sort_option:
startActivity(new Intent(this, SpruceActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
break;
case R.id.list_view_option:
break;
case R.id.recycler_option:
startActivity(new Intent(this, RecyclerActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
break;
default:
finish();
break;
}
return super.onOptionsItemSelected(item);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
case R.id.recycler_option:
break;
case R.id.list_view_option:
startActivity(new Intent(this, ListViewActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
break;
default:
finish();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(new Intent(this, RecyclerActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
break;
case R.id.list_view_option:
startActivity(new Intent(this, ListViewActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
break;
}
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Spruce
*
* Copyright (c) 2017 WillowTree, Inc.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package com.willowtreeapps.spurceexampleapp.fragments;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.willowtreeapps.spruce.Spruce;
import com.willowtreeapps.spruce.animation.DefaultAnimations;
import com.willowtreeapps.spruce.sort.DefaultSort;
import com.willowtreeapps.spurceexampleapp.R;

import java.util.ArrayList;
import java.util.List;

public class ListViewFragment extends Fragment {

public static ListViewFragment newInstance() {
return new ListViewFragment();
}

private ListView listView;
private Animator spruceAnimator;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
listView = (ListView) container.findViewById(R.id.list_view);

RelativeLayout placeholder = (RelativeLayout) container.findViewById(R.id.placeholder_view);

List<RelativeLayout> placeHolderList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
placeHolderList.add(placeholder);
}

listView.setAdapter(new ListViewAdapter(placeHolderList));
listView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// Animate in the visible children
spruceAnimator = new Spruce.SpruceBuilder(listView)
.sortWith(new DefaultSort(100))
.animateWith(DefaultAnimations.shrinkAnimator(listView, 800),
ObjectAnimator.ofFloat(listView, "translationX", -listView.getWidth(), 0f).setDuration(800))
.start();
}
});

return inflater.inflate(R.layout.list_view_fragment, container, false);
}

@Override
public void onResume() {
super.onResume();
if (spruceAnimator != null) {
spruceAnimator.start();
}
}

private class ListViewAdapter extends BaseAdapter {

private List<RelativeLayout> placeholderList;
private LayoutInflater inflater;

public ListViewAdapter(List<RelativeLayout> placeholderList) {
this.placeholderList = placeholderList;
this.inflater = LayoutInflater.from(getContext());
}

class ViewHolder implements View.OnClickListener{

private RelativeLayout placeholderView;

public void setPlaceholderView(RelativeLayout placeholderView) {
this.placeholderView = placeholderView;
this.placeholderView.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if (spruceAnimator != null) {
spruceAnimator.start();
}
}
}

@Override
public int getCount() {
return placeholderList.size();
}

@Override
public Object getItem(int position) {
return position;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

View vi = convertView;
ViewHolder vh;

if (convertView == null) {
vi = inflater.inflate(R.layout.view_placeholder, null);

vh = new ViewHolder();
vh.setPlaceholderView((RelativeLayout) vi);
vi.setTag(vh);

} else {

}

return vi;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void onClick(View v) {
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RelativeLayout view = (RelativeLayout) LayoutInflater.from(parent.getContext())
.inflate(R.layout.recycler_placeholder, parent, false);
.inflate(R.layout.view_placeholder, parent, false);

return new ViewHolder(view);
}
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/res/layout/list_view_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Spruce
~
~ Copyright (c) 2017 WillowTree, Inc.
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~ The above copyright notice and this permission notice shall be included in
~ all copies or substantial portions of the Software.
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
~ THE SOFTWARE.
~
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_view_fragment"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.Toolbar
android:id="@+id/list_view_tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/LightToolbarTheme"
android:background="@color/colorPrimary"/>

<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

</LinearLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@
android:title="@string/recycler_view_option"
app:showAsAction="never" />

<item
android:id="@+id/list_view_option"
android:title="@string/list_view_option"
app:showAsAction="never" />

</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
<resources>
<string name="app_name">Spruce</string>
<string name="recycler_name">Recycler Example</string>
<string name="list_view_name">List View Example</string>

<!-- Menu options -->
<string name="sort_option">Sort Example</string>
<string name="recycler_view_option">Recycler View Example</string>
<string name="list_view_option">List View Example</string>
<!-- Sort options -->
<string name="default_sort">Default Sort</string>
<string name="cornered_sort">Cornered Sort</string>
Expand Down

0 comments on commit 6efecca

Please sign in to comment.