-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathMainActivity.cs
100 lines (89 loc) · 3.75 KB
/
MainActivity.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
using System;
using Android.App;
using Android.Content.PM;
using Android.Content.Res;
using Android.OS;
using Android.Runtime;
using Chameleon.Core;
using Chameleon.Core.Helpers;
using Chameleon.Core.ViewModels;
using MediaManager;
using MvvmCross;
using MvvmCross.Forms.Platforms.Android.Views;
using MvvmCross.Navigation;
using Plugin.CurrentActivity;
using Xamarin.Forms;
using Intent = Android.Content.Intent;
namespace Chameleon.Droid
{
[Activity(
Label = "@string/app_name",
Icon = "@mipmap/icon",
Theme = "@style/MainTheme.Launcher",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode)]
[IntentFilter(new[] { Intent.ActionSend, Intent.ActionSendMultiple, Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable, Intent.CategoryAppMusic }, DataMimeTypes = new[] { "video/*", "audio/*" }, Label = "@string/app_name")]
public class MainActivity : MvxFormsAppCompatActivity<Setup, App, FormsApp>
{
protected override void OnCreate(Bundle savedInstanceState)
{
Forms.SetFlags("CollectionView_Experimental");
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
SetTheme(Resource.Style.MainTheme);
base.OnCreate(savedInstanceState);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);
CrossCurrentActivity.Current.Init(this, savedInstanceState);
CrossMediaManager.Current.Init(this);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
}
protected override void OnStart()
{
base.OnStart();
UpdateTheme(Resources.Configuration);
}
protected override void OnResume()
{
base.OnResume();
HandleIntent();
UpdateTheme(Resources.Configuration);
}
private async void HandleIntent()
{
if (await CrossMediaManager.Android.PlayFromIntent(Intent))
{
await Mvx.IoCProvider.Resolve<IMvxNavigationService>().Navigate<PlayerViewModel>();
}
}
public override void OnConfigurationChanged(Configuration newConfig)
{
base.OnConfigurationChanged(newConfig);
UpdateTheme(newConfig);
}
private void UpdateTheme(Configuration newConfig)
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.Froyo)
{
var uiModeFlags = newConfig.UiMode & UiMode.NightMask;
switch (uiModeFlags)
{
case UiMode.NightYes:
Mvx.IoCProvider.Resolve<IThemeService>().UpdateTheme(Core.Models.ThemeMode.Dark);
//AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightYes;
break;
case UiMode.NightNo:
Mvx.IoCProvider.Resolve<IThemeService>().UpdateTheme(Core.Models.ThemeMode.Light);
break;
default:
throw new NotSupportedException($"UiMode {uiModeFlags} not supported");
}
}
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
Plugin.Permissions.PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}