Refactor toolbar

Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
Stefan Niedermann 2021-10-19 10:10:16 +02:00
parent 14e95c67b1
commit bdc4f3c303
11 changed files with 121 additions and 117 deletions

View file

@ -31,7 +31,7 @@ public class AppendToNoteActivity extends MainActivity {
} else {
Log.e(TAG, "SupportActionBar is null. Expected toolbar to be present to set a title.");
}
binding.activityNotesListView.toolbar.setSubtitle(receivedText);
binding.activityNotesListView.searchToolbar.setSubtitle(receivedText);
}
@Override

View file

@ -1,10 +1,23 @@
package it.niedermann.owncloud.notes.main;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.O;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive;
import static it.niedermann.owncloud.notes.NotesApplication.isGridViewEnabled;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.getSecondaryForegroundColorDependingOnTheme;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.DEFAULT_CATEGORY;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.FAVORITES;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.RECENT;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.UNCATEGORIZED;
import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient;
import static it.niedermann.owncloud.notes.shared.util.SSOUtil.askForNewAccount;
import android.accounts.NetworkErrorException;
import android.animation.AnimatorInflater;
import android.app.SearchManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri;
@ -15,6 +28,7 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.SearchView;
@ -23,7 +37,6 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.view.GravityCompat;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.selection.SelectionTracker;
@ -46,10 +59,7 @@ import com.nextcloud.android.sso.exceptions.UnknownErrorException;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import java.net.HttpURLConnection;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
@ -82,7 +92,6 @@ import it.niedermann.owncloud.notes.persistence.CapabilitiesClient;
import it.niedermann.owncloud.notes.persistence.CapabilitiesWorker;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.shared.model.Capabilities;
import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod;
import it.niedermann.owncloud.notes.shared.model.IResponseCallback;
import it.niedermann.owncloud.notes.shared.model.NavigationCategory;
@ -91,20 +100,6 @@ import it.niedermann.owncloud.notes.shared.util.CustomAppGlideModule;
import it.niedermann.owncloud.notes.shared.util.NoteUtil;
import it.niedermann.owncloud.notes.shared.util.ShareUtil;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.O;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive;
import static it.niedermann.owncloud.notes.NotesApplication.isGridViewEnabled;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.getSecondaryForegroundColorDependingOnTheme;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.DEFAULT_CATEGORY;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.FAVORITES;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.RECENT;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.UNCATEGORIZED;
import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient;
import static it.niedermann.owncloud.notes.shared.util.SSOUtil.askForNewAccount;
public class MainActivity extends LockedActivity implements NoteClickListener, AccountPickerListener, AccountSwitcherListener, CategoryDialogFragment.CategoryDialogListener {
private static final String TAG = MainActivity.class.getSimpleName();
@ -389,16 +384,19 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
}
private void setupToolbars() {
setSupportActionBar(binding.activityNotesListView.toolbar);
setSupportActionBar(binding.activityNotesListView.searchToolbar);
activityBinding.homeToolbar.setOnClickListener((v) -> {
if (activityBinding.toolbar.getVisibility() == GONE) {
if (activityBinding.searchToolbar.getVisibility() == GONE) {
updateToolbars(true);
}
});
activityBinding.menuButton.setOnClickListener((v) -> binding.drawerLayout.openDrawer(GravityCompat.START));
final var toggle = new ActionBarDrawerToggle(this, binding.drawerLayout, activityBinding.homeToolbar, 0, 0);
binding.drawerLayout.addDrawerListener(toggle);
toggle.syncState();
activityBinding.searchView.setOnCloseListener(() -> {
if (activityBinding.toolbar.getVisibility() == VISIBLE && TextUtils.isEmpty(activityBinding.searchView.getQuery())) {
if (activityBinding.searchToolbar.getVisibility() == VISIBLE && TextUtils.isEmpty(activityBinding.searchView.getQuery())) {
updateToolbars(false);
return true;
}
@ -578,7 +576,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
@Override
public void applyBrand(int mainColor, int textColor) {
applyBrandToPrimaryToolbar(activityBinding.appBar, activityBinding.toolbar);
applyBrandToPrimaryToolbar(activityBinding.appBar, activityBinding.searchToolbar);
applyBrandToFAB(mainColor, textColor, activityBinding.fabCreate);
binding.headerView.setBackgroundColor(mainColor);
@ -597,7 +595,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
@Override
public boolean onSupportNavigateUp() {
if (activityBinding.toolbar.getVisibility() == VISIBLE) {
if (activityBinding.searchToolbar.getVisibility() == VISIBLE) {
updateToolbars(false);
return true;
} else {
@ -697,7 +695,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
runOnUiThread(() -> status$.observe(this, (status) -> {
importSnackbar.show();
Log.v(TAG, "Status: " + status.count + " of " + status.total);
if(status.count > 0) {
if (status.count > 0) {
importSnackbar.setText(getString(R.string.progress_import, status.count + 1, status.total));
}
}));
@ -750,7 +748,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
@Override
public void onBackPressed() {
if (activityBinding.toolbar.getVisibility() == VISIBLE) {
if (activityBinding.searchToolbar.getVisibility() == VISIBLE) {
updateToolbars(false);
} else if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) {
binding.drawerLayout.closeDrawer(GravityCompat.START);
@ -761,10 +759,10 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
private void updateToolbars(boolean enableSearch) {
activityBinding.homeToolbar.setVisibility(enableSearch ? GONE : VISIBLE);
activityBinding.toolbar.setVisibility(enableSearch ? VISIBLE : GONE);
activityBinding.searchToolbar.setVisibility(enableSearch ? VISIBLE : GONE);
activityBinding.appBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(activityBinding.appBar.getContext(), enableSearch
? R.animator.appbar_elevation_on
: R.animator.appbar_elevation_off));
? R.animator.appbar_elevation_on
: R.animator.appbar_elevation_off));
if (enableSearch) {
activityBinding.searchView.setIconified(false);
fabCreate.show();

View file

@ -28,9 +28,9 @@ public class SingleNoteWidgetConfigurationActivity extends MainActivity {
setResult(Activity.RESULT_CANCELED);
fabCreate.setVisibility(View.GONE);
final var toolbar = binding.activityNotesListView.toolbar;
final var searchToolbar = binding.activityNotesListView.searchToolbar;
final var swipeRefreshLayout = binding.activityNotesListView.swiperefreshlayout;
toolbar.setTitle(R.string.activity_select_single_note);
searchToolbar.setTitle(R.string.activity_select_single_note);
swipeRefreshLayout.setEnabled(false);
swipeRefreshLayout.setRefreshing(false);
}

View file

@ -15,6 +15,8 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginStart="@dimen/spacer_activity_sides"
android:layout_marginEnd="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:titleMarginStart="0dp"

View file

@ -15,6 +15,8 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginStart="@dimen/spacer_activity_sides"
android:layout_marginEnd="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:titleMarginStart="0dp"
@ -24,7 +26,7 @@
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container_view"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:background="?attr/colorPrimary" />
</LinearLayout>

View file

@ -11,6 +11,8 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginStart="@dimen/spacer_activity_sides"
android:layout_marginEnd="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
app:elevation="4dp"
app:titleMarginStart="0dp"

View file

@ -16,6 +16,8 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginStart="@dimen/spacer_activity_sides"
android:layout_marginEnd="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:title="@string/action_formatting_help"

View file

@ -16,6 +16,8 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginStart="@dimen/spacer_activity_sides"
android:layout_marginEnd="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:title="@string/manage_accounts"

View file

@ -17,91 +17,91 @@
android:layout_height="?attr/actionBarSize"
app:elevation="0dp">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:titleMarginStart="0dp"
tools:title="@string/app_name">
android:layout_height="wrap_content">
<androidx.appcompat.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.card.MaterialCardView
android:id="@+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacer_1x"
android:layout_marginTop="@dimen/spacer_1hx"
android:layout_marginEnd="@dimen/spacer_1x"
android:layout_marginBottom="@dimen/spacer_1hx"
app:cardBackgroundColor="@color/appbar"
app:cardCornerRadius="@dimen/spacer_4x"
app:cardElevation="2dp"
app:strokeWidth="0dp">
<LinearLayout
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:layout_marginStart="@dimen/spacer_activity_sides"
android:layout_marginTop="@dimen/spacer_1hx"
android:layout_marginEnd="@dimen/spacer_activity_sides"
android:layout_marginBottom="@dimen/spacer_1hx"
app:cardBackgroundColor="@color/appbar"
app:cardCornerRadius="@dimen/spacer_4x"
app:cardElevation="2dp"
app:strokeWidth="0dp">
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/menu_button"
android:layout_width="wrap_content"
<androidx.appcompat.widget.Toolbar
android:id="@+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:paddingStart="@dimen/spacer_1x"
android:paddingTop="@dimen/spacer_2x"
android:paddingEnd="@dimen/spacer_1x"
android:paddingBottom="@dimen/spacer_2x"
android:tint="?attr/colorAccent"
app:srcCompat="@drawable/ic_baseline_menu_24" />
android:orientation="horizontal"
app:contentInsetStartWithNavigation="0dp"
app:titleMarginStart="0dp">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/search_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/spacer_1x"
android:layout_marginEnd="@dimen/spacer_1x"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="start"
android:lines="1"
android:textSize="16sp"
tools:text="@string/search_in_all" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/sorting_method"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center_vertical|end"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/action_sorting_method"
android:padding="@dimen/spacer_2x"
android:tint="?attr/colorAccent"
android:translationX="@dimen/spacer_1x"
app:srcCompat="@drawable/alphabetical_asc" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/search_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="start"
android:lines="1"
android:textSize="16sp"
tools:text="@string/search_in_all" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/launchAccountSwitcher"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center_vertical|end"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="12dp"
android:tooltipText="@string/manage_accounts"
app:srcCompat="@drawable/ic_account_circle_grey_24dp"
tools:targetApi="o" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/sorting_method"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center_vertical|end"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/action_sorting_method"
android:padding="@dimen/spacer_2x"
android:tint="?attr/colorAccent"
android:translationX="@dimen/spacer_1x"
app:srcCompat="@drawable/alphabetical_asc" />
</com.google.android.material.card.MaterialCardView>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/launchAccountSwitcher"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center_vertical|end"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="12dp"
android:tooltipText="@string/manage_accounts"
app:srcCompat="@drawable/ic_account_circle_grey_24dp"
tools:targetApi="o" />
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.card.MaterialCardView>
<androidx.appcompat.widget.Toolbar
android:id="@+id/search_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/spacer_activity_sides"
android:layout_marginEnd="@dimen/spacer_activity_sides"
android:visibility="gone"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:titleMarginStart="0dp"
tools:title="@string/app_name">
<androidx.appcompat.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.appcompat.widget.Toolbar>
</FrameLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout

View file

@ -14,6 +14,8 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginStart="@dimen/spacer_activity_sides"
android:layout_marginEnd="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:title="@string/action_settings"

View file

@ -8,7 +8,6 @@
<item name="colorControlNormal">?attr/colorAccent</item>
<item name="windowActionModeOverlay">true</item>
<item name="actionModeStyle">@style/actionModeStyle</item>
<item name="appBarLayoutStyle">@style/appBarLayoutStyle</item>
<item name="toolbarStyle">@style/toolbarStyle</item>
</style>
@ -19,11 +18,6 @@
<item name="android:textColorHighlight">@color/defaultTextHighlightBackground</item>
</style>
<style name="appBarLayoutStyle" parent="@style/Widget.Design.AppBarLayout">
<item name="android:paddingStart">@dimen/spacer_activity_sides</item>
<item name="android:paddingEnd">@dimen/spacer_activity_sides</item>
</style>
<style name="toolbarStyle" parent="@style/Widget.AppCompat.Toolbar">
<item name="android:background">?attr/colorPrimary</item>
</style>