Display users lists

This commit is contained in:
Clayton Wilson 2020-10-04 19:48:00 -04:00
parent 64d4fb0192
commit 4a1bab2001
11 changed files with 163 additions and 5 deletions

View File

@ -76,7 +76,7 @@ public class MainActivity extends AppCompatActivity {
NavigationView navigationView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow, R.id.nav_lists)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);

View File

@ -43,7 +43,7 @@ public class DisplayShoppingListsAdapter extends BaseAdapter {
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
if (convertView == null) {
convertView = inflater.inflate(R.layout.search_list_item, null);
convertView = inflater.inflate(R.layout.display_shopping_lists_item, null);
}
ShoppingList curList = lists.get(position);

View File

@ -0,0 +1,53 @@
package com.example.listify.ui.lists;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import com.example.listify.MainActivity;
import com.example.listify.R;
import com.example.listify.adapter.DisplayShoppingListsAdapter;
import com.example.listify.model.ShoppingList;
import java.util.ArrayList;
public class ListsFragment extends Fragment {
ListView shoppingListsView;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_lists, container, false);
// Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar_lists);
// ((AppCompatActivity)getActivity()).setActionBar(toolbar);
// Hardcode shopping lists to demonstrate displaying lists
shoppingListsView = root.findViewById(R.id.shopping_lists);
ShoppingList a = new ShoppingList("first list");
ShoppingList b = new ShoppingList("Groceries");
ShoppingList c = new ShoppingList("Expensive Stuff");
ArrayList<ShoppingList> shoppingLists = new ArrayList<>();
shoppingLists.add(a);
shoppingLists.add(b);
shoppingLists.add(c);
// Set adapter and display this users lists
DisplayShoppingListsAdapter displayShoppingListsAdapter = new DisplayShoppingListsAdapter(getActivity(), shoppingLists);
shoppingListsView.setAdapter(displayShoppingListsAdapter);
shoppingListsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getContext(), "open and display " + shoppingLists.get(position).getName(), Toast.LENGTH_SHORT).show();
}
});
return root;
}
}

View File

@ -0,0 +1,5 @@
<vector android:height="28dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="28dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19,5v14L5,19L5,5h14m1.1,-2L3.9,3c-0.5,0 -0.9,0.4 -0.9,0.9v16.2c0,0.4 0.4,0.9 0.9,0.9h16.2c0.4,0 0.9,-0.5 0.9,-0.9L21,3.9c0,-0.5 -0.5,-0.9 -0.9,-0.9zM11,7h6v2h-6L11,7zM11,11h6v2h-6v-2zM11,15h6v2h-6zM7,7h2v2L7,9zM7,11h2v2L7,13zM7,15h2v2L7,17z"/>
</vector>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_lists"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" >
<!-- <ImageButton-->
<!-- android:id="@+id/searchButton"-->
<!-- android:layout_width="30dp"-->
<!-- android:layout_gravity="end"-->
<!-- android:layout_marginEnd="5dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:srcCompat="@drawable/ic_baseline_search_28"-->
<!-- android:contentDescription="@string/search_button_desc"-->
<!-- android:background="@null"/>-->
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" />
<!-- <com.google.android.material.floatingactionbutton.FloatingActionButton-->
<!-- android:id="@+id/fab"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="bottom|end"-->
<!-- android:layout_margin="@dimen/fab_margin"-->
<!-- app:srcCompat="@android:drawable/ic_dialog_email" />-->
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,8 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/shopping_list_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="8dp"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".ui.lists.ListsFragment"
tools:showIn="@layout/fragment_lists">
<ListView
android:id="@+id/shopping_lists"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/list_divider"
android:dividerHeight="1dp"/>
</RelativeLayout>

View File

@ -16,5 +16,9 @@
android:id="@+id/nav_slideshow"
android:icon="@drawable/ic_menu_slideshow"
android:title="@string/menu_slideshow" />
<item
android:id="@+id/nav_lists"
android:icon="@drawable/ic_baseline_list_alt_28"
android:title="@string/menu_lists" />
</group>
</menu>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-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_create_list"
android:orderInCategory="101"
android:title="Create List"
app:showAsAction="never" />
</menu>

View File

@ -22,4 +22,10 @@
android:name="com.example.listify.ui.slideshow.SlideshowFragment"
android:label="@string/menu_slideshow"
tools:layout="@layout/fragment_slideshow" />
<fragment
android:id="@+id/nav_lists"
android:name="com.example.listify.ui.lists.ListsFragment"
android:label="@string/menu_lists"
tools:layout="@layout/fragment_lists" />
</navigation>

View File

@ -29,4 +29,5 @@
<string name="search_button_desc">Search Button</string>
<string name="title_activity_search_results">SearchResults</string>
<string name="store_selection">Store selection</string>
<string name="menu_lists">My Lists</string>
</resources>