mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Fix warnings, Fix formatting, Add javadoc
This commit is contained in:
parent
8d5a0595d9
commit
b02fe08988
2 changed files with 40 additions and 31 deletions
|
|
@ -1739,7 +1739,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
replaceMarkerOverlays(NearbyController.markerLabelList);
|
replaceMarkerOverlays(NearbyController.markerLabelList);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ArrayList<MarkerPlaceGroup> es = new ArrayList<>();
|
ArrayList<MarkerPlaceGroup> placeGroupsToShow = new ArrayList<>();
|
||||||
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
|
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
|
||||||
final Place place = markerPlaceGroup.getPlace();
|
final Place place = markerPlaceGroup.getPlace();
|
||||||
// When label filter is engaged
|
// When label filter is engaged
|
||||||
|
|
@ -1780,11 +1780,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldUpdateMarker) {
|
if (shouldUpdateMarker) {
|
||||||
MarkerPlaceGroup e = new MarkerPlaceGroup(markerPlaceGroup.getIsBookmarked(), place);
|
placeGroupsToShow.add(
|
||||||
es.add(e);
|
new MarkerPlaceGroup(markerPlaceGroup.getIsBookmarked(), place)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
replaceMarkerOverlays(es);
|
replaceMarkerOverlays(placeGroupsToShow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -1884,6 +1885,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
return marker;
|
return marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds multiple markers representing places to the map and handles item gestures.
|
||||||
|
*
|
||||||
|
* @param markerPlaceGroups The list of marker place groups containing the places and
|
||||||
|
* their bookmarked status
|
||||||
|
*/
|
||||||
public void replaceMarkerOverlays(final List<MarkerPlaceGroup> markerPlaceGroups) {
|
public void replaceMarkerOverlays(final List<MarkerPlaceGroup> markerPlaceGroups) {
|
||||||
ArrayList<Marker> newMarkers = new ArrayList<>(markerPlaceGroups.size());
|
ArrayList<Marker> newMarkers = new ArrayList<>(markerPlaceGroups.size());
|
||||||
for (MarkerPlaceGroup markerPlaceGroup : markerPlaceGroups) {
|
for (MarkerPlaceGroup markerPlaceGroup : markerPlaceGroups) {
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,8 @@ class NearbyParentFragmentPresenter
|
||||||
* - **connnectionCount**: number of parallel requests
|
* - **connnectionCount**: number of parallel requests
|
||||||
*/
|
*/
|
||||||
private object LoadPlacesAsyncOptions {
|
private object LoadPlacesAsyncOptions {
|
||||||
val batchSize = 3
|
const val BATCH_SIZE = 3
|
||||||
val connectionCount = 3
|
const val CONNECTION_COUNT = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
private var schedulePlacesUpdateJob: Job? = null
|
private var schedulePlacesUpdateJob: Job? = null
|
||||||
|
|
@ -86,9 +86,9 @@ class NearbyParentFragmentPresenter
|
||||||
* @see schedulePlacesUpdate
|
* @see schedulePlacesUpdate
|
||||||
*/
|
*/
|
||||||
private object SchedulePlacesUpdateOptions {
|
private object SchedulePlacesUpdateOptions {
|
||||||
var skippedCount = 0 //
|
var skippedCount = 0
|
||||||
val skipLimit = 3 //
|
const val SKIP_LIMIT = 3
|
||||||
val skipDelayMs = 500L //
|
const val SKIP_DELAY_MS = 500L
|
||||||
}
|
}
|
||||||
|
|
||||||
// used to tell the asynchronous place detail loading job that the places' bookmarked status
|
// used to tell the asynchronous place detail loading job that the places' bookmarked status
|
||||||
|
|
@ -110,8 +110,10 @@ class NearbyParentFragmentPresenter
|
||||||
if (markerPlaceGroups.isEmpty()) return@withContext
|
if (markerPlaceGroups.isEmpty()) return@withContext
|
||||||
schedulePlacesUpdateJob?.cancel()
|
schedulePlacesUpdateJob?.cancel()
|
||||||
schedulePlacesUpdateJob = launch {
|
schedulePlacesUpdateJob = launch {
|
||||||
if (SchedulePlacesUpdateOptions.skippedCount++ < SchedulePlacesUpdateOptions.skipLimit) {
|
if (SchedulePlacesUpdateOptions.skippedCount++
|
||||||
delay(SchedulePlacesUpdateOptions.skipDelayMs)
|
< SchedulePlacesUpdateOptions.SKIP_LIMIT
|
||||||
|
) {
|
||||||
|
delay(SchedulePlacesUpdateOptions.SKIP_DELAY_MS)
|
||||||
}
|
}
|
||||||
SchedulePlacesUpdateOptions.skippedCount = 0
|
SchedulePlacesUpdateOptions.skippedCount = 0
|
||||||
updatePlaceGroupsToControllerAndRender(markerPlaceGroups)
|
updatePlaceGroupsToControllerAndRender(markerPlaceGroups)
|
||||||
|
|
@ -320,21 +322,21 @@ class NearbyParentFragmentPresenter
|
||||||
schedulePlacesUpdate(updatedGroups)
|
schedulePlacesUpdate(updatedGroups)
|
||||||
}
|
}
|
||||||
// channel for lists of indices of places, each list to be fetched in a single request
|
// channel for lists of indices of places, each list to be fetched in a single request
|
||||||
val fetchPlacesChannel = Channel<List<Int>>(Channel.UNLIMITED);
|
val fetchPlacesChannel = Channel<List<Int>>(Channel.UNLIMITED)
|
||||||
var totalBatches = 0
|
var totalBatches = 0
|
||||||
for (i in indicesToUpdate.indices step LoadPlacesAsyncOptions.batchSize) {
|
for (i in indicesToUpdate.indices step LoadPlacesAsyncOptions.BATCH_SIZE) {
|
||||||
++totalBatches
|
++totalBatches
|
||||||
fetchPlacesChannel.send(
|
fetchPlacesChannel.send(
|
||||||
indicesToUpdate.slice(
|
indicesToUpdate.slice(
|
||||||
i until (i + LoadPlacesAsyncOptions.batchSize).coerceAtMost(
|
i until (i + LoadPlacesAsyncOptions.BATCH_SIZE).coerceAtMost(
|
||||||
indicesToUpdate.size
|
indicesToUpdate.size
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fetchPlacesChannel.close()
|
fetchPlacesChannel.close()
|
||||||
val collectResults = Channel<List<Pair<Int, MarkerPlaceGroup>>>(totalBatches);
|
val collectResults = Channel<List<Pair<Int, MarkerPlaceGroup>>>(totalBatches)
|
||||||
repeat(LoadPlacesAsyncOptions.connectionCount) {
|
repeat(LoadPlacesAsyncOptions.CONNECTION_COUNT) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
for (indices in fetchPlacesChannel) {
|
for (indices in fetchPlacesChannel) {
|
||||||
ensureActive()
|
ensureActive()
|
||||||
|
|
@ -350,7 +352,7 @@ class NearbyParentFragmentPresenter
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.tag("NearbyPinDetails").e(e);
|
Timber.tag("NearbyPinDetails").e(e)
|
||||||
collectResults.send(indices.map { Pair(it, updatedGroups[it]) })
|
collectResults.send(indices.map { Pair(it, updatedGroups[it]) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -485,7 +487,7 @@ class NearbyParentFragmentPresenter
|
||||||
override fun updateMapMarkersToController(baseMarkers: MutableList<BaseMarker>) {
|
override fun updateMapMarkersToController(baseMarkers: MutableList<BaseMarker>) {
|
||||||
NearbyController.markerLabelList.clear()
|
NearbyController.markerLabelList.clear()
|
||||||
for (i in baseMarkers.indices) {
|
for (i in baseMarkers.indices) {
|
||||||
val nearbyBaseMarker = baseMarkers.get(i)
|
val nearbyBaseMarker = baseMarkers[i]
|
||||||
NearbyController.markerLabelList.add(
|
NearbyController.markerLabelList.add(
|
||||||
MarkerPlaceGroup(
|
MarkerPlaceGroup(
|
||||||
bookmarkLocationDao.findBookmarkLocation(nearbyBaseMarker.place),
|
bookmarkLocationDao.findBookmarkLocation(nearbyBaseMarker.place),
|
||||||
|
|
@ -544,13 +546,13 @@ class NearbyParentFragmentPresenter
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
//TODO
|
//TODO
|
||||||
val mylocation = Location("")
|
val myLocation = Location("")
|
||||||
val dest_location = Location("")
|
val destLocation = Location("")
|
||||||
dest_location.setLatitude(nearbyParentFragmentView.getMapFocus().latitude)
|
destLocation.latitude = nearbyParentFragmentView.getMapFocus().latitude
|
||||||
dest_location.setLongitude(nearbyParentFragmentView.getMapFocus().longitude)
|
destLocation.longitude = nearbyParentFragmentView.getMapFocus().longitude
|
||||||
mylocation.setLatitude(nearbyParentFragmentView.getLastMapFocus().latitude)
|
myLocation.latitude = nearbyParentFragmentView.getLastMapFocus().latitude
|
||||||
mylocation.setLongitude(nearbyParentFragmentView.getLastMapFocus().longitude)
|
myLocation.longitude = nearbyParentFragmentView.getLastMapFocus().longitude
|
||||||
val distance = mylocation.distanceTo(dest_location)
|
val distance = myLocation.distanceTo(destLocation)
|
||||||
|
|
||||||
return (distance <= 2000.0 * 3 / 4)
|
return (distance <= 2000.0 * 3 / 4)
|
||||||
}
|
}
|
||||||
|
|
@ -564,17 +566,17 @@ class NearbyParentFragmentPresenter
|
||||||
NearbyParentFragmentContract.View::class.java.getClassLoader(),
|
NearbyParentFragmentContract.View::class.java.getClassLoader(),
|
||||||
arrayOf<Class<*>>(NearbyParentFragmentContract.View::class.java),
|
arrayOf<Class<*>>(NearbyParentFragmentContract.View::class.java),
|
||||||
InvocationHandler { proxy: Any?, method: Method?, args: Array<Any?>? ->
|
InvocationHandler { proxy: Any?, method: Method?, args: Array<Any?>? ->
|
||||||
if (method!!.getName() == "onMyEvent") {
|
if (method!!.name == "onMyEvent") {
|
||||||
return@InvocationHandler null
|
return@InvocationHandler null
|
||||||
} else if (String::class.java == method.getReturnType()) {
|
} else if (String::class.java == method.returnType) {
|
||||||
return@InvocationHandler ""
|
return@InvocationHandler ""
|
||||||
} else if (Int::class.java == method.getReturnType()) {
|
} else if (Int::class.java == method.returnType) {
|
||||||
return@InvocationHandler 0
|
return@InvocationHandler 0
|
||||||
} else if (Int::class.javaPrimitiveType == method.getReturnType()) {
|
} else if (Int::class.javaPrimitiveType == method.returnType) {
|
||||||
return@InvocationHandler 0
|
return@InvocationHandler 0
|
||||||
} else if (Boolean::class.java == method.getReturnType()) {
|
} else if (Boolean::class.java == method.returnType) {
|
||||||
return@InvocationHandler java.lang.Boolean.FALSE
|
return@InvocationHandler java.lang.Boolean.FALSE
|
||||||
} else if (Boolean::class.javaPrimitiveType == method.getReturnType()) {
|
} else if (Boolean::class.javaPrimitiveType == method.returnType) {
|
||||||
return@InvocationHandler false
|
return@InvocationHandler false
|
||||||
} else {
|
} else {
|
||||||
return@InvocationHandler null
|
return@InvocationHandler null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue