todos: Partial implementation of "New List"
Add an element to the navigation drawer to create a new list. Tapping
on "+ New List" opens a dialog box where the user types the list name.
Tapping "Create" will add the list to the in-memory list of list names.
Change-Id: Ifc8407b98187b8328f7a0a5e8f47c9f4852b842d
diff --git a/android/app/app.iml b/android/app/app.iml
index 0cce8e6..fb6a9d3 100644
--- a/android/app/app.iml
+++ b/android/app/app.iml
@@ -86,6 +86,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
diff --git a/android/app/src/main/java/io/v/android/apps/todos/NavigationDrawerFragment.java b/android/app/src/main/java/io/v/android/apps/todos/NavigationDrawerFragment.java
index f548396..a7d829f 100644
--- a/android/app/src/main/java/io/v/android/apps/todos/NavigationDrawerFragment.java
+++ b/android/app/src/main/java/io/v/android/apps/todos/NavigationDrawerFragment.java
@@ -1,5 +1,7 @@
package io.v.android.apps.todos;
+import android.content.DialogInterface;
+import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.support.v7.app.ActionBar;
@@ -19,9 +21,14 @@
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
+import android.widget.EditText;
import android.widget.ListView;
+import android.widget.TextView;
import android.widget.Toast;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Fragment used for managing interactions for and presentation of a navigation drawer.
* See the <a href="https://developer.android.com/design/patterns/navigation-drawer.html#Interaction">
@@ -53,11 +60,14 @@
private DrawerLayout mDrawerLayout;
private ListView mDrawerListView;
private View mFragmentContainerView;
+ private TextView mNewListView;
private int mCurrentSelectedPosition = 0;
private boolean mFromSavedInstanceState;
private boolean mUserLearnedDrawer;
+ private List<String> mListNames = new ArrayList<String>();
+
public NavigationDrawerFragment() {
}
@@ -87,27 +97,61 @@
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- mDrawerListView = (ListView) inflater.inflate(
- R.layout.fragment_navigation_drawer, container, false);
+ View v = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
+ mDrawerListView = (ListView) v.findViewById(R.id.navigation_drawer_list);
mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
});
+ refreshList();
+ mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
+
+ mNewListView = (TextView) v.findViewById(R.id.new_list);
+ mNewListView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ addList(inflater);
+ }
+ });
+ return v;
+ }
+
+ /**
+ * Prompt the user for a new list name and add it to the navigation drawer.
+ */
+ private void addList(LayoutInflater inflater) {
+ View promptView = inflater.inflate(R.layout.new_list_prompt, null);
+ AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
+ dialogBuilder.setView(promptView);
+ final EditText input = (EditText) promptView.findViewById(R.id.new_list_input);
+ dialogBuilder.setCancelable(true);
+ dialogBuilder
+ .setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mListNames.add(input.getText().toString());
+ refreshList();
+ }
+ })
+ .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ });
+ dialogBuilder.create().show();
+ }
+
+ private void refreshList() {
mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1,
- new String[]{
- getString(R.string.title_section1),
- getString(R.string.title_section2),
- getString(R.string.title_section3),
- }));
- mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
- return mDrawerListView;
+ mListNames.toArray(new String[0])));
}
public boolean isDrawerOpen() {
diff --git a/android/app/src/main/res/layout/activity_pick_list.xml b/android/app/src/main/res/layout/activity_pick_list.xml
index d39fe60..49b56d6 100644
--- a/android/app/src/main/res/layout/activity_pick_list.xml
+++ b/android/app/src/main/res/layout/activity_pick_list.xml
@@ -1,12 +1,16 @@
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
- android:layout_width="match_parent" android:layout_height="match_parent"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:id="@+id/drawer_layout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
tools:context=".PickListActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
- <FrameLayout android:id="@+id/container" android:layout_width="match_parent"
+ <FrameLayout
+ android:id="@+id/container"
+ android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
@@ -16,10 +20,12 @@
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
- <fragment android:id="@+id/navigation_drawer"
- android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent"
- android:layout_gravity="start"
+ <fragment
+ android:id="@+id/navigation_drawer"
android:name="io.v.android.apps.todos.NavigationDrawerFragment"
+ android:layout_width="@dimen/navigation_drawer_width"
+ android:layout_height="match_parent"
+ android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
diff --git a/android/app/src/main/res/layout/fragment_navigation_drawer.xml b/android/app/src/main/res/layout/fragment_navigation_drawer.xml
index c05742d..c79dded 100644
--- a/android/app/src/main/res/layout/fragment_navigation_drawer.xml
+++ b/android/app/src/main/res/layout/fragment_navigation_drawer.xml
@@ -1,5 +1,37 @@
-<ListView xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
- android:layout_height="match_parent" android:choiceMode="singleChoice"
- android:divider="@android:color/transparent" android:dividerHeight="0dp"
- android:background="#cccc" tools:context=".NavigationDrawerFragment" />
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#cccc"
+ android:orientation="vertical"
+ tools:context=".NavigationDrawerFragment">
+
+ <!-- List of todo list titles -->
+ <ListView
+ android:id="@+id/navigation_drawer_list"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:choiceMode="singleChoice"
+ android:divider="@android:color/transparent"
+ android:dividerHeight="0dp" />
+
+ <!-- Horizontal line -->
+ <!-- TODO(kash): Figure out how to get the line to have a bit of margin on either side. -->
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="2dp"
+ android:background="#ffffff" />
+
+ <!-- New list action -->
+ <TextView
+ android:id="@+id/new_list"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ android:text="@string/new_list"
+ android:textAppearance="?android:attr/textAppearanceListItemSmall" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/android/app/src/main/res/layout/fragment_pick_list.xml b/android/app/src/main/res/layout/fragment_pick_list.xml
index 50aa1fa..e901d00 100644
--- a/android/app/src/main/res/layout/fragment_pick_list.xml
+++ b/android/app/src/main/res/layout/fragment_pick_list.xml
@@ -1,12 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
- android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".PickListActivity$PlaceholderFragment">
- <TextView android:id="@+id/section_label" android:layout_width="wrap_content"
+ <TextView
+ android:id="@+id/section_label"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
diff --git a/android/app/src/main/res/layout/new_list_prompt.xml b/android/app/src/main/res/layout/new_list_prompt.xml
new file mode 100644
index 0000000..97d0346
--- /dev/null
+++ b/android/app/src/main/res/layout/new_list_prompt.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/new_list_name"
+ android:textAppearance="?android:textAppearanceLargePopupMenu" />
+
+ <EditText
+ android:id="@+id/new_list_input"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="text">
+ <requestFocus />
+ </EditText>
+</LinearLayout>
\ No newline at end of file
diff --git a/android/app/src/main/res/menu/global.xml b/android/app/src/main/res/menu/global.xml
index 326a6a7..80dac4c 100644
--- a/android/app/src/main/res/menu/global.xml
+++ b/android/app/src/main/res/menu/global.xml
@@ -1,5 +1,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
- <item android:id="@+id/action_settings" android:title="@string/action_settings"
- android:orderInCategory="100" app:showAsAction="never" />
+ <item
+ android:id="@+id/action_settings"
+ android:orderInCategory="100"
+ android:title="@string/action_settings"
+ app:showAsAction="never" />
</menu>
diff --git a/android/app/src/main/res/menu/pick_list.xml b/android/app/src/main/res/menu/pick_list.xml
index 11b68a3..d370bc6 100644
--- a/android/app/src/main/res/menu/pick_list.xml
+++ b/android/app/src/main/res/menu/pick_list.xml
@@ -1,8 +1,14 @@
<menu 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" tools:context=".PickListActivity">
- <item android:id="@+id/action_example" android:title="@string/action_example"
+ xmlns:tools="http://schemas.android.com/tools"
+ tools:context=".PickListActivity">
+ <item
+ android:id="@+id/action_example"
+ android:title="@string/action_example"
app:showAsAction="withText|ifRoom" />
- <item android:id="@+id/action_settings" android:title="@string/action_settings"
- android:orderInCategory="100" app:showAsAction="never" />
+ <item
+ android:id="@+id/action_settings"
+ android:orderInCategory="100"
+ android:title="@string/action_settings"
+ app:showAsAction="never" />
</menu>
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index b32e069..9ab263e 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -4,6 +4,8 @@
<string name="title_section1">Section 1</string>
<string name="title_section2">Section 2</string>
<string name="title_section3">Section 3</string>
+ <string name="new_list">+ New List</string>
+ <string name="new_list_name">New list name:</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
@@ -11,4 +13,8 @@
<string name="action_example">Example action</string>
<string name="action_settings">Settings</string>
+
+ <!-- Used in dialog boxes. -->
+ <string name="create">Create</string>
+ <string name="cancel">Cancel</string>
</resources>