Search in sources :

Example 1 with NewsArticle

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();
}
Also used : InstalledPack(net.technicpack.launchercore.modpacks.InstalledPack) RestfulAPIException(net.technicpack.rest.RestfulAPIException) NewsArticle(net.technicpack.platform.io.NewsArticle) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) LinkedList(java.util.LinkedList)

Example 2 with NewsArticle

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);
}
Also used : NewsWidget(net.technicpack.launcher.ui.controls.feeds.NewsWidget) NewsArticle(net.technicpack.platform.io.NewsArticle) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Aggregations

NewsArticle (net.technicpack.platform.io.NewsArticle)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 LinkedList (java.util.LinkedList)1 NewsWidget (net.technicpack.launcher.ui.controls.feeds.NewsWidget)1 InstalledPack (net.technicpack.launchercore.modpacks.InstalledPack)1 ModpackModel (net.technicpack.launchercore.modpacks.ModpackModel)1 RestfulAPIException (net.technicpack.rest.RestfulAPIException)1