1 /* DashboardNewsStuv.java
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp.fragments;
17 import android.os.Bundle;
18 import android.support.v4.app.Fragment;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.widget.RelativeLayout;
23 import android.widget.TextView;
25 import java.util.Collections;
26 import java.util.Comparator;
27 import java.util.Date;
29 import de.dhbwloe.campusapp.R;
32 * A simple {@link Fragment} subclass.
34 public class DashboardNewsStuv extends News {
35 private View newsEntryPanel;
36 private View newsNonePanel;
38 public DashboardNewsStuv() {
39 // Required empty public constructor
44 public View onCreateView(LayoutInflater inflater, ViewGroup container,
45 Bundle savedInstanceState) {
47 oFragmentView = new RelativeLayout(inflater.getContext());
48 newsEntryPanel = inflater.inflate(R.layout.fragment_dashboard_news_entry, container, false);
49 newsNonePanel = inflater.inflate(R.layout.fragment_dashboard_news_none, container, false);
55 public void onResume() {
61 private void refreshStuvNews() {
62 loadNewsSource("STUV", false);
63 loadEventsSource("STUV", false);
65 Collections.sort(newsListItems, new Comparator<NewsListItem>() {
67 public int compare(NewsListItem item2, NewsListItem item1) {
68 long now = (new Date()).getTime() / 1000;
69 return (int) (item2.getTimeDifference(now) - item1.getTimeDifference(now));
73 RelativeLayout container = (RelativeLayout) oFragmentView;
74 container.removeAllViews();
76 if(newsListItems.size() > 0) {
77 container.addView(newsEntryPanel);
79 TextView dateView = (TextView) newsEntryPanel.findViewById(R.id.newsDate);
80 TextView titleView = (TextView) newsEntryPanel.findViewById(R.id.newsTitle);
81 NewsListItem newsItem = newsListItems.get(0);
83 dateView.setText(newsItem.getFormatedDate());
84 titleView.setText(newsItem.getTitle());
86 container.addView(newsNonePanel);