Skip to content

Commit fcc3053

Browse files
Fixes #3766, Added OPENSTREET attribution (#3889)
* Fixes #3766 * Added OPENSTREET attribution in nearby * Added custom text attribution in Nearby * Deleted unused class CustomBorderTextView * review suggested changes * modified telemetry summary string
1 parent aa1d6fe commit fcc3053

File tree

6 files changed

+71
-26
lines changed

6 files changed

+71
-26
lines changed

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

+26-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package fr.free.nrw.commons.nearby.fragments;
22

3+
import static fr.free.nrw.commons.contributions.MainActivity.CONTRIBUTIONS_TAB_POSITION;
4+
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
5+
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED;
6+
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.MAP_UPDATED;
7+
import static fr.free.nrw.commons.nearby.Label.TEXT_TO_DESCRIPTION;
8+
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
9+
import static fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT;
10+
311
import android.Manifest;
412
import android.app.AlertDialog;
513
import android.content.BroadcastReceiver;
@@ -11,6 +19,8 @@
1119
import android.graphics.Bitmap;
1220
import android.os.Bundle;
1321
import android.provider.Settings;
22+
import android.text.Html;
23+
import android.text.method.LinkMovementMethod;
1424
import android.util.Log;
1525
import android.view.Gravity;
1626
import android.view.LayoutInflater;
@@ -26,14 +36,15 @@
2636
import android.widget.SearchView;
2737
import android.widget.TextView;
2838
import android.widget.Toast;
29-
3039
import androidx.annotation.NonNull;
3140
import androidx.annotation.Nullable;
41+
import androidx.appcompat.widget.AppCompatTextView;
3242
import androidx.recyclerview.widget.DividerItemDecoration;
3343
import androidx.recyclerview.widget.LinearLayoutManager;
3444
import androidx.recyclerview.widget.RecyclerView;
3545
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
36-
46+
import butterknife.BindView;
47+
import butterknife.ButterKnife;
3748
import com.google.android.material.bottomsheet.BottomSheetBehavior;
3849
import com.google.android.material.chip.Chip;
3950
import com.google.android.material.chip.ChipGroup;
@@ -58,17 +69,6 @@
5869
import com.mapbox.pluginscalebar.ScaleBarOptions;
5970
import com.mapbox.pluginscalebar.ScaleBarPlugin;
6071
import com.pedrogomez.renderers.RVRendererAdapter;
61-
62-
import fr.free.nrw.commons.utils.DialogUtil;
63-
import java.util.ArrayList;
64-
import java.util.List;
65-
import java.util.concurrent.TimeUnit;
66-
67-
import javax.inject.Inject;
68-
import javax.inject.Named;
69-
70-
import butterknife.BindView;
71-
import butterknife.ButterKnife;
7272
import fr.free.nrw.commons.CommonsApplication;
7373
import fr.free.nrw.commons.R;
7474
import fr.free.nrw.commons.Utils;
@@ -92,6 +92,7 @@
9292
import fr.free.nrw.commons.nearby.Place;
9393
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
9494
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
95+
import fr.free.nrw.commons.utils.DialogUtil;
9596
import fr.free.nrw.commons.utils.ExecutorUtils;
9697
import fr.free.nrw.commons.utils.LayoutUtils;
9798
import fr.free.nrw.commons.utils.LocationUtils;
@@ -105,16 +106,13 @@
105106
import io.reactivex.Observable;
106107
import io.reactivex.android.schedulers.AndroidSchedulers;
107108
import io.reactivex.schedulers.Schedulers;
109+
import java.util.ArrayList;
110+
import java.util.List;
111+
import java.util.concurrent.TimeUnit;
112+
import javax.inject.Inject;
113+
import javax.inject.Named;
108114
import timber.log.Timber;
109115

110-
import static fr.free.nrw.commons.contributions.MainActivity.CONTRIBUTIONS_TAB_POSITION;
111-
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
112-
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED;
113-
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.MAP_UPDATED;
114-
import static fr.free.nrw.commons.nearby.Label.TEXT_TO_DESCRIPTION;
115-
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
116-
import static fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT;
117-
118116

119117
public class NearbyParentFragment extends CommonsDaggerSupportFragment
120118
implements NearbyParentFragmentContract.View,
@@ -154,6 +152,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
154152
MapView mapView;
155153
@BindView(R.id.rv_nearby_list)
156154
RecyclerView rvNearbyList;
155+
@BindView(R.id.tv_attribution)
156+
AppCompatTextView tvAttribution;
157157

158158
@Inject LocationServiceManager locationManager;
159159
@Inject NearbyController nearbyController;
@@ -236,8 +236,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
236236
UiSettings uiSettings = mapBoxMap.getUiSettings();
237237
uiSettings.setCompassGravity(Gravity.BOTTOM | Gravity.LEFT);
238238
uiSettings.setCompassMargins(12, 0, 0, 24);
239-
uiSettings.setLogoEnabled(true);
240-
uiSettings.setAttributionEnabled(true);
239+
uiSettings.setLogoEnabled(false);
240+
uiSettings.setAttributionEnabled(false);
241241
uiSettings.setRotateGesturesEnabled(false);
242242
NearbyParentFragment.this.isMapBoxReady=true;
243243
performMapReadyActions();
@@ -260,6 +260,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
260260
scaleBarPlugin.create(scaleBarOptions);
261261
});
262262
});
263+
264+
tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
265+
tvAttribution.setMovementMethod(LinkMovementMethod.getInstance());
263266
}
264267

265268
/**

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

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Prefs {
1010
public static final String MANAGED_EXIF_TAGS = "managed_exif_tags";
1111
public static final String KEY_LANGUAGE_VALUE = "languageDescription";
1212
public static final String KEY_THEME_VALUE = "appThemePref";
13+
public static final String TELEMETRY_PREFERENCE = "telemetryPref";
1314

1415
public static class Licenses {
1516
public static final String CC_BY_SA_3 = "CC BY-SA 3.0";

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

+20
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;
@@ -123,6 +125,24 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
123125
findPreference("displayCampaignsCardView").setEnabled(false);
124126
uploadLimit.setEnabled(false);
125127
}
128+
129+
findPreference("telemetryOptOut").setOnPreferenceChangeListener(
130+
(preference, newValue) -> {
131+
telemetryOptInOut((boolean)newValue);
132+
defaultKvStore.putBoolean(Prefs.TELEMETRY_PREFERENCE,(boolean)newValue);
133+
return false;
134+
});
135+
}
136+
137+
/**
138+
* Opt in or out of MapBox telemetry
139+
* @param shouldOptIn
140+
*/
141+
private void telemetryOptInOut(boolean shouldOptIn){
142+
TelemetryDefinition telemetry = Mapbox.getTelemetry();
143+
if (telemetry != null) {
144+
telemetry.setUserTelemetryRequestState(shouldOptIn);
145+
}
126146
}
127147

128148
/**

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<!-- I have done this intentionally, the mapview because of some elevation or something,
2727
sometimes hangs over the drawer layout and sometimes draws its onPaused state over the contributions, this seems to be the probable fix -->
28-
<FrameLayout
28+
<RelativeLayout
2929
android:layout_width="match_parent"
3030
android:layout_height="match_parent"
3131
android:layout_below="@id/nearby_filter">
@@ -40,7 +40,19 @@
4040
android:layout_height="match_parent"
4141
android:background="@android:color/transparent" />
4242

43-
</FrameLayout>
43+
<androidx.appcompat.widget.AppCompatTextView
44+
android:id="@+id/tv_attribution"
45+
android:textStyle="bold"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:layout_margin="8dp"
49+
android:layout_alignParentBottom="true"
50+
android:layout_alignParentLeft="true"
51+
android:text="@string/map_attribution"
52+
android:textAlignment="center"
53+
android:textSize="10sp" />
54+
55+
</RelativeLayout>
4456

4557

4658
<Button

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -610,5 +610,7 @@ Upload your first media by tapping on the add button.</string>
610610
<string name="ask_to_turn_location_on">Turn on location?</string>
611611
<string name="nearby_needs_location">Nearby needs location enabled to work properly</string>
612612
<string name="use_location_from_similar_image">Did you shoot these two pictures at the same place? Do you want to use the latitude/longitude of the picture on the right?</string>
613-
613+
<string name="mapbox_telemetry">Telemetry Opt Out</string>
614+
<string name="telemetry_opt_out_summary">Send anonymized location and usage data to Mapbox when using Nearby feature</string>
615+
<string name="map_attribution" translatable="false"><![CDATA[&#169; <a href="https://www.mapbox.com/about/maps/">Mapbox</a> &#169; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> <a href="https://www.mapbox.com/map-feedback/">Improve this map</a>]]></string>
614616
</resources>

app/src/main/res/xml/preferences.xml

+7
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
android:summary="@string/manage_exif_tags_summary"
8686
android:title="@string/manage_exif_tags" />
8787

88+
<SwitchPreference
89+
android:defaultValue="true"
90+
android:key="telemetryOptOut"
91+
app:singleLineTitle="false"
92+
android:summary="@string/telemetry_opt_out_summary"
93+
android:title="@string/mapbox_telemetry" />
94+
8895
</PreferenceCategory>
8996

9097
<!-- The key 'allowGps' was used before and has since been removed based on the discussion at #1599.

0 commit comments

Comments
 (0)