Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #4836 & #4840 Added the functionality of cancel upload and also solved the small bug of pausing upload #4843

Merged
merged 9 commits into from
Feb 25, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.os.Process;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.multidex.BuildConfig;
import androidx.multidex.MultiDexApplication;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipeline;
Expand Down Expand Up @@ -135,7 +136,7 @@ public AppLanguageLookUpTable getLanguageLookUpTable() {
ContributionDao contributionDao;

/**
* In memory list of contributios whose uploads ahve been paused by the user
* In memory list of contribution whose uploads have been paused by the user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for the future: Thanks for fixing these! Please do not hesitate to make such changes in a separate pull request, so that this pull request does not contain unrelated changes :-)

By the way:
In memory -> In-memory
contribution -> contributions

*/
public static Map<String, Boolean> pauseUploads = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ public void init(final int position, final Contribution contribution) {
}
break;
case Contribution.STATE_PAUSED:
progressView.setVisibility(View.GONE);
stateView.setVisibility(View.VISIBLE);
stateView.setText(R.string.paused);
setResume();
progressView.setVisibility(View.GONE);
cancelButton.setVisibility(View.GONE);
cancelButton.setVisibility(View.VISIBLE);
retryButton.setVisibility(View.GONE);
pauseResumeButton.setVisibility(View.VISIBLE);
imageOptions.setVisibility(View.VISIBLE);
setResume();
break;
case Contribution.STATE_FAILED:
stateView.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -254,14 +254,14 @@ private void pause() {
*/
private void setPaused() {
pauseResumeButton.setImageResource(R.drawable.pause_icon);
pauseResumeButton.setTag(R.string.pause);
pauseResumeButton.setTag("pause");
4D17Y4 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Update pause/resume button to show resume state
*/
private void setResume() {
pauseResumeButton.setImageResource(R.drawable.play_icon);
pauseResumeButton.setTag(R.string.resume);
pauseResumeButton.setTag("resume");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static android.view.View.VISIBLE;
import static fr.free.nrw.commons.di.NetworkingModule.NAMED_LANGUAGE_WIKI_PEDIA_WIKI_SITE;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.res.Configuration;
import android.net.Uri;
Expand Down Expand Up @@ -115,6 +116,8 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
private int contributionsSize;
String userName;

private ProgressDialog pausingPopUp;


@Override
public void onCreate(@Nullable @org.jetbrains.annotations.Nullable final Bundle savedInstanceState) {
Expand All @@ -138,6 +141,10 @@ public View onCreateView(
ButterKnife.bind(this, view);
contributionsListPresenter.onAttachView(this);

// setting the pausingPopUp properties
pausingPopUp = new ProgressDialog(getContext());
pausingPopUp.setMessage(getString(R.string.pausing_upload));

if (Objects.equals(sessionManager.getUserName(), userName)) {
tvContributionsOfUser.setVisibility(GONE);
fab_layout.setVisibility(VISIBLE);
Expand Down Expand Up @@ -220,6 +227,10 @@ public void onItemRangeChanged(final int positionStart, final int itemCount) {
if (callback != null) {
callback.viewPagerNotifyDataSetChanged();
}
// check for the pausingPopUp if it's visible then hide
if(pausingPopUp.isShowing()){
pausingPopUp.hide();
}
}
});

Expand Down Expand Up @@ -389,7 +400,17 @@ public void retryUpload(final Contribution contribution) {

@Override
public void deleteUpload(final Contribution contribution) {
contributionsListPresenter.deleteUpload(contribution);
DialogUtil.showAlertDialog(getActivity(),
"Cancel Upload",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind reminding me what this string is used for, and why is does not need localization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this string is the title of dialog util, And I forgot to do localization

String.format(getString(R.string.cancel_upload_dialog),
Locale.getDefault().getDisplayLanguage()),
"YES", "NO",
() -> {
ViewUtil.showShortToast(getContext(), R.string.cancelling_upload);
contributionsListPresenter.deleteUpload(contribution);
}, () -> {
///do nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Do nothing.

});
}

@Override
Expand Down Expand Up @@ -424,6 +445,7 @@ public void addImageToWikipedia(Contribution contribution) {
*/
@Override
public void pauseUpload(Contribution contribution) {
pausingPopUp.show();
ViewUtil.showShortToast(getContext(), R.string.pausing_upload);
callback.pauseUpload(contribution);
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
<string name="error_fetching_nearby_monuments">Error fetching nearby monuments.</string>
<string name="no_recent_searches">No recent searches</string>
<string name="delete_recent_searches_dialog">Are you sure you want to clear your search history?</string>
<string name="cancel_upload_dialog">Are you sure you want to cancel this upload?</string>
<string name="delete_search_dialog">Do you want to delete this search?</string>
<string name="search_history_deleted">Search history deleted</string>

Expand Down Expand Up @@ -625,6 +626,7 @@ Upload your first media by tapping on the add button.</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>
<string name="cancelling_upload">Cancelling upload…</string>
<string name="limited_connection_explanation">You have enabled limited connection mode. All uploads are paused and will resume once you disable this mode.</string>
<string name="limited_connection_is_on">Limited connection mode is on.</string>

Expand Down