New header (show avatar)

This commit is contained in:
stefan-niedermann 2019-09-21 21:42:02 +02:00
parent 39e15cef67
commit 9a161c1fea
5 changed files with 85 additions and 39 deletions

View file

@ -36,6 +36,9 @@ dependencies {
implementation 'com.yydcdut:markdown-processor:0.1.3'
implementation 'com.yydcdut:rxmarkdown-wrapper:0.1.3'
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
implementation 'com.jakewharton:butterknife:10.2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'

View file

@ -19,6 +19,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -27,6 +28,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;
@ -36,6 +38,8 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
@ -85,6 +89,10 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
Toolbar toolbar;
@BindView(R.id.drawerLayout)
DrawerLayout drawerLayout;
@BindView(R.id.current_account_image)
AppCompatImageView currentAccountImage;
@BindView(R.id.header_view)
RelativeLayout headerView;
@BindView(R.id.account)
TextView account;
@BindView(R.id.swiperefreshlayout)
@ -198,13 +206,13 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.syncState();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(SAVED_STATE_NAVIGATION_SELECTION, navigationSelection);
outState.putString(SAVED_STATE_NAVIGATION_ADAPTER_SLECTION, adapterCategories.getSelectedItem());
@ -408,7 +416,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
this.updateUsernameInDrawer();
final NotesListViewActivity that = this;
this.account.setOnClickListener((View v) -> {
this.headerView.setOnClickListener((View v) -> {
Intent settingsIntent = new Intent(that, SettingsActivity.class);
startActivityForResult(settingsIntent, server_settings);
});
@ -634,13 +642,19 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
String username = preferences.getString(SettingsActivity.SETTINGS_USERNAME, SettingsActivity.DEFAULT_SETTINGS);
String url = preferences.getString(SettingsActivity.SETTINGS_URL, SettingsActivity.DEFAULT_SETTINGS);
if (url != null) {
url = url.replace("https://", "").replace("http://", "");
String croppedUrl = url.replace("https://", "").replace("http://", "");
if (!SettingsActivity.DEFAULT_SETTINGS.equals(username) && !SettingsActivity.DEFAULT_SETTINGS.equals(url)) {
this.account.setText(username + "@" + croppedUrl.substring(0, croppedUrl.length() - 1));
Glide
.with(this)
.load(url + "/index.php/avatar/" + Uri.encode(username) + "/64")
.error(R.mipmap.ic_launcher_round)
.apply(RequestOptions.circleCropTransform())
.into(this.currentAccountImage);
}
} else {
Log.w(NotesListViewActivity.class.getSimpleName(), "url is null");
}
if (!SettingsActivity.DEFAULT_SETTINGS.equals(username) && !SettingsActivity.DEFAULT_SETTINGS.equals(url)) {
this.account.setText(username + "@" + url.substring(0, url.length() - 1));
}
}
@Override

View file

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
android:fitsSystemWindows="true"
tools:openDrawer="left">
<include
layout="@layout/activity_notes_list_view"
@ -27,50 +29,75 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
<RelativeLayout
android:id="@+id/header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:padding="10dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:orientation="horizontal"
android:gravity="bottom">
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="24dp"
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="164dp"
android:contentDescription="@null"
android:scaleType="centerCrop"
app:srcCompat="@drawable/background" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/current_account_image"
android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size"
android:layout_gravity="center_vertical"
android:src="@mipmap/ic_launcher"
android:contentDescription="@string/app_name" />
android:layout_marginStart="@dimen/header_padding"
android:layout_marginLeft="@dimen/header_padding"
android:layout_marginTop="46dp"
android:contentDescription="@string/app_name"
app:srcCompat="@mipmap/ic_launcher" />
<androidx.appcompat.widget.LinearLayoutCompat
<TextView
android:id="@+id/app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="12dp"
android:paddingStart="12dp"
android:paddingTop="24dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
android:layout_below="@id/current_account_image"
android:layout_marginTop="6dp"
android:layout_marginStart="@dimen/header_padding"
android:layout_marginLeft="@dimen/header_padding"
android:layout_marginEnd="@dimen/header_padding"
android:layout_marginRight="@dimen/header_padding"
android:ellipsize="end"
android:shadowColor="@color/fg_default"
android:shadowDx="0.5"
android:shadowDy="0"
android:shadowRadius="2"
android:text="@string/app_name_long"
android:textColor="@color/fg_contrast"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/account"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.appcompat.widget.LinearLayoutCompat>
</LinearLayout>
<TextView
android:id="@+id/account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/app_name"
android:layout_marginStart="@dimen/header_padding"
android:layout_marginLeft="@dimen/header_padding"
android:layout_marginEnd="@dimen/header_padding"
android:layout_marginRight="@dimen/header_padding"
android:ellipsize="end"
android:maxLines="1"
android:shadowColor="@color/fg_default"
android:shadowDx="0.5"
android:shadowDy="0"
android:shadowRadius="2"
android:textColor="@color/fg_contrast"
android:textSize="12sp"
tools:text="user@nextcloud.example.com"/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/navigationList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:paddingTop="8dp"
android:paddingBottom="8dp"
app:layoutManager="LinearLayoutManager" />
@ -84,7 +111,6 @@
android:id="@+id/navigationMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:paddingTop="8dp"
android:paddingBottom="8dp"
app:layoutManager="LinearLayoutManager" />

View file

@ -32,4 +32,6 @@
<dimen name="widget_note_list_fav_icon_width">26dp</dimen>
<dimen name="widget_note_list_fav_icon_height">20dp</dimen>
<dimen name="header_padding">16dp</dimen>
<dimen name="avatar_size">64dp</dimen>
</resources>

View file

@ -2,6 +2,7 @@
<resources>
<string name="app_name">Notes</string>
<string name="app_name_long">Nextcloud Notes</string>
<string name="no_notes">No notes yet</string>
<string name="label_all_notes">All notes</string>
<string name="label_favorites">Favorites</string>