Пример #1
0
  @Override
  public void recordsUpdated(List<CategoriesItem> list) {
    if (categoryList == null || categoryList.size() == 0) {
      categoryList = list;
      adapter.clear();

      for (int i = 0; i < list.size(); i++) adapter.add(list.get(i));
    } else {
      for (int i = categoryList.size(); i < list.size(); i++) {
        adapter.add(list.get(i));
        categoryList.add(list.get(i));
      }
    }

    adapter.notifyDataSetChanged();
  }
Пример #2
0
  @Override
  public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    Log.d(LOG_TAG, "Finishing loader: " + cursor.getCount());
    if (cursor.getCount() != 0) {
      callback.updateProgressIndicator(false);
    }
    mCustomAdapter.swapCursor(cursor);

    // Restore list ot position
    int listPosition =
        PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getInt(KEY_LIST_FIRST_VISIBLE_POSITION, 0);
    int listTopPosition =
        PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getInt(KEY_LIST_TOP_POSITION, 0);

    if (listPosition > 0) {
      mList.setSelectionFromTop(listPosition, listTopPosition);
    }
  }
Пример #3
0
  /*
   * onCreate method.
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (android.os.Build.VERSION.SDK_INT > 10) {
      setupActionBar();
      getOverflowMenu();
    }

    adapter = new CustomListAdapter<CategoriesItem>(this);

    if (isOnline()) {
      // Checking if there are any records in the CategoriesList
      try {
        categoryList = (List<CategoriesItem>) getLastNonConfigurationInstance();
      } catch (Exception e) {
        e.printStackTrace();
      }

      // AsyncTask is called if there are no records found
      if (categoryList == null)
        task = (LoadCategoriesTask) new LoadCategoriesTask(this).execute(50, null, null);
      else for (int i = 0; i < categoryList.size(); i++) adapter.add(categoryList.get(i));
    } else
      ((TextView) findViewById(R.id.emptyView)).setText(R.string.no_internet_connection_message);

    listView = ((ListView) this.findViewById(R.id.list));
    View footerView =
        ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.footer_layout, null, false);
    listView.addFooterView(footerView, null, false);
    listView.setAdapter(adapter);
    // Displays text "No videos Found" when the list is empty
    listView.setEmptyView((TextView) findViewById(R.id.emptyView));
    // Tells the application what to do when a category is clicked
    listView.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            startIntent(categoryList.get(arg2));
          }
        });

    listView.setOnScrollListener(
        new OnScrollListener() {
          // useless here, skip!
          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {}

          // dumdumdum
          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // what is the bottom iten that is visible
            int lastInScreen = firstVisibleItem + visibleItemCount;
            // is the bottom item visible & not loading more already ? Load
            // more !
            if ((lastInScreen == totalItemCount)
                && (task == null)
                && (totalItemCount > visibleItemCount)) {
              findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
              task =
                  (LoadCategoriesTask)
                      new LoadCategoriesTask(getParent()).execute(totalItemCount + 50, null, null);
            }
          }
        });
  }
Пример #4
0
 @Override
 public void onLoaderReset(Loader<Cursor> cursorLoader) {
   mCustomAdapter.swapCursor(null);
 }