<commit_before>﻿using Playnite.Commands;
using Playnite.SDK;
using Playnite.SDK.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Playnite.FullscreenApp.ViewModels
{
    public class GameDetailsViewModel : ObservableObject, IDisposable
    {
        public class GameActionItem
        {
            public RelayCommand Command { get; set; }
            public string Title { get; set; }

            public GameActionItem(RelayCommand command, string title)
            {
                Command = command;
                Title = title;
            }
        }

        private readonly IResourceProvider resources;
        private readonly GamesEditor gamesEditor;
        private readonly FullscreenAppViewModel mainModel;

        public GamesCollectionViewEntry Game { get; set; }

        private List<GameActionItem> gameItems;
        public List<GameActionItem> GameItems
        {
            get => gameItems;
            set
            {
                gameItems = value;
                OnPropertyChanged();
            }
        }

        #region Game Commands
        public RelayCommand<object> StartGameCommand { get; private set; }
        public RelayCommand<object> InstallGameCommand { get; private set; }
        public RelayCommand<object> UninstallGameCommand { get; private set; }
        public RelayCommand<object> ToggleFavoritesCommand { get; private set; }
        public RelayCommand<object> ToggleVisibilityCommand { get; private set; }
        public RelayCommand<object> RemoveGameCommand { get; private set; }
        #endregion

        public GameDetailsViewModel(
            GamesCollectionViewEntry gameView,
            IResourceProvider resources,
            GamesEditor gamesEditor,
            FullscreenAppViewModel mainModel)
        {
            this.resources = resources;
            this.gamesEditor = gamesEditor;
            this.mainModel = mainModel;
            Game = gameView;
            Game.Game.PropertyChanged += Game_PropertyChanged;
            InitializeCommands();
            InitializeItems();
        }

        public void Dispose()
        {
            Game.Game.PropertyChanged -= Game_PropertyChanged;
        }

        private void Game_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            InitializeItems();
        }

        public void InitializeCommands()
        {
            StartGameCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.PlayGame(Game.Game);
                mainModel.GameMenuVisible = false;
            });

            InstallGameCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.InstallGame(Game.Game);
                mainModel.GameMenuVisible = false;
            });

            UninstallGameCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.UnInstallGame(Game.Game);
                mainModel.GameMenuVisible = false;
            });

            ToggleFavoritesCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.ToggleFavoriteGame(Game.Game);
                mainModel.GameMenuVisible = false;
            });

            ToggleVisibilityCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.ToggleHideGame(Game.Game);
                mainModel.GameMenuVisible = false;
            });

            RemoveGameCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.RemoveGame(Game.Game);
                mainModel.GameMenuVisible = false;
            });
        }

        public void InitializeItems()
        {
            var items = new List<GameActionItem>();
            if (Game.IsInstalled)
            {
                items.Add(new GameActionItem(StartGameCommand, resources.GetString("LOCPlayGame")));
            }
            else
            {
                items.Add(new GameActionItem(InstallGameCommand, resources.GetString("LOCInstallGame")));
            }

            items.Add(new GameActionItem(ToggleFavoritesCommand, Game.Hidden ? resources.GetString("LOCRemoveFavoriteGame") : resources.GetString("LOCFavoriteGame")));<commit_msg>Favourite option in Fullscreen mode not changing status properly<commit_after>﻿using Playnite.Commands;
using Playnite.SDK;
using Playnite.SDK.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Playnite.FullscreenApp.ViewModels
{
    public class GameDetailsViewModel : ObservableObject, IDisposable
    {
        public class GameActionItem
        {
            public RelayCommand Command { get; set; }
            public string Title { get; set; }

            public GameActionItem(RelayCommand command, string title)
            {
                Command = command;
                Title = title;
            }
        }

        private readonly IResourceProvider resources;
        private readonly GamesEditor gamesEditor;
        private readonly FullscreenAppViewModel mainModel;

        public GamesCollectionViewEntry Game { get; set; }

        private List<GameActionItem> gameItems;
        public List<GameActionItem> GameItems
        {
            get => gameItems;
            set
            {
                gameItems = value;
                OnPropertyChanged();
            }
        }

        #region Game Commands
        public RelayCommand<object> StartGameCommand { get; private set; }
        public RelayCommand<object> InstallGameCommand { get; private set; }
        public RelayCommand<object> UninstallGameCommand { get; private set; }
        public RelayCommand<object> ToggleFavoritesCommand { get; private set; }
        public RelayCommand<object> ToggleVisibilityCommand { get; private set; }
        public RelayCommand<object> RemoveGameCommand { get; private set; }
        #endregion

        public GameDetailsViewModel(
            GamesCollectionViewEntry gameView,
            IResourceProvider resources,
            GamesEditor gamesEditor,
            FullscreenAppViewModel mainModel)
        {
            this.resources = resources;
            this.gamesEditor = gamesEditor;
            this.mainModel = mainModel;
            Game = gameView;
            Game.Game.PropertyChanged += Game_PropertyChanged;
            InitializeCommands();
            InitializeItems();
        }

        public void Dispose()
        {
            Game.Game.PropertyChanged -= Game_PropertyChanged;
        }

        private void Game_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            InitializeItems();
        }

        public void InitializeCommands()
        {
            StartGameCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.PlayGame(Game.Game);
                mainModel.ToggleGameOptionsCommand.Execute(null);
            });

            InstallGameCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.InstallGame(Game.Game);
                mainModel.ToggleGameOptionsCommand.Execute(null);
            });

            UninstallGameCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.UnInstallGame(Game.Game);
                mainModel.ToggleGameOptionsCommand.Execute(null);
            });

            ToggleFavoritesCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.ToggleFavoriteGame(Game.Game);
                mainModel.ToggleGameOptionsCommand.Execute(null);
            });

            ToggleVisibilityCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.ToggleHideGame(Game.Game);
                mainModel.ToggleGameOptionsCommand.Execute(null);
            });

            RemoveGameCommand = new RelayCommand<object>((a) =>
            {
                gamesEditor.RemoveGame(Game.Game);
                mainModel.ToggleGameOptionsCommand.Execute(null);
            });
        }

        public void InitializeItems()
        {
            var items = new List<GameActionItem>();
            if (Game.IsInstalled)
            {
                items.Add(new GameActionItem(StartGameCommand, resources.GetString("LOCPlayGame")));
            }
            else
            {
                items.Add(new GameActionItem(InstallGameCommand, resources.GetString("LOCInstallGame")));
            }

            items.Add(new GameActionItem(ToggleFavoritesCommand, Game.Favorite ? resources.GetString("LOCRemoveFavoriteGame") : resources.GetString("LOCFavoriteGame")));
{'fraction_non_alphanumeric': 0.0793414885103464, 'fraction_numerical': 0.0, 'mean_word_length': 1.9247743229689067, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5759959', 'n_tokens_mistral': 2104, 'n_tokens_neox': 2056, 'n_words': 417}