public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (_view != null)
            {
                ViewGroup parent = (ViewGroup)_view.Parent;
                if (parent != null)
                {
                    parent.RemoveView(_view);
                }
            }
            try
            {
                this.Log().Debug("OnCreateView");
                _view = inflater.Inflate(Resource.Layout.f_search, container, false);

                this.WireUpControls(_view, "search");

                var adapter = new ReactiveListAdapter <StockViewModel>(
                    ViewModel.Quotes,
                    (viewModel, parent) => new SearchResultItemView(viewModel, this.Activity, parent));

                ResultList.Adapter             = adapter;
                ResultList.OnItemClickListener = this;

                this.BindCommand(ViewModel, vm => vm.SearchCommand, c => c.Search);
                this.Bind(ViewModel, vm => vm.Symbol, c => c.Symbol.Text);
            }
            catch (InflateException e)
            {
                /* view is already there, just return view as it is */
            }

            return(_view);
        }
예제 #2
0
        public RemoteSongsActivity()
        {
            this.WhenActivated(() =>
            {
                var disposable = new CompositeDisposable();

                var adapter = new ReactiveListAdapter <RemoteSongViewModel>(new ReactiveList <RemoteSongViewModel>(this.ViewModel.Songs),
                                                                            (vm, parent) => new RemoteSongView(this, vm, parent));
                this.SongsList.Adapter = adapter;

                this.SongsList.Events().ItemClick.Select(x => x.Position)
                .Subscribe(x =>
                {
                    this.ViewModel.SelectedSong = this.ViewModel.Songs[x];

                    var items = new List <Tuple <string, IReactiveCommand> >();

                    if (this.ViewModel.IsAdmin)
                    {
                        items.Add(Tuple.Create(Resources.GetString(Resource.String.play), (IReactiveCommand)this.ViewModel.PlaySongsCommand));
                        items.Add(Tuple.Create(Resources.GetString(Resource.String.add_to_playlist), (IReactiveCommand)this.ViewModel.AddToPlaylistCommand));
                    }

                    else if (this.ViewModel.RemainingVotes > 0)
                    {
                        string voteString = string.Format(Resources.GetString(Resource.String.uses_vote), this.ViewModel.RemainingVotes);
                        items.Add(Tuple.Create(string.Format("{0} \n({1})", Resources.GetString(Resource.String.add_to_playlist), voteString),
                                               (IReactiveCommand)this.ViewModel.AddToPlaylistCommand));
                    }

                    else
                    {
                        items.Add(Tuple.Create(Resources.GetString(Resource.String.no_votes_left), (IReactiveCommand)null));
                    }

                    var builder = new AlertDialog.Builder(this);
                    builder.SetItems(items.Select(y => y.Item1).ToArray(), (o, eventArgs) =>
                    {
                        IReactiveCommand command = items[eventArgs.Which].Item2;

                        if (command != null)
                        {
                            command.Execute(null);
                        }
                    });
                    builder.Create().Show();
                })
                .DisposeWith(disposable);

                Observable.Merge(this.ViewModel.PlaySongsCommand.Select(_ => Resource.String.playing_songs),
                                 this.ViewModel.AddToPlaylistCommand.Select(_ => Resource.String.added_to_playlist),
                                 this.ViewModel.PlaySongsCommand.ThrownExceptions.Merge(this.ViewModel.AddToPlaylistCommand.ThrownExceptions).Select(_ => Resource.String.error_adding_song))
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x => Toast.MakeText(this, x, ToastLength.Short).Show())
                .DisposeWith(disposable);

                return(disposable);
            });
        }
예제 #3
0
        private void LoadPrimaryAdapter()
        {
            var adapter = new ReactiveListAdapter <SearchResultViewModel>(
                ViewModel.Images,
                (viewModel, parent) => new ImageItemView(viewModel, this, parent));

            ImagesList.Adapter = adapter;
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var service = new FlickrImageService();

            ViewModel = new FlickrSearchViewModel(service);

            // Load views
            SearchText   = FindViewById <EditText> (Resource.Id.searchText);
            SearchButton = FindViewById <Button>(Resource.Id.searchButton);
            ImagesList   = FindViewById <ListView> (Resource.Id.imagesList);

            // Set up bindings
            this.Bind(ViewModel, vm => vm.SearchText, v => v.SearchText.Text);
            this.OneWayBind(ViewModel, vm => vm.CanEnterSearchText, v => v.SearchText.Enabled);
            this.BindCommand(ViewModel, vm => vm.Search, v => v.SearchButton);

            // Configure list adapter
            var adapter = new ReactiveListAdapter <SearchResultViewModel>(
                ViewModel.Images,
                (viewModel, parent) => new ImageItemView(viewModel, this, parent));

            ImagesList.Adapter = adapter;

            // Set up animations
            var loadingAnimation = AnimationUtils.LoadAnimation(this, Resource.Animation.loading_rotate);

            loadingAnimation.RepeatCount = Animation.Infinite;
            loadingAnimation.RepeatMode  = RepeatMode.Restart;

            this.WhenAnyValue(v => v.ViewModel.IsLoading)
            .Subscribe(isLoading => {
                if (loadingItem != null)
                {
                    if (isLoading)
                    {
                        loadingView.StartAnimation(loadingAnimation);
                    }
                    else
                    {
                        loadingView.ClearAnimation();
                    }

                    loadingItem.SetVisible(isLoading);
                }
            });

            this.WhenAnyValue(v => v.ViewModel.ShowError)
            .Where(x => x)
            .Subscribe(showError => {
                Toast.MakeText(this, "Could not load image data", ToastLength.Long)
                .Show();
            });
        }
예제 #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.UsersLayout);
            this.WireUpControls();

            var adapter = new ReactiveListAdapter <BasicUserModel>(ViewModel.Users, (vm, parent) => null);

            List.Adapter = adapter;
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            ViewModel = new MainViewModel();

            var gridView = FindViewById <GridView>(Resource.Id.gridview);
            var adapter  = new ReactiveListAdapter <IRecipeViewModel>(ViewModel.RecipeViewModels, (viewModel, parent) => new RecipeItemView(viewModel, this, parent));

            gridView.Adapter = adapter;
        }
예제 #7
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.UsersLayout);
            this.WireUpControls();

            this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(x =>
            {
                var adapter  = new ReactiveListAdapter <BasicUserModel>(ViewModel.Users, (vm, parent) => null);
                List.Adapter = adapter;
            });
        }
예제 #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.CallHistoryView);

            this.ViewModel = new CallHistoryViewModel();

            this.callHistoryListView = FindViewById <ListView>(Resource.Id.CallHistoryListView);

            var adapter = new ReactiveListAdapter <CallHistoryItemViewModel>(this.ViewModel.CallHistoryList,
                                                                             (viewModel, parent) => new CallHistoryItemView(viewModel, this, parent));

            this.callHistoryListView.Adapter = adapter;
        }
예제 #9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.WatchList);
            ViewModel = new WatchListViewModel();

            this.WireUpControls();

            var adapter = new ReactiveListAdapter <WatchListItemViewModel>(
                ViewModel.Stocks,
                (viewModel, parent) => new WatchListItemView(viewModel, this, parent));

            WatchList.Adapter = adapter;

            this.BindCommand(ViewModel, vm => vm.OpenMarketCommand, c => c.OpenMarket);
            this.BindCommand(ViewModel, vm => vm.CloseMarketCommand, c => c.CloseMarket);
            this.BindCommand(ViewModel, vm => vm.ResetCommand, c => c.Reset);
        }
예제 #10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            this.WireUpControls();

            ViewModel = new MainViewModel();
            ViewModel.Init();
            // this.Bind(viewModel, x => x. , x => x.TheTextView.Text);
            this.OneWayBind(ViewModel, vm => vm.TheText, activity => activity.TheTextView.Text);
            var adapter = new ReactiveListAdapter <ItemViewModel>(ViewModel.Items, (model, viewGroup) =>
            {
                return(new ListItemView(model, this, viewGroup));
            });

            TheListView.Adapter = adapter;
        }
예제 #11
0
        public LocalSongsActivity()
        {
            this.WhenActivated(() =>
            {
                var disposable = new CompositeDisposable();

                var adapter = new ReactiveListAdapter <LocalSongViewModel>(new ReactiveList <LocalSongViewModel>(this.ViewModel.Songs),
                                                                           (vm, parent) => new LocalSongView(this, vm, parent));
                this.SongsList.Adapter = adapter;

                this.SongsList.Events().ItemClick
                .Subscribe(x => this.DisplayAddToPlaylistDialog <LocalSongsViewModel, LocalSongViewModel>(this, x.Position))
                .DisposeWith(disposable);

                this.ViewModel.AddToPlaylistCommand.ThrownExceptions
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ => Toast.MakeText(this, Resource.String.something_went_wrong, ToastLength.Short).Show())
                .DisposeWith(disposable);

                return(disposable);
            });
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (_view != null)
            {
                ViewGroup parent = (ViewGroup)_view.Parent;
                if (parent != null)
                {
                    parent.RemoveView(_view);
                }
            }
            try
            {
                this.Log().Debug("OnCreateView");
                _view = inflater.Inflate(Resource.Layout.f_watchlist, container, false);

                this.WireUpControls(_view, "watchList");

                var adapter = new ReactiveListAdapter <WatchListItemViewModel>(
                    ViewModel.WatchList,
                    (viewModel, parent) => new WatchListItemView(viewModel, this.Activity, parent));

                Listview.Adapter             = adapter;
                Listview.OnItemClickListener = this;

                if (_activatedSubscription == null && _deactivatedSubscription == null)
                {
                    _activatedSubscription   = Activated.Subscribe(r => this.Log().Debug("Activated"));
                    _deactivatedSubscription = Deactivated.Subscribe(r => this.Log().Debug("Deactivated"));
                }
            }
            catch (InflateException e)
            {
                /* view is already there, just return view as it is */
            }
            return(_view);
        }
예제 #13
0
        public PlaylistFragment()
        {
            this.menu = new Subject <IMenu>();

            this.WhenActivated(() =>
            {
                var disposable = new CompositeDisposable();

                Observable.Merge(this.ViewModel.PlayPlaylistSongCommand.Select(_ => Resource.String.playing_song),
                                 this.ViewModel.PlayPlaylistSongCommand.ThrownExceptions.Select(_ => Resource.String.playback_failed),
                                 this.ViewModel.LoadPlaylistCommand.ThrownExceptions.Select(_ => Resource.String.loading_playlist_failed),
                                 this.ViewModel.VoteCommand.ThrownExceptions.Select(_ => Resource.String.vote_failed),
                                 Observable.Merge(
                                     this.ViewModel.RemoveSongCommand.ThrownExceptions,
                                     this.ViewModel.MoveSongUpCommand.ThrownExceptions,
                                     this.ViewModel.MoveSongDownCommand.ThrownExceptions,
                                     this.ViewModel.PlayNextSongCommand.ThrownExceptions,
                                     this.ViewModel.PlayPreviousSongCommand.ThrownExceptions,
                                     this.ViewModel.PlayPauseCommand.ThrownExceptions).Select(_ => Resource.String.something_went_wrong))
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x => Toast.MakeText(this.Activity, x, ToastLength.Short).Show())
                .DisposeWith(disposable);

                var adapter           = new ReactiveListAdapter <PlaylistEntryViewModel>(this.ViewModel.Entries, (vm, parent) => new PlaylistEntryView(this.Activity, vm, parent));
                this.Playlist.Adapter = adapter;

                this.Playlist.Events().ItemClick.Select(x => x.Position)
                .Subscribe(x =>
                {
                    this.ViewModel.SelectedEntry = this.ViewModel.Entries[x];

                    bool hasVotesLeft = this.ViewModel.RemainingVotes > 0;
                    string voteString = hasVotesLeft ?
                                        string.Format(Resources.GetString(Resource.String.votes_and_votes_left),
                                                      Resources.GetString(Resource.String.vote).ToQuantity(this.ViewModel.RemainingVotes.Value)) :
                                        Resources.GetString(Resource.String.no_votes_left);

                    if (this.ViewModel.CanModify)
                    {
                        var builder = new AlertDialog.Builder(this.Activity);
                        builder.SetTitle(Resource.String.administrator_functions);

                        var items = new List <string>
                        {
                            Resources.GetString(Resource.String.play),
                            Resources.GetString(Resource.String.remove),
                            Resources.GetString(Resource.String.move_up),
                            Resources.GetString(Resource.String.move_down),
                        };

                        if (this.ViewModel.CanVoteOnSelectedEntry)
                        {
                            items.Add(voteString);
                        }

                        builder.SetItems(items.ToArray(), (o, eventArgs) =>
                        {
                            switch (eventArgs.Which)
                            {
                            case 0:
                                this.ViewModel.PlayPlaylistSongCommand.Execute(null);
                                break;

                            case 1:
                                this.ViewModel.RemoveSongCommand.Execute(null);
                                break;

                            case 2:
                                this.ViewModel.MoveSongUpCommand.Execute(null);
                                break;

                            case 3:
                                this.ViewModel.MoveSongDownCommand.Execute(null);
                                break;

                            case 4:
                                if (hasVotesLeft)
                                {
                                    this.ViewModel.VoteCommand.Execute(null);
                                }
                                break;
                            }
                        });
                        builder.Create().Show();
                    }

                    else if (this.ViewModel.CanVoteOnSelectedEntry)
                    {
                        var builder = new AlertDialog.Builder(this.Activity);
                        builder.SetTitle(Resource.String.guest_functions);

                        builder.SetItems(new[] { voteString }, (sender, args) =>
                        {
                            if (hasVotesLeft)
                            {
                                this.ViewModel.VoteCommand.Execute(null);
                            }
                        });
                        builder.Create().Show();
                    }
                }).DisposeWith(disposable);

                bool skipScrollEvents = false; // We use this flag to determine whether the scroll event was user or code induced
                this.WhenAnyValue(x => x.ViewModel.CurrentSong)
                .ThrottleWhenIncoming(this.Playlist.Events().ScrollStateChanged.Where(_ => !skipScrollEvents)
                                      .Where(x => x.ScrollState == ScrollState.Idle), TimeSpan.FromSeconds(10), RxApp.TaskpoolScheduler)
                .Select(entry => this.ViewModel.Entries.TakeWhile(x => x != entry).Count())
                .ObserveOn(RxApp.MainThreadScheduler)
                .SelectMany(async targetIndex =>
                {
                    var scrollFinishedAwaiter = this.Playlist.Events().ScrollStateChanged.FirstAsync(x => x.ScrollState == ScrollState.Idle).ToTask();

                    skipScrollEvents = true;
                    this.Playlist.SmoothScrollToPosition(targetIndex);

                    await scrollFinishedAwaiter;

                    skipScrollEvents = false;

                    return(Unit.Default);
                }).Subscribe();

                this.ViewModel.WhenAnyValue(x => x.CanModify).Select(x => x ? ViewStates.Visible : ViewStates.Gone)
                .BindTo(this.PlaybackControlPanel, x => x.Visibility)
                .DisposeWith(disposable);

                this.ViewModel.WhenAnyValue(x => x.TotalTime.TotalSeconds).Select(x => (int)x)
                .BindTo(this.DurationSeekBar, x => x.Max);
                this.OneWayBind(this.ViewModel, x => x.CurrentTimeSeconds, x => x.DurationSeekBar.Progress);
                this.DurationSeekBar.Events().ProgressChanged.Where(x => x.FromUser)
                .Subscribe(x => this.ViewModel.CurrentTimeSeconds = x.Progress);

                this.ViewModel.WhenAnyValue(x => x.CurrentTimeSeconds, x => TimeSpan.FromSeconds(x).FormatAdaptive())
                .BindTo(this.CurrentTimeTextView, x => x.Text);
                this.ViewModel.WhenAnyValue(x => x.TotalTime, x => x.FormatAdaptive())
                .BindTo(this.TotalTimeTextView, x => x.Text);

                this.BindCommand(this.ViewModel, x => x.PlayNextSongCommand, x => x.NextButton)
                .DisposeWith(disposable);
                this.BindCommand(this.ViewModel, x => x.PlayPreviousSongCommand, x => x.PreviousButton)
                .DisposeWith(disposable);
                this.BindCommand(this.ViewModel, x => x.PlayPauseCommand, x => x.PlayPauseButton)
                .DisposeWith(disposable);

                Func <bool, int> alphaSelector = x => x ? 255 : 100;

                // If we're setting a different background and alpha for the same button, we have to
                // do this when either of those change, or else there is a race condition where the
                // alpha is set before the background resource is changed, and therefore discarded
                this.ViewModel.WhenAnyValue(x => x.IsPlaying).Select(x => x ? Resource.Drawable.Pause : Resource.Drawable.Play)
                .CombineLatest(this.ViewModel.PlayPauseCommand.CanExecuteObservable.Select(alphaSelector), Tuple.Create)
                .Subscribe(x =>
                {
                    this.PlayPauseButton.SetBackgroundResource(x.Item1);
                    this.PlayPauseButton.Background.SetAlpha(x.Item2);
                })
                .DisposeWith(disposable);

                this.ViewModel.PlayPreviousSongCommand.CanExecuteObservable.Select(alphaSelector)
                .Subscribe(x => this.PreviousButton.Background.SetAlpha(x))
                .DisposeWith(disposable);

                this.ViewModel.PlayNextSongCommand.CanExecuteObservable.Select(alphaSelector)
                .Subscribe(x => this.NextButton.Background.SetAlpha(x))
                .DisposeWith(disposable);

                this.ViewModel.LoadPlaylistCommand.IsExecuting
                .Subscribe(x => this.ProgressSpinner.Visibility = x ? ViewStates.Visible : ViewStates.Gone)
                .DisposeWith(disposable);

                this.ViewModel.LoadPlaylistCommand.ExecuteAsync()
                .SwallowNetworkExceptions()
                .Subscribe(_ => this.Playlist.EmptyView = this.View.FindViewById(global::Android.Resource.Id.Empty))
                .DisposeWith(disposable);

                this.ViewModel.WhenAnyValue(x => x.CanModify).CombineLatest(this.menu, Tuple.Create)
                .Subscribe(x => x.Item2.FindItem(Resource.Id.ToggleVideoPlayer).SetVisible(x.Item1))
                .DisposeWith(disposable);

                return(disposable);
            });
        }