-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
176 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
OsmAnd/src/net/osmand/plus/nearbyplaces/NearbyPlacesLoadSavedTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package net.osmand.plus.nearbyplaces; | ||
|
||
import android.os.AsyncTask; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
import net.osmand.PlatformUtil; | ||
import net.osmand.data.NearbyPlacePoint; | ||
import net.osmand.plus.OsmandApplication; | ||
import net.osmand.plus.utils.FileUtils; | ||
|
||
import org.apache.commons.logging.Log; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.lang.reflect.Type; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class NearbyPlacesLoadSavedTask extends AsyncTask<Void, Void, List<NearbyPlacePoint>> { | ||
|
||
private static final Log LOG = PlatformUtil.getLog(NearbyPlacesLoadSavedTask.class.getName()); | ||
|
||
private final OsmandApplication app; | ||
private File file; | ||
|
||
public NearbyPlacesLoadSavedTask(@NonNull OsmandApplication app) { | ||
this.app = app; | ||
} | ||
|
||
@Override | ||
protected List<NearbyPlacePoint> doInBackground(Void... voids) { | ||
file = new File(FileUtils.getTempDir(app), "nearby_places"); | ||
return loadPlaces(); | ||
} | ||
|
||
@NonNull | ||
private List<NearbyPlacePoint> loadPlaces() { | ||
List<NearbyPlacePoint> nearbyPlaces = Collections.emptyList(); | ||
Gson gson = new Gson(); | ||
try (FileReader reader = new FileReader(file)) { | ||
Type type = new TypeToken<List<NearbyPlacePoint>>() { | ||
}.getType(); | ||
nearbyPlaces = gson.fromJson(reader, type); | ||
} catch (Exception e) { | ||
LOG.error("Error loading nearby places from file", e); | ||
} | ||
return nearbyPlaces; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(@NonNull List<NearbyPlacePoint> nearbyPlaces) { | ||
NearbyPlacesHelper.INSTANCE.onCacheLoaded(nearbyPlaces); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
OsmAnd/src/net/osmand/plus/nearbyplaces/SaveNearbyPlacesTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package net.osmand.plus.nearbyplaces | ||
|
||
import android.os.AsyncTask | ||
import com.google.gson.Gson | ||
import net.osmand.PlatformUtil | ||
import net.osmand.data.NearbyPlacePoint | ||
import net.osmand.plus.OsmandApplication | ||
import net.osmand.plus.utils.FileUtils | ||
import org.apache.commons.logging.Log | ||
import java.io.File | ||
import java.io.FileWriter | ||
|
||
class SaveNearbyPlacesTask(val app:OsmandApplication, val collection: List<NearbyPlacePoint>) : AsyncTask<Void, Void, Boolean>() { | ||
private val LOG: Log = PlatformUtil.getLog( | ||
NearbyPlacesLoadSavedTask::class.java.name) | ||
|
||
override fun doInBackground(vararg params: Void?): Boolean { | ||
val file = File(FileUtils.getTempDir(app), "nearby_places") | ||
val gson = Gson() | ||
return try { | ||
FileWriter(file).use { writer -> | ||
val jsonString = gson.toJson(collection) | ||
writer.write(jsonString) | ||
} | ||
true // Success | ||
} catch (e: Exception) { | ||
false // Failure | ||
} | ||
} | ||
|
||
override fun onPostExecute(success: Boolean) { | ||
if (success) { | ||
LOG.debug("Nearby places saved successfully.") | ||
} else { | ||
LOG.error("Failed to save nearby places.") | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
OsmAnd/src/net/osmand/plus/search/GetNearbyPlacesImagesTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0caa02c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Corwin-Kh There are 2 issues after this commit:
Both issues were not present immeditately before this commit.
0caa02c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your reply. Actually, the feature is still in progress and appeared in master by mistake, reverted it.
Answering you questions - items are sorted by popularity, not distance