Android Open Source - AndroidShoppingList Shopping List Fragment






From Project

Back to project page AndroidShoppingList.

License

The source code is released under:

Apache License

If you think the Android project AndroidShoppingList listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright 2012 C. A. Fitzgerald/*from   w  ww. ja v a  2 s. c  o  m*/
 *
 *  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
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed 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 permissions and
 *   limitations under the License.
 */

package com.github.riotopsys.shoppinglist.fragment;

import java.net.MalformedURLException;
import java.sql.SQLException;
import java.util.UUID;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.ShareActionProvider;

import com.github.riotopsys.shoppinglist.AppKeys;
import com.github.riotopsys.shoppinglist.Configurations;
import com.github.riotopsys.shoppinglist.IConfigurations;
import com.github.riotopsys.shoppinglist.R;
import com.github.riotopsys.shoppinglist.activity.ListItemEdit;
import com.github.riotopsys.shoppinglist.adapter.ShoppingListAdapter;
import com.github.riotopsys.shoppinglist.model.DatabaseHelper;
import com.github.riotopsys.shoppinglist.model.ShoppingList;
import com.j256.ormlite.android.apptools.OpenHelperManager;

public class ShoppingListFragment extends Fragment implements OnItemLongClickListener {

  private ShoppingList mList;
  private ShoppingListAdapter mListAdapter;

  private BroadcastReceiver mItemUpdateReciever = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
      mListAdapter.notifyDataSetChanged(context);
    }

  };

  private IntentFilter mFilter = new IntentFilter(AppKeys.ITEM_UPDATE_ACTION);

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ListView view = (ListView) inflater.inflate(R.layout.shopping_list_fragment, null);

    UUID uuid = (UUID) getArguments().getSerializable(AppKeys.LIST_KEY);
    DatabaseHelper databaseHelper = OpenHelperManager.getHelper(getActivity(), DatabaseHelper.class);
    try {
      mList = databaseHelper.getShoppingList(uuid);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    } finally {
      OpenHelperManager.releaseHelper();
    }

    mListAdapter = new ShoppingListAdapter(getActivity(), mList);

    view.setAdapter(mListAdapter);

    setHasOptionsMenu(true);

    view.setOnItemLongClickListener(this);

    return view;
  }

  @Override
  public void onResume() {
    getActivity().registerReceiver(mItemUpdateReciever, mFilter);
    mListAdapter.notifyDataSetChanged(getActivity());
    super.onResume();
  }

  @Override
  public void onPause() {
    getActivity().unregisterReceiver(mItemUpdateReciever);
    super.onPause();
  }

  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.shopping_list_fragment, menu);

      MenuItem item = menu.findItem(R.id.menu_share);

      ShareActionProvider shareActionProvider = (ShareActionProvider) item.getActionProvider();
      
      IConfigurations confs = new Configurations();
      Intent shareIntent = new Intent(Intent.ACTION_SEND);
      try {
      shareIntent.putExtra(Intent.EXTRA_TEXT, String.format("%s%s", confs.shareUrlBase(), mList.getGuid().toString()));
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
      shareIntent.setType("text/plain");
      
    shareActionProvider.setShareIntent(shareIntent );

    super.onCreateOptionsMenu(menu, inflater);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_add_item) {

      Intent i = new Intent(getActivity(), ListItemEdit.class);
      i.putExtra(AppKeys.LIST_KEY, mList.getGuid());
      startActivity(i);

    }
    return super.onOptionsItemSelected(item);
  }

  @Override
  public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

    Intent i = new Intent(getActivity(), ListItemEdit.class);
    i.putExtra(AppKeys.LIST_ITEM_KEY, mListAdapter.getListItem(position).getGuid());
    i.putExtra(AppKeys.LIST_KEY, mList.getGuid());
    startActivity(i);

    return false;
  }

}




Java Source Code List

com.github.riotopsys.shoppinglist.AppKeys.java
com.github.riotopsys.shoppinglist.GCMIntentService.java
com.github.riotopsys.shoppinglist.IConfigurations.java
com.github.riotopsys.shoppinglist.activity.ListItemEdit.java
com.github.riotopsys.shoppinglist.activity.ShoppingListPreview.java
com.github.riotopsys.shoppinglist.adapter.ShoppingListAdapter.java
com.github.riotopsys.shoppinglist.adapter.ShoppingListCollectionAdapter.java
com.github.riotopsys.shoppinglist.comparator.ListItemNameComparator.java
com.github.riotopsys.shoppinglist.comparator.ListNameComparator.java
com.github.riotopsys.shoppinglist.fragment.ShoppingListFragment.java
com.github.riotopsys.shoppinglist.listener.CheckedChangeListener.java
com.github.riotopsys.shoppinglist.model.DatabaseHelper.java
com.github.riotopsys.shoppinglist.model.DigestRecord.java
com.github.riotopsys.shoppinglist.model.PersistedRecord.java
com.github.riotopsys.shoppinglist.model.ShoppingListCollection.java
com.github.riotopsys.shoppinglist.model.ShoppingListItem.java
com.github.riotopsys.shoppinglist.model.ShoppingList.java
com.github.riotopsys.shoppinglist.model.Work.java
com.github.riotopsys.shoppinglist.server.DigestCollection.java
com.github.riotopsys.shoppinglist.server.RestHelper.java
com.github.riotopsys.shoppinglist.server.RestResult.java
com.github.riotopsys.shoppinglist.server.ServerInterfaceService.java
com.github.riotopsys.shoppinglist.server.ServerTask.java
com.github.riotopsys.shoppinglist.server.UrlBuilder.java
com.github.riotopsys.shoppinglist.server.work.Operations.java
com.github.riotopsys.shoppinglist.server.work.WorkQueue.java
com.github.riotopsys.shoppinglist.utils.AccountUtils.java