Skip to content

Commit

Permalink
Convert Toolbar to MaterialToolbar and use menu item for account button
Browse files Browse the repository at this point in the history
Signed-off-by: Christine Coenen <[email protected]>
  • Loading branch information
cemrich committed Oct 31, 2023
1 parent 28ab4a8 commit cc1c055
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ protected void onCreate(Bundle savedInstanceState) {

checkNotificationPermissions();

binding.toolbarLayout.avatar.setVisibility(View.VISIBLE);
binding.toolbarLayout.avatar.setOnClickListener((v) -> startActivityForResult(new Intent(this, LoginDialogActivity.class), RESULT_LOGIN));

// Init config --> if nothing is configured start the login dialog.
if (!isUserLoggedIn()) {
startLoginActivity();
Expand Down Expand Up @@ -651,7 +648,8 @@ public void onUserInfoUpdated(OcsUser userInfo) {
String mOc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null);
String avatarUrl = mOc_root_path + "/index.php/avatar/" + Uri.encode(userInfo.getId()) + "/64";

Glide.with(this)
// TODO: invalidate options menu and hack avatar and user name into the menu
/*Glide.with(this)
.load(avatarUrl)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.placeholder(placeHolder)
Expand All @@ -661,7 +659,7 @@ public void onUserInfoUpdated(OcsUser userInfo) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding.toolbarLayout.avatar.setTooltipText(userInfo.getDisplayName());
}
}*/
}
}

Expand Down Expand Up @@ -928,6 +926,9 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
} else if (itemId == R.id.menu_update) {
startSync();
}
else if (itemId == R.id.menu_account) {
startLoginActivity();
}
else if (itemId == R.id.menu_toggleShowOnlyUnread) {
boolean newValue = !mPrefs.getBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, false);
mPrefs.edit().putBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, newValue).commit();
Expand Down
35 changes: 6 additions & 29 deletions News-Android-App/src/main/res/layout/toolbar_layout.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
style="@style/Widget.Material3.Toolbar.Surface"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize" />

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1" />

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">

<ImageButton
android:id="@+id/avatar"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/spacer_1x"
android:background="@null"
android:contentDescription="@string/switch_account"
android:padding="@dimen/spacer_1x"
android:visibility="gone"
app:srcCompat="@drawable/ic_baseline_account_circle_24"
tools:visibility="visible" />
</FrameLayout>
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
</com.google.android.material.appbar.AppBarLayout>
7 changes: 7 additions & 0 deletions News-Android-App/src/main/res/menu/news_reader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always|collapseActionView" />

<item
android:id="@+id/menu_account"
android:enabled="true"
android:icon="@drawable/ic_baseline_account_circle_24"
android:title="@string/switch_account"
app:showAsAction="ifRoom" />

<item
android:id="@+id/menu_download_web_archive"
android:enabled="true"
Expand Down

0 comments on commit cc1c055

Please sign in to comment.