Skip to content

Commit

Permalink
Convert Kotlin code to Java, fix temporary file name
Browse files Browse the repository at this point in the history
  • Loading branch information
whym committed Mar 2, 2019
1 parent 1c1b57a commit 645bc8f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,10 @@ public Single<UploadStash> uploadFile(
if (errorCode.equals(ERROR_CODE_BAD_TOKEN)) {
ViewUtil.showLongToast(context, R.string.bad_token_error_proposed_solution);
}
return new UploadStash(resultStatus, errorCode, filename, "");
return new UploadStash(errorCode, resultStatus, filename, "");
} else {
String filekey = result.getString("/api/upload/@filekey");
return new UploadStash(resultStatus, "Success", filename, filekey);
return new UploadStash("", resultStatus, filename, filekey);
}
});
}
Expand Down
70 changes: 70 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/mwapi/UploadStash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package fr.free.nrw.commons.mwapi;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

public class UploadStash {
@NonNull
private String errorCode;
@NonNull
private String resultStatus;
@NonNull
private String filename;
@NonNull
private String filekey;

@NonNull
public final String getErrorCode() {
return this.errorCode;
}

@NonNull
public final String getResultStatus() {
return this.resultStatus;
}

@NonNull
public final String getFilename() {
return this.filename;
}

@NonNull
public final String getFilekey() {
return this.filekey;
}

public UploadStash(@NonNull String errorCode, @NonNull String resultStatus, @NonNull String filename, @NonNull String filekey) {
this.errorCode = errorCode;
this.resultStatus = resultStatus;
this.filename = filename;
this.filekey = filekey;
}

public String toString() {
return "UploadStash(errorCode=" + this.errorCode + ", resultStatus=" + this.resultStatus + ", filename=" + this.filename + ", filekey=" + this.filekey + ")";
}

public int hashCode() {
return ((this.errorCode.hashCode() * 31 + this.resultStatus.hashCode()
) * 31 + this.filename.hashCode()
) * 31 + this.filekey.hashCode();
}

public boolean equals(@Nullable Object obj) {
if (this != obj) {
if (obj instanceof UploadStash) {
UploadStash that = (UploadStash)obj;
if (this.errorCode.equals(that.errorCode)
&& this.resultStatus.equals(that.resultStatus)
&& this.filename.equals(that.filename)
&& this.filekey.equals(that.filekey)) {
return true;
}
}

return false;
} else {
return true;
}
}
}
8 changes: 0 additions & 8 deletions app/src/main/java/fr/free/nrw/commons/mwapi/UploadStash.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private void uploadContribution(Contribution contribution) {
getString(R.string.upload_progress_notification_title_finishing, contribution.getDisplayTitle()),
contribution
);
String stashFilename = filename + contribution.hashCode();
String stashFilename = "Temp_" + contribution.hashCode() + filename;
mwApi.uploadFile(
stashFilename, fileInputStream, contribution.getDataLength(),
localUri, contribution.getContentProviderUri(), notificationUpdater)
Expand Down

0 comments on commit 645bc8f

Please sign in to comment.