What the Parameter..? - forms

I want to ask what is the parameter content of this code
static frmMain _instance;
public frmMain(string userInfo)
{
InitializeComponent();
btnUserInfo.Text = userInfo;
//this.StyleManager = metroStyleManager1;
}
public static frmMain Instance
{
get
{
if (_instance == null)
**_instance = new frmMain(*//What's in here//*);**
return _instance;
}
}

Related

Flutter: how to run a code when user closes app?

I have the following subscription:
class CheckInternet with ChangeNotifier {
StreamSubscription<ConnectivityResult> _subscription;
bool haveInternet = false;
static CheckInternet _instance;
static CheckInternet getInstance() {
if (_instance == null) {
_instance = CheckInternet();
_instance.checkConnectivity();
}
return _instance;
}
void checkConnectivity() {
if (_subscription == null) {
_subscription = Connectivity()
.onConnectivityChanged
.listen((ConnectivityResult result) {
bool res = result == ConnectivityResult.mobile ||
result == ConnectivityResult.wifi;
setHaveInternet = res;
});
}
}
I create this subscription in my main() method and while the app is open, it is checking the internet connection. My problem is that how to make a method what will cancel the subscription when the user closes the app.
I need something like the dispose() is for widgets.

How to geocode destination point?

I am trying to navigation application on Mapbox with Unity. I can take the location of the user but i could not able to take destination point from the user. I want to take as text. If i can able to take destination point, i can plot the route easily.
I tried the reload map, but it is not useful. Also, i tried the forward geocode user input file, but i could not make it.
namespace Mapbox.Examples
{
using Mapbox.Unity;
using UnityEngine;
using UnityEngine.UI;
using System;
using Mapbox.Geocoding;
using Mapbox.Utils;
[RequireComponent(typeof(InputField))]
public class ForwardGeocodeUserInput : MonoBehaviour
{
InputField _inputField;
ForwardGeocodeResource _resource;
Vector2d _coordinate;
public Vector2d Coordinate
{
get
{
return _coordinate;
}
}
bool _hasResponse;
public bool HasResponse
{
get
{
return _hasResponse;
}
}
public ForwardGeocodeResponse Response { get; private set; }
//public event Action<> OnGeocoderResponse = delegate { };
public event Action<ForwardGeocodeResponse> OnGeocoderResponse = delegate { };
void Awake()
{
_inputField = GetComponent<InputField>();
_inputField.onEndEdit.AddListener(HandleUserInput);
_resource = new ForwardGeocodeResource("");
}
void HandleUserInput(string searchString)
{
_hasResponse = false;
if (!string.IsNullOrEmpty(searchString))
{
_resource.Query = searchString;
MapboxAccess.Instance.Geocoder.Geocode(_resource, HandleGeocoderResponse);
}
}
void HandleGeocoderResponse(ForwardGeocodeResponse res)
{
_hasResponse = true;
if (null == res)
{
_inputField.text = "no geocode response";
}
else if (null != res.Features && res.Features.Count > 0)
{
var center = res.Features[0].Center;
//_inputField.text = string.Format("{0},{1}", center.x, center.y);
_coordinate = res.Features[0].Center;
}
Response = res;
OnGeocoderResponse(res);
}
}
}
Could you help me?

use tableview as searchable input

I have this tableview that is searcheable. at this point I can fill it and on search goes to a detailview. know I want to convert this to use it as an input? but how?
I have a view with the input, and I technically have a tableview that returns the value, just not in the correct manner.
tableviewmodel:
public class CMCTableViewModel : MvxViewModel
{
protected readonly ICoinMarketCapService _coinMarketCapService;
public CMCTableViewModel(ICoinMarketCapService coinMarketCapService)
{
_coinMarketCapService = coinMarketCapService;
LoadData();
}
public MvxCommand<CoinMarketCapModel> NavigateToDetailCommand
{
get
{
return new MvxCommand<CoinMarketCapModel>(
SelectedCoin =>
{
ShowViewModel<CoinViewModel>(new { coinName = SelectedCoin.Id });
}
);
}
}
private List<CoinMarketCapModel> _coinMarketCapModelList;
private CoinMarketGlobData _CoinMarketGlobDataList;
public List<CoinMarketCapModel> CoinMarketCapModelList
{
get
{
return _coinMarketCapModelList;
}
set
{
_coinMarketCapModelList = value;
RaisePropertyChanged(() => CoinMarketCapModelList);
}
}
public CoinMarketGlobData CoinMarketGlobDatas
{
get
{
return _CoinMarketGlobDataList;
}
set
{
_CoinMarketGlobDataList = value;
RaisePropertyChanged(() => CoinMarketGlobDatas);
}
}
public async void LoadData()
{
//CoinMarketCapModelList = await _coinMarketCapService.GetCoins("20");
//CoinMarketGlobDatas = await _coinMarketCapService.GetGlobalData();
CoinMarketCapModelList = await _coinMarketCapService.GetCoins();
FilteredList = CoinMarketCapModelList;
}
private List<CoinMarketCapModel> _FilteredList;
public List<CoinMarketCapModel> FilteredList
{
get
{
return _FilteredList;
}
set
{
_FilteredList = value;
RaisePropertyChanged(() => FilteredList);
}
}
public void SearchByText(string text)
{
if (string.IsNullOrWhiteSpace(text))
FilteredList = CoinMarketCapModelList;
else
{
FilteredList = CoinMarketCapModelList;
FilteredList = FilteredList.Where(m => m.Name.ToLowerInvariant().Contains(text.ToLowerInvariant())).ToList();
}
}
/// <summary>
/// Gets or sets the subtitle for the base model
/// </summary>
}
View:
[MvxFromStoryboard(StoryboardName = "Main")]
public partial class CMCTableView : MvxTableViewController<CMCTableViewModel>
{
bool useRefreshControl = false;
//private UIRefreshControl refreshControl;
private MvxUIRefreshControl refreshControl;
private void refreshTable(object sender, EventArgs e)
{
refreshControl.EndRefreshing();
TableView.ReloadData();
}
public CMCTableView (IntPtr handle) : base (handle)
{
}
UISearchBar _searchBar;
CMCTableViewSource _cmcTableViewSource;
public override void ViewDidLoad()
{
refreshControl = new MvxUIRefreshControl();
refreshControl.ValueChanged += refreshTable;
TableView.AddSubview(refreshControl);
_cmcTableViewSource = new CMCTableViewSource(this.TableView);
base.ViewDidLoad();
this.TableView.Source = _cmcTableViewSource;
this.TableView.ReloadData();
//BEGIN initialize searchbar
var searchController = new UISearchController(searchResultsController: null);
searchController.SearchBar.SizeToFit();
searchController.SearchBar.SearchBarStyle = UISearchBarStyle.Minimal;
searchController.SearchBar.Placeholder = "Select a currency";
searchController.DimsBackgroundDuringPresentation = false;
NavigationItem.HidesSearchBarWhenScrolling = false;
NavigationItem.SearchController = searchController;
_searchBar = searchController.SearchBar;
_searchBar.SearchButtonClicked += SearchBar_SearchButtonClicked;
_searchBar.TextChanged += SearchBarOnTextChanged;
_searchBar.CancelButtonClicked += SearchBarOnCancelButtonClicked;
// END initialize searchbar
MvxFluentBindingDescriptionSet<CMCTableView, CMCTableViewModel> set = new MvxFluentBindingDescriptionSet<CMCTableView, CMCTableViewModel>(this);
set.Bind(_cmcTableViewSource).To(vm => vm.FilteredList);
set.Bind(_cmcTableViewSource)
.For(src => src.SelectionChangedCommand)
.To(vm => vm.NavigateToDetailCommand);
set.Apply();
}
private void SearchBarOnCancelButtonClicked(object sender, EventArgs eventArgs)
{
((CMCTableViewModel)ViewModel).SearchByText(string.Empty);
BeginInvokeOnMainThread(() => _searchBar.ResignFirstResponder());
}
//public override void ViewWillAppear(bool animated)
//{
// base.ViewWillAppear(animated);
// NavigationController.NavigationBarHidden = false;
//}
private void SearchBarOnTextChanged(object sender, UISearchBarTextChangedEventArgs e)
{
if (string.IsNullOrWhiteSpace(_searchBar.Text))
{
((CMCTableViewModel)ViewModel).SearchByText(string.Empty);
BeginInvokeOnMainThread(() => _searchBar.ResignFirstResponder());
}
else
{
((CMCTableViewModel)ViewModel).SearchByText(_searchBar.Text);
}
}
private void SearchBar_SearchButtonClicked(object sender, EventArgs e)
{
((CMCTableViewModel)ViewModel).SearchByText(_searchBar.Text);
BeginInvokeOnMainThread(() => _searchBar.ResignFirstResponder());
}
}
i used a button as input that goes to the tableview, on selection i store the needed data(id and name in this case) in a static model. then i return to the parentview.
model:
public class addUserCoinHelperModel
{
public static string coinID { get; set; }
public static string name { get; set; }
public static string Amount { get; set; }
}
on selection in viewmodel:
public MvxCommand<CoinMarketCapModel> NavigateToDetailCommand
{
get
{
return new MvxCommand<CoinMarketCapModel>(
SelectedCoin =>
{
addUserCoinHelperModel.coinID = SelectedCoin.Id;
addUserCoinHelperModel.name = SelectedCoin.Name;
ShowViewModel<AddUserCoinViewModel>();
//ShowViewModel<CoinViewModel>(new { coinName = SelectedCoin.Id });
}
);
}
}
in the view in the viewdidload:
if (addUserCoinHelperModel.coinID != null){
btnPickCoin.SetTitle(addUserCoinHelperModel.name, UIControlState.Normal);
}

Swift: class and properties - all only initialized once

I'm looking to have a class or struct (does not matter) with properties, where everything may only be initialized once in the app. Any attempt to modify the class or its properties will fail or not be possible.
Is this possible?
I've come up with this so far:
public struct ScreenInfo
{
static var scaleFactor:Int = 0
public init(initialScaleFactor:Int)
{
if (ScreenInfo.scaleFactor == 0) {
ScreenInfo.scaleFactor = initialScaleFactor
}
}
public static func getScaleFactor()
-> Int
{
return scaleFactor
}
}
let si1:ScreenInfo = ScreenInfo(initialScaleFactor:11)
ScreenInfo.getScaleFactor() // = 11
let si2:ScreenInfo = ScreenInfo(initialScaleFactor:22)
ScreenInfo.getScaleFactor() // = 11
What you want is somewhat unusual, but it is possible.
public struct ScreenInfo {
private static var _scaleFactor: Int?
public static var scaleFactor: Int? {
set {
if _scaleFactor == nil {
_scaleFactor = newValue
} else {
// Optionally throw an exception or something
}
}
get {
return _scaleFactor
}
}
}
ScreenInfo.scaleFactor // nil
ScreenInfo.scaleFactor = 5
ScreenInfo.scaleFactor // 5
ScreenInfo.scaleFactor = 15
ScreenInfo.scaleFactor // 5

MVVMCross iOS: How to trigger RowSelected on a Custom TableViewSource using CreateBindingSet?

My question is for MVVMCross in iOS. I have a custom TableView and a detailView. How can I bind my "showDetailCommand", so when user click on one of the rows on TableView with trigger RowSelected to switch to detailViewModel?
Here is my code structure:
public class SearchResultsViewModel: MvxViewModel
{
private MvxCommand _showDetailCommand;
public IMvxCommand ShowDetailCommand
{
get
{
_showDetailCommand = _showDetailCommand ?? new MvxCommand(ShowDetailCommandHandler);
return _showMapCommand;
}
}
private void ShowDetailCommandHandler()
{
ShowViewModel<ResultDetailViewModel>(new
{
city = _filter.City,
state = _filter.State,
interstate = _filter.Interstate,
travelPlaza = _filter.SearchTravelPlaza,
hasCatScale = _filter.HasCatScale,
hasWashoutExpress = _filter.HasWashoutExpress,
hasUndercarriage = _filter.HasUndercarriage,
nearest = _nearest
});
}
}
[Register("SearchResults")]
public class SearchResultsView : MvxTableViewController
{
public override void ViewDidLoad()
{
Title = "List";
base.ViewDidLoad();
var source = new TableViewSource(TableView);
var bindings = this.CreateBindingSet<SearchResultsView, SearchResultsViewModel>();
bindings.Bind(source).To(vm => vm.Items);
bindings.Apply();
TableView.BackgroundColor = UIColor.Clear;
TableView.ShowsVerticalScrollIndicator = false;
TableView.ScrollEnabled = true;
TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
TableView.Source = source;
TableView.ReloadData();
}
public class TableViewSource : MvxTableViewSource
{
public TableViewSource(UITableView tableView)
: base(tableView)
{
tableView.RegisterClassForCellReuse(typeof(TableViewCell), TableViewCell.CellIdentifier);
}
public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
var item = GetItemAt(indexPath);
return TableViewCell.CellHeight(item);
}
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
var cell = tableView.DequeueReusableCell(TableViewCell.CellIdentifier) ?? new TableViewCell();
return cell;
}
}
}
[Register("TableViewCell")]
public class TableViewCell : MvxTableViewCell
{
public static readonly NSString CellIdentifier = new NSString("TableViewCell");
public TableViewCell()
: base()
{
Initialise();
}
public TableViewCell(IntPtr handle)
: base(handle)
{
Initialise();
}
private void Initialise()
{
var titleLabel = new UILabel(new RectangleF(10, 2, 200, 25));
Add(titleLabel);
this.DelayBind(() =>
{
var bindings = this.CreateBindingSet<TableViewCell, SearchResultsItemViewModel>();
bindings.Bind(titleLabel).For(x => x.Text).To(vm => vm.Name);
bindings.Bind(??).For(x => x.SelectionChangeCommand).To(vm => vm.showDetailCommand); // what should be in this line ??
bindings.Apply();
});
}
}
You can bind a view model command to the SelectionChangedCommand on the table source.
This technique is demonstrated in several samples - e.g
N=27 http://www.youtube.com/watch?v=h0Eww89c9DM&feature=youtu.be&t=47m30s
https://github.com/slodge/MvvmCross-Tutorials/tree/master/DailyDilbert
// command
new Cirrious.MvvmCross.ViewModels.MvxCommand<DilbertItem>((dilbertItem) =>
{
// note that we can only pass an id here - do *not* serialiase the whole dilbertItem
ShowViewModel<DilbertDetailViewModel>(new { id = dilbertItem.Id });
});
// binding
set.Bind(source)
.For(s => s.SelectionChangedCommand)
.To(s => s.ShowDetailCommand);
Alternatively, you can also put commands inside your list items and can then bind within each cell to a SelectedCommand (or some other custom event within your cell).
For examples of this, look at some of the samples which have menus - e.g. the ValueConversion sample