mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Fix crash upload wizard (#5466)
* Upload Wizard Crash Fix * Upload Wizard Crash Fix 2 * Fixes --------- Co-authored-by: shashankkumar <shashankkumar45556@gmail.com>
This commit is contained in:
parent
8b8eb84fae
commit
e8e87b1d1c
7 changed files with 178 additions and 28 deletions
|
|
@ -18,6 +18,8 @@ import android.os.Build;
|
||||||
import android.os.Build.VERSION;
|
import android.os.Build.VERSION;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -54,6 +56,7 @@ import fr.free.nrw.commons.mwapi.UserClient;
|
||||||
import fr.free.nrw.commons.nearby.Place;
|
import fr.free.nrw.commons.nearby.Place;
|
||||||
import fr.free.nrw.commons.settings.Prefs;
|
import fr.free.nrw.commons.settings.Prefs;
|
||||||
import fr.free.nrw.commons.theme.BaseActivity;
|
import fr.free.nrw.commons.theme.BaseActivity;
|
||||||
|
import fr.free.nrw.commons.upload.UploadBaseFragment.Callback;
|
||||||
import fr.free.nrw.commons.upload.categories.UploadCategoriesFragment;
|
import fr.free.nrw.commons.upload.categories.UploadCategoriesFragment;
|
||||||
import fr.free.nrw.commons.upload.depicts.DepictsFragment;
|
import fr.free.nrw.commons.upload.depicts.DepictsFragment;
|
||||||
import fr.free.nrw.commons.upload.license.MediaLicenseFragment;
|
import fr.free.nrw.commons.upload.license.MediaLicenseFragment;
|
||||||
|
|
@ -171,6 +174,19 @@ public class UploadActivity extends BaseActivity implements UploadContract.View,
|
||||||
|
|
||||||
setContentView(R.layout.activity_upload);
|
setContentView(R.layout.activity_upload);
|
||||||
|
|
||||||
|
/*
|
||||||
|
If Configuration of device is changed then get the new fragments
|
||||||
|
created by the system and populate the fragments ArrayList
|
||||||
|
*/
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
List<Fragment> fragmentList = getSupportFragmentManager().getFragments();
|
||||||
|
fragments = new ArrayList<>();
|
||||||
|
for (Fragment fragment : fragmentList) {
|
||||||
|
fragments.add((UploadBaseFragment) fragment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
compositeDisposable = new CompositeDisposable();
|
compositeDisposable = new CompositeDisposable();
|
||||||
init();
|
init();
|
||||||
|
|
@ -459,7 +475,12 @@ public class UploadActivity extends BaseActivity implements UploadContract.View,
|
||||||
tvTopCardTitle.setText(getResources()
|
tvTopCardTitle.setText(getResources()
|
||||||
.getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size()));
|
.getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size()));
|
||||||
|
|
||||||
|
|
||||||
|
if(fragments==null){
|
||||||
fragments = new ArrayList<>();
|
fragments = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Suggest users to turn battery optimisation off when uploading more than a few files.
|
/* Suggest users to turn battery optimisation off when uploading more than a few files.
|
||||||
That's because we have noticed that many-files uploads have
|
That's because we have noticed that many-files uploads have
|
||||||
a much higher probability of failing than uploads with less files.
|
a much higher probability of failing than uploads with less files.
|
||||||
|
|
@ -521,7 +542,8 @@ public class UploadActivity extends BaseActivity implements UploadContract.View,
|
||||||
}
|
}
|
||||||
uploadMediaDetailFragment.setImageTobeUploaded(uploadableFile, place, currLocation);
|
uploadMediaDetailFragment.setImageTobeUploaded(uploadableFile, place, currLocation);
|
||||||
locationManager.unregisterLocationManager();
|
locationManager.unregisterLocationManager();
|
||||||
uploadMediaDetailFragment.setCallback(new UploadMediaDetailFragmentCallback() {
|
|
||||||
|
UploadMediaDetailFragmentCallback uploadMediaDetailFragmentCallback = new UploadMediaDetailFragmentCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void deletePictureAtIndex(int index) {
|
public void deletePictureAtIndex(int index) {
|
||||||
presenter.deletePictureAtIndex(index);
|
presenter.deletePictureAtIndex(index);
|
||||||
|
|
@ -573,16 +595,27 @@ public class UploadActivity extends BaseActivity implements UploadContract.View,
|
||||||
public boolean isWLMUpload() {
|
public boolean isWLMUpload() {
|
||||||
return place!=null && place.isMonument();
|
return place!=null && place.isMonument();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if(fragments.size()==0){
|
||||||
|
uploadMediaDetailFragment.setCallback(uploadMediaDetailFragmentCallback);
|
||||||
fragments.add(uploadMediaDetailFragment);
|
fragments.add(uploadMediaDetailFragment);
|
||||||
|
}else{
|
||||||
|
UploadMediaDetailFragment fragment = (UploadMediaDetailFragment) fragments.get(0);
|
||||||
|
fragment.setCallback(uploadMediaDetailFragmentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//If fragments are not created, create them and add them to the fragments ArrayList
|
||||||
|
if(!(fragments.size()>1)){
|
||||||
uploadCategoriesFragment = new UploadCategoriesFragment();
|
uploadCategoriesFragment = new UploadCategoriesFragment();
|
||||||
if (place != null) {
|
if (place != null) {
|
||||||
Bundle categoryBundle = new Bundle();
|
Bundle categoryBundle = new Bundle();
|
||||||
categoryBundle.putString(SELECTED_NEARBY_PLACE_CATEGORY, place.getCategory());
|
categoryBundle.putString(SELECTED_NEARBY_PLACE_CATEGORY, place.getCategory());
|
||||||
uploadCategoriesFragment.setArguments(categoryBundle);
|
uploadCategoriesFragment.setArguments(categoryBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadCategoriesFragment.setCallback(this);
|
uploadCategoriesFragment.setCallback(this);
|
||||||
|
|
||||||
depictsFragment = new DepictsFragment();
|
depictsFragment = new DepictsFragment();
|
||||||
|
|
@ -598,8 +631,63 @@ public class UploadActivity extends BaseActivity implements UploadContract.View,
|
||||||
fragments.add(uploadCategoriesFragment);
|
fragments.add(uploadCategoriesFragment);
|
||||||
fragments.add(mediaLicenseFragment);
|
fragments.add(mediaLicenseFragment);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
for(int i=1;i<fragments.size();i++){
|
||||||
|
fragments.get(i).setCallback(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onNextButtonClicked(int index) {
|
||||||
|
if (index < fragments.size() - 1) {
|
||||||
|
vpUpload.setCurrentItem(index + 1, false);
|
||||||
|
fragments.get(index + 1).onBecameVisible();
|
||||||
|
((LinearLayoutManager) rvThumbnails.getLayoutManager())
|
||||||
|
.scrollToPositionWithOffset((index > 0) ? index-1 : 0, 0);
|
||||||
|
} else {
|
||||||
|
presenter.handleSubmit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onPreviousButtonClicked(int index) {
|
||||||
|
if (index != 0) {
|
||||||
|
vpUpload.setCurrentItem(index - 1, true);
|
||||||
|
fragments.get(index - 1).onBecameVisible();
|
||||||
|
((LinearLayoutManager) rvThumbnails.getLayoutManager())
|
||||||
|
.scrollToPositionWithOffset((index > 3) ? index-2 : 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void showProgress(boolean shouldShow) {
|
||||||
|
if (shouldShow) {
|
||||||
|
if (!progressDialog.isShowing()) {
|
||||||
|
progressDialog.show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (progressDialog != null && !isFinishing()) {
|
||||||
|
progressDialog.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int getIndexInViewFlipper(UploadBaseFragment fragment) {
|
||||||
|
return fragments.indexOf(fragment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalNumberOfSteps() {
|
||||||
|
return fragments.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWLMUpload() {
|
||||||
|
return place!=null && place.isMonument();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uploadImagesAdapter.setFragments(fragments);
|
uploadImagesAdapter.setFragments(fragments);
|
||||||
vpUpload.setOffscreenPageLimit(fragments.size());
|
vpUpload.setOffscreenPageLimit(fragments.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -712,6 +800,7 @@ public class UploadActivity extends BaseActivity implements UploadContract.View,
|
||||||
* The adapter used to show image upload intermediate fragments
|
* The adapter used to show image upload intermediate fragments
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
private class UploadImageAdapter extends FragmentStatePagerAdapter {
|
private class UploadImageAdapter extends FragmentStatePagerAdapter {
|
||||||
List<UploadBaseFragment> fragments;
|
List<UploadBaseFragment> fragments;
|
||||||
|
|
||||||
|
|
@ -754,12 +843,15 @@ public class UploadActivity extends BaseActivity implements UploadContract.View,
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
presenter.onDetachView();
|
presenter.onDetachView();
|
||||||
compositeDisposable.clear();
|
compositeDisposable.clear();
|
||||||
|
fragments = null;
|
||||||
|
uploadImagesAdapter = null;
|
||||||
if (mediaLicenseFragment != null) {
|
if (mediaLicenseFragment != null) {
|
||||||
mediaLicenseFragment.setCallback(null);
|
mediaLicenseFragment.setCallback(null);
|
||||||
}
|
}
|
||||||
if (uploadCategoriesFragment != null) {
|
if (uploadCategoriesFragment != null) {
|
||||||
uploadCategoriesFragment.setCallback(null);
|
uploadCategoriesFragment.setCallback(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import android.os.Parcelable;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||||
|
|
@ -12,6 +13,7 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||||
public class UploadBaseFragment extends CommonsDaggerSupportFragment {
|
public class UploadBaseFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
public Callback callback;
|
public Callback callback;
|
||||||
|
public static final String CALLBACK = "callback";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
|
|
||||||
|
|
@ -102,10 +102,13 @@ public class UploadCategoriesFragment extends UploadBaseFragment implements Cate
|
||||||
wikiText = bundle.getString("WikiText");
|
wikiText = bundle.getString("WikiText");
|
||||||
nearbyPlaceCategory = bundle.getString(SELECTED_NEARBY_PLACE_CATEGORY);
|
nearbyPlaceCategory = bundle.getString(SELECTED_NEARBY_PLACE_CATEGORY);
|
||||||
}
|
}
|
||||||
|
if(callback!=null) {
|
||||||
init();
|
init();
|
||||||
presenter.getCategories().observe(getViewLifecycleOwner(), this::setCategories);
|
presenter.getCategories().observe(getViewLifecycleOwner(), this::setCategories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
if (media == null) {
|
if (media == null) {
|
||||||
tvTitle.setText(getString(R.string.step_count, callback.getIndexInViewFlipper(this) + 1,
|
tvTitle.setText(getString(R.string.step_count, callback.getIndexInViewFlipper(this) + 1,
|
||||||
|
|
|
||||||
|
|
@ -106,9 +106,11 @@ public class DepictsFragment extends UploadBaseFragment implements DepictsContra
|
||||||
nearbyPlace = bundle.getParcelable(SELECTED_NEARBY_PLACE);
|
nearbyPlace = bundle.getParcelable(SELECTED_NEARBY_PLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(callback!=null){
|
||||||
init();
|
init();
|
||||||
presenter.getDepictedItems().observe(getViewLifecycleOwner(), this::setDepictsList);
|
presenter.getDepictedItems().observe(getViewLifecycleOwner(), this::setDepictsList);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize presenter and views
|
* Initialize presenter and views
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
UploadMediaDetailsContract.View, UploadMediaDetailAdapter.EventListener {
|
UploadMediaDetailsContract.View, UploadMediaDetailAdapter.EventListener {
|
||||||
|
|
@ -74,6 +75,11 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
*/
|
*/
|
||||||
public static final String LAST_LOCATION = "last_location_while_uploading";
|
public static final String LAST_LOCATION = "last_location_while_uploading";
|
||||||
public static final String LAST_ZOOM = "last_zoom_level_while_uploading";
|
public static final String LAST_ZOOM = "last_zoom_level_while_uploading";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String UPLOADABLE_FILE = "uploadable_file";
|
||||||
|
|
||||||
|
public static final String UPLOAD_MEDIA_DETAILS = "upload_media_detail_adapter";
|
||||||
@BindView(R.id.tv_title)
|
@BindView(R.id.tv_title)
|
||||||
TextView tvTitle;
|
TextView tvTitle;
|
||||||
@BindView(R.id.location_image_view)
|
@BindView(R.id.location_image_view)
|
||||||
|
|
@ -154,8 +160,16 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
|
||||||
|
if(savedInstanceState!=null && uploadableFile==null) {
|
||||||
|
uploadableFile = savedInstanceState.getParcelable(UPLOADABLE_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setImageTobeUploaded(UploadableFile uploadableFile, Place place,
|
public void setImageTobeUploaded(UploadableFile uploadableFile, Place place,
|
||||||
LatLng inAppPictureLocation) {
|
LatLng inAppPictureLocation) {
|
||||||
this.uploadableFile = uploadableFile;
|
this.uploadableFile = uploadableFile;
|
||||||
|
|
@ -168,15 +182,25 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.fragment_upload_media_detail_fragment, container, false);
|
return inflater.inflate(R.layout.fragment_upload_media_detail_fragment, container, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(savedInstanceState!=null){
|
||||||
|
if(uploadMediaDetailAdapter.getItems().size()==0){
|
||||||
|
uploadMediaDetailAdapter.setItems(savedInstanceState.getParcelableArrayList(UPLOAD_MEDIA_DETAILS));
|
||||||
|
presenter.setUploadMediaDetails(uploadMediaDetailAdapter.getItems(), callback.getIndexInViewFlipper(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
|
@ -735,4 +759,18 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
Toast.makeText(getContext(), getResources().getString(R.string.copied_successfully), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), getResources().getString(R.string.copied_successfully), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(final Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
|
if(uploadableFile!=null){
|
||||||
|
outState.putParcelable(UPLOADABLE_FILE,uploadableFile);
|
||||||
|
}
|
||||||
|
if(uploadMediaDetailAdapter!=null){
|
||||||
|
outState.putParcelableArrayList(UPLOAD_MEDIA_DETAILS,
|
||||||
|
(ArrayList<? extends Parcelable>) uploadMediaDetailAdapter.getItems());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ public interface UploadMediaDetailsContract {
|
||||||
|
|
||||||
void receiveImage(UploadableFile uploadableFile, Place place, LatLng inAppPictureLocation);
|
void receiveImage(UploadableFile uploadableFile, Place place, LatLng inAppPictureLocation);
|
||||||
|
|
||||||
|
void setUploadMediaDetails(List<UploadMediaDetail> uploadMediaDetails, int uploadItemIndex);
|
||||||
|
|
||||||
boolean verifyImageQuality(int uploadItemIndex, LatLng inAppPictureLocation);
|
boolean verifyImageQuality(int uploadItemIndex, LatLng inAppPictureLocation);
|
||||||
|
|
||||||
void copyTitleAndDescriptionToSubsequentMedia(int indexInViewFlipper);
|
void copyTitleAndDescriptionToSubsequentMedia(int indexInViewFlipper);
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,17 @@ public class UploadMediaPresenter implements UserActionListener, SimilarImageInt
|
||||||
compositeDisposable.clear();
|
compositeDisposable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Upload Media Details for the corresponding upload item
|
||||||
|
*
|
||||||
|
* @param uploadMediaDetails
|
||||||
|
* @param uploadItemIndex
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setUploadMediaDetails(List<UploadMediaDetail> uploadMediaDetails, int uploadItemIndex) {
|
||||||
|
repository.getUploads().get(uploadItemIndex).setMediaDetails(uploadMediaDetails);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives the corresponding uploadable file, processes it and return the view with and uplaod item
|
* Receives the corresponding uploadable file, processes it and return the view with and uplaod item
|
||||||
* @param uploadableFile
|
* @param uploadableFile
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue