Skip to content

Commit 9c79e17

Browse files
author
Justin Harrison
committed
work on building out UI
1 parent f36fa16 commit 9c79e17

File tree

9 files changed

+301
-3
lines changed

9 files changed

+301
-3
lines changed

app/src/main/java/org/codeforbirmingham/spotholes/network/SpotholesSpiceService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import org.codeforbirmingham.spotholes.R;
99
import org.codeforbirmingham.spotholes.SpotholesApplication;
10+
import org.codeforbirmingham.spotholes.network.leaderboard.LeaderboardApiService;
1011
import org.codeforbirmingham.spotholes.network.potholes.PotholeApiService;
12+
import org.codeforbirmingham.spotholes.network.users.UserApiService;
1113
import org.codeforbirmingham.spotholes.utils.Util;
1214
import org.codeforbirmingham.spotholes.util.Environment;
1315

@@ -71,6 +73,8 @@ public void onCreate() {
7173
super.onCreate();
7274

7375
addRetrofitInterface(PotholeApiService.class);
76+
addRetrofitInterface(LeaderboardApiService.class);
77+
addRetrofitInterface(UserApiService.class);
7478
}
7579

7680
protected KeyStore readKeyStore() {

app/src/main/java/org/codeforbirmingham/spotholes/ui/BaseActivity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import android.support.v7.app.AppCompatActivity;
1010
import android.view.Gravity;
1111
import android.view.MenuItem;
12-
import android.view.View;
1312

1413
import org.codeforbirmingham.spotholes.R;
1514

@@ -114,6 +113,9 @@ private void goToNavDrawerItem(MenuItem item) {
114113
case R.id.nav_settings:
115114
// TODO Add intent here once activity is built
116115
break;
116+
case R.id.nav_about:
117+
// TODO Add intent here once activity is built
118+
break;
117119
}
118120
}
119121

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.codeforbirmingham.spotholes.ui;
2+
3+
import android.content.Context;
4+
import android.graphics.Typeface;
5+
import android.text.Spannable;
6+
import android.text.SpannableString;
7+
import android.text.style.StyleSpan;
8+
import android.view.LayoutInflater;
9+
import android.view.View;
10+
import android.view.ViewGroup;
11+
import android.widget.ImageView;
12+
import android.widget.RelativeLayout;
13+
import android.widget.TextView;
14+
15+
import org.codeforbirmingham.spotholes.R;
16+
import org.codeforbirmingham.spotholes.models.Pothole;
17+
import org.codeforbirmingham.spotholes.ui.widget.RealmAdapter;
18+
19+
import butterknife.ButterKnife;
20+
import butterknife.InjectView;
21+
import de.hdodenhof.circleimageview.CircleImageView;
22+
23+
/**
24+
* @author @justinharrison
25+
*/
26+
public class PotholeListAdapter extends RealmAdapter<Pothole, PotholeListAdapter.ViewHolder> {
27+
28+
public static class ViewHolder extends RealmAdapter.ViewHolder {
29+
@InjectView(R.id.pothole_thumbnail)
30+
CircleImageView potholeThumbnail;
31+
@InjectView(R.id.pothole_title)
32+
TextView potholeTitle;
33+
@InjectView(R.id.pothole_submitter)
34+
TextView potholeSubmitter;
35+
@InjectView(R.id.pothole_upvote)
36+
ImageView potholeUpvote;
37+
@InjectView(R.id.pothole_score)
38+
TextView potholeScore;
39+
@InjectView(R.id.pothole_downvote)
40+
ImageView potholeDownvote;
41+
@InjectView(R.id.pothole_list_item_layout)
42+
RelativeLayout potholeListItemLayout;
43+
44+
public ViewHolder(View view) {
45+
super(view);
46+
ButterKnife.inject(this, view);
47+
}
48+
}
49+
50+
private final LayoutInflater inflater;
51+
52+
public PotholeListAdapter(Context context) {
53+
this.inflater = LayoutInflater.from(context);
54+
}
55+
56+
@Override
57+
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
58+
return new ViewHolder(inflater.inflate(R.layout.pothole_list_item, parent, false));
59+
}
60+
61+
@Override
62+
public void onBindViewHolder(ViewHolder viewHolder, int position) {
63+
64+
Pothole pothole = getItem(position);
65+
66+
viewHolder.potholeTitle.setText(pothole.getName());
67+
68+
SpannableString name = new SpannableString(pothole.getUser().getName());
69+
StyleSpan boldItalic = new StyleSpan(Typeface.BOLD_ITALIC);
70+
name.setSpan(boldItalic, 0, pothole.getUser().getName().length() - 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
71+
72+
viewHolder.potholeSubmitter.setText("Submitted by " + name + " at " + pothole.getLogs().last().getCreatedAt().toString());
73+
74+
}
75+
76+
@Override
77+
public long getItemId(int position) {
78+
return results.get(position).getId();
79+
}
80+
81+
}

app/src/main/java/org/codeforbirmingham/spotholes/ui/PotholesListFragment.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import android.widget.ProgressBar;
1313
import android.widget.TextView;
1414

15+
import com.octo.android.robospice.SpiceManager;
16+
1517
import org.codeforbirmingham.spotholes.R;
18+
import org.codeforbirmingham.spotholes.network.SpotholesSpiceService;
1619

1720
import butterknife.ButterKnife;
1821
import butterknife.InjectView;
@@ -33,6 +36,8 @@ public class PotholesListFragment extends Fragment {
3336

3437
private LinearLayoutManager linearLayoutManager;
3538

39+
public final SpiceManager spotholesApi = new SpiceManager(SpotholesSpiceService.class);
40+
3641
@Override
3742
public void onCreate(Bundle savedInstanceState) {
3843
super.onCreate(savedInstanceState);
@@ -56,4 +61,27 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
5661
}
5762

5863

64+
@Override
65+
public void onStart() {
66+
super.onStart();
67+
spotholesApi.start(getActivity());
68+
}
69+
70+
@Override
71+
public void onStop() {
72+
super.onStop();
73+
if (spotholesApi.isStarted())
74+
spotholesApi.shouldStop();
75+
}
76+
77+
@Override
78+
public void onResume() {
79+
super.onResume();
80+
}
81+
82+
@Override
83+
public void onSaveInstanceState(Bundle outState) {
84+
super.onSaveInstanceState(outState);
85+
}
86+
5987
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.codeforbirmingham.spotholes.ui.widget;
2+
3+
import android.view.View;
4+
import android.view.ViewGroup;
5+
import android.widget.BaseAdapter;
6+
7+
import io.realm.RealmObject;
8+
import io.realm.RealmResults;
9+
10+
/**
11+
* @author @justinharrison
12+
*/
13+
public abstract class RealmAdapter<E extends RealmObject, VH extends RealmAdapter.ViewHolder>
14+
extends BaseAdapter {
15+
16+
public static class ViewHolder {
17+
public final View itemView;
18+
19+
public ViewHolder(View itemView) {
20+
this.itemView = itemView;
21+
this.itemView.setTag(this);
22+
}
23+
}
24+
25+
protected RealmResults<E> results;
26+
27+
public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);
28+
29+
public abstract void onBindViewHolder(VH holder, int position);
30+
31+
public void onViewRecycled(VH holder) {
32+
}
33+
34+
public void setResults(RealmResults<E> results) {
35+
this.results = results;
36+
notifyDataSetChanged();
37+
}
38+
39+
@Override
40+
public int getCount() {
41+
return results == null ? 0 : results.size();
42+
}
43+
44+
@Override
45+
public E getItem(int position) {
46+
return results == null ? null : results.get(position);
47+
}
48+
49+
@Override
50+
public long getItemId(int position) {
51+
return -1;
52+
}
53+
54+
@Override
55+
public View getView(int position, View convertView, ViewGroup parent) {
56+
if (convertView == null) {
57+
convertView = onCreateViewHolder(parent, getItemViewType(position)).itemView;
58+
} else {
59+
onViewRecycled(getViewHolder(convertView));
60+
}
61+
62+
onBindViewHolder(getViewHolder(convertView), position);
63+
64+
return convertView;
65+
}
66+
67+
private VH getViewHolder(View view) {
68+
return (VH) view.getTag();
69+
}
70+
71+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/pothole_list_item_layout"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:background="?attr/selectableItemBackground"
7+
android:clickable="true">
8+
9+
<de.hdodenhof.circleimageview.CircleImageView
10+
android:id="@+id/pothole_thumbnail"
11+
android:layout_width="@dimen/circular_image_size"
12+
android:layout_height="@dimen/circular_image_size"
13+
android:layout_marginLeft="@dimen/content_padding_normal"
14+
android:layout_marginStart="@dimen/content_padding_normal"
15+
android:layout_marginTop="@dimen/content_padding_normal"
16+
android:scaleType="centerCrop" />
17+
18+
<TextView
19+
android:id="@+id/pothole_title"
20+
style="@style/TextAppearance.AppCompat.Subhead"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:layout_alignTop="@+id/pothole_thumbnail"
24+
android:layout_marginEnd="@dimen/content_padding_normal"
25+
android:layout_marginLeft="@dimen/content_padding_normal"
26+
android:layout_marginRight="@dimen/content_padding_normal"
27+
android:layout_marginStart="@dimen/content_padding_normal"
28+
android:layout_toEndOf="@+id/pothole_thumbnail"
29+
android:layout_toLeftOf="@+id/pothole_score"
30+
android:layout_toRightOf="@+id/pothole_thumbnail"
31+
android:layout_toStartOf="@+id/pothole_score"
32+
android:ellipsize="end"
33+
android:maxLines="1"
34+
android:text="Pothole Title" />
35+
36+
<TextView
37+
android:id="@+id/pothole_submitter"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_below="@+id/pothole_title"
41+
android:layout_marginEnd="@dimen/content_padding_normal"
42+
android:layout_marginLeft="@dimen/content_padding_normal"
43+
android:layout_marginRight="@dimen/content_padding_normal"
44+
android:layout_marginStart="@dimen/content_padding_normal"
45+
android:layout_toEndOf="@+id/pothole_thumbnail"
46+
android:layout_toLeftOf="@+id/pothole_score"
47+
android:layout_toRightOf="@+id/pothole_thumbnail"
48+
android:layout_toStartOf="@+id/pothole_score"
49+
android:ellipsize="end"
50+
android:maxLines="2"
51+
android:text="Submitted by Justin at 5:30:09 December 12th" />
52+
53+
<ImageView
54+
android:id="@+id/pothole_upvote"
55+
android:layout_width="48dp"
56+
android:layout_height="48dp"
57+
android:layout_alignParentEnd="true"
58+
android:layout_alignParentRight="true"
59+
android:layout_alignParentTop="true"
60+
android:layout_marginEnd="@dimen/content_padding_normal"
61+
android:layout_marginRight="@dimen/content_padding_normal"
62+
android:adjustViewBounds="true"
63+
android:background="?attr/selectableItemBackgroundBorderless"
64+
android:clickable="true"
65+
android:scaleType="centerInside"
66+
android:src="@drawable/ic_nav_about" />
67+
68+
<TextView
69+
android:id="@+id/pothole_score"
70+
android:layout_width="wrap_content"
71+
android:layout_height="wrap_content"
72+
android:layout_alignLeft="@+id/pothole_upvote"
73+
android:layout_alignRight="@+id/pothole_upvote"
74+
android:layout_below="@+id/pothole_upvote"
75+
android:layout_marginTop="-8dp"
76+
android:ellipsize="end"
77+
android:gravity="center"
78+
android:maxLength="4"
79+
android:maxLines="1"
80+
android:text="1412"
81+
android:textSize="18sp" />
82+
83+
<ImageView
84+
android:id="@+id/pothole_downvote"
85+
android:layout_width="48dp"
86+
android:layout_height="48dp"
87+
android:layout_alignLeft="@+id/pothole_score"
88+
android:layout_alignStart="@+id/pothole_score"
89+
android:layout_below="@+id/pothole_score"
90+
android:layout_marginTop="-8dp"
91+
android:adjustViewBounds="true"
92+
android:background="?attr/selectableItemBackgroundBorderless"
93+
android:clickable="true"
94+
android:scaleType="centerInside"
95+
android:src="@drawable/ic_nav_about" />
96+
97+
</RelativeLayout>

app/src/main/res/layout/potholes_activity.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
android:fitsSystemWindows="true">
88

99
<!-- The main content view -->
10-
<RelativeLayout
10+
<android.support.design.widget.CoordinatorLayout
1111
android:layout_width="fill_parent"
1212
android:layout_height="fill_parent">
1313

@@ -31,7 +31,7 @@
3131
android:layout_width="match_parent"
3232
android:layout_height="match_parent"
3333
android:layout_below="@+id/appbar" />
34-
</RelativeLayout>
34+
</android.support.design.widget.CoordinatorLayout>
3535

3636
<android.support.design.widget.NavigationView
3737
android:id="@+id/nav_view"

app/src/main/res/values/colors.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
<color name="primaryLight">#C8E6C9</color>
66
<color name="accent">#03A9F4</color>
77

8+
<color name="text_primary">#de000000</color>
9+
<color name="text_secondary">#89000000</color>
10+
<color name="text_disabled">#42000000</color>
11+
812
<color name="window_background">#FFF5F5F5</color>
913
</resources>

app/src/main/res/values/dimens.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- body content -->
4+
<dimen name="element_spacing_normal">8dp</dimen>
5+
<dimen name="content_padding_normal">16dp</dimen>
6+
<dimen name="text_size_secondary">14sp</dimen>
7+
<dimen name="text_size_primary">14sp</dimen>
8+
<dimen name="text_size_large">18sp</dimen>
9+
<dimen name="text_size_xlarge">20sp</dimen>
10+
<dimen name="circular_image_size">40dp</dimen>
11+
</resources>

0 commit comments

Comments
 (0)