Browse Source

Greek filenames are upload-able but produce a warning, Notifications fix, Generator date range fix, Upload dialog fix for back button

uploads
Apostolos Fanakis 6 years ago
parent
commit
d9cb25adb4
  1. 78
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  2. 12
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java
  3. 19
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java
  4. 2
      app/src/main/res/values/styles.xml

78
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java

@ -1,9 +1,7 @@
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;
@ -24,7 +22,6 @@ import android.text.Spannable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -39,7 +36,6 @@ 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;
@ -312,7 +308,7 @@ public class UploadActivity extends BaseActivity {
} }
if (!editTextFilename.matches("(.+\\.)+.+") || if (!editTextFilename.matches("(.+\\.)+.+") ||
!FileUtils.getFilenameWithoutExtension(editTextFilename). !FileUtils.getFilenameWithoutExtension(editTextFilename).
matches("[0-9a-zA-Z~!@#$%^&()_+=\\-`\\[\\]{};',.]+")) { matches("[0-9a-zA-Zα-ωΑ-Ω~!@#$%^&()_+=\\-`\\[\\]{};',.]+")) {
uploadFilename.setError("Invalid filename"); uploadFilename.setError("Invalid filename");
shouldReturn = true; shouldReturn = true;
} }
@ -400,7 +396,7 @@ public class UploadActivity extends BaseActivity {
, "tp-dluploadfile") , "tp-dluploadfile")
.addParameter("tp_dluploadicon", fileIcon) .addParameter("tp_dluploadicon", fileIcon)
.addParameter("tp-uploaduser", uploaderProfileIndex) .addParameter("tp-uploaduser", uploaderProfileIndex)
.setNotificationConfig(new UploadNotificationConfig()) .setNotificationConfig(uploadNotificationConfig)
.setMaxRetries(2) .setMaxRetries(2)
.setDelegate(new UploadStatusDelegate() { .setDelegate(new UploadStatusDelegate() {
@Override @Override
@ -411,14 +407,14 @@ public class UploadActivity extends BaseActivity {
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) { Exception exception) {
Toast.makeText(context, "Upload failed", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Upload failed", Toast.LENGTH_SHORT).show();
UploadsHelper.deleteTempFiles(); UploadsHelper.deleteTempFiles(storage);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }
@Override @Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
Toast.makeText(context, "Upload completed successfully", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Upload completed successfully", Toast.LENGTH_SHORT).show();
UploadsHelper.deleteTempFiles(); UploadsHelper.deleteTempFiles(storage);
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null); BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null);
for (UploadFile file : filesList) { for (UploadFile file : filesList) {
@ -441,7 +437,7 @@ public class UploadActivity extends BaseActivity {
public void onCancelled(Context context, UploadInfo uploadInfo) { public void onCancelled(Context context, UploadInfo uploadInfo) {
Toast.makeText(context, "Upload canceled", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Upload canceled", Toast.LENGTH_SHORT).show();
UploadsHelper.deleteTempFiles(); UploadsHelper.deleteTempFiles(storage);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }
}) })
@ -459,6 +455,10 @@ public class UploadActivity extends BaseActivity {
}); });
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.setOnCancelListener(dialog -> {
progressBar.setVisibility(View.GONE);
dialog.dismiss();
});
alert.show(); alert.show();
}); });
@ -629,6 +629,36 @@ public class UploadActivity extends BaseActivity {
} }
} }
private void updateUIElements() {
String[] tmpSpinnerArray = new String[uploadRootCategories.size()];
for (int i = 0; i < uploadRootCategories.size(); ++i) {
tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle();
}
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(BaseApplication.getInstance().getApplicationContext(),
R.layout.spinner_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
rootCategorySpinner.setAdapter(spinnerArrayAdapter);
//Sets bundle selection
if (bundleCategory != null) {
int bundleSelectionIndex = -1, currentIndex = 0;
for (UploadCategory category : uploadRootCategories) {
if (bundleCategory.get(0).contains(category.getCategoryTitle())) {
bundleSelectionIndex = currentIndex;
break;
}
++currentIndex;
}
if (bundleSelectionIndex != -1) {
rootCategorySpinner.setSelection(bundleSelectionIndex, true);
bundleCategory.remove(0);
}
}
}
private void addFileViewToList(String filename) { private void addFileViewToList(String filename) {
LayoutInflater layoutInflater = getLayoutInflater(); LayoutInflater layoutInflater = getLayoutInflater();
LinearLayout newFileRow = (LinearLayout) layoutInflater. LinearLayout newFileRow = (LinearLayout) layoutInflater.
@ -859,34 +889,4 @@ public class UploadActivity extends BaseActivity {
progressBar.setVisibility(ProgressBar.GONE); progressBar.setVisibility(ProgressBar.GONE);
} }
} }
private void updateUIElements() {
String[] tmpSpinnerArray = new String[uploadRootCategories.size()];
for (int i = 0; i < uploadRootCategories.size(); ++i) {
tmpSpinnerArray[i] = uploadRootCategories.get(i).getCategoryTitle();
}
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(BaseApplication.getInstance().getApplicationContext(),
R.layout.spinner_item, tmpSpinnerArray);
spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
rootCategorySpinner.setAdapter(spinnerArrayAdapter);
//Sets bundle selection
if (bundleCategory != null) {
int bundleSelectionIndex = -1, currentIndex = 0;
for (UploadCategory category : uploadRootCategories) {
if (bundleCategory.get(0).contains(category.getCategoryTitle())) {
bundleSelectionIndex = currentIndex;
break;
}
++currentIndex;
}
if (bundleSelectionIndex != -1) {
rootCategorySpinner.setSelection(bundleSelectionIndex, true);
bundleCategory.remove(0);
}
}
}
} }

12
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java

@ -28,6 +28,7 @@ public class UploadFieldsBuilderActivity extends AppCompatActivity {
static final String RESULT_DESCRIPTION = "RESULT_DESCRIPTION"; static final String RESULT_DESCRIPTION = "RESULT_DESCRIPTION";
private String course, semester; private String course, semester;
private boolean isValidYear;
private LinearLayout semesterChooserLinear; private LinearLayout semesterChooserLinear;
private RadioGroup typeRadio, semesterRadio; private RadioGroup typeRadio, semesterRadio;
@ -38,18 +39,17 @@ public class UploadFieldsBuilderActivity extends AppCompatActivity {
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
String working = s.toString(); String working = s.toString();
boolean isValid;
if (working.length() == 4) { if (working.length() == 4) {
int currentYear = Calendar.getInstance().get(Calendar.YEAR); int currentYear = Calendar.getInstance().get(Calendar.YEAR);
int inputYear = Integer.parseInt(working); int inputYear = Integer.parseInt(working);
isValid = inputYear <= currentYear && inputYear > 2000; isValidYear = inputYear <= currentYear && inputYear > 1980;
} else { } else {
isValid = false; isValidYear = false;
} }
if (!isValid) { if (!isValidYear) {
year.setError("Please enter a valid year"); year.setError("Please enter a valid year");
} else { } else {
year.setError(null); year.setError(null);
@ -121,8 +121,8 @@ public class UploadFieldsBuilderActivity extends AppCompatActivity {
} else if (semesterChooserLinear.getVisibility() == View.VISIBLE && semesterId == -1) { } else if (semesterChooserLinear.getVisibility() == View.VISIBLE && semesterId == -1) {
Toast.makeText(view.getContext(), "Please choose a semester for the upload", Toast.LENGTH_SHORT).show(); Toast.makeText(view.getContext(), "Please choose a semester for the upload", Toast.LENGTH_SHORT).show();
return; return;
} else if (year.getText().toString().isEmpty()) { } else if (year.getText().toString().isEmpty() || !isValidYear) {
Toast.makeText(view.getContext(), "Please choose a year for the upload", Toast.LENGTH_SHORT).show(); Toast.makeText(view.getContext(), "Please choose a valid year for the upload", Toast.LENGTH_SHORT).show();
return; return;
} }

19
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java

@ -27,6 +27,7 @@ import timber.log.Timber;
class UploadsHelper { class UploadsHelper {
private final static int BUFFER = 4096; private final static int BUFFER = 4096;
private static final String TEMP_FILES_DIRECTORY = "~tmp_mThmmy_uploads";
@SuppressWarnings("ResultOfMethodCallIgnored") @SuppressWarnings("ResultOfMethodCallIgnored")
@Nullable @Nullable
@ -34,10 +35,10 @@ class UploadsHelper {
String oldFilename = FileUtils.filenameFromUri(context, fileUri); String oldFilename = FileUtils.filenameFromUri(context, fileUri);
String fileExtension = oldFilename.substring(oldFilename.indexOf(".")); String fileExtension = oldFilename.substring(oldFilename.indexOf("."));
String destinationFilename = Environment.getExternalStorageDirectory().getPath() + String destinationFilename = Environment.getExternalStorageDirectory().getPath() +
File.separatorChar + "~tmp_mThmmy_uploads" + File.separatorChar + newFilename + fileExtension; File.separatorChar + TEMP_FILES_DIRECTORY + File.separatorChar + newFilename + fileExtension;
File tempDirectory = new File(android.os.Environment.getExternalStorageDirectory().getPath() + File tempDirectory = new File(android.os.Environment.getExternalStorageDirectory().getPath() +
File.separatorChar + "~tmp_mThmmy_uploads"); File.separatorChar + TEMP_FILES_DIRECTORY);
if (!tempDirectory.exists()) { if (!tempDirectory.exists()) {
if (!tempDirectory.mkdirs()) { if (!tempDirectory.mkdirs()) {
@ -130,17 +131,15 @@ class UploadsHelper {
} }
} }
@SuppressWarnings("ResultOfMethodCallIgnored") static void deleteTempFiles(Storage storage) {
static void deleteTempFiles() {
File tempFilesDirectory = new File(Environment.getExternalStorageDirectory().getPath() + File tempFilesDirectory = new File(Environment.getExternalStorageDirectory().getPath() +
File.separatorChar + "~tmp_mThmmy_uploads"); File.separatorChar + TEMP_FILES_DIRECTORY);
if (tempFilesDirectory.isDirectory()) { if (storage.isDirectoryExists(tempFilesDirectory.getAbsolutePath())) {
String[] tempFilesArray = tempFilesDirectory.list(); for (File tempFile : storage.getFiles(tempFilesDirectory.getAbsolutePath())) {
for (String tempFile : tempFilesArray) { storage.deleteFile(tempFile.getAbsolutePath());
new File(tempFilesDirectory, tempFile).delete();
} }
tempFilesDirectory.delete(); storage.deleteDirectory(tempFilesDirectory.getAbsolutePath());
} }
} }
} }

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

@ -32,7 +32,7 @@
</style> </style>
<style name="PopupMenuStyle"> <style name="PopupMenuStyle">
<item name="android:popupBackground">@color/primary</item> <item name="android:popupBackground">@color/primary_light</item>
<item name="android:textAppearanceLargePopupMenu">@color/accent</item> <item name="android:textAppearanceLargePopupMenu">@color/accent</item>
<item name="android:textAppearanceSmallPopupMenu">@color/accent</item> <item name="android:textAppearanceSmallPopupMenu">@color/accent</item>
</style> </style>

Loading…
Cancel
Save