#4048 - "copy to subsequent media" button (#4308)

* added copy to subsequent media button

* minor change

Co-authored-by: Pratham2305 <Pratham2305@users.noreply.github.com>
This commit is contained in:
Pratham Pahariya 2021-04-02 11:42:11 +05:30 committed by GitHub
parent ff96f5047e
commit a479dd5bb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 44 deletions

View file

@ -205,16 +205,16 @@ public class UploadRepository {
} }
/** /**
* fetches and returns the previous upload item * fetches and returns the upload item
* *
* @param index * @param index
* @return * @return
*/ */
public UploadItem getPreviousUploadItem(int index) { public UploadItem getUploadItem(int index) {
if (index - 1 >= 0) { if (index >= 0) {
return uploadModel.getItems().get(index - 1); return uploadModel.getItems().get(index);
} }
return null; //There is no previous item to copy details return null; //There is no item to copy details
} }
/** /**

View file

@ -12,6 +12,7 @@ import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatButton; import androidx.appcompat.widget.AppCompatButton;
@ -69,8 +70,8 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
@BindView(R.id.tooltip) @BindView(R.id.tooltip)
ImageView tooltip; ImageView tooltip;
private UploadMediaDetailAdapter uploadMediaDetailAdapter; private UploadMediaDetailAdapter uploadMediaDetailAdapter;
@BindView(R.id.btn_copy_prev_title_desc) @BindView(R.id.btn_copy_subsequent_media)
AppCompatButton btnCopyPreviousTitleDesc; AppCompatButton btnCopyToSubsequentMedia;
@Inject @Inject
UploadMediaDetailsContract.UserActionListener presenter; UploadMediaDetailsContract.UserActionListener presenter;
@ -123,9 +124,9 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
showInfoAlert(R.string.media_detail_step_title, R.string.media_details_tooltip); showInfoAlert(R.string.media_detail_step_title, R.string.media_details_tooltip);
} }
}); });
initRecyclerView();
initPresenter(); initPresenter();
presenter.receiveImage(uploadableFile, place); presenter.receiveImage(uploadableFile, place);
initRecyclerView();
if (callback.getIndexInViewFlipper(this) == 0) { if (callback.getIndexInViewFlipper(this) == 0) {
btnPrevious.setEnabled(false); btnPrevious.setEnabled(false);
@ -135,11 +136,11 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
btnPrevious.setAlpha(1.0f); btnPrevious.setAlpha(1.0f);
} }
//If this is the first media, we have nothing to copy, lets not show the button //If this is the last media, we have nothing to copy, lets not show the button
if (callback.getIndexInViewFlipper(this) == 0) { if (callback.getIndexInViewFlipper(this) == callback.getTotalNumberOfSteps()-4) {
btnCopyPreviousTitleDesc.setVisibility(View.GONE); btnCopyToSubsequentMedia.setVisibility(View.GONE);
} else { } else {
btnCopyPreviousTitleDesc.setVisibility(View.VISIBLE); btnCopyToSubsequentMedia.setVisibility(View.VISIBLE);
} }
attachImageViewScaleChangeListener(); attachImageViewScaleChangeListener();
@ -261,6 +262,12 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this)); callback.onNextButtonClicked(callback.getIndexInViewFlipper(this));
} }
@Override
protected void onBecameVisible() {
super.onBecameVisible();
presenter.fetchTitleAndDescription(callback.getIndexInViewFlipper(this));
}
@Override @Override
public void showMessage(int stringResourceId, int colorResourceId) { public void showMessage(int stringResourceId, int colorResourceId) {
ViewUtil.showLongToast(getContext(), stringResourceId); ViewUtil.showLongToast(getContext(), stringResourceId);
@ -369,6 +376,9 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
@Override @Override
public void onPrimaryCaptionTextChange(boolean isNotEmpty) { public void onPrimaryCaptionTextChange(boolean isNotEmpty) {
btnCopyToSubsequentMedia.setEnabled(isNotEmpty);
btnCopyToSubsequentMedia.setClickable(isNotEmpty);
btnCopyToSubsequentMedia.setAlpha(isNotEmpty ? 1.0f: 0.5f);
btnNext.setEnabled(isNotEmpty); btnNext.setEnabled(isNotEmpty);
btnNext.setClickable(isNotEmpty); btnNext.setClickable(isNotEmpty);
btnNext.setAlpha(isNotEmpty ? 1.0f: 0.5f); btnNext.setAlpha(isNotEmpty ? 1.0f: 0.5f);
@ -380,9 +390,10 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
} }
@OnClick(R.id.btn_copy_prev_title_desc) @OnClick(R.id.btn_copy_subsequent_media)
public void onButtonCopyPreviousTitleDesc(){ public void onButtonCopyTitleDescToSubsequentMedia(){
presenter.fetchPreviousTitleAndDescription(callback.getIndexInViewFlipper(this)); presenter.copyTitleAndDescriptionToSubsequentMedia(callback.getIndexInViewFlipper(this));
Toast.makeText(getContext(), getResources().getString(R.string.copied_successfully), Toast.LENGTH_SHORT).show();
} }
} }

View file

@ -45,7 +45,9 @@ public interface UploadMediaDetailsContract {
void verifyImageQuality(int uploadItemIndex); void verifyImageQuality(int uploadItemIndex);
void fetchPreviousTitleAndDescription(int indexInViewFlipper); void copyTitleAndDescriptionToSubsequentMedia(int indexInViewFlipper);
void fetchTitleAndDescription(int indexInViewFlipper);
void useSimilarPictureCoordinates(ImageCoordinates imageCoordinates, int uploadItemIndex); void useSimilarPictureCoordinates(ImageCoordinates imageCoordinates, int uploadItemIndex);

View file

@ -147,22 +147,29 @@ public class UploadMediaPresenter implements UserActionListener, SimilarImageInt
/** /**
* Fetches and sets the caption and desctiption of the previous item * Copies the caption and description of the current item to the subsequent media
* *
* @param indexInViewFlipper * @param indexInViewFlipper
*/ */
@Override @Override
public void fetchPreviousTitleAndDescription(int indexInViewFlipper) { public void copyTitleAndDescriptionToSubsequentMedia(int indexInViewFlipper) {
UploadItem previousUploadItem = repository.getPreviousUploadItem(indexInViewFlipper); for(int i = indexInViewFlipper+1; i < repository.getCount(); i++){
if (null != previousUploadItem) { final UploadItem subsequentUploadItem = repository.getUploads().get(i);
final UploadItem currentUploadItem = repository.getUploads().get(indexInViewFlipper); subsequentUploadItem.setMediaDetails(deepCopy(repository.getUploads().get(indexInViewFlipper).getUploadMediaDetails()));
currentUploadItem.setMediaDetails(deepCopy(previousUploadItem.getUploadMediaDetails())); }
view.updateMediaDetails(currentUploadItem.getUploadMediaDetails());
} else {
view.showMessage(R.string.previous_image_title_description_not_found, R.color.color_error);
}
} }
/**
* Fetches and set the caption and description of the item
*
* @param indexInViewFlipper
*/
@Override
public void fetchTitleAndDescription(int indexInViewFlipper) {
final UploadItem currentUploadItem = repository.getUploads().get(indexInViewFlipper);
view.updateMediaDetails(currentUploadItem.getUploadMediaDetails());
}
@NotNull @NotNull
private List<UploadMediaDetail> deepCopy(List<UploadMediaDetail> uploadMediaDetails) { private List<UploadMediaDetail> deepCopy(List<UploadMediaDetail> uploadMediaDetails) {
final ArrayList<UploadMediaDetail> newList = new ArrayList<>(); final ArrayList<UploadMediaDetail> newList = new ArrayList<>();

View file

@ -99,11 +99,11 @@
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_copy_prev_title_desc" android:id="@+id/btn_copy_subsequent_media"
style="@style/Widget.AppCompat.Button.Borderless" style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/previous_image_caption_description" android:text="@string/copy_image_caption_description"
android:padding="@dimen/miniscule_margin" android:padding="@dimen/miniscule_margin"
android:textAlignment="textEnd" android:textAlignment="textEnd"
android:textColor="@color/button_blue" android:textColor="@color/button_blue"

View file

@ -460,7 +460,8 @@ Upload your first media by tapping on the add button.</string>
<string name="images_featured_explanation">Featured pictures are images from highly skilled photographers and illustrators that the Wikimedia Commons community has chosen as some of the highest quality on the site.</string> <string name="images_featured_explanation">Featured pictures are images from highly skilled photographers and illustrators that the Wikimedia Commons community has chosen as some of the highest quality on the site.</string>
<string name="images_via_nearby_explanation">Images Uploaded via Nearby places are the images which are uploaded by discovering places on the map.</string> <string name="images_via_nearby_explanation">Images Uploaded via Nearby places are the images which are uploaded by discovering places on the map.</string>
<string name="thanks_received_explanation">This feature allows editors to send a Thank you notification to users who make useful edits by using a small thank link on the history page or diff page.</string> <string name="thanks_received_explanation">This feature allows editors to send a Thank you notification to users who make useful edits by using a small thank link on the history page or diff page.</string>
<string name="previous_image_caption_description">Copy previous captions &amp; description</string> <string name="copy_image_caption_description">Copy to subsequent Media</string>
<string name="copied_successfully">Copied Successfully</string>
<string name="welcome_do_upload_content_description">Examples of good images to upload to Commons</string> <string name="welcome_do_upload_content_description">Examples of good images to upload to Commons</string>
<string name="welcome_dont_upload_content_description">Examples of images not to upload</string> <string name="welcome_dont_upload_content_description">Examples of images not to upload</string>
<string name="skip_image">Skip this image</string> <string name="skip_image">Skip this image</string>

View file

@ -164,30 +164,19 @@ class UploadMediaPresenterTest {
} }
/** /**
* Test fetch previous image title when there was one * Test fetch image title when there was one
*/ */
@Test @Test
fun fetchPreviousImageAndTitleTestPositive() { fun fetchImageAndTitleTest() {
whenever(repository.uploads).thenReturn(listOf(uploadItem)) whenever(repository.uploads).thenReturn(listOf(uploadItem))
whenever(repository.getPreviousUploadItem(ArgumentMatchers.anyInt())) whenever(repository.getUploadItem(ArgumentMatchers.anyInt()))
.thenReturn(uploadItem) .thenReturn(uploadItem)
whenever(uploadItem.uploadMediaDetails).thenReturn(listOf()) whenever(uploadItem.uploadMediaDetails).thenReturn(listOf())
uploadMediaPresenter.fetchPreviousTitleAndDescription(0) uploadMediaPresenter.fetchTitleAndDescription(0)
verify(view).updateMediaDetails(ArgumentMatchers.any()) verify(view).updateMediaDetails(ArgumentMatchers.any())
} }
/**
* Test fetch previous image title when there was none
*/
@Test
fun fetchPreviousImageAndTitleTestNegative() {
whenever(repository.getPreviousUploadItem(ArgumentMatchers.anyInt()))
.thenReturn(null)
uploadMediaPresenter.fetchPreviousTitleAndDescription(0)
verify(view).showMessage(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())
}
/** /**
* Test bad image invalid location * Test bad image invalid location
*/ */