Commit cdef9404 authored by Robert Hitt's avatar Robert Hitt
Browse files

Made the RecyclerView marginally prettier

parent e01bb4a0
......@@ -5,7 +5,7 @@
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" />
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.14.1" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
......
......@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
package srct.whatsopen.services;
package srct.whatsopen.service;
import com.google.gson.ExclusionStrategy;
......
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package srct.whatsopen.ui;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
......@@ -31,79 +12,41 @@ import android.view.View;
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
private static final int[] ATTRS = new int[]{
android.R.attr.listDivider
};
public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
private Drawable mDivider;
private int mOrientation;
public DividerItemDecoration(Context context, int orientation) {
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
a.recycle();
setOrientation(orientation);
}
public void setOrientation(int orientation) {
if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
throw new IllegalArgumentException("invalid orientation");
}
mOrientation = orientation;
public DividerItemDecoration(Drawable divider) {
mDivider = divider;
}
@Override
public void onDraw(Canvas c, RecyclerView parent) {
if (mOrientation == VERTICAL_LIST) {
drawVertical(c, parent);
} else {
drawHorizontal(c, parent);
}
}
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
public void drawVertical(Canvas c, RecyclerView parent) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
super.getItemOffsets(outRect, view, parent, state);
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
if(parent.getChildAdapterPosition(view) == 0) {
return;
}
}
public void drawHorizontal(Canvas c, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int left = child.getRight() + params.rightMargin;
final int right = left + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
outRect.top = mDivider.getIntrinsicHeight();
}
@Override
public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
if (mOrientation == VERTICAL_LIST) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
} else {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
int dividerLeft = parent.getPaddingLeft();
int dividerRight = parent.getWidth() - parent.getPaddingRight();
int childCount = parent.getChildCount();
for(int i = 0; i < childCount - 1; i++) {
View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int dividerTop = child.getBottom() + params.bottomMargin;
int dividerBottom = dividerTop + mDivider.getIntrinsicHeight();
mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
mDivider.draw(canvas);
}
}
}
......@@ -12,10 +12,13 @@ import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.realm.OrderedRealmCollection;
import io.realm.RealmList;
import io.realm.RealmRecyclerViewAdapter;
import srct.whatsopen.R;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.OpenTimes;
/**
* Basic RecyclerView boilerplate, with some added Realm stuff
......@@ -45,6 +48,7 @@ public class FacilityListAdapter extends
public void onBindViewHolder(ViewHolder holder, int position) {
Facility facility = getData().get(position);
RealmList<OpenTimes> openTimesList = facility.getMainSchedule().getOpenTimesList();
holder.data = facility;
TextView textView = holder.nameTextView;
textView.setText(facility.getName());
......@@ -62,6 +66,12 @@ public class FacilityListAdapter extends
super(itemView);
ButterKnife.bind(this, itemView);
}
@OnClick(R.id.favorite_button)
public void setFavorite(ImageButton favoriteButton) {
// this works very weirdly when the view is scrolled down. not sure why
//favoriteButton.setImageResource(R.drawable.ic_star_black_24dp);
}
}
}
package srct.whatsopen.ui;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
......@@ -16,8 +18,8 @@ import retrofit2.Callback;
import retrofit2.Response;
import srct.whatsopen.R;
import srct.whatsopen.services.WhatsOpenClient;
import srct.whatsopen.services.WhatsOpenService;
import srct.whatsopen.service.WhatsOpenClient;
import srct.whatsopen.service.WhatsOpenService;
import srct.whatsopen.model.Facility;
public class MainActivity extends AppCompatActivity {
......@@ -58,8 +60,8 @@ public class MainActivity extends AppCompatActivity {
mRecyclerView.setHasFixedSize(true);
// Adds dividers between items
mRecyclerView.addItemDecoration(new
DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
Drawable dividerDrawable = ContextCompat.getDrawable(this, R.drawable.divider);
mRecyclerView.addItemDecoration(new DividerItemDecoration(dividerDrawable));
}
// Gets a Call from the given Retrofit service, then asynchronously executes it
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="8dp"
android:width="8dp" />
<solid android:color="#80FFFFFF"/>
</shape>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/facilityText"
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/facilityText"
android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z"/>
</vector>
......@@ -9,6 +9,7 @@
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#FFFFFF"
tools:context="srct.whatsopen.ui.MainActivity">
<android.support.v7.widget.RecyclerView
......
......@@ -4,19 +4,22 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
android:paddingBottom="10dp">
android:paddingBottom="10dp"
android:background="@color/facilityClosed"
android:elevation="2dp">
<TextView android:id="@+id/facility_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/facilityText"
android:paddingLeft="10dp"
android:layout_weight="1"/>
<ImageButton android:id="@+id/favorite_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/btn_star"
android:background="#00ffffff"
android:scaleType="fitCenter"
android:paddingLeft="16dp"
android:paddingRight="16dp"/>
</LinearLayout>
\ No newline at end of file
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_star_border_black_24dp"
android:background="#00ffffff"
android:scaleType="fitCenter"
android:paddingLeft="16dp"
android:paddingRight="16dp"/>
</LinearLayout>
......@@ -3,4 +3,7 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="facilityText">#757575</color>
<color name="facilityClosed">#E0E0E0</color>
<color name="facilityOpen">#FAFAFA</color>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment