From 440354e578de99211ebce50278a3333cd9a61911 Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Thu, 13 Nov 2014 19:36:43 +0100 Subject: [PATCH] improving article list: adding host label --- .../java/fr/gaulupeau/apps/Poche/Article.java | 33 +++++++++++++++---- .../apps/Poche/ReadingListAdapter.java | 4 ++- app/src/main/res/layout/article_list.xml | 22 +++++++++---- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/Article.java b/app/src/main/java/fr/gaulupeau/apps/Poche/Article.java index 8d15d5a..c34339c 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/Article.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/Article.java @@ -1,18 +1,37 @@ package fr.gaulupeau.apps.Poche; +import android.util.Log; + +import java.net.URL; + public class Article { public String url; public String id; public String title; public String content; public String archive; + + private URL m_url = null; public Article(String url, String id, String title, String content, String archive) { - super(); - this.url = url; - this.id = id; - this.title = title; - this.content = content; - this.archive = archive; - } + super(); + this.url = url; + this.id = id; + this.title = title; + this.content = content; + this.archive = archive; + + try { + this.m_url = new URL(url); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public String getHostOfUrl() { + if (this.m_url != null) { + return m_url.getHost(); + } + return ""; + } } diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ReadingListAdapter.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ReadingListAdapter.java index bda0ca0..57f01d9 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ReadingListAdapter.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ReadingListAdapter.java @@ -42,8 +42,10 @@ public class ReadingListAdapter extends BaseAdapter { convertView = inflater.inflate(R.layout.article_list, parent, false); } TextView tvTitle = (TextView) convertView.findViewById(R.id.listitem_titre); - //Log.e("title", entry.title); + TextView tvHost = (TextView) convertView.findViewById(R.id.listitem_textview_url); + tvTitle.setText(entry.title); + tvHost.setText(entry.getHostOfUrl()); return convertView; } diff --git a/app/src/main/res/layout/article_list.xml b/app/src/main/res/layout/article_list.xml index fbd4c3b..5ce7349 100644 --- a/app/src/main/res/layout/article_list.xml +++ b/app/src/main/res/layout/article_list.xml @@ -1,14 +1,22 @@ - + + +