Show loading progress bar in catalogue

This commit is contained in:
inorichi 2015-10-14 12:27:51 +02:00
parent 991e4d40d0
commit 19eeb18d0d
4 changed files with 50 additions and 2 deletions

View File

@ -58,6 +58,7 @@ public class CatalogueListPresenter extends BasePresenter {
initializeSearch(); initializeSearch();
initializeMangaDetailsLoader(); initializeMangaDetailsLoader();
view.showProgressBar();
getMangasFromSource(1); getMangasFromSource(1);
} }
@ -154,6 +155,7 @@ public class CatalogueListPresenter extends BasePresenter {
.map(this::networkToLocalManga) .map(this::networkToLocalManga)
.toList() .toList()
.subscribe(newMangas -> { .subscribe(newMangas -> {
view.hideProgressBar();
adapter.addItems(newMangas); adapter.addItems(newMangas);
if (mMangaDetailPublishSubject != null) if (mMangaDetailPublishSubject != null)
mMangaDetailPublishSubject.onNext(Observable.just(newMangas)); mMangaDetailPublishSubject.onNext(Observable.just(newMangas));
@ -174,7 +176,6 @@ public class CatalogueListPresenter extends BasePresenter {
mSearchViewPublishSubject.onNext(Observable.just(query)); mSearchViewPublishSubject.onNext(Observable.just(query));
} }
private void queryFromSearch(String query) { private void queryFromSearch(String query) {
// If search button clicked // If search button clicked
if (mSearchName.equals("") && query.equals("")) { if (mSearchName.equals("") && query.equals("")) {
@ -191,11 +192,15 @@ public class CatalogueListPresenter extends BasePresenter {
mSearchName = query; mSearchName = query;
adapter.getItems().clear(); adapter.getItems().clear();
view.showProgressBar();
view.resetScrollListener(); view.resetScrollListener();
loadMoreMangas(1); loadMoreMangas(1);
} }
public void loadMoreMangas(int page) { public void loadMoreMangas(int page) {
if (page > 1) {
view.showGridProgressBar();
}
if (mSearchMode) { if (mSearchMode) {
getMangasFromSearch(page); getMangasFromSearch(page);
} else { } else {

View File

@ -7,6 +7,7 @@ import android.view.Menu;
import android.view.View; import android.view.View;
import android.widget.GridView; import android.widget.GridView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import butterknife.Bind; import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -24,6 +25,12 @@ public class CatalogueListActivity extends BaseActivity implements CatalogueList
@Bind(R.id.gridView) @Bind(R.id.gridView)
GridView manga_list; GridView manga_list;
@Bind(R.id.progress)
ProgressBar progress;
@Bind(R.id.progress_grid)
ProgressBar progress_grid;
private CatalogueListPresenter presenter; private CatalogueListPresenter presenter;
private EndlessScrollListener scrollListener; private EndlessScrollListener scrollListener;
@ -100,6 +107,22 @@ public class CatalogueListActivity extends BaseActivity implements CatalogueList
scrollListener.resetScroll(); scrollListener.resetScroll();
} }
@Override
public void showProgressBar() {
progress.setVisibility(ProgressBar.VISIBLE);
}
@Override
public void showGridProgressBar() {
progress_grid.setVisibility(ProgressBar.VISIBLE);
}
@Override
public void hideProgressBar() {
progress.setVisibility(ProgressBar.GONE);
progress_grid.setVisibility(ProgressBar.GONE);
}
@Override @Override
public ImageView getImageView(int position) { public ImageView getImageView(int position) {
View v = manga_list.getChildAt(position - View v = manga_list.getChildAt(position -

View File

@ -11,5 +11,8 @@ public interface CatalogueListView extends BaseView {
void setAdapter(EasyAdapter adapter); void setAdapter(EasyAdapter adapter);
void setScrollListener(); void setScrollListener();
void resetScrollListener(); void resetScrollListener();
void showProgressBar();
void showGridProgressBar();
void hideProgressBar();
ImageView getImageView(int position); ImageView getImageView(int position);
} }

View File

@ -11,9 +11,18 @@
android:id="@+id/toolbar" android:id="@+id/toolbar"
layout="@layout/toolbar"/> layout="@layout/toolbar"/>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="gone" />
<GridView <GridView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/gridView" android:id="@+id/gridView"
android:padding="10dp" android:padding="10dp"
android:clipToPadding="false" android:clipToPadding="false"
@ -25,4 +34,12 @@
android:fastScrollEnabled="true" android:fastScrollEnabled="true"
tools:listitem="@layout/item_catalogue" /> tools:listitem="@layout/item_catalogue" />
<ProgressBar
android:id="@+id/progress_grid"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="gone" />
</LinearLayout> </LinearLayout>