From acd50438ed3b2b870ba365401e40d80320a4258e Mon Sep 17 00:00:00 2001 From: Defend Date: Tue, 14 Feb 2017 19:58:56 +0300 Subject: [PATCH] New methods addNewsList and drawNewsList - they will be used for controlling cabinet activity news list. --- .../defdevteam/tstu/FeedController.java | 65 ++++++++++++------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java b/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java index eecab63..2008a89 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java @@ -11,6 +11,7 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par FeedReader feedReader; FeedUpdater feedUpdater; String newsFeed; + NewsItemList newsItemList; int updateRate; //in minutes private CabinetActivity activity; @@ -21,6 +22,7 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par public FeedController(CabinetActivity activity, int updateRate, String rssUrl) { feedReader = new FeedReader(this, rssUrl); feedReader.registerCallback(this); + newsItemList = new NewsItemList(); feedUpdater = new FeedUpdater(); this.activity = activity; this.updateRate = updateRate; @@ -64,34 +66,61 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par startFeedReader(); try { //TODO: вернуть к норме updateRate*60*1000 - sleep(updateRate*60); + sleep(updateRate*60*1000); } catch (InterruptedException e) { e.printStackTrace(); } } public FeedUpdater() { - this.start(); + //this.start(); } } - public String getRssString() throws Exception{ - if(checkFeedReader()) { - newsFeed = feedReader.getResult(); - return newsFeed; +// public String getRssString() throws Exception{ +// if(checkFeedReader()) { +// newsFeed = feedReader.getResult(); +// return newsFeed; +// } +// throw new Exception("Feed Reader returned empty string"); +// } + + public void addNewsList(String title, String text, String link) { + newsItemList.add(new NewsItemList().new Group( + title, + text, + link + )); + } + + public void drawNewsList(NewsItemList newsItemList) { + for (NewsItemList.Group item: newsItemList) { + final String title = item.getTitle(); + final String text = item.getText(); + final String link = item.getLink(); + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + activity.addNewsItem(title, text, link); + } + }); } - throw new Exception("Feed Reader returned empty string"); } - @Override - public void onSuccess(final String result){ - this.newsFeed = result; + public void logIt(final String LOGIT) { activity.runOnUiThread(new Runnable() { @Override public void run() { - activity.addNewsItem("Test", result, ""); + Log.i("MAIN DEBUG MESSAGE:", LOGIT); } }); + } + + + @Override + public void onSuccess(final String result){ + this.newsFeed = result; + addNewsList("Callback Reader Test", result, ""); FeedParser parser = new FeedParser(result); parser.registerCallback(this); parser.parseXML(); @@ -103,18 +132,8 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par } @Override - public void onSuccessParsing(NewsItemList newsItemList) { - for (NewsItemList.Group item: newsItemList) { - final String title = item.getTitle(); - final String text = item.getText(); - final String link = item.getLink(); - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - activity.addNewsItem(title, text, link); - } - }); - } + public void onSuccessParsing() { + drawNewsList(this.newsItemList); } @Override