better react on changes in the passStore regarding the category navigation
This commit is contained in:
parent
c370c2943f
commit
08d6b33e6f
3 changed files with 56 additions and 3 deletions
|
@ -0,0 +1,4 @@
|
|||
package org.ligi.passandroid.events;
|
||||
|
||||
public class NavigationOpenedEvent {
|
||||
}
|
|
@ -12,13 +12,18 @@ import android.widget.RadioButton;
|
|||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.ligi.passandroid.App;
|
||||
import org.ligi.passandroid.R;
|
||||
import org.ligi.passandroid.events.NavigationOpenedEvent;
|
||||
import org.ligi.passandroid.events.SortOrderChangeEvent;
|
||||
import org.ligi.passandroid.helper.CategoryHelper;
|
||||
import org.ligi.passandroid.model.PassStore;
|
||||
import org.ligi.passandroid.ui.views.CategoryIndicatorView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import butterknife.OnClick;
|
||||
|
@ -26,6 +31,7 @@ import butterknife.OnClick;
|
|||
public class NavigationFragment extends Fragment {
|
||||
|
||||
private static final String PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=org.ligi.passandroid";
|
||||
private List<PassStore.CountedType> countedTypes;
|
||||
|
||||
@OnClick(R.id.rate)
|
||||
void rateClick() {
|
||||
|
@ -64,6 +70,9 @@ public class NavigationFragment extends Fragment {
|
|||
@InjectView(R.id.navCategoriesInner)
|
||||
ViewGroup categoriesContainer;
|
||||
|
||||
@InjectView(R.id.navCategoriesOuter)
|
||||
ViewGroup categoriesContainerOuter;
|
||||
|
||||
public NavigationFragment() {
|
||||
|
||||
}
|
||||
|
@ -99,9 +108,44 @@ public class NavigationFragment extends Fragment {
|
|||
break;
|
||||
}
|
||||
|
||||
createCategoryJumpMarks(inflater);
|
||||
|
||||
App.getBus().register(this);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
App.getBus().unregister(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNavigationOpened(NavigationOpenedEvent event) {
|
||||
createCategoryJumpMarks(LayoutInflater.from(getActivity()));
|
||||
}
|
||||
|
||||
private void createCategoryJumpMarks(LayoutInflater inflater) {
|
||||
|
||||
List<PassStore.CountedType> newCountedTypes = App.getPassStore().getCountedTypes();
|
||||
|
||||
if (countedTypes != null && countedTypes.size() == newCountedTypes.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newCountedTypes.size() > 1) {
|
||||
categoriesContainerOuter.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
categoriesContainerOuter.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
|
||||
categoriesContainer.removeAllViews();
|
||||
|
||||
for (PassStore.CountedType countedType : App.getPassStore().getCountedTypes()) {
|
||||
countedTypes = newCountedTypes;
|
||||
|
||||
for (PassStore.CountedType countedType : countedTypes) {
|
||||
final String type = countedType.type;
|
||||
|
||||
View item = inflater.inflate(R.layout.item_nav_pass_category, null);
|
||||
|
@ -130,7 +174,6 @@ public class NavigationFragment extends Fragment {
|
|||
|
||||
categoriesContainer.addView(item);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.squareup.otto.Subscribe;
|
|||
import org.ligi.passandroid.App;
|
||||
import org.ligi.passandroid.R;
|
||||
import org.ligi.passandroid.Tracker;
|
||||
import org.ligi.passandroid.events.NavigationOpenedEvent;
|
||||
import org.ligi.passandroid.events.SortOrderChangeEvent;
|
||||
import org.ligi.passandroid.helper.PassVisualizer;
|
||||
import org.ligi.tracedroid.TraceDroid;
|
||||
|
@ -113,7 +114,12 @@ public class TicketListActivity extends ActionBarActivity {
|
|||
ms.level(MarketService.MINOR).checkVersion();
|
||||
}
|
||||
|
||||
drawerToggle = new ActionBarDrawerToggle(this, drawer, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);
|
||||
drawerToggle = new ActionBarDrawerToggle(this, drawer, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
App.getBus().post(new NavigationOpenedEvent());
|
||||
}
|
||||
};
|
||||
drawer.setDrawerListener(drawerToggle);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
|
Loading…
Reference in a new issue