-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainFragment.cs
118 lines (99 loc) · 4.31 KB
/
MainFragment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Util;
using Android.Views;
using Android.Widget;
using AndroidX.Leanback.App;
using AndroidX.Leanback.Widget;
using System;
namespace droidtvtest
{
public class MainFragment : BrowseFragment, View.IOnClickListener, IOnItemViewSelectedListener
{
private static readonly String TAG = "MainFragment";
private ArrayObjectAdapter mRowsAdapter;
private DisplayMetrics mMetrics;
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your fragment here
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
// return inflater.Inflate(Resource.Layout.YourFragment, container, false);
Log.Info(TAG, "onCreate");
mMetrics = new DisplayMetrics();
this.Activity.WindowManager.DefaultDisplay.GetMetrics(mMetrics);
BadgeDrawable = this.Activity.Resources.GetDrawable(Resource.Drawable.videos_by_google_banner);
Title = "My Home";
HeadersState = BrowseFragment.HeadersEnabled;
HeadersTransitionOnBackEnabled = true;
BrandColor = Resources.GetColor(Resource.Color.fastlane_background);
SearchAffordanceColor = Resources.GetColor(Resource.Color.search_opaque);
SetOnSearchClickedListener(this);
OnItemViewSelectedListener = this;
ItemViewClicked += (object sender, ItemViewClickedEventArgs e) => {
var item = e.Item;
Log.Debug(TAG, "click item");
};
LoadData();
return base.OnCreateView(inflater, container, savedInstanceState);
}
public void OnItemSelected(Presenter.ViewHolder itemViewHolder, Java.Lang.Object item, RowPresenter.ViewHolder rowViewHolder, Row row)
{
}
public void OnClick(View v)
{
Log.Debug(TAG, "Searcher click");
}
private void LoadData()
{
mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
var gridHeader = new HeaderItem(0, "test");
var gridPresenter = new GridItemPresenter(this.Context);
var gridRowAdapter = new ArrayObjectAdapter(gridPresenter);
gridRowAdapter.Add("test");
gridRowAdapter.Add("test2");
gridRowAdapter.Add("test3");
mRowsAdapter.Add(new ListRow(gridHeader, gridRowAdapter));
var gridHeader2 = new HeaderItem(1, "testB");
var gridPresenter2 = new GridItemPresenter(this.Context);
var gridRowAdapter2 = new ArrayObjectAdapter(gridPresenter2);
gridRowAdapter2.Add("test");
gridRowAdapter2.Add("test2");
gridRowAdapter2.Add("test3");
mRowsAdapter.Add(new ListRow(gridHeader2, gridRowAdapter2));
this.Adapter = mRowsAdapter;
}
private class GridItemPresenter : Presenter
{
private static int GRID_ITEM_WIDTH = 130;
private static int GRID_ITEM_HEIGHT = 130;
private Context mainFragment;
public GridItemPresenter(Context mainFragment)
{
this.mainFragment = mainFragment;
}
public override void OnBindViewHolder(ViewHolder viewHolder, Java.Lang.Object item)
{
((TextView)viewHolder.View).Text = (String)item;
}
public override ViewHolder OnCreateViewHolder(ViewGroup parent)
{
TextView view = new TextView(parent.Context);
view.LayoutParameters = new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT);
view.SetFocusable(ViewFocusability.Focusable);
view.FocusableInTouchMode = true;
view.SetBackgroundColor(new Color(30, 30, 30));
view.SetTextColor(Color.White);
view.SetForegroundGravity(GravityFlags.Center);
return new ViewHolder(view);
}
public override void OnUnbindViewHolder(ViewHolder viewHolder)
{
}
}
}
}