Skip to content

Commit

Permalink
Fixed #4836 & #4840 Added the functionality of cancel upload and also…
Browse files Browse the repository at this point in the history
… solved the small bug of pausing upload (#4843)

* Fixed #4836 & #4840

* Added Pausing PopUp

* Closing Pausing PopUp exactly when pause button disappears

* Managed to display the Pausing Upload

* Added the Pausing Dialog Using Progress Bar

* Added the Pausing Dialog Using Progress Bar

* Added Required Changes

* Added Required Changes-wording change

* Added Required Changes-wording change
  • Loading branch information
arinmodi authored Feb 25, 2022
1 parent f1169ea commit 9431e37
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
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 contributions whose uploads have been paused by the user
*/
public static Map<String, Boolean> pauseUploads = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AlertDialog.Builder;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
Expand Down Expand Up @@ -54,13 +56,23 @@ public class ContributionViewHolder extends RecyclerView.ViewHolder {
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
private final MediaClient mediaClient;
private boolean isWikipediaButtonDisplayed;
private AlertDialog pausingPopUp;
private View parent;

ContributionViewHolder(final View parent, final Callback callback,
final MediaClient mediaClient) {
super(parent);
this.parent = parent;
this.mediaClient = mediaClient;
ButterKnife.bind(this, parent);
this.callback = callback;

/* Set a dialog indicating that the upload is being paused. This is needed because pausing
an upload might take a dozen seconds. */
AlertDialog.Builder builder = new Builder(parent.getContext());
builder.setCancelable(false);
builder.setView(R.layout.progress_dialog);
pausingPopUp = builder.create();
}

public void init(final int position, final Contribution contribution) {
Expand Down Expand Up @@ -105,8 +117,8 @@ public void init(final int position, final Contribution contribution) {
break;
case Contribution.STATE_QUEUED:
case Contribution.STATE_QUEUED_LIMITED_CONNECTION_MODE:
stateView.setVisibility(View.VISIBLE);
progressView.setVisibility(View.GONE);
stateView.setVisibility(View.VISIBLE);
stateView.setText(R.string.contribution_state_queued);
imageOptions.setVisibility(View.GONE);
break;
Expand All @@ -128,14 +140,17 @@ 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();
if(pausingPopUp.isShowing()){
pausingPopUp.hide();
}
break;
case Contribution.STATE_FAILED:
stateView.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -245,6 +260,7 @@ private void resume() {
}

private void pause() {
pausingPopUp.show();
callback.pauseUpload(contribution);
setResume();
}
Expand All @@ -254,14 +270,14 @@ private void pause() {
*/
private void setPaused() {
pauseResumeButton.setImageResource(R.drawable.pause_icon);
pauseResumeButton.setTag(R.string.pause);
pauseResumeButton.setTag(parent.getContext().getString(R.string.pause));
}

/**
* Update pause/resume button to show resume state
*/
private void setResume() {
pauseResumeButton.setImageResource(R.drawable.play_icon);
pauseResumeButton.setTag(R.string.resume);
pauseResumeButton.setTag(parent.getContext().getString(R.string.resume));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
private int contributionsSize;
String userName;


@Override
public void onCreate(@Nullable @org.jetbrains.annotations.Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -389,7 +388,18 @@ public void retryUpload(final Contribution contribution) {

@Override
public void deleteUpload(final Contribution contribution) {
contributionsListPresenter.deleteUpload(contribution);
DialogUtil.showAlertDialog(getActivity(),
String.format(getString(R.string.cancelling_upload),
Locale.getDefault().getDisplayLanguage()),
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
});
}

@Override
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/layout/progress_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_marginHorizontal="10dp"
android:paddingVertical="20dp"
android:layout_weight="2"
android:layout_height="wrap_content">

<ProgressBar
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.6" />

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/pausing_upload"
android:layout_weight="1.5"
android:layout_gravity="center"
android:textSize="14sp" />

</LinearLayout>
3 changes: 3 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,8 @@ 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="cancel_upload">Cancel 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

0 comments on commit 9431e37

Please sign in to comment.