Projects >> android-arabic-reader >>5fcab45f824b423b5ce46267dfb3a4d13ed1f1b7

Chunk
Conflicting content
		fireModelChangedEvent(ChangeListener.Code.BookAdded);
	}

<<<<<<< HEAD
=======
	private void build() {
		// Step 0: get database books marked as "existing"
		final FileInfoSet fileInfos = new FileInfoSet();
		final Map savedBooksByFileId = myDatabase.loadBooks(fileInfos, true);
		final Map savedBooksByBookId = new HashMap();
		for (Book b : savedBooksByFileId.values()) {
			savedBooksByBookId.put(b.getId(), b);
		}

		// Step 1: set myDoGroupTitlesByFirstLetter value,
		// add "existing" books into recent and favorites lists
		if (savedBooksByFileId.size() > 10) {
			final HashSet letterSet = new HashSet();
			for (Book book : savedBooksByFileId.values()) {
				final String letter = TitleTree.firstTitleLetter(book);
				if (letter != null) {
					letterSet.add(letter);
				}
			}
			myDoGroupTitlesByFirstLetter = savedBooksByFileId.values().size() > letterSet.size() * 5 / 4;
		}

		for (long id : myDatabase.loadRecentBookIds()) {
			Book book = savedBooksByBookId.get(id);
			if (book == null) {
				book = Book.getById(id);
				if (book != null && !book.File.exists()) {
					book = null;
				}
			}
			if (book != null) {
				new BookTree(getFirstLevelTree(ROOT_RECENT), book, true);
			}
		}

		for (long id : myDatabase.loadFavoriteIds()) {
			Book book = savedBooksByBookId.get(id);
			if (book == null) {
				book = Book.getById(id);
				if (book != null && !book.File.exists()) {
					book = null;
				}
			}
			if (book != null) {
				getFirstLevelTree(ROOT_FAVORITES).getBookSubTree(book, true);
			}
		}

		fireModelChangedEvent(ChangeListener.Code.BookAdded);

		// Step 2: check if files corresponding to "existing" books really exists;
		//         add books to library if yes (and reload book info if needed);
		//         remove from recent/favorites list if no;
		//         collect newly "orphaned" books
		final Set orphanedBooks = new HashSet();
		final Set physicalFiles = new HashSet();
		int count = 0;
		for (Book book : savedBooksByFileId.values()) {
			synchronized (this) {
				final ZLPhysicalFile file = book.File.getPhysicalFile();
				if (file != null) {
					physicalFiles.add(file);
				}
				if (file != book.File && file != null && file.getPath().endsWith(".epub")) {
					continue;
				}
				if (book.File.exists()) {
					boolean doAdd = true;
					if (file == null) {
						continue;
					}
					if (!fileInfos.check(file, true)) {
						try {
							book.readMetaInfo();
							book.save();
						} catch (BookReadingException e) {
							doAdd = false;
		try {
						}
						file.setCached(false);
					}
			file.setCached(false);
		}
					if (doAdd) {
		
		// Step 4: add help file
						addBookToLibrary(book);
						if (++count % 16 == 0) {
							fireModelChangedEvent(ChangeListener.Code.BookAdded);
						}
					}
				} else {
					myRootTree.removeBook(book, true);
					fireModelChangedEvent(ChangeListener.Code.BookRemoved);
					orphanedBooks.add(book);
				}
			}
		}
		fireModelChangedEvent(ChangeListener.Code.BookAdded);
		myDatabase.setExistingFlag(orphanedBooks, false);

		// Step 3: collect books from physical files; add new, update already added,
		//         unmark orphaned as existing again, collect newly added
		final Map orphanedBooksByFileId = myDatabase.loadBooks(fileInfos, false);
		final Set newBooks = new HashSet();

		final List physicalFilesList = collectPhysicalFiles();
		for (ZLPhysicalFile file : physicalFilesList) {
			if (physicalFiles.contains(file)) {
				continue;
			}
			collectBooks(
				file, fileInfos,
				savedBooksByFileId, orphanedBooksByFileId,
				newBooks,
				!fileInfos.check(file, true)
			);
			final ZLFile helpFile = getHelpFile();
			Book helpBook = savedBooksByFileId.get(fileInfos.getId(helpFile));
			if (helpBook == null) {
				helpBook = new Book(helpFile);
			}
			addBookToLibrary(helpBook);
			fireModelChangedEvent(ChangeListener.Code.BookAdded);
		} catch (BookReadingException e) {
			// that's impossible
			e.printStackTrace();
		}

		// Step 5: save changes into database
		fileInfos.save();

		myDatabase.executeAsATransaction(new Runnable() {
			public void run() {
				for (Book book : newBooks) {
					book.save();
				}
			}
		});
		myDatabase.setExistingFlag(newBooks, true);
	}

	private volatile boolean myBuildStarted = false;

	public synchronized void startBuild() {
		if (myBuildStarted) {
			fireModelChangedEvent(ChangeListener.Code.StatusChanged);
			return;
		}
		myBuildStarted = true;

		setStatus(myStatusMask | STATUS_LOADING);
		final Thread builder = new Thread("Library.build") {
			public void run() {
				try {
					build();
				} finally {
					setStatus(myStatusMask & ~STATUS_LOADING);
				}
			}
		};
		builder.setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2);
		builder.start();
	}

>>>>>>> d9b061117aae6ae672696c5eff5484fe0a8dd640
	public boolean isUpToDate() {
		return myStatusMask == 0;
	}
Solution content
		fireModelChangedEvent(ChangeListener.Code.BookAdded);
	}

	public boolean isUpToDate() {
		return myStatusMask == 0;
	}
File
Library.java
Developer's decision
Version 1
Kind of conflict
Attribute
Method declaration