forked from Meel703/elemental-pixel-dungeon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.8.2: added a news checker service
- Loading branch information
Showing
14 changed files
with
437 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/News.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Pixel Dungeon | ||
* Copyright (C) 2012-2015 Oleg Dolya | ||
* | ||
* Shattered Pixel Dungeon | ||
* Copyright (C) 2014-2020 Evan Debenham | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
package com.shatteredpixel.shatteredpixeldungeon.services.news; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
|
||
public class News { | ||
|
||
public static NewsService service; | ||
|
||
public static boolean supportsNews(){ | ||
return service != null; | ||
} | ||
|
||
private static Date lastCheck = null; | ||
private static final long CHECK_DELAY = 1000*60*60; //1 hour | ||
|
||
public static void checkForNews(){ | ||
if (!supportsNews()) return; | ||
if (lastCheck != null && (new Date().getTime() - lastCheck.getTime()) < CHECK_DELAY) return; | ||
|
||
service.checkForArticles(new NewsService.NewsResultCallback() { | ||
@Override | ||
public void onArticlesFound(ArrayList<NewsArticle> articles) { | ||
lastCheck = new Date(); | ||
News.articles = articles; | ||
} | ||
|
||
@Override | ||
public void onConnectionFailed() { | ||
lastCheck = null; | ||
News.articles = null; | ||
} | ||
}); | ||
|
||
} | ||
|
||
private static ArrayList<NewsArticle> articles; | ||
|
||
public static boolean articlesAvailable(){ | ||
return articles != null; | ||
} | ||
|
||
public static ArrayList<NewsArticle> articles(){ | ||
return articles; | ||
} | ||
|
||
public static int unreadArticles(Date lastRead){ | ||
int unread = 0; | ||
for (NewsArticle article : articles){ | ||
if (article.date.after(lastRead)) unread++; | ||
} | ||
return unread; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Pixel Dungeon | ||
* Copyright (C) 2012-2015 Oleg Dolya | ||
* | ||
* Shattered Pixel Dungeon | ||
* Copyright (C) 2014-2020 Evan Debenham | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
apply plugin: 'java-library' | ||
|
||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' | ||
sourceCompatibility = targetCompatibility = appJavaCompatibility | ||
|
||
dependencies { | ||
implementation project(':SPD-classes') | ||
api project(':services') | ||
} |
59 changes: 59 additions & 0 deletions
59
...gNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/DebugNews.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Pixel Dungeon | ||
* Copyright (C) 2012-2015 Oleg Dolya | ||
* | ||
* Shattered Pixel Dungeon | ||
* Copyright (C) 2014-2020 Evan Debenham | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
package com.shatteredpixel.shatteredpixeldungeon.services.news; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
public class DebugNews extends NewsService { | ||
|
||
@Override | ||
public void checkForArticles(NewsResultCallback callback) { | ||
|
||
//turn on to test connection failure | ||
if (false){ | ||
callback.onConnectionFailed(); | ||
return; | ||
} | ||
|
||
ArrayList<NewsArticle> articles = new ArrayList<>(); | ||
for (int i = 0; i < 10; i++){ | ||
NewsArticle article = new NewsArticle(); | ||
article.title = "TEST ARTICLE " + i; | ||
article.summary = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do " + | ||
"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + | ||
"veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + | ||
"commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit " + | ||
"esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat " + | ||
"non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; | ||
article.URL = "http://www.google.com"; | ||
// a year in the past, plus one day for each article | ||
long daysBack = 365+i; | ||
article.date = new Date(System.currentTimeMillis() - (daysBack*1000*60*60*24)); | ||
articles.add(article); | ||
} | ||
|
||
callback.onArticlesFound(articles); | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ugNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/NewsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Pixel Dungeon | ||
* Copyright (C) 2012-2015 Oleg Dolya | ||
* | ||
* Shattered Pixel Dungeon | ||
* Copyright (C) 2014-2020 Evan Debenham | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
package com.shatteredpixel.shatteredpixeldungeon.services.news; | ||
|
||
public class NewsImpl { | ||
|
||
private static NewsService newsChecker = new DebugNews(); | ||
|
||
public static NewsService getNewsService(){ | ||
return newsChecker; | ||
} | ||
|
||
public static boolean supportsNews(){ | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Pixel Dungeon | ||
* Copyright (C) 2012-2015 Oleg Dolya | ||
* | ||
* Shattered Pixel Dungeon | ||
* Copyright (C) 2014-2020 Evan Debenham | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
apply plugin: 'java-library' | ||
|
||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' | ||
sourceCompatibility = targetCompatibility = appJavaCompatibility | ||
|
||
dependencies { | ||
implementation project(':SPD-classes') | ||
api project(':services') | ||
} |
36 changes: 36 additions & 0 deletions
36
...edNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/NewsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Pixel Dungeon | ||
* Copyright (C) 2012-2015 Oleg Dolya | ||
* | ||
* Shattered Pixel Dungeon | ||
* Copyright (C) 2014-2020 Evan Debenham | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
package com.shatteredpixel.shatteredpixeldungeon.services.news; | ||
|
||
public class NewsImpl { | ||
|
||
private static NewsService newsChecker = new ShatteredNews(); | ||
|
||
public static NewsService getNewsService(){ | ||
return newsChecker; | ||
} | ||
|
||
public static boolean supportsNews(){ | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.