Browse Source

Uploads improvements & fixes

pull/63/head
Ezerous 6 years ago
parent
commit
6a76d7e399
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 36
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  2. 21
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsCourse.java
  3. 28
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java
  4. 3
      app/src/main/java/gr/thmmy/mthmmy/utils/CrashReportingTree.java
  5. 6
      app/src/main/java/gr/thmmy/mthmmy/utils/TakePhoto.java

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

@ -457,12 +457,8 @@ public class UploadActivity extends BaseActivity {
fileIcon = "archive.gif"; fileIcon = "archive.gif";
textWatcher.setFileExtension(".zip"); textWatcher.setFileExtension(".zip");
if (!hasModifiedFilename) { if (!hasModifiedFilename)
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date()); setZipUploadFilename();
String zipFilename = "mTHMMY_" + timeStamp + ".zip";
uploadFilename.setText(zipFilename);
hasModifiedFilename = false;
}
for (int fileIndex = 0; fileIndex < data.getClipData().getItemCount(); ++fileIndex) { for (int fileIndex = 0; fileIndex < data.getClipData().getItemCount(); ++fileIndex) {
Uri newFileUri = data.getClipData().getItemAt(fileIndex).getUri(); Uri newFileUri = data.getClipData().getItemAt(fileIndex).getUri();
@ -506,12 +502,8 @@ public class UploadActivity extends BaseActivity {
fileIcon = "archive.gif"; fileIcon = "archive.gif";
textWatcher.setFileExtension(".zip"); textWatcher.setFileExtension(".zip");
if (!hasModifiedFilename) { if (!hasModifiedFilename)
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date()); setZipUploadFilename();
String zipFilename = "mTHMMY_" + timeStamp + ".zip";
uploadFilename.setText(zipFilename);
hasModifiedFilename = false;
}
} }
addFileViewToList(filename); addFileViewToList(filename);
@ -538,12 +530,8 @@ public class UploadActivity extends BaseActivity {
fileIcon = "archive.gif"; fileIcon = "archive.gif";
textWatcher.setFileExtension(".zip"); textWatcher.setFileExtension(".zip");
if (!hasModifiedFilename) { if (!hasModifiedFilename)
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date()); setZipUploadFilename();
String zipFilename = "mTHMMY_" + timeStamp + ".zip";
uploadFilename.setText(zipFilename);
hasModifiedFilename = false;
}
} }
UploadFile newFile = new UploadFile(true, TakePhoto.processResult(this, UploadFile newFile = new UploadFile(true, TakePhoto.processResult(this,
@ -599,6 +587,13 @@ public class UploadActivity extends BaseActivity {
} }
} }
private void setZipUploadFilename(){
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date());
String zipFilename = "mTHMMY_" + timeStamp + ".zip";
uploadFilename.setText(zipFilename);
hasModifiedFilename = false;
}
// Should only be called after making sure permissions are granted // Should only be called after making sure permissions are granted
private void takePhoto() { private void takePhoto() {
// Create the File where the photo should go // Create the File where the photo should go
@ -768,8 +763,7 @@ public class UploadActivity extends BaseActivity {
} }
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) { }
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
@ -951,7 +945,7 @@ public class UploadActivity extends BaseActivity {
if(foundUploadsCourse != null){ if(foundUploadsCourse != null){
uploadsCourse = foundUploadsCourse; uploadsCourse = foundUploadsCourse;
semester = retrievedSemester; semester = retrievedSemester;
Timber.i("Selected course: %s, semester: %s", uploadsCourse.getName(), semester); Timber.d("Selected course: %s, semester: %s", uploadsCourse.getName(), semester);
titleDescriptionBuilderButton.setEnabled(true); titleDescriptionBuilderButton.setEnabled(true);
return; return;
} }

21
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsCourse.java

@ -1,16 +1,21 @@
package gr.thmmy.mthmmy.activities.upload; package gr.thmmy.mthmmy.activities.upload;
import android.os.Bundle;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import gr.thmmy.mthmmy.base.BaseApplication;
import timber.log.Timber; import timber.log.Timber;
public class UploadsCourse { class UploadsCourse {
private String name; private String name;
private String minifiedName; private String minifiedName;
private String greeklishName; private String greeklishName;
public UploadsCourse(String fullName, String minifiedName, String greeklishName) { private UploadsCourse(String fullName, String minifiedName, String greeklishName) {
this.name = fullName; this.name = fullName;
this.minifiedName = minifiedName; this.minifiedName = minifiedName;
this.greeklishName = greeklishName; this.greeklishName = greeklishName;
@ -41,7 +46,6 @@ public class UploadsCourse {
static UploadsCourse findCourse(String retrievedCourse, static UploadsCourse findCourse(String retrievedCourse,
Map<String, UploadsCourse> uploadsCourses){ Map<String, UploadsCourse> uploadsCourses){
retrievedCourse = normalizeGreekNumbers(retrievedCourse); retrievedCourse = normalizeGreekNumbers(retrievedCourse);
Timber.w("AAAAAAAA %s",retrievedCourse);
UploadsCourse uploadsCourse = uploadsCourses.get(retrievedCourse); UploadsCourse uploadsCourse = uploadsCourses.get(retrievedCourse);
if(uploadsCourse != null) return uploadsCourse; if(uploadsCourse != null) return uploadsCourse;
@ -54,13 +58,20 @@ public class UploadsCourse {
if(foundKey==null){ if(foundKey==null){
Timber.w("Couldn't find course that matches %s", retrievedCourse); Timber.w("Couldn't find course that matches %s", retrievedCourse);
//TODO: report to Firebase for a new Course Bundle bundle = new Bundle();
bundle.putString("COURSE_NAME", retrievedCourse);
BaseApplication.getInstance().logFirebaseAnalyticsEvent("UNSUPPORTED_UPLOADS_COURSE", bundle);
} }
return uploadsCourses.get(foundKey); return uploadsCourses.get(foundKey);
} }
private static String normalizeGreekNumbers(String stringWithGreekNumbers) { private static String normalizeGreekNumbers(String stringWithGreekNumbers) {
return stringWithGreekNumbers.replaceAll("Ι", "I"); StringBuilder normalizedStrBuilder = new StringBuilder(stringWithGreekNumbers);
Pattern pattern = Pattern.compile("(Ι+)(?:\\s|\\(|\\)|$)");
Matcher matcher = pattern.matcher(stringWithGreekNumbers);
while (matcher.find())
normalizedStrBuilder.replace(matcher.start(1), matcher.end(1), matcher.group(1).replaceAll("Ι", "I"));
return normalizedStrBuilder.toString();
} }
} }

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

@ -25,26 +25,24 @@ import gr.thmmy.mthmmy.utils.FileUtils;
import timber.log.Timber; import timber.log.Timber;
public class UploadsHelper { public class UploadsHelper {
private final static int BUFFER = 4096; private static final int BUFFER = 4096;
private static final String TEMP_FILES_DIRECTORY = "~tmp_mThmmy_uploads"; private static final String TEMP_FILES_DIRECTORY = "~tmp_mTHMMY_uploads";
@SuppressWarnings("ResultOfMethodCallIgnored") @SuppressWarnings("ResultOfMethodCallIgnored")
@Nullable @Nullable
static Uri createTempFile(Context context, Storage storage, Uri fileUri, String newFilename) { static Uri createTempFile(Context context, Storage storage, Uri fileUri, String newFilename) {
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 + TEMP_FILES_DIRECTORY + 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 + TEMP_FILES_DIRECTORY); File.separatorChar + TEMP_FILES_DIRECTORY);
if (!tempDirectory.exists()) { if (!tempDirectory.exists() && !tempDirectory.mkdirs()) {
if (!tempDirectory.mkdirs()) { Timber.w("Temporary directory build returned false in %s", UploadActivity.class.getSimpleName());
Timber.w("Temporary directory build returned false in %s", UploadActivity.class.getSimpleName()); Toast.makeText(context, "Couldn't create temporary directory", Toast.LENGTH_SHORT).show();
Toast.makeText(context, "Couldn't create temporary directory", Toast.LENGTH_SHORT).show(); return null;
return null;
}
} }
InputStream inputStream; InputStream inputStream;
@ -82,28 +80,26 @@ public class UploadsHelper {
} }
@Nullable @Nullable
public static File createZipFile(@NonNull String zipFilename) { static File createZipFile(@NonNull String zipFilename) {
// Create a zip file name // Create a zip file name
File zipFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + File zipFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) +
File.separator + "mThmmy"); File.separator + "mTHMMY");
if (!zipFolder.exists()) { if (!zipFolder.exists() && !zipFolder.mkdirs()) {
if (!zipFolder.mkdirs()) {
Timber.w("Zip folder build returned false in %s", UploadsHelper.class.getSimpleName()); Timber.w("Zip folder build returned false in %s", UploadsHelper.class.getSimpleName());
return null; return null;
}
} }
return new File(zipFolder, zipFilename); return new File(zipFolder, zipFilename);
} }
public static void zip(Context context, Uri[] files, Uri zipFile) { static void zip(Context context, Uri[] files, Uri zipFile) {
try { try {
BufferedInputStream origin; BufferedInputStream origin;
OutputStream dest = context.getContentResolver().openOutputStream(zipFile); OutputStream dest = context.getContentResolver().openOutputStream(zipFile);
assert dest != null; assert dest != null;
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
byte data[] = new byte[BUFFER]; byte[] data = new byte[BUFFER];
for (Uri file : files) { for (Uri file : files) {
InputStream inputStream = context.getContentResolver().openInputStream(file); InputStream inputStream = context.getContentResolver().openInputStream(file);

3
app/src/main/java/gr/thmmy/mthmmy/utils/CrashReportingTree.java

@ -27,8 +27,7 @@ public class CrashReportingTree extends DebugTree {
Crashlytics.log(level + "/" + tag + ": " + message); Crashlytics.log(level + "/" + tag + ": " + message);
if(priority == Log.ERROR) if(priority == Log.ERROR) {
{
if (t!=null) if (t!=null)
Crashlytics.logException(t); Crashlytics.logException(t);
else else

6
app/src/main/java/gr/thmmy/mthmmy/utils/TakePhoto.java

@ -32,7 +32,7 @@ import timber.log.Timber;
public class TakePhoto { public class TakePhoto {
private static final int DEFAULT_MIN_WIDTH_QUALITY = 400; private static final int DEFAULT_MIN_WIDTH_QUALITY = 400;
private static final String IMAGE_CONTENT_DESCRIPTION = "mThmmy uploads image"; private static final String IMAGE_CONTENT_DESCRIPTION = "mTHMMY uploads image";
@Nullable @Nullable
public static Intent getIntent(Context context, @NonNull File photoFile) { public static Intent getIntent(Context context, @NonNull File photoFile) {
@ -81,10 +81,10 @@ public class TakePhoto {
public static File createImageFile(Context context) { public static File createImageFile(Context context) {
// Create an image file name // Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date()); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date());
String imageFileName = "mThmmy_" + timeStamp + ".jpg"; String imageFileName = "mTHMMY_" + timeStamp + ".jpg";
File imageFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File imageFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) +
File.separator + "mThmmy"); File.separator + "mTHMMY");
if (!imageFolder.exists()) { if (!imageFolder.exists()) {
if (!imageFolder.mkdirs()) { if (!imageFolder.mkdirs()) {

Loading…
Cancel
Save