From bdc4f3c30384f5d54ad71ad6d273784a7ca90a1d Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Tue, 19 Oct 2021 10:10:16 +0200 Subject: [PATCH] Refactor toolbar Signed-off-by: Stefan Niedermann --- .../owncloud/notes/AppendToNoteActivity.java | 2 +- .../owncloud/notes/main/MainActivity.java | 60 ++++--- ...SingleNoteWidgetConfigurationActivity.java | 4 +- app/src/main/res/layout/activity_about.xml | 2 + app/src/main/res/layout/activity_edit.xml | 6 +- .../main/res/layout/activity_exception.xml | 2 + .../res/layout/activity_formatting_help.xml | 2 + .../res/layout/activity_manage_accounts.xml | 2 + .../res/layout/activity_notes_list_view.xml | 150 +++++++++--------- .../main/res/layout/activity_preferences.xml | 2 + app/src/main/res/values/styles.xml | 6 - 11 files changed, 121 insertions(+), 117 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java index f8c647c3..4f0fb280 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java @@ -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 diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index 132acc9c..0c2fbb6e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -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(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java index 7324f8b2..eb897def 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java @@ -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); } diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index d96e3026..aebbea0f 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -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" diff --git a/app/src/main/res/layout/activity_edit.xml b/app/src/main/res/layout/activity_edit.xml index fab74018..1fcff7ca 100644 --- a/app/src/main/res/layout/activity_edit.xml +++ b/app/src/main/res/layout/activity_edit.xml @@ -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 @@ + android:layout_height="match_parent" + android:background="?attr/colorPrimary" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_exception.xml b/app/src/main/res/layout/activity_exception.xml index 98aaa0c6..f275a703 100644 --- a/app/src/main/res/layout/activity_exception.xml +++ b/app/src/main/res/layout/activity_exception.xml @@ -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" diff --git a/app/src/main/res/layout/activity_formatting_help.xml b/app/src/main/res/layout/activity_formatting_help.xml index d9becb26..8f3c0ae8 100644 --- a/app/src/main/res/layout/activity_formatting_help.xml +++ b/app/src/main/res/layout/activity_formatting_help.xml @@ -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" diff --git a/app/src/main/res/layout/activity_manage_accounts.xml b/app/src/main/res/layout/activity_manage_accounts.xml index 883ca457..7e01326b 100644 --- a/app/src/main/res/layout/activity_manage_accounts.xml +++ b/app/src/main/res/layout/activity_manage_accounts.xml @@ -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" diff --git a/app/src/main/res/layout/activity_notes_list_view.xml b/app/src/main/res/layout/activity_notes_list_view.xml index a6cddce4..858c3a91 100644 --- a/app/src/main/res/layout/activity_notes_list_view.xml +++ b/app/src/main/res/layout/activity_notes_list_view.xml @@ -17,91 +17,91 @@ android:layout_height="?attr/actionBarSize" app:elevation="0dp"> - + android:layout_height="wrap_content"> - - - - - - + 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"> - + android:orientation="horizontal" + app:contentInsetStartWithNavigation="0dp" + app:titleMarginStart="0dp"> - + - + - - + - + + + + + + + + + + + ?attr/colorAccent true @style/actionModeStyle - @style/appBarLayoutStyle @style/toolbarStyle @@ -19,11 +18,6 @@ @color/defaultTextHighlightBackground - -