|
@ -1,7 +1,9 @@ |
|
|
package gr.thmmy.mthmmy.activities.upload; |
|
|
package gr.thmmy.mthmmy.activities.upload; |
|
|
|
|
|
|
|
|
import android.app.Activity; |
|
|
import android.app.Activity; |
|
|
|
|
|
import android.app.PendingIntent; |
|
|
import android.content.Context; |
|
|
import android.content.Context; |
|
|
|
|
|
import android.content.DialogInterface; |
|
|
import android.content.Intent; |
|
|
import android.content.Intent; |
|
|
import android.content.SharedPreferences; |
|
|
import android.content.SharedPreferences; |
|
|
import android.content.pm.PackageManager; |
|
|
import android.content.pm.PackageManager; |
|
@ -12,6 +14,7 @@ import android.os.Bundle; |
|
|
import android.support.annotation.NonNull; |
|
|
import android.support.annotation.NonNull; |
|
|
import android.support.design.widget.FloatingActionButton; |
|
|
import android.support.design.widget.FloatingActionButton; |
|
|
import android.support.v4.content.FileProvider; |
|
|
import android.support.v4.content.FileProvider; |
|
|
|
|
|
import android.support.v7.app.AlertDialog; |
|
|
import android.support.v7.content.res.AppCompatResources; |
|
|
import android.support.v7.content.res.AppCompatResources; |
|
|
import android.support.v7.preference.PreferenceManager; |
|
|
import android.support.v7.preference.PreferenceManager; |
|
|
import android.support.v7.widget.AppCompatButton; |
|
|
import android.support.v7.widget.AppCompatButton; |
|
@ -36,6 +39,7 @@ import android.widget.Toast; |
|
|
import net.gotev.uploadservice.MultipartUploadRequest; |
|
|
import net.gotev.uploadservice.MultipartUploadRequest; |
|
|
import net.gotev.uploadservice.ServerResponse; |
|
|
import net.gotev.uploadservice.ServerResponse; |
|
|
import net.gotev.uploadservice.UploadInfo; |
|
|
import net.gotev.uploadservice.UploadInfo; |
|
|
|
|
|
import net.gotev.uploadservice.UploadNotificationAction; |
|
|
import net.gotev.uploadservice.UploadNotificationConfig; |
|
|
import net.gotev.uploadservice.UploadNotificationConfig; |
|
|
import net.gotev.uploadservice.UploadStatusDelegate; |
|
|
import net.gotev.uploadservice.UploadStatusDelegate; |
|
|
|
|
|
|
|
@ -232,7 +236,6 @@ public class UploadActivity extends BaseActivity { |
|
|
popUp.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); |
|
|
popUp.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); |
|
|
popUp.setFocusable(true); |
|
|
popUp.setFocusable(true); |
|
|
|
|
|
|
|
|
//((TextView) popUpContent.findViewById(R.id.upload_filename_info_text)).setTe
|
|
|
|
|
|
((TextView) popUpContent.findViewById(R.id.upload_filename_info_text)). |
|
|
((TextView) popUpContent.findViewById(R.id.upload_filename_info_text)). |
|
|
setMovementMethod(LinkMovementMethod.getInstance()); |
|
|
setMovementMethod(LinkMovementMethod.getInstance()); |
|
|
//Displays the popup
|
|
|
//Displays the popup
|
|
@ -279,7 +282,7 @@ public class UploadActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
String uploadTitleText = uploadTitle.getText().toString(); |
|
|
String uploadTitleText = uploadTitle.getText().toString(); |
|
|
String editTextFilename = uploadFilename.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
|
|
|
//Checks if all required fields are filled
|
|
|
{ |
|
|
{ |
|
@ -307,7 +310,9 @@ public class UploadActivity extends BaseActivity { |
|
|
shouldReturn = true; |
|
|
shouldReturn = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (!editTextFilename.matches("(.+\\.)+.+")) { |
|
|
if (!editTextFilename.matches("(.+\\.)+.+") || |
|
|
|
|
|
!FileUtils.getFilenameWithoutExtension(editTextFilename). |
|
|
|
|
|
matches("[0-9a-zA-Z~!@#$%^&()_+=\\-`\\[\\]{};',.]+")) { |
|
|
uploadFilename.setError("Invalid filename"); |
|
|
uploadFilename.setError("Invalid filename"); |
|
|
shouldReturn = true; |
|
|
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
|
|
|
//Checks settings and possibly adds "Uploaded from mTHMMY" string to description
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(view.getContext()); |
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(view.getContext()); |
|
|
if (sharedPrefs.getBoolean(UPLOADING_APP_SIGNATURE_ENABLE_KEY, true)) { |
|
|
if (sharedPrefs.getBoolean(UPLOADING_APP_SIGNATURE_ENABLE_KEY, true)) { |
|
|
uploadDescriptionText += uploadedFromThmmyPromptHtml; |
|
|
uploadDescriptionText[0] += uploadedFromThmmyPromptHtml; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Uri tempFileUri = null; |
|
|
Uri tempFileUri = null; |
|
@ -371,11 +380,20 @@ public class UploadActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
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) |
|
|
new MultipartUploadRequest(view.getContext(), uploadIndexUrl) |
|
|
.setUtf8Charset() |
|
|
.setUtf8Charset() |
|
|
|
|
|
.setNotificationConfig(uploadNotificationConfig) |
|
|
.addParameter("tp-dluploadtitle", uploadTitleText) |
|
|
.addParameter("tp-dluploadtitle", uploadTitleText) |
|
|
.addParameter("tp-dluploadcat", categorySelected) |
|
|
.addParameter("tp-dluploadcat", categorySelected) |
|
|
.addParameter("tp-dluploadtext", uploadDescriptionText) |
|
|
.addParameter("tp-dluploadtext", uploadDescriptionText[0]) |
|
|
.addFileToUpload(tempFileUri == null |
|
|
.addFileToUpload(tempFileUri == null |
|
|
? filesList.get(0).getFileUri().toString() |
|
|
? filesList.get(0).getFileUri().toString() |
|
|
: tempFileUri.toString() |
|
|
: tempFileUri.toString() |
|
@ -432,6 +450,16 @@ public class UploadActivity extends BaseActivity { |
|
|
Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); |
|
|
Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); |
|
|
progressBar.setVisibility(View.GONE); |
|
|
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()) { |
|
|
if (uploadRootCategories.isEmpty()) { |
|
|