adjust UI

This commit is contained in:
2021-08-10 17:17:32 +08:00
parent f8850073cd
commit 6507f7cadf
100 changed files with 3138 additions and 963 deletions

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using Gallery.Resources.UI;
using Gallery.Util.Model;
using Xamarin.Essentials;
namespace Gallery.Services
{
public class GalleryCollection : List<GalleryItem>, ICollectionChanged
{
private static GalleryCollection empty;
public static GalleryCollection Empty
{
get
{
if (empty == null)
{
empty = new GalleryCollection();
}
return empty;
}
}
public event EventHandler<CollectionChangedEventArgs> CollectionChanged;
public bool Running { get; set; }
public GalleryCollection() : base()
{
Running = true;
}
public GalleryCollection(IEnumerable<GalleryItem> gallery) : base(gallery)
{
Running = true;
}
public void AddRange(List<GalleryItem> items)
{
var e = new CollectionChangedEventArgs
{
NewStartingIndex = Count,
NewItems = items
};
base.AddRange(items);
if (MainThread.IsMainThread)
{
CollectionChanged?.Invoke(this, e);
}
else
{
MainThread.BeginInvokeOnMainThread(() => CollectionChanged?.Invoke(this, e));
}
}
}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Gallery.Services
{
public interface IDataStore<T>
{
Task<bool> AddItemAsync(T item);
Task<bool> UpdateItemAsync(T item);
Task<bool> DeleteItemAsync(string id);
Task<T> GetItemAsync(string id);
Task<IEnumerable<T>> GetItemsAsync(bool forceRefresh = false);
}
}

View File

@ -1,60 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Gallery.Models;
namespace Gallery.Services
{
public class MockDataStore : IDataStore<Item>
{
readonly List<Item> items;
public MockDataStore()
{
items = new List<Item>()
{
new Item { Id = Guid.NewGuid().ToString(), Text = "First item", Description="This is an item description." },
new Item { Id = Guid.NewGuid().ToString(), Text = "Second item", Description="This is an item description." },
new Item { Id = Guid.NewGuid().ToString(), Text = "Third item", Description="This is an item description." },
new Item { Id = Guid.NewGuid().ToString(), Text = "Fourth item", Description="This is an item description." },
new Item { Id = Guid.NewGuid().ToString(), Text = "Fifth item", Description="This is an item description." },
new Item { Id = Guid.NewGuid().ToString(), Text = "Sixth item", Description="This is an item description." }
};
}
public async Task<bool> AddItemAsync(Item item)
{
items.Add(item);
return await Task.FromResult(true);
}
public async Task<bool> UpdateItemAsync(Item item)
{
var oldItem = items.Where((Item arg) => arg.Id == item.Id).FirstOrDefault();
items.Remove(oldItem);
items.Add(item);
return await Task.FromResult(true);
}
public async Task<bool> DeleteItemAsync(string id)
{
var oldItem = items.Where((Item arg) => arg.Id == id).FirstOrDefault();
items.Remove(oldItem);
return await Task.FromResult(true);
}
public async Task<Item> GetItemAsync(string id)
{
return await Task.FromResult(items.FirstOrDefault(s => s.Id == id));
}
public async Task<IEnumerable<Item>> GetItemsAsync(bool forceRefresh = false)
{
return await Task.FromResult(items);
}
}
}