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. 22
      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";
textWatcher.setFileExtension(".zip");
if (!hasModifiedFilename) {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date());
String zipFilename = "mTHMMY_" + timeStamp + ".zip";
uploadFilename.setText(zipFilename);
hasModifiedFilename = false;
}
if (!hasModifiedFilename)
setZipUploadFilename();
for (int fileIndex = 0; fileIndex < data.getClipData().getItemCount(); ++fileIndex) {
Uri newFileUri = data.getClipData().getItemAt(fileIndex).getUri();
@ -506,12 +502,8 @@ public class UploadActivity extends BaseActivity {
fileIcon = "archive.gif";
textWatcher.setFileExtension(".zip");
if (!hasModifiedFilename) {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date());
String zipFilename = "mTHMMY_" + timeStamp + ".zip";
uploadFilename.setText(zipFilename);
hasModifiedFilename = false;
}
if (!hasModifiedFilename)
setZipUploadFilename();
}
addFileViewToList(filename);
@ -538,12 +530,8 @@ public class UploadActivity extends BaseActivity {
fileIcon = "archive.gif";
textWatcher.setFileExtension(".zip");
if (!hasModifiedFilename) {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date());
String zipFilename = "mTHMMY_" + timeStamp + ".zip";
uploadFilename.setText(zipFilename);
hasModifiedFilename = false;
}
if (!hasModifiedFilename)
setZipUploadFilename();
}
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
private void takePhoto() {
// Create the File where the photo should go
@ -768,8 +763,7 @@ public class UploadActivity extends BaseActivity {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override
public void afterTextChanged(Editable s) {
@ -951,7 +945,7 @@ public class UploadActivity extends BaseActivity {
if(foundUploadsCourse != null){
uploadsCourse = foundUploadsCourse;
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);
return;
}

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

@ -1,16 +1,21 @@
package gr.thmmy.mthmmy.activities.upload;
import android.os.Bundle;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import gr.thmmy.mthmmy.base.BaseApplication;
import timber.log.Timber;
public class UploadsCourse {
class UploadsCourse {
private String name;
private String minifiedName;
private String greeklishName;
public UploadsCourse(String fullName, String minifiedName, String greeklishName) {
private UploadsCourse(String fullName, String minifiedName, String greeklishName) {
this.name = fullName;
this.minifiedName = minifiedName;
this.greeklishName = greeklishName;
@ -41,7 +46,6 @@ public class UploadsCourse {
static UploadsCourse findCourse(String retrievedCourse,
Map<String, UploadsCourse> uploadsCourses){
retrievedCourse = normalizeGreekNumbers(retrievedCourse);
Timber.w("AAAAAAAA %s",retrievedCourse);
UploadsCourse uploadsCourse = uploadsCourses.get(retrievedCourse);
if(uploadsCourse != null) return uploadsCourse;
@ -54,13 +58,20 @@ public class UploadsCourse {
if(foundKey==null){
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);
}
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();
}
}

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

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

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

@ -32,7 +32,7 @@ import timber.log.Timber;
public class TakePhoto {
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
public static Intent getIntent(Context context, @NonNull File photoFile) {
@ -81,10 +81,10 @@ public class TakePhoto {
public static File createImageFile(Context context) {
// Create an image file name
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.separator + "mThmmy");
File.separator + "mTHMMY");
if (!imageFolder.exists()) {
if (!imageFolder.mkdirs()) {

Loading…
Cancel
Save