ScrollListItem.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*===============================================================================
  2. Copyright (C) 2022 Immersal - Part of Hexagon. All Rights Reserved.
  3. This file is part of the Immersal SDK.
  4. The Immersal SDK cannot be copied, distributed, or made available to
  5. third-parties for commercial purposes without written permission of Immersal Ltd.
  6. Contact sdk@immersal.com for licensing requests.
  7. ===============================================================================*/
  8. using System;
  9. using UnityEngine;
  10. using UnityEngine.UI;
  11. using TMPro;
  12. using Immersal.REST;
  13. namespace Immersal.Samples.Mapping.ScrollList
  14. {
  15. public class ScrollListItem : MonoBehaviour
  16. {
  17. [SerializeField]
  18. private VisualizeManager visualizeManager = null;
  19. [SerializeField]
  20. private Sprite sprite_queued = null;
  21. [SerializeField]
  22. private Sprite sprite_processing = null;
  23. [SerializeField]
  24. private Sprite sprite_done = null;
  25. [SerializeField]
  26. private Sprite sprite_failed = null;
  27. [SerializeField]
  28. private Image iconField = null;
  29. [SerializeField]
  30. private TextMeshProUGUI nameField = null;
  31. [SerializeField]
  32. private TextMeshProUGUI dateField = null;
  33. [SerializeField]
  34. private Toggle toggle = null;
  35. private SDKJob m_Data = default;
  36. public SDKJob data
  37. {
  38. get { return m_Data; }
  39. set
  40. {
  41. m_Data = value;
  42. SetName();
  43. SetDate();
  44. SetIcon();
  45. }
  46. }
  47. public void OnClick()
  48. {
  49. toggle.isOn = !toggle.isOn;
  50. }
  51. public void OnToggleChanged(bool value)
  52. {
  53. SelectListItem();
  54. }
  55. private void SelectListItem()
  56. {
  57. if (visualizeManager != null && (m_Data.status == SDKJobState.Sparse || m_Data.status == SDKJobState.Done))
  58. {
  59. if (VisualizeManager.loadJobs.Contains(data.id))
  60. {
  61. toggle.SetIsOnWithoutNotify(true);
  62. }
  63. else
  64. {
  65. if (toggle.isOn)
  66. {
  67. VisualizeManager.loadJobs.Add(data.id);
  68. }
  69. visualizeManager.OnListItemSelect(data);
  70. }
  71. }
  72. else
  73. {
  74. // if still processing
  75. toggle.SetIsOnWithoutNotify(false);
  76. }
  77. }
  78. public void DeleteItem()
  79. {
  80. if (visualizeManager != null)
  81. {
  82. visualizeManager.activeFunctionJob = data;
  83. visualizeManager.ToggleDeletePrompt(true);
  84. }
  85. }
  86. public void RestoreItem()
  87. {
  88. if (visualizeManager != null)
  89. {
  90. visualizeManager.activeFunctionJob = data;
  91. visualizeManager.ToggleRestoreMapImagesPrompt(true);
  92. }
  93. }
  94. public void PopulateData(SDKJob data, bool isActive)
  95. {
  96. this.data = data;
  97. toggle.SetIsOnWithoutNotify(isActive);
  98. }
  99. private void SetName()
  100. {
  101. if (nameField != null)
  102. {
  103. nameField.text = m_Data.name;
  104. }
  105. }
  106. private void SetDate()
  107. {
  108. if (dateField != null)
  109. {
  110. DateTime dateCreated = DateTime.Parse(m_Data.created).ToLocalTime();
  111. DateTime dateModified = DateTime.Parse(m_Data.modified).ToLocalTime();
  112. dateField.text = dateCreated.ToString("yyyy-MM-dd HH:mm");
  113. }
  114. }
  115. private void SetIcon()
  116. {
  117. if (iconField != null)
  118. {
  119. switch (m_Data.status)
  120. {
  121. case SDKJobState.Pending:
  122. iconField.sprite = sprite_queued;
  123. break;
  124. case SDKJobState.Processing:
  125. iconField.sprite = sprite_processing;
  126. break;
  127. case SDKJobState.Failed:
  128. iconField.sprite = sprite_failed;
  129. break;
  130. default: // Sparse & Done
  131. iconField.sprite = sprite_done;
  132. break;
  133. }
  134. }
  135. }
  136. private void Start()
  137. {
  138. if (visualizeManager == null)
  139. {
  140. visualizeManager = GetComponentInParent<VisualizeManager>();
  141. }
  142. }
  143. }
  144. }