mirror of
https://github.com/MatomoCamp/matomocamp-companion-android.git
synced 2024-09-19 16:13:46 +02:00
Dynamic toolbar elevation in MainActivity
depending on the current section.
This commit is contained in:
parent
040d8a070a
commit
3100bce74c
1 changed files with 24 additions and 8 deletions
|
@ -67,21 +67,24 @@ import be.digitalia.fosdem.widgets.AdapterLinearLayout;
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private enum Section {
|
private enum Section {
|
||||||
TRACKS(TracksFragment.class, R.string.menu_tracks, R.drawable.ic_event_grey600_24dp, true),
|
TRACKS(TracksFragment.class, R.string.menu_tracks, R.drawable.ic_event_grey600_24dp, true, true),
|
||||||
BOOKMARKS(BookmarksListFragment.class, R.string.menu_bookmarks, R.drawable.ic_bookmark_grey600_24dp, false),
|
BOOKMARKS(BookmarksListFragment.class, R.string.menu_bookmarks, R.drawable.ic_bookmark_grey600_24dp, false, false),
|
||||||
LIVE(LiveFragment.class, R.string.menu_live, R.drawable.ic_play_circle_outline_grey600_24dp, false),
|
LIVE(LiveFragment.class, R.string.menu_live, R.drawable.ic_play_circle_outline_grey600_24dp, true, false),
|
||||||
SPEAKERS(PersonsListFragment.class, R.string.menu_speakers, R.drawable.ic_people_grey600_24dp, false),
|
SPEAKERS(PersonsListFragment.class, R.string.menu_speakers, R.drawable.ic_people_grey600_24dp, false, false),
|
||||||
MAP(MapFragment.class, R.string.menu_map, R.drawable.ic_map_grey600_24dp, false);
|
MAP(MapFragment.class, R.string.menu_map, R.drawable.ic_map_grey600_24dp, false, false);
|
||||||
|
|
||||||
private final String fragmentClassName;
|
private final String fragmentClassName;
|
||||||
private final int titleResId;
|
private final int titleResId;
|
||||||
private final int iconResId;
|
private final int iconResId;
|
||||||
|
private final boolean extendsAppBar;
|
||||||
private final boolean keep;
|
private final boolean keep;
|
||||||
|
|
||||||
Section(Class<? extends Fragment> fragmentClass, int titleResId, int iconResId, boolean keep) {
|
Section(Class<? extends Fragment> fragmentClass, int titleResId, int iconResId,
|
||||||
|
boolean extendsAppBar, boolean keep) {
|
||||||
this.fragmentClassName = fragmentClass.getName();
|
this.fragmentClassName = fragmentClass.getName();
|
||||||
this.titleResId = titleResId;
|
this.titleResId = titleResId;
|
||||||
this.iconResId = iconResId;
|
this.iconResId = iconResId;
|
||||||
|
this.extendsAppBar = extendsAppBar;
|
||||||
this.keep = keep;
|
this.keep = keep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +102,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return iconResId;
|
return iconResId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean extendsAppBar() {
|
||||||
|
return extendsAppBar;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean shouldKeep() {
|
public boolean shouldKeep() {
|
||||||
return keep;
|
return keep;
|
||||||
}
|
}
|
||||||
|
@ -111,9 +118,12 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static final String LAST_UPDATE_DATE_FORMAT = "d MMM yyyy kk:mm:ss";
|
private static final String LAST_UPDATE_DATE_FORMAT = "d MMM yyyy kk:mm:ss";
|
||||||
|
|
||||||
private Section currentSection;
|
|
||||||
|
|
||||||
|
private Toolbar toolbar;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
|
|
||||||
|
// Main menu
|
||||||
|
private Section currentSection;
|
||||||
private DrawerLayout drawerLayout;
|
private DrawerLayout drawerLayout;
|
||||||
private ActionBarDrawerToggle drawerToggle;
|
private ActionBarDrawerToggle drawerToggle;
|
||||||
private View mainMenu;
|
private View mainMenu;
|
||||||
|
@ -192,7 +202,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
|
||||||
|
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
progressBar = (ProgressBar) findViewById(R.id.progress);
|
progressBar = (ProgressBar) findViewById(R.id.progress);
|
||||||
|
|
||||||
|
@ -255,6 +267,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private void updateActionBar() {
|
private void updateActionBar() {
|
||||||
getSupportActionBar().setTitle(currentSection.getTitleResId());
|
getSupportActionBar().setTitle(currentSection.getTitleResId());
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
toolbar.setElevation(currentSection.extendsAppBar()
|
||||||
|
? 0f : getResources().getDimension(R.dimen.toolbar_elevation));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLastUpdateTime() {
|
private void updateLastUpdateTime() {
|
||||||
|
|
Loading…
Reference in a new issue