package com.saki.ui;

import com.saki.service.NewConnection;
import com.saki.service.NewService;
import com.saki.ui.i.IB;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.widget.ListView;
import android.widget.RelativeLayout;

public abstract class Bannerlist extends RelativeLayout implements IB {
    private Banner banner;
    private ListView list;
    protected LayoutInflater inflater;
    private NewConnection connection;

    public Bannerlist(Context context, int id) {
        super(context);
        inflater = LayoutInflater.from(context);
        inflater.inflate(id, this);
        banner = initBanner(context);
        list = initList(context);
        context.bindService(new Intent(context, NewService.class),
                connection = new NewConnection(this), Context.BIND_AUTO_CREATE);
    }

    public ListView getListView() {
        return list;
    }

    public Banner getPromote() {
        return banner;
    }

    public NewService getService() {
        return connection.getService();
    }

    protected abstract Banner initBanner(Context c);

    protected abstract ListView initList(Context c);

    public void onDestroy() {
        list = null;
        banner = null;
        inflater = null;
        getContext().unbindService(connection);
    }

    @Override
    public void onBind(NewService service) {
    }
}
