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.LinearLayout
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import net.osmand.GPXUtilities
import net.osmand.PlatformUtil import net.osmand.PlatformUtil
import net.osmand.aidl.gpx.AGpxBitmap import net.osmand.aidl.gpx.AGpxBitmap
import net.osmand.telegram.R 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.LocationMessages
import net.osmand.telegram.helpers.OsmandAidlHelper import net.osmand.telegram.helpers.OsmandAidlHelper
import net.osmand.telegram.helpers.TelegramUiHelper 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 net.osmand.util.Algorithms
import java.io.File import java.io.File
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@ -42,7 +46,7 @@ class UserGpxInfoFragment : BaseDialogFragment() {
private val uiUtils get() = app.uiUtils private val uiUtils get() = app.uiUtils
private var gpxFile = GPXUtilities.GPXFile() private var gpxFile = GPXUtilities.GPXFile("")
private lateinit var mainView: View private lateinit var mainView: View
private lateinit var dateStartBtn: TextView private lateinit var dateStartBtn: TextView
@ -101,8 +105,10 @@ class UserGpxInfoFragment : BaseDialogFragment() {
openGpx(path) openGpx(path)
} }
override fun onSavingGpxError(warnings: List<String>?) { override fun onSavingGpxError(warning: String?) {
Toast.makeText(app, warnings?.firstOrNull(), Toast.LENGTH_LONG).show() warning?.also {
Toast.makeText(app, it, Toast.LENGTH_LONG).show()
}
} }
}) })
} }
@ -198,8 +204,10 @@ class UserGpxInfoFragment : BaseDialogFragment() {
(activity as MainActivity).shareGpx(path) (activity as MainActivity).shareGpx(path)
} }
override fun onSavingGpxError(warnings: List<String>?) { override fun onSavingGpxError(warning: String?) {
Toast.makeText(app, warnings?.firstOrNull(), Toast.LENGTH_LONG).show() warning?.also {
Toast.makeText(app, it, Toast.LENGTH_LONG).show()
}
} }
}) })
} }
@ -320,7 +328,7 @@ class UserGpxInfoFragment : BaseDialogFragment() {
checkTime() checkTime()
locationMessages = app.locationMessages.getMessagesForUserInChat(userId, chatId, deviceName, startCalendar.timeInMillis, endCalendar.timeInMillis) 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() updateGPXStatisticRow()
updateDateAndTimeButtons() updateDateAndTimeButtons()
updateGPXMap() updateGPXMap()
@ -390,8 +398,8 @@ class UserGpxInfoFragment : BaseDialogFragment() {
} }
} }
override fun onSavingGpxError(warnings: List<String>?) { override fun onSavingGpxError(warning: String?) {
log.debug("onSavingGpxError ${warnings?.firstOrNull()}") 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 package net.osmand.telegram.utils
import android.os.AsyncTask import android.os.AsyncTask
import net.osmand.GPXUtilities
import net.osmand.Location import net.osmand.Location
import net.osmand.data.LatLon import net.osmand.data.LatLon
import net.osmand.telegram.TelegramApplication import net.osmand.telegram.TelegramApplication
@ -15,6 +16,7 @@ import org.drinkless.td.libcore.telegram.TdApi
import java.io.File import java.io.File
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlin.math.abs
const val TRACKS_DIR = "tracker/" const val TRACKS_DIR = "tracker/"
@ -412,7 +414,7 @@ object OsmandLocationUtils {
return TdApi.InputMessageText(TdApi.FormattedText(textMessage, entities.toTypedArray()), true, true) 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>() val dataTracks = ArrayList<GPXUtilities.GPXFile>()
var previousTime: Long = -1 var previousTime: Long = -1
@ -432,24 +434,25 @@ object OsmandLocationUtils {
} }
countedLocations++ countedLocations++
if (previousUserId != userId || (newGpxPerChat && previousChatId != chatId)) { if (previousUserId != userId || (newGpxPerChat && previousChatId != chatId)) {
gpx = GPXUtilities.GPXFile() gpx = GPXUtilities.GPXFile(author).apply {
gpx!!.chatId = chatId metadata = GPXUtilities.Metadata().apply {
gpx!!.userId = userId extensionsToWrite["chatId"] = chatId.toString()
extensionsToWrite["userId"] = userId.toString()
}
}
previousTime = 0 previousTime = 0
track = null track = null
segment = null segment = null
dataTracks.add(gpx!!) dataTracks.add(gpx!!)
} }
val pt = GPXUtilities.WptPt() val pt = GPXUtilities.WptPt()
pt.userId = userId
pt.chatId = chatId
pt.lat = it.lat pt.lat = it.lat
pt.lon = it.lon pt.lon = it.lon
pt.ele = it.altitude pt.ele = it.altitude
pt.speed = it.speed pt.speed = it.speed
pt.hdop = it.hdop pt.hdop = it.hdop
pt.time = time pt.time = time
val currentInterval = Math.abs(time - previousTime) val currentInterval = abs(time - previousTime)
if (track != null) { if (track != null) {
if (currentInterval < 30 * 60 * 1000) { if (currentInterval < 30 * 60 * 1000) {
// 30 minute - same segment // 30 minute - same segment
@ -524,44 +527,46 @@ object OsmandLocationUtils {
private val app: TelegramApplication, private val listener: SaveGpxListener?, private val app: TelegramApplication, private val listener: SaveGpxListener?,
private val gpxFile: GPXUtilities.GPXFile, private val dir: File, private val userId: Int 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> { override fun doInBackground(vararg params: Void): Exception? {
val warnings = ArrayList<String>()
dir.mkdirs() dir.mkdirs()
if (dir.parentFile.canWrite()) { if (dir.parentFile.canWrite()) {
if (dir.exists()) { if (dir.exists()) {
// save file // save file
var fout = File(dir, "$userId.gpx")
if (!gpxFile.isEmpty) { if (!gpxFile.isEmpty) {
val pt = gpxFile.findPointToShow() val pt = gpxFile.findPointToShow()
val userId = gpxFile.metadata.extensionsToRead["userId"]
val user = app.telegramHelper.getUser(pt!!.userId) val user = if (!userId.isNullOrEmpty()) {
try {
app.telegramHelper.getUser(userId.toInt())
} catch (e: NumberFormatException) {
null
}
} else {
null
}
val fileName: String val fileName: String
fileName = if (user != null) { fileName = if (user != null) {
(TelegramUiHelper.getUserName(user) + "_" + SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date(pt.time))) (TelegramUiHelper.getUserName(user) + "_" + SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date(pt.time)))
} else { } else {
userId.toString() + "_" + SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date(pt.time)) userId.toString() + "_" + SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date(pt.time))
} }
fout = File(dir, "$fileName.gpx") gpxFile.metadata?.name = fileName
} val fout = File(dir, "$fileName.gpx")
val warn = GPXUtilities.writeGpxFile(fout, gpxFile, app) return GPXUtilities.writeGpxFile(fout, gpxFile)
if (warn != null) {
warnings.add(warn)
return warnings
} }
} }
} }
return null
return warnings
} }
override fun onPostExecute(warnings: List<String>?) { override fun onPostExecute(warning: Exception?) {
if (listener != null) { if (listener != null) {
if (warnings != null && warnings.isEmpty()) { if (warning == null) {
listener.onSavingGpxFinish(gpxFile.path) listener.onSavingGpxFinish(gpxFile.path)
} else { } else {
listener.onSavingGpxError(warnings) listener.onSavingGpxError(warning.message)
} }
} }
} }
@ -571,6 +576,6 @@ object OsmandLocationUtils {
fun onSavingGpxFinish(path: String) fun onSavingGpxFinish(path: String)
fun onSavingGpxError(warnings: List<String>?) fun onSavingGpxError(warning: String?)
} }
} }