Remove unnecessary copy of GpxUtilities

(cherry picked from commit f2c63eeb2a)
This commit is contained in:
Chumva 2019-07-16 14:16:53 +03:00
parent c2cf37113b
commit a33be76618
4 changed files with 47 additions and 1866 deletions

View file

@ -23,6 +23,7 @@ import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import net.osmand.GPXUtilities
import net.osmand.PlatformUtil
import net.osmand.aidl.gpx.AGpxBitmap
import net.osmand.telegram.R
@ -30,7 +31,10 @@ import net.osmand.telegram.TelegramSettings
import net.osmand.telegram.helpers.LocationMessages
import net.osmand.telegram.helpers.OsmandAidlHelper
import net.osmand.telegram.helpers.TelegramUiHelper
import net.osmand.telegram.utils.*
import net.osmand.telegram.utils.AndroidUtils
import net.osmand.telegram.utils.OsmandFormatter
import net.osmand.telegram.utils.OsmandLocationUtils
import net.osmand.telegram.utils.TRACKS_DIR
import net.osmand.util.Algorithms
import java.io.File
import java.text.SimpleDateFormat
@ -42,7 +46,7 @@ class UserGpxInfoFragment : BaseDialogFragment() {
private val uiUtils get() = app.uiUtils
private var gpxFile = GPXUtilities.GPXFile()
private var gpxFile = GPXUtilities.GPXFile("")
private lateinit var mainView: View
private lateinit var dateStartBtn: TextView
@ -101,8 +105,10 @@ class UserGpxInfoFragment : BaseDialogFragment() {
openGpx(path)
}
override fun onSavingGpxError(warnings: List<String>?) {
Toast.makeText(app, warnings?.firstOrNull(), Toast.LENGTH_LONG).show()
override fun onSavingGpxError(warning: String?) {
warning?.also {
Toast.makeText(app, it, Toast.LENGTH_LONG).show()
}
}
})
}
@ -198,8 +204,10 @@ class UserGpxInfoFragment : BaseDialogFragment() {
(activity as MainActivity).shareGpx(path)
}
override fun onSavingGpxError(warnings: List<String>?) {
Toast.makeText(app, warnings?.firstOrNull(), Toast.LENGTH_LONG).show()
override fun onSavingGpxError(warning: String?) {
warning?.also {
Toast.makeText(app, it, Toast.LENGTH_LONG).show()
}
}
})
}
@ -320,7 +328,7 @@ class UserGpxInfoFragment : BaseDialogFragment() {
checkTime()
locationMessages = app.locationMessages.getMessagesForUserInChat(userId, chatId, deviceName, startCalendar.timeInMillis, endCalendar.timeInMillis)
gpxFile = OsmandLocationUtils.convertLocationMessagesToGpxFiles(locationMessages).firstOrNull()?:GPXUtilities.GPXFile()
gpxFile = OsmandLocationUtils.convertLocationMessagesToGpxFiles(app.packageName, locationMessages).firstOrNull() ?: GPXUtilities.GPXFile(app.packageName)
updateGPXStatisticRow()
updateDateAndTimeButtons()
updateGPXMap()
@ -390,8 +398,8 @@ class UserGpxInfoFragment : BaseDialogFragment() {
}
}
override fun onSavingGpxError(warnings: List<String>?) {
log.debug("onSavingGpxError ${warnings?.firstOrNull()}")
override fun onSavingGpxError(warning: String?) {
log.debug("onSavingGpxError $warning")
}
})
}

File diff suppressed because it is too large Load diff

View file

@ -1,24 +0,0 @@
package net.osmand.telegram.utils;
import android.content.Context;
/**
*/
public interface LocationPoint {
public double getLatitude();
public double getLongitude();
public int getColor();
public boolean isVisible();
// public PointDescription getPointDescription(Context ctx);
// public String getSpeakableName();
//public void prepareCommandPlayer(CommandBuilder cmd, String names);
}

View file

@ -1,6 +1,7 @@
package net.osmand.telegram.utils
import android.os.AsyncTask
import net.osmand.GPXUtilities
import net.osmand.Location
import net.osmand.data.LatLon
import net.osmand.telegram.TelegramApplication
@ -15,6 +16,7 @@ import org.drinkless.td.libcore.telegram.TdApi
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
import kotlin.math.abs
const val TRACKS_DIR = "tracker/"
@ -412,7 +414,7 @@ object OsmandLocationUtils {
return TdApi.InputMessageText(TdApi.FormattedText(textMessage, entities.toTypedArray()), true, true)
}
fun convertLocationMessagesToGpxFiles(items: List<LocationMessage>, newGpxPerChat: Boolean = true): List<GPXUtilities.GPXFile> {
fun convertLocationMessagesToGpxFiles(author:String, items: List<LocationMessage>, newGpxPerChat: Boolean = true): List<GPXUtilities.GPXFile> {
val dataTracks = ArrayList<GPXUtilities.GPXFile>()
var previousTime: Long = -1
@ -432,24 +434,25 @@ object OsmandLocationUtils {
}
countedLocations++
if (previousUserId != userId || (newGpxPerChat && previousChatId != chatId)) {
gpx = GPXUtilities.GPXFile()
gpx!!.chatId = chatId
gpx!!.userId = userId
gpx = GPXUtilities.GPXFile(author).apply {
metadata = GPXUtilities.Metadata().apply {
extensionsToWrite["chatId"] = chatId.toString()
extensionsToWrite["userId"] = userId.toString()
}
}
previousTime = 0
track = null
segment = null
dataTracks.add(gpx!!)
}
val pt = GPXUtilities.WptPt()
pt.userId = userId
pt.chatId = chatId
pt.lat = it.lat
pt.lon = it.lon
pt.ele = it.altitude
pt.speed = it.speed
pt.hdop = it.hdop
pt.time = time
val currentInterval = Math.abs(time - previousTime)
val currentInterval = abs(time - previousTime)
if (track != null) {
if (currentInterval < 30 * 60 * 1000) {
// 30 minute - same segment
@ -524,44 +527,46 @@ object OsmandLocationUtils {
private val app: TelegramApplication, private val listener: SaveGpxListener?,
private val gpxFile: GPXUtilities.GPXFile, private val dir: File, private val userId: Int
) :
AsyncTask<Void, Void, List<String>>() {
AsyncTask<Void, Void, java.lang.Exception>() {
override fun doInBackground(vararg params: Void): List<String> {
val warnings = ArrayList<String>()
override fun doInBackground(vararg params: Void): Exception? {
dir.mkdirs()
if (dir.parentFile.canWrite()) {
if (dir.exists()) {
// save file
var fout = File(dir, "$userId.gpx")
if (!gpxFile.isEmpty) {
val pt = gpxFile.findPointToShow()
val user = app.telegramHelper.getUser(pt!!.userId)
val userId = gpxFile.metadata.extensionsToRead["userId"]
val user = if (!userId.isNullOrEmpty()) {
try {
app.telegramHelper.getUser(userId.toInt())
} catch (e: NumberFormatException) {
null
}
} else {
null
}
val fileName: String
fileName = if (user != null) {
(TelegramUiHelper.getUserName(user) + "_" + SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date(pt.time)))
} else {
userId.toString() + "_" + SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date(pt.time))
}
fout = File(dir, "$fileName.gpx")
}
val warn = GPXUtilities.writeGpxFile(fout, gpxFile, app)
if (warn != null) {
warnings.add(warn)
return warnings
gpxFile.metadata?.name = fileName
val fout = File(dir, "$fileName.gpx")
return GPXUtilities.writeGpxFile(fout, gpxFile)
}
}
}
return null
}
return warnings
}
override fun onPostExecute(warnings: List<String>?) {
override fun onPostExecute(warning: Exception?) {
if (listener != null) {
if (warnings != null && warnings.isEmpty()) {
if (warning == null) {
listener.onSavingGpxFinish(gpxFile.path)
} else {
listener.onSavingGpxError(warnings)
listener.onSavingGpxError(warning.message)
}
}
}
@ -571,6 +576,6 @@ object OsmandLocationUtils {
fun onSavingGpxFinish(path: String)
fun onSavingGpxError(warnings: List<String>?)
fun onSavingGpxError(warning: String?)
}
}