Browse Source

Background colors change, Invalid filenames won't upload, Change uploads notification icon

uploads
Apostolos Fanakis 6 years ago
parent
commit
3a9275b13d
  1. 38
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java
  3. 8
      app/src/main/res/layout/activity_upload.xml
  4. 2
      app/src/main/res/layout/activity_upload_fields_builder.xml
  5. 1
      app/src/main/res/layout/activity_upload_filename_info_popup.xml
  6. 2
      app/src/main/res/values-v21/styles.xml
  7. 1
      app/src/main/res/values/colors.xml
  8. 2
      app/src/main/res/values/styles.xml

38
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,10 +322,14 @@ public class UploadActivity extends BaseActivity {
}
}
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 += uploadedFromThmmyPromptHtml;
uploadDescriptionText[0] += uploadedFromThmmyPromptHtml;
}
Uri tempFileUri = null;
@ -371,11 +380,20 @@ public class UploadActivity extends BaseActivity {
}
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)
.addParameter("tp-dluploadtext", uploadDescriptionText[0])
.addFileToUpload(tempFileUri == null
? filesList.get(0).getFileUri().toString()
: tempFileUri.toString()
@ -432,6 +450,16 @@ public class UploadActivity extends BaseActivity {
Timber.e(exception, "AndroidUploadService: %s", exception.getMessage());
progressBar.setVisibility(View.GONE);
}
dialog.dismiss();
});
builder.setNegativeButton("NOPE", (dialog, which) -> {
progressBar.setVisibility(View.GONE);
dialog.dismiss();
});
AlertDialog alert = builder.create();
alert.show();
});
if (uploadRootCategories.isEmpty()) {

2
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";

8
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 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:background="@color/primary_light"
android:focusableInTouchMode="true"
android:orientation="vertical">
@ -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">
<gr.thmmy.mthmmy.utils.AppCompatSpinnerWithoutDefault
@ -100,7 +100,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="12dp"
android:background="@color/background"
android:theme="@style/LightBackgroundColoredButton"
app:srcCompat="@drawable/ic_info_outline_white_24dp" />
</LinearLayout>

2
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"

1
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"

2
app/src/main/res/values-v21/styles.xml

@ -33,6 +33,6 @@
</style>
<style name="LightBackgroundColoredButton" parent="Widget.AppCompat.ImageButton">
<item name="android:colorButtonNormal">@color/background</item>
<item name="android:colorButtonNormal">@color/primary_light</item>
</style>
</resources>

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

@ -18,6 +18,7 @@
<color name="divider">#8B8B8B</color>
<color name="link_color">#FF9800</color>
<color name="mention_color">#FAA61A</color>
<color name="error_red">#890d0d</color>
<color name="white">#FFFFFF</color>
<color name="iron">#CCCCCC</color>

2
app/src/main/res/values/styles.xml

@ -84,6 +84,6 @@
</style>
<style name="LightBackgroundColoredButton" parent="Widget.AppCompat.ImageButton">
<item name="colorButtonNormal">@color/background</item>
<item name="colorButtonNormal">@color/primary_light</item>
</style>
</resources>

Loading…
Cancel
Save