@@ -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 mSidebarQuotaView ;
191+
192+ /**
193+ * progress bar of the quota view on sidebar.
194+ */
195+ private LinearProgressIndicator mSidebarQuotaProgressBar ;
196+
197+ /**
198+ * text view of the quota view on sidebar.
199+ */
200+ private TextView mSidebarQuotaTextPercentage ;
201+ private TextView mSidebarQuotaTextLink ;
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 mSidebarMenu ;
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 (mSidebarMenu == null ) {
266+ mSidebarMenu = findViewById (R .id .sidebar_menu );
267+ }
268+
246269 if (drawerNavigationView == null ) {
247270 drawerNavigationView = findViewById (R .id .nav_view );
248271 }
249272
273+ if (mSidebarMenu != null && sidebarNavigationView == null ) {
274+ sidebarNavigationView = mSidebarMenu .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 );
264290
265- if (getSupportActionBar () != null ) {
266- getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
291+ // Setting up drawer header
292+ mNavigationViewHeader = sidebarNavigationView .getHeaderView (0 );
293+ updateHeader ();
294+
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+ mSidebarQuotaView = (LinearLayout ) findSidebarQuotaViewById (R .id .drawer_quota );
463+ mSidebarQuotaProgressBar = (LinearProgressIndicator ) findSidebarQuotaViewById (R .id .drawer_quota_ProgressBar );
464+ mSidebarQuotaTextPercentage = (TextView ) findSidebarQuotaViewById (R .id .drawer_quota_percentage );
465+ mSidebarQuotaTextLink = (TextView ) findSidebarQuotaViewById (R .id .drawer_quota_link );
466+ viewThemeUtils .material .colorProgressBar (mSidebarQuotaProgressBar , ColorRole .PRIMARY );
467+ mSidebarQuotaProgressBar .setTrackStopIndicatorSize (0 );
468+ viewThemeUtils .platform .colorViewBackground (mSidebarQuotaView );
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 );
@@ -903,8 +977,14 @@ protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
903977 private void showQuota (boolean showQuota ) {
904978 if (showQuota ) {
905979 mQuotaView .setVisibility (View .VISIBLE );
980+ if (mSidebarQuotaView != null ) {
981+ mSidebarQuotaView .setVisibility (View .VISIBLE );
982+ }
906983 } else {
907984 mQuotaView .setVisibility (View .GONE );
985+ if (mSidebarQuotaView != null ) {
986+ mSidebarQuotaView .setVisibility (View .GONE );
987+ }
908988 }
909989 }
910990
@@ -921,38 +1001,65 @@ private void setQuotaInformation(long usedSpace, long totalSpace, int relative,
9211001 mQuotaTextPercentage .setText (String .format (
9221002 getString (R .string .drawer_quota_unlimited ),
9231003 DisplayUtils .bytesToHumanReadable (usedSpace )));
1004+
1005+ if (mSidebarQuotaTextPercentage != null ) {
1006+ mSidebarQuotaTextPercentage .setText (String .format (
1007+ getString (R .string .drawer_quota_unlimited ),
1008+ DisplayUtils .bytesToHumanReadable (usedSpace )));
1009+ }
9241010 } else {
9251011 mQuotaTextPercentage .setText (String .format (
9261012 getString (R .string .drawer_quota ),
9271013 DisplayUtils .bytesToHumanReadable (usedSpace ),
9281014 DisplayUtils .bytesToHumanReadable (totalSpace )));
1015+
1016+ if (mSidebarQuotaTextPercentage != null ) {
1017+ mSidebarQuotaTextPercentage .setText (String .format (
1018+ getString (R .string .drawer_quota ),
1019+ DisplayUtils .bytesToHumanReadable (usedSpace ),
1020+ DisplayUtils .bytesToHumanReadable (totalSpace )));
1021+ }
9291022 }
9301023
9311024 mQuotaProgressBar .setProgress (relative );
9321025
1026+ if (mSidebarQuotaProgressBar != null ) {
1027+ mSidebarQuotaProgressBar .setProgress (relative );
1028+ }
1029+
9331030 if (relative < RELATIVE_THRESHOLD_WARNING ) {
9341031 viewThemeUtils .material .colorProgressBar (mQuotaProgressBar , ColorRole .PRIMARY );
1032+ if (mSidebarQuotaProgressBar != null ) {
1033+ viewThemeUtils .material .colorProgressBar (mSidebarQuotaProgressBar , ColorRole .PRIMARY );
1034+ }
9351035 } else {
9361036 viewThemeUtils .material .colorProgressBar (
9371037 mQuotaProgressBar ,
9381038 getResources ().getColor (R .color .infolevel_warning , null )
9391039 );
1040+
1041+ if (mSidebarQuotaProgressBar != null ) {
1042+ viewThemeUtils .material .colorProgressBar (
1043+ mSidebarQuotaProgressBar ,
1044+ getResources ().getColor (R .color .infolevel_warning , null )
1045+ );
1046+ }
9401047 }
9411048
9421049 updateQuotaLink ();
9431050 showQuota (true );
9441051 }
9451052
9461053 private void updateQuotaLink () {
947- if (mQuotaTextLink != null ) {
948- if (MDMConfig .INSTANCE .externalSiteSupport (this )) {
949- List <ExternalLink > quotas = externalLinksProvider .getExternalLink (ExternalLinkType .QUOTA );
1054+ if (MDMConfig .INSTANCE .externalSiteSupport (this )) {
1055+ List <ExternalLink > quotas = externalLinksProvider .getExternalLink (ExternalLinkType .QUOTA );
9501056
951- float density = getResources ().getDisplayMetrics ().density ;
952- final int size = Math .round (24 * density );
1057+ float density = getResources ().getDisplayMetrics ().density ;
1058+ final int size = Math .round (24 * density );
9531059
954- if (!quotas .isEmpty ()) {
955- final ExternalLink firstQuota = quotas .get (0 );
1060+ if (!quotas .isEmpty ()) {
1061+ final ExternalLink firstQuota = quotas .get (0 );
1062+ if (mQuotaTextLink != null ) {
9561063 mQuotaTextLink .setText (firstQuota .getName ());
9571064 mQuotaTextLink .setClickable (true );
9581065 mQuotaTextLink .setVisibility (View .VISIBLE );
@@ -973,12 +1080,47 @@ private void updateQuotaLink() {
9731080 R .drawable .ic_link );
9741081 return Unit .INSTANCE ;
9751082 });
976- } else {
977- mQuotaTextLink .setVisibility (View .GONE );
1083+ }
1084+ if (mSidebarQuotaTextLink != null ) {
1085+ mSidebarQuotaTextLink .setText (firstQuota .getName ());
1086+ mSidebarQuotaTextLink .setClickable (true );
1087+ mSidebarQuotaTextLink .setVisibility (View .VISIBLE );
1088+ mSidebarQuotaTextLink .setOnClickListener (v -> {
1089+ Intent externalWebViewIntent = new Intent (getApplicationContext (), ExternalSiteWebView .class );
1090+ externalWebViewIntent .putExtra (ExternalSiteWebView .EXTRA_TITLE , firstQuota .getName ());
1091+ externalWebViewIntent .putExtra (ExternalSiteWebView .EXTRA_URL , firstQuota .getUrl ());
1092+ externalWebViewIntent .putExtra (ExternalSiteWebView .EXTRA_SHOW_SIDEBAR , true );
1093+ startActivity (externalWebViewIntent );
1094+ });
1095+
1096+ Target <Drawable > quotaTarget = createQuotaDrawableTarget (size , mSidebarQuotaTextLink );
1097+ getClientRepository ().getNextcloudClient (nextcloudClient -> {
1098+ GlideHelper .INSTANCE .loadIntoTarget (this ,
1099+ nextcloudClient ,
1100+ firstQuota .getIconUrl (),
1101+ quotaTarget ,
1102+ R .drawable .ic_link );
1103+ return Unit .INSTANCE ;
1104+ });
9781105 }
9791106 } else {
1107+ if (mQuotaTextLink != null ) {
1108+ mQuotaTextLink .setVisibility (View .GONE );
1109+ }
1110+
1111+ if (mSidebarQuotaTextLink != null ) {
1112+ mSidebarQuotaTextLink .setVisibility (View .GONE );
1113+ }
1114+
1115+ }
1116+ } else {
1117+ if (mQuotaTextLink != null ) {
9801118 mQuotaTextLink .setVisibility (View .GONE );
9811119 }
1120+
1121+ if (mSidebarQuotaTextLink != null ) {
1122+ mSidebarQuotaTextLink .setVisibility (View .GONE );
1123+ }
9821124 }
9831125 }
9841126
@@ -1189,6 +1331,29 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
11891331 if (mDrawerToggle != null ) {
11901332 mDrawerToggle .onConfigurationChanged (newConfig );
11911333 }
1334+
1335+ hideOrShowSidebar ();
1336+ }
1337+
1338+ private void hideOrShowSidebar () {
1339+ if (isDrawerLayout ()) {
1340+ if (getSupportActionBar () != null ) {
1341+ getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
1342+ }
1343+
1344+ if (mSidebarMenu != null ) {
1345+ mSidebarMenu .setVisibility (View .GONE );
1346+ }
1347+ } else {
1348+ if (getSupportActionBar () != null ) {
1349+ getSupportActionBar ().setDisplayHomeAsUpEnabled (false );
1350+ }
1351+
1352+ if (mSidebarMenu != null ) {
1353+ mSidebarMenu .setVisibility (View .VISIBLE );
1354+ }
1355+ closeDrawer ();
1356+ }
11921357 }
11931358
11941359 public void addOnBackPressedCallback () {
@@ -1256,6 +1421,22 @@ private View findQuotaViewById(int id) {
12561421 }
12571422 }
12581423
1424+ /**
1425+ * Quota view can be either at navigation bottom or header on sidebar
1426+ *
1427+ * @param id the view's id
1428+ * @return The view if found or <code>null</code> otherwise.
1429+ */
1430+ private View findSidebarQuotaViewById (int id ) {
1431+ View v = ((NavigationView ) findViewById (R .id .sidebar_view )).getHeaderView (0 ).findViewById (id );
1432+
1433+ if (v != null ) {
1434+ return v ;
1435+ } else {
1436+ return findViewById (id );
1437+ }
1438+ }
1439+
12591440 /**
12601441 * restart helper method which is called after a changing the current account.
12611442 */
@@ -1507,4 +1688,8 @@ public boolean isMenuItemIdBelongsToSearchType() {
15071688 menuItemId == R .id .nav_recently_modified ||
15081689 menuItemId == R .id .nav_gallery ;
15091690 }
1691+
1692+ protected boolean isDrawerLayout () {
1693+ return getResources ().getBoolean (R .bool .is_support_drawer );
1694+ }
15101695}
0 commit comments