// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/screen/ScreenManager.java
// public class ScreenManager {
// 
// 	private static Screen currentScreen;
// 
// 	public static Screen createScreen(String url) {
// 		try {
// 			URL u = new URL(url);
// 			String path = u.getPath();
// 
// 			if ("/catalog.opds".equals(path)) {
// 				return new HomeScreen(new OpdsPage(url));
// 			} else if ("/authors.opds".equals(path)
// 					|| "/translators.opds".equals(path)
// 					|| "/books.opds".equals(path) || "/texts.opds".equals(path)) {
// 				return new ShortListScreen(new OpdsPage(url));
// 			} else if ("/authors/first-name.opds".equals(path)
// 					|| "/authors/last-name.opds".equals(path)
// 					|| "/translators/first-name.opds".equals(path)
// 					|| "/translators/last-name.opds".equals(path)
// 					|| "/books/alpha.opds".equals(path)
// 					|| "/texts/alpha.opds".equals(path)
// 					|| "/series.opds".equals(path)
// 					|| "/sequences.opds".equals(path)) {
// 				return new AlphaScreen(new OpdsPage(url));
// 			} else if ("/books/category.opds".equals(path)
// 					|| "/texts/label.opds".equals(path)
// 					|| "/texts/type.opds".equals(path)
// 					|| path.indexOf("/country/") != -1
// 					|| path.indexOf("/first-name/") != -1
// 					|| path.indexOf("/last-name/") != -1
// 					|| path.indexOf("/series/alpha/") != -1
// 					|| path.indexOf("/sequences/alpha/") != -1) {
// 				return new LongListScreen(new OpdsPage(url));
// 			} else if (path.indexOf("/search.json") != -1) {
// 				String query = u.getQuery();
// 				if (query.endsWith("&filter=texts")) {
// 					return new BookListScreen(new SearchTextsPage(url));
// 				} else if (query.endsWith("&filter=persons")) {
// 					return new LongListScreen(new SearchPersonsPage(url));
// 				} else if (query.endsWith("&filter=categories")) {
// 					return new LongListScreen(new SearchCategoriesPage(url));
// 				} else if (query.endsWith("&filter=sequences")) {
// 					return new LongListScreen(new SearchSequencesPage(url));
// 				} else if (query.endsWith("&filter=series")) {
// 					return new LongListScreen(new SearchSeriesPage(url));
// 				} else if (query.endsWith("&filter=labels")) {
// 					return new LongListScreen(new SearchLabelsPage(url));
// 				} else {
// 					return new ShortListScreen(new SearchOverviewPage(url));
// 				}
// 			}
// 		} catch (MalformedURLException e) {
// 			// return the default screen
// 		}
// 
// 		// default screen
// 		return new BookListScreen(new OpdsPage(url));
// 	}
// 
// 	public static void setCurrentScreen(Screen screen) {
// 		currentScreen = screen;
// 	}
// 
// 	public static Screen getCurrentScreen() {
// 		return currentScreen;
// 	}
// 
// }
// 
// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/screen/SplashScreen.java
// public class SplashScreen extends Screen {
// 
// 	public SplashScreen() {
// 		super(new NullPage());
// 	}
// 
// 	protected int getPageSize() {
// 		return 1;
// 	}
// 
// 	protected void createContent(Container container) throws IOException {
// 		GridBagConstraints c = new GridBagConstraints();
// 		c.gridx = 0;
// 		c.gridwidth = GridBagConstraints.REMAINDER;
// 		c.gridy = GridBagConstraints.RELATIVE;
// 		c.weightx = 1.0;
// 		c.weighty = 1.0;
// 
// 		KLabel label = new KLabel("Зарежда се…");
// 		container.add(label, c);
// 	}
// 
// 	protected void updateContent(Container container) {
// 		// nothing to update
// 	}
// 
// }


import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.io.IOException;
import com.amazon.kindle.kindlet.AbstractKindlet;
import com.amazon.kindle.kindlet.KindletContext;
import com.amazon.kindle.kindlet.event.KindleKeyCodes;
import name.raev.kaloyan.kindle.chitanka.screen.ScreenManager;
import name.raev.kaloyan.kindle.chitanka.screen.SplashScreen;
							if (mgr.canGoBack()) {
								key.consume();
								mgr.goBack();
								return true;
							}
							break;

						case KindleKeyCodes.VK_LEFT_HAND_SIDE_TURN_PAGE:
						case KindleKeyCodes.VK_RIGHT_HAND_SIDE_TURN_PAGE:
							key.consume();
							ScreenManager.getCurrentScreen().nextPage();
							return true;

						case KindleKeyCodes.VK_TURN_PAGE_BACK:
							key.consume();
							ScreenManager.getCurrentScreen().previousPage();
							return true;

						case VK_KEYBOARD:
							ScreenManager.getCurrentScreen().focusOnSearch();
							return true;
						}

						return false;
					}
				});
	}

	public void start() {
		try {
// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/screen/ScreenManager.java
// public class ScreenManager {
// 
// 	private static Screen currentScreen;
// 
// 	public static Screen createScreen(String url) {
// 		try {
// 			URL u = new URL(url);
// 			String path = u.getPath();
// 
// 			if ("/catalog.opds".equals(path)) {
// 				return new HomeScreen(new OpdsPage(url));
// 			} else if ("/authors.opds".equals(path)
// 					|| "/translators.opds".equals(path)
// 					|| "/books.opds".equals(path) || "/texts.opds".equals(path)) {
// 				return new ShortListScreen(new OpdsPage(url));
// 			} else if ("/authors/first-name.opds".equals(path)
// 					|| "/authors/last-name.opds".equals(path)
// 					|| "/translators/first-name.opds".equals(path)
// 					|| "/translators/last-name.opds".equals(path)
// 					|| "/books/alpha.opds".equals(path)
// 					|| "/texts/alpha.opds".equals(path)
// 					|| "/series.opds".equals(path)
// 					|| "/sequences.opds".equals(path)) {
// 				return new AlphaScreen(new OpdsPage(url));
// 			} else if ("/books/category.opds".equals(path)
// 					|| "/texts/label.opds".equals(path)
// 					|| "/texts/type.opds".equals(path)
// 					|| path.indexOf("/country/") != -1
// 					|| path.indexOf("/first-name/") != -1
// 					|| path.indexOf("/last-name/") != -1
// 					|| path.indexOf("/series/alpha/") != -1
// 					|| path.indexOf("/sequences/alpha/") != -1) {
// 				return new LongListScreen(new OpdsPage(url));
// 			} else if (path.indexOf("/search.json") != -1) {
// 				String query = u.getQuery();
// 				if (query.endsWith("&filter=texts")) {
// 					return new BookListScreen(new SearchTextsPage(url));
// 				} else if (query.endsWith("&filter=persons")) {
// 					return new LongListScreen(new SearchPersonsPage(url));
// 				} else if (query.endsWith("&filter=categories")) {
// 					return new LongListScreen(new SearchCategoriesPage(url));
// 				} else if (query.endsWith("&filter=sequences")) {
// 					return new LongListScreen(new SearchSequencesPage(url));
// 				} else if (query.endsWith("&filter=series")) {
// 					return new LongListScreen(new SearchSeriesPage(url));
// 				} else if (query.endsWith("&filter=labels")) {
// 					return new LongListScreen(new SearchLabelsPage(url));
// 				} else {
// 					return new ShortListScreen(new SearchOverviewPage(url));
// 				}
// 			}
// 		} catch (MalformedURLException e) {
// 			// return the default screen
// 		}
// 
// 		// default screen
// 		return new BookListScreen(new OpdsPage(url));
// 	}
// 
// 	public static void setCurrentScreen(Screen screen) {
// 		currentScreen = screen;
// 	}
// 
// 	public static Screen getCurrentScreen() {
// 		return currentScreen;
// 	}
// 
// }
// 
// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/screen/SplashScreen.java
// public class SplashScreen extends Screen {
// 
// 	public SplashScreen() {
// 		super(new NullPage());
// 	}
// 
// 	protected int getPageSize() {
// 		return 1;
// 	}
// 
// 	protected void createContent(Container container) throws IOException {
// 		GridBagConstraints c = new GridBagConstraints();
// 		c.gridx = 0;
// 		c.gridwidth = GridBagConstraints.REMAINDER;
// 		c.gridy = GridBagConstraints.RELATIVE;
// 		c.weightx = 1.0;
// 		c.weighty = 1.0;
// 
// 		KLabel label = new KLabel("Зарежда се…");
// 		container.add(label, c);
// 	}
// 
// 	protected void updateContent(Container container) {
// 		// nothing to update
// 	}
// 
// }


// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/ChitankaKindlet.java
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.io.IOException;
import com.amazon.kindle.kindlet.AbstractKindlet;
import com.amazon.kindle.kindlet.KindletContext;
import com.amazon.kindle.kindlet.event.KindleKeyCodes;
import name.raev.kaloyan.kindle.chitanka.screen.ScreenManager;
import name.raev.kaloyan.kindle.chitanka.screen.SplashScreen;

							if (mgr.canGoBack()) {
								key.consume();
								mgr.goBack();
								return true;
							}
							break;

						case KindleKeyCodes.VK_LEFT_HAND_SIDE_TURN_PAGE:
						case KindleKeyCodes.VK_RIGHT_HAND_SIDE_TURN_PAGE:
							key.consume();
							ScreenManager.getCurrentScreen().nextPage();
							return true;

						case KindleKeyCodes.VK_TURN_PAGE_BACK:
							key.consume();
							ScreenManager.getCurrentScreen().previousPage();
							return true;

						case VK_KEYBOARD:
							ScreenManager.getCurrentScreen().focusOnSearch();
							return true;
						}

						return false;
					}
				});
	}

	public void start() {
		try {
			new SplashScreen().display();