|
1 | 1 | # AndroidLayoutToCSharp |
| 2 | + |
2 | 3 | Tiny prgram that converts android xml's into c# properties. It can save a few minutes of your life ^^ |
3 | 4 | It runs on UWP. |
4 | 5 |
|
5 | | -All what it does is this: |
6 | | -###Input: |
7 | | -``` |
8 | | -<?xml version="1.0" encoding="utf-8"?> |
9 | | -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
10 | | - xmlns:app="http://schemas.android.com/apk/res-auto" |
11 | | - android:orientation="vertical" |
12 | | - android:layout_width="match_parent" |
13 | | - android:layout_height="match_parent" |
14 | | - android:paddingTop="2dp" android:paddingBottom="2dp" |
15 | | - android:background="?android:selectableItemBackground"> |
16 | | - <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/border_accent_left_wide" android:paddingTop="2dp" android:paddingBottom="2dp" android:paddingStart="10dp"> |
17 | | - <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> |
18 | | - <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="5dp"> |
19 | | - <FFImageLoading.Views.ImageViewAsync android:layout_width="35dp" android:layout_height="50dp" android:scaleType="fitXY" |
20 | | - android:id="@+id/AnimeReviewItemLayoutAvatarImage"/> |
21 | | - <LinearLayout android:layout_width="wrap_content" android:layout_gravity="center" android:orientation="vertical" android:layout_height="wrap_content" android:layout_marginStart="10dp"> |
22 | | - <TextView android:layout_width="wrap_content" android:fontFamily="@string/font_family_medium" android:layout_height="wrap_content" android:text="Author" android:textColor="@color/BrushText" |
23 | | - android:id="@+id/AnimeReviewItemLayoutAuthor"/> |
24 | | - <TextView android:layout_width="wrap_content" android:fontFamily="@string/font_family_light" android:layout_height="wrap_content" android:text="Yesteday blaldfg" android:textColor="@color/BrushText" |
25 | | - android:id="@+id/AnimeReviewItemLayoutDate"/> |
26 | | - </LinearLayout> |
27 | | - </LinearLayout> |
28 | | - <TextView android:layout_width="wrap_content" android:fontFamily="@string/font_family_light" android:layout_height="wrap_content" android:textColor="@color/BrushText" android:text="Overall: 9" |
29 | | - android:id="@+id/AnimeReviewItemLayoutOverallScore"/> |
30 | | - <TextView android:layout_width="wrap_content" android:fontFamily="@string/font_family_light" android:layout_height="wrap_content" android:textColor="@color/BrushText" android:text="9 of 20 eps seen" |
31 | | - android:id="@+id/AnimeReviewItemLayoutEpsSeen"/> |
32 | | - <TextView android:layout_width="wrap_content" android:fontFamily="@string/font_family_light" android:layout_height="wrap_content" android:textColor="@color/BrushText" android:text="12 found this helpful" |
33 | | - android:id="@+id/AnimeReviewItemLayoutHelpfulCount"/> |
34 | | - </LinearLayout> |
35 | | -
|
36 | | - <LinearLayout android:id="@+id/AnimeReviewItemLayoutMarksList" android:layout_width="100dp" android:layout_marginTop="5dp" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:orientation="vertical" android:gravity="start"/> |
37 | | - </RelativeLayout> |
38 | | -
|
39 | | - <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:text="Lorem" android:textColor="@color/BrushText" |
40 | | - android:id="@+id/AnimeReviewItemLayoutReviewContent"/> |
41 | | -</LinearLayout> |
42 | | -``` |
43 | | -###Output: |
44 | | -``` |
45 | | -private ImageViewAsync _animeReviewItemLayoutAvatarImage; |
46 | | -private TextView _animeReviewItemLayoutAuthor; |
47 | | -private TextView _animeReviewItemLayoutDate; |
48 | | -private TextView _animeReviewItemLayoutOverallScore; |
49 | | -private TextView _animeReviewItemLayoutEpsSeen; |
50 | | -private TextView _animeReviewItemLayoutHelpfulCount; |
51 | | -private LinearLayout _animeReviewItemLayoutMarksList; |
52 | | -private TextView _animeReviewItemLayoutReviewContent; |
53 | | -
|
54 | | -public ImageViewAsync AnimeReviewItemLayoutAvatarImage => _animeReviewItemLayoutAvatarImage ?? (_animeReviewItemLayoutAvatarImage = FindViewById<ImageViewAsync>(Resource.Id.AnimeReviewItemLayoutAvatarImage)); |
55 | | -
|
56 | | -public TextView AnimeReviewItemLayoutAuthor => _animeReviewItemLayoutAuthor ?? (_animeReviewItemLayoutAuthor = FindViewById<TextView>(Resource.Id.AnimeReviewItemLayoutAuthor)); |
57 | | -
|
58 | | -public TextView AnimeReviewItemLayoutDate => _animeReviewItemLayoutDate ?? (_animeReviewItemLayoutDate = FindViewById<TextView>(Resource.Id.AnimeReviewItemLayoutDate)); |
59 | | -
|
60 | | -public TextView AnimeReviewItemLayoutOverallScore => _animeReviewItemLayoutOverallScore ?? (_animeReviewItemLayoutOverallScore = FindViewById<TextView>(Resource.Id.AnimeReviewItemLayoutOverallScore)); |
| 6 | + |
61 | 7 |
|
62 | | -public TextView AnimeReviewItemLayoutEpsSeen => _animeReviewItemLayoutEpsSeen ?? (_animeReviewItemLayoutEpsSeen = FindViewById<TextView>(Resource.Id.AnimeReviewItemLayoutEpsSeen)); |
| 8 | +## Features |
63 | 9 |
|
64 | | -public TextView AnimeReviewItemLayoutHelpfulCount => _animeReviewItemLayoutHelpfulCount ?? (_animeReviewItemLayoutHelpfulCount = FindViewById<TextView>(Resource.Id.AnimeReviewItemLayoutHelpfulCount)); |
| 10 | +- [x] Convert Android XML layout to C# properties. |
| 11 | +- [x] Recursive resolution of layouts in `<include>` elements. |
| 12 | +- [x] Creating ViewHolders |
65 | 13 |
|
66 | | -public LinearLayout AnimeReviewItemLayoutMarksList => _animeReviewItemLayoutMarksList ?? (_animeReviewItemLayoutMarksList = FindViewById<LinearLayout>(Resource.Id.AnimeReviewItemLayoutMarksList)); |
| 14 | +## Additional stuff |
67 | 15 |
|
68 | | -public TextView AnimeReviewItemLayoutReviewContent => _animeReviewItemLayoutReviewContent ?? (_animeReviewItemLayoutReviewContent = FindViewById<TextView>(Resource.Id.AnimeReviewItemLayoutReviewContent)); |
69 | | -``` |
| 16 | +* You can add `tools:managedTypeName` attribute to use custom Type for properties. Useful when you have override Type name in library binding project. |
| 17 | +* Warns about duplicated IDs, helpful when layout in `<include>` contains the same ID. |
0 commit comments