Skip to content

Commit 2063f8f

Browse files
ashishkumar468macgillssivaraamkbhardwaj123VitalyVPinchuk
committed
Sync master with release (commons-app#3922)
* commons-app#3624 DateTimeFormat wrong - match pattern returned from servers (commons-app#3625) * Revert "Fixes: commons-app#3179 Make category search non case-sensitive (commons-app#3326)" (commons-app#3636) Simply lower casing the name of the category sent to the server doesn't result in the server doing a case insensitive category search. In fact, it reduces the category search space as only categories that has a lower case character is searched even if the search text contains upper case characters. The test case did not catch this issue as the first character of the title is case insensitive[1]. So, revert the changes done in commit afdeaae. See further disucssion in the issue thread of commons-app#3179 starting from [2]. [1]: https://www.mediawiki.org/wiki/Manual:Page_title [2]: commons-app#3179 (comment) * Bugfix/security exception (commons-app#3627) * Fixes commons-app#3626 * Check is file is actually created before writing to file, file picker android * Handle Security exception * Fixes commons-app#3436 and commons-app#2881: Media Detail design Overhaul (commons-app#3505) * ic_map_dark_24dp: map icon for white background * ic_info_outline_dark_24dp: info icon for dark background * MediaDetailFragment: update the spacer as per image aspect ratio * fragment_media_detail: design overhaul * fragment_media_detail: remove redundant background color statements * make requested changes * add dark mode support * minor ui tweak * white map icon in dark mode * make rquested changes * make requested changes to layout * fix misalignment of category list * subtle amendments * convert comments to javadocs * minor amendments * minor changes * add styles for media detail * Media detail fragment refactored * make suggested changes * minor name fix * fix the delete button border * Fixes commons-app#3639 (Fix Save State implementation of CheckBoxTriState ) (commons-app#3686) * Add commons-app#3723 and commons-app#3721 to 2.13 release, fix conflicts Conflicts were caused by merging commons-app#3723 before commons-app#3721 , so I just rolled both into one commit. * Fix NullPointer when clicking on image in MediaDetailFragment (commons-app#3730)… (commons-app#3739) * Update changelog.md * Versioning for v2.13 * Fixes commons-app#3705 (Crash when viewing pic I just uploaded) (commons-app#3782) * Fixes commons-app#3705 * Let the MediaDetailPager fragment know when the contributions have been updated * Handle NPE, null check on adapter in MediaDetailPagerFragment * Fixed BookmarkLocationsDao DB migration (commons-app#3793) * Fixes commons-app#3725 (commons-app#3795) * Downgraded okhttp version to support Api 19 devices * Handled null CompoundDrawable[2] in etTitle-> UploadMediaDetailsFragment (commons-app#3828) * DownSample Upload image to be shown in UploadMediaDetailFragment to handle OOM, Bitmap Too large exception (commons-app#3830) * Fixes commons-app#3829 * DownSample Upload image to be shown in UploadMediaDetailFragment to handle OOM, Bitmap Too large exception * removed unused imports, handled possible exceptions * Let Fresco handle the downsampling of image * invalidate in onTransformEnd * Expose an interface TransformationListener in ZoomableDraweeView to listen to transformation change end * removed photoView dependency * removed unused imports in ZoomableActivity * Bugfix, expand/collapse * changed functio name * Bugfix/p18 uploads (commons-app#3869) * updated gradle plugin version * BugFix commons-app#3856 * Do not use preference for deciding acceptable lat long for nearby uploads, instead save the corresponding location in the Contribution via UploadItem * Marshall contribution's hasInvalidLocation * reset un-related changes * Fixed test cases * Minor code formatting and docs * Fixes commons-app#3882 (commons-app#3883) * Make hasInvalidLocation non-null integer with default value 0 Co-authored-by: Ashish Kumar <[email protected]> * Fixes commons-app#3766, Added OPENSTREET attribution (commons-app#3889) * Fixes commons-app#3766 * Added OPENSTREET attribution in nearby * Added custom text attribution in Nearby * Deleted unused class CustomBorderTextView * review suggested changes * modified telemetry summary string * Versioning and changelog for v2.13.1 (commons-app#3908) * Update changelog.md * Versioning for v2.13.1 * Fixes commons-app#3914 (commons-app#3915) * Verify user login before setting upload count * fixed compile-time error * fix erros * delete emptied files * remove empty file CategoriesModel.java Co-authored-by: Seán Mac Gillicuddy <[email protected]> Co-authored-by: Kaartic Sivaraam <[email protected]> Co-authored-by: Kshitij Bhardwaj <[email protected]> Co-authored-by: Vitaly V. Pinchuk <[email protected]> Co-authored-by: Josephine Lim <[email protected]> Co-authored-by: Ashish Kumar <[email protected]>
1 parent ab2ba07 commit 2063f8f

22 files changed

+545
-428
lines changed

app/build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ dependencies {
2121
// Utils
2222
implementation 'in.yuvi:http.fluent:1.3'
2323
implementation 'com.google.code.gson:gson:2.8.5'
24-
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
24+
implementation ("com.squareup.okhttp3:okhttp:$OKHTTP_VERSION"){
25+
force = true //API 19 support
26+
}
2527
implementation 'com.squareup.okio:okio:2.2.2'
2628
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
2729
implementation 'io.reactivex.rxjava2:rxjava:2.2.3'
@@ -35,6 +37,7 @@ dependencies {
3537
// UI
3638
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
3739
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
40+
implementation 'com.github.pedrovgs:renderers:3.3.3'
3841
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.2'
3942
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v8:0.11.0'
4043
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-scalebar-v9:0.4.0'
@@ -51,7 +54,7 @@ dependencies {
5154
testImplementation "androidx.paging:paging-common-ktx:$PAGING_VERSION"
5255
implementation "androidx.paging:paging-rxjava2-ktx:$PAGING_VERSION"
5356
implementation "androidx.recyclerview:recyclerview:1.2.0-alpha02"
54-
implementation 'com.squareup.okhttp3:okhttp-ws:3.4.1'
57+
implementation "com.squareup.okhttp3:okhttp-ws:$OKHTTP_VERSION"
5558

5659
// Logging
5760
implementation 'ch.acra:acra-dialog:5.3.0'
@@ -60,7 +63,7 @@ dependencies {
6063
api('com.github.tony19:logback-android-classic:1.1.1-6') {
6164
exclude group: 'com.google.android', module: 'android'
6265
}
63-
implementation "com.squareup.okhttp3:logging-interceptor:4.5.0"
66+
implementation "com.squareup.okhttp3:logging-interceptor:$OKHTTP_VERSION"
6467

6568
// Dependency injector
6669
implementation "com.google.dagger:dagger-android-support:$DAGGER_VERSION"
@@ -81,7 +84,7 @@ dependencies {
8184
testImplementation 'junit:junit:4.13'
8285
testImplementation 'org.robolectric:robolectric:4.3'
8386
testImplementation 'androidx.test:core:1.2.0'
84-
testImplementation "com.squareup.okhttp3:mockwebserver:4.8.0"
87+
testImplementation "com.squareup.okhttp3:mockwebserver:$OKHTTP_VERSION"
8588
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
8689
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
8790
testImplementation 'org.mockito:mockito-core:2.23.0'
@@ -139,8 +142,8 @@ android {
139142

140143
defaultConfig {
141144
//applicationId 'fr.free.nrw.commons'
142-
versionCode 561
143-
versionName '2.12.3'
145+
versionCode 775
146+
versionName '2.13.1'
144147
setProperty("archivesBaseName", "app-commons-v$versionName-" + getBranchName())
145148

146149
minSdkVersion 19

app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationsDao.java

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,24 +248,44 @@ public static void onDelete(SQLiteDatabase db) {
248248

249249
public static void onUpdate(SQLiteDatabase db, int from, int to) {
250250
Timber.d("bookmarksLocations db is updated from:"+from+", to:"+to);
251-
switch (from) {
252-
case 7: onCreate(db);
253-
case 8: // No change
254-
case 9: // No change
255-
case 10:
256-
try {
257-
db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_pic STRING;");
258-
} catch (SQLiteException exception){
259-
Timber.e(exception);
260-
}
261-
case 11: // No change
262-
case 12:
263-
try {
264-
db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_destroyed STRING;");
265-
}catch (SQLiteException exception){
266-
Timber.e(exception);
267-
}
268-
break;
251+
if (from == to) {
252+
return;
253+
}
254+
if (from < 7) {
255+
// doesn't exist yet
256+
from++;
257+
onUpdate(db, from, to);
258+
return;
259+
}
260+
if (from == 7) {
261+
// table added in version 8
262+
onCreate(db);
263+
from++;
264+
onUpdate(db, from, to);
265+
return;
266+
}
267+
if (from == 8) {
268+
from++;
269+
onUpdate(db, from, to);
270+
return;
271+
}
272+
if (from == 10) {
273+
//This is safe, and can be called clean, as we/I do not remember the appropriate version for this
274+
//We are anyways switching to room, these things won't be necessary then
275+
try {
276+
db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_pic STRING;");
277+
}catch (SQLiteException exception){
278+
Timber.e(exception);//
279+
}
280+
return;
281+
}
282+
if (from == 12) {
283+
try {
284+
db.execSQL(
285+
"ALTER TABLE bookmarksLocations ADD COLUMN location_destroyed STRING;");
286+
} catch (SQLiteException exception) {
287+
Timber.e(exception);
288+
}
269289
}
270290
}
271291
}

app/src/main/java/fr/free/nrw/commons/contributions/Contribution.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ data class Contribution constructor(
3838
val localUri: Uri? = null,
3939
var dataLength: Long = 0,
4040
var dateCreated: Date? = null,
41-
var dateModified: Date? = null
41+
var dateModified: Date? = null,
42+
var hasInvalidLocation : Int = 0
4243
) : Parcelable {
4344

4445
fun completeWith(media: Media): Contribution {
@@ -65,6 +66,18 @@ data class Contribution constructor(
6566
wikidataPlace = from(item.place)
6667
)
6768

69+
/**
70+
* Set this true when ImageProcessor has said that the location is invalid
71+
* @param hasInvalidLocation
72+
*/
73+
fun setHasInvalidLocation(hasInvalidLocation: Boolean) {
74+
this.hasInvalidLocation = if (hasInvalidLocation) 1 else 0
75+
}
76+
77+
fun hasInvalidLocation(): Boolean {
78+
return hasInvalidLocation == 1
79+
}
80+
6881
companion object {
6982
const val STATE_COMPLETED = -1
7083
const val STATE_FAILED = 1

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
import androidx.fragment.app.Fragment;
2323
import androidx.fragment.app.FragmentManager.OnBackStackChangedListener;
2424
import androidx.fragment.app.FragmentTransaction;
25+
26+
import fr.free.nrw.commons.MediaDataExtractor;
27+
import fr.free.nrw.commons.auth.SessionManager;
28+
import io.reactivex.disposables.Disposable;
29+
import java.util.List;
30+
31+
import javax.inject.Inject;
32+
import javax.inject.Named;
33+
2534
import butterknife.BindView;
2635
import butterknife.ButterKnife;
2736
import fr.free.nrw.commons.Media;
@@ -83,6 +92,9 @@ public class ContributionsFragment
8392

8493
@Inject ContributionsPresenter contributionsPresenter;
8594

95+
@Inject
96+
SessionManager sessionManager;
97+
8698
private LatLng curLatLng;
8799

88100
private boolean firstLocationUpdate = true;
@@ -143,7 +155,14 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
143155

144156
initFragments();
145157

146-
if (!ConfigUtils.isBetaFlavour()) {
158+
if(shouldShowMediaDetailsFragment){
159+
showMediaDetailPagerFragment();
160+
}else{
161+
showContributionsListFragment();
162+
}
163+
164+
if (!ConfigUtils.isBetaFlavour() && sessionManager.isUserLoggedIn()
165+
&& sessionManager.getCurrentAccount() != null) {
147166
setUploadCount();
148167
}
149168

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private void initRecyclerView() {
132132
getSpanCount(getResources().getConfiguration().orientation));
133133
rvContributionsList.setLayoutManager(layoutManager);
134134
contributionsListPresenter.setup();
135-
contributionsListPresenter.contributionList.observe(this, adapter::submitList);
135+
contributionsListPresenter.contributionList.observe(this.getViewLifecycleOwner(), adapter::submitList);
136136
rvContributionsList.setAdapter(adapter);
137137
}
138138

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import android.view.inputmethod.InputMethodManager;
88
import androidx.collection.LruCache;
99
import androidx.room.Room;
10+
import androidx.room.migration.Migration;
11+
import androidx.sqlite.db.SupportSQLiteDatabase;
1012
import com.google.gson.Gson;
1113
import dagger.Module;
1214
import dagger.Provides;
@@ -49,6 +51,15 @@ public class CommonsApplicationModule {
4951
private Context applicationContext;
5052
public static final String IO_THREAD="io_thread";
5153
public static final String MAIN_THREAD="main_thread";
54+
private AppDatabase appDatabase;
55+
56+
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
57+
@Override
58+
public void migrate(SupportSQLiteDatabase database) {
59+
database.execSQL("ALTER TABLE contribution "
60+
+ " ADD COLUMN hasInvalidLocation INTEGER NOT NULL DEFAULT 0");
61+
}
62+
};
5263

5364
public CommonsApplicationModule(Context applicationContext) {
5465
this.applicationContext = applicationContext;
@@ -103,11 +114,6 @@ public ContentProviderClient provideCategoryContentProviderClient(Context contex
103114
return context.getContentResolver().acquireContentProviderClient(BuildConfig.CATEGORY_AUTHORITY);
104115
}
105116

106-
/**
107-
* This method is used to provide instance of DepictsContentProviderClient
108-
* @param context context
109-
* @return DepictsContentProviderClient*/
110-
111117
/**
112118
* This method is used to provide instance of RecentSearchContentProviderClient
113119
* which provides content of Recent Searches from database
@@ -224,9 +230,11 @@ public String provideLoggedInUsername() {
224230
@Provides
225231
@Singleton
226232
public AppDatabase provideAppDataBase() {
227-
return Room.databaseBuilder(applicationContext, AppDatabase.class, "commons_room.db")
233+
appDatabase = Room.databaseBuilder(applicationContext, AppDatabase.class, "commons_room.db")
234+
.addMigrations(MIGRATION_1_2)
228235
.fallbackToDestructiveMigration()
229236
.build();
237+
return appDatabase;
230238
}
231239

232240
@Provides

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public HttpLoggingInterceptor provideHttpLoggingInterceptor() {
7676
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(message -> {
7777
Timber.tag("OkHttp").v(message);
7878
});
79-
httpLoggingInterceptor.level(BuildConfig.DEBUG ? Level.BODY: Level.BASIC);
79+
httpLoggingInterceptor.setLevel(BuildConfig.DEBUG ? Level.BODY: Level.BASIC);
8080
return httpLoggingInterceptor;
8181
}
8282

app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ public void showImage(int i) {
295295
* The method notify the viewpager that number of items have changed.
296296
*/
297297
public void notifyDataSetChanged(){
298-
adapter.notifyDataSetChanged();
298+
if (null != adapter) {
299+
adapter.notifyDataSetChanged();
300+
}
299301
}
300302

301303
@Override

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import android.graphics.drawable.VectorDrawable;
2020
import android.os.Bundle;
2121
import android.provider.Settings;
22+
import android.text.Html;
23+
import android.text.method.LinkMovementMethod;
2224
import android.util.Log;
2325
import android.view.Gravity;
2426
import android.view.LayoutInflater;
@@ -39,6 +41,7 @@
3941
import androidx.annotation.Nullable;
4042
import androidx.appcompat.app.AlertDialog;
4143
import androidx.fragment.app.Fragment;
44+
import androidx.appcompat.widget.AppCompatTextView;
4245
import androidx.recyclerview.widget.DividerItemDecoration;
4346
import androidx.recyclerview.widget.LinearLayoutManager;
4447
import androidx.recyclerview.widget.RecyclerView;
@@ -75,7 +78,6 @@
7578
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
7679
import fr.free.nrw.commons.contributions.ContributionController;
7780
import fr.free.nrw.commons.contributions.MainActivity;
78-
import fr.free.nrw.commons.di.ApplicationlessInjection;
7981
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
8082
import fr.free.nrw.commons.kvstore.JsonKvStore;
8183
import fr.free.nrw.commons.location.LocationServiceManager;
@@ -154,6 +156,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
154156
@BindView(R.id.rv_nearby_list)
155157
RecyclerView rvNearbyList;
156158
@BindView(R.id.no_results_message) TextView noResultsView;
159+
@BindView(R.id.tv_attribution)
160+
AppCompatTextView tvAttribution;
157161

158162
@Inject LocationServiceManager locationManager;
159163
@Inject NearbyController nearbyController;
@@ -235,8 +239,8 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved
235239
final UiSettings uiSettings = mapBoxMap.getUiSettings();
236240
uiSettings.setCompassGravity(Gravity.BOTTOM | Gravity.LEFT);
237241
uiSettings.setCompassMargins(12, 0, 0, 24);
238-
uiSettings.setLogoEnabled(true);
239-
uiSettings.setAttributionEnabled(true);
242+
uiSettings.setLogoEnabled(false);
243+
uiSettings.setAttributionEnabled(false);
240244
uiSettings.setRotateGesturesEnabled(false);
241245
isMapBoxReady =true;
242246
performMapReadyActions();
@@ -259,6 +263,9 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved
259263
scaleBarPlugin.create(scaleBarOptions);
260264
});
261265
});
266+
267+
tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
268+
tvAttribution.setMovementMethod(LinkMovementMethod.getInstance());
262269
}
263270

264271
/**
@@ -659,7 +666,7 @@ public LatLng getLastFocusLocation() {
659666

660667
@Override
661668
public boolean isCurrentLocationMarkerVisible() {
662-
if (latLngBounds == null) {
669+
if (latLngBounds == null || currentLocationMarker==null) {
663670
Timber.d("Map projection bounds are null");
664671
return false;
665672
} else {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import com.karumi.dexter.Dexter;
1515
import com.karumi.dexter.listener.PermissionGrantedResponse;
1616
import com.karumi.dexter.listener.single.BasePermissionListener;
17+
import com.mapbox.mapboxsdk.Mapbox;
18+
import com.mapbox.mapboxsdk.maps.TelemetryDefinition;
1719
import fr.free.nrw.commons.R;
1820
import fr.free.nrw.commons.Utils;
1921
import fr.free.nrw.commons.di.ApplicationlessInjection;
@@ -85,6 +87,24 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
8587
findPreference("displayLocationPermissionForCardView").setEnabled(false);
8688
findPreference("displayCampaignsCardView").setEnabled(false);
8789
}
90+
91+
findPreference("telemetryOptOut").setOnPreferenceChangeListener(
92+
(preference, newValue) -> {
93+
telemetryOptInOut((boolean)newValue);
94+
defaultKvStore.putBoolean(Prefs.TELEMETRY_PREFERENCE,(boolean)newValue);
95+
return false;
96+
});
97+
}
98+
99+
/**
100+
* Opt in or out of MapBox telemetry
101+
* @param shouldOptIn
102+
*/
103+
private void telemetryOptInOut(boolean shouldOptIn){
104+
TelemetryDefinition telemetry = Mapbox.getTelemetry();
105+
if (telemetry != null) {
106+
telemetry.setUserTelemetryRequestState(shouldOptIn);
107+
}
88108
}
89109

90110
/**

app/src/main/java/fr/free/nrw/commons/upload/UploadItem.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class UploadItem {
2222
private final long createdTimestamp;
2323
private final String createdTimestampSource;
2424
private final BehaviorSubject<Integer> imageQuality;
25+
private boolean hasInvalidLocation;
26+
2527

2628
@SuppressLint("CheckResult")
2729
UploadItem(final Uri mediaUri,
@@ -103,4 +105,11 @@ public void setGpsCoords(final ImageCoordinates gpsCoords) {
103105
this.gpsCoords = gpsCoords;
104106
}
105107

108+
public void setHasInvalidLocation(boolean hasInvalidLocation) {
109+
this.hasInvalidLocation=hasInvalidLocation;
110+
}
111+
112+
public boolean hasInvalidLocation() {
113+
return hasInvalidLocation;
114+
}
106115
}

0 commit comments

Comments
 (0)