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;
}
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();
}
}
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;
}
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);
}
}
});
}
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;
}
Aggregations