From 93b0c4b328da003fa8c61217598839158efb77f7 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Sat, 1 Sep 2018 12:33:04 +0300 Subject: [PATCH 1/5] improve uploads UI --- app/src/main/res/layout/activity_upload.xml | 40 ++++++--------------- app/src/main/res/values/strings.xml | 6 ++-- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/app/src/main/res/layout/activity_upload.xml b/app/src/main/res/layout/activity_upload.xml index 70cbbed2..3ee745a4 100644 --- a/app/src/main/res/layout/activity_upload.xml +++ b/app/src/main/res/layout/activity_upload.xml @@ -41,16 +41,6 @@ android:focusableInTouchMode="true" android:orientation="vertical"> - - - - - - + + @@ -129,6 +110,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" + android:layout_marginEnd="16dp" android:drawablePadding="5dp" android:gravity="center_vertical" android:text="@string/upload_select_file" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b3b51708..1c904e1d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -109,12 +109,10 @@ Upload - Select the correct category for the file - Fill in the title and description\nor - build them automatically + Generate title and description Title Description - Select file to upload + Select file Upload Select a category From 9a9633e3e3e93443a64712794b427adee33b5cdf Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 1 Sep 2018 15:02:44 +0300 Subject: [PATCH 2/5] Uploads UI fixes --- .../activities/upload/UploadActivity.java | 77 +++++++++---------- .../drawable/ic_photo_camera_white_24dp.xml | 5 ++ app/src/main/res/layout/activity_upload.xml | 35 ++++++++- app/src/main/res/values/strings.xml | 2 + 4 files changed, 74 insertions(+), 45 deletions(-) create mode 100644 app/src/main/res/drawable/ic_photo_camera_white_24dp.xml diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java index 051af6ea..41fd9b53 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java @@ -11,7 +11,6 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.MediaStore; -import android.support.v7.app.AlertDialog; import android.support.v7.content.res.AppCompatResources; import android.support.v7.preference.PreferenceManager; import android.support.v7.widget.AppCompatButton; @@ -21,6 +20,7 @@ import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ProgressBar; +import android.widget.TextView; import android.widget.Toast; import net.gotev.uploadservice.MultipartUploadRequest; @@ -86,8 +86,7 @@ public class UploadActivity extends BaseActivity { private EditText uploadTitle; private EditText uploadDescription; private AppCompatButton titleDescriptionBuilderButton; - private AppCompatButton selectFileButton; - //private static AppCompatButton titleDescriptionBuilderButton; + private TextView filenameHolder; @Override protected void onCreate(Bundle savedInstanceState) { @@ -193,47 +192,39 @@ public class UploadActivity extends BaseActivity { uploadTitle = findViewById(R.id.upload_title); uploadDescription = findViewById(R.id.upload_description); - selectFileButton = findViewById(R.id.upload_select_file_button); + filenameHolder = findViewById(R.id.upload_filename); + + AppCompatButton selectFileButton = findViewById(R.id.upload_select_file_button); Drawable selectStartDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_insert_drive_file_white_24dp); selectFileButton.setCompoundDrawablesRelativeWithIntrinsicBounds(selectStartDrawable, null, null, null); selectFileButton.setOnClickListener(v -> { - final CharSequence[] options = {"Take photo", "Choose file", - "Cancel"}; - AlertDialog.Builder builder = new AlertDialog.Builder(UploadActivity.this); - builder.setTitle("Upload file"); - builder.setItems(options, (dialog, item) -> { - if (options[item].equals("Take photo")) { - /*Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - startActivityForResult(intent, REQUEST_CODE_CAMERA);*/ - - Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - takePhotoIntent.putExtra("return-data", true); - takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(UploadsHelper.getTempFile(this))); - - Intent targetedIntent = new Intent(takePhotoIntent); - List resInfo = this.getPackageManager().queryIntentActivities(takePhotoIntent, 0); - for (ResolveInfo resolveInfo : resInfo) { - String packageName = resolveInfo.activityInfo.packageName; - targetedIntent.setPackage(packageName); - } - startActivityForResult(takePhotoIntent, REQUEST_CODE_CAMERA); + String[] mimeTypes = {"image/jpeg", "text/html", "image/png", "image/jpg", "image/gif", + "application/pdf", "application/rar", "application/x-tar", "application/zip", + "application/msword", "image/vnd.djvu", "application/gz", "application/tar.gz"}; - } else if (options[item].equals("Choose file")) { - String[] mimeTypes = {"image/jpeg", "text/html", "image/png", "image/jpg", "image/gif", - "application/pdf", "application/rar", "application/x-tar", "application/zip", - "application/msword", "image/vnd.djvu", "application/gz", "application/tar.gz"}; + Intent intent = new Intent(Intent.ACTION_GET_CONTENT) + //.setType("*/*") + .setType("image/jpeg") + .putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes); - Intent intent = new Intent(Intent.ACTION_GET_CONTENT) - //.setType("*/*") - .setType("image/jpeg") - .putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes); + startActivityForResult(intent, REQUEST_CODE_CHOOSE_FILE); + }); - startActivityForResult(intent, REQUEST_CODE_CHOOSE_FILE); - } else if (options[item].equals("Cancel")) { - dialog.dismiss(); - } - }); - builder.show(); + AppCompatButton takePhotoButton = findViewById(R.id.upload_take_photo_button); + Drawable takePhotoDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_photo_camera_white_24dp); + takePhotoButton.setCompoundDrawablesRelativeWithIntrinsicBounds(takePhotoDrawable, null, null, null); + takePhotoButton.setOnClickListener(v -> { + Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + takePhotoIntent.putExtra("return-data", true); + takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(UploadsHelper.getTempFile(this))); + + Intent targetedIntent = new Intent(takePhotoIntent); + List resInfo = this.getPackageManager().queryIntentActivities(takePhotoIntent, 0); + for (ResolveInfo resolveInfo : resInfo) { + String packageName = resolveInfo.activityInfo.packageName; + targetedIntent.setPackage(packageName); + } + startActivityForResult(takePhotoIntent, REQUEST_CODE_CAMERA); }); findViewById(R.id.upload_upload_button).setOnClickListener(view -> { @@ -244,7 +235,7 @@ public class UploadActivity extends BaseActivity { uploadTitle.setError("Required"); } if (fileUri == null) { - selectFileButton.setError("Required"); + filenameHolder.setError("Required"); } if (categorySelected.equals("-1")) { Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show(); @@ -308,6 +299,10 @@ public class UploadActivity extends BaseActivity { Toast.makeText(context, "Failed to delete temporary file", Toast.LENGTH_SHORT).show(); } } + + uploadTitle.setText(null); + uploadDescription.setText(null); + filenameHolder.setText(R.string.upload_filename); } @Override @@ -392,7 +387,7 @@ public class UploadActivity extends BaseActivity { fileUri = data.getData(); if (fileUri != null) { String filename = UploadsHelper.filenameFromUri(this, fileUri); - selectFileButton.setText(filename); + filenameHolder.setText(filename); filename = filename.toLowerCase(); if (filename.endsWith(".jpg")) { @@ -443,7 +438,7 @@ public class UploadActivity extends BaseActivity { fileUri = Uri.parse(UploadsHelper.createTempFile(this, fileUri, newFilename)); newFilename += ".jpg"; - selectFileButton.setText(newFilename); + filenameHolder.setText(newFilename); } } else if (requestCode == REQUEST_CODE_FIELDS_BUILDER) { if (resultCode == Activity.RESULT_CANCELED) { diff --git a/app/src/main/res/drawable/ic_photo_camera_white_24dp.xml b/app/src/main/res/drawable/ic_photo_camera_white_24dp.xml new file mode 100644 index 00000000..9835771a --- /dev/null +++ b/app/src/main/res/drawable/ic_photo_camera_white_24dp.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/activity_upload.xml b/app/src/main/res/layout/activity_upload.xml index 3ee745a4..3cc89d2f 100644 --- a/app/src/main/res/layout/activity_upload.xml +++ b/app/src/main/res/layout/activity_upload.xml @@ -98,13 +98,26 @@ android:textAlignment="center" android:textColor="@color/accent" /> + + + + + + + android:text="@string/upload_select_file" + android:textColor="@color/primary_text" /> + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c904e1d..acccc404 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -112,7 +112,9 @@ Generate title and description Title Description + Filename Select file + Take photo Upload Select a category From 4ae0deef20b2dc693b8baa58ef6d5d47b75083c4 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 1 Sep 2018 17:44:26 +0300 Subject: [PATCH 3/5] Upload button fab and other UI fixes --- .../activities/upload/UploadActivity.java | 13 ++++--- .../drawable/ic_attach_file_white_24dp.xml | 4 +++ app/src/main/res/layout/activity_upload.xml | 35 +++++++++---------- app/src/main/res/values/strings.xml | 2 -- 4 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 app/src/main/res/drawable/ic_attach_file_white_24dp.xml diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java index 41fd9b53..b413fed3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java @@ -11,16 +11,17 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.MediaStore; +import android.support.design.widget.FloatingActionButton; import android.support.v7.content.res.AppCompatResources; import android.support.v7.preference.PreferenceManager; import android.support.v7.widget.AppCompatButton; +import android.support.v7.widget.AppCompatTextView; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ProgressBar; -import android.widget.TextView; import android.widget.Toast; import net.gotev.uploadservice.MultipartUploadRequest; @@ -86,7 +87,8 @@ public class UploadActivity extends BaseActivity { private EditText uploadTitle; private EditText uploadDescription; private AppCompatButton titleDescriptionBuilderButton; - private TextView filenameHolder; + private AppCompatTextView filenameHolder; + private FloatingActionButton uploadFAB; @Override protected void onCreate(Bundle savedInstanceState) { @@ -193,6 +195,8 @@ public class UploadActivity extends BaseActivity { uploadDescription = findViewById(R.id.upload_description); filenameHolder = findViewById(R.id.upload_filename); + Drawable filenameDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_attach_file_white_24dp); + filenameHolder.setCompoundDrawablesRelativeWithIntrinsicBounds(filenameDrawable, null, null, null); AppCompatButton selectFileButton = findViewById(R.id.upload_select_file_button); Drawable selectStartDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_insert_drive_file_white_24dp); @@ -227,7 +231,8 @@ public class UploadActivity extends BaseActivity { startActivityForResult(takePhotoIntent, REQUEST_CODE_CAMERA); }); - findViewById(R.id.upload_upload_button).setOnClickListener(view -> { + uploadFAB = findViewById(R.id.upload_fab); + uploadFAB.setOnClickListener(view -> { String uploadTitleText = uploadTitle.getText().toString(); String uploadDescriptionText = uploadDescription.getText().toString(); @@ -302,7 +307,7 @@ public class UploadActivity extends BaseActivity { uploadTitle.setText(null); uploadDescription.setText(null); - filenameHolder.setText(R.string.upload_filename); + filenameHolder.setText(null); } @Override diff --git a/app/src/main/res/drawable/ic_attach_file_white_24dp.xml b/app/src/main/res/drawable/ic_attach_file_white_24dp.xml new file mode 100644 index 00000000..4834305b --- /dev/null +++ b/app/src/main/res/drawable/ic_attach_file_white_24dp.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/layout/activity_upload.xml b/app/src/main/res/layout/activity_upload.xml index 3cc89d2f..b6ff0f8a 100644 --- a/app/src/main/res/layout/activity_upload.xml +++ b/app/src/main/res/layout/activity_upload.xml @@ -23,7 +23,7 @@ app:popupTheme="@style/ToolbarTheme" /> - + android:inputType="textMultiLine" /> - + android:textColor="@color/primary_text" /> - - - + - + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index acccc404..6a59a209 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -112,10 +112,8 @@ Generate title and description Title Description - Filename Select file Take photo - Upload Select a category From e4e8204afe4ae3d6d82a4b1cc0bc327ec26458b3 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 1 Sep 2018 18:18:16 +0300 Subject: [PATCH 4/5] Upload spinners theme fix --- .../mthmmy/activities/upload/UploadActivity.java | 12 ++++++------ app/src/main/res/layout/spinner_dropdown_item.xml | 14 ++++++++++++++ app/src/main/res/layout/spinner_item.xml | 14 ++++++++++++++ app/src/main/res/values-w820dp/dimens.xml | 1 + app/src/main/res/values/dimens.xml | 1 + 5 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/layout/spinner_dropdown_item.xml create mode 100644 app/src/main/res/layout/spinner_item.xml diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java index b413fed3..3f8eda73 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java @@ -335,8 +335,8 @@ public class UploadActivity extends BaseActivity { } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(BaseApplication.getInstance().getApplicationContext(), - android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray); - spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + R.layout.spinner_item, tmpSpinnerArray); + spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); rootCategorySpinner.setAdapter(spinnerArrayAdapter); //Sets bundle selection @@ -491,8 +491,8 @@ public class UploadActivity extends BaseActivity { } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(getApplicationContext(), - android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray); - spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + R.layout.spinner_item, tmpSpinnerArray); + spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); AppCompatSpinnerWithoutDefault subSpinner = new AppCompatSpinnerWithoutDefault(categoriesSpinners.getContext()); subSpinner.setPromptId(R.string.upload_spinners_hint); @@ -591,8 +591,8 @@ public class UploadActivity extends BaseActivity { } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(BaseApplication.getInstance().getApplicationContext(), - android.R.layout.simple_spinner_dropdown_item, tmpSpinnerArray); - spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + R.layout.spinner_item, tmpSpinnerArray); + spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); rootCategorySpinner.setAdapter(spinnerArrayAdapter); //Sets bundle selection diff --git a/app/src/main/res/layout/spinner_dropdown_item.xml b/app/src/main/res/layout/spinner_dropdown_item.xml new file mode 100644 index 00000000..ebe364c6 --- /dev/null +++ b/app/src/main/res/layout/spinner_dropdown_item.xml @@ -0,0 +1,14 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/spinner_item.xml b/app/src/main/res/layout/spinner_item.xml new file mode 100644 index 00000000..1fb5f1c4 --- /dev/null +++ b/app/src/main/res/layout/spinner_item.xml @@ -0,0 +1,14 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml index e1c4971b..ea1b50c0 100644 --- a/app/src/main/res/values-w820dp/dimens.xml +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -9,5 +9,6 @@ 144dp 64dp 40dp + 16sp 24sp diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 20a265af..ee377b5c 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -7,5 +7,6 @@ 36dp 16dp 10dp + 16sp 24sp From a5ee4d5b27cbbef837b24dcb80797b4438a48108 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 1 Sep 2018 19:12:13 +0300 Subject: [PATCH 5/5] Upload UI minor change --- .../mthmmy/activities/upload/UploadActivity.java | 13 ++++++++++--- app/src/main/res/layout/activity_upload.xml | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java index 3f8eda73..18ba84c1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java @@ -88,7 +88,6 @@ public class UploadActivity extends BaseActivity { private EditText uploadDescription; private AppCompatButton titleDescriptionBuilderButton; private AppCompatTextView filenameHolder; - private FloatingActionButton uploadFAB; @Override protected void onCreate(Bundle savedInstanceState) { @@ -231,7 +230,7 @@ public class UploadActivity extends BaseActivity { startActivityForResult(takePhotoIntent, REQUEST_CODE_CAMERA); }); - uploadFAB = findViewById(R.id.upload_fab); + FloatingActionButton uploadFAB = findViewById(R.id.upload_fab); uploadFAB.setOnClickListener(view -> { String uploadTitleText = uploadTitle.getText().toString(); String uploadDescriptionText = uploadDescription.getText().toString(); @@ -240,7 +239,7 @@ public class UploadActivity extends BaseActivity { uploadTitle.setError("Required"); } if (fileUri == null) { - filenameHolder.setError("Required"); + Toast.makeText(view.getContext(), "Please choose a file to upload or take a photo", Toast.LENGTH_LONG).show(); } if (categorySelected.equals("-1")) { Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show(); @@ -299,6 +298,8 @@ public class UploadActivity extends BaseActivity { @Override public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { + Toast.makeText(context, "Upload completed successfully", Toast.LENGTH_SHORT).show(); + if (finalTempFilePath != null) { if (!UploadsHelper.deleteTempFile(finalTempFilePath)) { Toast.makeText(context, "Failed to delete temporary file", Toast.LENGTH_SHORT).show(); @@ -307,11 +308,15 @@ public class UploadActivity extends BaseActivity { uploadTitle.setText(null); uploadDescription.setText(null); + fileUri = null; filenameHolder.setText(null); + filenameHolder.setVisibility(View.GONE); } @Override public void onCancelled(Context context, UploadInfo uploadInfo) { + Toast.makeText(context, "Upload canceled", Toast.LENGTH_SHORT).show(); + if (finalTempFilePath != null) { if (!UploadsHelper.deleteTempFile(finalTempFilePath)) { Toast.makeText(context, "Failed to delete temporary file", Toast.LENGTH_SHORT).show(); @@ -393,6 +398,7 @@ public class UploadActivity extends BaseActivity { if (fileUri != null) { String filename = UploadsHelper.filenameFromUri(this, fileUri); filenameHolder.setText(filename); + filenameHolder.setVisibility(View.VISIBLE); filename = filename.toLowerCase(); if (filename.endsWith(".jpg")) { @@ -444,6 +450,7 @@ public class UploadActivity extends BaseActivity { newFilename += ".jpg"; filenameHolder.setText(newFilename); + filenameHolder.setVisibility(View.VISIBLE); } } else if (requestCode == REQUEST_CODE_FIELDS_BUILDER) { if (resultCode == Activity.RESULT_CANCELED) { diff --git a/app/src/main/res/layout/activity_upload.xml b/app/src/main/res/layout/activity_upload.xml index b6ff0f8a..d2f81b4c 100644 --- a/app/src/main/res/layout/activity_upload.xml +++ b/app/src/main/res/layout/activity_upload.xml @@ -106,7 +106,8 @@ android:drawablePadding="5dp" android:ellipsize="marquee" android:singleLine="true" - android:textColor="@color/primary_text" /> + android:textColor="@color/primary_text" + android:visibility="gone" />