Skip to content

Commit

Permalink
[HUP-799] Refactor: Classes and structs should be declared within a n…
Browse files Browse the repository at this point in the history
…amespace.

Namespaces are used to group related entities like classes and structs, providing scope and preventing name clashes. It is essential to declare a namespace to avoid placing entities in the global namespace.

Related Issues:
- [HUP-821]: Main Task
  • Loading branch information
Andronovo-bit authored and alihan98ersoy committed Feb 22, 2024
1 parent d434dd9 commit 3b47aab
Show file tree
Hide file tree
Showing 38 changed files with 2,045 additions and 1,968 deletions.
1 change: 1 addition & 0 deletions Assets/Huawei/Demos/APM/APMDemoManager.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using HmsPlugin;
using HuaweiMobileServices.APM;

using UnityEngine;
Expand Down
1 change: 1 addition & 0 deletions Assets/Huawei/Demos/CrashKit/CrashDemoManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using HmsPlugin;
using UnityEngine;

public class CrashDemoManager : MonoBehaviour
Expand Down
5 changes: 3 additions & 2 deletions Assets/Huawei/Demos/Location/ActivityIdentificationDemo.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using HuaweiMobileServices.Location;
using HuaweiMobileServices.Location;
using HuaweiMobileServices.Location.Activity;
using HuaweiMobileServices.Utils;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Text;
using Huawei.Scripts.Location;
using HmsPlugin;

namespace Huawei.Demos.Location
{
Expand Down Expand Up @@ -103,7 +104,7 @@ private void SetParameterForActivityConversion()
ActivityConversionInfo activityConversionInfoStillEnter = new ActivityConversionInfo(
ActivityIdentificationData.STILL, ActivityConversionInfo.ENTER_ACTIVITY_CONVERSION);

// Create an information object for switching from the activity state to the static state.
// Create an information object for switching from the activity state to the static state.
ActivityConversionInfo activityConversionInfoStillExit = new ActivityConversionInfo(
ActivityIdentificationData.FOOT, ActivityConversionInfo.EXIT_ACTIVITY_CONVERSION);
List<ActivityConversionInfo> activityConversionInfos = new List<ActivityConversionInfo>();
Expand Down
1 change: 1 addition & 0 deletions Assets/Huawei/Demos/Location/FusedLocationDemo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Text;
using HmsPlugin;
using HuaweiMobileServices.Location;
using HuaweiMobileServices.Location.Location;
using UnityEngine;
Expand Down
1 change: 1 addition & 0 deletions Assets/Huawei/Demos/Location/GeofenceDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Huawei.Scripts.Location;
using HuaweiMobileServices.Location;
using HuaweiMobileServices.Location.Location;
using HmsPlugin;

public class GeofenceDemo : MonoBehaviour
{
Expand Down
1 change: 1 addition & 0 deletions Assets/Huawei/Demos/RemoteConfig/RemoteConfigDemo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using HmsPlugin;
using HuaweiMobileServices.RemoteConfig;
using HuaweiMobileServices.Utils;

Expand Down
1 change: 1 addition & 0 deletions Assets/Huawei/Demos/Scan/ScanKitDemo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using HmsPlugin;
using HuaweiMobileServices.Scan;

using UnityEngine;
Expand Down
59 changes: 31 additions & 28 deletions Assets/Huawei/Editor/Utils/HMSExcelHelper.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
using OfficeOpenXml;
using OfficeOpenXml;
using System;
using System.IO;

public static class HMSExcelHelper
namespace HmsPlugin
{
public static string[,] ReadExcel(string path)
public static class HMSExcelHelper
{
string[,] result = null;

using (ExcelPackage package = new ExcelPackage(new FileInfo(path)))
public static string[,] ReadExcel(string path)
{
ExcelWorksheet sheet = package.Workbook.Worksheets[1];
result = ToStringArray(sheet.Cells.Value);
string[,] result = null;

}
return result;
}
using (ExcelPackage package = new ExcelPackage(new FileInfo(path)))
{
ExcelWorksheet sheet = package.Workbook.Worksheets[1];
result = ToStringArray(sheet.Cells.Value);

private static string[,] ToStringArray(object arg)
{
string[,] result = null;
}
return result;
}

if (arg is Array)
private static string[,] ToStringArray(object arg)
{
int rank = ((Array)arg).Rank;
if (rank == 2)
{
int columnCount = ((Array)arg).GetLength(1) - 1;
int rowCount = ((Array)arg).GetLength(0);
result = new string[rowCount, columnCount];
string[,] result = null;

for (int i = 0; i < rowCount; i++)
if (arg is Array)
{
int rank = ((Array)arg).Rank;
if (rank == 2)
{
for (int j = 0; j < columnCount; j++)
int columnCount = ((Array)arg).GetLength(1) - 1;
int rowCount = ((Array)arg).GetLength(0);
result = new string[rowCount, columnCount];

for (int i = 0; i < rowCount; i++)
{
var value = ((Array)arg).GetValue(i, j);
if (value != null)
result[i, j] = value.ToString();
for (int j = 0; j < columnCount; j++)
{
var value = ((Array)arg).GetValue(i, j);
if (value != null)
result[i, j] = value.ToString();
}
}
}
}
}

return result;
return result;
}
}
}
184 changes: 93 additions & 91 deletions Assets/Huawei/Editor/Utils/HMSGradleFixer.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using HmsPlugin;
using System.IO;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEditor.Android;
using UnityEngine;
using System;
using System.Text.RegularExpressions;

public class HMSGradleFixer : IPostGenerateGradleAndroidProject
namespace HmsPlugin
{
public int callbackOrder => 1;
private const string MINGRADLEVERSION = "3.5.4";
private const string agconnect_agcp = "classpath 'com.huawei.agconnect:agcp:1.6.1.300'";
private const string build_gradle = "classpath 'com.android.tools.build:gradle:" + MINGRADLEVERSION + "'";

private void GradleVersionFixer(string gradleFileAsString, string path)
public class HMSGradleFixer : IPostGenerateGradleAndroidProject
{
public int callbackOrder => 1;
private const string MINGRADLEVERSION = "3.5.4";
private const string agconnect_agcp = "classpath 'com.huawei.agconnect:agcp:1.6.1.300'";
private const string build_gradle = "classpath 'com.android.tools.build:gradle:" + MINGRADLEVERSION + "'";

private void GradleVersionFixer(string gradleFileAsString, string path)
{
#if UNITY_2022_2_OR_NEWER
// Grade 7.2
string currentBuildgradle = File.ReadAllText(Directory.GetParent(path).FullName + "/build.gradle").Replace("apply from: 'hmsBaseProjectTemplate.gradle'", "");
Expand Down Expand Up @@ -44,118 +45,118 @@ private void GradleVersionFixer(string gradleFileAsString, string path)
File.WriteAllText(Directory.GetParent(path).FullName + "/settings.gradle", currentSettingsgradle.Replace("mavenCentral()", "mavenCentral()\n\t\tmaven { url 'https://developer.huawei.com/repo/' }"));

#else
string gradleRowPattern = @".*gradle:(\d\.?)+";
string gradleVersionPattern = @"(\d\.?)+";
string gradleRowPattern = @".*gradle:(\d\.?)+";
string gradleVersionPattern = @"(\d\.?)+";

if (!Version.TryParse(MINGRADLEVERSION, out Version gradleMinVersion))
{
gradleMinVersion = new Version(3, 5, 4);
}
if (!Version.TryParse(MINGRADLEVERSION, out Version gradleMinVersion))
{
gradleMinVersion = new Version(3, 5, 4);
}

Match gradleRowMatch = Regex.Match(gradleFileAsString, gradleRowPattern);
Match gradleVersionMatch = Regex.Match(gradleRowMatch.Value, gradleVersionPattern);
Match gradleRowMatch = Regex.Match(gradleFileAsString, gradleRowPattern);
Match gradleVersionMatch = Regex.Match(gradleRowMatch.Value, gradleVersionPattern);

if (!Version.TryParse(gradleVersionMatch.Value, out Version gradleVersion))
{
gradleVersion = new Version(3, 5, 4);
}
// if users gradle version is lesser than our minimum version.
if (gradleVersion.CompareTo(gradleMinVersion) < 0)
{
gradleFileAsString = gradleFileAsString.Replace(gradleVersion.ToString(), gradleMinVersion.ToString());
if (!Version.TryParse(gradleVersionMatch.Value, out Version gradleVersion))
{
gradleVersion = new Version(3, 5, 4);
}
// if users gradle version is lesser than our minimum version.
if (gradleVersion.CompareTo(gradleMinVersion) < 0)
{
gradleFileAsString = gradleFileAsString.Replace(gradleVersion.ToString(), gradleMinVersion.ToString());

#if UNITY_2019_3_OR_NEWER
File.WriteAllText(Directory.GetParent(path).FullName + "/build.gradle", gradleFileAsString);
File.WriteAllText(Directory.GetParent(path).FullName + "/build.gradle", gradleFileAsString);
#elif UNITY_2018_1_OR_NEWER
File.WriteAllText(path + "/build.gradle", gradleFileAsString);
#endif
}
}
#endif
}
}

public void OnPostGenerateGradleAndroidProject(string path)
{
if (!HMSPluginSettings.Instance.Settings.GetBool(PluginToggleEditor.PluginEnabled, true))
public void OnPostGenerateGradleAndroidProject(string path)
{
HMSEditorUtils.UpdateAssemblyDefinitions(false);
return;
}
if (!HMSPluginSettings.Instance.Settings.GetBool(PluginToggleEditor.PluginEnabled, true))
{
HMSEditorUtils.UpdateAssemblyDefinitions(false);
return;
}

string fileName = "agconnect-services.json";
string filePath = Path.Combine(Application.streamingAssetsPath, fileName);
string destPath = "";
string fileName = "agconnect-services.json";
string filePath = Path.Combine(Application.streamingAssetsPath, fileName);
string destPath = "";
#if UNITY_2019_3_OR_NEWER
destPath = Path.Combine(Directory.GetParent(path).FullName + Path.DirectorySeparatorChar + "launcher", fileName);
destPath = Path.Combine(Directory.GetParent(path).FullName + Path.DirectorySeparatorChar + "launcher", fileName);

string hmsMainTemplatePath = Application.dataPath + "/Huawei/Plugins/Android/hmsMainTemplate.gradle";
FileUtil.ReplaceFile(hmsMainTemplatePath, Path.GetFullPath(path) + @"/hmsMainTemplate.gradle");
using (var writer = File.AppendText(Path.GetFullPath(path) + "/build.gradle"))
writer.WriteLine("\napply from: 'hmsMainTemplate.gradle'");
string hmsMainTemplatePath = Application.dataPath + "/Huawei/Plugins/Android/hmsMainTemplate.gradle";
FileUtil.ReplaceFile(hmsMainTemplatePath, Path.GetFullPath(path) + @"/hmsMainTemplate.gradle");
using (var writer = File.AppendText(Path.GetFullPath(path) + "/build.gradle"))
writer.WriteLine("\napply from: 'hmsMainTemplate.gradle'");

string launcherTemplatePath = Application.dataPath + "/Huawei/Plugins/Android/hmsLauncherTemplate.gradle";
FileUtil.ReplaceFile(launcherTemplatePath, Directory.GetParent(path).FullName + @"/launcher/hmsLauncherTemplate.gradle");
using (var writer = File.AppendText(Directory.GetParent(path).FullName + "/launcher/build.gradle"))
writer.WriteLine("\napply from: 'hmsLauncherTemplate.gradle'");
string launcherTemplatePath = Application.dataPath + "/Huawei/Plugins/Android/hmsLauncherTemplate.gradle";
FileUtil.ReplaceFile(launcherTemplatePath, Directory.GetParent(path).FullName + @"/launcher/hmsLauncherTemplate.gradle");
using (var writer = File.AppendText(Directory.GetParent(path).FullName + "/launcher/build.gradle"))
writer.WriteLine("\napply from: 'hmsLauncherTemplate.gradle'");

string baseProjectTemplatePath = Application.dataPath + "/Huawei/Plugins/Android/hmsBaseProjectTemplate.gradle";
FileUtil.ReplaceFile(baseProjectTemplatePath, Directory.GetParent(path).FullName + @"/hmsBaseProjectTemplate.gradle");
string baseProjectTemplatePath = Application.dataPath + "/Huawei/Plugins/Android/hmsBaseProjectTemplate.gradle";
FileUtil.ReplaceFile(baseProjectTemplatePath, Directory.GetParent(path).FullName + @"/hmsBaseProjectTemplate.gradle");

//TODO: HMSMainKitsTabFactory.GetEnabledEditors() counts zero sometimes
// Get enabled Kits and check if they are one of the below, because only them needs to be updated to the latest version.
/*foreach (var toggle in HMSMainKitsTabFactory.GetEnabledEditors())
{
if (toggle.GetType() == typeof(AccountToggleEditor)
|| toggle.GetType() == typeof(PushToggleEditor)
|| toggle.GetType() == typeof(IAPToggleEditor)
|| toggle.GetType() == typeof(NearbyServiceToggleEditor)
|| toggle.GetType() == typeof(AnalyticsToggleEditor))
//TODO: HMSMainKitsTabFactory.GetEnabledEditors() counts zero sometimes
// Get enabled Kits and check if they are one of the below, because only them needs to be updated to the latest version.
/*foreach (var toggle in HMSMainKitsTabFactory.GetEnabledEditors())
{
GradleVersionFixer(File.ReadAllText(Directory.GetParent(path).FullName + "/build.gradle"), path);
}
}*/
if (toggle.GetType() == typeof(AccountToggleEditor)
|| toggle.GetType() == typeof(PushToggleEditor)
|| toggle.GetType() == typeof(IAPToggleEditor)
|| toggle.GetType() == typeof(NearbyServiceToggleEditor)
|| toggle.GetType() == typeof(AnalyticsToggleEditor))
{
GradleVersionFixer(File.ReadAllText(Directory.GetParent(path).FullName + "/build.gradle"), path);
}
}*/


#if UNITY_2022_2_OR_NEWER

GradleVersionFixer(File.ReadAllText(Directory.GetParent(path).FullName + "/build.gradle"), path);
#else
GradleVersionFixer(File.ReadAllText(Directory.GetParent(path).FullName + "/build.gradle"), path);
using (var writer = File.AppendText(Directory.GetParent(path).FullName + "/build.gradle"))
writer.WriteLine("\napply from: 'hmsBaseProjectTemplate.gradle'");
GradleVersionFixer(File.ReadAllText(Directory.GetParent(path).FullName + "/build.gradle"), path);
using (var writer = File.AppendText(Directory.GetParent(path).FullName + "/build.gradle"))
writer.WriteLine("\napply from: 'hmsBaseProjectTemplate.gradle'");
#endif

if (HMSMainEditorSettings.Instance.Settings.GetBool(PushToggleEditor.PushKitEnabled))
{
string unityPlayerActivityJavaPath = path + @"/src/main/java/com/unity3d/player/UnityPlayerActivity.java";

var sb = new StringBuilder();
FileStream fs = new FileStream(unityPlayerActivityJavaPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
using (StreamReader sr = new StreamReader(fs))
if (HMSMainEditorSettings.Instance.Settings.GetBool(PushToggleEditor.PushKitEnabled))
{
string line;
do
string unityPlayerActivityJavaPath = path + @"/src/main/java/com/unity3d/player/UnityPlayerActivity.java";

var sb = new StringBuilder();
FileStream fs = new FileStream(unityPlayerActivityJavaPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
using (StreamReader sr = new StreamReader(fs))
{
line = sr.ReadLine();
sb.AppendLine(line);
string line;
do
{
line = sr.ReadLine();
sb.AppendLine(line);
}
while (line.Trim().TrimStart().TrimEnd() != "import android.os.Process;");
sb.AppendLine("import org.m0skit0.android.hms.unity.push.PushBridge;");

do
{
line = sr.ReadLine();
sb.AppendLine(line);
}
while (line.Trim().TrimStart().TrimEnd() != "mUnityPlayer.newIntent(intent);");
sb.AppendLine("PushBridge.OnNotificationMessage(intent);");
sb.Append(sr.ReadToEnd());
}
while (line.Trim().TrimStart().TrimEnd() != "import android.os.Process;");
sb.AppendLine("import org.m0skit0.android.hms.unity.push.PushBridge;");

do
using (var sw = new StreamWriter(unityPlayerActivityJavaPath))
{
line = sr.ReadLine();
sb.AppendLine(line);
sw.Write(sb.ToString());
}
while (line.Trim().TrimStart().TrimEnd() != "mUnityPlayer.newIntent(intent);");
sb.AppendLine("PushBridge.OnNotificationMessage(intent);");
sb.Append(sr.ReadToEnd());
}

using (var sw = new StreamWriter(unityPlayerActivityJavaPath))
{
sw.Write(sb.ToString());
}
}

#elif UNITY_2018_1_OR_NEWER
string hmsMainTemplatePath = Application.dataPath + @"/Huawei/Plugins/Android/hmsMainTemplate.gradle";
Expand All @@ -165,8 +166,9 @@ public void OnPostGenerateGradleAndroidProject(string path)
GradleVersionFixer(File.ReadAllText(path + "/build.gradle"), path);
destPath = Path.Combine(path, fileName);
#endif
if (File.Exists(destPath))
FileUtil.DeleteFileOrDirectory(destPath);
File.Copy(filePath, destPath);
if (File.Exists(destPath))
FileUtil.DeleteFileOrDirectory(destPath);
File.Copy(filePath, destPath);
}
}
}

0 comments on commit 3b47aab

Please sign in to comment.