@@ -184,6 +184,22 @@ public abstract class DrawerActivity extends ToolbarActivity
184184 private TextView mQuotaTextPercentage ;
185185 private TextView mQuotaTextLink ;
186186
187+ /**
188+ * container layout of the quota view on sidebar.
189+ */
190+ private LinearLayout sidebarQuotaView ;
191+
192+ /**
193+ * progress bar of the quota view on sidebar.
194+ */
195+ private LinearProgressIndicator sidebarQuotaProgressBar ;
196+
197+ /**
198+ * text view of the quota view on sidebar.
199+ */
200+ private TextView sidebarQuotaTextPercentage ;
201+ private TextView sidebarQuotaTextLink ;
202+
187203 /**
188204 * runnable that will be executed after the drawer has been closed.
189205 */
@@ -195,6 +211,9 @@ public abstract class DrawerActivity extends ToolbarActivity
195211 private BottomNavigationView bottomNavigationView ;
196212 private NavigationView drawerNavigationView ;
197213
214+ private View sidebarMenu ;
215+ private NavigationView sidebarNavigationView ;
216+
198217 /**
199218 * Returns the navigation drawer menu item ID that represents
200219 * the current activity.
@@ -243,10 +262,18 @@ protected void setupDrawer(int id) {
243262 mDrawerLayout = findViewById (R .id .drawer_layout );
244263 }
245264
265+ if (sidebarMenu == null ) {
266+ sidebarMenu = findViewById (R .id .sidebar_menu );
267+ }
268+
246269 if (drawerNavigationView == null ) {
247270 drawerNavigationView = findViewById (R .id .nav_view );
248271 }
249272
273+ if (sidebarMenu != null && sidebarNavigationView == null ) {
274+ sidebarNavigationView = sidebarMenu .findViewById (R .id .sidebar_view );
275+ }
276+
250277 if (drawerNavigationView != null ) {
251278 viewThemeUtils .files .colorNavigationView (drawerNavigationView );
252279
@@ -255,16 +282,23 @@ protected void setupDrawer(int id) {
255282 updateHeader ();
256283
257284 setupDrawerMenu (drawerNavigationView );
258- getAndDisplayUserQuota ();
259285 setupQuotaElement ();
260- highlightNavigationViewItem (id );
261286 }
262287
263- setupDrawerToggle ();
288+ if (sidebarNavigationView != null ) {
289+ viewThemeUtils .files .colorNavigationView (sidebarNavigationView );
290+
291+ // Setting up drawer header
292+ mNavigationViewHeader = sidebarNavigationView .getHeaderView (0 );
293+ updateHeader ();
264294
265- if ( getSupportActionBar () != null ) {
266- getSupportActionBar (). setDisplayHomeAsUpEnabled ( true );
295+ setupSidebarMenu ( sidebarNavigationView );
296+ setupSidebarQuotaElement ( );
267297 }
298+ getAndDisplayUserQuota ();
299+ highlightNavigationViewItem (id );
300+
301+ setupDrawerToggle ();
268302
269303 if (bottomNavigationView == null ) {
270304 bottomNavigationView = findViewById (R .id .bottom_navigation );
@@ -276,6 +310,12 @@ protected void setupDrawer(int id) {
276310 handleBottomNavigationViewClicks ();
277311 highlightNavigationViewItem (id );
278312 }
313+
314+ if (!isDrawerLayout () && mMenuButton != null ) {
315+ mMenuButton .setVisibility (View .GONE );
316+ }
317+
318+ hideOrShowSidebar ();
279319 }
280320
281321 /**
@@ -307,6 +347,15 @@ public void highlightNavigationViewItem(int menuItemId) {
307347 }
308348 }
309349
350+ if (sidebarNavigationView != null ) {
351+ NavigationViewExtensionsKt .unsetAllNavigationItems (sidebarNavigationView );
352+ MenuItem menuItem = sidebarNavigationView .getMenu ().findItem (menuItemId );
353+
354+ if (menuItem != null && !menuItem .isChecked ()) {
355+ menuItem .setChecked (true );
356+ }
357+ }
358+
310359 if (bottomNavigationView != null ) {
311360 NavigationViewExtensionsKt .unsetAllNavigationItems (bottomNavigationView );
312361 MenuItem menuItem = bottomNavigationView .getMenu ().findItem (menuItemId );
@@ -409,6 +458,16 @@ private void setupQuotaElement() {
409458 viewThemeUtils .platform .colorViewBackground (mQuotaView );
410459 }
411460
461+ private void setupSidebarQuotaElement () {
462+ sidebarQuotaView = (LinearLayout ) findSidebarQuotaViewById (R .id .sidebar_quota );
463+ sidebarQuotaProgressBar = (LinearProgressIndicator ) findSidebarQuotaViewById (R .id .sidebar_quota_ProgressBar );
464+ sidebarQuotaTextPercentage = (TextView ) findSidebarQuotaViewById (R .id .sidebar_quota_percentage );
465+ sidebarQuotaTextLink = (TextView ) findSidebarQuotaViewById (R .id .sidebar_quota_link );
466+ viewThemeUtils .material .colorProgressBar (sidebarQuotaProgressBar , ColorRole .PRIMARY );
467+ sidebarQuotaProgressBar .setTrackStopIndicatorSize (0 );
468+ viewThemeUtils .platform .colorViewBackground (sidebarQuotaView );
469+ }
470+
412471 public void updateHeader () {
413472 final var account = getAccount ();
414473 boolean isClientBranded = getResources ().getBoolean (R .bool .is_branded_client );
@@ -586,6 +645,17 @@ private void setupDrawerMenu(NavigationView navigationView) {
586645 filterDrawerMenu (navigationView .getMenu (), account );
587646 }
588647
648+ private void setupSidebarMenu (NavigationView navigationView ) {
649+ navigationView .setNavigationItemSelectedListener (
650+ menuItem -> {
651+ onNavigationItemClicked (menuItem );
652+ return true ;
653+ });
654+
655+ User account = accountManager .getUser ();
656+ filterDrawerMenu (navigationView .getMenu (), account );
657+ }
658+
589659 private void filterDrawerMenu (final Menu menu , @ NonNull final User user ) {
590660 final var optionalCapability = getCapabilities ();
591661 if (optionalCapability .isPresent ()) {
@@ -607,6 +677,10 @@ private void filterDrawerMenu(final Menu menu, @NonNull final User user) {
607677 private void onNavigationItemClicked (final MenuItem menuItem ) {
608678 int itemId = menuItem .getItemId ();
609679
680+ if (itemId == getMenuItemId ()) {
681+ return ;
682+ }
683+
610684 if (itemId == R .id .nav_all_files || itemId == R .id .nav_personal_files ) {
611685 closeDrawer ();
612686 DrawerActivityExtensionsKt .navigateToAllFiles (this ,itemId == R .id .nav_personal_files );
@@ -902,9 +976,19 @@ protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
902976 */
903977 private void showQuota (boolean showQuota ) {
904978 if (showQuota ) {
905- mQuotaView .setVisibility (View .VISIBLE );
979+ if (mQuotaView != null ) {
980+ mQuotaView .setVisibility (View .VISIBLE );
981+ }
982+ if (sidebarQuotaView != null ) {
983+ sidebarQuotaView .setVisibility (View .VISIBLE );
984+ }
906985 } else {
907- mQuotaView .setVisibility (View .GONE );
986+ if (mQuotaView != null ) {
987+ mQuotaView .setVisibility (View .GONE );
988+ }
989+ if (sidebarQuotaView != null ) {
990+ sidebarQuotaView .setVisibility (View .GONE );
991+ }
908992 }
909993 }
910994
@@ -918,41 +1002,78 @@ private void showQuota(boolean showQuota) {
9181002 */
9191003 private void setQuotaInformation (long usedSpace , long totalSpace , int relative , long quotaValue ) {
9201004 if (GetUserInfoRemoteOperation .SPACE_UNLIMITED == quotaValue ) {
921- mQuotaTextPercentage .setText (String .format (
922- getString (R .string .drawer_quota_unlimited ),
923- DisplayUtils .bytesToHumanReadable (usedSpace )));
1005+ if (mQuotaTextPercentage != null ) {
1006+ mQuotaTextPercentage .setText (String .format (
1007+ getString (R .string .drawer_quota_unlimited ),
1008+ DisplayUtils .bytesToHumanReadable (usedSpace )));
1009+ }
1010+
1011+ if (sidebarQuotaTextPercentage != null ) {
1012+ sidebarQuotaTextPercentage .setText (String .format (
1013+ getString (R .string .drawer_quota_unlimited ),
1014+ DisplayUtils .bytesToHumanReadable (usedSpace )));
1015+ }
9241016 } else {
925- mQuotaTextPercentage .setText (String .format (
926- getString (R .string .drawer_quota ),
927- DisplayUtils .bytesToHumanReadable (usedSpace ),
928- DisplayUtils .bytesToHumanReadable (totalSpace )));
1017+ if (mQuotaTextPercentage != null ) {
1018+ mQuotaTextPercentage .setText (String .format (
1019+ getString (R .string .drawer_quota ),
1020+ DisplayUtils .bytesToHumanReadable (usedSpace ),
1021+ DisplayUtils .bytesToHumanReadable (totalSpace )));
1022+ }
1023+
1024+ if (sidebarQuotaTextPercentage != null ) {
1025+ sidebarQuotaTextPercentage .setText (String .format (
1026+ getString (R .string .drawer_quota ),
1027+ DisplayUtils .bytesToHumanReadable (usedSpace ),
1028+ DisplayUtils .bytesToHumanReadable (totalSpace )));
1029+ }
9291030 }
9301031
931- mQuotaProgressBar .setProgress (relative );
1032+ if (mQuotaProgressBar != null ) {
1033+ mQuotaProgressBar .setProgress (relative );
1034+ }
1035+
1036+ if (sidebarQuotaProgressBar != null ) {
1037+ sidebarQuotaProgressBar .setProgress (relative );
1038+ }
9321039
9331040 if (relative < RELATIVE_THRESHOLD_WARNING ) {
934- viewThemeUtils .material .colorProgressBar (mQuotaProgressBar , ColorRole .PRIMARY );
1041+ if (mQuotaProgressBar != null ) {
1042+ viewThemeUtils .material .colorProgressBar (mQuotaProgressBar , ColorRole .PRIMARY );
1043+ }
1044+ if (sidebarQuotaProgressBar != null ) {
1045+ viewThemeUtils .material .colorProgressBar (sidebarQuotaProgressBar , ColorRole .PRIMARY );
1046+ }
9351047 } else {
936- viewThemeUtils .material .colorProgressBar (
937- mQuotaProgressBar ,
938- getResources ().getColor (R .color .infolevel_warning , null )
939- );
1048+ if (mQuotaProgressBar != null ) {
1049+ viewThemeUtils .material .colorProgressBar (
1050+ mQuotaProgressBar ,
1051+ getResources ().getColor (R .color .infolevel_warning , null )
1052+ );
1053+ }
1054+
1055+ if (sidebarQuotaProgressBar != null ) {
1056+ viewThemeUtils .material .colorProgressBar (
1057+ sidebarQuotaProgressBar ,
1058+ getResources ().getColor (R .color .infolevel_warning , null )
1059+ );
1060+ }
9401061 }
9411062
9421063 updateQuotaLink ();
9431064 showQuota (true );
9441065 }
9451066
9461067 private void updateQuotaLink () {
947- if (mQuotaTextLink != null ) {
948- if (MDMConfig .INSTANCE .externalSiteSupport (this )) {
949- List <ExternalLink > quotas = externalLinksProvider .getExternalLink (ExternalLinkType .QUOTA );
1068+ if (MDMConfig .INSTANCE .externalSiteSupport (this )) {
1069+ List <ExternalLink > quotas = externalLinksProvider .getExternalLink (ExternalLinkType .QUOTA );
9501070
951- float density = getResources ().getDisplayMetrics ().density ;
952- final int size = Math .round (24 * density );
1071+ float density = getResources ().getDisplayMetrics ().density ;
1072+ final int size = Math .round (24 * density );
9531073
954- if (!quotas .isEmpty ()) {
955- final ExternalLink firstQuota = quotas .get (0 );
1074+ if (!quotas .isEmpty ()) {
1075+ final ExternalLink firstQuota = quotas .get (0 );
1076+ if (mQuotaTextLink != null ) {
9561077 mQuotaTextLink .setText (firstQuota .getName ());
9571078 mQuotaTextLink .setClickable (true );
9581079 mQuotaTextLink .setVisibility (View .VISIBLE );
@@ -973,12 +1094,47 @@ private void updateQuotaLink() {
9731094 R .drawable .ic_link );
9741095 return Unit .INSTANCE ;
9751096 });
976- } else {
977- mQuotaTextLink .setVisibility (View .GONE );
1097+ }
1098+ if (sidebarQuotaTextLink != null ) {
1099+ sidebarQuotaTextLink .setText (firstQuota .getName ());
1100+ sidebarQuotaTextLink .setClickable (true );
1101+ sidebarQuotaTextLink .setVisibility (View .VISIBLE );
1102+ sidebarQuotaTextLink .setOnClickListener (v -> {
1103+ Intent externalWebViewIntent = new Intent (getApplicationContext (), ExternalSiteWebView .class );
1104+ externalWebViewIntent .putExtra (ExternalSiteWebView .EXTRA_TITLE , firstQuota .getName ());
1105+ externalWebViewIntent .putExtra (ExternalSiteWebView .EXTRA_URL , firstQuota .getUrl ());
1106+ externalWebViewIntent .putExtra (ExternalSiteWebView .EXTRA_SHOW_SIDEBAR , true );
1107+ startActivity (externalWebViewIntent );
1108+ });
1109+
1110+ Target <Drawable > quotaTarget = createQuotaDrawableTarget (size , sidebarQuotaTextLink );
1111+ getClientRepository ().getNextcloudClient (nextcloudClient -> {
1112+ GlideHelper .INSTANCE .loadIntoTarget (this ,
1113+ nextcloudClient ,
1114+ firstQuota .getIconUrl (),
1115+ quotaTarget ,
1116+ R .drawable .ic_link );
1117+ return Unit .INSTANCE ;
1118+ });
9781119 }
9791120 } else {
1121+ if (mQuotaTextLink != null ) {
1122+ mQuotaTextLink .setVisibility (View .GONE );
1123+ }
1124+
1125+ if (sidebarQuotaTextLink != null ) {
1126+ sidebarQuotaTextLink .setVisibility (View .GONE );
1127+ }
1128+
1129+ }
1130+ } else {
1131+ if (mQuotaTextLink != null ) {
9801132 mQuotaTextLink .setVisibility (View .GONE );
9811133 }
1134+
1135+ if (sidebarQuotaTextLink != null ) {
1136+ sidebarQuotaTextLink .setVisibility (View .GONE );
1137+ }
9821138 }
9831139 }
9841140
@@ -1189,6 +1345,29 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
11891345 if (mDrawerToggle != null ) {
11901346 mDrawerToggle .onConfigurationChanged (newConfig );
11911347 }
1348+
1349+ hideOrShowSidebar ();
1350+ }
1351+
1352+ private void hideOrShowSidebar () {
1353+ if (isDrawerLayout ()) {
1354+ if (getSupportActionBar () != null ) {
1355+ getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
1356+ }
1357+
1358+ if (sidebarMenu != null ) {
1359+ sidebarMenu .setVisibility (View .GONE );
1360+ }
1361+ } else {
1362+ if (getSupportActionBar () != null ) {
1363+ getSupportActionBar ().setDisplayHomeAsUpEnabled (false );
1364+ }
1365+
1366+ if (sidebarMenu != null ) {
1367+ sidebarMenu .setVisibility (View .VISIBLE );
1368+ }
1369+ closeDrawer ();
1370+ }
11921371 }
11931372
11941373 public void addOnBackPressedCallback () {
@@ -1256,6 +1435,22 @@ private View findQuotaViewById(int id) {
12561435 }
12571436 }
12581437
1438+ /**
1439+ * Quota view can be either at navigation bottom or header on sidebar
1440+ *
1441+ * @param id the view's id
1442+ * @return The view if found or <code>null</code> otherwise.
1443+ */
1444+ private View findSidebarQuotaViewById (int id ) {
1445+ View v = ((NavigationView ) findViewById (R .id .sidebar_view )).getHeaderView (0 ).findViewById (id );
1446+
1447+ if (v != null ) {
1448+ return v ;
1449+ } else {
1450+ return findViewById (id );
1451+ }
1452+ }
1453+
12591454 /**
12601455 * restart helper method which is called after a changing the current account.
12611456 */
@@ -1507,4 +1702,8 @@ public boolean isMenuItemIdBelongsToSearchType() {
15071702 menuItemId == R .id .nav_recently_modified ||
15081703 menuItemId == R .id .nav_gallery ;
15091704 }
1705+
1706+ protected boolean isDrawerLayout () {
1707+ return getResources ().getBoolean (R .bool .is_support_drawer );
1708+ }
15101709}
0 commit comments