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 a555a18e..45c3d77f 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 @@ -1,7 +1,9 @@ package gr.thmmy.mthmmy.activities.upload; import android.app.Activity; +import android.app.PendingIntent; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -12,6 +14,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; import android.support.v4.content.FileProvider; +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; @@ -36,6 +39,7 @@ import android.widget.Toast; import net.gotev.uploadservice.MultipartUploadRequest; import net.gotev.uploadservice.ServerResponse; import net.gotev.uploadservice.UploadInfo; +import net.gotev.uploadservice.UploadNotificationAction; import net.gotev.uploadservice.UploadNotificationConfig; import net.gotev.uploadservice.UploadStatusDelegate; @@ -232,7 +236,6 @@ public class UploadActivity extends BaseActivity { popUp.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); popUp.setFocusable(true); - //((TextView) popUpContent.findViewById(R.id.upload_filename_info_text)).setTe ((TextView) popUpContent.findViewById(R.id.upload_filename_info_text)). setMovementMethod(LinkMovementMethod.getInstance()); //Displays the popup @@ -279,7 +282,7 @@ public class UploadActivity extends BaseActivity { String uploadTitleText = uploadTitle.getText().toString(); String editTextFilename = uploadFilename.getText().toString(); - String uploadDescriptionText = uploadDescription.getText().toString(); + final String[] uploadDescriptionText = {uploadDescription.getText().toString()}; //Checks if all required fields are filled { @@ -307,7 +310,9 @@ public class UploadActivity extends BaseActivity { shouldReturn = true; } } - if (!editTextFilename.matches("(.+\\.)+.+")) { + if (!editTextFilename.matches("(.+\\.)+.+") || + !FileUtils.getFilenameWithoutExtension(editTextFilename). + matches("[0-9a-zA-Z~!@#$%^&()_+=\\-`\\[\\]{};',.]+")) { uploadFilename.setError("Invalid filename"); shouldReturn = true; } @@ -317,121 +322,144 @@ public class UploadActivity extends BaseActivity { } } - //Checks settings and possibly adds "Uploaded from mTHMMY" string to description - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(view.getContext()); - if (sharedPrefs.getBoolean(UPLOADING_APP_SIGNATURE_ENABLE_KEY, true)) { - uploadDescriptionText += uploadedFromThmmyPromptHtml; - } + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Upload to thmmy"); + builder.setMessage("Are you sure?"); + builder.setPositiveButton("YES, FIRE AWAY", (dialog, which) -> { + //Checks settings and possibly adds "Uploaded from mTHMMY" string to description + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(view.getContext()); + if (sharedPrefs.getBoolean(UPLOADING_APP_SIGNATURE_ENABLE_KEY, true)) { + uploadDescriptionText[0] += uploadedFromThmmyPromptHtml; + } - Uri tempFileUri = null; - if (filesList.size() == 1) { - //Checks if the file needs renaming - UploadFile uploadFile = filesList.get(0); - String selectedFileFilename = FileUtils.filenameFromUri(this, uploadFile.getFileUri()); - - if (!editTextFilename.equals(selectedFileFilename)) { - //File should be uploaded with a different name - if (!uploadFile.isCameraPhoto()) { - //Temporarily copies the file to a another location and renames it - tempFileUri = UploadsHelper.createTempFile(this, storage, - uploadFile.getFileUri(), - FileUtils.getFilenameWithoutExtension(editTextFilename)); - } else { - //Renames the photo taken - String photoPath = uploadFile.getPhotoFile().getPath(); - photoPath = photoPath.substring(0, photoPath.lastIndexOf(File.separator)); - String destinationFilename = photoPath + File.separator + - FileUtils.getFilenameWithoutExtension(editTextFilename) + ".jpg"; - - if (!storage.rename(uploadFile.getPhotoFile().getAbsolutePath(), destinationFilename)) { - //Something went wrong, abort - Toast.makeText(this, "Could not create temporary file for renaming", Toast.LENGTH_SHORT).show(); - progressBar.setVisibility(View.GONE); - return; - } + Uri tempFileUri = null; + if (filesList.size() == 1) { + //Checks if the file needs renaming + UploadFile uploadFile = filesList.get(0); + String selectedFileFilename = FileUtils.filenameFromUri(this, uploadFile.getFileUri()); + + if (!editTextFilename.equals(selectedFileFilename)) { + //File should be uploaded with a different name + if (!uploadFile.isCameraPhoto()) { + //Temporarily copies the file to a another location and renames it + tempFileUri = UploadsHelper.createTempFile(this, storage, + uploadFile.getFileUri(), + FileUtils.getFilenameWithoutExtension(editTextFilename)); + } else { + //Renames the photo taken + String photoPath = uploadFile.getPhotoFile().getPath(); + photoPath = photoPath.substring(0, photoPath.lastIndexOf(File.separator)); + String destinationFilename = photoPath + File.separator + + FileUtils.getFilenameWithoutExtension(editTextFilename) + ".jpg"; + + if (!storage.rename(uploadFile.getPhotoFile().getAbsolutePath(), destinationFilename)) { + //Something went wrong, abort + Toast.makeText(this, "Could not create temporary file for renaming", Toast.LENGTH_SHORT).show(); + progressBar.setVisibility(View.GONE); + return; + } - //Points photoFile and fileUri to the new copied and renamed file - uploadFile.setPhotoFile(storage.getFile(destinationFilename)); - uploadFile.setFileUri(FileProvider.getUriForFile(this, getPackageName() + - ".provider", uploadFile.getPhotoFile())); + //Points photoFile and fileUri to the new copied and renamed file + uploadFile.setPhotoFile(storage.getFile(destinationFilename)); + uploadFile.setFileUri(FileProvider.getUriForFile(this, getPackageName() + + ".provider", uploadFile.getPhotoFile())); + } + } + } else { + Uri[] filesListArray = new Uri[filesList.size()]; + for (int i = 0; i < filesList.size(); ++i) { + filesListArray[i] = filesList.get(i).getFileUri(); } - } - } else { - Uri[] filesListArray = new Uri[filesList.size()]; - for (int i = 0; i < filesList.size(); ++i) { - filesListArray[i] = filesList.get(i).getFileUri(); - } - File zipFile = UploadsHelper.createZipFile(this); - assert zipFile != null; - tempFileUri = FileProvider.getUriForFile(this, getPackageName() + - ".provider", zipFile); + File zipFile = UploadsHelper.createZipFile(this); + assert zipFile != null; + tempFileUri = FileProvider.getUriForFile(this, getPackageName() + + ".provider", zipFile); - UploadsHelper.zip(this, filesListArray, tempFileUri); - } + UploadsHelper.zip(this, filesListArray, tempFileUri); + } - try { - new MultipartUploadRequest(view.getContext(), uploadIndexUrl) - .setUtf8Charset() - .addParameter("tp-dluploadtitle", uploadTitleText) - .addParameter("tp-dluploadcat", categorySelected) - .addParameter("tp-dluploadtext", uploadDescriptionText) - .addFileToUpload(tempFileUri == null - ? filesList.get(0).getFileUri().toString() - : tempFileUri.toString() - , "tp-dluploadfile") - .addParameter("tp_dluploadicon", fileIcon) - .addParameter("tp-uploaduser", uploaderProfileIndex) - .setNotificationConfig(new UploadNotificationConfig()) - .setMaxRetries(2) - .setDelegate(new UploadStatusDelegate() { - @Override - public void onProgress(Context context, UploadInfo uploadInfo) { - } + try { + UploadNotificationConfig uploadNotificationConfig = new UploadNotificationConfig(); + uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload); + + uploadNotificationConfig.getProgress().iconResourceID = android.R.drawable.stat_sys_upload; + uploadNotificationConfig.getCompleted().iconResourceID = android.R.drawable.stat_sys_upload_done; + uploadNotificationConfig.getError().iconResourceID = android.R.drawable.stat_sys_upload_done; + uploadNotificationConfig.getError().iconColorResourceID = R.color.error_red; + + new MultipartUploadRequest(view.getContext(), uploadIndexUrl) + .setUtf8Charset() + .setNotificationConfig(uploadNotificationConfig) + .addParameter("tp-dluploadtitle", uploadTitleText) + .addParameter("tp-dluploadcat", categorySelected) + .addParameter("tp-dluploadtext", uploadDescriptionText[0]) + .addFileToUpload(tempFileUri == null + ? filesList.get(0).getFileUri().toString() + : tempFileUri.toString() + , "tp-dluploadfile") + .addParameter("tp_dluploadicon", fileIcon) + .addParameter("tp-uploaduser", uploaderProfileIndex) + .setNotificationConfig(new UploadNotificationConfig()) + .setMaxRetries(2) + .setDelegate(new UploadStatusDelegate() { + @Override + public void onProgress(Context context, UploadInfo uploadInfo) { + } - @Override - public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, - Exception exception) { - Toast.makeText(context, "Upload failed", Toast.LENGTH_SHORT).show(); - UploadsHelper.deleteTempFiles(); - progressBar.setVisibility(View.GONE); - } + @Override + public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, + Exception exception) { + Toast.makeText(context, "Upload failed", Toast.LENGTH_SHORT).show(); + UploadsHelper.deleteTempFiles(); + progressBar.setVisibility(View.GONE); + } - @Override - public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { - Toast.makeText(context, "Upload completed successfully", Toast.LENGTH_SHORT).show(); - UploadsHelper.deleteTempFiles(); - BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null); + @Override + public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { + Toast.makeText(context, "Upload completed successfully", Toast.LENGTH_SHORT).show(); + UploadsHelper.deleteTempFiles(); + BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null); - for (UploadFile file : filesList) { - if (file.isCameraPhoto()) { - TakePhoto.galleryAddPic(context, file.getPhotoFile()); + for (UploadFile file : filesList) { + if (file.isCameraPhoto()) { + TakePhoto.galleryAddPic(context, file.getPhotoFile()); + } } + + uploadTitle.setText(null); + uploadFilename.setText(null); + hasModifiedFilename = false; + uploadDescription.setText(null); + filesList.clear(); + filesListView.removeAllViews(); + photoFileCreated = null; + progressBar.setVisibility(View.GONE); } - uploadTitle.setText(null); - uploadFilename.setText(null); - hasModifiedFilename = false; - uploadDescription.setText(null); - filesList.clear(); - filesListView.removeAllViews(); - photoFileCreated = null; - progressBar.setVisibility(View.GONE); - } + @Override + public void onCancelled(Context context, UploadInfo uploadInfo) { + Toast.makeText(context, "Upload canceled", Toast.LENGTH_SHORT).show(); - @Override - public void onCancelled(Context context, UploadInfo uploadInfo) { - Toast.makeText(context, "Upload canceled", Toast.LENGTH_SHORT).show(); + UploadsHelper.deleteTempFiles(); + progressBar.setVisibility(View.GONE); + } + }) + .startUpload(); + } catch (Exception exception) { + Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); + progressBar.setVisibility(View.GONE); + } + dialog.dismiss(); + }); - UploadsHelper.deleteTempFiles(); - progressBar.setVisibility(View.GONE); - } - }) - .startUpload(); - } catch (Exception exception) { - Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); + builder.setNegativeButton("NOPE", (dialog, which) -> { progressBar.setVisibility(View.GONE); - } + dialog.dismiss(); + }); + + AlertDialog alert = builder.create(); + alert.show(); }); if (uploadRootCategories.isEmpty()) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java index 6a736566..9ad789df 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java @@ -83,7 +83,7 @@ class UploadsHelper { @Nullable public static File createZipFile(Context context) { - // Create an image file name + // Create a zip file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date()); String zipFileName = "mThmmy_" + timeStamp + ".zip"; diff --git a/app/src/main/res/layout/activity_upload.xml b/app/src/main/res/layout/activity_upload.xml index 7aea59c3..507914f8 100644 --- a/app/src/main/res/layout/activity_upload.xml +++ b/app/src/main/res/layout/activity_upload.xml @@ -28,7 +28,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="top|start" - android:background="@color/background" + android:background="@color/primary_light" android:paddingEnd="@dimen/activity_horizontal_margin" android:paddingStart="@dimen/activity_horizontal_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" @@ -37,7 +37,7 @@ @@ -46,7 +46,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:background="@color/background" + android:background="@color/primary_light" android:orientation="vertical"> diff --git a/app/src/main/res/layout/activity_upload_fields_builder.xml b/app/src/main/res/layout/activity_upload_fields_builder.xml index af3daae6..9b748fe8 100644 --- a/app/src/main/res/layout/activity_upload_fields_builder.xml +++ b/app/src/main/res/layout/activity_upload_fields_builder.xml @@ -27,7 +27,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="top|start" - android:background="@color/background" + android:background="@color/primary_light" android:paddingEnd="@dimen/activity_horizontal_margin" android:paddingStart="@dimen/activity_horizontal_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" diff --git a/app/src/main/res/layout/activity_upload_filename_info_popup.xml b/app/src/main/res/layout/activity_upload_filename_info_popup.xml index 8b31440c..bb6a9704 100644 --- a/app/src/main/res/layout/activity_upload_filename_info_popup.xml +++ b/app/src/main/res/layout/activity_upload_filename_info_popup.xml @@ -3,6 +3,7 @@ android:id="@+id/upload_filename_info_text" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:background="@color/primary_light" android:linksClickable="true" android:padding="8dp" android:text="@string/upload_filename_info" diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index 29d0ef94..29bc9180 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -33,6 +33,6 @@ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c3bdac7a..abad71bb 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -18,6 +18,7 @@ #8B8B8B #FF9800 #FAA61A + #890d0d #FFFFFF #CCCCCC diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0e5ec576..d42f405f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -84,6 +84,6 @@