use of net.technicpack.platform.io.NewsArticle in project LauncherV3 by TechnicPack.
the class InitialV3Migrator method migrate.
@Override
public void migrate(TechnicSettings settings, IInstalledPackRepository packStore, LauncherDirectories directories, IUserStore<MojangUser> users) {
// A fresh install/upgrade from v2 shouldn't show the latest news as being new
int maxNewsId = 0;
try {
for (NewsArticle article : platformApi.getNews().getArticles()) {
int newsId = article.getId();
if (newsId > maxNewsId)
maxNewsId = newsId;
}
settings.setLatestNewsArticle(maxNewsId);
} catch (RestfulAPIException ex) {
// Just kill the exception & go with ID 0
}
List<ModpackModel> deletePacks = new LinkedList<ModpackModel>();
for (String packName : packStore.getPackNames()) {
InstalledPack pack = packStore.getInstalledPacks().get(packName);
ModpackModel model = new ModpackModel(pack, null, packStore, directories);
if (!model.getInstalledDirectory().exists()) {
deletePacks.add(model);
}
}
for (ModpackModel deletePack : deletePacks) {
deletePack.delete();
}
packStore.save();
}
use of net.technicpack.platform.io.NewsArticle in project LauncherV3 by TechnicPack.
the class NewsSelector method loadNewsItems.
protected void loadNewsItems(NewsData news) {
int count = 0;
newLatestNewsArticle = settings.getLatestNewsArticle();
for (int i = 0; i < news.getArticles().size(); i++) {
if (news.getArticles().get(i).getId() > settings.getLatestNewsArticle()) {
count++;
if (news.getArticles().get(i).getId() > newLatestNewsArticle)
newLatestNewsArticle = news.getArticles().get(i).getId();
}
}
if (count > 0) {
circle.setVisible(true);
circle.setCount(count);
} else {
circle.setVisible(false);
}
Collections.sort(news.getArticles(), new Comparator<NewsArticle>() {
@Override
public int compare(NewsArticle o1, NewsArticle o2) {
if (o1.getDate().getTime() > o2.getDate().getTime())
return -1;
else if (o1.getDate().getTime() < o2.getDate().getTime())
return 1;
else
return 0;
}
});
widgetHost.removeAll();
GridBagConstraints constraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
for (int i = 0; i < news.getArticles().size(); i++) {
NewsWidget widget = new NewsWidget(resources, news.getArticles().get(i), avatarRepo.startImageJob(news.getArticles().get(i).getAuthorshipInfo()));
widget.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof NewsWidget)
selectNewsItem((NewsWidget) e.getSource());
}
});
widgetHost.add(widget, constraints);
constraints.gridy++;
if (selectedItem == null)
selectNewsItem(widget);
}
constraints.weighty = 1.0;
widgetHost.add(Box.createGlue(), constraints);
}
Aggregations