Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<activity
android:name=".ui.activeListDetails.ActiveListDetailsActivity"
android:label="@string/title_activity_list_details"
android:parentActivityName=".ui.MainActivity"
android:windowSoftInputMode="adjustPan">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity" />
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package com.udacity.firebase.shoppinglistplusplus.ui.activeListDetails;

import android.app.DialogFragment;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.udacity.firebase.shoppinglistplusplus.R;
import com.udacity.firebase.shoppinglistplusplus.model.ShoppingList;
import com.udacity.firebase.shoppinglistplusplus.ui.BaseActivity;

/**
* Represents the details screen for the selected shopping list
*/
public class ActiveListDetailsActivity extends BaseActivity {
private static final String LOG_TAG = ActiveListDetailsActivity.class.getSimpleName();
private ListView mListView;
private ShoppingList mShoppingList;

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_active_list_details);

/**
* Link layout elements from XML and setup the toolbar
*/
initializeScreen();

/* Calling invalidateOptionsMenu causes onCreateOptionsMenu to be called */
invalidateOptionsMenu();

/**
* Set up click listeners for interaction.
*/

/* Show edit list item name dialog on listView item long click event */
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
/* Check that the view is not the empty footer item */
if(view.getId() != R.id.list_view_footer_empty) {
showEditListItemNameDialog();
}
return true;
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
/* Inflate the menu; this adds items to the action bar if it is present. */
getMenuInflater().inflate(R.menu.menu_list_details, menu);

/**
* Get menu items
*/
MenuItem remove = menu.findItem(R.id.action_remove_list);
MenuItem edit = menu.findItem(R.id.action_edit_list_name);
MenuItem share = menu.findItem(R.id.action_share_list);
MenuItem archive = menu.findItem(R.id.action_archive);

/* Only the edit and remove options are implemented */
remove.setVisible(true);
edit.setVisible(true);
share.setVisible(false);
archive.setVisible(false);

return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

/**
* Show edit list dialog when the edit action is selected
*/
if (id == R.id.action_edit_list_name) {
showEditListNameDialog();
return true;
}

/**
* removeList() when the remove action is selected
*/
if (id == R.id.action_remove_list) {
removeList();
return true;
}

/**
* Eventually we'll add this
*/
if (id == R.id.action_share_list) {
return true;
}

/**
* archiveList() when the archive action is selected
*/
if (id == R.id.action_archive) {
archiveList();
return true;
}

return super.onOptionsItemSelected(item);
}


/**
* Cleanup when the activity is destroyed.
*/
@Override
public void onDestroy() {
super.onDestroy();
}

/**
* Link layout elements from XML and setup the toolbar
*/
private void initializeScreen() {
mListView = (ListView) findViewById(R.id.list_view_shopping_list_items);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
/* Common toolbar setup */
setSupportActionBar(toolbar);
/* Add back button to the action bar */
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
/* Inflate the footer, set root layout to null*/
View footer = getLayoutInflater().inflate(R.layout.footer_empty, null);
mListView.addFooterView(footer);
}


/**
* Archive current list when user selects "Archive" menu item
*/
public void archiveList() {
}


/**
* Start AddItemsFromMealActivity to add meal ingredients into the shopping list
* when the user taps on "add meal" fab
*/
public void addMeal(View view) {
}

/**
* Remove current shopping list and its items from all nodes
*/
public void removeList() {
/* Create an instance of the dialog fragment and show it */
DialogFragment dialog = RemoveListDialogFragment.newInstance(mShoppingList);
dialog.show(getFragmentManager(), "RemoveListDialogFragment");
}

/**
* Show the add list item dialog when user taps "Add list item" fab
*/
public void showAddListItemDialog(View view) {
/* Create an instance of the dialog fragment and show it */
DialogFragment dialog = AddListItemDialogFragment.newInstance(mShoppingList);
dialog.show(getFragmentManager(), "AddListItemDialogFragment");
}

/**
* Show edit list name dialog when user selects "Edit list name" menu item
*/
public void showEditListNameDialog() {
/* Create an instance of the dialog fragment and show it */
DialogFragment dialog = EditListNameDialogFragment.newInstance(mShoppingList);
dialog.show(this.getFragmentManager(), "EditListNameDialogFragment");
}

/**
* Show the edit list item name dialog after longClick on the particular item
*/
public void showEditListItemNameDialog() {
/* Create an instance of the dialog fragment and show it */
DialogFragment dialog = EditListItemNameDialogFragment.newInstance(mShoppingList);
dialog.show(this.getFragmentManager(), "EditListItemNameDialogFragment");
}

/**
* This method is called when user taps "Start/Stop shopping" button
*/
public void toggleShopping(View view) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.udacity.firebase.shoppinglistplusplus.ui.activeListDetails;

import android.app.Dialog;
import android.os.Bundle;

import com.udacity.firebase.shoppinglistplusplus.R;
import com.udacity.firebase.shoppinglistplusplus.model.ShoppingList;

/**
* Lets user add new list item.
*/
public class AddListItemDialogFragment extends EditListDialogFragment {

/**
* Public static constructor that creates fragment and passes a bundle with data into it when adapter is created
*/
public static AddListItemDialogFragment newInstance(ShoppingList shoppingList) {
AddListItemDialogFragment addListItemDialogFragment = new AddListItemDialogFragment();

Bundle bundle = newInstanceHelper(shoppingList, R.layout.dialog_add_item);
addListItemDialogFragment.setArguments(bundle);

return addListItemDialogFragment;
}

/**
* Initialize instance variables with data from bundle
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
/** {@link EditListDialogFragment#createDialogHelper(int)} is a
* superclass method that creates the dialog
**/
return super.createDialogHelper(R.string.positive_button_add_list_item);
}

/**
* Adds new item to the current shopping list
*/
@Override
protected void doListEdit() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.udacity.firebase.shoppinglistplusplus.ui.activeListDetails;

import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;

import com.udacity.firebase.shoppinglistplusplus.R;
import com.udacity.firebase.shoppinglistplusplus.model.ShoppingList;
import com.udacity.firebase.shoppinglistplusplus.utils.Constants;

/**
* Base class for {@link DialogFragment}s involved with editing a shopping list.
*/
public abstract class EditListDialogFragment extends DialogFragment {
EditText mEditTextForList;
int mResource;

/**
* Helper method that creates a basic bundle of all of the information needed to change
* values in a shopping list.
*
* @param shoppingList
* @param resource
* @return
*/
protected static Bundle newInstanceHelper(ShoppingList shoppingList, int resource) {
Bundle bundle = new Bundle();
bundle.putInt(Constants.KEY_LAYOUT_RESOURCE, resource);
return bundle;
}

/**
* Initialize instance variables with data from bundle
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mResource = getArguments().getInt(Constants.KEY_LAYOUT_RESOURCE);
}

/**
* Open the keyboard automatically when the dialog fragment is opened
*/
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}

protected Dialog createDialogHelper(int stringResourceForPositiveButton) {
/* Use the Builder class for convenient dialog construction */
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.CustomTheme_Dialog);
/* Get the layout inflater */
LayoutInflater inflater = getActivity().getLayoutInflater();
/* Inflate the layout, set root ViewGroup to null*/
View rootView = inflater.inflate(mResource, null);
mEditTextForList = (EditText) rootView.findViewById(R.id.edit_text_list_dialog);

/**
* Call doListEdit() when user taps "Done" keyboard action
*/
mEditTextForList.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_DONE || keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
doListEdit();

/**
* Close the dialog fragment when done
*/
EditListDialogFragment.this.getDialog().cancel();
}
return true;
}
});
/* Inflate and set the layout for the dialog */
/* Pass null as the parent view because its going in the dialog layout */
builder.setView(rootView)
/* Add action buttons */
.setPositiveButton(stringResourceForPositiveButton, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
doListEdit();

/**
* Close the dialog fragment
*/
EditListDialogFragment.this.getDialog().cancel();
}
})
.setNegativeButton(R.string.negative_button_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {

/**
* Close the dialog fragment
*/
EditListDialogFragment.this.getDialog().cancel();
}
});

return builder.create();
}

/**
* Set the EditText text to be the inputted text
* and put the pointer at the end of the input
*
* @param defaultText
*/
protected void helpSetDefaultValueEditText(String defaultText) {
mEditTextForList.setText(defaultText);
mEditTextForList.setSelection(defaultText.length());
}

/**
* Method to be overriden with whatever edit is supposed to happen to the list
*/
protected abstract void doListEdit();
}
Loading