|
@@ -22,16 +22,23 @@
|
|
|
|
|
|
package com.owncloud.android.ui.activity;
|
|
package com.owncloud.android.ui.activity;
|
|
|
|
|
|
|
|
+import android.animation.AnimatorInflater;
|
|
|
|
+import android.annotation.SuppressLint;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Bitmap;
|
|
-import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
+import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
|
|
+import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
+import com.google.android.material.appbar.AppBarLayout;
|
|
|
|
+import com.google.android.material.button.MaterialButton;
|
|
|
|
+import com.google.android.material.card.MaterialCardView;
|
|
|
|
+import com.google.android.material.textview.MaterialTextView;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
@@ -40,15 +47,25 @@ import com.owncloud.android.utils.ThemeUtils;
|
|
import androidx.annotation.StringRes;
|
|
import androidx.annotation.StringRes;
|
|
import androidx.appcompat.app.ActionBar;
|
|
import androidx.appcompat.app.ActionBar;
|
|
import androidx.appcompat.widget.Toolbar;
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
+import androidx.core.content.ContextCompat;
|
|
|
|
+import androidx.core.view.ViewCompat;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Base class providing toolbar registration functionality, see {@link #setupToolbar()}.
|
|
|
|
|
|
+ * Base class providing toolbar registration functionality, see {@link #setupToolbar(boolean)}.
|
|
*/
|
|
*/
|
|
public abstract class ToolbarActivity extends BaseActivity {
|
|
public abstract class ToolbarActivity extends BaseActivity {
|
|
|
|
+ protected MaterialButton mMenuButton;
|
|
|
|
+ protected MaterialTextView mSearchText;
|
|
|
|
+ protected MaterialButton mSwitchAccountButton;
|
|
|
|
+
|
|
|
|
+ private AppBarLayout mAppBar;
|
|
|
|
+ private RelativeLayout mDefaultToolbar;
|
|
|
|
+ private MaterialCardView mHomeSearchToolbar;
|
|
private ImageView mPreviewImage;
|
|
private ImageView mPreviewImage;
|
|
private FrameLayout mPreviewImageContainer;
|
|
private FrameLayout mPreviewImageContainer;
|
|
private LinearLayout mInfoBox;
|
|
private LinearLayout mInfoBox;
|
|
private TextView mInfoBoxMessage;
|
|
private TextView mInfoBoxMessage;
|
|
|
|
+ private boolean isHomeSearchToolbarShow = false;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -56,15 +73,25 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Toolbar setup that must be called in implementer's {@link #onCreate} after {@link #setContentView} if they
|
|
|
|
- * want to use the toolbar.
|
|
|
|
|
|
+ * Toolbar setup that must be called in implementer's {@link #onCreate} after {@link #setContentView} if they want
|
|
|
|
+ * to use the toolbar.
|
|
*/
|
|
*/
|
|
- protected void setupToolbar(boolean useBackgroundImage) {
|
|
|
|
- int primaryColor = ThemeUtils.primaryAppbarColor(this);
|
|
|
|
|
|
+ protected void setupToolbar(boolean isHomeSearchToolbarShow) {
|
|
int fontColor = ThemeUtils.appBarPrimaryFontColor(this);
|
|
int fontColor = ThemeUtils.appBarPrimaryFontColor(this);
|
|
|
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
setSupportActionBar(toolbar);
|
|
setSupportActionBar(toolbar);
|
|
|
|
+ ThemeUtils.colorStatusBar(this);
|
|
|
|
+
|
|
|
|
+ mAppBar = findViewById(R.id.appbar);
|
|
|
|
+ mDefaultToolbar = findViewById(R.id.default_toolbar);
|
|
|
|
+ mHomeSearchToolbar = findViewById(R.id.home_toolbar);
|
|
|
|
+ mMenuButton = findViewById(R.id.menu_button);
|
|
|
|
+ mSearchText = findViewById(R.id.search_text);
|
|
|
|
+ mSwitchAccountButton = findViewById(R.id.switch_account_button);
|
|
|
|
+
|
|
|
|
+ this.isHomeSearchToolbarShow = isHomeSearchToolbarShow;
|
|
|
|
+ updateActionBarTitleAndHomeButton(null);
|
|
|
|
|
|
mInfoBox = findViewById(R.id.info_box);
|
|
mInfoBox = findViewById(R.id.info_box);
|
|
mInfoBoxMessage = findViewById(R.id.info_box_message);
|
|
mInfoBoxMessage = findViewById(R.id.info_box_message);
|
|
@@ -72,8 +99,6 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|
mPreviewImage = findViewById(R.id.preview_image);
|
|
mPreviewImage = findViewById(R.id.preview_image);
|
|
mPreviewImageContainer = findViewById(R.id.preview_image_frame);
|
|
mPreviewImageContainer = findViewById(R.id.preview_image_frame);
|
|
|
|
|
|
- ThemeUtils.colorStatusBar(this);
|
|
|
|
-
|
|
|
|
if (toolbar.getOverflowIcon() != null) {
|
|
if (toolbar.getOverflowIcon() != null) {
|
|
ThemeUtils.tintDrawable(toolbar.getOverflowIcon(), fontColor);
|
|
ThemeUtils.tintDrawable(toolbar.getOverflowIcon(), fontColor);
|
|
}
|
|
}
|
|
@@ -81,10 +106,6 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|
if (toolbar.getNavigationIcon() != null) {
|
|
if (toolbar.getNavigationIcon() != null) {
|
|
ThemeUtils.tintDrawable(toolbar.getNavigationIcon(), fontColor);
|
|
ThemeUtils.tintDrawable(toolbar.getNavigationIcon(), fontColor);
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (!useBackgroundImage) {
|
|
|
|
- toolbar.setBackgroundColor(primaryColor);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public void setupToolbar() {
|
|
public void setupToolbar() {
|
|
@@ -95,17 +116,57 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|
* Updates title bar and home buttons (state and icon).
|
|
* Updates title bar and home buttons (state and icon).
|
|
*/
|
|
*/
|
|
protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
|
|
protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
|
|
- String title = ThemeUtils.getDefaultDisplayNameForRootFolder(this); // default
|
|
|
|
- boolean inRoot;
|
|
|
|
-
|
|
|
|
- // choose the appropriate title
|
|
|
|
- inRoot = chosenFile == null ||
|
|
|
|
- (chosenFile.isFolder() && chosenFile.getParentId() == FileDataStorageManager.ROOT_PARENT_ID);
|
|
|
|
- if (!inRoot) {
|
|
|
|
- title = chosenFile.getFileName();
|
|
|
|
- }
|
|
|
|
|
|
+ String title;
|
|
|
|
+ boolean isRoot = isRoot(chosenFile);
|
|
|
|
|
|
|
|
+ title = isRoot ? ThemeUtils.getDefaultDisplayNameForRootFolder(this) : chosenFile.getFileName();
|
|
updateActionBarTitleAndHomeButtonByString(title);
|
|
updateActionBarTitleAndHomeButtonByString(title);
|
|
|
|
+
|
|
|
|
+ if (mAppBar != null) {
|
|
|
|
+ showHomeSearchToolbar(title, isRoot);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void showSearchView() {
|
|
|
|
+ if (isHomeSearchToolbarShow) {
|
|
|
|
+ showHomeSearchToolbar(false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void hideSearchView(OCFile chosenFile) {
|
|
|
|
+ if (isHomeSearchToolbarShow) {
|
|
|
|
+ showHomeSearchToolbar(isRoot(chosenFile));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void showHomeSearchToolbar(String title, boolean isRoot) {
|
|
|
|
+ showHomeSearchToolbar(isHomeSearchToolbarShow && isRoot);
|
|
|
|
+ mSearchText.setText(getString(R.string.appbar_search_in, title));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @SuppressLint("PrivateResource")
|
|
|
|
+ private void showHomeSearchToolbar(boolean isShow) {
|
|
|
|
+ if (isShow) {
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
+ mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(),
|
|
|
|
+ R.animator.appbar_elevation_off));
|
|
|
|
+ } else {
|
|
|
|
+ ViewCompat.setElevation(mAppBar, 0);
|
|
|
|
+ }
|
|
|
|
+ mDefaultToolbar.setVisibility(View.GONE);
|
|
|
|
+ mHomeSearchToolbar.setVisibility(View.VISIBLE);
|
|
|
|
+ ThemeUtils.colorStatusBar(this, ContextCompat.getColor(this, R.color.bg_default));
|
|
|
|
+ } else {
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
+ mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(),
|
|
|
|
+ R.animator.appbar_elevation_on));
|
|
|
|
+ } else {
|
|
|
|
+ ViewCompat.setElevation(mAppBar, getResources().getDimension(R.dimen.design_appbar_elevation));
|
|
|
|
+ }
|
|
|
|
+ mDefaultToolbar.setVisibility(View.VISIBLE);
|
|
|
|
+ mHomeSearchToolbar.setVisibility(View.GONE);
|
|
|
|
+ ThemeUtils.colorStatusBar(this);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -192,6 +253,6 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|
* get the toolbar's preview image view.
|
|
* get the toolbar's preview image view.
|
|
*/
|
|
*/
|
|
public ImageView getPreviewImageView() {
|
|
public ImageView getPreviewImageView() {
|
|
- return mPreviewImage;
|
|
|
|
|
|
+ return mPreviewImage;
|
|
}
|
|
}
|
|
}
|
|
}
|