protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Name = Intent.Extras.GetString("name"); Address = Intent.Extras.GetString("address"); Title = $"{Name} ({Address})"; SetContentView(Resource.Layout.Processes); ProcessesListView = FindViewById <ListView>(Resource.Id.ProcessesListView); ProcessesListView.Adapter = new TwoLineListAdapter(this); Api = new ApiClient(Address); UpdateTask = CreateUpdateTask(); // Context menu setup. RegisterForContextMenu(ProcessesListView); ListViewMenuItems.AddRange(new ListViewMenuItem[] { new ListViewMenuItem { Title = "Close", Action = item => KillProcess(item) }, new ListViewMenuItem { Title = "Volume", Action = item => Volume(item) } }); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Id = Intent.Extras.GetInt("id"); Name = Intent.Extras.GetString("name"); Address = Intent.Extras.GetString("address"); Title = $"{Name} ({Address})"; SetContentView(Resource.Layout.FileBrowser); FileListView = FindViewById <ListView>(Resource.Id.FileBrowserListView); FileListView.Adapter = new ActivityListAdapter(this); Api = new ApiClient(Address); // Register long press FileListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { try { var item = Adapter.GetItem(e.Position) as ActivityListItem; if (item == null) { return; } var entry = (Entry)item.Tag; if (CanClick(entry.Type)) { RenderDirectory(entry.Path); } } catch (Exception er) { Toast.MakeText(this, $"Failed to enter directory.", ToastLength.Short).Show(); Log.Error(TAG, $"Failed to enter directory with error {er}."); } }; // Context menu setup. RegisterForContextMenu(FileListView); ListViewMenuItems.Add(new ListViewMenuItem { Title = "Run", ValidTypes = new EntryType[] { EntryType.File }, Action = async i => { var entry = (Entry)i.Tag; await Api.Call <Api.Responses.RunFile>(new Api.Requests.RunFile(entry.Path, null), Canceller.Token); } }); // Option menu setup. Options.AddItem("Refresh", () => { RenderLastSuccessfulPath(); }); Options.AddItem("Drives", () => { RenderDrives(); }); try { RenderLastSuccessfulPath(); } catch (Exception e) { Toast.MakeText(this, $"Failed to browse files on {Title}.", ToastLength.Short).Show(); Log.Error(TAG, $"Failed to start activity with error {e}."); Finish(); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); // Initialise the ListView content. MainListView = FindViewById <ListView>(Resource.Id.MainListView); MainListView.Adapter = new ActivityListAdapter(this); MainListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { var item = Adapter.GetItem(e.Position) as ActivityListItem; if (item == null) { return; } var server = (Server)item.Tag; // Add the ListViewItem to the Saved list. SaveServer(server); // Update ListView in case that an image has changed. UpdateListItem(item, server); Adapter.NotifyDataSetChanged(); // Send a ping for diagnostic purposes. new ApiClient(server.Address).Call <Api.Responses.Ping>(new Api.Requests.Ping($"HookshotMagic@{DateTime.Now}"), Canceller.Token) .ContinueWith(t => { if (t.IsCompleted) { Log.Info(TAG, t.Result.msg); } else { Log.Warn(TAG, $"Failed to ping {server.Address}"); } }); // Start the ServerActivity to display it. StartActivity(new Intent(this, typeof(ServerActivity)) .PutExtra("id", server.DbId.Value) .PutExtra("address", server.Address) .PutExtra("name", server.Name)); }; // Initialise item discovery. Client.Discovered += (DiscoveryClient.DiscoveredArgs args) => { RunOnUiThread(() => OnDiscovered(args)); }; Client.Run(); // Add in saved servers to ListView. foreach (var i in LoadSavedServers()) { AddToListView(i); } // Context menu setup. RegisterForContextMenu(MainListView); ListViewMenuItems.AddRange(new ListViewMenuItem[] { new ListViewMenuItem { Title = "Edit", Action = item => { ShowServerEditor((Server)item.Tag); } }, new ListViewMenuItem { Title = "Delete", Action = item => { var server = (Server)item.Tag; new Db().DeleteServer(server.ToServer()); Adapter.Items.Remove(item); Adapter.Items.Sort(Comparer); Adapter.NotifyDataSetChanged(); } }, }); // Option menu setup. Options.AddItem("Add", () => { ShowServerEditor(null); }); }