Skip to content

Commit 190135d

Browse files
authored
Fix failing tests for updateDepictsProperty method (#5795)
* tests: fix failing testUpdateDepictsProperty * replace deprecated circular progress bar with material progress bar * refactor: update SettingsActivity to not use custom appCompatDeletegate It is required because that delegate is automatically handled in new libraries.
1 parent ec4a6bc commit 190135d

File tree

8 files changed

+107
-84
lines changed

8 files changed

+107
-84
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ dependencies {
4747

4848
implementation 'com.jakewharton.timber:timber:4.7.1'
4949
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
50-
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
50+
implementation "com.google.android.material:material:1.9.0"
5151
implementation 'com.karumi:dexter:5.0.0'
5252
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
5353

app/src/main/java/fr/free/nrw/commons/profile/achievements/AchievementsFragment.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ private void setUploadProgress(int uploadCount){
306306
if (uploadCount==0){
307307
setZeroAchievements();
308308
}else {
309+
309310
binding.imagesUploadedProgressbar.setVisibility(View.VISIBLE);
310311
binding.imagesUploadedProgressbar.setProgress
311312
(100*uploadCount/levelInfo.getMaxUploadCount());
@@ -342,8 +343,8 @@ private void setZeroAchievements() {
342343
private void setImageRevertPercentage(int notRevertPercentage){
343344
binding.imageRevertsProgressbar.setVisibility(View.VISIBLE);
344345
binding.imageRevertsProgressbar.setProgress(notRevertPercentage);
345-
String revertPercentage = Integer.toString(notRevertPercentage);
346-
binding.imageRevertsProgressbar.setProgressTextFormatPattern(revertPercentage + "%%");
346+
final String revertPercentage = Integer.toString(notRevertPercentage);
347+
binding.tvRevertedImages.setText(revertPercentage + "%");
347348
binding.imagesRevertLimitText.setText(getResources().getString(R.string.achievements_revert_limit_message)+ levelInfo.getMinNonRevertPercentage() + "%");
348349
}
349350

@@ -357,10 +358,8 @@ private void inflateAchievements(Achievements achievements) {
357358
binding.thanksReceived.setText(String.valueOf(achievements.getThanksReceived()));
358359
binding.imagesUsedByWikiProgressBar.setProgress
359360
(100 * achievements.getUniqueUsedImages() / levelInfo.getMaxUniqueImages());
360-
if(binding.tvWikiPb != null) {
361-
binding.tvWikiPb.setText
362-
(achievements.getUniqueUsedImages() + "/" + levelInfo.getMaxUniqueImages());
363-
}
361+
binding.tvWikiPb.setText(achievements.getUniqueUsedImages() + "/"
362+
+ levelInfo.getMaxUniqueImages());
364363
binding.imageFeatured.setText(String.valueOf(achievements.getFeaturedImages()));
365364
binding.qualityImages.setText(String.valueOf(achievements.getQualityImages()));
366365
String levelUpInfoString = getString(R.string.level).toUpperCase();

app/src/main/java/fr/free/nrw/commons/quiz/QuizResultActivity.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ protected void onDestroy() {
6565
* @param score
6666
*/
6767
public void setScore(int score) {
68-
int per = score * MULTIPLIER_TO_GET_PERCENTAGE;
69-
binding.resultProgressBar.setProgress(per);
70-
binding.resultProgressBar.setProgressTextFormatPattern(score +" / " + NUMBER_OF_QUESTIONS);
71-
String message = getResources().getString(R.string.congratulatory_message_quiz,per + "%");
68+
final int scorePercent = score * MULTIPLIER_TO_GET_PERCENTAGE;
69+
binding.resultProgressBar.setProgress(scorePercent);
70+
binding.tvResultProgress.setText(score +" / " + NUMBER_OF_QUESTIONS);
71+
final String message = getResources().getString(R.string.congratulatory_message_quiz,scorePercent + "%");
7272
binding.congratulatoryMessage.setText(message);
7373
}
7474

app/src/main/java/fr/free/nrw/commons/settings/SettingsActivity.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class SettingsActivity extends BaseActivity {
1616

1717
private ActivitySettingsBinding binding;
18-
private AppCompatDelegate settingsDelegate;
18+
// private AppCompatDelegate settingsDelegate;
1919
/**
2020
* to be called when the activity starts
2121
* @param savedInstanceState the previously saved state
@@ -39,10 +39,10 @@ protected void onCreate(Bundle savedInstanceState) {
3939
@Override
4040
protected void onPostCreate(Bundle savedInstanceState) {
4141
super.onPostCreate(savedInstanceState);
42-
if (settingsDelegate == null) {
43-
settingsDelegate = AppCompatDelegate.create(this, null);
44-
}
45-
settingsDelegate.onPostCreate(savedInstanceState);
42+
// if (settingsDelegate == null) {
43+
// settingsDelegate = AppCompatDelegate.create(this, null);
44+
// }
45+
// settingsDelegate.onPostCreate(savedInstanceState);
4646
}
4747

4848
@Override

app/src/main/java/fr/free/nrw/commons/wikidata/WikiBaseClient.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class WikiBaseClient @Inject constructor(
4747
}
4848
}
4949

50-
fun postDeleteClaims(entityId: String, data: String): Observable<Boolean> {
50+
fun postDeleteClaims(entityId: String, data: String?): Observable<Boolean> {
5151
return csrfToken().switchMap { editToken ->
52-
wikiBaseInterface.postDeleteClaims(editToken, entityId, data)
52+
wikiBaseInterface.postDeleteClaims(editToken, entityId, data!!)
5353
.map { response: MwPostResponse -> response.successVal == 1 }
5454
}
5555
}

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

+31-14
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,37 @@
4141
android:textSize="32sp"
4242
android:layout_marginTop="@dimen/activity_margin_vertical" />
4343

44-
<com.dinuscxj.progressbar.CircleProgressBar
45-
android:layout_width="match_parent"
46-
android:layout_height="@dimen/dimen_250"
47-
android:layout_marginRight="@dimen/activity_margin_horizontal"
48-
android:layout_marginLeft="@dimen/activity_margin_horizontal"
49-
android:layout_marginTop="@dimen/activity_margin_vertical"
50-
android:progress="50"
51-
app:progress_end_color="#8C8B98"
52-
app:progress_start_color="#3A3381"
53-
app:progress_stroke_width="@dimen/first_fab"
54-
app:progress_text_size="@dimen/large_gap"
55-
app:progress_text_format_pattern="4/5"
56-
app:style="solid_line"
57-
android:id="@+id/result_progress_bar"/>
44+
<FrameLayout
45+
android:layout_width="match_parent"
46+
android:layout_height="@dimen/dimen_250"
47+
android:layout_marginRight="@dimen/activity_margin_horizontal"
48+
android:layout_marginLeft="@dimen/activity_margin_horizontal"
49+
android:layout_marginTop="@dimen/activity_margin_vertical">
50+
51+
<com.google.android.material.progressindicator.CircularProgressIndicator
52+
android:id="@+id/result_progress_bar"
53+
android:layout_width="match_parent"
54+
android:layout_height="@dimen/dimen_250"
55+
android:layout_gravity="center"
56+
android:indeterminate="false"
57+
app:showAnimationBehavior="outward"
58+
app:indicatorColor="#3A3381"
59+
app:indicatorSize="128dp"
60+
app:trackThickness="@dimen/first_fab"
61+
app:trackColor="#B7B6B6" />
62+
63+
<androidx.appcompat.widget.AppCompatTextView
64+
android:id="@+id/tv_result_progress"
65+
android:layout_width="match_parent"
66+
android:layout_height="match_parent"
67+
android:padding="@dimen/progressbar_padding"
68+
android:gravity="center"
69+
android:maxLines="1"
70+
android:textColor="@color/secondaryColor"
71+
app:autoSizeMaxTextSize="@dimen/large_gap"
72+
app:autoSizeStepGranularity="1sp"
73+
app:autoSizeTextType="uniform" />
74+
</FrameLayout>
5875

5976
<TextView
6077
android:layout_width="match_parent"

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

+48-48
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,20 @@
133133
android:layout_width="@dimen/dimen_40"
134134
android:layout_height="@dimen/dimen_40"
135135
android:layout_alignParentEnd="true"
136-
android:layout_alignParentRight="true"
137-
android:layout_marginEnd="32dp"
138-
android:layout_marginRight="32dp">
136+
android:layout_marginEnd="32dp">
139137

140-
<com.dinuscxj.progressbar.CircleProgressBar
138+
<com.google.android.material.progressindicator.CircularProgressIndicator
139+
android:id="@+id/images_uploaded_progressbar"
141140
android:layout_width="@dimen/dimen_40"
142141
android:layout_height="@dimen/dimen_40"
143-
android:layout_alignParentRight="true"
144-
android:layout_alignParentEnd="true"
142+
android:indeterminate="false"
145143
android:layout_marginEnd="@dimen/large_gap"
146-
android:layout_marginRight="@dimen/large_gap"
147-
android:id="@+id/images_uploaded_progressbar"
148-
android:progress="50"
149-
app:progress_text_size="@dimen/progressbar_text"
150-
app:progress_end_color="#8C8B98"
151-
app:progress_start_color="#3A3381"
152-
app:progress_stroke_width="@dimen/progressbar_stroke"
153-
app:progress_text_format_pattern=""
154-
android:visibility="gone"
155-
app:progress_text_color="@color/secondaryColor"
156-
app:style="solid_line" />
144+
app:showAnimationBehavior="outward"
145+
app:indicatorColor="@color/primaryColor"
146+
app:indicatorSize="32dp"
147+
app:trackThickness="@dimen/progressbar_stroke"
148+
app:trackColor="#B7B6B6"
149+
android:visibility="gone"/>
157150

158151
<androidx.appcompat.widget.AppCompatTextView
159152
android:id="@+id/tv_uploaded_images"
@@ -228,24 +221,38 @@
228221
android:layout_marginStart="@dimen/activity_margin_horizontal"
229222
android:layout_below="@id/images_reverted_info"/>
230223

231-
<com.dinuscxj.progressbar.CircleProgressBar
224+
<FrameLayout
232225
android:layout_width="@dimen/dimen_40"
233226
android:layout_height="@dimen/dimen_40"
234-
android:layout_alignParentRight="true"
235227
android:layout_alignParentEnd="true"
236-
android:layout_marginRight="@dimen/large_gap"
237-
android:layout_marginEnd="@dimen/large_gap"
238-
android:progress="50"
239-
android:visibility="gone"
240-
android:id="@+id/image_reverts_progressbar"
241-
app:progress_end_color="#8C8B98"
242-
app:progress_start_color="#3A3381"
243-
app:progress_text_size="@dimen/progressbar_text"
244-
app:progress_stroke_width="@dimen/progressbar_stroke"
245-
app:progress_text_format_pattern="92%%"
246-
app:progress_text_color="@color/secondaryColor"
247-
app:style="solid_line" />
228+
android:layout_marginEnd="32dp">
229+
230+
<com.google.android.material.progressindicator.CircularProgressIndicator
231+
android:id="@+id/image_reverts_progressbar"
232+
android:layout_width="@dimen/dimen_40"
233+
android:layout_height="@dimen/dimen_40"
234+
android:indeterminate="false"
235+
android:layout_marginEnd="@dimen/large_gap"
236+
app:showAnimationBehavior="outward"
237+
app:indicatorColor="@color/primaryColor"
238+
app:indicatorSize="32dp"
239+
app:trackThickness="@dimen/progressbar_stroke"
240+
app:trackColor="#B7B6B6"
241+
android:visibility="gone"/>
248242

243+
<androidx.appcompat.widget.AppCompatTextView
244+
android:id="@+id/tv_reverted_images"
245+
android:layout_width="match_parent"
246+
android:layout_height="match_parent"
247+
android:padding="@dimen/progressbar_padding"
248+
android:gravity="center"
249+
android:maxLines="1"
250+
android:textColor="@color/secondaryColor"
251+
app:autoSizeMaxTextSize="@dimen/progressbar_text"
252+
app:autoSizeMinTextSize="2sp"
253+
app:autoSizeStepGranularity="1sp"
254+
app:autoSizeTextType="uniform" />
255+
</FrameLayout>
249256
</RelativeLayout>
250257

251258
<RelativeLayout
@@ -295,27 +302,20 @@
295302
android:layout_width="@dimen/dimen_40"
296303
android:layout_height="@dimen/dimen_40"
297304
android:layout_alignParentEnd="true"
298-
android:layout_alignParentRight="true"
299-
android:layout_marginEnd="32dp"
300-
android:layout_marginRight="32dp">
305+
android:layout_marginEnd="32dp">
301306

302-
<com.dinuscxj.progressbar.CircleProgressBar
307+
<com.google.android.material.progressindicator.CircularProgressIndicator
308+
android:id="@+id/images_used_by_wiki_progress_bar"
303309
android:layout_width="@dimen/dimen_40"
304310
android:layout_height="@dimen/dimen_40"
305-
android:layout_alignParentRight="true"
306-
android:layout_alignParentEnd="true"
307-
android:layout_marginRight="@dimen/large_gap"
311+
android:indeterminate="false"
308312
android:layout_marginEnd="@dimen/large_gap"
309-
android:progress="50"
310-
app:progress_text_size="@dimen/progressbar_text"
311-
android:id="@+id/images_used_by_wiki_progress_bar"
312-
app:progress_end_color="#8C8B98"
313-
app:progress_start_color="#3A3381"
314-
app:progress_stroke_width="2.5dp"
315-
android:visibility="gone"
316-
app:progress_text_color="@color/secondaryColor"
317-
app:progress_text_format_pattern=""
318-
app:style="solid_line" />
313+
app:showAnimationBehavior="outward"
314+
app:indicatorColor="@color/primaryColor"
315+
app:indicatorSize="32dp"
316+
app:trackThickness="@dimen/progressbar_stroke"
317+
app:trackColor="#B7B6B6"
318+
android:visibility="gone"/>
319319

320320
<androidx.appcompat.widget.AppCompatTextView
321321
android:id="@+id/tv_wiki_pb"

app/src/test/kotlin/fr/free/nrw/commons/wikidata/WikidataEditServiceTest.kt

+11-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.nhaarman.mockitokotlin2.whenever
88
import fr.free.nrw.commons.kvstore.JsonKvStore
99
import fr.free.nrw.commons.upload.UploadResult
1010
import fr.free.nrw.commons.upload.WikidataPlace
11+
import fr.free.nrw.commons.wikidata.model.RemoveClaim
1112
import io.reactivex.Observable
1213
import org.junit.Before
1314
import org.junit.Test
@@ -18,7 +19,6 @@ import org.mockito.Mock
1819
import org.mockito.Mockito
1920
import org.mockito.Mockito.verifyNoInteractions
2021
import org.mockito.MockitoAnnotations
21-
import fr.free.nrw.commons.wikidata.model.EditClaim
2222

2323
class WikidataEditServiceTest {
2424
@Mock
@@ -53,9 +53,16 @@ class WikidataEditServiceTest {
5353

5454
@Test
5555
fun testUpdateDepictsProperty() {
56-
whenever(wikibaseClient.postEditEntityByFilename("Test.jpg",
57-
gson.toJson(Mockito.mock(EditClaim::class.java)))).thenReturn(Observable.just(true))
58-
wikidataEditService.updateDepictsProperty("Test.jpg", listOf())
56+
val fileEntityId = "12345"
57+
58+
whenever(wikibaseClient.getClaimIdsByProperty("M" + fileEntityId,
59+
WikidataProperties.DEPICTS.propertyName))
60+
.thenReturn(Observable.just(emptyList()))
61+
whenever(wikibaseClient.postDeleteClaims("M" + fileEntityId,
62+
gson.toJson(Mockito.mock(RemoveClaim::class.java)))
63+
).thenReturn(Observable.just(true))
64+
65+
wikidataEditService.updateDepictsProperty(fileEntityId, listOf())
5966
}
6067

6168
@Test

0 commit comments

Comments
 (0)