Skip to content

Commit 6a23c3a

Browse files
Add description #34
1 parent a8584d2 commit 6a23c3a

3 files changed

Lines changed: 137 additions & 11 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package org.open311.android.adapters;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.ArrayAdapter;
9+
import android.widget.TextView;
10+
11+
import org.codeforamerica.open311.facade.data.Service;
12+
import org.open311.android.R;
13+
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
/**
18+
* Created by miblon on 11/14/16.
19+
*/
20+
21+
public class ServicesAdapter extends ArrayAdapter<Service> {
22+
private Activity activity;
23+
private List<Service> services;
24+
25+
private LayoutInflater inflater;
26+
27+
public ServicesAdapter(Context context, int resource) {
28+
super(context, resource);
29+
}
30+
31+
public ServicesAdapter(Activity activity, List<Service> services) {
32+
super(activity, R.layout.item_service, services);
33+
this.activity = activity;
34+
if (services == null) {
35+
services = new ArrayList<Service>();
36+
} else {
37+
this.services = services;
38+
}
39+
}
40+
@Override
41+
public int getCount() {
42+
return services.size();
43+
}
44+
45+
@Override
46+
public Service getItem(int location) {
47+
return services.get(location);
48+
}
49+
50+
@Override
51+
public long getItemId(int position) {
52+
return 0;
53+
}
54+
55+
@Override
56+
public View getView(int position, View convertView, ViewGroup parent) {
57+
58+
59+
if (inflater == null)
60+
inflater = (LayoutInflater) activity
61+
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
62+
if (convertView == null)
63+
convertView = inflater.inflate(R.layout.item_service, null);
64+
65+
TextView name = (TextView) convertView.findViewById(R.id.item_service_name);
66+
TextView description = (TextView) convertView.findViewById(R.id.item_service_description);
67+
68+
// getting data for the row
69+
Service m = services.get(position);
70+
// name
71+
name.setText(m.getServiceName());
72+
// description
73+
description.setText(m.getDescription());
74+
75+
return convertView;
76+
}
77+
78+
@Override
79+
public void add(Service service) {
80+
super.add(service);
81+
services.add(service);
82+
notifyDataSetChanged();
83+
}
84+
85+
@Override
86+
public void remove(Service service) {
87+
super.remove(service);
88+
services.remove(service);
89+
notifyDataSetChanged();
90+
}
91+
}

app/src/main/java/org/open311/android/fragments/ReportFragment.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.open311.android.helpers.MyReportsFile;
6666
import org.open311.android.network.POSTServiceRequestDataWrapper;
6767
import org.open311.android.helpers.SingleValueAttributeWrapper;
68+
import org.open311.android.adapters.ServicesAdapter;
6869

6970
import java.io.File;
7071
import java.io.IOException;
@@ -576,17 +577,22 @@ private void onServiceButtonClicked() {
576577
values[index] = item.getServiceName();
577578
index++;
578579
}
579-
builder.setTitle(R.string.report_hint_service).setItems(values, new DialogInterface.OnClickListener() {
580-
public void onClick(DialogInterface dialog, int index) {
581-
serviceName = values[index];
582-
serviceCode = codes[index];
583-
Log.d(LOG_TAG, "SELECTED SERVICE: " + serviceName);
584-
updateService();
585-
if (ATTRIBUTES_ENABLED) {
586-
new RetrieveAttributesTask(codes[index]).execute();
587-
}
588-
}
589-
});
580+
builder.setTitle(R.string.report_hint_service)
581+
.setCancelable(false)
582+
.setAdapter(new ServicesAdapter(getActivity(), services),
583+
new DialogInterface.OnClickListener() {
584+
@Override
585+
public void onClick(DialogInterface dialog, int index) {
586+
serviceName = values[index];
587+
serviceCode = codes[index];
588+
Log.d(LOG_TAG, "SELECTED SERVICE: " + serviceName);
589+
updateService();
590+
if (ATTRIBUTES_ENABLED) {
591+
new RetrieveAttributesTask(codes[index]).execute();
592+
}
593+
}
594+
595+
});
590596
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
591597
public void onClick(DialogInterface dialog, int id) {
592598
// User cancelled the dialog
@@ -637,13 +643,15 @@ public void onClick(DialogInterface dialog, int id) {
637643
builder.show();
638644

639645
}
646+
640647
/**
641648
* User clicked the Button to add a sound to the request.
642649
* We present the user with a dialog to select a sound from storage, or use the recorder.
643650
*/
644651
private void onSoundButtonClicked() {
645652

646653
}
654+
647655
private void onLocationButtonClicked() {
648656
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission_group.LOCATION) == PackageManager.PERMISSION_DENIED) {
649657
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/service_text_container"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:baselineAligned="false"
7+
android:orientation="vertical"
8+
android:padding="24dp"
9+
android:paddingBottom="24dp"
10+
android:paddingLeft="24dp"
11+
android:paddingRight="24dp">
12+
13+
<TextView
14+
android:id="@+id/item_service_name"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:lines="1"
18+
android:maxLines="1"
19+
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
20+
21+
<TextView
22+
android:id="@+id/item_service_description"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
26+
27+
</android.support.v7.widget.LinearLayoutCompat>

0 commit comments

Comments
 (0)