|
|
@ -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 |
|
|
|