Android Open Source - HorribleSubs-Schedule Schedule Items Adapter






From Project

Back to project page HorribleSubs-Schedule.

License

The source code is released under:

Copyright (c) 2014, ?hsan I??k All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project HorribleSubs-Schedule 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

package tr.xip.horriblesubsschedule;
/* www. ja  va 2  s  .c  o m*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tonicartos.widget.stickygridheaders.StickyGridHeadersSimpleArrayAdapter;

import java.util.List;

import tr.xip.horriblesubsschedule.database.DatabaseManager;
import tr.xip.horriblesubsschedule.database.items.AnimeItem;

/**
 * Created by Hikari on 8/29/14.
 */
public class ScheduleItemsAdapter extends StickyGridHeadersSimpleArrayAdapter<AnimeItem> {

    DatabaseManager dbMan;

    View rootView;
    Context context;
    List<AnimeItem> mList;
    int mHeaderResId;
    int mItemResId;

    String[] mDaysList;

    public ScheduleItemsAdapter(Context context, List<AnimeItem> items, int headerResId, int itemResId) {
        super(context, items, headerResId, itemResId);
        this.context = context;
        mList = items;
        mHeaderResId = headerResId;
        mItemResId = itemResId;
        dbMan = new DatabaseManager(context);

        mDaysList = context.getResources().getStringArray(R.array.schedule_days_list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        rootView = convertView;

        if (rootView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            rootView = inflater.inflate(R.layout.item_schedule_item, null);
        }

        final AnimeItem item = mList.get(position);

        TextView mAnimeName = (TextView) rootView.findViewById(R.id.item_schedule_anime_name);
        TextView mAnimeReleaseTime = (TextView) rootView.findViewById(R.id.item_schedule_anime_release_time);

        mAnimeName.setText(item.getName());
        mAnimeReleaseTime.setText(Utils.convertAnimeReleaseTimeToLocal(item.getTime()));

        return rootView;
    }


    @Override
    public long getHeaderId(int position) {
        return mList.get(position).getDay();
    }

    @Override
    public View getHeaderView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.item_header, null);
        }
        AnimeItem item = mList.get(position);

        TextView mHeaderTitle = (TextView) convertView.findViewById(R.id.item_header_title);

        mHeaderTitle.setText(mDaysList[item.getDay()]);

        return convertView;
    }
}




Java Source Code List

tr.xip.horriblesubsschedule.ApplicationTest.java
tr.xip.horriblesubsschedule.MainActivity.java
tr.xip.horriblesubsschedule.ScheduleFragment.java
tr.xip.horriblesubsschedule.ScheduleItemsAdapter.java
tr.xip.horriblesubsschedule.Utils.java
tr.xip.horriblesubsschedule.database.DatabaseHelper.java
tr.xip.horriblesubsschedule.database.DatabaseManager.java
tr.xip.horriblesubsschedule.database.items.AnimeItem.java
tr.xip.horriblesubsschedule.database.tables.AnimeTable.java