Skip to content

Commit d0fa28c

Browse files
committed
Merge branch 'master' of https://github.com/commons-app/apps-android-commons into notification_read
2 parents 53c8758 + 341f961 commit d0fa28c

File tree

87 files changed

+1015
-417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1015
-417
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ dependencies {
6666
// Android testing
6767
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
6868
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
69+
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
6970
androidTestImplementation 'androidx.test:runner:1.1.1'
7071
androidTestImplementation 'androidx.test:rules:1.1.1'
7172
androidTestImplementation 'androidx.annotation:annotation:1.0.2'

app/proguard-rules.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
-dontwarn net.bytebuddy.**
66
-dontwarn org.mockito.**
77

8+
# --- Apache ---
89
-keep class org.apache.http.** { *; }
9-
-dontwarn org.apache.http.**
10-
-keep class android.support.v7.widget.ShareActionProvider { *; }
10+
-dontwarn org.apache.**
11+
# --- /Apache ---
1112

1213
# --- Butter Knife ---
1314
# Finder.castParam() is stripped when not needed and ProGuard notes it
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package fr.free.nrw.commons;
2+
3+
import org.junit.Rule;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
7+
import androidx.test.espresso.contrib.DrawerActions;
8+
import androidx.test.espresso.contrib.NavigationViewActions;
9+
import androidx.test.filters.LargeTest;
10+
import androidx.test.rule.ActivityTestRule;
11+
import androidx.test.runner.AndroidJUnit4;
12+
13+
import static androidx.test.espresso.Espresso.onView;
14+
import static androidx.test.espresso.matcher.ViewMatchers.withId;
15+
16+
@LargeTest
17+
@RunWith(AndroidJUnit4.class)
18+
public class NavigationBaseActivityTest {
19+
@Rule
20+
public ActivityTestRule activityRule = new ActivityTestRule<>(AboutActivity.class);
21+
22+
/**
23+
* Goes through all the activities in the app and checks we don't crash
24+
* NB: This is not realistic if we're not logged in; we can access 'home', 'notifications', 'settings' and 'achievements' which we wouldn't otherwise be able to.
25+
*/
26+
@Test
27+
public void goThroughNavigationBaseActivityActivities() {
28+
// Home
29+
openNavigationDrawerAndNavigateTo(R.id.action_home);
30+
31+
// Explore
32+
openNavigationDrawerAndNavigateTo(R.id.action_explore);
33+
34+
// Bookmarks
35+
openNavigationDrawerAndNavigateTo(R.id.action_bookmarks);
36+
37+
// About
38+
openNavigationDrawerAndNavigateTo(R.id.action_about);
39+
40+
// Settings
41+
openNavigationDrawerAndNavigateTo(R.id.action_settings);
42+
43+
// Achievements
44+
openNavigationDrawerAndNavigateTo(R.id.action_login);
45+
}
46+
47+
/**
48+
* Clicks 'Explore' in the navigation drawer twice, then clicks 'home'
49+
* Testing to avoid regression of #2200
50+
*/
51+
@Test
52+
public void doubleNavigateToExploreThenReturnHome() {
53+
// Explore
54+
openNavigationDrawerAndNavigateTo(R.id.action_explore);
55+
56+
// Explore
57+
openNavigationDrawerAndNavigateTo(R.id.action_explore);
58+
59+
// Home
60+
openNavigationDrawerAndNavigateTo(R.id.action_home);
61+
}
62+
63+
public void openNavigationDrawerAndNavigateTo(int menuItemId) {
64+
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
65+
onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(menuItemId));
66+
}
67+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package fr.free.nrw.commons
2+
3+
import androidx.test.espresso.Espresso.onView
4+
import androidx.test.espresso.assertion.ViewAssertions.matches
5+
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
6+
import androidx.test.espresso.matcher.ViewMatchers.withId
7+
import androidx.test.filters.LargeTest
8+
import androidx.test.rule.ActivityTestRule
9+
import androidx.test.runner.AndroidJUnit4
10+
import fr.free.nrw.commons.utils.ConfigUtils
11+
import org.hamcrest.core.IsNot.not
12+
import org.junit.Rule
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
16+
@LargeTest
17+
@RunWith(AndroidJUnit4::class)
18+
class WelcomeActivityTest {
19+
@get:Rule
20+
var activityRule: ActivityTestRule<*> = ActivityTestRule(WelcomeActivity::class.java)
21+
22+
@Test
23+
fun ifBetaShowsSkipButton() {
24+
if (ConfigUtils.isBetaFlavour()) {
25+
onView(withId(R.id.finishTutorialButton))
26+
.check(matches(isDisplayed()))
27+
}
28+
}
29+
30+
@Test
31+
fun ifProdHidesSkipButton() {
32+
if (!ConfigUtils.isBetaFlavour()) {
33+
onView(withId(R.id.finishTutorialButton))
34+
.check(matches(not(isDisplayed())))
35+
}
36+
}
37+
}

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@
109109
android:label="@string/title_activity_featured_images"
110110
android:parentActivityName=".contributions.MainActivity" />
111111

112+
<activity
113+
android:name=".explore.categories.ExploreActivity"
114+
android:label="@string/title_activity_explore"
115+
android:parentActivityName=".contributions.MainActivity" />
116+
112117
<activity
113118
android:name=".explore.SearchActivity"
114119
android:label="@string/title_activity_search"

app/src/main/java/fr/free/nrw/commons/Media.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public Media[] newArray(int i) {
3939
protected String imageUrl;
4040
protected String filename;
4141
protected String description; // monolingual description on input...
42+
protected String discussion;
4243
protected long dataLength;
4344
protected Date dateCreated;
4445
protected @Nullable Date dateUploaded;
@@ -195,6 +196,22 @@ public void setFilename(String filename) {
195196
this.filename = filename;
196197
}
197198

199+
/**
200+
* Sets the discussion of the file.
201+
* @param discussion
202+
*/
203+
public void setDiscussion(String discussion) {
204+
this.discussion = discussion;
205+
}
206+
207+
/**
208+
* Gets the file discussion as a string.
209+
* @return file discussion as a string
210+
*/
211+
public String getDiscussion() {
212+
return discussion;
213+
}
214+
198215
/**
199216
* Gets the file description.
200217
* @return file description as a string

app/src/main/java/fr/free/nrw/commons/MediaDataExtractor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.free.nrw.commons;
22

3+
import android.text.Html;
34
import androidx.annotation.Nullable;
45
import android.text.TextUtils;
56

@@ -39,6 +40,7 @@ public class MediaDataExtractor {
3940
private boolean deletionStatus;
4041
private ArrayList<String> categories;
4142
private Map<String, String> descriptions;
43+
private String discussion;
4244
private String license;
4345
private @Nullable LatLng coordinates;
4446

@@ -48,6 +50,7 @@ public MediaDataExtractor(MediaWikiApi mwApi) {
4850
this.descriptions = new HashMap<>();
4951
this.fetched = false;
5052
this.mediaWikiApi = mwApi;
53+
this.discussion = new String();
5154
}
5255

5356
/*
@@ -70,6 +73,9 @@ public void fetch(String filename, LicenseList licenseList) throws IOException {
7073
}
7174

7275
MediaResult result = mediaWikiApi.fetchMediaByFilename(filename);
76+
MediaResult discussion = mediaWikiApi.fetchMediaByFilename(filename.replace("File", "File talk"));
77+
setDiscussion(discussion.getWikiSource());
78+
7379

7480
// In-page category links are extracted from source, as XML doesn't cover [[links]]
7581
extractCategories(result.getWikiSource());
@@ -94,6 +100,14 @@ private void extractCategories(String source) {
94100
}
95101
}
96102

103+
private void setDiscussion(String source) {
104+
try {
105+
discussion = Html.fromHtml(mediaWikiApi.parseWikicode(source)).toString();
106+
} catch (IOException e) {
107+
e.printStackTrace();
108+
}
109+
}
110+
97111
private void processWikiParseTree(String source, LicenseList licenseList) throws IOException {
98112
Document doc;
99113
try {
@@ -307,6 +321,7 @@ public void fill(Media media) {
307321
media.setCategories(categories);
308322
media.setDescriptions(descriptions);
309323
media.setCoordinates(coordinates);
324+
media.setDiscussion(discussion);
310325
if (license != null) {
311326
media.setLicense(license);
312327
}

app/src/main/java/fr/free/nrw/commons/achievements/AchievementsActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ private void inflateAchievements(Achievements achievements) {
363363
*/
364364
public static void startYourself(Context context) {
365365
Intent intent = new Intent(context, AchievementsActivity.class);
366-
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
367-
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
366+
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
368367
context.startActivity(intent);
369368
}
370369

app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@
4141
import fr.free.nrw.commons.R;
4242
import fr.free.nrw.commons.Utils;
4343
import fr.free.nrw.commons.WelcomeActivity;
44-
import fr.free.nrw.commons.category.CategoryImagesActivity;
4544
import fr.free.nrw.commons.contributions.MainActivity;
4645
import fr.free.nrw.commons.di.ApplicationlessInjection;
47-
import fr.free.nrw.commons.kvstore.JsonKvStore;
46+
import fr.free.nrw.commons.explore.categories.ExploreActivity;
4847
import fr.free.nrw.commons.kvstore.JsonKvStore;
4948
import fr.free.nrw.commons.mwapi.MediaWikiApi;
5049
import fr.free.nrw.commons.theme.NavigationBaseActivity;
@@ -63,8 +62,6 @@
6362

6463
public class LoginActivity extends AccountAuthenticatorActivity {
6564

66-
private static final String FEATURED_IMAGES_CATEGORY = "Category:Featured_pictures_on_Wikimedia_Commons";
67-
6865
@Inject MediaWikiApi mwApi;
6966
@Inject SessionManager sessionManager;
7067
@Inject
@@ -155,7 +152,7 @@ public void onCreate(Bundle savedInstanceState) {
155152
*/
156153
private void skipLogin() {
157154
applicationKvStore.putBoolean("login_skipped", true);
158-
CategoryImagesActivity.startYourself(this, getString(R.string.title_activity_explore), FEATURED_IMAGES_CATEGORY);
155+
ExploreActivity.startYourself(this);
159156
finish();
160157

161158
}

app/src/main/java/fr/free/nrw/commons/category/CategoryImagesListFragment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import dagger.android.support.DaggerFragment;
2626
import fr.free.nrw.commons.Media;
2727
import fr.free.nrw.commons.R;
28+
import fr.free.nrw.commons.explore.categories.ExploreActivity;
2829
import fr.free.nrw.commons.kvstore.JsonKvStore;
2930
import fr.free.nrw.commons.utils.NetworkUtils;
3031
import fr.free.nrw.commons.utils.ViewUtil;
@@ -251,6 +252,11 @@ private void handleSuccess(List<Media> collection) {
251252
}catch (Exception e){
252253
e.printStackTrace();
253254
}
255+
try {
256+
((ExploreActivity) getContext()).viewPagerNotifyDataSetChanged();
257+
}catch (Exception e){
258+
e.printStackTrace();
259+
}
254260
}
255261
progressBar.setVisibility(GONE);
256262
isLoading = false;

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsSyncAdapter.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
4242
private static final ContentValues[] EMPTY = {};
4343
private static int COMMIT_THRESHOLD = 10;
4444

45+
// Arbitrary limit to cap the number of contributions to ever load. This is a maximum built
46+
// into the app, rather than the user's setting. Also see Github issue #52.
47+
public static final int ABSOLUTE_CONTRIBUTIONS_LOAD_LIMIT = 500;
48+
4549
@SuppressWarnings("WeakerAccess")
4650
@Inject MediaWikiApi mwApi;
4751
@Inject
@@ -52,13 +56,6 @@ public ContributionsSyncAdapter(Context context, boolean autoInitialize) {
5256
super(context, autoInitialize);
5357
}
5458

55-
private int getLimit() {
56-
57-
int limit = 500;
58-
Timber.d("Max number of uploads set to %d", limit);
59-
return limit; // FIXME: Parameterize!
60-
}
61-
6259
private boolean fileExists(ContentProviderClient client, String filename) {
6360
if (filename == null) {
6461
return false;
@@ -100,7 +97,7 @@ public void onPerformSync(Account account, Bundle bundle, String authority,
10097
while (!done) {
10198

10299
try {
103-
result = mwApi.logEvents(user, lastModified, queryContinue, getLimit());
100+
result = mwApi.logEvents(user, lastModified, queryContinue, ABSOLUTE_CONTRIBUTIONS_LOAD_LIMIT);
104101
} catch (IOException e) {
105102
// There isn't really much we can do, eh?
106103
// FIXME: Perhaps add EventLogging?

app/src/main/java/fr/free/nrw/commons/di/ActivityBuilderModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import fr.free.nrw.commons.category.CategoryImagesActivity;
1414
import fr.free.nrw.commons.explore.SearchActivity;
1515

16+
import fr.free.nrw.commons.explore.categories.ExploreActivity;
1617
import fr.free.nrw.commons.notification.NotificationActivity;
1718
import fr.free.nrw.commons.settings.SettingsActivity;
1819
import fr.free.nrw.commons.upload.UploadActivity;
@@ -54,6 +55,9 @@ public abstract class ActivityBuilderModule {
5455
@ContributesAndroidInjector
5556
abstract CategoryDetailsActivity bindCategoryDetailsActivity();
5657

58+
@ContributesAndroidInjector
59+
abstract ExploreActivity bindExploreActivity();
60+
5761
@ContributesAndroidInjector
5862
abstract AchievementsActivity bindAchievementsActivity();
5963

0 commit comments

Comments
 (0)