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;
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;
@ -24,7 +22,6 @@ import android.text.Spannable;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
@ -39,7 +36,6 @@ 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;
@ -312,7 +308,7 @@ public class UploadActivity extends BaseActivity {
}
if (!editTextFilename.matches("(.+\\.)+.+") ||
!FileUtils.getFilenameWithoutExtension(editTextFilename).
matches("[0-9a-zA-Z~!@#$%^&()_+=\\-`\\[\\]{};',.]+")) {
matches("[0-9a-zA-Zα-ωΑ-Ω~!@#$%^&()_+=\\-`\\[\\]{};',.]+")) {
uploadFilename.setError("Invalid filename");
shouldReturn = true;
}
@ -400,7 +396,7 @@ public class UploadActivity extends BaseActivity {
, "tp-dluploadfile")
.addParameter("tp_dluploadicon", fileIcon)
.addParameter("tp-uploaduser", uploaderProfileIndex)
.setNotificationConfig(new UploadNotificationConfig())
.setNotificationConfig(uploadNotificationConfig)
.setMaxRetries(2)
.setDelegate(new UploadStatusDelegate() {
@Override
@ -411,14 +407,14 @@ public class UploadActivity extends BaseActivity {
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) {
Toast.makeText(context, "Upload failed", Toast.LENGTH_SHORT).show();
UploadsHelper.deleteTempFiles();
UploadsHelper.deleteTempFiles(storage);
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();
UploadsHelper.deleteTempFiles(storage);
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null);
for (UploadFile file : filesList) {
@ -441,7 +437,7 @@ public class UploadActivity extends BaseActivity {
public void onCancelled(Context context, UploadInfo uploadInfo) {
Toast.makeText(context, "Upload canceled", Toast.LENGTH_SHORT).show();
UploadsHelper.deleteTempFiles();
UploadsHelper.deleteTempFiles(storage);
progressBar.setVisibility(View.GONE);
}
})
@ -459,6 +455,10 @@ public class UploadActivity extends BaseActivity {
});
AlertDialog alert = builder.create();
alert.setOnCancelListener(dialog -> {
progressBar.setVisibility(View.GONE);
dialog.dismiss();
});
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) {
LayoutInflater layoutInflater = getLayoutInflater();
LinearLayout newFileRow = (LinearLayout) layoutInflater.
@ -859,34 +889,4 @@ public class UploadActivity extends BaseActivity {
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";
private String course, semester;
private boolean isValidYear;
private LinearLayout semesterChooserLinear;
private RadioGroup typeRadio, semesterRadio;
@ -38,18 +39,17 @@ public class UploadFieldsBuilderActivity extends AppCompatActivity {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String working = s.toString();
boolean isValid;
if (working.length() == 4) {
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
int inputYear = Integer.parseInt(working);
isValid = inputYear <= currentYear && inputYear > 2000;
isValidYear = inputYear <= currentYear && inputYear > 1980;
} else {
isValid = false;
isValidYear = false;
}
if (!isValid) {
if (!isValidYear) {
year.setError("Please enter a valid year");
} else {
year.setError(null);
@ -121,8 +121,8 @@ public class UploadFieldsBuilderActivity extends AppCompatActivity {
} else if (semesterChooserLinear.getVisibility() == View.VISIBLE && semesterId == -1) {
Toast.makeText(view.getContext(), "Please choose a semester for the upload", Toast.LENGTH_SHORT).show();
return;
} else if (year.getText().toString().isEmpty()) {
Toast.makeText(view.getContext(), "Please choose a year for the upload", Toast.LENGTH_SHORT).show();
} else if (year.getText().toString().isEmpty() || !isValidYear) {
Toast.makeText(view.getContext(), "Please choose a valid year for the upload", Toast.LENGTH_SHORT).show();
return;
}

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

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

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

@ -32,7 +32,7 @@
</style>
<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:textAppearanceSmallPopupMenu">@color/accent</item>
</style>

Loading…
Cancel
Save