mirror of
				https://github.com/MinimalBible/MinimalBible-Legacy
				synced 2025-10-31 01:10:29 -04:00 
			
		
		
		
	Start switch to new Android Annotation format
This commit is contained in:
		| @ -1,73 +1,55 @@ | |||||||
| package org.bspeice.minimalbible.activities.downloader; | package org.bspeice.minimalbible.activities.downloader; | ||||||
|  |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| import org.bspeice.minimalbible.MinimalBibleConstants; |  | ||||||
| import org.bspeice.minimalbible.R; |  | ||||||
| import org.crosswire.jsword.book.Book; |  | ||||||
| import org.crosswire.jsword.book.BookCategory; |  | ||||||
| import org.crosswire.jsword.book.BookFilter; |  | ||||||
| import org.crosswire.jsword.book.BookFilters; |  | ||||||
|  |  | ||||||
| import de.greenrobot.event.EventBus; |  | ||||||
|  |  | ||||||
| import android.app.Activity; |  | ||||||
| import android.app.AlertDialog; | import android.app.AlertDialog; | ||||||
| import android.app.ProgressDialog; | import android.app.ProgressDialog; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.content.DialogInterface; | import android.content.DialogInterface; | ||||||
| import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||||
| import android.os.Bundle; |  | ||||||
| import android.support.v4.app.Fragment; | import android.support.v4.app.Fragment; | ||||||
| import android.view.LayoutInflater; | import android.util.Log; | ||||||
| import android.view.View; |  | ||||||
| import android.view.ViewGroup; |  | ||||||
| import android.widget.TextView; | import android.widget.TextView; | ||||||
| import android.widget.Toast; | import android.widget.Toast; | ||||||
|  |  | ||||||
|  | import org.androidannotations.annotations.AfterViews; | ||||||
|  | import org.androidannotations.annotations.EFragment; | ||||||
|  | import org.androidannotations.annotations.FragmentArg; | ||||||
|  | import org.androidannotations.annotations.Trace; | ||||||
|  | import org.androidannotations.annotations.ViewById; | ||||||
|  | import org.bspeice.minimalbible.MinimalBibleConstants; | ||||||
|  | import org.bspeice.minimalbible.R; | ||||||
|  | import org.crosswire.jsword.book.Book; | ||||||
|  | import org.crosswire.jsword.book.BookCategory; | ||||||
|  | import org.crosswire.jsword.book.BookFilter; | ||||||
|  | import org.crosswire.jsword.book.FilterUtil; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * A placeholder fragment containing a simple view. |  * A placeholder fragment containing a simple view. | ||||||
|  */ |  */ | ||||||
|  | @EFragment(R.layout.fragment_download) | ||||||
| public class BookListFragment extends Fragment { | public class BookListFragment extends Fragment { | ||||||
| 	/** | 	/** | ||||||
| 	 * The fragment argument representing the section number for this fragment. | 	 * The fragment argument representing the section number for this fragment. | ||||||
| 	 */ | 	 */ | ||||||
| 	private static final String ARG_BOOK_CATEGORY = "book_category"; |  | ||||||
|  |  | ||||||
|  |     private final String TAG = "BookListFragment"; | ||||||
|  |  | ||||||
|  |     @FragmentArg | ||||||
|  | 	BookCategory bookCategory; | ||||||
|  |  | ||||||
|  |     @ViewById(R.id.section_label) | ||||||
| 	protected TextView tv; | 	protected TextView tv; | ||||||
|  |  | ||||||
| 	private ProgressDialog refreshDialog; | 	private ProgressDialog refreshDialog; | ||||||
|  |  | ||||||
| 	/** |     @Trace | ||||||
| 	 * Returns a new instance of this fragment for the given section number. |     @AfterViews | ||||||
| 	 */ |     public void updateName() { | ||||||
| 	public static BookListFragment newInstance(BookCategory c) { |         ((DownloadActivity) getActivity()).onSectionAttached(bookCategory.toString()); | ||||||
| 		BookListFragment fragment = new BookListFragment(); |         tv.setText(bookCategory.toString()); | ||||||
| 		Bundle args = new Bundle(); |         displayModules(); | ||||||
| 		args.putString(ARG_BOOK_CATEGORY, c.toString()); |     } | ||||||
| 		fragment.setArguments(args); |  | ||||||
| 		return fragment; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public BookListFragment() { |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	@Override |  | ||||||
| 	public View onCreateView(LayoutInflater inflater, ViewGroup container, |  | ||||||
| 			Bundle savedInstanceState) { |  | ||||||
| 		View rootView = inflater.inflate(R.layout.fragment_download, container, |  | ||||||
| 				false); |  | ||||||
| 		tv = (TextView) rootView.findViewById(R.id.section_label); |  | ||||||
| 		tv.setText(getArguments().getString(ARG_BOOK_CATEGORY)); |  | ||||||
| 		displayModules(); |  | ||||||
| 		return rootView; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	@Override |  | ||||||
| 	public void onAttach(Activity activity) { |  | ||||||
| 		super.onAttach(activity); |  | ||||||
| 		((DownloadActivity) activity).onSectionAttached(getArguments() |  | ||||||
| 				.getString(ARG_BOOK_CATEGORY)); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public void displayModules() { | 	public void displayModules() { | ||||||
| 		SharedPreferences prefs = getActivity() | 		SharedPreferences prefs = getActivity() | ||||||
| @ -91,55 +73,42 @@ public class BookListFragment extends Fragment { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	private void refreshModules() { | 	private void refreshModules() { | ||||||
| 		BookCategory bc = BookCategory.fromString(getArguments().getString( |  | ||||||
| 				ARG_BOOK_CATEGORY)); |  | ||||||
| 		BookFilter f; |  | ||||||
| 		// We wouldn't need this switch if BookFilters.BookCategoryFilter were |  | ||||||
| 		// public... |  | ||||||
| 		switch (bc) { |  | ||||||
| 		case BIBLE: |  | ||||||
| 			f = BookFilters.getBibles(); |  | ||||||
| 			break; |  | ||||||
| 		case COMMENTARY: |  | ||||||
| 			f = BookFilters.getCommentaries(); |  | ||||||
| 			break; |  | ||||||
| 		case DAILY_DEVOTIONS: |  | ||||||
| 			f = BookFilters.getDailyDevotionals(); |  | ||||||
| 			break; |  | ||||||
| 		case DICTIONARY: |  | ||||||
| 			f = BookFilters.getDictionaries(); |  | ||||||
| 			break; |  | ||||||
| 		case GENERAL_BOOK: |  | ||||||
| 			f = BookFilters.getGeneralBooks(); |  | ||||||
| 			break; |  | ||||||
| 		case GLOSSARY: |  | ||||||
| 			f = BookFilters.getGlossaries(); |  | ||||||
| 			break; |  | ||||||
| 		case MAPS: |  | ||||||
| 			f = BookFilters.getMaps(); |  | ||||||
| 			break; |  | ||||||
| 		default: |  | ||||||
| 			// DownloadManager takes care of accepting a null value |  | ||||||
| 			f = null; |  | ||||||
| 			break; |  | ||||||
| 		} |  | ||||||
| 		DownloadManager dm = DownloadManager.getInstance(); | 		DownloadManager dm = DownloadManager.getInstance(); | ||||||
| 		EventBus downloadBus = dm.getDownloadBus(); | 		EventBookList bookList = dm.getDownloadBus().getStickyEvent(EventBookList.class); | ||||||
| 		downloadBus.registerSticky(this); | 		if (bookList == null) { | ||||||
| 		 |             dm.getDownloadBus().registerSticky(this); | ||||||
| 		refreshDialog = new ProgressDialog(getActivity());	 |             refreshDialog = new ProgressDialog(getActivity()); | ||||||
| 		refreshDialog.setMessage("Refreshing available modules..."); |             refreshDialog.setMessage("Refreshing available modules..."); | ||||||
| 		refreshDialog.setCancelable(false); |             refreshDialog.setCancelable(false); | ||||||
| 		refreshDialog.show(); |             refreshDialog.show(); | ||||||
|  |         } else { | ||||||
|  |             displayBooks(bookList.getBookList()); | ||||||
|  |         } | ||||||
| 	} | 	} | ||||||
| 	 |  | ||||||
|  |     /* | ||||||
|  |     Used by GreenRobot for notifying us that the book refresh is complete | ||||||
|  |      */ | ||||||
|  |     @SuppressWarnings("unused") | ||||||
| 	public void onEventMainThread(EventBookList event) { | 	public void onEventMainThread(EventBookList event) { | ||||||
| 		if (refreshDialog != null) { | 		if (refreshDialog != null) { | ||||||
| 			refreshDialog.cancel(); | 			refreshDialog.cancel(); | ||||||
| 		} | 		} | ||||||
| 		tv.setText(event.getBookList().get(0).getName()); | 		displayBooks(event.getBookList()); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |     public void displayBooks(List<Book> bookList) { | ||||||
|  |         try { | ||||||
|  |             BookFilter f = FilterUtil.filterFromCategory(bookCategory); | ||||||
|  |             List<Book> filteredBooks = FilterUtil.applyFilter(bookList, f); | ||||||
|  |             tv.setText(filteredBooks.get(0).getName()); | ||||||
|  |         } catch (FilterUtil.InvalidFilterCategoryMappingException e) { | ||||||
|  |             // To be honest, there should be no reason you end up here. | ||||||
|  |             Log.e(TAG, e.getMessage()); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
| 	private class DownloadDialogListener implements | 	private class DownloadDialogListener implements | ||||||
| 			DialogInterface.OnClickListener { | 			DialogInterface.OnClickListener { | ||||||
| 		@Override | 		@Override | ||||||
|  | |||||||
| @ -47,7 +47,7 @@ public class DownloadActivity extends BaseActivity implements | |||||||
| 		fragmentManager | 		fragmentManager | ||||||
| 				.beginTransaction() | 				.beginTransaction() | ||||||
| 				.replace(R.id.container, | 				.replace(R.id.container, | ||||||
| 						BookListFragment.newInstance(DownloadManager.VALID_CATEGORIES[position])).commit(); | 						BookListFragment_.builder().bookCategory(DownloadManager.VALID_CATEGORIES[position]).build()).commit(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	public void onSectionAttached(String category) { | 	public void onSectionAttached(String category) { | ||||||
|  | |||||||
| @ -1,13 +1,16 @@ | |||||||
| package org.bspeice.minimalbible.activities.downloader; | package org.bspeice.minimalbible.activities.downloader; | ||||||
|  |  | ||||||
| import java.util.Map; | import android.util.Log; | ||||||
|  |  | ||||||
| import org.bspeice.minimalbible.MinimalBible; | import org.bspeice.minimalbible.MinimalBible; | ||||||
| import org.crosswire.jsword.book.BookCategory; | import org.crosswire.jsword.book.BookCategory; | ||||||
|  | import org.crosswire.jsword.book.BookFilter; | ||||||
|  | import org.crosswire.jsword.book.BookFilters; | ||||||
| import org.crosswire.jsword.book.install.InstallManager; | import org.crosswire.jsword.book.install.InstallManager; | ||||||
| import org.crosswire.jsword.book.install.Installer; | import org.crosswire.jsword.book.install.Installer; | ||||||
|  |  | ||||||
| import android.util.Log; | import java.util.Map; | ||||||
|  |  | ||||||
| import de.greenrobot.event.EventBus; | import de.greenrobot.event.EventBus; | ||||||
|  |  | ||||||
| public class DownloadManager { | public class DownloadManager { | ||||||
| @ -18,7 +21,7 @@ public class DownloadManager { | |||||||
|  |  | ||||||
| 	public static final BookCategory[] VALID_CATEGORIES = { BookCategory.BIBLE, | 	public static final BookCategory[] VALID_CATEGORIES = { BookCategory.BIBLE, | ||||||
| 			BookCategory.COMMENTARY, BookCategory.DICTIONARY, | 			BookCategory.COMMENTARY, BookCategory.DICTIONARY, | ||||||
| 			BookCategory.IMAGES, BookCategory.MAPS }; | 			BookCategory.MAPS }; | ||||||
|  |  | ||||||
| 	public static DownloadManager getInstance() { | 	public static DownloadManager getInstance() { | ||||||
| 		if (instance == null) { | 		if (instance == null) { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Bradlee Speice
					Bradlee Speice