148 lines
5.0 KiB
C#
148 lines
5.0 KiB
C#
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("BigLeft/Left/Main/Name").GetComponent<Text>();
|
|
var Time = transform.Find("BigLeft/Left/Main/Time").GetComponent<Text>();
|
|
var RidingTime = transform.Find("BigLeft/Left/Main/Row1/Time").GetComponent<Text>();
|
|
var RidingDistance = transform.Find("BigLeft/Left/Main/Row1/Distance").GetComponent<Text>();
|
|
var Device = transform.Find("BigLeft/Left/Main/Row2/Device").GetComponent<Text>();
|
|
var recordImage = transform.Find("BigLeft/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);
|
|
//不是自己的记录不显示
|
|
var isself = record.UserId == App.CurrentUser.Id;
|
|
if (!isself)
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
|
|
Name.text = record.RouteName;
|
|
Time.text = record.StartTime.ToString("HH:mm:ss dd-MM-yyyy");
|
|
RidingTime.text = $"<color={titleColor}>Riding time:</color>{Helper.FormatTicks(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()
|
|
{
|
|
UIManager.ShowConfirm("Upload", "Upload the local record?", () =>
|
|
{
|
|
try
|
|
{
|
|
MapInterruptRecordApi service = new MapInterruptRecordApi();
|
|
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()
|
|
{
|
|
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)
|
|
{
|
|
|
|
}
|
|
}
|