コード例 #1
0
        void SavedListView_ItemTapped(System.Object sender, Xamarin.Forms.ItemTappedEventArgs e)
        {
            var context = e.Item as TransportData;
            var details = new LikedCity();

            details.name    = context.weatherData.name;
            details.country = context.weatherData.sys.country;

            var x_ = ThreadAction.likedCities.Find(x => x.name == details.name);

            ThreadAction.likedCities.Remove(x_);
            TransportPop(details.name);

            string fileName = "citylikedlist.json";
            var    path     = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var    filename = Path.Combine(path, fileName);

            string data = JsonConvert.SerializeObject(ThreadAction.likedCities);

            File.WriteAllText(filename, data);
        }
コード例 #2
0
        void CityListView_ItemTapped(System.Object sender, Xamarin.Forms.ItemTappedEventArgs e)
        {
            var context = e.Item as City;
            var details = new LikedCity();

            details.name    = context.name;
            details.country = context.country;

            bool isContains = false;

            if (ThreadAction.likedCities.Count != 0)
            {
                foreach (var city in ThreadAction.likedCities)
                {
                    if (city.name == details.name && city.country == details.country)
                    {
                        isContains = true;
                    }
                }
            }

            if (!isContains)
            {
                ThreadAction.likedCities.Add(details);
                TransportPush($"{details.name}, {details.country}");

                string fileName = "citylikedlist.json";
                var    path     = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                var    filename = Path.Combine(path, fileName);

                string data = JsonConvert.SerializeObject(ThreadAction.likedCities);
                File.WriteAllText(filename, data);
            }

            Navigation.PushAsync(new MainPage());
        }