Skip to content

Commit

Permalink
UI redesign; fiction and scimag support
Browse files Browse the repository at this point in the history
  • Loading branch information
libgenapps committed Dec 31, 2017
1 parent 2149779 commit 2970cbe
Show file tree
Hide file tree
Showing 112 changed files with 7,590 additions and 1,488 deletions.
2 changes: 2 additions & 0 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Red.xaml" />
<ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/materialdesign.xaml"/>
<ResourceDictionary Source="Views\Styles\CommonStyles.xaml" />
<ResourceDictionary Source="Views\Styles\TabControlStyles.xaml" />
<ResourceDictionary Source="Views\Styles\WindowStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down
37 changes: 34 additions & 3 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Windows;
using LibgenDesktop.Infrastructure;
using LibgenDesktop.Models;
using LibgenDesktop.ViewModels;

namespace LibgenDesktop
{
Expand All @@ -8,9 +10,38 @@ public partial class App : Application
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
IWindowContext mainWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.MAIN_WINDOW);
mainWindowContext.Closed += (sender, args) => Shutdown();
mainWindowContext.Show();
MainModel mainModel = new MainModel();
if (mainModel.LocalDatabaseStatus == MainModel.DatabaseStatus.OPENED)
{
ShowMainWindow(mainModel);
}
else
{
ShowCreateDatabaseWindow(mainModel);
}
}

private void ShowMainWindow(MainModel mainModel)
{
MainWindowViewModel mainWindowViewModel = new MainWindowViewModel(mainModel);
IWindowContext windowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.MAIN_WINDOW, mainWindowViewModel);
windowContext.Closed += (sender, args) => Shutdown();
windowContext.Show();
}

private void ShowCreateDatabaseWindow(MainModel mainModel)
{
CreateDatabaseViewModel createDatabaseViewModel = new CreateDatabaseViewModel(mainModel);
IWindowContext windowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.CREATE_DATABASE_WINDOW, createDatabaseViewModel);
bool? result = windowContext.ShowDialog();
if (result == true)
{
ShowMainWindow(mainModel);
}
else
{
Shutdown();
}
}
}
}
95 changes: 72 additions & 23 deletions Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,88 @@
{
internal static class Constants
{
public const string CURRENT_DATABASE_VERSION = "0.7";

public const int MAIN_WINDOW_MIN_WIDTH = 1000;
public const int MAIN_WINDOW_MIN_HEIGHT = 500;
public const int BOOK_WINDOW_MIN_WIDTH = 1000;
public const int BOOK_WINDOW_MIN_HEIGHT = 500;
public const int NON_FICTION_DETAILS_WINDOW_MIN_WIDTH = 1000;
public const int NON_FICTION_DETAILS_WINDOW_MIN_HEIGHT = 500;
public const int NON_FICTION_GRID_TITLE_COLUMN_MIN_WIDTH = 150;
public const int NON_FICTION_GRID_AUTHORS_COLUMN_MIN_WIDTH = 150;
public const int NON_FICTION_GRID_SERIES_COLUMN_MIN_WIDTH = 150;
public const int NON_FICTION_GRID_YEAR_COLUMN_MIN_WIDTH = 60;
public const int NON_FICTION_GRID_PUBLISHER_COLUMN_MIN_WIDTH = 150;
public const int NON_FICTION_GRID_FORMAT_COLUMN_MIN_WIDTH = 80;
public const int NON_FICTION_GRID_FILESIZE_COLUMN_MIN_WIDTH = 130;
public const int NON_FICTION_GRID_OCR_COLUMN_MIN_WIDTH = 55;
public const int FICTION_DETAILS_WINDOW_MIN_WIDTH = 600;
public const int FICTION_DETAILS_WINDOW_MIN_HEIGHT = 500;
public const int FICTION_GRID_TITLE_COLUMN_MIN_WIDTH = 150;
public const int FICTION_GRID_AUTHORS_COLUMN_MIN_WIDTH = 150;
public const int FICTION_GRID_SERIES_COLUMN_MIN_WIDTH = 150;
public const int FICTION_GRID_YEAR_COLUMN_MIN_WIDTH = 60;
public const int FICTION_GRID_PUBLISHER_COLUMN_MIN_WIDTH = 150;
public const int FICTION_GRID_FORMAT_COLUMN_MIN_WIDTH = 80;
public const int FICTION_GRID_FILESIZE_COLUMN_MIN_WIDTH = 130;
public const int SCI_MAG_DETAILS_WINDOW_MIN_WIDTH = 600;
public const int SCI_MAG_DETAILS_WINDOW_MIN_HEIGHT = 500;
public const int SCI_MAG_GRID_TITLE_COLUMN_MIN_WIDTH = 150;
public const int SCI_MAG_GRID_AUTHORS_COLUMN_MIN_WIDTH = 150;
public const int SCI_MAG_GRID_JOURNAL_COLUMN_MIN_WIDTH = 100;
public const int SCI_MAG_GRID_YEAR_COLUMN_MIN_WIDTH = 60;
public const int SCI_MAG_GRID_FILESIZE_COLUMN_MIN_WIDTH = 130;
public const int SCI_MAG_GRID_DOI_COLUMN_MIN_WIDTH = 150;
public const int ERROR_WINDOW_DEFAULT_WIDTH = 620;
public const int ERROR_WINDOW_DEFAULT_HEIGHT = 450;
public const int ERROR_WINDOW_MIN_WIDTH = 400;
public const int ERROR_WINDOW_MIN_HEIGHT = 300;
public const int TITLE_COLUMN_MIN_WIDTH = 150;
public const int AUTHORS_COLUMN_MIN_WIDTH = 150;
public const int SERIES_COLUMN_MIN_WIDTH = 150;
public const int YEAR_COLUMN_MIN_WIDTH = 60;
public const int PUBLISHER_COLUMN_MIN_WIDTH = 150;
public const int FORMAT_COLUMN_MIN_WIDTH = 80;
public const int FILESIZE_COLUMN_MIN_WIDTH = 130;
public const int OCR_COLUMN_MIN_WIDTH = 55;
public const int IMPORT_WINDOW_MIN_WIDTH = 500;
public const int IMPORT_WINDOW_MIN_HEIGHT = 400;
public const int CREATE_DATABASE_WINDOW_WIDTH = 500;
public const int SETTINGS_WINDOW_DEFAULT_WIDTH = 700;
public const int SETTINGS_WINDOW_DEFAULT_HEIGHT = 450;
public const int SETTINGS_WINDOW_MIN_WIDTH = 650;
public const int SETTINGS_WINDOW_MIN_HEIGHT = 450;

public const string DEFAULT_DATABASE_FILE_NAME = "libgen.db";
public const int DEFAULT_MAIN_WINDOW_WIDTH = 1200;
public const int DEFAULT_MAIN_WINDOW_WIDTH = 1000;
public const int DEFAULT_MAIN_WINDOW_HEIGHT = 650;
public const int DEFAULT_BOOK_WINDOW_WIDTH = 1200;
public const int DEFAULT_BOOK_WINDOW_HEIGHT = 618;
public const int DEFAULT_TITLE_COLUMN_WIDTH = 200;
public const int DEFAULT_AUTHORS_COLUMN_WIDTH = 200;
public const int DEFAULT_SERIES_COLUMN_WIDTH = 180;
public const int DEFAULT_YEAR_COLUMN_WIDTH = 60;
public const int DEFAULT_PUBLISHER_COLUMN_WIDTH = 180;
public const int DEFAULT_FORMAT_COLUMN_WIDTH = 100;
public const int DEFAULT_FILESIZE_COLUMN_WIDTH = 150;
public const int DEFAULT_OCR_COLUMN_WIDTH = 55;
public const int DEFAULT_NON_FICTION_DETAILS_WINDOW_WIDTH = 1200;
public const int DEFAULT_NON_FICTION_DETAILS_WINDOW_HEIGHT = 618;
public const int DEFAULT_NON_FICTION_GRID_TITLE_COLUMN_WIDTH = 200;
public const int DEFAULT_NON_FICTION_GRID_AUTHORS_COLUMN_WIDTH = 200;
public const int DEFAULT_NON_FICTION_GRID_SERIES_COLUMN_WIDTH = 180;
public const int DEFAULT_NON_FICTION_GRID_YEAR_COLUMN_WIDTH = 60;
public const int DEFAULT_NON_FICTION_GRID_PUBLISHER_COLUMN_WIDTH = 180;
public const int DEFAULT_NON_FICTION_GRID_FORMAT_COLUMN_WIDTH = 100;
public const int DEFAULT_NON_FICTION_GRID_FILESIZE_COLUMN_WIDTH = 150;
public const int DEFAULT_NON_FICTION_GRID_OCR_COLUMN_WIDTH = 55;
public const int DEFAULT_FICTION_DETAILS_WINDOW_WIDTH = 850;
public const int DEFAULT_FICTION_DETAILS_WINDOW_HEIGHT = 650;
public const int DEFAULT_FICTION_GRID_TITLE_COLUMN_WIDTH = 200;
public const int DEFAULT_FICTION_GRID_AUTHORS_COLUMN_WIDTH = 200;
public const int DEFAULT_FICTION_GRID_SERIES_COLUMN_WIDTH = 180;
public const int DEFAULT_FICTION_GRID_YEAR_COLUMN_WIDTH = 60;
public const int DEFAULT_FICTION_GRID_PUBLISHER_COLUMN_WIDTH = 180;
public const int DEFAULT_FICTION_GRID_FORMAT_COLUMN_WIDTH = 100;
public const int DEFAULT_FICTION_GRID_FILESIZE_COLUMN_WIDTH = 150;
public const int DEFAULT_SCI_MAG_DETAILS_WINDOW_WIDTH = 910;
public const int DEFAULT_SCI_MAG_DETAILS_WINDOW_HEIGHT = 680;
public const int DEFAULT_SCI_MAG_GRID_TITLE_COLUMN_WIDTH = 270;
public const int DEFAULT_SCI_MAG_GRID_AUTHORS_COLUMN_WIDTH = 200;
public const int DEFAULT_SCI_MAG_GRID_JOURNAL_COLUMN_WIDTH = 120;
public const int DEFAULT_SCI_MAG_GRID_YEAR_COLUMN_WIDTH = 60;
public const int DEFAULT_SCI_MAG_GRID_FILESIZE_COLUMN_WIDTH = 150;
public const int DEFAULT_SCI_MAG_GRID_DOI_COLUMN_WIDTH = 290;
public const int DEFAULT_MAXIMUM_SEARCH_RESULT_COUNT = 50000;

public const int SEARCH_REPORT_PROGRESS_BATCH_SIZE = 2000;
public const int INSERT_TRANSACTION_BATCH = 500;

public const string BOOK_COVER_URL_PREFIX = "http://libgen.io/covers/";
public const string BOOK_DOWNLOAD_URL_PREFIX = "http://libgen.io/book/index.php?md5=";
public const string NON_FICTION_COVER_URL_PREFIX = "http://libgen.io/covers/";
public const string NON_FICTION_DOWNLOAD_URL_PREFIX = "http://libgen.io/book/index.php?md5=";
public const string FICTION_COVER_URL_PREFIX = "http://libgen.io/fictioncovers/";
public const string FICTION_DOWNLOAD_URL_PREFIX = "http://libgen.io/foreignfiction/ads.php?md5=";
public const string SCI_MAG_DOWNLOAD_URL_PREFIX = "http://libgen.io/scimag/ads.php?doi=";
}
}
47 changes: 47 additions & 0 deletions Infrastructure/EventProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace LibgenDesktop.Infrastructure
{
public class EventProvider
{
private readonly Queue<ViewModelEvent> eventQueue;
private IEventListener eventListener;

public EventProvider()
{
eventQueue = new Queue<ViewModelEvent>();
eventListener = null;
}

public void SetEventListener(IEventListener eventListener)
{
this.eventListener = eventListener;
PassEvents();
}

public void RaiseEvent(ViewModelEvent viewModelEvent)
{
eventQueue.Enqueue(viewModelEvent);
PassEvents();
}

public void RaiseEvent(ViewModelEvent.RegisteredEventId eventId)
{
RaiseEvent(new ViewModelEvent(eventId));
}

private void PassEvents()
{
if (eventListener != null)
{
while (eventQueue.Any())
{
ViewModelEvent viewModelEvent = eventQueue.Dequeue();
eventListener.OnViewModelEvent(viewModelEvent);
}
}
}
}
}
7 changes: 7 additions & 0 deletions Infrastructure/IEventListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace LibgenDesktop.Infrastructure
{
public interface IEventListener
{
void OnViewModelEvent(ViewModelEvent viewModelEvent);
}
}
2 changes: 1 addition & 1 deletion Infrastructure/OpenFileDialogResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LibgenDesktop.Infrastructure
{
public class OpenFileDialogResult
internal class OpenFileDialogResult
{
public bool DialogResult { get; set; }
public List<string> SelectedFilePaths { get; set; }
Expand Down
29 changes: 20 additions & 9 deletions Infrastructure/RegisteredWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ internal static class RegisteredWindows
internal enum WindowKey
{
MAIN_WINDOW = 1,
BOOK_DETAILS_WINDOW,
NON_FICTION_DETAILS_WINDOW,
FICTION_DETAILS_WINDOW,
SCI_MAG_DETAILS_WINDOW,
ERROR_WINDOW,
SQL_DUMP_IMPORT_WINDOW
IMPORT_WINDOW,
CREATE_DATABASE_WINDOW,
SETTINGS_WINDOW
}

internal class RegisteredWindow
Expand All @@ -31,15 +35,22 @@ public RegisteredWindow(WindowKey windowKey, Type windowType, Type viewModelType

static RegisteredWindows()
{
AllWindows = new Dictionary<WindowKey, RegisteredWindow>
{
{ WindowKey.MAIN_WINDOW, new RegisteredWindow(WindowKey.MAIN_WINDOW, typeof(MainWindow), typeof(MainWindowViewModel)) },
{ WindowKey.BOOK_DETAILS_WINDOW, new RegisteredWindow(WindowKey.BOOK_DETAILS_WINDOW, typeof(BookDetailsWindow), typeof(BookDetailsWindowViewModel)) },
{ WindowKey.ERROR_WINDOW, new RegisteredWindow(WindowKey.ERROR_WINDOW, typeof(ErrorWindow), typeof(ErrorWindowViewModel)) },
{ WindowKey.SQL_DUMP_IMPORT_WINDOW, new RegisteredWindow(WindowKey.SQL_DUMP_IMPORT_WINDOW, typeof(SqlDumpImportWindow), typeof(SqlDumpImportWindowViewModel)) }
};
AllWindows = new Dictionary<WindowKey, RegisteredWindow>();
RegisterWindow(WindowKey.MAIN_WINDOW, typeof(MainWindow), typeof(MainWindowViewModel));
RegisterWindow(WindowKey.NON_FICTION_DETAILS_WINDOW, typeof(NonFictionDetailsWindow), typeof(NonFictionDetailsWindowViewModel));
RegisterWindow(WindowKey.FICTION_DETAILS_WINDOW, typeof(FictionDetailsWindow), typeof(FictionDetailsWindowViewModel));
RegisterWindow(WindowKey.SCI_MAG_DETAILS_WINDOW, typeof(SciMagDetailsWindow), typeof(SciMagDetailsWindowViewModel));
RegisterWindow(WindowKey.ERROR_WINDOW, typeof(ErrorWindow), typeof(ErrorWindowViewModel));
RegisterWindow(WindowKey.IMPORT_WINDOW, typeof(ImportWindow), typeof(ImportWindowViewModel));
RegisterWindow(WindowKey.CREATE_DATABASE_WINDOW, typeof(CreateDatabaseWindow), typeof(CreateDatabaseViewModel));
RegisterWindow(WindowKey.SETTINGS_WINDOW, typeof(SettingsWindow), typeof(SettingsWindowViewModel));
}

public static Dictionary<WindowKey, RegisteredWindow> AllWindows { get; }

private static void RegisterWindow(WindowKey windowKey, Type windowType, Type viewModelType)
{
AllWindows.Add(windowKey, new RegisteredWindow(windowKey, windowType, viewModelType));
}
}
}
11 changes: 11 additions & 0 deletions Infrastructure/SaveFileDialogParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace LibgenDesktop.Infrastructure
{
internal class SaveFileDialogParameters
{
public string DialogTitle { get; set; }
public string Filter { get; set; }
public bool OverwritePrompt { get; set; }
public string InitialDirectory { get; set; }
public string InitialFileName { get; set; }
}
}
8 changes: 8 additions & 0 deletions Infrastructure/SaveFileDialogResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace LibgenDesktop.Infrastructure
{
internal class SaveFileDialogResult
{
public bool DialogResult { get; set; }
public string SelectedFilePath { get; set; }
}
}
17 changes: 17 additions & 0 deletions Infrastructure/ViewModelEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace LibgenDesktop.Infrastructure
{
public class ViewModelEvent
{
public enum RegisteredEventId
{
FOCUS_SEARCH_TEXT_BOX = 1
}

public ViewModelEvent(RegisteredEventId eventId)
{
EventId = eventId;
}

public RegisteredEventId EventId { get; }
}
}
11 changes: 7 additions & 4 deletions Infrastructure/WindowContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public void Show(bool showMaximized = false)
Window.Owner = parentWindow;
Window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
}
return ShowDialog(showMaximized, true);
else
{
Window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
return ShowDialog(showMaximized, parentWindow == null);
}

public void Close()
Expand Down Expand Up @@ -102,10 +106,9 @@ protected virtual void OnClosed()
Closed?.Invoke(this, EventArgs.Empty);
}

private bool? ShowDialog(bool showMaximized, bool hasOwner)
private bool? ShowDialog(bool showMaximized, bool showInTaskbar)
{
Window.WindowStartupLocation = hasOwner ? WindowStartupLocation.CenterOwner : WindowStartupLocation.CenterScreen;
Window.ShowInTaskbar = false;
Window.ShowInTaskbar = showInTaskbar;
Window.WindowState = GetWindowState(showMaximized);
return Window.ShowDialog();
}
Expand Down
Loading

0 comments on commit 2970cbe

Please sign in to comment.