Skip to content

Commit f9653a2

Browse files
Further on with attachments
1 parent 932aef6 commit f9653a2

3 files changed

Lines changed: 141 additions & 64 deletions

File tree

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

Lines changed: 45 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,6 @@ public String toString() {
137137
}
138138
}
139139

140-
enum GalleryType {
141-
IMAGE("Image", 0),
142-
AUDIO("Audio", 1);
143-
144-
private String stringValue;
145-
private int intValue;
146-
147-
GalleryType(String toString, int value) {
148-
stringValue = toString;
149-
intValue = value;
150-
}
151-
152-
@Override
153-
public String toString() {
154-
return stringValue;
155-
}
156-
}
157-
158140
public ReportFragment() {
159141
// Required empty public constructor
160142
}
@@ -342,7 +324,7 @@ public void onCompletion(MediaPlayer mp) {
342324

343325
public void updateAudio(final Uri uri) {
344326
if (uri != null) {
345-
Attachment _attachment = new Attachment();
327+
Attachment _attachment = new Attachment(Attachment.AttachmentType.AUDIO);
346328
_attachment.setUri(uri);
347329
attachmentAdapter.add(_attachment);
348330
Log.d(LOG_TAG, "updateAudio " + uri);
@@ -388,7 +370,7 @@ private String niceName(Uri uri) {
388370

389371
public void updatePhoto(Uri uri, Boolean broadcast) {
390372
if (uri != null) {
391-
Attachment _attachment = new Attachment();
373+
Attachment _attachment = new Attachment(Attachment.AttachmentType.IMAGE);
392374
_attachment.setUri(uri);
393375
attachmentAdapter.add(_attachment);
394376
Log.d(LOG_TAG, "updatePhoto " + uri);
@@ -455,7 +437,7 @@ public void onCreate(Bundle savedInstanceState) {
455437

456438
// Retain this fragment across configuration changes
457439
setRetainInstance(true);
458-
440+
attachmentAdapter = new AttachmentAdapter(getContext());
459441
attributes = new LinkedList<Attribute>();
460442
attrInfoList = new LinkedList<AttributeInfo>();
461443
installationId = ((MainActivity) getActivity()).getInstallationId();
@@ -702,7 +684,7 @@ public void onClick(DialogInterface dialog, int item) {
702684
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
703685
READ_STORAGE_REQUEST);
704686
} else {
705-
handleGallery(GalleryType.AUDIO);
687+
handleGallery(Attachment.AttachmentType.AUDIO);
706688
}
707689
}
708690
}
@@ -743,7 +725,7 @@ public void onClick(DialogInterface dialog, int item) {
743725
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
744726
READ_STORAGE_REQUEST);
745727
} else {
746-
handleGallery(GalleryType.IMAGE);
728+
handleGallery(Attachment.AttachmentType.IMAGE);
747729
}
748730
}
749731
}
@@ -780,7 +762,7 @@ private void handleLocation() {
780762
* Because we check permissions for Android 6+, this function is also used to propagate
781763
* actions from the checker
782764
*/
783-
private void handleGallery(GalleryType type) {
765+
private void handleGallery(Attachment.AttachmentType type) {
784766
Log.d(LOG_TAG, "HandleGallery");
785767
View v = getActivity().findViewById(R.id.report_submit);
786768
if (!isExternalStorageWritable()) {
@@ -791,7 +773,7 @@ private void handleGallery(GalleryType type) {
791773
}
792774
// Pass the GalleryType to the intent
793775
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
794-
intent.putExtra("GalleryType", type.intValue);
776+
intent.putExtra("GalleryType", type.toInt());
795777
intent.putExtra("return_data", true);
796778
// Initiate the correct type of Gallery
797779
switch (type) {
@@ -819,7 +801,7 @@ private void handleRecorder() {
819801
}
820802
Intent audioIntent = new Intent(getActivity(), SoundRecorderActivity.class);
821803
try {
822-
File audio = createFile(GalleryType.AUDIO);
804+
File audio = createFile(Attachment.AttachmentType.AUDIO);
823805
audioIntent.setAction(ACTION_EDIT);
824806
audioIntent.setData(Uri.fromFile(audio));
825807
startActivityForResult(audioIntent, RECORDER_REQUEST);
@@ -851,7 +833,7 @@ private void handleCamera() {
851833
// Create the File where the photo should go
852834
File photo;
853835
try {
854-
photo = createFile(GalleryType.IMAGE);
836+
photo = createFile(Attachment.AttachmentType.IMAGE);
855837
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
856838
startActivityForResult(cameraIntent, CAMERA_REQUEST);
857839

@@ -901,23 +883,23 @@ private void onSubmitButtonClicked() {
901883
Normalizer.normalize(
902884
mDescriptionView.getText().toString(), Normalizer.Form.NFD)
903885
.replaceAll(pattern, ""));
904-
905-
if (imageUri != null) {
906-
Glide.with(getActivity().getApplicationContext())
907-
.load(imageUri)
908-
.asBitmap()
909-
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
910-
.into(new SimpleTarget<Bitmap>() {
911-
@Override
912-
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
913-
PostServiceRequestTask bgTask = new PostServiceRequestTask(data, bitmap);
914-
bgTask.execute();
915-
}
916-
});
917-
} else {
886+
// todo, if single attachment and the type is image
887+
// if (imageUri != null) {
888+
// Glide.with(getActivity().getApplicationContext())
889+
// .load(imageUri)
890+
// .asBitmap()
891+
// .diskCacheStrategy(DiskCacheStrategy.SOURCE)
892+
// .into(new SimpleTarget<Bitmap>() {
893+
// @Override
894+
// public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
895+
// PostServiceRequestTask bgTask = new PostServiceRequestTask(data, bitmap);
896+
// bgTask.execute();
897+
// }
898+
// });
899+
// } else {
918900
PostServiceRequestTask bgTask = new PostServiceRequestTask(data, null);
919901
bgTask.execute();
920-
}
902+
// }
921903
} else {
922904

923905
AlertDialog.Builder builder = new AlertDialog.Builder(getContext(), R.style.AppTheme_Dialog);
@@ -941,22 +923,22 @@ public void onClick(DialogInterface dialog, int which) {
941923
mDescriptionView.getText().toString(), Normalizer.Form.NFD)
942924
.replaceAll(pattern, ""));
943925

944-
if (imageUri != null) {
945-
Glide.with(getActivity().getApplicationContext())
946-
.load(imageUri)
947-
.asBitmap()
948-
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
949-
.into(new SimpleTarget<Bitmap>() {
950-
@Override
951-
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
952-
PostServiceRequestTask bgTask = new PostServiceRequestTask(data, bitmap);
953-
bgTask.execute();
954-
}
955-
});
956-
} else {
926+
// if (imageUri != null) {
927+
// Glide.with(getActivity().getApplicationContext())
928+
// .load(imageUri)
929+
// .asBitmap()
930+
// .diskCacheStrategy(DiskCacheStrategy.SOURCE)
931+
// .into(new SimpleTarget<Bitmap>() {
932+
// @Override
933+
// public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
934+
// PostServiceRequestTask bgTask = new PostServiceRequestTask(data, bitmap);
935+
// bgTask.execute();
936+
// }
937+
// });
938+
// } else {
957939
PostServiceRequestTask bgTask = new PostServiceRequestTask(data, null);
958940
bgTask.execute();
959-
}
941+
// }
960942
}
961943
})
962944
.show();
@@ -1036,10 +1018,10 @@ protected String doInBackground(Void... ignore) {
10361018
try {
10371019
APIWrapperFactory wrapperFactory = new APIWrapperFactory(((MainActivity) getActivity()).getCurrentCity(), EndpointType.PRODUCTION);
10381020
// todo this has to go as the app should check the attachments
1039-
if (imageUri != null) {
1040-
HTTPNetworkManager networkManager = new HTTPNetworkManager(bitmap);
1041-
wrapperFactory.setNetworkManager(networkManager);
1042-
}
1021+
// if (imageUri != null) {
1022+
// HTTPNetworkManager networkManager = new HTTPNetworkManager(bitmap);
1023+
// wrapperFactory.setNetworkManager(networkManager);
1024+
// }
10431025
wrapperFactory.setApiKey(((MainActivity) getActivity()).getCurrentCity().getApiKey());
10441026

10451027
APIWrapper wrapper = wrapperFactory.build();
@@ -1175,11 +1157,11 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
11751157
}
11761158
if (requestCode == GALLERY_AUDIO_REQUEST
11771159
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
1178-
handleGallery(GalleryType.AUDIO);
1160+
handleGallery(Attachment.AttachmentType.AUDIO);
11791161
}
11801162
if (requestCode == GALLERY_IMAGE_REQUEST
11811163
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
1182-
handleGallery(GalleryType.IMAGE);
1164+
handleGallery(Attachment.AttachmentType.IMAGE);
11831165
}
11841166
if (requestCode == LOCATION_REQUEST
11851167
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
@@ -1206,7 +1188,7 @@ public static boolean hasPermissions(Context context, String... permissions) {
12061188
return true;
12071189
}
12081190

1209-
private File createFile(GalleryType type) throws IOException {
1191+
private File createFile(Attachment.AttachmentType type) throws IOException {
12101192
String prefix;
12111193
String extension;
12121194
File storageDir;
@@ -1233,7 +1215,6 @@ private File createFile(GalleryType type) throws IOException {
12331215
extension, /* suffix */
12341216
storageDir /* directory */
12351217
);
1236-
12371218
return file;
12381219
}
12391220

app/src/main/java/org/open311/android/models/Attachment.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,30 @@
1212

1313
public class Attachment implements Serializable {
1414

15+
public enum AttachmentType {
16+
IMAGE("Image", 0),
17+
AUDIO("Audio", 1);
18+
19+
private String stringValue;
20+
private int intValue;
21+
22+
AttachmentType(String toString, int value) {
23+
stringValue = toString;
24+
intValue = value;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return stringValue;
30+
}
31+
public int toInt(){
32+
return intValue;
33+
}
34+
}
1535
private Uri uri;
1636
private int status;
37+
private AttachmentType type;
38+
1739

1840
public int getStatus() {
1941
return status;
@@ -31,4 +53,8 @@ public Attachment setUri(Uri uri) {
3153
this.uri = uri;
3254
return this;
3355
}
56+
57+
public Attachment(AttachmentType type){
58+
this.type = type;
59+
}
3460
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/recorder_audio_layout"
6+
android:layout_width="fill_parent"
7+
android:layout_height="fill_parent"
8+
android:orientation="vertical">
9+
10+
<Chronometer
11+
android:id="@+id/record_audio_seekbar"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:layout_alignBottom="@+id/record_audio_progress"
15+
android:layout_centerHorizontal="true"
16+
android:layout_marginBottom="74dp"
17+
android:countDown="false"
18+
android:fontFamily="sans-serif-light"
19+
android:format="MM:SS"
20+
android:text="00:00"
21+
android:textSize="40sp"
22+
android:visibility="visible" />
23+
24+
<ProgressBar
25+
android:id="@+id/record_audio_progress"
26+
style="?android:attr/progressBarStyleHorizontal"
27+
android:layout_width="200dp"
28+
android:layout_height="200dp"
29+
android:layout_alignParentTop="true"
30+
android:layout_centerHorizontal="true"
31+
android:layout_marginTop="27dp"
32+
android:background="@drawable/record_progress_bar_background"
33+
android:indeterminate="false"
34+
android:progress="0"
35+
android:progressDrawable="@drawable/record_progress_bar" />
36+
37+
<android.support.design.widget.FloatingActionButton
38+
android:id="@+id/record_submit"
39+
android:layout_width="wrap_content"
40+
android:layout_height="match_parent"
41+
android:layout_alignParentBottom="true"
42+
android:layout_alignParentRight="true"
43+
android:layout_alignParentEnd="true"
44+
android:layout_gravity="end|bottom"
45+
android:layout_marginBottom="10dp"
46+
android:layout_marginEnd="10dp"
47+
android:layout_marginRight="10dp"
48+
android:visibility="invisible"
49+
android:src="@drawable/ic_done"
50+
app:backgroundTint="@color/colorPrimary" />
51+
52+
<android.support.design.widget.FloatingActionButton
53+
android:id="@+id/record_audio_control_button"
54+
android:layout_width="wrap_content"
55+
android:layout_height="wrap_content"
56+
android:src="@drawable/ic_mic_white_24dp"
57+
app:backgroundTint="?attr/colorPrimary"
58+
android:layout_alignTop="@+id/record_submit"
59+
android:layout_alignLeft="@+id/record_submit"
60+
android:layout_alignStart="@+id/record_submit" />
61+
62+
<TextView
63+
android:id="@+id/recording_status_text"
64+
android:layout_width="wrap_content"
65+
android:layout_height="wrap_content"
66+
android:text="@string/record_start"
67+
android:textColor="#000000"
68+
android:layout_alignTop="@+id/record_submit"
69+
android:layout_centerHorizontal="true" />
70+
</RelativeLayout>

0 commit comments

Comments
 (0)