Android Open Source - ghwatch Notification Repositories List Adapter

From Project

Back to project page ghwatch.


The source code is released under:

Apache License

If you think the Android project ghwatch 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 2014 contributors as indicated by the @authors tag.
 * //from w  ww.j a  va2s .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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package com.daskiworks.ghwatch;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.daskiworks.ghwatch.model.NotifCount;
import com.daskiworks.ghwatch.model.NotificationStream;

 * {@link ListView} adapter used to show list of repositories we have notifications for in {@link NotificationStream}.
 * @author Vlastimil Elias <>
public class NotificationRepositoriesListAdapter extends BaseAdapter {

  private LayoutInflater layoutInflater;
  private NotificationStream notificationStream;
  private Context context;

  public NotificationRepositoriesListAdapter(Context activity, final NotificationStream notificationStream) {
    this.context = activity;
    layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.notificationStream = notificationStream;

  public int getCount() {
    return notificationStream.getRepositoriesInfo().size();

  public Object getItem(int position) {
    return notificationStream.getRepositoriesInfo().get(position);

  public long getItemId(int position) {
    return position;

  public void setNotificationStream(NotificationStream notificationStream) {
    this.notificationStream = notificationStream;

  public View getView(int position, View convertView, ViewGroup parent) {

    View listItem = null;
    if (convertView == null) {
      listItem = layoutInflater.inflate(R.layout.list_repositories_for_notifications, parent, false);
    } else {
      listItem = convertView;

    // Initialize the views in the layout
    TextView tvRepoName = (TextView) listItem.findViewById(;
    TextView tvCount = (TextView) listItem.findViewById(;

    NotifCount notifCount = notificationStream.getRepositoriesInfo().get(position);
    tvCount.setText(notifCount.count + "");
    return listItem;

   * Set selection into listView based on repository filter value.
   * @param repositoriesListView to set selection into
   * @param filterByRepository value of filter to set selection for
   * @return true if filterByRepository is found in data (we have notification for it)
  public boolean setSelectionForFilter(ListView repositoriesListView, String filterByRepository) {
    if (filterByRepository != null) {
      int i = 0;
      for (NotifCount nc : notificationStream.getRepositoriesInfo()) {
        if (filterByRepository.equals(nc.title)) {
          repositoriesListView.setItemChecked(i, true);
          return true;
    repositoriesListView.setItemChecked(-1, true);
    return false;


Java Source Code List