本地记录重新上传,一些界面bug修复

This commit is contained in:
lishuo committed 2021-05-19 18:39:47 +08:00
1 parent 470d52b1bc
commit f1eeb11543
11 files changed
+6363 -3355

No files matched your search

@@ -0,0 +1,139 @@
using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Assets.Scripts.Apis;
using Assets.Scenes.Ride.Scripts;
public class LocalRouteItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler
{
MapInterruptRecord record;
// Start is called before the first frame update
Transform left,row1,row2,right;
Transform btnReRide, btnContinue, btnDelete;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
string titleColor = "#5c5c6e";
RouteResult data;
//滑动索引 0route 1match
int index;
List<string> listFileName = new List<string>();
string path;
public void Initial(string path,int index)
{
this.path = path;
this.index = index;
var Name = transform.Find("Left/Main/Name").GetComponent<Text>();
var Time = transform.Find("Left/Main/Time").GetComponent<Text>();
var RidingTime = transform.Find("Left/Main/Row1/Time").GetComponent<Text>();
var RidingDistance = transform.Find("Left/Main/Row1/Distance").GetComponent<Text>();
var Device = transform.Find("Left/Main/Row2/Device").GetComponent<Text>();
var recordImage = transform.Find("CoverImage").GetComponent<RawImage>();
var uploadBtn = transform.Find("Right/BtnContinue").GetComponent<Button>();
var deleteBtn = transform.Find("Right/BtnDelete").GetComponent<Button>();
UIManager.AddEvent(uploadBtn.gameObject, EventTriggerType.PointerClick, (b) => GoUplaod());
UIManager.AddEvent(deleteBtn.gameObject, EventTriggerType.PointerClick, (b) => GoDelete());
var fileList = Directory.GetFiles(path);
foreach (var item in fileList)
{
var fileInfo = new FileInfo(item);
//显示封面图片
if (fileInfo.Extension.ToLower().Equals(".png"))
{
var fileStream = fileInfo.OpenRead();
fileStream.Seek(0, SeekOrigin.Begin);
byte[] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, (int)fileStream.Length);
fileStream.Close();
fileStream.Dispose();
Texture2D texture = new Texture2D(800, 450);
texture.LoadImage(bytes);
recordImage.texture = texture;
}
//显示骑行记录实体
if (fileInfo.Name.Equals("record.txt"))
{
var recordStr = File.ReadAllText(item);
record = Newtonsoft.Json.JsonConvert.DeserializeObject<MapInterruptRecord>(recordStr);
Name.text = record.RouteName;
Time.text = record.StartTime.ToString();
RidingTime.text = $"<color={titleColor}>Riding time:</color>{record.Ticks}";
RidingDistance.text = $"<color={titleColor}>Mileage:</color>{record.EndDistance.ToString("#0.00")}KM";
Device.text = $"<color={titleColor}>Cycling equipment:</color>{record.ManufacturerName}";
}
else
{
listFileName.Add(item);
}
}
}
void GoUplaod()
{
if (!Directory.Exists(path))
return;
UIManager.ShowConfirm("Upload", "Upload the local record?", () =>
{
MapInterruptRecordApi service = new MapInterruptRecordApi();
var result = service.Add(record, listFileName);
//删除文件
try
{
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()
{
if (!Directory.Exists(path))
return;
UIManager.ShowConfirm("Delete", "Delete the local record?", () =>
{
//删除文件
try
{
UIManager.CloseConfirm();
Helper.DelectDir(path);
DestroyImmediate(gameObject);
}
catch (Exception e)
{
Utils.showToast(gameObject, e.Message);
}
});
}
public void OnPointerExit(PointerEventData eventData)
{
}
public void OnPointerEnter(PointerEventData eventData)
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b2305835a4128974baaed486343c2b37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -4,6 +4,7 @@ using Assets.Scripts.Apis.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
@@ -11,6 +12,7 @@ using UnityEngine.UI;
public class ResultListController : MonoBehaviour
{
[SerializeField]Transform routeResult;
Transform localRouteItem;
Transform scrollContent;
Transform routeScroll, matchScroll;
Transform routeContent, matchContent;
@@ -38,6 +40,7 @@ public class ResultListController : MonoBehaviour
matchScroll = scrollContent.Find("MatchList");
matchContent = matchScroll.Find("Viewport").Find("Content");
contents = new Transform[] { routeContent, matchContent};
localRouteItem = Resources.Load<Transform>("UI/Prefab/ResultList/LocalRouteItem");
if (btnMatch != null)
{
UIManager.AddEvent(btnMatch.gameObject, EventTriggerType.PointerClick, (b) =>
@@ -161,8 +164,10 @@ public class ResultListController : MonoBehaviour
{
isEnd[index] = false;
DisplayRouteResult(r.data, contents[index],index);
DisplayLocalRouteResult(contents[index], index);//显示本地未上传成功的记录
scroll.transform.Find("Error").gameObject.SetActive(false);
//DisplayRouteResult(r.data, matchContent);
}
}
else
@@ -184,6 +189,30 @@ public class ResultListController : MonoBehaviour
}
}
}
void DisplayLocalRouteResult(Transform content, int index)
{
//查询本地上传失败的文件
var parentPath = PFConstants.MapWorkoutRecordFolder;
var dirList = Directory.GetDirectories(parentPath);
foreach (var item in dirList)
{
if (Directory.Exists(item))
{
var d = new DirectoryInfo(item);
//var createTime = d.CreationTime;//create time
//var newTime = createTime.AddSeconds(30D);
//if (newTime < DateTime.Now)
{
var obj = Instantiate(localRouteItem);
obj.GetComponent<LocalRouteItem>().Initial(item, 0);
obj.transform.parent = content;
obj.transform.localScale = new Vector3(1, 1, 1);
obj.SetAsFirstSibling();
}
}
}
}
void InitialColor()
{
ColorUtility.TryParseHtmlString("#FFFFFF", out c1);