Search in sources :

Example 1 with Nouvelle

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

the class NewsAdapter 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_news, parent, false);
        holder = new ViewHolder();
        holder.tvTitre = (TextView) view.findViewById(R.id.tv_row_news_titre);
        holder.tvDate = (TextView) view.findViewById(R.id.tv_row_news_date);
        holder.imageSource = (ImageView) view.findViewById(R.id.iv_news_image);
        view.setTag(holder);
    }
    Nouvelle item = getItem(position);
    String image = item.getUrlPicture();
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTime date = dateTimeFormatter.parseDateTime(item.getDate());
    holder.tvDate.setText(date.toString("dd MMM yyyy", Locale.CANADA_FRENCH));
    if (!image.equals("")) {
        Picasso.with(context).load(image).placeholder(R.drawable.loading_spinner).resize(300, 300).into(holder.imageSource);
    }
    holder.tvTitre.setText(item.getTitre());
    return view;
}
Also used : Nouvelle(ca.etsmtl.applets.etsmobile.model.Nouvelle) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) SuppressLint(android.annotation.SuppressLint)

Example 2 with Nouvelle

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

the class NewsDetailsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_news_details);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(name);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (savedInstanceState == null) {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            return;
        }
        key = extras.getString("key");
        name = extras.getString("name");
        type = extras.getString("type");
        urlImage = extras.getString("urlImage");
        value = extras.getString("value");
        toolbar.setTitle(name);
    }
    listView = (ListView) findViewById(R.id.list_news_details);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Nouvelle item = (Nouvelle) parent.getItemAtPosition(position);
            String url = item.getLink();
            if (URLUtil.isValidUrl(url)) {
                Intent internetIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(internetIntent);
            } else {
                Toast.makeText(NewsDetailsActivity.this, getString(R.string.erreur_lien), Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : Bundle(android.os.Bundle) Nouvelle(ca.etsmtl.applets.etsmobile.model.Nouvelle) AdapterView(android.widget.AdapterView) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Aggregations

Nouvelle (ca.etsmtl.applets.etsmobile.model.Nouvelle)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1