Skip to content

Commit

Permalink
Merge pull request #1983 from TeamAmaze/ArpitShukIa-release/3.5
Browse files Browse the repository at this point in the history
Fix nav drawer locking; persist nav drawer selection; fix date spacing
  • Loading branch information
VishalNehra authored Sep 14, 2020
2 parents 1de2aee + ecb5796 commit 8519ce2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,6 @@ public void onCreate(final Bundle savedInstanceState) {

checkForExternalIntent(intent);

if (savedInstanceState != null) {
drawer.setSomethingSelected(savedInstanceState.getBoolean(KEY_DRAWER_SELECTED));
}

// setting window background color instead of each item, in order to reduce pixel overdraw
if (getAppTheme().equals(AppTheme.LIGHT)) {
/*if(Main.IS_LIST)
Expand Down Expand Up @@ -398,7 +394,6 @@ public void onPostExecute(Void result) {
transaction.replace(
R.id.content_frame, new ProcessViewerFragment(), KEY_INTENT_PROCESS_VIEWER);
// transaction.addToBackStack(null);
drawer.setSomethingSelected(true);
openProcesses = false;
// title.setText(utils.getString(con, R.string.process_viewer));
// Commit the transaction
Expand All @@ -416,7 +411,6 @@ public void onPostExecute(Void result) {
.setInterpolator(new DecelerateInterpolator(2))
.start();

drawer.setSomethingSelected(true);
drawer.deselectEverything();
transaction2.commit();
} else {
Expand All @@ -439,6 +433,8 @@ public void onPostExecute(Void result) {
oparrayList = savedInstanceState.getParcelableArrayList(KEY_OPERATIONS_PATH_LIST);
operation = savedInstanceState.getInt(KEY_OPERATION);
// mainFragment = (Main) savedInstanceState.getParcelable("main_fragment");
int selectedStorage = savedInstanceState.getInt(KEY_DRAWER_SELECTED, 0);
getDrawer().selectCorrectDrawerItem(selectedStorage);
}
}
});
Expand Down Expand Up @@ -896,7 +892,6 @@ public void goToMain(String path) {
}
transaction.replace(R.id.content_frame, tabFragment);
// Commit the transaction
drawer.setSomethingSelected(true);
transaction.addToBackStack("tabt" + 1);
transaction.commitAllowingStateLoss();
appbar.setTitle(null);
Expand Down Expand Up @@ -1197,7 +1192,7 @@ public void onConfigurationChanged(Configuration newConfig) {
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_DRAWER_SELECTED, drawer.isSomethingSelected());
outState.putInt(KEY_DRAWER_SELECTED, getDrawer().getDrawerSelectedItem());
if (pasteHelper != null) {
outState.putParcelable(PASTEHELPER_BUNDLE, pasteHelper);
}
Expand Down Expand Up @@ -1234,7 +1229,7 @@ public void onResume() {
}

drawer.refreshDrawer();
drawer.deselectEverything();
drawer.refactorDrawerLockMode();

IntentFilter newFilter = new IntentFilter();
newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
Expand Down Expand Up @@ -1578,12 +1573,12 @@ void initialiseViews() {
FrameLayout.MarginLayoutParams p =
(ViewGroup.MarginLayoutParams) findViewById(R.id.drawer_layout).getLayoutParams();
SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
if (!drawer.isLocked()) p.setMargins(0, config.getStatusBarHeight(), 0, 0);
if (!drawer.isOnTablet()) p.setMargins(0, config.getStatusBarHeight(), 0, 0);
} else if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (drawer.isLocked()) {
if (drawer.isOnTablet()) {
window.setStatusBarColor((skinStatusBar));
} else window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (getBoolean(PREFERENCE_COLORED_NAVIGATION)) window.setNavigationBarColor(skinStatusBar);
Expand Down Expand Up @@ -1723,7 +1718,6 @@ public void onNewIntent(Intent i) {
transaction.replace(
R.id.content_frame, new ProcessViewerFragment(), KEY_INTENT_PROCESS_VIEWER);
// transaction.addToBackStack(null);
drawer.setSomethingSelected(true);
openProcesses = false;
// title.setText(utils.getString(con, R.string.process_viewer));
// Commit the transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,6 @@ public void onResume() {
(getActivity())
.registerReceiver(receiver2, new IntentFilter(MainActivity.KEY_INTENT_LOAD_LIST));

getMainActivity().getDrawer().selectCorrectDrawerItemForPath(getPath());
resumeDecryptOperations();
startFileObserver();
}
Expand Down
63 changes: 41 additions & 22 deletions app/src/main/java/com/amaze/filemanager/ui/views/drawer/Drawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public class Drawer implements NavigationView.OnNavigationItemSelectedListener {
private DataUtils dataUtils;

private ActionViewStateManager actionViewStateManager;
private boolean isSomethingSelected;
private volatile int phoneStorageCount =
0; // number of storage available (internal/external/otg etc)
private boolean isDrawerLocked = false;
Expand Down Expand Up @@ -200,18 +199,11 @@ public Drawer(MainActivity mainActivity) {
// drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
if (mainActivity.findViewById(R.id.tab_frame) != null) {
isOnTablet = true;
lock(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
open();
mDrawerLayout.setScrimColor(Color.TRANSPARENT);
mDrawerLayout.post(this::open);
} else if (mainActivity.findViewById(R.id.tab_frame) == null) {
unlockIfNotOnTablet();
close();
mDrawerLayout.post(this::close);
}
navView.addHeaderView(drawerHeaderLayout);

if (!isDrawerLocked) {
if (!isOnTablet) {
mDrawerToggle =
new ActionBarDrawerToggle(
mainActivity, /* host Activity */
Expand Down Expand Up @@ -246,6 +238,19 @@ private void setNavViewDimension(CustomNavigationView navView) {
desiredWidthInPx, LinearLayout.LayoutParams.MATCH_PARENT, Gravity.START));
}

/** Refactors lock mode based on orientation */
public void refactorDrawerLockMode() {
if (mainActivity.findViewById(R.id.tab_frame) != null) {
isOnTablet = true;
mDrawerLayout.setScrimColor(Color.TRANSPARENT);
open();
lock(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
} else {
unlockIfNotOnTablet();
close();
}
}

public void refreshDrawer() {
Menu menu = navView.getMenu();
menu.clear();
Expand Down Expand Up @@ -546,7 +551,6 @@ public void refreshDrawer() {
if (item != null) {
item.setChecked(true);
actionViewStateManager.selectActionView(item);
isSomethingSelected = true;
}
}

Expand Down Expand Up @@ -627,6 +631,10 @@ public boolean isLocked() {
return isDrawerLocked;
}

public boolean isOnTablet() {
return isOnTablet;
}

public boolean isOpen() {
return mDrawerLayout.isDrawerOpen(navView);
}
Expand Down Expand Up @@ -670,7 +678,6 @@ public void onDrawerClosed() {
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
actionViewStateManager.deselectCurrentActionView();
actionViewStateManager.selectActionView(item);
isSomethingSelected = true;

String title = item.getTitle().toString();
MenuMetadata meta = dataUtils.getDrawerMetadata(item);
Expand Down Expand Up @@ -761,14 +768,6 @@ public void onNavigationItemActionClick(MenuItem item) {
}
}

public boolean isSomethingSelected() {
return isSomethingSelected;
}

public void setSomethingSelected(boolean isSelected) {
isSomethingSelected = isSelected;
}

public int getPhoneStorageCount() {
return phoneStorageCount;
}
Expand Down Expand Up @@ -804,12 +803,34 @@ public void selectCorrectDrawerItemForPath(final String path) {

if (id == null) deselectEverything();
else {
selectCorrectDrawerItem(id);
}
}

/**
* Select given item id in navigation drawer
*
* @param id given item id from menu
*/
public void selectCorrectDrawerItem(int id) {
if (id < 0) {
deselectEverything();
} else {
MenuItem item = navView.getMenu().findItem(id);
navView.setCheckedItem(item);
actionViewStateManager.selectActionView(item);
}
}

/**
* Get selected item id
*
* @return item id from menu
*/
public int getDrawerSelectedItem() {
return navView.getSelected().getItemId();
}

public void setBackgroundColor(@ColorInt int color) {
mDrawerLayout.setStatusBarBackgroundColor(color);
drawerHeaderParent.setBackgroundColor(color);
Expand Down Expand Up @@ -843,7 +864,7 @@ public void setDrawerIndicatorEnabled() {
public void deselectEverything() {
actionViewStateManager
.deselectCurrentActionView(); // If you set the item as checked the listener doesn't trigger
if (!isSomethingSelected) {
if (navView.getSelected() == null) {
return;
}

Expand All @@ -852,8 +873,6 @@ public void deselectEverything() {
for (int i = 0; i < navView.getMenu().size(); i++) {
navView.getMenu().getItem(i).setChecked(false);
}

isSomethingSelected = false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/amaze/filemanager/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void setTint(Context context, CheckBox box, int color) {
public static String getDate(@NonNull Context c, long f) {
return String.format(
DATE_TIME_FORMAT,
DateUtils.formatDateTime(c, f, DateUtils.FORMAT_SHOW_DATE),
DateUtils.formatDateTime(c, f, DateUtils.FORMAT_ABBREV_MONTH),
DateUtils.formatDateTime(c, f, DateUtils.FORMAT_SHOW_TIME));
}

Expand Down

0 comments on commit 8519ce2

Please sign in to comment.