コード例 #1
0
        private void WaitForVpnThreadToFinish()
        {
            if (vpnThread == null)
            {
                return;
            }

            try
            {
                vpnThread.Join(THREAD_MAX_JOIN_TIME);
            }
            catch (Java.Lang.InterruptedException)
            {
                EddieLogger.Error("VPNService.WaitVpnThreadToFinish(): VPN thread has been interrupted");
            }
            finally
            {
                if (vpnThread.IsAlive)
                {
                    EddieLogger.Error("VPNService.WaitVpnThreadToFinish(): VPN thread did not end");
                }
                else
                {
                    EddieLogger.Info("VPN thread execution has completed");
                }
            }
        }
コード例 #2
0
        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);
            View view = inflater.Inflate(Resource.Layout.ax_Settings, container, false);

            ax_settings = this;

            // --------- SET VARS ---------

            var cbookmarks = view.FindViewById(Resource.Id.clearbookmarks);
            var chistory   = view.FindViewById(Resource.Id.clearhistory);

            msearch    = view.FindViewById <CheckBox>(Resource.Id.msearch);
            hdasearch  = view.FindViewById <CheckBox>(Resource.Id.hdasearch);
            asearch    = view.FindViewById <CheckBox>(Resource.Id.asearch);
            basearch   = view.FindViewById <CheckBox>(Resource.Id.basearch);
            tvasearch  = view.FindViewById <CheckBox>(Resource.Id.tvasearch);
            htvasearch = view.FindViewById <CheckBox>(Resource.Id.htvasearch);
            bmsearch   = view.FindViewById <CheckBox>(Resource.Id.bmsearch);
            hdbasearch = view.FindViewById <CheckBox>(Resource.Id.hdbasearch);

            savelinks  = view.FindViewById <CheckBox>(Resource.Id.savelinks);
            savetitles = view.FindViewById <CheckBox>(Resource.Id.savetitles);
            savem3u    = view.FindViewById <CheckBox>(Resource.Id.savem3u);

            Button updatebtt = view.FindViewById <Button>(Resource.Id.update);

            updatebtt.Visibility = ViewStates.Gone;


            // --------- PING DATA ---------

            seachBoxes = new List <CheckBox> {
                msearch, hdasearch, asearch, basearch, tvasearch, bmsearch, htvasearch, hdbasearch
            };
            for (int i = 0; i < seachBoxes.Count; i++)
            {
                searchTxts[i] = seachBoxes[i].Text;
            }

            Button pingBtt = view.FindViewById <Button>(Resource.Id.pingProviders);

            pingBtt.Click += (o, e) =>
            {
                for (int i = 0; i < providersCount; i++)
                {
                    DelegateWithParameters_int ping =
                        new DelegateWithParameters_int(Ping);

                    IAsyncResult tag =
                        ping.BeginInvoke(i, null, null);
                }
            };

            Button showBtt = view.FindViewById <Button>(Resource.Id.showProviders);

            showBtt.Click += (o, e) =>
            {
                showSites = !showSites;
                for (int i = 0; i < providersCount; i++)
                {
                    seachBoxes[i].Text = searchTxts[i] + (showSites ? (" (" + pingLinks[i] + ")") : "");
                }
            };

            // --------- AUTO UPDATE ---------

            version = Context.PackageManager.GetPackageInfo(Context.PackageName, 0).VersionName;
            TextView versionTxt = view.FindViewById <TextView>(Resource.Id.versionTxt);

            versionTxt.Text = "v" + version;
            sThred          = new Java.Lang.Thread(() =>
            {
                try {
                    WebClient client = new WebClient();
                    string d         = client.DownloadString("https://github.com/LagradOst/CloudStream/releases");
                    string look      = "/LagradOst/CloudStream/releases/tag/";
                    //   float bigf = -1;
                    //     string bigUpdTxt = "";
                    // while (d.Contains(look)) {
                    string tag     = FindHTML(d, look, "\"");
                    string updText = FindHTML(d, look + tag + "\">", "<");

                    /*
                     *  try {
                     *      float tagf = float.Parse(tag.Replace("v", ""));
                     *      print("" + tagf);
                     *      if(tagf > bigf) {
                     *          bigf = tagf;
                     *          bigUpdTxt = updText;
                     *      }
                     *  }
                     *  catch (Exception) {
                     *
                     *  }
                     *  d = d.Substring(d.IndexOf(look) + 1, d.Length - d.IndexOf(look) - 1);
                     */
                    updatebtt.Click += (o, e) =>
                    {
                        if (version != updateTo && updateTo != "-1")
                        {
                            string downloadLink = "https://github.com/LagradOst/CloudStream/releases/download/" + updateTo + "/CloudStream.CloudStream.apk";
                            DownloadFromLink(downloadLink, "CloudStream-" + updateTo, "Downloading APK", this, ".apk", true);
                            updatebtt.Visibility = ViewStates.Gone;
                        }
                    };

                    if (tag != "")
                    {
                        Activity.RunOnUiThread(new Action(() =>
                        {
                            updateTo = tag;
                            if (tag == "v" + version)
                            {
                                versionTxt.Text      = "v" + version + " (Up to date)";
                                updatebtt.Visibility = ViewStates.Gone;
                            }
                            else
                            {
                                versionTxt.Text      = "v" + version + " -> " + tag + " (" + updText + ")";
                                updatebtt.Visibility = ViewStates.Visible;
                                updatebtt.Text       = "Update to " + tag;
                            }
                        }));
                    }
                }
                finally {
                    sThred.Join();
                }
            });
            if (searchForUpdates)
            {
                sThred.Start();
            }
            //  var sdownloads =  view.FindViewById(Resource.Id.showdownloads);

            // sdownloads.Click += (o,e) => MainActivity.mainActivity.ShowDownloads();



            // --------- DEF DATA ---------

            var set = Application.Context.GetSharedPreferences("Settings", FileCreationMode.Private);

            msearch.Checked    = set.GetBoolean("msearch", true);
            hdasearch.Checked  = set.GetBoolean("hdasearch", haveAnimeEnabled);
            asearch.Checked    = set.GetBoolean("asearch", false);
            basearch.Checked   = set.GetBoolean("basearch", false);
            tvasearch.Checked  = set.GetBoolean("tvasearch", false);
            bmsearch.Checked   = set.GetBoolean("bmsearch", false);
            htvasearch.Checked = set.GetBoolean("htvasearch", true);
            hdbasearch.Checked = set.GetBoolean("hdbasearch", false);
            savem3u.Checked    = set.GetBoolean("savem3u", false);

            if (!haveAnimeEnabled)
            {
                hdasearch.Visibility  = ViewStates.Gone;
                asearch.Visibility    = ViewStates.Gone;
                basearch.Visibility   = ViewStates.Gone;
                hdbasearch.Visibility = ViewStates.Gone;
            }


            // --------- SAVE DATA ---------

            savelinks.Checked  = set.GetBoolean("savelinks", true);
            savetitles.Checked = set.GetBoolean("savetitles", true);

            msearch.Click    += (o, e) => SaveBool("msearch", msearch.Checked);
            hdasearch.Click  += (o, e) => SaveBool("hdasearch", hdasearch.Checked);
            asearch.Click    += (o, e) => SaveBool("asearch", asearch.Checked);
            basearch.Click   += (o, e) => SaveBool("basearch", basearch.Checked);
            tvasearch.Click  += (o, e) => SaveBool("tvasearch", tvasearch.Checked);
            bmsearch.Click   += (o, e) => SaveBool("bmsearch", bmsearch.Checked);
            htvasearch.Click += (o, e) => SaveBool("htvasearch", htvasearch.Checked);
            hdbasearch.Click += (o, e) => SaveBool("hdbasearch", hdbasearch.Checked);

            savelinks.Click  += (o, e) => SaveBool("savelinks", savelinks.Checked);
            savetitles.Click += (o, e) => SaveBool("savetitles", savetitles.Checked);
            savem3u.Click    += (o, e) => SaveBool("savem3u", savem3u.Checked); // M3U FILE

            // --------- HISTORY ---------

            chistory.SetBackgroundColor(Color.AliceBlue);
            cbookmarks.SetBackgroundColor(Color.AliceBlue);
            //  sdownloads.SetBackgroundColor(Color.AliceBlue);

            chistory.LongClickable   = true;
            cbookmarks.LongClickable = true;

            chistory.LongClick += (o, e) =>
            {
                ShowSnackBar("Removed All Viewhistory", o);
                var localC = Application.Context.GetSharedPreferences("History", FileCreationMode.Private);
                var edit   = localC.Edit();
                edit.Clear();
                edit.Commit();
            };
            cbookmarks.LongClick += (o, e) =>
            {
                ShowSnackBar("Removed All Bookmarks", o);
                var localC = Application.Context.GetSharedPreferences("Bookmarks", FileCreationMode.Private);
                var edit   = localC.Edit();
                edit.Clear();
                edit.Commit();
                ax_Bookmarks.ax_bookmarks.UpdateList();
            };
            chistory.Click += (o, e) =>
            {
                ShowSnackBar("Hold To Remove History", o);
            };
            cbookmarks.Click += (o, e) =>
            {
                ShowSnackBar("Hold To Remove Bookmarks", o);
            };

            // --------- ACTIONS ---------

            var defAct = view.FindViewById <Spinner>(Resource.Id.DefSpinner);
            var secAct = view.FindViewById <Spinner>(Resource.Id.SecSpinner);


            var adapter = new ArrayAdapter <string>(Context, Android.Resource.Layout.SimpleSpinnerItem, defChecks);

            defAct.Adapter = adapter;
            secAct.Adapter = adapter;

            defActions[0] = SettingsGetDef(0); // set.GetInt("defAct", 0);
            defActions[1] = SettingsGetDef(1); // set.GetInt("secAct", 1);

            defAct.SetSelection(defActions[0]);
            secAct.SetSelection(defActions[1]);

            defAct.ItemSelected += (o, e) => { SaveInt("defAct", e.Position); defActions[0] = e.Position; };
            secAct.ItemSelected += (o, e) => { SaveInt("secAct", e.Position); defActions[1] = e.Position; };

            return(view);
        }
コード例 #3
0
        public static void DownloadFromLink(string url, string title, string toast = "", string ending = "", bool openFile = false, string descripts = "")
        {
            print("DOWNLOADING: " + url);

            DownloadManager.Request request = new DownloadManager.Request(Android.Net.Uri.Parse(url));
            request.SetTitle(title);
            request.SetDescription(descripts);
            string mainPath = Android.OS.Environment.DirectoryDownloads;
            string subPath  = title + ending;
            string fullPath = mainPath + "/" + subPath;

            print("PATH: " + fullPath);

            request.SetDestinationInExternalPublicDir(mainPath, subPath);
            request.SetVisibleInDownloadsUi(true);
            request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);

            DownloadManager manager;

            manager = (DownloadManager)MainActivity.activity.GetSystemService(Context.DownloadService);

            long downloadId = manager.Enqueue(request);



            // AUTO OPENS FILE WHEN DONE DOWNLOADING
            if (openFile || toast != "")
            {
                downloadThread = new Java.Lang.Thread(() => {
                    try {
                        bool exists = false;
                        while (!exists)
                        {
                            try {
                                string p = manager.GetUriForDownloadedFile(downloadId).Path;
                                exists   = true;
                            }
                            catch (System.Exception) {
                                Java.Lang.Thread.Sleep(100);
                            }
                        }
                        Java.Lang.Thread.Sleep(1000);
                        if (toast != "")
                        {
                            App.ShowToast(toast);
                        }
                        if (openFile)
                        {
                            print("OPEN FILE");
                            //
                            string truePath = ("file://" + Android.OS.Environment.ExternalStorageDirectory + "/" + fullPath);

                            OpenFile(truePath);
                        }
                    }
                    finally {
                        downloadThread.Join();
                    }
                });
                downloadThread.Start();
            }
        }