Search in sources :

Example 1 with Sponsor

use of ca.etsmtl.applets.etsmobile.model.Sponsor in project ETSMobile-Android2 by ApplETS.

the class SponsorManager method getSponsorList.

public ArrayList<Sponsor> getSponsorList() {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    ArrayList<Sponsor> sponsorList = null;
    try {
        sponsorList = (ArrayList<Sponsor>) dbHelper.getDao(Sponsor.class).queryForAll();
    } catch (SQLException e) {
        Log.e("SQL Exception", e.getMessage());
    }
    return sponsorList;
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) Sponsor(ca.etsmtl.applets.etsmobile.model.Sponsor)

Example 2 with Sponsor

use of ca.etsmtl.applets.etsmobile.model.Sponsor in project ETSMobile-Android2 by ApplETS.

the class SponsorManager method deleteExpiredSponsor.

public void deleteExpiredSponsor(SponsorList sponsorList) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, Sponsor> sponsorHashMap = new HashMap<String, Sponsor>();
    for (Sponsor sponsor : sponsorList) {
        sponsorHashMap.put(sponsor.getName(), sponsor);
    }
    ArrayList<Sponsor> dbSponsor;
    try {
        dbSponsor = (ArrayList<Sponsor>) dbHelper.getDao(Sponsor.class).queryForAll();
        for (Sponsor sponsorNew : dbSponsor) {
            if (!sponsorHashMap.containsKey(sponsorNew.getName())) {
                Dao<Sponsor, String> sponsorDao = dbHelper.getDao(Sponsor.class);
                sponsorDao.deleteById(sponsorNew.getName());
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Sponsor(ca.etsmtl.applets.etsmobile.model.Sponsor)

Example 3 with Sponsor

use of ca.etsmtl.applets.etsmobile.model.Sponsor in project ETSMobile-Android2 by ApplETS.

the class SponsorsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup v = (ViewGroup) inflater.inflate(R.layout.fragment_sponsors, container, false);
    loadingView = (LoadingView) v.findViewById(R.id.loadingView_sponsor);
    sponsorGridView = (GridView) v.findViewById(R.id.gridView_sponsor);
    sponsorList = new ArrayList<Sponsor>();
    mSponsorManager = new SponsorManager(getActivity());
    mSponsorManager.addObserver(this);
    loadingView.showLoadingView();
    refreshList();
    dataManager.sendRequest(new AppletsApiSponsorRequest(getActivity()), this);
    AnalyticsHelper.getInstance(getActivity()).sendScreenEvent(getClass().getSimpleName());
    return v;
}
Also used : AppletsApiSponsorRequest(ca.etsmtl.applets.etsmobile.http.AppletsApiSponsorRequest) ViewGroup(android.view.ViewGroup) Sponsor(ca.etsmtl.applets.etsmobile.model.Sponsor) SponsorManager(ca.etsmtl.applets.etsmobile.util.SponsorManager)

Example 4 with Sponsor

use of ca.etsmtl.applets.etsmobile.model.Sponsor in project ETSMobile-Android2 by ApplETS.

the class SponsorsFragment method refreshList.

public void refreshList() {
    sponsorList = mSponsorManager.getSponsorList();
    adapter = new SponsorAdapter(getActivity(), R.layout.row_sponsor, sponsorList, this);
    sponsorGridView.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    sponsorGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Sponsor item = sponsorList.get(position);
            String url = item.getUrl();
            if (URLUtil.isValidUrl(url)) {
                Intent internetIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(internetIntent);
            }
        }
    });
}
Also used : Sponsor(ca.etsmtl.applets.etsmobile.model.Sponsor) AdapterView(android.widget.AdapterView) Intent(android.content.Intent) GridView(android.widget.GridView) LoadingView(ca.etsmtl.applets.etsmobile.views.LoadingView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SponsorAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.SponsorAdapter)

Example 5 with Sponsor

use of ca.etsmtl.applets.etsmobile.model.Sponsor in project ETSMobile-Android2 by ApplETS.

the class SponsorAdapter method getView.

@SuppressLint("DefaultLocale")
@Override
public View getView(int position, View view, ViewGroup parent) {
    ViewHolder holder;
    if (view != null) {
        holder = (ViewHolder) view.getTag();
    } else {
        view = inflater.inflate(R.layout.row_sponsor, parent, false);
        holder = new ViewHolder();
        holder.tvName = (TextView) view.findViewById(R.id.tv_row_sponsor_name);
        holder.imageSource = (ImageView) view.findViewById(R.id.iv_sponsor_source);
        view.setTag(holder);
    }
    int imageSize;
    Sponsor item = getItem(position);
    switch(item.getIndex()) {
        case 6:
            imageSize = 500;
            break;
        case 5 | 4:
            imageSize = 400;
            break;
        default:
            imageSize = 300;
            break;
    }
    Picasso.with(context).load(item.getImageUrl()).resize(imageSize, imageSize).into(holder.imageSource);
    holder.tvName.setText(item.getName());
    return view;
}
Also used : Sponsor(ca.etsmtl.applets.etsmobile.model.Sponsor) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

Sponsor (ca.etsmtl.applets.etsmobile.model.Sponsor)5 DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)2 SQLException (java.sql.SQLException)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 ListView (android.widget.ListView)1 AppletsApiSponsorRequest (ca.etsmtl.applets.etsmobile.http.AppletsApiSponsorRequest)1 SponsorAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.SponsorAdapter)1 SponsorManager (ca.etsmtl.applets.etsmobile.util.SponsorManager)1 LoadingView (ca.etsmtl.applets.etsmobile.views.LoadingView)1 HashMap (java.util.HashMap)1