Skip to content

Commit

Permalink
Fix #5182 Switch From Mapbox to MapLibre
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikaykaushik14 committed Mar 21, 2023
1 parent 9722628 commit 2a0b823
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 68 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ dependencies {
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
implementation 'com.github.pedrovgs:renderers:3.3.3'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v9:0.12.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-scalebar-v9:0.5.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:7.0.0'
implementation "org.maplibre.gl:android-sdk:$MAPLIBRE_VERSION"
implementation 'org.maplibre.gl:android-plugin-scalebar-v9:1.0.0'

implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
implementation 'com.karumi:dexter:5.0.0'
Expand Down Expand Up @@ -246,6 +246,7 @@ android {

configurations.all {
resolutionStrategy.force 'androidx.annotation:annotation:1.1.0'
resolutionStrategy.force 'com.jakewharton.timber:timber:4.7.1'
exclude module: 'okhttp-ws'
}
flavorDimensions 'tier'
Expand Down
17 changes: 2 additions & 15 deletions app/src/main/java/fr/free/nrw/commons/CommonsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.WellKnownTileServer;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table;
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
Expand Down Expand Up @@ -53,7 +54,6 @@
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import leakcanary.ObjectWatcher;
import org.acra.ACRA;
import org.acra.annotation.AcraCore;
import org.acra.annotation.AcraDialog;
Expand Down Expand Up @@ -121,8 +121,6 @@ public class CommonsApplication extends MultiDexApplication {
* Constants End
*/

private ObjectWatcher objectWatcher;

private static CommonsApplication INSTANCE;

public static CommonsApplication getInstance() {
Expand Down Expand Up @@ -152,7 +150,7 @@ public void onCreate() {

INSTANCE = this;
ACRA.init(this);
Mapbox.getInstance(this, getString(R.string.mapbox_commons_app_token));
Mapbox.getInstance(this, getString(R.string.mapbox_commons_app_token), WellKnownTileServer.Mapbox);

ApplicationlessInjection
.getInstance(this)
Expand Down Expand Up @@ -268,17 +266,6 @@ public String getUserAgent() {
+ " (https://mediawiki.org/wiki/Apps/Commons) Android/" + Build.VERSION.RELEASE;
}

/**
* Provides a way to get member objectWatcher
*
* @param context Application context
* @return application member objectWatcher
*/
public static ObjectWatcher getObjectWatcher(Context context) {
CommonsApplication application = (CommonsApplication) context.getApplicationContext();
return application.objectWatcher;
}

/**
* clears data of current application
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.mapbox.android.core.location.LocationEngineCallback;
import com.mapbox.android.core.location.LocationEngineResult;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraPosition.Builder;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
import com.mapbox.mapboxsdk.location.engine.LocationEngineCallback;
import com.mapbox.mapboxsdk.location.engine.LocationEngineResult;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.location.permissions.PermissionsManager;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraIdleListener;
Expand Down Expand Up @@ -194,7 +194,7 @@ private void addCredits() {
* Clicking back button destroy locationPickerActivity
*/
private void addBackButtonListener() {
final ImageView backButton = findViewById(R.id.mapbox_place_picker_toolbar_back_button);
final ImageView backButton = findViewById(R.id.maplibre_place_picker_toolbar_back_button);
backButton.setOnClickListener(view -> finish());
}

Expand Down Expand Up @@ -238,7 +238,7 @@ private void getToolbarUI() {
@Override
public void onMapReady(final MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS, this::onStyleLoaded);
mapboxMap.setStyle(Style.getPredefinedStyle("Streets"), this::onStyleLoaded);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import javax.inject.Inject
*/
class CustomSelectorViewModelFactory @Inject constructor(val context: Context,val imageFileLoader: ImageFileLoader) : ViewModelProvider.Factory {

override fun<CustomSelectorViewModel: ViewModel?> create(modelClass: Class<CustomSelectorViewModel>) : CustomSelectorViewModel {
override fun<CustomSelectorViewModel: ViewModel> create(modelClass: Class<CustomSelectorViewModel>) : CustomSelectorViewModel {
return CustomSelectorViewModel(context,imageFileLoader) as CustomSelectorViewModel
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.Arrays;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
Expand Down Expand Up @@ -189,7 +190,8 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved
mapBox = mapBoxMap;
initViews();
presenter.setActionListeners(applicationKvStore);
mapBoxMap.setStyle(isDarkTheme? Style.DARK:Style.OUTDOORS, style -> {
mapBoxMap.setStyle(isDarkTheme? Style.getPredefinedStyle("Dark"):
Style.getPredefinedStyle("Outdoors"), style -> {
final UiSettings uiSettings = mapBoxMap.getUiSettings();
uiSettings.setCompassGravity(Gravity.BOTTOM | Gravity.LEFT);
uiSettings.setCompassMargins(12, 0, 0, 24);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved
initViews();
presenter.setActionListeners(applicationKvStore);
initNearbyFilter();
mapBoxMap.setStyle(isDarkTheme?Style.DARK:Style.OUTDOORS, style -> {
mapBoxMap.setStyle(isDarkTheme?Style.getPredefinedStyle("Dark"):Style.getPredefinedStyle("Outdoor"), style -> {
final UiSettings uiSettings = mapBoxMap.getUiSettings();
uiSettings.setCompassGravity(Gravity.BOTTOM | Gravity.LEFT);
uiSettings.setCompassMargins(12, 0, 0, 24);
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/fr/free/nrw/commons/settings/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class Prefs {
public static final String DESCRIPTION_LANGUAGE = "languageDescription";
public static final String APP_UI_LANGUAGE = "appUiLanguage";
public static final String KEY_THEME_VALUE = "appThemePref";
public static final String TELEMETRY_PREFERENCE = "telemetryPref";

public static class Licenses {
public static final String CC_BY_SA_3 = "CC BY-SA 3.0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.karumi.dexter.listener.PermissionGrantedResponse;
import com.karumi.dexter.listener.single.BasePermissionListener;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.TelemetryDefinition;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.campaigns.CampaignView;
Expand Down Expand Up @@ -161,21 +160,6 @@ public boolean onPreferenceClick(Preference preference) {
findPreference(CampaignView.CAMPAIGNS_DEFAULT_PREFERENCE).setEnabled(false);
findPreference("managed_exif_tags").setEnabled(false);
}

// Opting out of telemetry due to app's privacy policy
telemetryOptInOut(false);
defaultKvStore.putBoolean(Prefs.TELEMETRY_PREFERENCE,false);
}

/**
* Opt in or out of MapBox telemetry
* @param shouldOptIn
*/
private void telemetryOptInOut(boolean shouldOptIn){
TelemetryDefinition telemetry = Mapbox.getTelemetry();
if (telemetry != null) {
telemetry.setUserTelemetryRequestState(shouldOptIn);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ public void bind(int position) {
if (position == 0) {
removeButton.setVisibility(View.GONE);
captionInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
captionInputLayout.setEndIconDrawable(R.drawable.mapbox_info_icon_default);
captionInputLayout.setEndIconDrawable(R.drawable.maplibre_info_icon_default);
captionInputLayout.setEndIconOnClickListener(v ->
callback.showAlert(R.string.media_detail_caption, R.string.caption_info));
Objects.requireNonNull(captionInputLayout.getEditText()).setFilters(new InputFilter[] {
new UploadMediaDetailInputFilter()
});

descInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
descInputLayout.setEndIconDrawable(R.drawable.mapbox_info_icon_default);
descInputLayout.setEndIconDrawable(R.drawable.maplibre_info_icon_default);
descInputLayout.setEndIconOnClickListener(v ->
callback.showAlert(R.string.media_detail_description, R.string.description_info));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.core.app.NotificationManagerCompat
import androidx.work.CoroutineWorker
import androidx.work.Data
import androidx.work.WorkerParameters
import com.mapbox.mapboxsdk.plugins.localization.BuildConfig
import androidx.multidex.BuildConfig
import dagger.android.ContributesAndroidInjector
import fr.free.nrw.commons.CommonsApplication
import fr.free.nrw.commons.Media
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/content_location_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
android:id="@+id/map_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:mapbox_uiLogo="false"
app:maplibre_uiLogo="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_advance_query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset"
android:textColor="@color/mapbox_blue"
android:textColor="@color/maplibre_blue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/btn_apply" />

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_media_license.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
android:id="@+id/tooltip"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/mapbox_info_icon_default"/>
android:src="@drawable/maplibre_info_icon_default"/>
</LinearLayout>

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
android:id="@+id/tooltip"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/mapbox_info_icon_default"/>
android:src="@drawable/maplibre_info_icon_default"/>
</LinearLayout>

<androidx.appcompat.widget.AppCompatImageButton
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/toolbar_location_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
app:layout_constraintTop_toBottomOf="@+id/location_picker_toolbar_primary_text_view" />

<ImageView
android:id="@+id/mapbox_place_picker_toolbar_back_button"
android:id="@+id/maplibre_place_picker_toolbar_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/upload_categories_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:id="@+id/tooltip"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/mapbox_info_icon_default" />
android:src="@drawable/maplibre_info_icon_default" />
</LinearLayout>

<TextView
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/upload_depicts_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
android:id="@+id/tooltip"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/mapbox_info_icon_default" />
android:src="@drawable/maplibre_info_icon_default" />
</LinearLayout>

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.WellKnownTileServer
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.maps.UiSettings
import com.mapbox.mapboxsdk.style.layers.Layer
import com.mapbox.mapboxsdk.util.TileServerOptions
import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import fr.free.nrw.commons.LocationPicker.LocationPickerActivity
import fr.free.nrw.commons.R
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.kvstore.JsonKvStore
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.LAST_LOCATION
Expand Down Expand Up @@ -95,6 +99,12 @@ class LocationPickerActivityUnitTests {
context = RuntimeEnvironment.getApplication().applicationContext
activity = Robolectric.buildActivity(LocationPickerActivity::class.java).get()

Mapbox.getInstance(
context,
context.getString(R.string.mapbox_commons_app_token),
WellKnownTileServer.Mapbox
)

Whitebox.setInternalState(activity, "mapboxMap", mapboxMap)
Whitebox.setInternalState(activity, "applicationKvStore", applicationKvStore)
Whitebox.setInternalState(activity, "cameraPosition", cameraPosition)
Expand Down Expand Up @@ -234,9 +244,9 @@ class LocationPickerActivityUnitTests {
method.isAccessible = true
method.invoke(activity)
verify(applicationKvStore, times(1))
.putString(LAST_LOCATION, position.target.latitude.toString()
.putString(LAST_LOCATION, position.target!!.latitude.toString()
+ ","
+ position.target.longitude
+ position.target!!.longitude
)
verify(applicationKvStore, times(1))
.putString(LAST_ZOOM, position.zoom.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ class SettingsFragmentUnitTests {
method.invoke(fragment)
}

@Test
@Throws(Exception::class)
fun testTelemetryOptInOut() {
val method: Method = SettingsFragment::class.java.getDeclaredMethod(
"telemetryOptInOut",
Boolean::class.java
)
method.isAccessible = true
method.invoke(fragment, true)
}

@Test
@Throws(Exception::class)
fun testCheckPermissionsAndSendLogs() {
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Thu Mar 01 15:28:48 IST 2018
org.gradle.jvmargs=-Xmx4096M
org.gradle.jvmargs=-Xmx1536M
android.enableBuildCache=true

KOTLIN_VERSION=1.7.20
Expand All @@ -27,6 +27,7 @@ ADAPTER_DELEGATES_VERSION=4.3.0
PAGING_VERSION=2.1.2
MULTIDEX_VERSION=2.0.1
OKHTTP_VERSION=4.10.0
MAPLIBRE_VERSION=10.0.1

systemProp.http.proxyPort=0
systemProp.http.proxyHost=
Expand Down

0 comments on commit 2a0b823

Please sign in to comment.