mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Increase chunk size to 1MB (#4011)
* Increase chunk size to 1MB * Increase timeouts * Add logs * Enable HTTP logging * Encode file name * Update chunk size * Add toast
This commit is contained in:
parent
71d200ee41
commit
6fa8cc627a
8 changed files with 51 additions and 22 deletions
|
|
@ -37,9 +37,9 @@ public final class OkHttpConnectionFactory {
|
|||
return new OkHttpClient.Builder()
|
||||
.cookieJar(SharedPreferenceCookieManager.getInstance())
|
||||
.cache(NET_CACHE)
|
||||
.connectTimeout(60, TimeUnit.SECONDS)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.connectTimeout(120, TimeUnit.SECONDS)
|
||||
.writeTimeout(120, TimeUnit.SECONDS)
|
||||
.readTimeout(120, TimeUnit.SECONDS)
|
||||
.addInterceptor(getLoggingInterceptor())
|
||||
.addInterceptor(new UnsuccessfulResponseInterceptor())
|
||||
.addInterceptor(new CommonHeaderRequestInterceptor())
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.contributions.ContributionsListAdapter.Callback;
|
||||
import fr.free.nrw.commons.media.MediaClient;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
|
@ -224,14 +225,22 @@ public class ContributionViewHolder extends RecyclerView.ViewHolder {
|
|||
@OnClick(R.id.pauseResumeButton)
|
||||
public void onPauseResumeButtonClicked() {
|
||||
if (pauseResumeButton.getTag().toString().equals("pause")) {
|
||||
callback.pauseUpload(contribution);
|
||||
setResume();
|
||||
pause();
|
||||
} else {
|
||||
callback.resumeUpload(contribution);
|
||||
setPaused();
|
||||
resume();
|
||||
}
|
||||
}
|
||||
|
||||
private void resume() {
|
||||
callback.resumeUpload(contribution);
|
||||
setPaused();
|
||||
}
|
||||
|
||||
private void pause() {
|
||||
callback.pauseUpload(contribution);
|
||||
setResume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update pause/resume button to show pause state
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import fr.free.nrw.commons.Utils;
|
|||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.utils.DialogUtil;
|
||||
import fr.free.nrw.commons.media.MediaClient;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import java.util.Locale;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
|
@ -283,6 +284,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
*/
|
||||
@Override
|
||||
public void pauseUpload(Contribution contribution) {
|
||||
ViewUtil.showShortToast(getContext(), R.string.pausing_upload);
|
||||
callback.pauseUpload(contribution);
|
||||
}
|
||||
|
||||
|
|
@ -292,6 +294,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
*/
|
||||
@Override
|
||||
public void resumeUpload(Contribution contribution) {
|
||||
ViewUtil.showShortToast(getContext(), R.string.resuming_upload);
|
||||
callback.retryUpload(contribution);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,10 +63,10 @@ public class NetworkingModule {
|
|||
HttpLoggingInterceptor httpLoggingInterceptor) {
|
||||
File dir = new File(context.getCacheDir(), "okHttpCache");
|
||||
return new OkHttpClient.Builder()
|
||||
.connectTimeout(60, TimeUnit.SECONDS)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)
|
||||
.connectTimeout(120, TimeUnit.SECONDS)
|
||||
.writeTimeout(120, TimeUnit.SECONDS)
|
||||
.addInterceptor(httpLoggingInterceptor)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.readTimeout(120, TimeUnit.SECONDS)
|
||||
.cache(new Cache(dir, OK_HTTP_CACHE_SIZE))
|
||||
.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import io.reactivex.Observable;
|
|||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -34,7 +36,7 @@ import timber.log.Timber;
|
|||
@Singleton
|
||||
public class UploadClient {
|
||||
|
||||
private final int CHUNK_SIZE = 256 * 1024; // 256 KB
|
||||
private final int CHUNK_SIZE = 512 * 1024; // 512 KB
|
||||
|
||||
//This is maximum duration for which a stash is persisted on MediaWiki
|
||||
// https://www.mediawiki.org/wiki/Manual:$wgUploadStashMaxAge
|
||||
|
|
@ -134,18 +136,23 @@ public class UploadClient {
|
|||
new ChunkInfo(uploadResult, index.get(), totalChunks));
|
||||
notificationUpdater.onChunkUploaded(contribution, chunkInfo.get());
|
||||
}, throwable -> {
|
||||
Timber.e(throwable, "Received error in chunk upload");
|
||||
failures.set(true);
|
||||
}));
|
||||
}));
|
||||
|
||||
if (pauseUploads.get(contribution.getPageId())) {
|
||||
Timber.d("Upload stash paused %s", contribution.getPageId());
|
||||
return Observable.just(new StashUploadResult(StashUploadState.PAUSED, null));
|
||||
} else if (failures.get()) {
|
||||
Timber.d("Upload stash contains failures %s", contribution.getPageId());
|
||||
return Observable.just(new StashUploadResult(StashUploadState.FAILED, null));
|
||||
} else if (chunkInfo.get() != null) {
|
||||
Timber.d("Upload stash success %s", contribution.getPageId());
|
||||
return Observable.just(new StashUploadResult(StashUploadState.SUCCESS,
|
||||
chunkInfo.get().getUploadResult().getFilekey()));
|
||||
} else {
|
||||
Timber.d("Upload stash failed %s", contribution.getPageId());
|
||||
return Observable.just(new StashUploadResult(StashUploadState.FAILED, null));
|
||||
}
|
||||
}
|
||||
|
|
@ -176,9 +183,11 @@ public class UploadClient {
|
|||
final long offset,
|
||||
final String fileKey,
|
||||
final CountingRequestBody countingRequestBody) {
|
||||
final MultipartBody.Part filePart = MultipartBody.Part
|
||||
.createFormData("chunk", filename, countingRequestBody);
|
||||
final MultipartBody.Part filePart;
|
||||
try {
|
||||
filePart = MultipartBody.Part
|
||||
.createFormData("chunk", URLEncoder.encode(filename, "utf-8"), countingRequestBody);
|
||||
|
||||
return uploadInterface.uploadFileToStash(toRequestBody(filename),
|
||||
toRequestBody(String.valueOf(fileSize)),
|
||||
toRequestBody(String.valueOf(offset)),
|
||||
|
|
@ -227,6 +236,7 @@ public class UploadClient {
|
|||
UploadResponse uploadResult = gson.fromJson(uploadResponse, UploadResponse.class);
|
||||
if (uploadResult.getUpload() == null) {
|
||||
final MwException exception = gson.fromJson(uploadResponse, MwException.class);
|
||||
Timber.e(exception, "Error in uploading file from stash");
|
||||
throw new RuntimeException(exception.getErrorCode());
|
||||
}
|
||||
return uploadResult.getUpload();
|
||||
|
|
|
|||
|
|
@ -310,6 +310,7 @@ public class UploadService extends CommonsDaggerService {
|
|||
}
|
||||
})
|
||||
.flatMap(uploadStash -> {
|
||||
Timber.d("Upload stash result %s", uploadStash.toString());
|
||||
notificationManager.cancel(notificationTag, NOTIFICATION_UPLOAD_IN_PROGRESS);
|
||||
|
||||
if (uploadStash.getState() == StashUploadState.SUCCESS) {
|
||||
|
|
|
|||
|
|
@ -15,20 +15,16 @@ import android.widget.AdapterView.OnItemSelectedListener;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.upload.UploadBaseFragment;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class MediaLicenseFragment extends UploadBaseFragment implements MediaLicenseContract.View {
|
||||
|
|
@ -81,12 +77,15 @@ public class MediaLicenseFragment extends UploadBaseFragment implements MediaLic
|
|||
* Initialise the license spinner
|
||||
*/
|
||||
private void initLicenseSpinner() {
|
||||
if (getContext() == null) {
|
||||
return;
|
||||
}
|
||||
adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerLicenseList.setAdapter(adapter);
|
||||
spinnerLicenseList.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int position,
|
||||
long l) {
|
||||
long l) {
|
||||
String licenseName = adapterView.getItemAtPosition(position).toString();
|
||||
presenter.selectLicense(licenseName);
|
||||
}
|
||||
|
|
@ -145,6 +144,7 @@ public class MediaLicenseFragment extends UploadBaseFragment implements MediaLic
|
|||
int end = strBuilder.getSpanEnd(span);
|
||||
int flags = strBuilder.getSpanFlags(span);
|
||||
ClickableSpan clickable = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// Handle hyperlink click
|
||||
String hyperLink = span.getURL();
|
||||
|
|
@ -161,12 +161,16 @@ public class MediaLicenseFragment extends UploadBaseFragment implements MediaLic
|
|||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
presenter.onDetachView();
|
||||
//Free the adapter to avoid memory leaks
|
||||
adapter=null;
|
||||
adapter = null;
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@OnClick(R.id.btn_previous)
|
||||
public void onPreviousButtonClicked() {
|
||||
|
|
|
|||
|
|
@ -701,4 +701,6 @@ Upload your first media by tapping on the add button.</string>
|
|||
<string name="limited_connection">Limited Connection</string>
|
||||
<string name="statistics_quality">Quality Images</string>
|
||||
<string name="quality_images_info">Quality images are diagrams or photographs that meet certain quality standards (which are mostly technical in nature) and are valuable for Wikimedia projects</string>
|
||||
<string name="resuming_upload">Resuming upload…</string>
|
||||
<string name="pausing_upload">Pausing upload…</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue