Fix erreur lors de query vide + disable champ de recherche durant la mise a jour de l'affichage
This commit is contained in:
parent
d3d845f15c
commit
52279c68c5
|
@ -152,13 +152,13 @@ public class RootLayout extends Application implements EventObserver {
|
|||
|
||||
case "NewsQuerySuccess":
|
||||
System.out.println(NewsListModel.getInstance().getNews().size()+" News ont été trouvé");
|
||||
if(NewsListModel.getInstance().getNews().size() != 0) {
|
||||
|
||||
this.articles.clearContent();
|
||||
|
||||
TextField tx = new TextField();
|
||||
tx.setPromptText("search...");
|
||||
tx.setId("mag_searchbar");
|
||||
tx.setDisable(true);
|
||||
tx.setOnKeyPressed(new EventHandler<KeyEvent>() {
|
||||
|
||||
@Override
|
||||
|
@ -181,6 +181,9 @@ public class RootLayout extends Application implements EventObserver {
|
|||
|
||||
});
|
||||
|
||||
|
||||
if(NewsListModel.getInstance().getNews().size() != 0) {
|
||||
|
||||
// For each news
|
||||
for( NewsModel news : NewsListModel.getInstance().getNews() ){
|
||||
|
||||
|
@ -197,6 +200,8 @@ public class RootLayout extends Application implements EventObserver {
|
|||
}
|
||||
}
|
||||
|
||||
tx.setDisable(false);
|
||||
|
||||
break;
|
||||
|
||||
case "NewsQueryFailed":
|
||||
|
|
|
@ -119,6 +119,13 @@ public class NewsListModel implements Observable{
|
|||
}
|
||||
|
||||
public void query(String q) {
|
||||
//si recherche vide
|
||||
if(q.isEmpty()) {
|
||||
this.news = new ArrayList<NewsModel>();
|
||||
NewsListModel.this.notifyObservers(new Event("NewsModel","NewsQuerySuccess"));
|
||||
return;
|
||||
}
|
||||
|
||||
//si la recherche de source s'est fini avec une erreur, pas la peine de chercher des articles
|
||||
if(this.apiError) {
|
||||
NewsListModel.this.notifyObservers(new Event("NewsModel","NewsQueryFailed"));
|
||||
|
|
Loading…
Reference in New Issue