diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerAssembly.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerAssembly.cs index df98d2ec0d0..dd4975845ea 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerAssembly.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerAssembly.cs @@ -131,10 +131,10 @@ bool Run(DirectoryAssemblyResolver res) { var r = resource.Value; switch (r.Type) { case RType.Integer: - CreateIntProperty (resource.Key, r.Identifier, r.Id, resourceDesigner, module); + CreateIntProperty (r.ResourceType, r.Identifier, r.Id, resourceDesigner, module); break; case RType.Array: - CreateIntArrayProperty (resource.Key, r.Identifier, r.Ids, resourceDesigner, module); + CreateIntArrayProperty (r.ResourceType, r.Identifier, r.Ids, resourceDesigner, module); break; } } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs index 3c90e7891a0..2ea0c52825c 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs @@ -296,98 +296,18 @@ public CodeTypeDeclaration Parse (string resourceDirectory, string rTxtFile, IEn void ProcessRtxtFile (string file) { - var lines = System.IO.File.ReadLines (file); - foreach (var line in lines) { - var items = line.Split (new char [] { ' ' }, 4); - int value = items [1] != "styleable" ? Convert.ToInt32 (items [3], 16) : -1; - string itemName = items [2]; - switch (items [1]) { - case "anim": - CreateIntField (animation, itemName, value); - break; - case "animator": - CreateIntField (animator, itemName, value); - break; - case "attr": - CreateIntField (attrib, itemName, value); - break; - case "array": - CreateIntField (arrays, itemName, value); - break; - case "bool": - CreateIntField (boolean, itemName, value); - break; - case "color": - CreateIntField (colors, itemName, value); - break; - case "dimen": - CreateIntField (dimension, itemName, value); - break; - case "drawable": - CreateIntField (drawable, itemName, value); - break; - case "font": - CreateIntField (font, itemName, value); - break; - case "id": - CreateIntField (ids, itemName, value); - break; - case "integer": - CreateIntField (ints, itemName, value); - break; - case "interpolator": - CreateIntField (interpolators, itemName, value); - break; - case "layout": - CreateIntField (layout, itemName, value); - break; - case "menu": - CreateIntField (menu, itemName, value); - break; - case "mipmap": - CreateIntField (mipmaps, itemName, value); - break; - case "plurals": - CreateIntField (plurals, itemName, value); - break; - case "raw": - CreateIntField (raw, itemName, value); - break; - case "string": - CreateIntField (strings, itemName, value); - break; - case "style": - CreateIntField (style, itemName, value); - break; - case "styleable": - switch (items [0]) { - case "int": - CreateIntField (styleable, itemName, Convert.ToInt32 (items [3], 10)); + var parser = new RtxtParser (); + var resources = parser.Parse (file, Log, map); + foreach (var resource in resources) { + var r = resource.Value; + var cl = CreateClass (r.ResourceType); + switch (r.Type) { + case RType.Integer: + CreateIntField (cl, r.Identifier, r.Id); break; - case "int[]": - var arrayValues = items [3].Trim (new char [] { '{', '}' }) - .Replace (" ", "") - .Split (new char [] { ',' }); - CreateIntArrayField (styleable, itemName, arrayValues.Length, - arrayValues.Select (x => string.IsNullOrEmpty (x) ? -1 : Convert.ToInt32 (x, 16)).ToArray ()); + case RType.Array: + CreateIntArrayField (cl, r.Identifier, r.Ids.Length, r.Ids); break; - } - break; - case "transition": - CreateIntField (transition, itemName, value); - break; - case "xml": - CreateIntField (xml, itemName, value); - break; - // for custom views - default: - CodeTypeDeclaration customClass; - if (!custom_types.TryGetValue (items [1], out customClass)) { - customClass = CreateClass (items [1]); - custom_types.Add (items [1], customClass); - } - CreateIntField (customClass, itemName, value); - break; } } } @@ -435,8 +355,13 @@ CodeTypeDeclaration CreateResourceClass () return decl; } + Dictionary classes = new Dictionary (StringComparer.OrdinalIgnoreCase); + CodeTypeDeclaration CreateClass (string type) { + if (classes.ContainsKey (type)) { + return classes[type]; + } var t = new CodeTypeDeclaration (ResourceParser.GetNestedTypeName (type)) { IsPartial = true, TypeAttributes = TypeAttributes.Public, @@ -444,6 +369,7 @@ CodeTypeDeclaration CreateClass (string type) t.Members.Add (new CodeConstructor () { Attributes = MemberAttributes.Private, }); + classes.Add (type, t); return t; } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/RtxtParser.cs b/src/Xamarin.Android.Build.Tasks/Utilities/RtxtParser.cs index e20bb8baa79..5a0203efc2b 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/RtxtParser.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/RtxtParser.cs @@ -12,7 +12,7 @@ public enum RType { Array, } public struct R { - public RType Type = RType.Integer; + public RType Type; public int Id; public int [] Ids; public string Identifier; @@ -37,6 +37,7 @@ public Dictionary Parse (string file, TaskLoggingHelper logger, Dicti var result = new Dictionary (); if (File.Exists (file)) ProcessRtxtFile (file, result); + return result; } @@ -47,6 +48,7 @@ void ProcessRtxtFile (string file, Dictionary result) var items = line.Split (new char [] { ' ' }, 4); int value = items [1] != "styleable" ? Convert.ToInt32 (items [3], 16) : -1; string itemName = ResourceIdentifier.GetResourceName(items [1], items [2], resource_fixup, log); + string itemKey = $"{items [1]}:{itemName}"; switch (items [1]) { case "anim": case "animator": @@ -69,7 +71,7 @@ void ProcessRtxtFile (string file, Dictionary result) case "style": case "transition": case "xml": - result[ items [1]] = new R () { + result [itemKey] = new R () { ResourceType = items[1], Identifier = itemName, Id = value, @@ -78,7 +80,7 @@ void ProcessRtxtFile (string file, Dictionary result) case "styleable": switch (items [0]) { case "int": - result[ items [1]] = new R () { + result [itemKey] = new R () { ResourceType = items[1], Identifier = itemName, Id = Convert.ToInt32 (items [3], 10), @@ -89,7 +91,7 @@ void ProcessRtxtFile (string file, Dictionary result) .Replace (" ", "") .Split (new char [] { ',' }); - result[ items [1]] = new R () { + result [itemKey] = new R () { ResourceType = items[1], Type = RType.Array, Identifier = itemName, @@ -100,7 +102,7 @@ void ProcessRtxtFile (string file, Dictionary result) break; // for custom views default: - result[ items [1]] = new R () { + result [itemKey] = new R () { ResourceType = items[1], Identifier = itemName, Id = value,