Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / News.java
index 5efb4f7b429c4e68cbdaa00d305e400c461bceaf..d2e6e0a3edb4ec72503ab2639cc87bd53a7394fd 100644 (file)
@@ -1,6 +1,19 @@
+/* News.java
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
 package de.dhbwloe.campusapp.fragments;
-
-
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentActivity;
@@ -42,7 +55,7 @@ public class News extends CampusAppFragment {
 
     private View view;
     private NewsListAdapter listAdapter;
-    private ArrayList<NewsListItem> newsListItems = new ArrayList<NewsListItem>();
+    protected ArrayList<NewsListItem> newsListItems = new ArrayList<NewsListItem>();
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
@@ -86,10 +99,11 @@ public class News extends CampusAppFragment {
     @Override
     public void onResume() {
         super.onResume();
-        refreshNewsItems();
+        if(view != null)
+            refreshNewsItems();
     }
 
-    private void refreshNewsItems() {
+    protected void refreshNewsItems() {
         newsListItems.clear();
 
         CheckBox showDhbwNewsChkbok = (CheckBox) view.findViewById(R.id.showDhbwNews);
@@ -109,14 +123,15 @@ public class News extends CampusAppFragment {
         Collections.sort(newsListItems, new Comparator<NewsListItem>() {
             @Override
             public int compare(NewsListItem item2, NewsListItem item1) {
-                long now = (new Date()).getTime()/1000;
+                long now = (new Date()).getTime() / 1000;
                 return (int) (item2.getTimeDifference(now) - item1.getTimeDifference(now));
             }
         });
-        listAdapter.notifyDataSetChanged();
+        if(listAdapter != null)
+            listAdapter.notifyDataSetChanged();
     }
 
-    private void loadNewsSource(String sourceName, boolean isDhbw) {
+    protected void loadNewsSource(String sourceName, boolean isDhbw) {
         long now = (new Date()).getTime() / 1000;
 
         NewsItem[] news = AppContext.getDatabaseManager().getNewsItems(sourceName, now, now - (86400 * 30 * 6)); // load 6 month
@@ -126,7 +141,7 @@ public class News extends CampusAppFragment {
         }
     }
 
-    private void loadEventsSource(String sourceName, boolean isDhbw) {
+    protected void loadEventsSource(String sourceName, boolean isDhbw) {
         long now = (new Date()).getTime() / 1000;
 
         CourseEvent[] events = AppContext.getDatabaseManager().getCourseCalendarTimetable(sourceName, now, 30 * 6); // load 6 month