profile list: replace FAB with an options menu; add back navigation icon
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 20 Jan 2019 18:57:25 +0000 (18:57 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 20 Jan 2019 18:57:25 +0000 (18:57 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java
app/src/main/res/drawable/ic_add_circle_white_24dp.xml [new file with mode: 0644]
app/src/main/res/layout/activity_profile_list.xml
app/src/main/res/menu/profile_list.xml [new file with mode: 0644]

index 98afa51..1643b9e 100644 (file)
@@ -21,7 +21,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
-import android.support.design.widget.FloatingActionButton;
+import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.DividerItemDecoration;
 import android.support.v7.widget.RecyclerView;
@@ -29,6 +29,7 @@ import android.support.v7.widget.Toolbar;
 import android.support.v7.widget.helper.ItemTouchHelper;
 import android.util.Log;
 import android.view.LayoutInflater;
+import android.view.Menu;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.RadioButton;
@@ -62,8 +63,13 @@ public class ProfileListActivity extends AppCompatActivity {
      * device.
      */
     private boolean mTwoPane;
-    private FloatingActionButton fab;
+    private RecyclerView recyclerView;
 
+    @Override
+    public boolean onSupportNavigateUp() {
+        onBackPressed();
+        return super.onSupportNavigateUp();
+    }
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -72,18 +78,16 @@ public class ProfileListActivity extends AppCompatActivity {
         Toolbar toolbar = findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
         toolbar.setTitle(getTitle());
+        final ActionBar supportActionBar = getSupportActionBar();
+        if (supportActionBar != null) {
+            supportActionBar.setDisplayHomeAsUpEnabled(true);
+            supportActionBar.setDisplayShowHomeEnabled(true);
+        }
 
-        RecyclerView recyclerView = findViewById(R.id.profile_list);
+        recyclerView = findViewById(R.id.profile_list);
         if (recyclerView == null) throw new AssertionError();
         setupRecyclerView(recyclerView);
 
-        fab = findViewById(R.id.fab);
-        fab.setOnClickListener(view -> {
-            ProfilesRecyclerViewAdapter adapter =
-                    (ProfilesRecyclerViewAdapter) recyclerView.getAdapter();
-            if (adapter != null) adapter.editProfile(recyclerView, null);
-        });
-
         if (findViewById(R.id.profile_detail_container) != null) {
             // The detail container view will be present only in the
             // large-screen layouts (res/values-w900dp).
@@ -98,8 +102,7 @@ public class ProfileListActivity extends AppCompatActivity {
             int index = getIntent().getIntExtra(ARG_PROFILE_INDEX, PROFILE_INDEX_NONE);
 
             MobileLedgerProfile profile = (index >= 0) ? Data.profiles.get(index) : null;
-            ProfilesRecyclerViewAdapter adapter =
-                    (ProfilesRecyclerViewAdapter) recyclerView.getAdapter();
+            ProfilesRecyclerViewAdapter adapter = (ProfilesRecyclerViewAdapter) recyclerView.getAdapter();
             if (adapter != null) {
                 adapter.editProfile(recyclerView, profile);
 
@@ -109,11 +112,10 @@ public class ProfileListActivity extends AppCompatActivity {
             }
         }
     }
-
-    @Override
-    protected void onStart() {
-        super.onStart();
-        fab.show();
+    void launchNewProfileActivity() {
+        ProfilesRecyclerViewAdapter adapter =
+                (ProfilesRecyclerViewAdapter) recyclerView.getAdapter();
+        if (adapter != null) adapter.editProfile(recyclerView, null);
     }
     private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
         final ProfilesRecyclerViewAdapter adapter = new ProfilesRecyclerViewAdapter(this, mTwoPane);
@@ -144,7 +146,15 @@ public class ProfileListActivity extends AppCompatActivity {
         recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(),
                 DividerItemDecoration.VERTICAL));
     }
-
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        getMenuInflater().inflate(R.menu.profile_list, menu);
+        menu.findItem(R.id.menu_add_profile).setOnMenuItemClickListener(item -> {
+            launchNewProfileActivity();
+            return true;
+        });
+        return super.onCreateOptionsMenu(menu);
+    }
     public static class ProfilesRecyclerViewAdapter
             extends RecyclerView.Adapter<ProfilesRecyclerViewAdapter.ProfileListViewHolder> {
 
diff --git a/app/src/main/res/drawable/ic_add_circle_white_24dp.xml b/app/src/main/res/drawable/ic_add_circle_white_24dp.xml
new file mode 100644 (file)
index 0000000..4fa6c6c
--- /dev/null
@@ -0,0 +1,43 @@
+<!--
+  ~ Copyright © 2019 Damyan Ivanov.
+  ~ This file is part of Mobile-Ledger.
+  ~ Mobile-Ledger is free software: you can distribute it and/or modify it
+  ~ under the term of the GNU General Public License as published by
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~ (at your opinion), any later version.
+  ~
+  ~ Mobile-Ledger is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  ~ GNU General Public License terms for details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
+  -->
+
+<!--
+  ~ Copyright Google Inc.
+  ~
+  ~ Licensed under the Apache License, version 2.0 ("the License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the license at:
+  ~
+  ~   https://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distribution under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissionsand
+  ~ limitations under the License.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:tint="#EEEEEE"
+    android:viewportWidth="24.0"
+    android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13h-4v4h-2v-4L7,13v-2h4L11,7h2v4h4v2z" />
+</vector>
index c237031..8e7e371 100644 (file)
         <include layout="@layout/profile_list" />
     </android.support.v4.widget.NestedScrollView>
 
-    <android.support.design.widget.FloatingActionButton
-        android:id="@+id/fab"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="start|center_vertical"
-        android:layout_margin="@dimen/fab_margin"
-        app:layout_anchor="@id/frameLayout"
-        app:layout_anchorGravity="top|end"
-        app:srcCompat="@drawable/svg_thick_plus_white" />
-
-
 </android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
diff --git a/app/src/main/res/menu/profile_list.xml b/app/src/main/res/menu/profile_list.xml
new file mode 100644 (file)
index 0000000..3aeba7c
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ Copyright © 2019 Damyan Ivanov.
+  ~ This file is part of Mobile-Ledger.
+  ~ Mobile-Ledger is free software: you can distribute it and/or modify it
+  ~ under the term of the GNU General Public License as published by
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~ (at your opinion), any later version.
+  ~
+  ~ Mobile-Ledger is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  ~ GNU General Public License terms for details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
+  -->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <item
+        android:id="@+id/menu_add_profile"
+        android:icon="@drawable/ic_add_circle_white_24dp"
+        android:title="@string/create_profile_label"
+        app:showAsAction="ifRoom" />
+</menu>
\ No newline at end of file