diff --git a/Atarashii/build.gradle b/Atarashii/build.gradle index 253403df..05a7d79e 100644 --- a/Atarashii/build.gradle +++ b/Atarashii/build.gradle @@ -28,23 +28,23 @@ android { productFlavors { Production { applicationId 'net.somethingdreadful.MAL' - versionCode 39 - versionName '2.4' + versionCode 40 + versionName '2.4.1' } FLOSSProduction { applicationId 'net.somethingdreadful.MAL' - versionCode 39 - versionName '2.4' + versionCode 40 + versionName '2.4.1' } Beta { applicationId 'net.somethingdreadful.MAL.beta' - versionCode 82 - versionName '2.4' + versionCode 83 + versionName '2.4.1' } FLOSSBeta { applicationId 'net.somethingdreadful.MAL.beta' - versionCode 82 - versionName '2.4' + versionCode 83 + versionName '2.4.1' } } diff --git a/Atarashii/src/main/java/net/somethingdreadful/MAL/api/MALApi.java b/Atarashii/src/main/java/net/somethingdreadful/MAL/api/MALApi.java index adb4df48..a59aaa83 100644 --- a/Atarashii/src/main/java/net/somethingdreadful/MAL/api/MALApi.java +++ b/Atarashii/src/main/java/net/somethingdreadful/MAL/api/MALApi.java @@ -31,11 +31,12 @@ public class MALApi { // Use version 2.1 of the API interface - private static final String API_HOST = "https://api.atarashiiapp.com/2.1/"; + private static final String API_HOST = "https://malapi.atarashiiapp.com/2.1/"; private static final String MAL_HOST = "https://myanimelist.net/"; private Activity activity = null; - private MALInterface service; + private MALInterface APIservice; + private MALInterface MALservice; public MALApi() { setupRESTService(AccountService.getUsername(), AccountService.getPassword()); @@ -50,7 +51,7 @@ public MALApi(Activity activity) { * Only use for verifying. */ public MALApi(String username, String password) { - service = APIHelper.createClient(MAL_HOST, MALInterface.class, Credentials.basic(username, password)); + setupRESTService(username, password); } public static String getListTypeString(ListType type) { @@ -58,18 +59,19 @@ public static String getListTypeString(ListType type) { } private void setupRESTService(String username, String password) { - service = APIHelper.createClient(API_HOST, MALInterface.class, Credentials.basic(username, password)); + APIservice = APIHelper.createClient(API_HOST, MALInterface.class, Credentials.basic(username, password)); + MALservice = APIHelper.createClient(MAL_HOST, MALInterface.class, Credentials.basic(username, password)); } public boolean isAuth() { - return APIHelper.isOK(service.verifyAuthentication(), "isAuth"); + return APIHelper.isOK(MALservice.verifyAuthentication(), "isAuth"); } public ArrayList searchAnime(String query, int page) { if (PrefManager.getNSFWEnabled()) { Response> response = null; try { - response = service.searchAnime(query, page).execute(); + response = APIservice.searchAnime(query, page).execute(); return AnimeList.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "searchAnime", e); @@ -89,7 +91,7 @@ public ArrayList searchManga(String query, int page) { if (PrefManager.getNSFWEnabled()) { Response> response = null; try { - response = service.searchManga(query, page).execute(); + response = APIservice.searchManga(query, page).execute(); return MangaList.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "searchManga", e); @@ -108,7 +110,7 @@ public ArrayList searchManga(String query, int page) { public UserList getAnimeList(String username) { Response response = null; try { - response = service.getAnimeList(username).execute(); + response = APIservice.getAnimeList(username).execute(); return AnimeList.createBaseModel(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getAnimeList", e); @@ -119,7 +121,7 @@ public UserList getAnimeList(String username) { public UserList getMangaList(String username) { Response response = null; try { - response = service.getMangaList(username).execute(); + response = APIservice.getMangaList(username).execute(); return MangaList.createBaseModel(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getMangaList", e); @@ -130,7 +132,7 @@ public UserList getMangaList(String username) { public Anime getAnime(int id, int mine) { Response response = null; try { - response = service.getAnime(id, mine).execute(); + response = APIservice.getAnime(id, mine).execute(); return response.body().createBaseModel(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getAnime", e); @@ -141,7 +143,7 @@ public Anime getAnime(int id, int mine) { public Manga getManga(int id, int mine) { Response response = null; try { - response = service.getManga(id, mine).execute(); + response = APIservice.getManga(id, mine).execute(); return response.body().createBaseModel(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getManga", e); @@ -151,7 +153,7 @@ public Manga getManga(int id, int mine) { public boolean addOrUpdateAnime(Anime anime) { if (anime.getCreateFlag()) - return APIHelper.isOK(service.addAnime(anime.getId(), anime.getWatchedStatus(), anime.getWatchedEpisodes(), anime.getScore()), "addOrUpdateAnime"); + return APIHelper.isOK(APIservice.addAnime(anime.getId(), anime.getWatchedStatus(), anime.getWatchedEpisodes(), anime.getScore()), "addOrUpdateAnime"); else { if (anime.isDirty()) { // map anime property names to api field names @@ -182,7 +184,7 @@ public boolean addOrUpdateAnime(Anime anime) { } } } - return APIHelper.isOK(service.updateAnime(anime.getId(), fieldMap), "addOrUpdateAnime"); + return APIHelper.isOK(APIservice.updateAnime(anime.getId(), fieldMap), "addOrUpdateAnime"); } } return false; @@ -190,7 +192,7 @@ public boolean addOrUpdateAnime(Anime anime) { public boolean addOrUpdateManga(Manga manga) { if (manga.getCreateFlag()) - return APIHelper.isOK(service.addManga(manga.getId(), manga.getReadStatus(), manga.getChaptersRead(), manga.getVolumesRead(), manga.getScore()), "addOrUpdateManga"); + return APIHelper.isOK(APIservice.addManga(manga.getId(), manga.getReadStatus(), manga.getChaptersRead(), manga.getVolumesRead(), manga.getScore()), "addOrUpdateManga"); else { if (manga.isDirty()) { // map manga property names to api field names @@ -218,25 +220,25 @@ public boolean addOrUpdateManga(Manga manga) { } } } - return APIHelper.isOK(service.updateManga(manga.getId(), fieldMap), "addOrUpdateManga"); + return APIHelper.isOK(APIservice.updateManga(manga.getId(), fieldMap), "addOrUpdateManga"); } } return false; } public boolean deleteAnimeFromList(int id) { - return APIHelper.isOK(service.deleteAnime(id), "deleteAnimeFromList"); + return APIHelper.isOK(APIservice.deleteAnime(id), "deleteAnimeFromList"); } public boolean deleteMangaFromList(int id) { - return APIHelper.isOK(service.deleteManga(id), "deleteMangaFromList"); + return APIHelper.isOK(APIservice.deleteManga(id), "deleteMangaFromList"); } public ArrayList getBrowseAnime(Map queries) { retrofit2.Response> response = null; AppLog.log(Log.INFO, "Atarashii", "MALApi.getBrowseAnime(): queries=" + queries.toString()); try { - response = service.getBrowseAnime(queries).execute(); + response = APIservice.getBrowseAnime(queries).execute(); return AnimeList.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getBrowseAnime: " + queries.toString(), e); @@ -248,7 +250,7 @@ public ArrayList getBrowseManga(Map queries) { retrofit2.Response> response = null; AppLog.log(Log.INFO, "Atarashii", "MALApi.getBrowseManga(): queries=" + queries.toString()); try { - response = service.getBrowseManga(queries).execute(); + response = APIservice.getBrowseManga(queries).execute(); return MangaList.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getBrowseManga: " + queries.toString(), e); @@ -267,7 +269,7 @@ private HashMap checkNSFW(HashMap map) { public ArrayList getMostPopularAnime(int page) { Response> response = null; try { - response = service.getPopularAnime(page).execute(); + response = APIservice.getPopularAnime(page).execute(); return AnimeList.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getMostPopularAnime: page =" + page, e); @@ -278,7 +280,7 @@ public ArrayList getMostPopularAnime(int page) { public ArrayList getMostPopularManga(int page) { Response> response = null; try { - response = service.getPopularManga(page).execute(); + response = APIservice.getPopularManga(page).execute(); return MangaList.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getMostPopularManga: page =" + page, e); @@ -289,7 +291,7 @@ public ArrayList getMostPopularManga(int page) { public ArrayList getTopRatedAnime(int page) { Response> response = null; try { - response = service.getTopRatedAnime(page).execute(); + response = APIservice.getTopRatedAnime(page).execute(); return AnimeList.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getTopRatedAnime: page =" + page, e); @@ -300,7 +302,7 @@ public ArrayList getTopRatedAnime(int page) { public ArrayList getTopRatedManga(int page) { Response> response = null; try { - response = service.getTopRatedManga(page).execute(); + response = APIservice.getTopRatedManga(page).execute(); return MangaList.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getTopRatedManga: page =" + page, e); @@ -347,7 +349,7 @@ public ArrayList getUpcomingManga(int page) { public Profile getProfile(String user) { Response response = null; try { - response = service.getProfile(user).execute(); + response = APIservice.getProfile(user).execute(); return response.body().createBaseModel(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getProfile", e); @@ -358,7 +360,7 @@ public Profile getProfile(String user) { public ArrayList getFriends(String user) { Response> response = null; try { - response = service.getFriends(user).execute(); + response = APIservice.getFriends(user).execute(); return Friend.convertBaseFriendList(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getFriends", e); @@ -369,7 +371,7 @@ public ArrayList getFriends(String user) { public ForumMain getForum() { Response response = null; try { - response = service.getForum().execute(); + response = APIservice.getForum().execute(); return response.body(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getForum", e); @@ -380,7 +382,7 @@ public ForumMain getForum() { public ForumMain getCategoryTopics(int id, int page) { Response response = null; try { - response = service.getCategoryTopics(id, page).execute(); + response = APIservice.getCategoryTopics(id, page).execute(); return response.body(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getCategoryTopics", e); @@ -391,7 +393,7 @@ public ForumMain getCategoryTopics(int id, int page) { public ForumMain getForumAnime(int id, int page) { Response response = null; try { - response = service.getForumAnime(id, page).execute(); + response = APIservice.getForumAnime(id, page).execute(); return response.body(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getForumAnime", e); @@ -402,7 +404,7 @@ public ForumMain getForumAnime(int id, int page) { public ForumMain getForumManga(int id, int page) { Response response = null; try { - response = service.getForumManga(id, page).execute(); + response = APIservice.getForumManga(id, page).execute(); return response.body(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getForumManga", e); @@ -413,7 +415,7 @@ public ForumMain getForumManga(int id, int page) { public ForumMain getPosts(int id, int page) { Response response = null; try { - response = service.getPosts(id, page).execute(); + response = APIservice.getPosts(id, page).execute(); return response.body(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getPosts", e); @@ -424,7 +426,7 @@ public ForumMain getPosts(int id, int page) { public ForumMain getSubBoards(int id, int page) { Response response = null; try { - response = service.getSubBoards(id, page).execute(); + response = APIservice.getSubBoards(id, page).execute(); return response.body(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getSubBoards", e); @@ -433,21 +435,21 @@ public ForumMain getSubBoards(int id, int page) { } public boolean addComment(int id, String message) { - return APIHelper.isOK(service.addComment(id, message), "addComment"); + return APIHelper.isOK(APIservice.addComment(id, message), "addComment"); } public boolean updateComment(int id, String message) { - return APIHelper.isOK(service.updateComment(id, message), "updateComment"); + return APIHelper.isOK(APIservice.updateComment(id, message), "updateComment"); } public boolean addTopic(int id, String title, String message) { - return APIHelper.isOK(service.addTopic(id, title, message), "addTopic"); + return APIHelper.isOK(APIservice.addTopic(id, title, message), "addTopic"); } public ForumMain search(String query) { Response response = null; try { - response = service.search(query).execute(); + response = APIservice.search(query).execute(); return response.body(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "search", e); @@ -458,7 +460,7 @@ public ForumMain search(String query) { public ArrayList getAnimeReviews(int id, int page) { Response> response = null; try { - response = service.getAnimeReviews(id, page).execute(); + response = APIservice.getAnimeReviews(id, page).execute(); return net.somethingdreadful.MAL.api.MALModels.AnimeManga.Reviews.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getAnimeReviews", e); @@ -469,7 +471,7 @@ public ArrayList getAnimeReviews(int id, int page) { public ArrayList getMangaReviews(int id, int page) { Response> response = null; try { - response = service.getMangaReviews(id, page).execute(); + response = APIservice.getMangaReviews(id, page).execute(); return net.somethingdreadful.MAL.api.MALModels.AnimeManga.Reviews.convertBaseArray(response.body()); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getMangaReviews", e); @@ -480,7 +482,7 @@ public ArrayList getMangaReviews(int id, int page) { public ArrayList getActivity(String username) { Response> response = null; try { - response = service.getActivity(username).execute(); + response = APIservice.getActivity(username).execute(); return History.convertBaseHistoryList(response.body(), username); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getActivity", e); @@ -491,7 +493,7 @@ public ArrayList getActivity(S public ArrayList getAnimeRecs(int id) { Response> response = null; try { - response = service.getAnimeRecs(id).execute(); + response = APIservice.getAnimeRecs(id).execute(); return response.body(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getAnimeRecs", e); @@ -502,7 +504,7 @@ public ArrayList getAnimeRecs(int id) { public ArrayList getMangaRecs(int id) { Response> response = null; try { - response = service.getMangaRecs(id).execute(); + response = APIservice.getMangaRecs(id).execute(); return response.body(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getMangaRecs", e); @@ -513,7 +515,7 @@ public ArrayList getMangaRecs(int id) { public Schedule getSchedule() { Response response = null; try { - response = service.getSchedule().execute(); + response = APIservice.getSchedule().execute(); return response.body().convertBaseSchedule(); } catch (Exception e) { APIHelper.logE(activity, response, "MALApi", "getSchedule", e); diff --git a/Atarashii/src/main/java/net/somethingdreadful/MAL/tasks/ForumNetworkTask.java b/Atarashii/src/main/java/net/somethingdreadful/MAL/tasks/ForumNetworkTask.java index 8fab4655..b66ef5e5 100644 --- a/Atarashii/src/main/java/net/somethingdreadful/MAL/tasks/ForumNetworkTask.java +++ b/Atarashii/src/main/java/net/somethingdreadful/MAL/tasks/ForumNetworkTask.java @@ -5,7 +5,6 @@ import net.somethingdreadful.MAL.AppLog; import net.somethingdreadful.MAL.ContentManager; -import net.somethingdreadful.MAL.account.AccountService; import net.somethingdreadful.MAL.api.APIHelper; import net.somethingdreadful.MAL.api.BaseModels.Forum; @@ -28,8 +27,9 @@ public ForumNetworkTask(ForumNetworkTaskListener callback, Activity activity, Fo protected ArrayList doInBackground(String... params) { ArrayList result = new ArrayList<>(); ContentManager cManager = new ContentManager(activity); - if (!AccountService.isMAL() && APIHelper.isNetworkAvailable(activity)) - cManager.verifyAuthentication(); + boolean error = false; + if (APIHelper.isNetworkAvailable(activity)) + error = cManager.verifyAuthentication(); try { switch (type) { @@ -49,12 +49,16 @@ protected ArrayList doInBackground(String... params) { result = cManager.search(params[0]); break; case ADDCOMMENT: - result = cManager.addComment(id, params[0]) ? new ArrayList() : null; - if (result != null) - result = cManager.getTopic(id, Integer.parseInt(params[1])); + if (!error) { + result = cManager.addComment(id, params[0]) ? new ArrayList() : null; + if (result != null) + result = cManager.getTopic(id, Integer.parseInt(params[1])); + } break; case UPDATECOMMENT: - result = cManager.updateComment(id, params[0]) ? new ArrayList() : null; + if (!error) { + result = cManager.updateComment(id, params[0]) ? new ArrayList() : null; + } break; } } catch (Exception e) { diff --git a/Atarashii/src/main/java/net/somethingdreadful/MAL/tasks/WriteDetailTask.java b/Atarashii/src/main/java/net/somethingdreadful/MAL/tasks/WriteDetailTask.java index db9ce10f..578be330 100644 --- a/Atarashii/src/main/java/net/somethingdreadful/MAL/tasks/WriteDetailTask.java +++ b/Atarashii/src/main/java/net/somethingdreadful/MAL/tasks/WriteDetailTask.java @@ -8,7 +8,6 @@ import net.somethingdreadful.MAL.AppLog; import net.somethingdreadful.MAL.ContentManager; -import net.somethingdreadful.MAL.account.AccountService; import net.somethingdreadful.MAL.api.APIHelper; import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Anime; import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord; @@ -31,8 +30,9 @@ protected Boolean doInBackground(GenericRecord... gr) { boolean isNetworkAvailable = APIHelper.isNetworkAvailable(activity); ContentManager manager = new ContentManager(activity); - if (!AccountService.isMAL() && isNetworkAvailable) + if (isNetworkAvailable) error = manager.verifyAuthentication(); + AppLog.log(Log.INFO, "Atarashii", "WriteDetailTask.doInBackground(4, " + type + "): error: " + error); try { // Sync details if there is network connection