保存优化&本地记录自动上传

This commit is contained in:
lishuo 2022-02-21 16:16:35 +08:00
parent f5294b0d39
commit 0c1c2ed382
3 changed files with 35 additions and 23 deletions

View File

@ -62,6 +62,7 @@ public class CyclingController : DeviceServiceMonoBase
#endregion #endregion
GameObject loadingcanvas; GameObject loadingcanvas;
AbstratctLoadingController loadingController; AbstratctLoadingController loadingController;
private async Task Login() private async Task Login()
{ {
var result = await new UserApi().Login("15261826280", "123456", ""); var result = await new UserApi().Login("15261826280", "123456", "");
@ -73,6 +74,8 @@ public class CyclingController : DeviceServiceMonoBase
public GraphChartBase graph { get; set; } public GraphChartBase graph { get; set; }
private float activeSeconds { get; set; }//移动端用户进入骑行超过2min界面进入沉浸状态 private float activeSeconds { get; set; }//移动端用户进入骑行超过2min界面进入沉浸状态
public int RankingId;
public string recordId;
protected override void Awake() protected override void Awake()
{ {
base.Awake(); base.Awake();
@ -83,6 +86,7 @@ public class CyclingController : DeviceServiceMonoBase
} }
#endif #endif
//获取路书信息 //获取路书信息
recordId = Guid.NewGuid().ToString();
mapApi = ConfigHelper.mapApi; mapApi = ConfigHelper.mapApi;
routeId = App.RouteIdParam > 0 ? App.RouteIdParam : 2633; routeId = App.RouteIdParam > 0 ? App.RouteIdParam : 2633;
competitionId = App.CompetionId; competitionId = App.CompetionId;
@ -1196,14 +1200,14 @@ public BaseUIManager singleUIManager;
var tempContent = Newtonsoft.Json.JsonConvert.SerializeObject(tempRecordData); var tempContent = Newtonsoft.Json.JsonConvert.SerializeObject(tempRecordData);
System.IO.File.WriteAllText(filePath, tempContent); System.IO.File.WriteAllText(filePath, tempContent);
} }
public int RankingId;
public void Save(double totalDistance) public void Save(double totalDistance)
{ {
ClearTempFile(); ClearTempFile();
cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime(); cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
isQuit = true; isQuit = true;
isStart = false; isStart = false;
string recordId = Guid.NewGuid().ToString(); //string recordId = Guid.NewGuid().ToString();
//var path = Helper.GetDataDir("MapWorkoutRecords/"+ recordId); //var path = Helper.GetDataDir("MapWorkoutRecords/"+ recordId);
var path = PFConstants.MapWorkoutRecordFolder + "/" + recordId; var path = PFConstants.MapWorkoutRecordFolder + "/" + recordId;
Helper.CreateDirectoryIfNotExsit(path); Helper.CreateDirectoryIfNotExsit(path);

View File

@ -88,33 +88,41 @@ public class LocalRouteItem : MonoBehaviour, IPointerExitHandler, IPointerEnterH
listFileName.Add(item); listFileName.Add(item);
} }
} }
DeleteLocalRecord();
} }
void DeleteLocalRecord(bool showMessage=false)
{
//自动上传
try
{
MapInterruptRecordApi service = ConfigHelper.mapInterruptRecordApi;
var result = service.Add(record, listFileName);
//删除文件
if (result.result)
{
Helper.DelectDir(path);
Destroy(gameObject);
}
if (showMessage)
{
Utils.showToast(gameObject, result.errMsg);
}
}
catch (Exception e)
{
Utils.showToast(gameObject, e.Message);
}
}
void GoUplaod() void GoUplaod()
{ {
UIManager.ShowConfirm("Upload", "Upload the local record?", () => UIManager.ShowConfirm("Upload", "Upload the local record?", () =>
{ {
try DeleteLocalRecord(true);
{ //删除文件
MapInterruptRecordApi service = new MapInterruptRecordApi(); UIManager.CloseConfirm();
var result = service.Add(record, listFileName);
//删除文件
UIManager.CloseConfirm();
if (result.result)
{
Helper.DelectDir(path);
DestroyImmediate(gameObject);
}
else
{
Utils.showToast(gameObject, result.errMsg);
}
}
catch (Exception e)
{
Utils.showToast(gameObject, e.Message);
}
}); });
} }
void GoDelete() void GoDelete()

View File

@ -264,7 +264,7 @@ public class ResultListController : PFUIPanel
{ {
if (Directory.Exists(item)) if (Directory.Exists(item))
{ {
var d = new DirectoryInfo(item); //var d = new DirectoryInfo(item);
//var createTime = d.CreationTime;//create time //var createTime = d.CreationTime;//create time
//var newTime = createTime.AddSeconds(30D); //var newTime = createTime.AddSeconds(30D);
//if (newTime < DateTime.Now) //if (newTime < DateTime.Now)