1818using YoutubeExplode . Videos . Streams ;
1919
2020namespace YoutubeDL {
21- [ Activity ( Label = "@string/app_name" , Theme = "@style/AppTheme.NoActionBar" , MainLauncher = true ) ]
21+ [ Activity ( Label = "@string/app_name" , Theme = "@style/AppTheme.NoActionBar" ) ]
2222 [ IntentFilter (
2323 new [ ] { Intent . ActionSend } ,
2424 Categories = new [ ] { Intent . CategoryDefault } ,
@@ -30,30 +30,22 @@ public class MainActivity : AppCompatActivity {
3030 private static int s_NextNotificationID ;
3131
3232 protected override void OnCreate ( Bundle savedInstanceState ) {
33- // TODO planned features:
34- // - History in main activity
35- // - Configure download location
36- // - Configure download type (support all types available)
37- // - Move hardcoded strings to strings.xml
3833 base . OnCreate ( savedInstanceState ) ;
3934 Xamarin . Essentials . Platform . Init ( this , savedInstanceState ) ;
40- SetContentView ( Resource . Layout . activity_main ) ;
4135
42- if ( ContextCompat . CheckSelfPermission ( this , Manifest . Permission . WriteExternalStorage ) != ( int ) Permission . Granted ) {
43- ActivityCompat . RequestPermissions ( this , new string [ ] { Manifest . Permission . WriteExternalStorage } , 0 ) ;
36+ string [ ] requiredPermissions = new string [ ] { Manifest . Permission . Internet , Manifest . Permission . ReadExternalStorage , Manifest . Permission . WriteExternalStorage } ;
37+ if ( requiredPermissions . Any ( perm => ContextCompat . CheckSelfPermission ( this , perm ) != Permission . Granted ) ) {
38+ ActivityCompat . RequestPermissions ( this , requiredPermissions , 0 ) ;
39+ } else {
40+ DoDownload ( ) ;
4441 }
4542
46- if ( ContextCompat . CheckSelfPermission ( this , Manifest . Permission . ReadExternalStorage ) != ( int ) Permission . Granted ) {
47- ActivityCompat . RequestPermissions ( this , new string [ ] { Manifest . Permission . ReadExternalStorage } , 0 ) ;
48- }
49-
50- if ( ContextCompat . CheckSelfPermission ( this , Manifest . Permission . Internet ) != ( int ) Permission . Granted ) {
51- ActivityCompat . RequestPermissions ( this , new string [ ] { Manifest . Permission . Internet } , 0 ) ;
52- }
43+ Finish ( ) ;
44+ }
5345
46+ private void DoDownload ( ) {
5447 if ( Intent ? . Extras != null ) {
5548 string youtubeUrl = Intent . GetStringExtra ( Intent . ExtraText ) ;
56- Finish ( ) ; // works inconsistently
5749 Task . Run ( async ( ) => {
5850 int notificationID = s_NextNotificationID ++ ;
5951 var manager = ( NotificationManager ) GetSystemService ( Java . Lang . Class . FromType ( typeof ( NotificationManager ) ) ) ;
@@ -119,25 +111,12 @@ void makeNotif(string title, string text) {
119111 }
120112 }
121113
122- public override bool OnCreateOptionsMenu ( IMenu menu ) {
123- MenuInflater . Inflate ( Resource . Menu . menu_main , menu ) ;
124- return true ;
125- }
126-
127- public override bool OnOptionsItemSelected ( IMenuItem item ) {
128- int id = item . ItemId ;
129- if ( id == Resource . Id . action_settings ) {
130- // Open the options menu here
131- return true ;
132- }
133-
134- return base . OnOptionsItemSelected ( item ) ;
135- }
136-
137114 public override void OnRequestPermissionsResult ( int requestCode , string [ ] permissions , [ GeneratedEnum ] Android . Content . PM . Permission [ ] grantResults ) {
138115 Xamarin . Essentials . Platform . OnRequestPermissionsResult ( requestCode , permissions , grantResults ) ;
139116
140117 base . OnRequestPermissionsResult ( requestCode , permissions , grantResults ) ;
118+
119+ DoDownload ( ) ;
141120 }
142121
143122 private string SanitizeFilename ( string inputStr ) {
0 commit comments