-
Notifications
You must be signed in to change notification settings - Fork 1
/
TVScheduleActivity.cs
106 lines (94 loc) · 3.94 KB
/
TVScheduleActivity.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using AndroidX.AppCompat.App;
using AndroidX.AppCompat.Widget;
using AndroidX.Core.Content;
using AndroidX.Core.Widget;
using AndroidX.SwipeRefreshLayout.Widget;
using AndroidX.ViewPager.Widget;
using AndroidX.ViewPager2.Widget;
using com.aa.tvshows.Fragments;
using com.aa.tvshows.Helper;
using Google.Android.Material.Tabs;
namespace com.aa.tvshows
{
[Activity(Label = "TV Schedule", ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
public class TVScheduleActivity : AppCompatActivity
{
ViewPager2 viewPager;
TabLayout tabLayout;
AppCompatTextView status;
LinearLayoutCompat emptyView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.tv_schedule_base);
var toolbar = FindViewById<Toolbar>(Resource.Id.main_toolbar);
AppView.SetActionBarForActivity(toolbar, this);
viewPager = FindViewById<ViewPager2>(Resource.Id.main_tabs_viewpager);
tabLayout = FindViewById<TabLayout>(Resource.Id.main_tabs_header);
tabLayout.Visibility = ViewStates.Invisible;
tabLayout.TabMode = TabLayout.ModeScrollable;
//tabLayout.SetupWithViewPager(viewPager);
status = new AppCompatTextView(this);
TextViewCompat.SetTextAppearance(status, Resource.Style.TextAppearance_AppCompat_Body2);
status.TextAlignment = TextAlignment.Center;
emptyView = FindViewById<LinearLayoutCompat>(Resource.Id.tv_schedule_empty_view);
SetupScheduleData();
}
public override bool OnCreateOptionsMenu(IMenu menu)
{
return AppView.ShowOptionsMenu(menu, this);
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
return AppView.OnOptionsItemSelected(item, this);
}
public override bool OnSupportNavigateUp()
{
OnBackPressed();
return true;
}
public async void SetupScheduleData(SwipeRefreshLayout swipeRefresh = default)
{
AppView.SetEmptyView(emptyView, false);
if (viewPager.Adapter != null)
{
tabLayout.Visibility = viewPager.Visibility = ViewStates.Gone;
}
var tabsAdapter = new PageTabsAdapter(this);
if (swipeRefresh != null)swipeRefresh.Refreshing = true;
emptyView.Visibility = ViewStates.Visible;
status.Text = "Loading...";
emptyView.AddView(status);
var data = await WebData.GetTVSchedule().ConfigureAwait(true);
if (data != null && data.Count > 0)
{
AppView.SetEmptyView(emptyView, false);
tabLayout.Visibility = ViewStates.Visible;
viewPager.Visibility = ViewStates.Visible;
viewPager.Adapter = tabsAdapter;
TabMediatorStrategy tabStrategy = new TabMediatorStrategy(tabsAdapter.Fragments);
TabLayoutMediator tabMediator = new TabLayoutMediator(tabLayout, viewPager, tabStrategy);
tabMediator.Attach();
foreach (var item in data)
{
tabsAdapter.AddTab(new TitleFragment() { Title = item.Key, Fragmnet = new MainTabs(DataEnum.DataType.TVSchedule, new List<object>(item.Value)) });
}
}
else
{
AppView.SetEmptyView(emptyView, true, false, delegate { SetupScheduleData(swipeRefresh); });
}
if (swipeRefresh != null) swipeRefresh.Refreshing = false;
}
}
}