Skip to content

Commit a479dd5

Browse files
authored
commons-app#4048 - "copy to subsequent media" button (commons-app#4308)
* added copy to subsequent media button * minor change Co-authored-by: Pratham2305 <Pratham2305@users.noreply.github.com>
1 parent ff96f50 commit a479dd5

File tree

7 files changed

+54
-44
lines changed

7 files changed

+54
-44
lines changed

app/src/main/java/fr/free/nrw/commons/repository/UploadRepository.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ public void deletePicture(String filePath) {
205205
}
206206

207207
/**
208-
* fetches and returns the previous upload item
208+
* fetches and returns the upload item
209209
*
210210
* @param index
211211
* @return
212212
*/
213-
public UploadItem getPreviousUploadItem(int index) {
214-
if (index - 1 >= 0) {
215-
return uploadModel.getItems().get(index - 1);
213+
public UploadItem getUploadItem(int index) {
214+
if (index >= 0) {
215+
return uploadModel.getItems().get(index);
216216
}
217-
return null; //There is no previous item to copy details
217+
return null; //There is no item to copy details
218218
}
219219

220220
/**

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.widget.ImageView;
1313
import android.widget.LinearLayout;
1414
import android.widget.TextView;
15+
import android.widget.Toast;
1516
import androidx.annotation.NonNull;
1617
import androidx.annotation.Nullable;
1718
import androidx.appcompat.widget.AppCompatButton;
@@ -69,8 +70,8 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
6970
@BindView(R.id.tooltip)
7071
ImageView tooltip;
7172
private UploadMediaDetailAdapter uploadMediaDetailAdapter;
72-
@BindView(R.id.btn_copy_prev_title_desc)
73-
AppCompatButton btnCopyPreviousTitleDesc;
73+
@BindView(R.id.btn_copy_subsequent_media)
74+
AppCompatButton btnCopyToSubsequentMedia;
7475

7576
@Inject
7677
UploadMediaDetailsContract.UserActionListener presenter;
@@ -123,9 +124,9 @@ public void onClick(View v) {
123124
showInfoAlert(R.string.media_detail_step_title, R.string.media_details_tooltip);
124125
}
125126
});
126-
initRecyclerView();
127127
initPresenter();
128128
presenter.receiveImage(uploadableFile, place);
129+
initRecyclerView();
129130

130131
if (callback.getIndexInViewFlipper(this) == 0) {
131132
btnPrevious.setEnabled(false);
@@ -135,11 +136,11 @@ public void onClick(View v) {
135136
btnPrevious.setAlpha(1.0f);
136137
}
137138

138-
//If this is the first media, we have nothing to copy, lets not show the button
139-
if (callback.getIndexInViewFlipper(this) == 0) {
140-
btnCopyPreviousTitleDesc.setVisibility(View.GONE);
139+
//If this is the last media, we have nothing to copy, lets not show the button
140+
if (callback.getIndexInViewFlipper(this) == callback.getTotalNumberOfSteps()-4) {
141+
btnCopyToSubsequentMedia.setVisibility(View.GONE);
141142
} else {
142-
btnCopyPreviousTitleDesc.setVisibility(View.VISIBLE);
143+
btnCopyToSubsequentMedia.setVisibility(View.VISIBLE);
143144
}
144145

145146
attachImageViewScaleChangeListener();
@@ -261,6 +262,12 @@ public void onImageValidationSuccess() {
261262
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this));
262263
}
263264

265+
@Override
266+
protected void onBecameVisible() {
267+
super.onBecameVisible();
268+
presenter.fetchTitleAndDescription(callback.getIndexInViewFlipper(this));
269+
}
270+
264271
@Override
265272
public void showMessage(int stringResourceId, int colorResourceId) {
266273
ViewUtil.showLongToast(getContext(), stringResourceId);
@@ -369,6 +376,9 @@ private void expandCollapseLlMediaDetail(boolean shouldExpand){
369376

370377
@Override
371378
public void onPrimaryCaptionTextChange(boolean isNotEmpty) {
379+
btnCopyToSubsequentMedia.setEnabled(isNotEmpty);
380+
btnCopyToSubsequentMedia.setClickable(isNotEmpty);
381+
btnCopyToSubsequentMedia.setAlpha(isNotEmpty ? 1.0f: 0.5f);
372382
btnNext.setEnabled(isNotEmpty);
373383
btnNext.setClickable(isNotEmpty);
374384
btnNext.setAlpha(isNotEmpty ? 1.0f: 0.5f);
@@ -380,9 +390,10 @@ public interface UploadMediaDetailFragmentCallback extends Callback {
380390
}
381391

382392

383-
@OnClick(R.id.btn_copy_prev_title_desc)
384-
public void onButtonCopyPreviousTitleDesc(){
385-
presenter.fetchPreviousTitleAndDescription(callback.getIndexInViewFlipper(this));
393+
@OnClick(R.id.btn_copy_subsequent_media)
394+
public void onButtonCopyTitleDescToSubsequentMedia(){
395+
presenter.copyTitleAndDescriptionToSubsequentMedia(callback.getIndexInViewFlipper(this));
396+
Toast.makeText(getContext(), getResources().getString(R.string.copied_successfully), Toast.LENGTH_SHORT).show();
386397
}
387398

388399
}

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailsContract.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ interface UserActionListener extends BasePresenter<View> {
4545

4646
void verifyImageQuality(int uploadItemIndex);
4747

48-
void fetchPreviousTitleAndDescription(int indexInViewFlipper);
48+
void copyTitleAndDescriptionToSubsequentMedia(int indexInViewFlipper);
49+
50+
void fetchTitleAndDescription(int indexInViewFlipper);
4951

5052
void useSimilarPictureCoordinates(ImageCoordinates imageCoordinates, int uploadItemIndex);
5153

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaPresenter.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,29 @@ public void verifyImageQuality(int uploadItemIndex) {
147147

148148

149149
/**
150-
* Fetches and sets the caption and desctiption of the previous item
150+
* Copies the caption and description of the current item to the subsequent media
151151
*
152152
* @param indexInViewFlipper
153153
*/
154154
@Override
155-
public void fetchPreviousTitleAndDescription(int indexInViewFlipper) {
156-
UploadItem previousUploadItem = repository.getPreviousUploadItem(indexInViewFlipper);
157-
if (null != previousUploadItem) {
158-
final UploadItem currentUploadItem = repository.getUploads().get(indexInViewFlipper);
159-
currentUploadItem.setMediaDetails(deepCopy(previousUploadItem.getUploadMediaDetails()));
160-
view.updateMediaDetails(currentUploadItem.getUploadMediaDetails());
161-
} else {
162-
view.showMessage(R.string.previous_image_title_description_not_found, R.color.color_error);
163-
}
155+
public void copyTitleAndDescriptionToSubsequentMedia(int indexInViewFlipper) {
156+
for(int i = indexInViewFlipper+1; i < repository.getCount(); i++){
157+
final UploadItem subsequentUploadItem = repository.getUploads().get(i);
158+
subsequentUploadItem.setMediaDetails(deepCopy(repository.getUploads().get(indexInViewFlipper).getUploadMediaDetails()));
159+
}
164160
}
165161

162+
/**
163+
* Fetches and set the caption and description of the item
164+
*
165+
* @param indexInViewFlipper
166+
*/
167+
@Override
168+
public void fetchTitleAndDescription(int indexInViewFlipper) {
169+
final UploadItem currentUploadItem = repository.getUploads().get(indexInViewFlipper);
170+
view.updateMediaDetails(currentUploadItem.getUploadMediaDetails());
171+
}
172+
166173
@NotNull
167174
private List<UploadMediaDetail> deepCopy(List<UploadMediaDetail> uploadMediaDetails) {
168175
final ArrayList<UploadMediaDetail> newList = new ArrayList<>();

app/src/main/res/layout/fragment_upload_media_detail_fragment.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@
9999

100100

101101
<androidx.appcompat.widget.AppCompatButton
102-
android:id="@+id/btn_copy_prev_title_desc"
102+
android:id="@+id/btn_copy_subsequent_media"
103103
style="@style/Widget.AppCompat.Button.Borderless"
104104
android:layout_width="match_parent"
105105
android:layout_height="wrap_content"
106-
android:text="@string/previous_image_caption_description"
106+
android:text="@string/copy_image_caption_description"
107107
android:padding="@dimen/miniscule_margin"
108108
android:textAlignment="textEnd"
109109
android:textColor="@color/button_blue"

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ Upload your first media by tapping on the add button.</string>
460460
<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>
461461
<string name="images_via_nearby_explanation">Images Uploaded via Nearby places are the images which are uploaded by discovering places on the map.</string>
462462
<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>
463-
<string name="previous_image_caption_description">Copy previous captions &amp; description</string>
463+
<string name="copy_image_caption_description">Copy to subsequent Media</string>
464+
<string name="copied_successfully">Copied Successfully</string>
464465
<string name="welcome_do_upload_content_description">Examples of good images to upload to Commons</string>
465466
<string name="welcome_dont_upload_content_description">Examples of images not to upload</string>
466467
<string name="skip_image">Skip this image</string>

app/src/test/kotlin/fr/free/nrw/commons/upload/UploadMediaPresenterTest.kt

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,30 +164,19 @@ class UploadMediaPresenterTest {
164164
}
165165

166166
/**
167-
* Test fetch previous image title when there was one
167+
* Test fetch image title when there was one
168168
*/
169169
@Test
170-
fun fetchPreviousImageAndTitleTestPositive() {
170+
fun fetchImageAndTitleTest() {
171171
whenever(repository.uploads).thenReturn(listOf(uploadItem))
172-
whenever(repository.getPreviousUploadItem(ArgumentMatchers.anyInt()))
172+
whenever(repository.getUploadItem(ArgumentMatchers.anyInt()))
173173
.thenReturn(uploadItem)
174174
whenever(uploadItem.uploadMediaDetails).thenReturn(listOf())
175175

176-
uploadMediaPresenter.fetchPreviousTitleAndDescription(0)
176+
uploadMediaPresenter.fetchTitleAndDescription(0)
177177
verify(view).updateMediaDetails(ArgumentMatchers.any())
178178
}
179179

180-
/**
181-
* Test fetch previous image title when there was none
182-
*/
183-
@Test
184-
fun fetchPreviousImageAndTitleTestNegative() {
185-
whenever(repository.getPreviousUploadItem(ArgumentMatchers.anyInt()))
186-
.thenReturn(null)
187-
uploadMediaPresenter.fetchPreviousTitleAndDescription(0)
188-
verify(view).showMessage(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())
189-
}
190-
191180
/**
192181
* Test bad image invalid location
193182
*/

0 commit comments

Comments
 (0)