Fix force close when no more mangas found
This commit is contained in:
		
							parent
							
								
									0278531e51
								
							
						
					
					
						commit
						0febdfb715
					
				| @ -2,6 +2,7 @@ package eu.kanade.mangafeed.presenter; | |||||||
| 
 | 
 | ||||||
| import android.content.Intent; | import android.content.Intent; | ||||||
| 
 | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
| import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||||
| 
 | 
 | ||||||
| import javax.inject.Inject; | import javax.inject.Inject; | ||||||
| @ -31,6 +32,7 @@ public class CatalogueListPresenter extends BasePresenter { | |||||||
|     @Inject DatabaseHelper db; |     @Inject DatabaseHelper db; | ||||||
| 
 | 
 | ||||||
|     private String mSearchName; |     private String mSearchName; | ||||||
|  |     private boolean mSearchMode; | ||||||
|     private final int SEARCH_TIMEOUT = 1000; |     private final int SEARCH_TIMEOUT = 1000; | ||||||
| 
 | 
 | ||||||
|     private Subscription mMangaFetchSubscription; |     private Subscription mMangaFetchSubscription; | ||||||
| @ -81,7 +83,7 @@ public class CatalogueListPresenter extends BasePresenter { | |||||||
|                 .flatMap(Observable::from) |                 .flatMap(Observable::from) | ||||||
|                 .map(this::networkToLocalManga) |                 .map(this::networkToLocalManga) | ||||||
|                 .toList() |                 .toList() | ||||||
|                 .subscribe(adapter::setItems); |                 .subscribe(adapter::addItems); | ||||||
| 
 | 
 | ||||||
|         subscriptions.add(mMangaSearchSubscription); |         subscriptions.add(mMangaSearchSubscription); | ||||||
|     } |     } | ||||||
| @ -101,6 +103,8 @@ public class CatalogueListPresenter extends BasePresenter { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void initializeSearch() { |     private void initializeSearch() { | ||||||
|  |         mSearchName = ""; | ||||||
|  |         mSearchMode = false; | ||||||
|         mSearchViewPublishSubject = PublishSubject.create(); |         mSearchViewPublishSubject = PublishSubject.create(); | ||||||
|         mSearchViewSubscription = Observable.switchOnNext(mSearchViewPublishSubject) |         mSearchViewSubscription = Observable.switchOnNext(mSearchViewPublishSubject) | ||||||
|                 .debounce(SEARCH_TIMEOUT, TimeUnit.MILLISECONDS) |                 .debounce(SEARCH_TIMEOUT, TimeUnit.MILLISECONDS) | ||||||
| @ -114,24 +118,39 @@ public class CatalogueListPresenter extends BasePresenter { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void queryFromSearch(String query) { |     private void queryFromSearch(String query) { | ||||||
|  |         // If search button clicked | ||||||
|  |         if (mSearchName.equals("") && query.equals("")) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         // If going to search mode | ||||||
|  |         else if (mSearchName.equals("") && !query.equals("")) { | ||||||
|  |             mSearchMode = true; | ||||||
|             mSearchName = query; |             mSearchName = query; | ||||||
|         if (!isSearchMode()) { |             adapter.setItems(new ArrayList<>()); | ||||||
|  |             getMangasFromSearch(1); | ||||||
|  |         } | ||||||
|  |         // If going to normal mode | ||||||
|  |         else if (!mSearchName.equals("") && query.equals("")) { | ||||||
|  |             mSearchMode = false; | ||||||
|  |             mSearchName = query; | ||||||
|  |             adapter.setItems(new ArrayList<>()); | ||||||
|             getMangasFromSource(1); |             getMangasFromSource(1); | ||||||
|         } else { |         } | ||||||
|  |         // If query changes | ||||||
|  |         else { | ||||||
|  |             mSearchName = query; | ||||||
|  |             adapter.setItems(new ArrayList<>()); | ||||||
|             getMangasFromSearch(1); |             getMangasFromSearch(1); | ||||||
|         } |         } | ||||||
|         view.setScrollListener(); |         view.setScrollListener(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void loadMoreMangas(int page) { |     public void loadMoreMangas(int page) { | ||||||
|         if (!isSearchMode()) { |         if (!mSearchMode) { | ||||||
|             getMangasFromSource(page); |             getMangasFromSource(page); | ||||||
|         } else { |         } else { | ||||||
|             getMangasFromSearch(page); |             getMangasFromSearch(page); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private boolean isSearchMode() { |  | ||||||
|         return !mSearchName.equals(""); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -113,6 +113,10 @@ public class Batoto extends Source { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private List<Manga> parseMangasFromHtml(String unparsedHtml) { |     private List<Manga> parseMangasFromHtml(String unparsedHtml) { | ||||||
|  |         if (unparsedHtml.contains("No (more) comics found!")) { | ||||||
|  |             return new ArrayList<>(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         Document parsedDocument = Jsoup.parse(unparsedHtml); |         Document parsedDocument = Jsoup.parse(unparsedHtml); | ||||||
| 
 | 
 | ||||||
|         List<Manga> updatedMangaList = new ArrayList<>(); |         List<Manga> updatedMangaList = new ArrayList<>(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 inorichi
						inorichi