Эх сурвалжийг харах

Toolbar extension for displaying offline and maintenance status #989

AndyScherzinger 7 жил өмнө
parent
commit
5cc7b5983a

+ 34 - 0
src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java

@@ -32,6 +32,8 @@ import android.support.v7.app.ActionBar;
 import android.support.v7.widget.Toolbar;
 import android.widget.ImageView;
 import android.widget.ProgressBar;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
 
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -44,6 +46,8 @@ import com.owncloud.android.utils.ThemeUtils;
 public abstract class ToolbarActivity extends BaseActivity {
     private ProgressBar mProgressBar;
     private ImageView mPreviewImage;
+    private RelativeLayout mInfoBox;
+    private TextView mInfoBoxMessage;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -69,6 +73,8 @@ public abstract class ToolbarActivity extends BaseActivity {
 
             ThemeUtils.colorToolbarProgressBar(this, ThemeUtils.primaryColor(this, false));
         }
+        mInfoBox = (RelativeLayout) findViewById(R.id.info_box);
+        mInfoBoxMessage = (TextView) findViewById(R.id.info_box_message);
 
         mPreviewImage = findViewById(R.id.preview_image);
 
@@ -146,6 +152,34 @@ public abstract class ToolbarActivity extends BaseActivity {
         return file == null || (file.isFolder() && file.getParentId() == FileDataStorageManager.ROOT_PARENT_ID);
     }
 
+    /**
+     * de-/activates the maintenance message within the toolbar.
+     *
+     * @param active flag is mode should be de-/activated
+     */
+    protected final void setMaintenanceMode(boolean active) {
+        if(active) {
+            mInfoBox.setVisibility(View.VISIBLE);
+            mInfoBoxMessage.setText(R.string.maintenance_mode);
+        } else {
+            mInfoBox.setVisibility(View.GONE);
+        }
+    }
+
+    /**
+     * de-/activates the offline message within the toolbar.
+     *
+     * @param active flag is mode should be de-/activated
+     */
+    protected final void setOfflineMode(boolean active) {
+        if(active) {
+            mInfoBox.setVisibility(View.VISIBLE);
+            mInfoBoxMessage.setText(R.string.offline_mode);
+        } else {
+            mInfoBox.setVisibility(View.GONE);
+        }
+    }
+
     /**
      * Change the indeterminate mode for the toolbar's progress bar.
      *

+ 8 - 0
src/main/res/drawable/ic_information_outline_18dp.xml

@@ -0,0 +1,8 @@
+<!-- drawable/information-outline.xml -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="18dp"
+    android:width="18dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#757575" android:pathData="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z" />
+</vector>

+ 53 - 0
src/main/res/layout/info_box.xml

@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Nextcloud Android client application
+
+  Copyright (C) 2017 Andy Scherzinger
+
+  This program is free software; you can redistribute it and/or
+  modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+  License as published by the Free Software Foundation; either
+  version 3 of the License, or any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+  You should have received a copy of the GNU Affero General Public
+  License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                android:id="@+id/info_box"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_horizontal|bottom"
+                android:background="@color/filelist_icon_backgorund"
+                android:gravity="center"
+                android:padding="@dimen/standard_half_padding"
+                android:visibility="gone">
+
+    <ImageView
+        android:id="@+id/info_box_icon"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        android:src="@drawable/ic_information_outline_18dp"/>
+
+    <TextView
+        android:id="@+id/info_box_message"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:gravity="center"
+        android:layout_toEndOf="@+id/info_box_icon"
+        android:layout_toRightOf="@id/info_box_icon"
+        android:paddingEnd="@dimen/standard_half_margin"
+        android:paddingLeft="@dimen/standard_half_padding"
+        android:paddingRight="@dimen/standard_half_padding"
+        android:paddingStart="@dimen/standard_half_margin"
+        android:paddingTop="@dimen/zero"
+        android:paddingBottom="@dimen/zero"
+        android:text="@string/offline_mode"
+        android:textColor="@color/standard_gray"/>
+
+</RelativeLayout>

+ 4 - 1
src/main/res/layout/toolbar_standard.xml

@@ -19,7 +19,8 @@
   You should have received a copy of the GNU Affero General Public
   License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
-<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<android.support.design.widget.AppBarLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/appbar"
     android:layout_width="match_parent"
@@ -57,4 +58,6 @@
             android:visibility="visible" />
     </RelativeLayout>
 
+    <include layout="@layout/info_box"/>
+
 </android.support.design.widget.AppBarLayout>

+ 4 - 2
src/main/res/layout/toolbar_user_information.xml

@@ -115,7 +115,9 @@
 
             </RelativeLayout>
 
-        </LinearLayout>
+        <include layout="@layout/info_box"/>
+
+    </LinearLayout>
     </RelativeLayout>
 
-</android.support.design.widget.AppBarLayout>
+</android.support.design.widget.AppBarLayout>

+ 1 - 0
src/main/res/values/colors.xml

@@ -32,6 +32,7 @@
     <color name="transparent">#00000000</color>
     <color name="secondaryTextColor">#a0a0a0</color>
     <color name="highlight_textColor_Warning">#e53935</color>
+    <color name="standard_gray">#757575</color>
 
     <!-- Colors -->
     <color name="standard_grey">#757575</color>

+ 1 - 0
src/main/res/values/strings.xml

@@ -537,6 +537,7 @@
     <string name="confirmation_remove_files_alert">Do you really want to delete the selected items?</string>
     <string name="confirmation_remove_folders_alert">Do you really want to delete the selected items and their contents?</string>
     <string name="maintenance_mode">Server in maintenance mode</string>
+    <string name="offline_mode">No internet connection</string>
 
     <string name="uploads_view_upload_status_waiting_for_charging">Awaiting charge</string>
     <string name="actionbar_search">Search</string>