Skip to content

Commit

Permalink
Update to SDK 28 (P)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Oct 4, 2018
1 parent cbcf27e commit c3fa512
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -14,7 +14,7 @@ if (enable_plugin_kotlin) {
apply plugin: 'kotlin-kapt'
}

ext.version_setup_minSdk = 15
ext.version_setup_minSdk = 16

// https://github.com/vsch/flexmark-java/releases
ext.version_library_flexmark = "0.32.18"
Expand Down
36 changes: 10 additions & 26 deletions app/src/main/java/net/gsantner/markor/activity/MainActivity.java
Expand Up @@ -119,7 +119,6 @@ protected void onCreate(Bundle savedInstanceState) {
}

// Setup viewpager
removeShiftMode(_bottomNav);
_viewPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
_viewPager.setAdapter(_viewPagerAdapter);
_viewPager.setOffscreenPageLimit(4);
Expand Down Expand Up @@ -308,8 +307,8 @@ public void onBackPressed() {

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
updateFabVisibility(item.getItemId() == R.id.nav_notebook);
PermissionChecker permc = new PermissionChecker(this);
_fab.setVisibility(item.getItemId() == R.id.nav_notebook ? View.VISIBLE : View.INVISIBLE);
switch (item.getItemId()) {
case R.id.nav_notebook: {
_viewPager.setCurrentItem(0);
Expand All @@ -334,42 +333,27 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return false;
}

public void updateFabVisibility(boolean visible){
if (visible){
_fab.show();
} else {
_fab.hide();
}
}

@OnPageChange(value = R.id.main__view_pager_container, callback = OnPageChange.Callback.PAGE_SELECTED)
public void onViewPagerPageSelected(int pos) {
Menu menu = _bottomNav.getMenu();
PermissionChecker permc = new PermissionChecker(this);
(_lastBottomMenuItem != null ? _lastBottomMenuItem : menu.getItem(0)).setChecked(false);
_lastBottomMenuItem = menu.getItem(pos).setChecked(true);
_fab.setVisibility(pos == 0 ? View.VISIBLE : View.INVISIBLE);
updateFabVisibility(pos == 0);

if (pos == 1 || pos == 2) {
permc.doIfExtStoragePermissionGranted(); // cannot prevent bottom tab selection
}
}

@SuppressLint("RestrictedApi")
public static void removeShiftMode(BottomNavigationView view) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
try {
Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
shiftingMode.setAccessible(true);
shiftingMode.setBoolean(menuView, false);
shiftingMode.setAccessible(false);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
item.setShiftingMode(false);
// set once again checked value, so view will be updated
item.setChecked(item.getItemData().isChecked());
}

} catch (NoSuchFieldException e) {
Log.e("ERROR NO SUCH FIELD", "Unable to get shift mode field");
} catch (IllegalAccessException e) {
Log.e("ERROR ILLEGAL ALG", "Unable to change value of shift mode");
}
}


class SectionsPagerAdapter extends FragmentPagerAdapter {
private HashMap<Integer, GsFragmentBase> _fragCache = new LinkedHashMap<>();

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/main__activity.xml
Expand Up @@ -71,6 +71,7 @@
app:itemBackground="@color/primary"
app:itemIconTint="@drawable/bottomnav_color_selector"
app:itemTextColor="@drawable/bottomnav_color_selector"
app:labelVisibilityMode="labeled"
app:menu="@menu/main__bottom_nav"
tools:elevation="2dp" />

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Expand Up @@ -12,15 +12,15 @@ import java.text.SimpleDateFormat
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.version_setup_compileSdk = 27
ext.version_setup_compileSdk = 28
ext.version_setup_minSdk = 17
ext.version_setup_targetSdk = ext.version_setup_compileSdk
ext.version_setup_buildTools = "27.0.3" // Specifying optional
ext.version_setup_buildTools = ext.version_setup_compileSdk + ".0.3" // Specifying optional

// https://developer.android.com/studio/releases/gradle-plugin.html
ext.version_gradle_tools = "3.2.0"
// https://developer.android.com/topic/libraries/support-library/revisions.html
ext.version_library_appcompat = "27.1.1"
ext.version_library_appcompat = ext.version_setup_compileSdk + ".0.0"
// https://github.com/JakeWharton/butterknife/releases
ext.version_library_butterknife = "8.8.1"
// https://github.com/guardianproject/NetCipher/releases
Expand Down

0 comments on commit c3fa512

Please sign in to comment.