diff --git a/Atarashii/AndroidManifest.xml b/Atarashii/AndroidManifest.xml index 0741d729..eeb84d6f 100644 --- a/Atarashii/AndroidManifest.xml +++ b/Atarashii/AndroidManifest.xml @@ -1,7 +1,5 @@ + package="net.somethingdreadful.MAL"> diff --git a/Atarashii/res/layout-w720dp/activity_detailview_general.xml b/Atarashii/res/layout-w720dp/activity_detailview_general.xml index 25ed6ea8..8bf4302f 100644 --- a/Atarashii/res/layout-w720dp/activity_detailview_general.xml +++ b/Atarashii/res/layout-w720dp/activity_detailview_general.xml @@ -9,7 +9,6 @@ android:id="@+id/scrollView"> @@ -44,7 +43,6 @@ diff --git a/Atarashii/res/layout-w720dp/fragment_profile_mal.xml b/Atarashii/res/layout-w720dp/fragment_profile_mal.xml index f6ca28fe..bdb9cca0 100644 --- a/Atarashii/res/layout-w720dp/fragment_profile_mal.xml +++ b/Atarashii/res/layout-w720dp/fragment_profile_mal.xml @@ -13,7 +13,6 @@ android:layout_height="fill_parent"> diff --git a/Atarashii/res/layout/activity_about.xml b/Atarashii/res/layout/activity_about.xml index 84242095..343f5b1c 100644 --- a/Atarashii/res/layout/activity_about.xml +++ b/Atarashii/res/layout/activity_about.xml @@ -10,7 +10,6 @@ android:layout_height="fill_parent"> diff --git a/Atarashii/res/layout/activity_firstrun.xml b/Atarashii/res/layout/activity_firstrun.xml index cfc8c01a..460b99c6 100644 --- a/Atarashii/res/layout/activity_firstrun.xml +++ b/Atarashii/res/layout/activity_firstrun.xml @@ -88,7 +88,6 @@ android:textSize="16sp" /> diff --git a/Atarashii/res/layout/activity_forum.xml b/Atarashii/res/layout/activity_forum.xml index d9a11fcf..03b0e2ad 100644 --- a/Atarashii/res/layout/activity_forum.xml +++ b/Atarashii/res/layout/activity_forum.xml @@ -3,30 +3,19 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="match_parent"/> - - - - - - + \ No newline at end of file diff --git a/Atarashii/res/layout/activity_forum_main.xml b/Atarashii/res/layout/activity_forum_main.xml deleted file mode 100644 index 84323b60..00000000 --- a/Atarashii/res/layout/activity_forum_main.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Atarashii/res/layout/activity_forum_topics.xml b/Atarashii/res/layout/activity_forum_topics.xml deleted file mode 100644 index eeb7b5c3..00000000 --- a/Atarashii/res/layout/activity_forum_topics.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/Atarashii/res/layout/activity_home.xml b/Atarashii/res/layout/activity_home.xml index 4aadff46..bf680ce1 100644 --- a/Atarashii/res/layout/activity_home.xml +++ b/Atarashii/res/layout/activity_home.xml @@ -1,8 +1,21 @@ + android:layout_height="match_parent" + android:fitsSystemWindows="true" + tools:context=".Home"> + + diff --git a/Atarashii/res/layout/card_about_translations.xml b/Atarashii/res/layout/card_about_translations.xml index 5f81b167..a81beac1 100644 --- a/Atarashii/res/layout/card_about_translations.xml +++ b/Atarashii/res/layout/card_about_translations.xml @@ -35,7 +35,6 @@ android:textStyle="bold" /> diff --git a/Atarashii/res/layout/card_detailview_personal_basic.xml b/Atarashii/res/layout/card_detailview_personal_basic.xml index 7a21225a..feee29fc 100644 --- a/Atarashii/res/layout/card_detailview_personal_basic.xml +++ b/Atarashii/res/layout/card_detailview_personal_basic.xml @@ -18,13 +18,11 @@ android:background="@drawable/highlite_details"> diff --git a/Atarashii/res/layout/fragment_profile_al.xml b/Atarashii/res/layout/fragment_profile_al.xml index 39a53dab..b97021e0 100644 --- a/Atarashii/res/layout/fragment_profile_al.xml +++ b/Atarashii/res/layout/fragment_profile_al.xml @@ -13,7 +13,6 @@ android:layout_height="fill_parent"> diff --git a/Atarashii/res/layout/fragment_profile_mal.xml b/Atarashii/res/layout/fragment_profile_mal.xml index 104dd38a..3cd90300 100644 --- a/Atarashii/res/layout/fragment_profile_mal.xml +++ b/Atarashii/res/layout/fragment_profile_mal.xml @@ -13,7 +13,6 @@ android:layout_height="fill_parent"> diff --git a/Atarashii/res/layout/navdrawer_header.xml b/Atarashii/res/layout/navdrawer_header.xml new file mode 100644 index 00000000..1f422a1a --- /dev/null +++ b/Atarashii/res/layout/navdrawer_header.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + diff --git a/Atarashii/res/layout/record_forum_listview.xml b/Atarashii/res/layout/record_forum_listview.xml deleted file mode 100644 index 08c00a27..00000000 --- a/Atarashii/res/layout/record_forum_listview.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Atarashii/res/layout/record_friends_gridview.xml b/Atarashii/res/layout/record_friends_gridview.xml index b29a5ae4..30eb81a1 100644 --- a/Atarashii/res/layout/record_friends_gridview.xml +++ b/Atarashii/res/layout/record_friends_gridview.xml @@ -20,8 +20,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" - android:layout_marginLeft="72dp" - android:id="@+id/relativeLayout"> + android:layout_marginLeft="72dp"> - - - - - - diff --git a/Atarashii/res/layout/record_home_navigationdrawer.xml b/Atarashii/res/layout/record_home_navigationdrawer.xml deleted file mode 100644 index 56843d84..00000000 --- a/Atarashii/res/layout/record_home_navigationdrawer.xml +++ /dev/null @@ -1,205 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Atarashii/res/menu/activity_forum.xml b/Atarashii/res/menu/activity_forum.xml index ee2963cf..231f27a0 100644 --- a/Atarashii/res/menu/activity_forum.xml +++ b/Atarashii/res/menu/activity_forum.xml @@ -12,16 +12,4 @@ android:icon="@drawable/ic_language" android:title="@string/action_viewMALPage" res-auto:showAsAction="ifRoom" /> - - - - diff --git a/Atarashii/res/menu/navdrawer.xml b/Atarashii/res/menu/navdrawer.xml new file mode 100644 index 00000000..ad6684b9 --- /dev/null +++ b/Atarashii/res/menu/navdrawer.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Atarashii/res/raw/forum_comment.html b/Atarashii/res/raw/forum_comment.html new file mode 100644 index 00000000..74db894a --- /dev/null +++ b/Atarashii/res/raw/forum_comment.html @@ -0,0 +1,263 @@ + + + + <!-- title --> + + + + + + +
+
+
+ + + + + + + + + + + + + + +
+ +
+
+ +Previous +Next +1 + \ No newline at end of file diff --git a/Atarashii/res/raw/forum_post_spoiler_structure.html b/Atarashii/res/raw/forum_comment_spoiler_structure.html similarity index 100% rename from Atarashii/res/raw/forum_post_spoiler_structure.html rename to Atarashii/res/raw/forum_comment_spoiler_structure.html diff --git a/Atarashii/res/raw/forum_comment_tiles.html b/Atarashii/res/raw/forum_comment_tiles.html new file mode 100644 index 00000000..94625eaf --- /dev/null +++ b/Atarashii/res/raw/forum_comment_tiles.html @@ -0,0 +1,16 @@ +
+ +
+
+
+
+ + + + + + +
+ +
+
\ No newline at end of file diff --git a/Atarashii/res/raw/forum_list.html b/Atarashii/res/raw/forum_list.html new file mode 100644 index 00000000..90e6b6c5 --- /dev/null +++ b/Atarashii/res/raw/forum_list.html @@ -0,0 +1,90 @@ + + + + <!-- title --> + + + + + + + + + + \ No newline at end of file diff --git a/Atarashii/res/raw/forum_list_tiles.html b/Atarashii/res/raw/forum_list_tiles.html new file mode 100644 index 00000000..bc02af35 --- /dev/null +++ b/Atarashii/res/raw/forum_list_tiles.html @@ -0,0 +1,6 @@ + +
+ + | +
+
\ No newline at end of file diff --git a/Atarashii/res/raw/forum_menu.html b/Atarashii/res/raw/forum_menu.html new file mode 100644 index 00000000..75cc8af3 --- /dev/null +++ b/Atarashii/res/raw/forum_menu.html @@ -0,0 +1,44 @@ + + + + <!-- title --> + + + + + + + \ No newline at end of file diff --git a/Atarashii/res/raw/forum_menu_tiles.html b/Atarashii/res/raw/forum_menu_tiles.html new file mode 100644 index 00000000..5d9e5a71 --- /dev/null +++ b/Atarashii/res/raw/forum_menu_tiles.html @@ -0,0 +1,6 @@ + +
+ + +
+
\ No newline at end of file diff --git a/Atarashii/res/values/strings.xml b/Atarashii/res/values/strings.xml index 94a7b113..8d5edc17 100644 --- a/Atarashii/res/values/strings.xml +++ b/Atarashii/res/values/strings.xml @@ -31,6 +31,7 @@ Check your credentials and try again. Sync error while getting friendlist! No anime or manga results found. + The comment could not be converted! Syncing everything. This could take a few seconds. Username and password combination doesn\'t match! Copied the title successfully to the clipboard! @@ -44,6 +45,7 @@ The backup has been removed! The backup is not compatible with this site! A widget with the chosen record already exists! + The comment is short! Username mismatch @@ -84,6 +86,8 @@ Last post by Do you want to view the $child1; or $child2; category? It is possible that the chosen backup is not your backup! + Are you sure that your comment should be updated? + Do you really want to add a new comment? Cancel Update Anime @@ -150,6 +154,9 @@ Add a comment or topic Topic title Message + Page number + Next + Previous Welcome to Atarashii!\nPlease choose your preferred site. diff --git a/Atarashii/src/Beta/AndroidManifest.xml b/Atarashii/src/Beta/AndroidManifest.xml index e77e8da4..e7cb6b49 100644 --- a/Atarashii/src/Beta/AndroidManifest.xml +++ b/Atarashii/src/Beta/AndroidManifest.xml @@ -1,9 +1,6 @@ + package="net.somethingdreadful.MAL"> files = new ArrayList<>(); - int position = 0; + private BackupGridviewAdapter backupGridviewAdapter; + private final ArrayList files = new ArrayList<>(); + private int position = 0; @Bind(R.id.progressBar) ProgressBar progressBar; @Bind(R.id.swiperefresh) - public SwipeRefreshLayout swipeRefresh; + SwipeRefreshLayout swipeRefresh; @Override protected void onCreate(Bundle savedInstanceState) { @@ -54,7 +54,7 @@ protected void onCreate(Bundle savedInstanceState) { Gridview.setVisibility(View.VISIBLE); Gridview.setOnItemClickListener(this); swipeRefresh.setOnRefreshListener(this); - swipeRefresh.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); + swipeRefresh.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeRefresh.setEnabled(true); toggle(1); getListFiles(); @@ -115,7 +115,7 @@ private void getListFiles() { /** * Refresh the backup list */ - public void refresh() { + private void refresh() { Gridview.setAdapter(backupGridviewAdapter); try { backupGridviewAdapter.supportAddAll(files); diff --git a/Atarashii/src/net/somethingdreadful/MAL/Card.java b/Atarashii/src/net/somethingdreadful/MAL/Card.java index b1557cc2..256197b8 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/Card.java +++ b/Atarashii/src/net/somethingdreadful/MAL/Card.java @@ -22,17 +22,16 @@ public class Card extends RelativeLayout { - public boolean center; - public TextView Header; - public ImageView Image; - public CardView Card; - public RelativeLayout Content; + private final boolean center; + public final TextView Header; + private ImageView Image; + private final CardView Card; + private final RelativeLayout Content; - onCardClickListener listener; + private onCardClickListener listener; private int screenWidth; - private int minHeight; - private Float density; - private LayoutInflater inflater; + private final int minHeight; + private final LayoutInflater inflater; public Card(Context context) { this(context, null); @@ -213,7 +212,7 @@ public void setBelowof(Card res, int amount, int screen) { * * @param color The resource id of the color */ - public void setHeaderColor(int color) { + private void setHeaderColor(int color) { GradientDrawable shape = (GradientDrawable) Header.getBackground(); shape.setColor(getResources().getColor(color)); } @@ -275,7 +274,7 @@ public void setWidth(Integer amount, Integer maxWidth) { * @param maxWidth The maximum width in dp * @return int The width that the card should be */ - public int getWidth(Integer amount, Integer maxWidth) { + private int getWidth(Integer amount, Integer maxWidth) { if (amount == 0) amount = 1; int divider = amount - 1; @@ -319,6 +318,6 @@ public void addView(View child, int index, ViewGroup.LayoutParams params) { * The Interface that will get triggered by the OnClick method. */ public interface onCardClickListener { - public void onCardClickListener(int id); + void onCardClickListener(int id); } } \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/DateTools.java b/Atarashii/src/net/somethingdreadful/MAL/DateTools.java index 787c2297..b67ccf17 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/DateTools.java +++ b/Atarashii/src/net/somethingdreadful/MAL/DateTools.java @@ -35,19 +35,12 @@ public static String parseDate(String ISO8601, boolean withTime) { * Parse a date with miliseconds. * * @param time The time in miliseconds - * @param withTime Use true when you want also the time (hours & minutes) * @return String The readable string. */ - public static String parseDate(Long time, boolean withTime) { + public static String parseDate(Long time) { Calendar calander = Calendar.getInstance(); calander.setTimeInMillis(time); - return getDateString(calander.getTime(), withTime); - } - - public static Long getmilis(String time) { - Calendar calander = Calendar.getInstance(); - calander.setTime(parseISO8601(time)); - return calander.getTimeInMillis(); + return getDateString(calander.getTime(), true); } private static Date parseISO8601(String ISO8601) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/DetailView.java b/Atarashii/src/net/somethingdreadful/MAL/DetailView.java index 29606b2e..47dc9268 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/DetailView.java +++ b/Atarashii/src/net/somethingdreadful/MAL/DetailView.java @@ -54,13 +54,13 @@ public class DetailView extends AppCompatActivity implements Serializable, Netwo public ListType type; public Anime animeRecord; public Manga mangaRecord; - public String username; - public DetailViewGeneral general; - public DetailViewDetails details; - public DetailViewPersonal personal; + private String username; + private DetailViewGeneral general; + private DetailViewDetails details; + private DetailViewPersonal personal; public DetailViewReviews reviews; - public DetailViewPagerAdapter PageAdapter; - int recordID; + private DetailViewPagerAdapter PageAdapter; + private int recordID; private ActionBar actionBar; private ViewFlipper viewFlipper; private Menu menu; @@ -89,7 +89,7 @@ public void onCreate(Bundle savedInstanceState) { /* * Set text in all fragments */ - public void setText() { + private void setText() { try { actionBar.setTitle(type == ListType.ANIME ? animeRecord.getTitle() : mangaRecord.getTitle()); if (general != null) @@ -113,7 +113,7 @@ public String nullCheck(String string) { return isEmpty(string) ? getString(R.string.unknown) : string; } - public boolean isEmpty(String string) { + private boolean isEmpty(String string) { return ((string == null || string.equals("") || string.equals("0-00-00"))); } @@ -149,7 +149,7 @@ public boolean isAdded() { /* * Set refreshing on all SwipeRefreshViews */ - public void setRefreshing(Boolean show) { + private void setRefreshing(Boolean show) { if (general != null) { general.swipeRefresh.setRefreshing(show); general.swipeRefresh.setEnabled(!show); @@ -302,17 +302,17 @@ public void setMenu() { /* * Add record to list */ - public void addToList() { + private void addToList() { if (!isEmpty()) { if (type.equals(ListType.ANIME)) { - animeRecord.setCreateFlag(true); + animeRecord.setCreateFlag(); // If the anime hasn't aired mark is planned if (animeRecord.getStatusInt() != 2) animeRecord.setWatchedStatus(PrefManager.getAddList()); else animeRecord.setWatchedStatus(GenericRecord.STATUS_PLANTOWATCH); } else { - mangaRecord.setCreateFlag(true); + mangaRecord.setCreateFlag(); mangaRecord.setReadStatus(PrefManager.getAddList()); } PageAdapter.hidePersonal(false); @@ -323,7 +323,7 @@ public void addToList() { /* * Open the share dialog */ - public void Share() { + private void Share() { Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); @@ -334,7 +334,7 @@ public void Share() { /* * Make the share text for the share dialog */ - public String makeShareText() { + private String makeShareText() { String shareText = PrefManager.getCustomShareText(); shareText = shareText.replace("$title;", actionBar.getTitle()); if (AccountService.isMAL()) @@ -379,17 +379,17 @@ public boolean isDone() { /* * Get the translation from strings.xml */ - private String getStringFromResourceArray(int resArrayId, int notFoundStringId, int index) { + private String getStringFromResourceArray(int resArrayId, int index) { Resources res = getResources(); try { String[] types = res.getStringArray(resArrayId); if (index < 0 || index >= types.length) // make sure to have a valid array index - return res.getString(notFoundStringId); + return res.getString(R.string.unknown); else return types[index]; } catch (Resources.NotFoundException e) { Crashlytics.logException(e); - return res.getString(notFoundStringId); + return res.getString(R.string.unknown); } } @@ -398,9 +398,9 @@ private String getStringFromResourceArray(int resArrayId, int notFoundStringId, */ public String getTypeString(int typesInt) { if (type.equals(ListType.ANIME)) - return getStringFromResourceArray(R.array.mediaType_Anime, R.string.unknown, typesInt); + return getStringFromResourceArray(R.array.mediaType_Anime, typesInt); else - return getStringFromResourceArray(R.array.mediaType_Manga, R.string.unknown, typesInt); + return getStringFromResourceArray(R.array.mediaType_Manga, typesInt); } /* @@ -408,9 +408,9 @@ public String getTypeString(int typesInt) { */ public String getStatusString(int statusInt) { if (type.equals(ListType.ANIME)) - return getStringFromResourceArray(R.array.mediaStatus_Anime, R.string.unknown, statusInt); + return getStringFromResourceArray(R.array.mediaStatus_Anime, statusInt); else - return getStringFromResourceArray(R.array.mediaStatus_Manga, R.string.unknown, statusInt); + return getStringFromResourceArray(R.array.mediaStatus_Manga, statusInt); } /* @@ -419,7 +419,7 @@ public String getStatusString(int statusInt) { public ArrayList getGenresString(ArrayList genresInt) { ArrayList genres = new ArrayList<>(); for (Integer genreInt : genresInt) { - genres.add(getStringFromResourceArray(R.array.genresArray, R.string.unknown, genreInt)); + genres.add(getStringFromResourceArray(R.array.genresArray, genreInt)); } return genres; } @@ -428,11 +428,11 @@ public ArrayList getGenresString(ArrayList genresInt) { * Get the anime or manga classification translations */ public String getClassificationString(Integer classificationInt) { - return getStringFromResourceArray(R.array.classificationArray, R.string.unknown, classificationInt); + return getStringFromResourceArray(R.array.classificationArray, classificationInt); } public String getUserStatusString(int statusInt) { - return getStringFromResourceArray(R.array.mediaStatus_User, R.string.unknown, statusInt); + return getStringFromResourceArray(R.array.mediaStatus_User, statusInt); } /* @@ -441,7 +441,7 @@ public String getUserStatusString(int statusInt) { * Try to fetch them from the Database first to get reading/watching details. * If the record doesn't contains a synopsis this method will get it. */ - public void getRecord(boolean forceUpdate) { + private void getRecord(boolean forceUpdate) { setRefreshing(true); toggleLoadingIndicator(isEmpty()); actionBar.setTitle(R.string.layout_card_loading); @@ -496,9 +496,9 @@ public void onMangaDialogDismissed(int value, int value2) { public void onRemoveConfirmed() { if (type.equals(ListType.ANIME)) - animeRecord.setDeleteFlag(true); + animeRecord.setDeleteFlag(); else - mangaRecord.setDeleteFlag(true); + mangaRecord.setDeleteFlag(); finish(); } diff --git a/Atarashii/src/net/somethingdreadful/MAL/FirstTimeInit.java b/Atarashii/src/net/somethingdreadful/MAL/FirstTimeInit.java index 5ee84db9..066e6f50 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/FirstTimeInit.java +++ b/Atarashii/src/net/somethingdreadful/MAL/FirstTimeInit.java @@ -1,5 +1,6 @@ package net.somethingdreadful.MAL; +import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; @@ -32,10 +33,10 @@ import butterknife.ButterKnife; public class FirstTimeInit extends AppCompatActivity implements AuthenticationCheckTask.AuthenticationCheckListener, OnClickListener { - String MalUser; - String MalPass; - Context context; - ProgressDialog dialog; + private String MalUser; + private String MalPass; + private Context context; + private ProgressDialog dialog; @Bind(R.id.edittext_malUser) EditText malUser; @@ -54,6 +55,7 @@ public class FirstTimeInit extends AppCompatActivity implements AuthenticationCh @Bind(R.id.anilist) TextView anilist; + @SuppressLint("SetJavaScriptEnabled") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/Atarashii/src/net/somethingdreadful/MAL/ForumActivity.java b/Atarashii/src/net/somethingdreadful/MAL/ForumActivity.java index 9ee2630c..efb38b08 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/ForumActivity.java +++ b/Atarashii/src/net/somethingdreadful/MAL/ForumActivity.java @@ -1,6 +1,6 @@ package net.somethingdreadful.MAL; -import android.app.FragmentManager; +import android.annotation.SuppressLint; import android.app.SearchManager; import android.content.ComponentName; import android.content.Context; @@ -13,235 +13,103 @@ import android.support.v7.widget.SearchView; import android.view.Menu; import android.view.MenuItem; -import android.widget.ViewFlipper; - -import net.somethingdreadful.MAL.api.MALApi; -import net.somethingdreadful.MAL.api.MALModels.ForumMain; -import net.somethingdreadful.MAL.dialog.ForumChildDialogFragment; -import net.somethingdreadful.MAL.dialog.MessageDialogFragment; -import net.somethingdreadful.MAL.forum.ForumsMain; -import net.somethingdreadful.MAL.forum.ForumsPosts; -import net.somethingdreadful.MAL.forum.ForumsTopics; +import android.view.View; +import android.webkit.CookieManager; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.ProgressBar; + +import com.crashlytics.android.Crashlytics; + +import net.somethingdreadful.MAL.account.AccountService; +import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Forum; +import net.somethingdreadful.MAL.dialog.NumberPickerDialogFragment; +import net.somethingdreadful.MAL.forum.ForumInterface; import net.somethingdreadful.MAL.tasks.ForumJob; import net.somethingdreadful.MAL.tasks.ForumNetworkTask; +import java.io.InputStream; +import java.util.ArrayList; + import butterknife.Bind; import butterknife.ButterKnife; - -public class ForumActivity extends AppCompatActivity implements MessageDialogFragment.onSendClickListener, ForumNetworkTask.ForumNetworkTaskListener { - Menu menu; - MenuItem search; - public ForumsMain main; - FragmentManager manager; - public ForumsPosts posts; - public String message = ""; - public ForumsTopics topics; - public boolean closeOnBack = false; - - @Bind(R.id.viewFlipper) ViewFlipper viewFlipper; - - public boolean discussion = false; - public ForumJob task = ForumJob.BOARD; - +import lombok.Getter; +import lombok.Setter; + +public class ForumActivity extends AppCompatActivity implements ForumNetworkTask.ForumNetworkTaskListener, NumberPickerDialogFragment.onUpdateClickListener { + @Bind(R.id.webview) + public + WebView webview; + @Bind(R.id.progress1) + ProgressBar progress; + private testforumhtmlunit test; + private MenuItem search; + private String query; + private boolean loading = false; + + @SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"}) @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); Theme.setTheme(this, R.layout.activity_forum, false); Theme.setActionBar(this); ButterKnife.bind(this); - - handleIntent(getIntent()); - - manager = getFragmentManager(); - main = (ForumsMain) manager.findFragmentById(R.id.main); - topics = (ForumsTopics) manager.findFragmentById(R.id.topics); - posts = (ForumsPosts) manager.findFragmentById(R.id.posts); - - if (getIntent() != null) { - int id = getIntent().getIntExtra("id", 0); - if (id != 0) { - topics.type = (MALApi.ListType) getIntent().getSerializableExtra("listType"); - getDiscussion(id); - closeOnBack = true; + webview.getSettings().setJavaScriptEnabled(true); + webview.addJavascriptInterface(new ForumInterface(this), "Forum"); + webview.setWebViewClient(new WebViewClient() { + public void onPageFinished(WebView view, String url) { + setLoading(false); } - } + }); + test = new testforumhtmlunit(this); if (bundle != null) { - viewFlipper.setDisplayedChild(bundle.getInt("child")); - task = (ForumJob) bundle.getSerializable("task"); - discussion = bundle.getBoolean("discussion"); + test.setForumMenuLayout(bundle.getString("forumMenuLayout")); + webview.restoreState(bundle.getBundle("webview")); + } else { + getRecords(ForumJob.MENU, 0, "1"); } } - @Override - public void onSaveInstanceState(Bundle state) { - state.putInt("child", viewFlipper.getDisplayedChild()); - state.putSerializable("task", task); - state.putBoolean("discussion", discussion); - super.onSaveInstanceState(state); - } - - /** - * Switch the view to the topics fragment. - * - * @param id The board id - */ - public void getTopics(int id) { - viewFlipper.setDisplayedChild(1); - setTask(topics.setId(id, ForumJob.TOPICS)); - } - - /** - * Switch the view to the topics fragment. - * - * @param query The query - */ - public void getTopics(String query) { - viewFlipper.setDisplayedChild(1); - setTask(topics.setId(query)); - } - - /** - * Switch the view to the topics fragment to show subBoards. - * - * @param id The subBoard id - */ - public void getSubBoard(int id) { - viewFlipper.setDisplayedChild(1); - topics.type = ((id == 1 || id == 2) ? MALApi.ListType.ANIME : MALApi.ListType.MANGA); - setTask(topics.setId(id, ForumJob.SUBBOARD)); - } - - /** - * Switch the view to the topics posts. - * - * @param id The id of the topic - */ - public void getPosts(int id) { - viewFlipper.setDisplayedChild(2); - setTask(posts.setId(id)); - } - - /** - * Create the edithor dialog. - * - * @param id The comment id - * @param message The comment text - * @param task The task to peform - */ - public void getComments(int id, String message, ForumJob task) { - MessageDialogFragment info = new MessageDialogFragment().setListeners(this); - Bundle args = new Bundle(); - args.putInt("id", id); - args.putString("message", message); - args.putSerializable("task", task); - info.setArguments(args); - info.show(getFragmentManager(), "fragment_forum"); - } - - /** - * Switch the view to the discussion view. - * - * @param id The comment id - */ - public void getDiscussion(int id) { - viewFlipper.setDisplayedChild(1); - setTask(topics.setId(id, ForumJob.DISCUSSION)); - discussion = true; - } - - /** - * Handle the back and home buttons. - */ - public void back() { - switch (task) { - case BOARD: - finish(); - break; - case SUBBOARD: - setTask(ForumJob.BOARD); - viewFlipper.setDisplayedChild(0); - break; - case DISCUSSION: - if (closeOnBack) - finish(); - setTask(ForumJob.SUBBOARD); - topics.task = ForumJob.SUBBOARD; - topics.topicsAdapter.clear(); - topics.apply(topics.subBoard); - discussion = false; - break; - case TOPICS: - case SEARCH: - setTask(ForumJob.BOARD); - viewFlipper.setDisplayedChild(0); - break; - case POSTS: - if (discussion) { - setTask(ForumJob.DISCUSSION); - } else - setTask(ForumJob.TOPICS); - viewFlipper.setDisplayedChild(1); - break; - } - message = ""; - } - - /** - * Refresh the displayed view. - */ - public void refresh() { - if (task == ForumJob.TOPICS) - topics.getRecords(topics.page, topics.task); - else - posts.getRecords(posts.page); - } - - /** - * Change the task & change the menu items. - * - * @param task The new ForumTask - */ - public void setTask(ForumJob task) { - this.task = task; - if (menu != null) { - menu.findItem(R.id.action_add).setVisible((task == ForumJob.POSTS || task == ForumJob.TOPICS) && getTopicStatus() && viewFlipper.getDisplayedChild() != 3); - menu.findItem(R.id.action_send).setVisible(viewFlipper.getDisplayedChild() == 3); - menu.findItem(R.id.action_ViewMALPage).setVisible(viewFlipper.getDisplayedChild() != 3); - search.setVisible(task == ForumJob.BOARD); - } - } - - /** - * Checks if the ID allows to add a topics - * - * @return boolean If true then the ID allows to add comments - */ - public boolean getTopicStatus() { - return task != ForumJob.TOPICS || (topics.id != 5 && topics.id != 14 && topics.id != 15 && topics.id != 17); - } - - @Override - public void onBackPressed() { - back(); - } - @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_forum, menu); - this.menu = menu; - SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); ComponentName cn = new ComponentName(this, ForumActivity.class); searchView.setSearchableInfo(searchManager.getSearchableInfo(cn)); search = searchItem; - - setTask(task); return true; } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + break; + case R.id.action_ViewMALPage: + String[] details = webview.getTitle().split(" "); + switch (details[0]) { + case "M": // main board + startActivity((new Intent(Intent.ACTION_VIEW)).setData(Uri.parse("http://myanimelist.net/forum/"))); + break; + case "S": // sub board + startActivity((new Intent(Intent.ACTION_VIEW)).setData(Uri.parse("http://myanimelist.net/forum/?subboard=" + details[1]))); + break; + case "T": // topic list + startActivity((new Intent(Intent.ACTION_VIEW)).setData(Uri.parse("http://myanimelist.net/forum/?board=" + details[1]))); + break; + case "C": // commments + startActivity((new Intent(Intent.ACTION_VIEW)).setData(Uri.parse("http://myanimelist.net/forum/?topicid=" + details[1]))); + break; + } + break; + } + return super.onOptionsItemSelected(item); + } + @Override protected void onNewIntent(Intent intent) { handleIntent(intent); @@ -254,75 +122,295 @@ protected void onNewIntent(Intent intent) { */ private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { - String query = intent.getStringExtra(SearchManager.QUERY); - getTopics(query); - topics.task = ForumJob.SEARCH; + query = intent.getStringExtra(SearchManager.QUERY); + if (query.equals("Atarashii:clear")) { + webview.clearCache(true); + CookieManager.getInstance().removeAllCookie(); + finish(); + } else { + getRecords(ForumJob.SEARCH, 0, "1"); + } search.collapseActionView(); } } + public void setLoading(boolean loading) { + progress.setVisibility(loading ? View.VISIBLE : View.GONE); + } + @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - back(); - break; - case R.id.action_ViewMALPage: - startActivity(new Intent(Intent.ACTION_VIEW, getUri())); - break; - case R.id.action_add: - if (task == ForumJob.POSTS) - getComments(posts.id, message, ForumJob.ADDCOMMENT); - else if (task == ForumJob.TOPICS) - getComments(topics.id, null, ForumJob.ADDTOPIC); - break; - } - return super.onOptionsItemSelected(item); + public void onSaveInstanceState(Bundle state) { + state.putString("forumMenuLayout", test.getForumMenuLayout()); + Bundle webviewState = new Bundle(); + webview.saveState(webviewState); + state.putBundle("webview", webviewState); + super.onSaveInstanceState(state); } - /** - * Get the Uri depending on the ForumTask. - * - * @return Uri The uri of the desired URL to launch - */ - public Uri getUri() { - switch (task) { - case BOARD: - return Uri.parse("http://myanimelist.net/forum/"); - case SUBBOARD: - return Uri.parse("http://myanimelist.net/forum/?subboard=" + topics.id); - case DISCUSSION: - if (ForumChildDialogFragment.DBModificationRequest) - return Uri.parse("http://myanimelist.net/forum/?topicid=" + topics.id); - else - return Uri.parse("http://myanimelist.net/forum/?" + (topics.type == MALApi.ListType.ANIME ? "anime" : "manga") + "id=" + topics.id); - case TOPICS: - return Uri.parse("http://myanimelist.net/forum/?board=" + topics.id); - case POSTS: - return Uri.parse("http://myanimelist.net/forum/?topicid=" + posts.id); + public void getRecords(ForumJob job, int id, String page) { + if (!loading) { + loading = true; + test.setSubBoard(false); + setLoading(true); + test.setId(id); + test.setPage(page); + switch (job) { + case MENU: + if (!test.menuExists()) + new ForumNetworkTask(this, this, job, id).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else + test.setForumMenu(null); + break; + case SUBCATEGORY: + test.setSubBoard(true); + case CATEGORY: + case TOPIC: + new ForumNetworkTask(this, this, job, id).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, page); + break; + case SEARCH: + new ForumNetworkTask(this, this, job, id).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, query); + break; + } } - return null; } @Override - public void onSendClicked(String message, String subject, ForumJob task, int id) { - if (task == ForumJob.ADDTOPIC && !message.equals("") && !subject.equals("")) - new ForumNetworkTask(this, this, this, task, id).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, subject, message); - else if (!message.equals("")) - new ForumNetworkTask(this, this, this, task, id).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, message); + public void onBackPressed() { + if (webview.canGoBack()) + webview.goBack(); + else + finish(); } @Override - public void onForumNetworkTaskFinished(ForumMain result, ForumJob task) { - if (task == ForumJob.ADDCOMMENT) - Theme.Snackbar(this, R.string.toast_info_comment_add); - if (task == ForumJob.ADDTOPIC || task == ForumJob.ADDCOMMENT || task == ForumJob.UPDATECOMMENT) - Theme.Snackbar(this, R.string.toast_info_comment_added); - refresh(); + public void onForumNetworkTaskFinished(ArrayList forum, ForumJob job) { + switch (job) { + case MENU: + test.setForumMenu(forum); + break; + case SEARCH: + case CATEGORY: + case SUBCATEGORY: + test.setForumList(forum); + break; + case TOPIC: + test.setForumComments(forum); + break; + case UPDATECOMMENT: + Theme.Snackbar(this, forum != null ? R.string.toast_info_comment_added : R.string.toast_error_Records); + setLoading(false); + break; + case ADDCOMMENT: + Theme.Snackbar(this, forum != null ? R.string.toast_info_comment_added : R.string.toast_error_Records); + if (forum != null) + test.setForumComments(forum); + break; + } + loading = false; } @Override - public void onCloseClicked(String message) { - this.message = message; + public void onUpdated(int number, int id) { + String[] details = webview.getTitle().split(" "); + switch (details[0]) { + case "S": // sub board + getRecords(ForumJob.SUBCATEGORY, Integer.parseInt(String.valueOf(id)), String.valueOf(number)); + break; + case "T": // topic list + getRecords(ForumJob.CATEGORY, Integer.parseInt(String.valueOf(id)), String.valueOf(number)); + break; + case "C": // commments + getRecords(ForumJob.TOPIC, Integer.parseInt(String.valueOf(id)), String.valueOf(number)); + break; + } + } + + public class testforumhtmlunit { + final Context context; + @Getter + @Setter + String forumMenuLayout; + final String forumMenuTiles; + final String forumListLayout; + final String forumListTiles; + final String forumCommentsLayout; + final String forumCommentsTiles; + final String spoilerStructure; + @Getter + @Setter + int id; + @Getter + @Setter + String page; + boolean subBoard = false; + + public testforumhtmlunit(Context context) { + forumMenuLayout = getString(context, R.raw.forum_menu); + forumMenuTiles = getString(context, R.raw.forum_menu_tiles); + forumListLayout = getString(context, R.raw.forum_list); + forumListTiles = getString(context, R.raw.forum_list_tiles); + forumCommentsLayout = getString(context, R.raw.forum_comment); + forumCommentsTiles = getString(context, R.raw.forum_comment_tiles); + spoilerStructure = getString(context, R.raw.forum_comment_spoiler_structure); + this.context = context; + } + + public void setSubBoard(boolean subBoard) { + this.subBoard = subBoard; + } + + public boolean getSubBoard() { + return this.subBoard; + } + + public boolean menuExists() { + return !forumMenuLayout.contains(""); + } + + private void loadWebview(String html) { + if (Theme.darkTheme) { + html = html.replace("#f2f2f2;", "#212121;"); // hover tags + html = html.replace("#FFF;", "#313131;"); // body + html = html.replace("#EEE;", "#212121;"); // body border + html = html.replace("#022f70;", "#0078a0;"); // selection tags + html = html.replace("#3E454F;", "#818181;"); // time ago + html = html.replace("markdown {", "markdown {color:#818181;"); // comment body color + } + html = html.replace("data:text/html,", ""); + webview.loadData(html, "text/html; charset=utf-8", "UTF-8"); + } + + public void setForumMenu(ArrayList menu) { + if (menu != null && menu.size() > 0) { + String forumArray = ""; + String tempTile; + String description; + for (Forum item : menu) { + tempTile = forumMenuTiles; + description = item.getDescription(); + + if (item.getChildren() != null) { + tempTile = tempTile.replace("onClick=\"tileClick()\"", ""); + description = description + " "; + + for (int i = 0; i < item.getChildren().size(); i++) { + Forum child = item.getChildren().get(i); + description = description + "" + child.getName() + "" + (i < item.getChildren().size() - 1 ? ", " : ""); + } + } else { + tempTile = tempTile.replace("", String.valueOf(item.getId())); + } + + tempTile = tempTile.replace("", item.getName()); + tempTile = tempTile.replace("", description); + tempTile = tempTile.replace("", getString(context, R.string.dialog_message_last_post)); + forumArray = forumArray + tempTile; + } + forumMenuLayout = forumMenuLayout.replace("", forumArray); + forumMenuLayout = forumMenuLayout.replace("", "M 0"); // M = menu, 0 = id + } + if (menuExists()) + loadWebview(forumMenuLayout); + } + + public void setForumList(ArrayList forumList) { + if (forumList != null && forumList.size() > 0) { + String tempForumList; + String forumArray = ""; + String tempTile; + int maxPages = forumList.get(0).getMaxPages(); + for (Forum item : forumList) { + tempTile = forumListTiles; + tempTile = tempTile.replace("", String.valueOf(item.getId())); + tempTile = tempTile.replace("", item.getName()); + tempTile = tempTile.replace("", item.getReply().getUsername()); + tempTile = tempTile.replace("", DateTools.parseDate(item.getReply().getTime(), true)); + forumArray = forumArray + tempTile; + } + tempForumList = forumListLayout.replace("", forumArray); + tempForumList = tempForumList.replace("", (getSubBoard() ? "S " : "T ") + getId() + " " + maxPages); // T = Topics || S = subboard, id + if (Integer.parseInt(getPage()) == 1) { + tempForumList = tempForumList.replace("class=\"previous\"", "class=\"previous\" style=\"visibility: hidden;\""); + } + if (Integer.parseInt(getPage()) == maxPages) { + tempForumList = tempForumList.replace("class=\"next\"", "class=\"next\" style=\"visibility: hidden;\""); + } + tempForumList = tempForumList.replace("Forum.prevTopicList(" + getPage(), "Forum.prevTopicList(" + (Integer.parseInt(getPage()) - 1)); + tempForumList = tempForumList.replace("Forum.nextTopicList(" + getPage(), "Forum.nextTopicList(" + (Integer.parseInt(getPage()) + 1)); + tempForumList = tempForumList.replace("", getPage()); + tempForumList = tempForumList.replace("", context.getString(R.string.next)); + tempForumList = tempForumList.replace("", context.getString(R.string.previous)); + loadWebview(tempForumList); + } + } + + public void setForumComments(ArrayList forumList) { + if (forumList != null && forumList.size() > 0) { + String tempForumList; + String rank; + String comment; + String forumArray = ""; + String tempTile; + int maxPages = forumList.get(0).getMaxPages(); + for (Forum item : forumList) { + rank = item.getProfile().getSpecialAccesRank(item.getUsername()); + comment = item.getComment(); + comment = comment.replaceAll("
((.|\\n)+?)
((.|\\n)+?)((.|\\n)+?)
", spoilerStructure + "$3"); + comment = comment.replaceAll("
((.|\\n)+?)class=\"quotetext\">((.|\\n)+?)
", spoilerStructure + "$3"); + comment = comment.replaceAll("@(\\w+)", "@$1"); + + tempTile = forumCommentsTiles; + if (item.getUsername().equalsIgnoreCase(AccountService.getUsername())) + tempTile = tempTile.replace("fa-quote-right fa-lg\"", "fa-pencil fa-lg\" id=\"edit\""); + tempTile = tempTile.replace("", item.getUsername()); + tempTile = tempTile.replace("", Integer.toString(item.getId())); + tempTile = tempTile.replace("", DateTools.parseDate(item.getTime(), true)); + tempTile = tempTile.replace("", comment); + if (item.getProfile().getAvatarUrl().contains("xmlhttp-loader")) + tempTile = tempTile.replace("", "http://cdn.myanimelist.net/images/na.gif"); + else + tempTile = tempTile.replace("", item.getProfile().getAvatarUrl()); + if (!rank.equals("")) + tempTile = tempTile.replace("", rank); + else + tempTile = tempTile.replace("", ""); + forumArray = forumArray + tempTile; + } + tempForumList = forumCommentsLayout.replace("", forumArray); + tempForumList = tempForumList.replace("", "C " + getId() + " " + maxPages + " " + getPage()); // C = Comments, id, maxPages, page + if (Integer.parseInt(getPage()) == 1) { + tempForumList = tempForumList.replace("class=\"previous\"", "class=\"previous\" style=\"visibility: hidden;\""); + } + if (Integer.parseInt(getPage()) == maxPages) { + tempForumList = tempForumList.replace("class=\"next\"", "class=\"next\" style=\"visibility: hidden;\""); + } + tempForumList = tempForumList.replace("Forum.prevCommentList(" + getPage(), "Forum.prevCommentList(" + (Integer.parseInt(getPage()) - 1)); + tempForumList = tempForumList.replace("Forum.nextCommentList(" + getPage(), "Forum.nextCommentList(" + (Integer.parseInt(getPage()) + 1)); + tempForumList = tempForumList.replace("", getPage()); + tempForumList = tempForumList.replace("", context.getString(R.string.next)); + tempForumList = tempForumList.replace("", context.getString(R.string.previous)); + loadWebview(tempForumList); + } + } + + /** + * Get the string of the given resource file. + * + * @param context The application context + * @param resource The resource of which string we need + * @return String the wanted string + */ + @SuppressWarnings("StatementWithEmptyBody") + private String getString(Context context, int resource) { + try { + InputStream inputStream = context.getResources().openRawResource(resource); + byte[] buffer = new byte[inputStream.available()]; + while (inputStream.read(buffer) != -1) ; + return new String(buffer); + } catch (Exception e) { + Crashlytics.logException(e); + } + return ""; + } } } diff --git a/Atarashii/src/net/somethingdreadful/MAL/Home.java b/Atarashii/src/net/somethingdreadful/MAL/Home.java index c7b8ac92..847a0757 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/Home.java +++ b/Atarashii/src/net/somethingdreadful/MAL/Home.java @@ -10,29 +10,24 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.graphics.Color; +import android.content.res.ColorStateList; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.support.v4.view.GravityCompat; +import android.support.design.widget.NavigationView; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.util.Log; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.AdapterView; import android.widget.ImageView; -import android.widget.ListView; -import android.widget.RelativeLayout; import android.widget.TextView; import com.crashlytics.android.Crashlytics; @@ -41,7 +36,6 @@ import net.somethingdreadful.MAL.account.AccountService; import net.somethingdreadful.MAL.adapters.IGFPagerAdapter; -import net.somethingdreadful.MAL.adapters.NavigationDrawerAdapter; import net.somethingdreadful.MAL.api.BaseModels.Profile; import net.somethingdreadful.MAL.api.MALApi; import net.somethingdreadful.MAL.dialog.ChooseDialogFragment; @@ -53,92 +47,86 @@ import butterknife.Bind; import butterknife.ButterKnife; -public class Home extends AppCompatActivity implements ChooseDialogFragment.onClickListener, SwipeRefreshLayout.OnRefreshListener, IGF.IGFCallbackListener, APIAuthenticationErrorListener, View.OnClickListener, UserNetworkTask.UserNetworkTaskListener, ViewPager.OnPageChangeListener { - IGF af; - IGF mf; - Menu menu; - Context context; - View mPreviousView; - ActionBar actionBar; - DrawerLayout DrawerLayout; - IGFPagerAdapter mIGFPagerAdapter; - BroadcastReceiver networkReceiver; - ActionBarDrawerToggle mDrawerToggle; - NavigationDrawerAdapter mNavigationDrawerAdapter; - - @Bind(R.id.about) RelativeLayout about; - @Bind(R.id.listview) ListView DrawerList; - @Bind(R.id.logout) RelativeLayout logout; - @Bind(R.id.settings) RelativeLayout settings; - @Bind(R.id.support) RelativeLayout support; - - String username; - - boolean networkAvailable; - boolean myList = true; //tracks if the user is on 'My List' or not - boolean callbackAnimeError = false; - boolean callbackMangaError = false; - int callbackCounter = 0; +public class Home extends AppCompatActivity implements ChooseDialogFragment.onClickListener, SwipeRefreshLayout.OnRefreshListener, IGF.IGFCallbackListener, APIAuthenticationErrorListener, View.OnClickListener, UserNetworkTask.UserNetworkTaskListener, ViewPager.OnPageChangeListener, NavigationView.OnNavigationItemSelectedListener { + private IGF af; + private IGF mf; + private Menu menu; + private Context context; + private BroadcastReceiver networkReceiver; + + private String username; + private boolean networkAvailable; + private boolean myList = true; //tracks if the user is on 'My List' or not + private int callbackCounter = 0; + @Bind(R.id.navigationView) + NavigationView navigationView; + @Bind(R.id.drawerLayout) + DrawerLayout drawerLayout; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + //Initializing activity and application context = getApplicationContext(); Theme.context = context; + if (AccountService.getAccount() != null) { //The following is state handling code networkAvailable = savedInstanceState == null || savedInstanceState.getBoolean("networkAvailable", true); if (savedInstanceState != null) myList = savedInstanceState.getBoolean("myList"); + //Initializing Theme Theme.setTheme(this, R.layout.activity_home, false); - mIGFPagerAdapter = (IGFPagerAdapter) Theme.setActionBar(this, new IGFPagerAdapter(getFragmentManager(), true)); - actionBar = getSupportActionBar(); + //Initializing IGF + Theme.setActionBar(this, new IGFPagerAdapter(getFragmentManager(), true)); + getSupportActionBar(); - LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); - DrawerLayout = (DrawerLayout) inflater.inflate(R.layout.record_home_navigationdrawer, (DrawerLayout) findViewById(R.id.drawer_layout)); + //Initializing ButterKnife ButterKnife.bind(this); - DrawerLayout.setDrawerListener(new DrawerListener()); - DrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); + //setup navigation profile information username = AccountService.getUsername(); - ((TextView) DrawerLayout.findViewById(R.id.name)).setText(username); - ((TextView) DrawerLayout.findViewById(R.id.siteName)).setText(getString(AccountService.isMAL() ? R.string.init_hint_myanimelist : R.string.init_hint_anilist)); new UserNetworkTask(context, false, this, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, username); - logout.setOnClickListener(this); - settings.setOnClickListener(this); - about.setOnClickListener(this); - support.setOnClickListener(this); - Theme.setBackground(this, logout); - Theme.setBackground(this, settings); - Theme.setBackground(this, support); - Theme.setBackground(this, about); + //Initializing NavigationView + navigationView = (NavigationView) findViewById(R.id.navigationView); + navigationView.setNavigationItemSelectedListener(this); + navigationView.getMenu().findItem(R.id.nav_list).setChecked(true); + ((TextView) navigationView.getHeaderView(0).findViewById(R.id.name)).setText(username); + ((TextView) navigationView.getHeaderView(0).findViewById(R.id.siteName)).setText(getString(AccountService.isMAL() ? R.string.init_hint_myanimelist : R.string.init_hint_anilist)); + + //Initializing navigation toggle button + drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); + ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, (Toolbar) findViewById(R.id.actionbar), R.string.drawer_open, R.string.drawer_close) { + }; + drawerLayout.setDrawerListener(drawerToggle); + drawerToggle.syncState(); + //Applying dark theme if (Theme.darkTheme) { - DrawerLayout.findViewById(R.id.scrollView).setBackgroundColor(getResources().getColor(R.color.bg_dark)); - DrawerLayout.findViewById(R.id.divider).setBackgroundColor(getResources().getColor(R.color.bg_dark_card)); - ((ImageView) DrawerLayout.findViewById(R.id.supportImg)).setImageDrawable(getResources().getDrawable(R.drawable.mobihelp_ic_conversation_dark)); - ((TextView) DrawerLayout.findViewById(R.id.logoutText)).setTextColor(getResources().getColor(R.color.text_dark)); - ((TextView) DrawerLayout.findViewById(R.id.settingsText)).setTextColor(getResources().getColor(R.color.text_dark)); - ((TextView) DrawerLayout.findViewById(R.id.supportText)).setTextColor(getResources().getColor(R.color.text_dark)); - ((TextView) DrawerLayout.findViewById(R.id.aboutText)).setTextColor(getResources().getColor(R.color.text_dark)); + int[][] states = new int[][] { + new int[] {-android.R.attr.state_checked}, // unchecked + new int[] {android.R.attr.state_checked} // checked + }; + + int[] colors = new int[] { + context.getResources().getColor(R.color.bg_light_card), + context.getResources().getColor(R.color.primary) + }; + + ColorStateList myList = new ColorStateList(states, colors); + navigationView.setBackgroundColor(getResources().getColor(R.color.bg_dark)); + navigationView.setItemTextColor(myList); + navigationView.setItemIconTintList(myList); } - NavigationItems mNavigationContent = new NavigationItems(DrawerList, context); - mNavigationDrawerAdapter = new NavigationDrawerAdapter(this, mNavigationContent.ITEMS); - DrawerList.setAdapter(mNavigationDrawerAdapter); - DrawerList.setOnItemClickListener(new DrawerItemClickListener()); - DrawerList.setOverScrollMode(View.OVER_SCROLL_NEVER); - - mDrawerToggle = new ActionBarDrawerToggle(this, DrawerLayout, (Toolbar) findViewById(R.id.actionbar), R.string.drawer_open, R.string.drawer_close); - mDrawerToggle.syncState(); - networkReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { checkNetworkAndDisplayCrouton(); + myListChanged(); } }; } else { @@ -163,9 +151,6 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - if (mDrawerToggle.onOptionsItemSelected(item)) { - return true; - } switch (item.getItemId()) { case R.id.listType_all: getRecords(true, TaskJob.GETLIST, 0); @@ -212,7 +197,7 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - public void getRecords(boolean clear, TaskJob task, int list) { + private void getRecords(boolean clear, TaskJob task, int list) { if (af != null && mf != null) { af.getRecords(clear, task, list); mf.getRecords(clear, task, list); @@ -237,7 +222,7 @@ public void onPause() { unregisterReceiver(networkReceiver); } - public void synctask(boolean clear) { + private void synctask(boolean clear) { getRecords(clear, TaskJob.FORCESYNC, af.list); } @@ -281,15 +266,17 @@ public boolean onPrepareOptionsMenu(Menu menu) { return true; } - public void setChecked(MenuItem item) { + private void setChecked(MenuItem item) { item.setChecked(true); } - public void myListChanged() { - menu.findItem(R.id.menu_listType).setVisible(myList); - menu.findItem(R.id.menu_inverse).setVisible(myList || (!AccountService.isMAL() && af.taskjob == TaskJob.GETMOSTPOPULAR)); - menu.findItem(R.id.forceSync).setVisible(myList && networkAvailable); - menu.findItem(R.id.action_search).setVisible(networkAvailable); + private void myListChanged() { + if (menu != null) { + menu.findItem(R.id.menu_listType).setVisible(myList); + menu.findItem(R.id.menu_inverse).setVisible(myList || (!AccountService.isMAL() && af.taskjob == TaskJob.GETMOSTPOPULAR)); + menu.findItem(R.id.forceSync).setVisible(myList && networkAvailable); + menu.findItem(R.id.action_search).setVisible(networkAvailable); + } } private void syncNotify() { @@ -325,7 +312,7 @@ private void showLogoutDialog() { lcdf.show(getFragmentManager(), "fragment_LogoutConfirmationDialog"); } - public void checkNetworkAndDisplayCrouton() { + private void checkNetworkAndDisplayCrouton() { if (MALApi.isNetworkAvailable(context) && !networkAvailable) synctask(false); networkAvailable = MALApi.isNetworkAvailable(context); @@ -401,18 +388,6 @@ public void onAPIAuthenticationError(MALApi.ListType type, TaskJob job) { @Override public void onClick(View v) { switch (v.getId()) { - case R.id.logout: - showLogoutDialog(); - break; - case R.id.settings: - startActivity(new Intent(this, Settings.class)); - break; - case R.id.support: - Mobihelp.showSupport(this); - break; - case R.id.about: - startActivity(new Intent(this, AboutActivity.class)); - break; case R.id.Image: Intent Profile = new Intent(context, ProfileActivity.class); Profile.putExtra("username", username); @@ -423,7 +398,6 @@ public void onClick(View v) { lcdf.show(getFragmentManager(), "fragment_NDImage"); break; } - DrawerLayout.closeDrawers(); } @Override @@ -460,100 +434,92 @@ public void onPageScrollStateChanged(int state) {} @Override public void onPositiveButtonClicked() { - AccountService.clearData(true); + AccountService.clearData(); startActivity(new Intent(this, FirstTimeInit.class)); System.exit(0); } - public class DrawerItemClickListener implements ListView.OnItemClickListener { + @Override + public boolean onNavigationItemSelected(MenuItem item) { + // disable swipeRefresh for other lists + af.setSwipeRefreshEnabled(myList); + mf.setSwipeRefreshEnabled(myList); - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - if (!networkAvailable && position > 2) { - position = 0; - Theme.Snackbar(Home.this, R.string.toast_error_noConnectivity); - } - myList = ((position <= 3 && myList) || position == 0); - // disable swipeRefresh for other lists - af.setSwipeRefreshEnabled(myList); - mf.setSwipeRefreshEnabled(myList); - switch (position) { - case 0: - getRecords(true, TaskJob.GETLIST, af.list); - break; - case 1: - Intent Profile = new Intent(context, ProfileActivity.class); - Profile.putExtra("username", username); - startActivity(Profile); - break; - case 2: - Intent Friends = new Intent(context, ProfileActivity.class); - Friends.putExtra("username", username); - Friends.putExtra("friends", username); - startActivity(Friends); - break; - case 3: - if (AccountService.isMAL()) { - Intent Forum = new Intent(context, ForumActivity.class); - startActivity(Forum); - } else { - Theme.Snackbar(Home.this, R.string.toast_info_disabled); - } - break; - case 4: - getRecords(true, TaskJob.GETTOPRATED, af.list); - break; - case 5: - getRecords(true, TaskJob.GETMOSTPOPULAR, af.list); - break; - case 6: - getRecords(true, TaskJob.GETJUSTADDED, af.list); - break; - case 7: - getRecords(true, TaskJob.GETUPCOMING, af.list); - break; - } - myListChanged(); - - /* - * This part is for figuring out which item in the nav drawer is selected and highlighting it with colors. - */ - if (position != 1 && position != 2 && position != 3) { - if (mPreviousView != null) - mPreviousView.setBackgroundColor(Color.parseColor("#00000000")); - if (Theme.darkTheme) - view.setBackgroundColor(getResources().getColor(R.color.bg_dark_card)); + //Checking if the item should be checked + switch (item.getItemId()) { + case R.id.nav_profile: + break; + case R.id.nav_friends: + break; + case R.id.nav_forum: + break; + case R.id.nav_settings: + break; + case R.id.nav_support: + break; + case R.id.nav_about: + break; + default: + if (item.isChecked()) + item.setChecked(false); else - view.setBackgroundColor(Color.parseColor("#E8E8E8")); - mPreviousView = view; - } - - DrawerLayout.closeDrawers(); - } - } - - private class DrawerListener implements DrawerLayout.DrawerListener { - @Override - public void onDrawerOpened(View drawerView) { - mDrawerToggle.onDrawerOpened(drawerView); - actionBar.setTitle(getTitle()); + item.setChecked(true); + break; } - @Override - public void onDrawerClosed(View drawerView) { - mDrawerToggle.onDrawerClosed(drawerView); - actionBar.setTitle(getTitle()); - drawerView.requestFocusFromTouch(); - } + //Closing drawer on item click + drawerLayout.closeDrawers(); - @Override - public void onDrawerSlide(View drawerView, float slideOffset) { - mDrawerToggle.onDrawerSlide(drawerView, slideOffset); - } - - @Override - public void onDrawerStateChanged(int newState) { - mDrawerToggle.onDrawerStateChanged(newState); + //Performing the action + switch (item.getItemId()) { + case R.id.nav_list: + getRecords(true, TaskJob.GETLIST, af.list); + break; + case R.id.nav_profile: + Intent Profile = new Intent(context, ProfileActivity.class); + Profile.putExtra("username", username); + startActivity(Profile); + break; + case R.id.nav_friends: + Intent Friends = new Intent(context, ProfileActivity.class); + Friends.putExtra("username", username); + Friends.putExtra("friends", username); + startActivity(Friends); + break; + case R.id.nav_forum: + if (AccountService.isMAL()) { + Intent Forum = new Intent(context, ForumActivity.class); + startActivity(Forum); + } else { + Theme.Snackbar(Home.this, R.string.toast_info_disabled); + } + break; + case R.id.nav_rated: + getRecords(true, TaskJob.GETTOPRATED, af.list); + break; + case R.id.nav_popular: + getRecords(true, TaskJob.GETMOSTPOPULAR, af.list); + break; + case R.id.nav_added: + getRecords(true, TaskJob.GETJUSTADDED, af.list); + break; + case R.id.nav_upcoming: + getRecords(true, TaskJob.GETUPCOMING, af.list); + break; + case R.id.nav_logout: // Others subgroup + showLogoutDialog(); + break; + case R.id.nav_settings: + startActivity(new Intent(this, Settings.class)); + break; + case R.id.nav_support: + Mobihelp.showSupport(this); + break; + case R.id.nav_about: + startActivity(new Intent(this, AboutActivity.class)); + break; } + myListChanged(); + return false; } } diff --git a/Atarashii/src/net/somethingdreadful/MAL/IGF.java b/Atarashii/src/net/somethingdreadful/MAL/IGF.java index 8bacc2ff..59f9cbb0 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/IGF.java +++ b/Atarashii/src/net/somethingdreadful/MAL/IGF.java @@ -52,37 +52,39 @@ public class IGF extends Fragment implements OnScrollListener, OnItemClickListener, NetworkTask.NetworkTaskListener, RecordStatusUpdatedReceiver.RecordStatusUpdatedListener { public ListType listType = ListType.ANIME; // just to have it proper initialized - Context context; + private Context context; public TaskJob taskjob; - Activity activity; - NetworkTask networkTask; - IGFCallbackListener callback; - ListViewAdapter ga; - ArrayList gl = new ArrayList<>(); - - @Bind(R.id.gridview) GridView Gridview; - @Bind(R.id.viewFlipper) ViewFlipper viewflipper; - @Bind(R.id.swiperefresh) SwipeRefreshLayout swipeRefresh; - - RecordStatusUpdatedReceiver recordStatusReceiver; - - int page = 1; + private Activity activity; + private NetworkTask networkTask; + private IGFCallbackListener callback; + private ListViewAdapter ga; + private ArrayList gl = new ArrayList<>(); + + @Bind(R.id.gridview) + GridView Gridview; + @Bind(R.id.viewFlipper) + ViewFlipper viewflipper; + @Bind(R.id.swiperefresh) + SwipeRefreshLayout swipeRefresh; + + private RecordStatusUpdatedReceiver recordStatusReceiver; + + private int page = 1; public int list = -1; - int resource; - int height = 0; - boolean loading = true; - boolean useSecondaryAmounts; - boolean hasmorepages = false; - boolean clearAfterLoading = false; + private int resource; + private int height = 0; + private boolean loading = true; + private boolean useSecondaryAmounts; + private boolean hasmorepages = false; + private boolean clearAfterLoading = false; /* setSwipeRefreshEnabled() may be called before swipeRefresh exists (before onCreateView() is * called), so save it and apply it in onCreateView() */ - boolean swipeRefreshEnabled = true; + private boolean swipeRefreshEnabled = true; - String query; + private String query; // use setter to change this! private String username; - private boolean ownList = false; // not set directly, is set by setUsername() public boolean popup; @Override @@ -129,12 +131,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle st if (isOnHomeActivity()) swipeRefresh.setOnRefreshListener((Home) getActivity()); - swipeRefresh.setColorScheme( - android.R.color.holo_blue_bright, - android.R.color.holo_green_light, - android.R.color.holo_orange_light, - android.R.color.holo_red_light - ); + swipeRefresh.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeRefresh.setEnabled(swipeRefreshEnabled); if (gl.size() > 0) // there are already records, fragment has been rotated @@ -169,7 +166,7 @@ public void onDetach() { * Set the numbers columns for the best overview. */ @SuppressLint("InlinedApi") - public void setColumns() { + private void setColumns() { int screenWidth = Theme.convert(context.getResources().getConfiguration().screenWidthDp); if (PrefManager.getTraditionalListEnabled()) { Gridview.setNumColumns(1); //remain in the listview mode @@ -233,7 +230,7 @@ private boolean isOnHomeActivity() { * @param anime The Anime record that should increase by one * @param manga The manga record that should increase by one */ - public void setProgressPlusOne(Anime anime, Manga manga) { + private void setProgressPlusOne(Anime anime, Manga manga) { if (listType.equals(ListType.ANIME)) { anime.setWatchedEpisodes(anime.getWatchedEpisodes() + 1); new WriteDetailTask(listType, TaskJob.UPDATE, context, getAuthErrorCallback(), activity).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, anime); @@ -252,7 +249,7 @@ public void setProgressPlusOne(Anime anime, Manga manga) { * @param anime The Anime record that should be marked as complete * @param manga The manga record that should be marked as complete */ - public void setMarkAsComplete(Anime anime, Manga manga) { + private void setMarkAsComplete(Anime anime, Manga manga) { if (listType.equals(ListType.ANIME)) { anime.setWatchedStatus(GenericRecord.STATUS_COMPLETED); gl.remove(anime); @@ -341,7 +338,7 @@ public void getRecords(boolean clear, TaskJob task, int list) { Bundle data = new Bundle(); data.putInt("page", page); networkTask = new NetworkTask(taskjob, listType, activity, data, this, getAuthErrorCallback()); - ArrayList args = new ArrayList(); + ArrayList args = new ArrayList<>(); if (!username.equals("") && isList()) { args.add(username); if (isList()) @@ -373,7 +370,7 @@ public void searchRecords(String search) { /** * Reset the page number of anime/manga lists. */ - public void resetPage() { + private void resetPage() { page = 1; if (Gridview != null) { Gridview.requestFocusFromTouch(); @@ -389,15 +386,15 @@ public void run() { /** * Set the adapter anime/manga. */ - public void setAdapter() { - ga = new ListViewAdapter(context, resource, popup); + private void setAdapter() { + ga = new ListViewAdapter<>(context, resource, popup); ga.setNotifyOnChange(true); } /** * Refresh all the covers. */ - public void refresh() { + private void refresh() { try { filterTime(); if (ga == null) @@ -431,7 +428,7 @@ public void refresh() { * @param job The current taskjob to compare with * @return boolean If true then the list is of the logged in user */ - public boolean isList(TaskJob job) { + private boolean isList(TaskJob job) { return job != null && (job.equals(TaskJob.GETLIST) || job.equals(TaskJob.FORCESYNC)); } @@ -440,7 +437,7 @@ public boolean isList(TaskJob job) { * * @return boolean If true then the list is of the logged in user */ - public boolean isList() { + private boolean isList() { return isList(taskjob); } @@ -467,7 +464,7 @@ public void inverse() { */ private void filterTime() { if (!AccountService.isMAL() && taskjob == TaskJob.GETMOSTPOPULAR && PrefManager.getAiringOnly() && listType == ListType.ANIME) { - ArrayList record = new ArrayList(); + ArrayList record = new ArrayList<>(); for (GenericRecord gr : gl) if (((Anime) gr).getAiring() != null) record.add(gr); @@ -584,7 +581,6 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun */ public void setUsername(String username) { this.username = username; - ownList = !(username == null || username.equals("")) && AccountService.getUsername().equals(username); } // user updated record on DetailsView, so update the list if necessary @@ -622,7 +618,7 @@ static class ViewHolder { * The custom adapter for the covers anime/manga. */ public class ListViewAdapter extends ArrayAdapter { - boolean popup; + final boolean popup; public ListViewAdapter(Context context, int resource, boolean popup) { super(context, resource); @@ -777,8 +773,8 @@ public void supportAddAll(Collection collection) { } public interface IGFCallbackListener { - public void onIGFReady(IGF igf); - public void onRecordsLoadingFinished(MALApi.ListType type, TaskJob job, boolean error, boolean resultEmpty, boolean cancelled); - public void onItemClick(int id, ListType listType, String username); + void onIGFReady(IGF igf); + void onRecordsLoadingFinished(MALApi.ListType type, TaskJob job, boolean error, boolean resultEmpty, boolean cancelled); + void onItemClick(int id, ListType listType, String username); } } \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/MALManager.java b/Atarashii/src/net/somethingdreadful/MAL/MALManager.java index f3843690..2658eabe 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/MALManager.java +++ b/Atarashii/src/net/somethingdreadful/MAL/MALManager.java @@ -9,6 +9,7 @@ import net.somethingdreadful.MAL.api.ALApi; import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Anime; import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.BrowseList; +import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Forum; import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Manga; import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews; import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.UserList; @@ -24,10 +25,9 @@ import java.util.Comparator; public class MALManager { - MALApi malApi; - ALApi alApi; - DatabaseManager dbMan; - Context context; + private MALApi malApi; + private ALApi alApi; + private final DatabaseManager dbMan; public MALManager(Context context) { if (AccountService.isMAL()) @@ -35,7 +35,6 @@ public MALManager(Context context) { else alApi = new ALApi(); dbMan = new DatabaseManager(context); - this.context = context; } public static String listSortFromInt(int i, MALApi.ListType type) { @@ -188,17 +187,9 @@ public void saveMangaToDatabase(Manga manga) { } public boolean cleanDirtyAnimeRecords() { - return cleanDirtyAnimeRecords(true); - } - - public boolean cleanDirtyMangaRecords() { - return cleanDirtyMangaRecords(true); - } - - public boolean cleanDirtyAnimeRecords(boolean dirtyOnly) { boolean totalSuccess = true; - ArrayList dirtyAnimes = dirtyOnly ? dbMan.getDirtyAnimeList() : getAnimeListFromDB(MALApi.ListType.ANIME.toString()); + ArrayList dirtyAnimes = dbMan.getDirtyAnimeList(); if (dirtyAnimes != null) { Crashlytics.log(Log.VERBOSE, "MALX", "MALManager.cleanDirtyAnimeRecords(): Got " + dirtyAnimes.size() + " dirty anime records. Cleaning.."); @@ -218,10 +209,10 @@ public boolean cleanDirtyAnimeRecords(boolean dirtyOnly) { return totalSuccess; } - public boolean cleanDirtyMangaRecords(boolean dirtyOnly) { + public boolean cleanDirtyMangaRecords() { boolean totalSuccess = true; - ArrayList dirtyMangas = dirtyOnly ? dbMan.getDirtyMangaList() : getMangaListFromDB(MALApi.ListType.MANGA.toString()); + ArrayList dirtyMangas = dbMan.getDirtyMangaList(); if (dirtyMangas != null) { Crashlytics.log(Log.VERBOSE, "MALX", "MALManager.cleanDirtyMangaRecords(): Got " + dirtyMangas.size() + " dirty manga records. Cleaning.."); @@ -253,10 +244,6 @@ public ArrayList getActivity(String username) { * All the methods below this block is used to determine and make request to the API. */ - public ForumMain search(String query) { - return malApi.search(query); - } - public Anime getAnimeRecord(int id) { Crashlytics.log(Log.DEBUG, "MALX", "MALManager.getAnimeRecord(): Downloading " + id); return AccountService.isMAL() ? malApi.getAnime(id) : alApi.getAnime(id); @@ -267,30 +254,10 @@ public Manga getMangaRecord(int id) { return AccountService.isMAL() ? malApi.getManga(id) : alApi.getManga(id); } - public ForumMain getForum() { - return malApi.getForum(); - } - - public ForumMain getTopics(int id, int page) { - return malApi.getTopics(id, page); - } - public ForumMain getDiscussion(int id, int page, MALApi.ListType type) { return type.equals(MALApi.ListType.ANIME) ? malApi.getAnime(id, page) : malApi.getManga(id, page); } - public ForumMain getPosts(int id, int page) { - return malApi.getPosts(id, page); - } - - public ForumMain getSubBoards(int id, int page) { - return malApi.getSubBoards(id, page); - } - - public Boolean addComment(int id, String message) { - return malApi.addComment(id, message); - } - public Boolean updateComment(int id, String message) { return malApi.updateComment(id, message); } @@ -376,6 +343,19 @@ public ArrayList getMangaReviews(int id, int page) { return AccountService.isMAL() ? malApi.getMangaReviews(id, page) : alApi.getMangaReviews(id, page); } + public ArrayList getForumCategories() { + return malApi.getForum().createBaseModel(); + } + + + public ArrayList getCategoryTopics(int id, int page) { + return malApi.getCategoryTopics(id, page).createBaseModel(); + } + + public ArrayList getTopic(int id, int page) { + return malApi.getPosts(id, page).createBaseModel(); + } + public boolean deleteAnime(Anime anime) { return dbMan.deleteAnime(anime.getId()); } @@ -383,4 +363,16 @@ public boolean deleteAnime(Anime anime) { public boolean deleteManga(Manga manga) { return dbMan.deleteManga(manga.getId()); } + + public ArrayList search(String query) { + return malApi.search(query).createBaseModel(); + } + + public ArrayList getSubCategory(int id, int page) { + return malApi.getSubBoards(id, page).createBaseModel(); + } + + public boolean addComment(int id, String message) { + return malApi.addComment(id, message); + } } diff --git a/Atarashii/src/net/somethingdreadful/MAL/NavigationItems.java b/Atarashii/src/net/somethingdreadful/MAL/NavigationItems.java deleted file mode 100644 index 09f4eb7c..00000000 --- a/Atarashii/src/net/somethingdreadful/MAL/NavigationItems.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.somethingdreadful.MAL; - -import android.content.Context; -import android.widget.ListView; - -import net.somethingdreadful.MAL.account.AccountService; - -import java.util.ArrayList; - -public class NavigationItems { - - public ArrayList ITEMS = new ArrayList(); - - public NavigationItems(ListView list, Context context) { - addItem(new NavItem(R.drawable.ic_format_list, R.string.nav_item_my_list)); - addItem(new NavItem(R.drawable.ic_person, R.string.nav_item_my_profile)); - if (AccountService.isMAL()) - addItem(new NavItem(R.drawable.ic_group, R.string.nav_item_my_friends)); - else - addItem(new NavItem(R.drawable.ic_group, R.string.nav_item_my_following)); - addItem(new NavItem(R.drawable.ic_forum_grey, R.string.nav_item_my_forum)); - if (AccountService.isMAL()) { - addItem(new NavItem(R.drawable.ic_star, R.string.nav_item_top_rated)); - addItem(new NavItem(R.drawable.ic_insert_chart, R.string.nav_item_most_popular)); - } else { - addItem(new NavItem(R.drawable.ic_star, R.string.nav_item_year)); - addItem(new NavItem(R.drawable.ic_insert_chart, R.string.nav_item_airing)); - } - addItem(new NavItem(R.drawable.ic_access_time, R.string.nav_item_just_added)); - addItem(new NavItem(R.drawable.ic_event, R.string.nav_item_upcoming)); - - // Calculate the best ListView height and apply it - list.getLayoutParams().height = (int) (ITEMS.size() * 48 * (context.getResources().getDisplayMetrics().densityDpi / 160f)); - } - - public void addItem(NavItem item) { - ITEMS.add(item); - } - - public static class NavItem { - public int icon; - public int title; - - public NavItem(int icon, int title) { - this.icon = icon; - this.title = title; - } - } - -} \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/PrefManager.java b/Atarashii/src/net/somethingdreadful/MAL/PrefManager.java index 087162b8..22f868ae 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/PrefManager.java +++ b/Atarashii/src/net/somethingdreadful/MAL/PrefManager.java @@ -1,5 +1,6 @@ package net.somethingdreadful.MAL; +import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; @@ -10,9 +11,9 @@ public class PrefManager { private static SharedPreferences prefs; private static SharedPreferences.Editor prefEditor; private static Context context; - private static boolean darkTheme; + @SuppressLint("CommitPrefEdits") public static void create(Context mContext) { context = mContext; prefs = PreferenceManager.getDefaultSharedPreferences(context); diff --git a/Atarashii/src/net/somethingdreadful/MAL/ProfileActivity.java b/Atarashii/src/net/somethingdreadful/MAL/ProfileActivity.java index 4af2e77b..6326dfd0 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/ProfileActivity.java +++ b/Atarashii/src/net/somethingdreadful/MAL/ProfileActivity.java @@ -28,17 +28,18 @@ import butterknife.ButterKnife; public class ProfileActivity extends AppCompatActivity implements UserNetworkTask.UserNetworkTaskListener { - Context context; + private Context context; public Profile record; - ProfileFriends friends; - ProfileDetailsAL detailsAL; - ProfileDetailsMAL detailsMAL; - ProfileHistory history; - boolean isLoading = false; + private ProfileFriends friends; + private ProfileDetailsAL detailsAL; + private ProfileDetailsMAL detailsMAL; + private ProfileHistory history; + private boolean isLoading = false; - @Bind(R.id.pager) ViewPager viewPager; + @Bind(R.id.pager) + ViewPager viewPager; - boolean forcesync = false; + private final boolean forcesync = false; @Override protected void onCreate(Bundle bundle) { @@ -107,11 +108,11 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } - public String getProfileURL() { + private String getProfileURL() { return AccountService.isMAL() ? "http://myanimelist.net/profile/" : "http://anilist.co/user/"; } - public void refresh() { + private void refresh() { if (record == null) { if (MALApi.isNetworkAvailable(context)) { Theme.Snackbar(this, R.string.toast_error_UserRecord); @@ -145,7 +146,7 @@ record = result; isLoading = false; } - public void setText() { + private void setText() { if (detailsMAL != null) detailsMAL.refresh(); if (detailsAL != null) @@ -201,7 +202,7 @@ public void setFriends(ProfileFriends friends) { viewPager.setCurrentItem(1); } - public void toggle(int number) { + private void toggle(int number) { if (detailsMAL != null) detailsMAL.toggle(number); if (detailsAL != null) diff --git a/Atarashii/src/net/somethingdreadful/MAL/SearchActivity.java b/Atarashii/src/net/somethingdreadful/MAL/SearchActivity.java index 2e780dd2..a9b2e50a 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/SearchActivity.java +++ b/Atarashii/src/net/somethingdreadful/MAL/SearchActivity.java @@ -26,22 +26,14 @@ public class SearchActivity extends AppCompatActivity implements IGF.IGFCallbackListener { public String query; - IGF af; - IGF mf; - IGFPagerAdapter mIGFPagerAdapter; - SearchView searchView; - - boolean callbackAnimeError = false; - boolean callbackMangaError = false; - boolean callbackAnimeResultEmpty = false; - boolean callbackMangaResultEmpty = false; - int callbackCounter = 0; + private IGF af; + private IGF mf; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.theme_viewpager); - mIGFPagerAdapter = (IGFPagerAdapter) Theme.setActionBar(this, new IGFPagerAdapter(getFragmentManager(), true)); + Theme.setActionBar(this, new IGFPagerAdapter(getFragmentManager(), true)); } @Override @@ -66,9 +58,6 @@ private void handleIntent(Intent intent) { FragmentManager fm = getFragmentManager(); (new SearchIdDialogFragment()).show(fm, "fragment_id_search"); } else { - if (searchView != null) { - searchView.setQuery(query, false); - } if (af != null && mf != null) { af.searchRecords(query); mf.searchRecords(query); diff --git a/Atarashii/src/net/somethingdreadful/MAL/SettingsFragment.java b/Atarashii/src/net/somethingdreadful/MAL/SettingsFragment.java index f4187f93..3b4aaa8e 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/SettingsFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/SettingsFragment.java @@ -20,7 +20,7 @@ public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener, Preference.OnPreferenceClickListener, NumberPickerDialogFragment.onUpdateClickListener { private Context context; - AlarmManager alarmMgr; + private AlarmManager alarmMgr; @Override public void onCreate(Bundle savedInstanceState) { @@ -132,7 +132,7 @@ public boolean onPreferenceClick(Preference preference) { return false; } - public void makeNumberpicker(Bundle bundle) { + private void makeNumberpicker(Bundle bundle) { NumberPickerDialogFragment numberPickerDialogFragment = new NumberPickerDialogFragment().setOnSendClickListener(this); numberPickerDialogFragment.setArguments(bundle); numberPickerDialogFragment.show(getActivity().getFragmentManager(), "numberPickerDialogFragment"); diff --git a/Atarashii/src/net/somethingdreadful/MAL/Theme.java b/Atarashii/src/net/somethingdreadful/MAL/Theme.java index 29ebdf09..e983436d 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/Theme.java +++ b/Atarashii/src/net/somethingdreadful/MAL/Theme.java @@ -35,8 +35,8 @@ public class Theme extends Application { public static boolean darkTheme; private static float density; - Locale locale; - Configuration config; + private Locale locale; + private Configuration config; static Context context; @Override @@ -82,6 +82,7 @@ public void onConfigurationChanged(Configuration newConfig) { public static void logTaskCrash(String className, String message, Exception e) { Crashlytics.log(Log.ERROR, "MALX", className + "." + message + ": " + e.getMessage()); Crashlytics.logException(e); + e.printStackTrace(); Answers.getInstance().logCustom(new CustomEvent("Error (Task)").putCustomAttribute(className, e.getMessage())); } @@ -97,7 +98,7 @@ public static boolean isPortrait() { /** * Changes the language to the preferred one. */ - public void setLanguage() { + private void setLanguage() { Resources res = getBaseContext().getResources(); res.updateConfiguration(config, res.getDisplayMetrics()); } diff --git a/Atarashii/src/net/somethingdreadful/MAL/account/AccountService.java b/Atarashii/src/net/somethingdreadful/MAL/account/AccountService.java index 1313675d..3a9cc50f 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/account/AccountService.java +++ b/Atarashii/src/net/somethingdreadful/MAL/account/AccountService.java @@ -27,7 +27,7 @@ public class AccountService extends Service { /** * The account version will be used to peform */ - private static int accountVersion = 2; + private static final int accountVersion = 2; public static void create(Context context) { AccountService.context = context; @@ -116,7 +116,7 @@ public static boolean isMAL() { * @param type The authToken string * @return AccountType The type of account */ - public static AccountType getAccountType(String type) { + private static AccountType getAccountType(String type) { if (AccountType.AniList.toString().equals(type)) return AccountType.AniList; else @@ -126,7 +126,7 @@ public static AccountType getAccountType(String type) { /** * Removes an account from the accountmanager. */ - public static void deleteAccount() { + private static void deleteAccount() { AccountManager accountManager = AccountManager.get(context); accountManager.removeAccount(getAccount(), null, null); account = null; @@ -188,7 +188,7 @@ public static String getAccesToken() { * * @param accountVersion The new accountversion of the account that will be saved */ - public static void setAccountVersion(int accountVersion) { + private static void setAccountVersion(int accountVersion) { if (account != null) { AccountManager accountManager = AccountManager.get(context); accountManager.setUserData(account, "accountVersion", String.valueOf(accountVersion)); @@ -215,13 +215,10 @@ public static String getRefreshToken() { /** * Removes the userdata - * - * @param prefs If true it will remove all the prefrences saved. */ - public static void clearData(boolean prefs) { + public static void clearData() { DatabaseTest.deleteDatabase(context); - if (prefs) - PrefManager.clear(); + PrefManager.clear(); Mobihelp.clearUserData(context); AccountService.deleteAccount(); } diff --git a/Atarashii/src/net/somethingdreadful/MAL/adapters/BackupGridviewAdapter.java b/Atarashii/src/net/somethingdreadful/MAL/adapters/BackupGridviewAdapter.java index 1adc62e9..1ce85010 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/adapters/BackupGridviewAdapter.java +++ b/Atarashii/src/net/somethingdreadful/MAL/adapters/BackupGridviewAdapter.java @@ -23,10 +23,10 @@ import java.util.Collections; public class BackupGridviewAdapter extends ArrayAdapter { - private Context context; + private final Context context; private ArrayList list; - private String username; - private onClickListener onClickListener; + private final String username; + private final onClickListener onClickListener; public BackupGridviewAdapter(Context context, ArrayList list, onClickListener onClickListener) { super(context, R.layout.record_friends_gridview); @@ -75,7 +75,7 @@ public void onClick(View v) { try { viewHolder.username.setText(fileName.substring(fileName.indexOf('_') + 1).replace(".json", "")); - viewHolder.last_online.setText(DateTools.parseDate(Long.parseLong(fileName.substring(6, fileName.indexOf('_'))), true)); + viewHolder.last_online.setText(DateTools.parseDate(Long.parseLong(fileName.substring(6, fileName.indexOf('_'))))); if (!username.equals(viewHolder.username.getText())) viewHolder.username.setTextColor(context.getResources().getColor(R.color.card_red)); else diff --git a/Atarashii/src/net/somethingdreadful/MAL/adapters/DetailViewPagerAdapter.java b/Atarashii/src/net/somethingdreadful/MAL/adapters/DetailViewPagerAdapter.java index 4e3002c8..b2c6b8ed 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/adapters/DetailViewPagerAdapter.java +++ b/Atarashii/src/net/somethingdreadful/MAL/adapters/DetailViewPagerAdapter.java @@ -16,23 +16,21 @@ import net.somethingdreadful.MAL.detailView.DetailViewReviews; public class DetailViewPagerAdapter extends FragmentPagerAdapter { - public int count; - boolean hidePersonal = false; - DetailView activity; - int maxCount = 4; - FragmentManager fm; + private int count; + private boolean hidePersonal = false; + private final DetailView activity; + private int maxCount = 4; public ViewGroup container; private long fragmentId = 0; public DetailViewPagerAdapter(FragmentManager fm, DetailView activity) { super(fm); - this.fm = fm; this.activity = activity; this.maxCount = MALApi.isNetworkAvailable(activity) ? maxCount : maxCount - 1; this.count = getMaxcount(); } - public int getMaxcount() { + private int getMaxcount() { return maxCount; } @@ -107,7 +105,7 @@ public long getItemId(int position) { * * @param number number of items which have been changed */ - public void notifyChangeInPosition(int number) { + private void notifyChangeInPosition(int number) { fragmentId += getCount() + number; } } \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/adapters/DetailViewRelationsAdapter.java b/Atarashii/src/net/somethingdreadful/MAL/adapters/DetailViewRelationsAdapter.java index fd516b89..66d815e7 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/adapters/DetailViewRelationsAdapter.java +++ b/Atarashii/src/net/somethingdreadful/MAL/adapters/DetailViewRelationsAdapter.java @@ -16,11 +16,11 @@ import java.util.Map; public class DetailViewRelationsAdapter extends BaseExpandableListAdapter { - public Map> list = new LinkedHashMap>(); - public ArrayList headers = new ArrayList<>(); + private final Map> list = new LinkedHashMap<>(); + public final ArrayList headers = new ArrayList<>(); public int visable; - ViewHolder viewHolder; - private Context context; + private ViewHolder viewHolder; + private final Context context; public DetailViewRelationsAdapter(Context context) { this.context = context; @@ -72,7 +72,7 @@ public RecordStub getRecordStub(int groupPos, int childPos) { */ public void addTitles(ArrayList strings, String header) { if (strings != null) { - ArrayList records = new ArrayList(); + ArrayList records = new ArrayList<>(); for (String stub : strings) { RecordStub record = new RecordStub(); record.setTitle(stub); @@ -90,7 +90,7 @@ public void addTitles(ArrayList strings, String header) { */ public void addRelations(RecordStub recordStub, String header) { if (recordStub != null) { - ArrayList record = new ArrayList(); + ArrayList record = new ArrayList<>(); record.add(recordStub); addRelations(record, header); } diff --git a/Atarashii/src/net/somethingdreadful/MAL/adapters/ForumMainAdapter.java b/Atarashii/src/net/somethingdreadful/MAL/adapters/ForumMainAdapter.java deleted file mode 100644 index 46110a3b..00000000 --- a/Atarashii/src/net/somethingdreadful/MAL/adapters/ForumMainAdapter.java +++ /dev/null @@ -1,110 +0,0 @@ -package net.somethingdreadful.MAL.adapters; - -import android.app.Activity; -import android.app.FragmentManager; -import android.content.Context; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.TextView; - -import com.crashlytics.android.Crashlytics; - -import net.somethingdreadful.MAL.DateTools; -import net.somethingdreadful.MAL.R; -import net.somethingdreadful.MAL.Theme; -import net.somethingdreadful.MAL.api.MALModels.Forum; -import net.somethingdreadful.MAL.dialog.InformationDialogFragment; -import net.somethingdreadful.MAL.tasks.ForumJob; - -import java.util.Collection; - -public class ForumMainAdapter extends ArrayAdapter { - private Context context; - private FragmentManager fm; - private ListView listview; - private ForumJob task; - - public ForumMainAdapter(Activity context, ListView listview, FragmentManager fm, ForumJob task) { - super(context, R.layout.record_forum_listview); - this.context = context; - this.listview = listview; - this.fm = fm; - this.task = task; - } - - public View getView(int position, View view, ViewGroup parent) { - final Forum record = ((Forum) this.getItem(position)); - ViewHolder viewHolder; - - if (view == null) { - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = inflater.inflate(R.layout.record_forum_listview, parent, false); - - viewHolder = new ViewHolder(); - viewHolder.title = (TextView) view.findViewById(R.id.title); - viewHolder.image = (ImageView) view.findViewById(R.id.Image); - - if (Theme.darkTheme) { - viewHolder.title.setTextColor(context.getResources().getColor(R.color.text_dark)); - Theme.setBackground(context, viewHolder.image); - Theme.setBackground(context, view); - } - - view.setTag(viewHolder); - } else { - viewHolder = (ViewHolder) view.getTag(); - } - - try { - viewHolder.title.setText(record.getName()); - if (record.getReply() != null || record.getDescription() != null) { - viewHolder.image.setVisibility(View.VISIBLE); - viewHolder.image.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - InformationDialogFragment info = new InformationDialogFragment(); - Bundle args = new Bundle(); - args.putString("title", record.getName()); - if (task == ForumJob.BOARD) - args.putString("message", record.getDescription()); - else - args.putString("message", context.getString(R.string.dialog_message_created_by) - + " " + record.getUsername() - + "\n" - + context.getString(R.string.dialog_message_last_post) - + " " + record.getReply().getUsername() - + ", " + DateTools.parseDate(record.getReply().getTime(), true)); - info.setArguments(args); - info.show(fm, "fragment_forum"); - - } - }); - } else { - viewHolder.image.setVisibility(View.GONE); - } - } catch (Exception e) { - Crashlytics.log(Log.ERROR, "MALX", "ForumActivity.ListViewAdapter(): " + e.getMessage()); - Crashlytics.logException(e); - } - return view; - } - - public void supportAddAll(Collection collection) { - if (task == ForumJob.BOARD) - listview.getLayoutParams().height = (int) (((48 + 1) * collection.size() - 1) * (context.getResources().getDisplayMetrics().densityDpi / 160f)); - for (T record : collection) { - this.add(record); - } - } - - static class ViewHolder { - TextView title; - ImageView image; - } -} \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/adapters/FriendsGridviewAdapter.java b/Atarashii/src/net/somethingdreadful/MAL/adapters/FriendsGridviewAdapter.java index 508e00bf..935d48bb 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/adapters/FriendsGridviewAdapter.java +++ b/Atarashii/src/net/somethingdreadful/MAL/adapters/FriendsGridviewAdapter.java @@ -26,7 +26,7 @@ import java.util.Collection; public class FriendsGridviewAdapter extends ArrayAdapter { - private Context context; + private final Context context; private ArrayList list; public FriendsGridviewAdapter(Context context, ArrayList list) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/adapters/IGFPagerAdapter.java b/Atarashii/src/net/somethingdreadful/MAL/adapters/IGFPagerAdapter.java index aa1ef068..27205c8d 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/adapters/IGFPagerAdapter.java +++ b/Atarashii/src/net/somethingdreadful/MAL/adapters/IGFPagerAdapter.java @@ -9,8 +9,8 @@ import net.somethingdreadful.MAL.api.MALApi; public class IGFPagerAdapter extends FragmentPagerAdapter { - FragmentManager fm; - boolean popup = true; + private final FragmentManager fm; + private boolean popup = true; /** * Init page adapter @@ -46,7 +46,7 @@ public CharSequence getPageTitle(int position) { return MALApi.getListTypeString(getTag(position)).toUpperCase(); } - public MALApi.ListType getTag(int position) { + private MALApi.ListType getTag(int position) { switch (position) { case 0: return MALApi.ListType.ANIME; diff --git a/Atarashii/src/net/somethingdreadful/MAL/adapters/NavigationDrawerAdapter.java b/Atarashii/src/net/somethingdreadful/MAL/adapters/NavigationDrawerAdapter.java deleted file mode 100644 index afd00051..00000000 --- a/Atarashii/src/net/somethingdreadful/MAL/adapters/NavigationDrawerAdapter.java +++ /dev/null @@ -1,65 +0,0 @@ -package net.somethingdreadful.MAL.adapters; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.TextView; - -import net.somethingdreadful.MAL.Home; -import net.somethingdreadful.MAL.NavigationItems; -import net.somethingdreadful.MAL.R; -import net.somethingdreadful.MAL.Theme; - -import java.util.ArrayList; - -public class NavigationDrawerAdapter extends ArrayAdapter { - private ArrayList items; - private Home home; - - public NavigationDrawerAdapter(Home home, ArrayList items) { - super(home, R.layout.record_home_navigation, items); - this.items = items; - this.home = home; - } - - public View getView(int position, View v, ViewGroup parent) { - ViewHolder viewHolder; - - if (v == null) { - LayoutInflater vi = home.getLayoutInflater(); - v = vi.inflate(R.layout.record_home_navigation, parent, false); - - viewHolder = new ViewHolder(); - viewHolder.mIcon = (ImageView) v.findViewById(R.id.nav_item_icon); - viewHolder.mTitle = (TextView) v.findViewById(R.id.nav_item_text); - - if (Theme.darkTheme) { - viewHolder.mTitle.setTextColor(home.getResources().getColor(R.color.text_dark)); - Theme.setBackground(home, v); - } - - v.setTag(viewHolder); - } else { - viewHolder = (ViewHolder) v.getTag(); - } - - NavigationItems.NavItem item = items.get(position); - if (item != null) { - if (viewHolder.mIcon != null) { - viewHolder.mIcon.setImageResource(item.icon); - } - if (viewHolder.mTitle != null) { - viewHolder.mTitle.setText(item.title); - } - } - - return v; - } - - static class ViewHolder { - ImageView mIcon; - TextView mTitle; - } -} \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/adapters/ProfilePagerAdapter.java b/Atarashii/src/net/somethingdreadful/MAL/adapters/ProfilePagerAdapter.java index 2b18afe6..08600005 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/adapters/ProfilePagerAdapter.java +++ b/Atarashii/src/net/somethingdreadful/MAL/adapters/ProfilePagerAdapter.java @@ -13,7 +13,7 @@ import net.somethingdreadful.MAL.profile.ProfileHistory; public class ProfilePagerAdapter extends FragmentPagerAdapter { - ProfileActivity activity; + private final ProfileActivity activity; public ProfilePagerAdapter(FragmentManager fm, ProfileActivity activity) { super(fm); diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/ALApi.java b/Atarashii/src/net/somethingdreadful/MAL/api/ALApi.java index a6269539..02225c88 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/ALApi.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/ALApi.java @@ -30,14 +30,14 @@ import retrofit.converter.GsonConverter; public class ALApi { - private static String anilistURL = "http://anilist.co/api"; + private static final String anilistURL = "http://anilist.co/api"; private static String accesToken; //It's not best practice to use internals, but there is no other good way to get the OkHttp default UA private static final String okUa = com.squareup.okhttp.internal.Version.userAgent(); private static final String USER_AGENT = "Atarashii! (Linux; Android " + Build.VERSION.RELEASE + "; " + Build.MODEL + " Build/" + Build.DISPLAY + ") " + okUa; - ALInterface service; + private ALInterface service; public ALApi() { setupRESTService(); diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/ALInterface.java b/Atarashii/src/net/somethingdreadful/MAL/api/ALInterface.java index 8d8f3ac4..cfb2a45d 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/ALInterface.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/ALInterface.java @@ -23,7 +23,7 @@ import retrofit.http.Path; import retrofit.http.Query; -public interface ALInterface { +interface ALInterface { @FormUrlEncoded @POST("/auth/access_token") OAuth getAuthCode(@Field("grant_type") String grant_type, @Field("client_id") String client_id, @Field("client_secret") String client_secret, diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/AnimeManga/GenericRecord.java b/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/AnimeManga/GenericRecord.java index f429abb5..73cc7d1f 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/AnimeManga/GenericRecord.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/AnimeManga/GenericRecord.java @@ -173,7 +173,7 @@ public class GenericRecord implements Serializable { @Setter private ArrayList genres; - public net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord createGeneralBaseModel(net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord model) { + net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord createGeneralBaseModel(net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord model) { model.setId(getId()); model.setTitle(getTitleRomaji()); model.setTitleEnglish(createTitleArray(getTitleEnglish())); @@ -192,7 +192,7 @@ public net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord createG return model; } - public ArrayList createTitleArray(String title) { + private ArrayList createTitleArray(String title) { ArrayList titleArray = new ArrayList<>(); titleArray.add(title); return titleArray; diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/AnimeManga/Reviews.java b/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/AnimeManga/Reviews.java index d0da478e..c36d5b89 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/AnimeManga/Reviews.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/AnimeManga/Reviews.java @@ -47,7 +47,7 @@ public class Reviews implements Serializable { @Getter private Manga manga; - public net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews createBaseModel() { + private net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews createBaseModel() { net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews model = new net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews(); model.setId(getId()); model.setRating(getUserRating()); diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/Follow.java b/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/Follow.java index 0caea306..fe0c5206 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/Follow.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/Follow.java @@ -27,7 +27,7 @@ public class Follow implements Serializable { @SerializedName("image_url_med") private String imageUrlMed; - public Profile createBaseModel() { + private Profile createBaseModel() { net.somethingdreadful.MAL.api.BaseModels.Profile model = new net.somethingdreadful.MAL.api.BaseModels.Profile(); model.setUsername(getDisplayName()); model.setImageUrl(getImageUrlLge()); diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/History.java b/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/History.java index 0d330bdc..e46da0d9 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/History.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/ALModels/History.java @@ -109,7 +109,7 @@ private class Series { private String type; } - public net.somethingdreadful.MAL.api.BaseModels.History createBaseModel(String username) { + private net.somethingdreadful.MAL.api.BaseModels.History createBaseModel(String username) { net.somethingdreadful.MAL.api.BaseModels.History model = new net.somethingdreadful.MAL.api.BaseModels.History(); if (getSeries() != null && getSeries().getSeriesType() != null) { if (getSeries().getSeriesType().equals("anime")) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Anime.java b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Anime.java index aee7ce37..41c284b8 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Anime.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Anime.java @@ -4,6 +4,7 @@ import android.text.TextUtils; import net.somethingdreadful.MAL.MALManager; +import net.somethingdreadful.MAL.PrefManager; import net.somethingdreadful.MAL.api.MALApi; import net.somethingdreadful.MAL.api.MALModels.RecordStub; @@ -345,18 +346,18 @@ public void setRewatchValue(int rewatchValue) { this.rewatchValue = rewatchValue; } - public void checkProgress() { + private void checkProgress() { boolean completed = false; + boolean started = false; - // Automatically set the max episode on completed - if (getWatchedStatus().equals(GenericRecord.STATUS_COMPLETED) && getEpisodes() > 0) { - setWatchedEpisodes(getEpisodes()); - completed = true; + // Automatically set the status on completed + if (getEpisodes() > 0 && getWatchedEpisodes() == getEpisodes() && !getDirty().contains("watchedStatus")) { + setWatchedStatus(GenericRecord.STATUS_COMPLETED); } - // Automatically set the progress when the max episode has reached - if (getWatchedEpisodes() == getEpisodes() && getEpisodes() > 0) { - setWatchedStatus(GenericRecord.STATUS_COMPLETED); + // Automatically set the max episode on completed + if (getEpisodes() > 0 && getWatchedStatus().equals(GenericRecord.STATUS_COMPLETED) && !getDirty().contains("watchedEpisodes")) { + setWatchedEpisodes(getEpisodes()); completed = true; } @@ -368,7 +369,7 @@ public void checkProgress() { } // Automatically set the end date on completed if it is empty - if (getWatchingEnd() == null || getWatchingEnd().equals("")) { + if ((getWatchingEnd() == null || getWatchingEnd().equals("") || getWatchingEnd().equals("0-00-00")) && PrefManager.getAutoDateSetter()) { final Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); @@ -377,20 +378,23 @@ public void checkProgress() { } } + if (getWatchedStatus().equals(GenericRecord.STATUS_WATCHING) && getWatchedEpisodes() == 0 && !getDirty().contains("watchedEpisodes")) { + started = true; + } + // Automatically set the progress when the episode 1 has been watched - if (getWatchedStatus().equals(GenericRecord.STATUS_PLANTOWATCH) && getWatchedEpisodes() == 1) { + if (getWatchedStatus().equals(GenericRecord.STATUS_PLANTOWATCH) && getWatchedEpisodes() == 1 && !getDirty().contains("watchedStatus")) { setWatchedStatus(GenericRecord.STATUS_WATCHING); + started = true; } // Automatically set the start date on start if it is empty - if (getWatchedStatus().equals(GenericRecord.STATUS_WATCHING) && getWatchedEpisodes() == 1) { - if (getWatchingStart() == null || getWatchingStart().equals("")) { - final Calendar c = Calendar.getInstance(); - int year = c.get(Calendar.YEAR); - int month = c.get(Calendar.MONTH); - int day = c.get(Calendar.DAY_OF_MONTH); - setWatchingStart(year + "-" + month + "-" + day); - } + if ((getWatchingStart() == null || getWatchingStart().equals("") || getWatchingStart().equals("0-00-00")) && PrefManager.getAutoDateSetter() && started) { + final Calendar c = Calendar.getInstance(); + int year = c.get(Calendar.YEAR); + int month = c.get(Calendar.MONTH); + int day = c.get(Calendar.DAY_OF_MONTH); + setWatchingStart(year + "-" + month + "-" + day); } } @@ -455,7 +459,7 @@ public boolean getRewatching() { return rewatching; } - public void setRewatching(int cv) { + private void setRewatching(int cv) { rewatching = cv == 1; } diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Forum.java b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Forum.java similarity index 81% rename from Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Forum.java rename to Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Forum.java index 74ac7b48..a75eac85 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Forum.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Forum.java @@ -1,4 +1,6 @@ -package net.somethingdreadful.MAL.api.MALModels; +package net.somethingdreadful.MAL.api.BaseModels.AnimeManga; + +import net.somethingdreadful.MAL.api.MALModels.Profile; import java.io.Serializable; import java.util.ArrayList; @@ -7,6 +9,7 @@ import lombok.Setter; public class Forum implements Serializable { + /** * The ID used to get topic/board */ @@ -70,6 +73,15 @@ public class Forum implements Serializable { @Getter private String time; + /** + * The max amount of pages + * + * Note: Only the first item will contain this + */ + @Setter + @Getter + private int maxPages; + /** * The userprofile for the user details in topics */ diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/GenericRecord.java b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/GenericRecord.java index 83edc24a..e92c137f 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/GenericRecord.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/GenericRecord.java @@ -35,13 +35,13 @@ public class GenericRecord implements Serializable { public static final String STATUS_REREADING = "rereading"; public static final String STATUS_PLANTOREAD = "plan to read"; - String[] genresList = {"Action", "Adventure", "Cars", "Comedy", "Dementia", "Demons", "Drama", + private final String[] genresList = {"Action", "Adventure", "Cars", "Comedy", "Dementia", "Demons", "Drama", "Ecchi", "Fantasy", "Game", "Harem", "Hentai", "Historical", "Horror", "Josei", "Kids", "Magic", "Martial Arts", "Mecha", "Military", "Music", "Mystery", "Parody", "Police", "Psychological", "Romance", "Samurai", "School", "Sci-Fi", "Seinen", "Shoujo", "Shoujo Ai", "Shounen", "Shounen Ai", "Slice of Life", "Space", "Sports", "Super Power", "Supernatural", "Thriller", "Vampire", "Yaoi", "Yuri"}; - String[] statusList = {"completed", "on-hold", "dropped", "watching", "plan to watch", "reading", "plan to read"}; + private final String[] statusList = {"completed", "on-hold", "dropped", "watching", "plan to watch", "reading", "plan to read"}; /** * The ID of the record @@ -312,15 +312,15 @@ private void setCreateFlag(int createFlag) { this.createFlag = createFlag == 1; } - public void setDeleteFlag(boolean deleteFlag) { - this.deleteFlag = deleteFlag; + public void setDeleteFlag() { + this.deleteFlag = true; } - public void setCreateFlag(boolean createFlag) { - this.createFlag = createFlag; + public void setCreateFlag() { + this.createFlag = true; } - public void addDirtyField(String field) { + void addDirtyField(String field) { if (dirty == null) dirty = new ArrayList<>(); if (!dirty.contains((field))) @@ -332,7 +332,7 @@ public void clearDirty() { } public ArrayList getGenresInt() { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); if (getGenres() != null) for (String genre : getGenres()) result.add(Arrays.asList(genresList).indexOf(genre)); @@ -372,7 +372,7 @@ private Field getField(Class c, String property) { } } - protected Object getPropertyValue(String property) { + private Object getPropertyValue(String property) { try { Field field = getField(this.getClass(), property); if (field != null) { @@ -405,7 +405,7 @@ public String getArrayPropertyValue(String property) { return (String) value; } - public int getUserStatusInt(String statusString) { + int getUserStatusInt(String statusString) { return Arrays.asList(statusList).indexOf(statusString); } @@ -417,7 +417,7 @@ public void setPersonalTags(ArrayList tags) { this.tags = tags; } - public static GenericRecord fromCursor(GenericRecord result, Cursor cursor, List columnNames) { + static GenericRecord fromCursor(GenericRecord result, Cursor cursor, List columnNames) { GenericRecord.setFromCursor(true); result.setId(cursor.getInt(columnNames.indexOf(DatabaseTest.COLUMN_ID))); result.setTitle(cursor.getString(columnNames.indexOf("title"))); diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Manga.java b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Manga.java index c77406a0..b64f036b 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Manga.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/AnimeManga/Manga.java @@ -194,7 +194,7 @@ public void setRereadValue(int rereadValue) { this.rereadValue = rereadValue; } - public void checkProgress() { + private void checkProgress() { boolean completed = false; boolean started = false; diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/Profile.java b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/Profile.java index 606dd823..6c7f3b28 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/Profile.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/BaseModels/Profile.java @@ -18,8 +18,8 @@ public class Profile implements Serializable { /** * List of developers. */ - static String[] developersMAL = {"ratan12", "motoko"}; - static String[] developersAL = {"ratan12", "motokoaoyama"}; + private static final String[] developersMAL = {"ratan12", "motoko"}; + private static final String[] developersAL = {"ratan12", "motokoaoyama"}; /** * The username of the requested profile. diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/MALApi.java b/Atarashii/src/net/somethingdreadful/MAL/api/MALApi.java index 54e9ca93..e4bbda1b 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/MALApi.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/MALApi.java @@ -288,8 +288,8 @@ public ForumMain getForum() { return service.getForum(); } - public ForumMain getTopics(int id, int page) { - return service.getTopics(id, page); + public ForumMain getCategoryTopics(int id, int page) { + return service.getCategoryTopics(id, page); } public ForumMain getAnime(int id, int page) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/MALInterface.java b/Atarashii/src/net/somethingdreadful/MAL/api/MALInterface.java index 692246d2..86e24f62 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/MALInterface.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/MALInterface.java @@ -22,7 +22,7 @@ import retrofit.http.Path; import retrofit.http.Query; -public interface MALInterface { +interface MALInterface { @GET("/account/verify_credentials") Response verifyAuthentication(); @@ -102,7 +102,7 @@ Response addManga(@Field("manga_id") int id, @Field("status") String status, @Fi ForumMain getForum(); @GET("/forum/{id}") - ForumMain getTopics(@Path("id") int id, @Query("page") int page); + ForumMain getCategoryTopics(@Path("id") int id, @Query("page") int page); @GET("/forum/anime/{id}") ForumMain getAnime(@Path("id") int id, @Query("page") int page); diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/AnimeManga/GenericRecord.java b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/AnimeManga/GenericRecord.java index 989938ce..e0071bd2 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/AnimeManga/GenericRecord.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/AnimeManga/GenericRecord.java @@ -158,7 +158,7 @@ public class GenericRecord implements Serializable { @SerializedName("personal_comments") private String personalComments; - public net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord createGeneralBaseModel(net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord model) { + net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord createGeneralBaseModel(net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord model) { model.setId(getId()); model.setTitle(getTitle()); // MAL is using default romaji model.setTitleEnglish(getOtherTitles().get("english")); @@ -183,13 +183,13 @@ public net.somethingdreadful.MAL.api.BaseModels.AnimeManga.GenericRecord createG return model; } - public ArrayList getTitleArray() { + private ArrayList getTitleArray() { ArrayList title = new ArrayList<>(); title.add(getTitle()); return title; } - public String getImageUrl() { + private String getImageUrl() { if (imageUrl != null) return imageUrl.replace("t.jpg", "l.jpg"); else diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/AnimeManga/Reviews.java b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/AnimeManga/Reviews.java index f0a0efb1..17ac72d6 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/AnimeManga/Reviews.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/AnimeManga/Reviews.java @@ -93,7 +93,7 @@ public class Reviews implements Serializable { @Getter private String review; - public net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews createBaseModel() { + private net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews createBaseModel() { net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews model = new net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews(); model.setDate(getDate()); model.setRating(getRating()); diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/ForumMain.java b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/ForumMain.java index f4e1c470..849e3ff0 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/ForumMain.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/ForumMain.java @@ -2,6 +2,8 @@ import com.google.gson.annotations.SerializedName; +import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Forum; + import java.io.Serializable; import java.util.ArrayList; @@ -35,10 +37,30 @@ public class ForumMain implements Serializable { /** * A general list for multi use. */ - @Setter @Getter private ArrayList list; + @Setter + @Getter + private ArrayList list; /** * Amount of pages. */ - @Setter @Getter private int pages; + @Setter + @Getter + private int pages; + + + public ArrayList createBaseModel() { + ArrayList model = new ArrayList<>(); + if (getMyAnimeList() != null) + model.addAll(getMyAnimeList()); + if (getAnimeManga() != null) + model.addAll(getAnimeManga()); + if (getGeneral() != null) + model.addAll(getGeneral()); + if (getList() != null) { + model.addAll(getList()); + model.get(0).setMaxPages(getPages()); + } + return model; + } } diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Friend.java b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Friend.java index a4a7928c..e731bce9 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Friend.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Friend.java @@ -34,7 +34,7 @@ public class Friend implements Serializable { @Setter private Profile profile; - public net.somethingdreadful.MAL.api.BaseModels.Profile createBaseModel() { + private net.somethingdreadful.MAL.api.BaseModels.Profile createBaseModel() { net.somethingdreadful.MAL.api.BaseModels.Profile model = new net.somethingdreadful.MAL.api.BaseModels.Profile(); model.setUsername(getName()); model.setImageUrl(getProfile().getAvatarUrl()); diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/History.java b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/History.java index 4c4cc395..cc079f1f 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/History.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/History.java @@ -82,7 +82,7 @@ class Series { private String timeUpdated; } - public net.somethingdreadful.MAL.api.BaseModels.History createBaseModel(String username) { + private net.somethingdreadful.MAL.api.BaseModels.History createBaseModel(String username) { net.somethingdreadful.MAL.api.BaseModels.History model = new net.somethingdreadful.MAL.api.BaseModels.History(); if (type.equals("anime")) { model.setAnime(new Anime()); diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Profile.java b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Profile.java index 64f834ac..e3753966 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Profile.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/MALModels/Profile.java @@ -42,6 +42,23 @@ public class Profile implements Serializable { @SerializedName("manga_stats") private MangaStats mangaStats; + public String getSpecialAccesRank(String username) { + String rank = getDetails().getAccessRank(); + if (rank.contains("IRC")) + return "IRC"; + else if (rank.contains("News")) + return "News Team"; + else if (rank.contains("Social")) + return "SMT"; + else if (rank.contains("Mod")) + return "Mod"; + else if (rank.contains("Admin")) + return "Admin"; + else if (net.somethingdreadful.MAL.api.BaseModels.Profile.isDeveloper(username)) + return "Atarashii dev"; + return ""; + } + public static class Details implements Serializable { /** * The date of when the user was last online. diff --git a/Atarashii/src/net/somethingdreadful/MAL/api/UserAgentInterceptor.java b/Atarashii/src/net/somethingdreadful/MAL/api/UserAgentInterceptor.java index 723277ca..2e6ffd85 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/api/UserAgentInterceptor.java +++ b/Atarashii/src/net/somethingdreadful/MAL/api/UserAgentInterceptor.java @@ -6,7 +6,7 @@ import java.io.IOException; -public class UserAgentInterceptor implements Interceptor { +class UserAgentInterceptor implements Interceptor { private final String userAgent; diff --git a/Atarashii/src/net/somethingdreadful/MAL/broadcasts/AutoSync.java b/Atarashii/src/net/somethingdreadful/MAL/broadcasts/AutoSync.java index f145b939..117695a4 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/broadcasts/AutoSync.java +++ b/Atarashii/src/net/somethingdreadful/MAL/broadcasts/AutoSync.java @@ -25,7 +25,7 @@ import java.util.ArrayList; public class AutoSync extends BroadcastReceiver implements APIAuthenticationErrorListener, NetworkTask.NetworkTaskListener { - static NotificationManager nm; + private static NotificationManager nm; @Override public void onReceive(Context context, Intent intent) { @@ -39,7 +39,7 @@ public void onReceive(Context context, Intent intent) { Intent notificationIntent = new Intent(context, Home.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 1, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); if (networkChange(intent) && !PrefManager.getAutosyncDone() || !networkChange(intent)) { - ArrayList args = new ArrayList(); + ArrayList args = new ArrayList<>(); args.add(AccountService.getUsername()); args.add(""); new NetworkTask(TaskJob.FORCESYNC, MALApi.ListType.ANIME, context, this, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args.toArray(new String[args.size()])); @@ -84,7 +84,7 @@ public void onNetworkTaskError(TaskJob job, MALApi.ListType type, Bundle data, b PrefManager.setAutosyncDone(false); } - public boolean networkChange(Intent intent) { + private boolean networkChange(Intent intent) { return intent != null && intent.getAction() != null && intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION); } } \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/broadcasts/RecordStatusUpdatedReceiver.java b/Atarashii/src/net/somethingdreadful/MAL/broadcasts/RecordStatusUpdatedReceiver.java index 39d96cf7..807112fa 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/broadcasts/RecordStatusUpdatedReceiver.java +++ b/Atarashii/src/net/somethingdreadful/MAL/broadcasts/RecordStatusUpdatedReceiver.java @@ -8,7 +8,7 @@ public class RecordStatusUpdatedReceiver extends BroadcastReceiver { public static final String RECV_IDENT = "net.somethingdreadful.MAL.broadcasts.RecordStatusUpdatedReceiver"; - private RecordStatusUpdatedListener callback; + private final RecordStatusUpdatedListener callback; public RecordStatusUpdatedReceiver(RecordStatusUpdatedListener callback) { this.callback = callback; @@ -25,6 +25,6 @@ public void onReceive(Context context, Intent intent) { } public interface RecordStatusUpdatedListener { - public void onRecordStatusUpdated(MALApi.ListType type); + void onRecordStatusUpdated(MALApi.ListType type); } } diff --git a/Atarashii/src/net/somethingdreadful/MAL/database/DatabaseManager.java b/Atarashii/src/net/somethingdreadful/MAL/database/DatabaseManager.java index ee3611ee..872936c2 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/database/DatabaseManager.java +++ b/Atarashii/src/net/somethingdreadful/MAL/database/DatabaseManager.java @@ -19,7 +19,7 @@ import java.util.ArrayList; public class DatabaseManager { - SQLiteDatabase db; + private final SQLiteDatabase db; public DatabaseManager(Context context) { this.db = DatabaseTest.getInstance(context).getWritableDatabase(); @@ -89,7 +89,7 @@ public void saveAnimeList(ArrayList result) { * * @param anime The Anime model */ - public void saveAnimeList(Anime anime) { + private void saveAnimeList(Anime anime) { ContentValues cv = new ContentValues(); cv.put(DatabaseTest.COLUMN_ID, anime.getId()); cv.put("title", anime.getTitle()); @@ -161,7 +161,7 @@ public void saveMangaList(ArrayList result) { * * @param manga The Anime model */ - public void saveMangaList(Manga manga) { + private void saveMangaList(Manga manga) { ContentValues cv = new ContentValues(); cv.put(DatabaseTest.COLUMN_ID, manga.getId()); cv.put("title", manga.getTitle()); @@ -501,14 +501,13 @@ public boolean addWidgetRecord(int id, MALApi.ListType type) { return true; } - public boolean updateWidgetRecord(int oldId, MALApi.ListType oldType, int id, MALApi.ListType type) { + public boolean updateWidgetRecord(int oldId, int id, MALApi.ListType type) { if (checkWidgetID(id, type)) return false; // Remove old record ContentValues cv = new ContentValues(); cv.putNull("widget"); - boolean anime = oldType.equals(MALApi.ListType.ANIME); try { db.beginTransaction(); diff --git a/Atarashii/src/net/somethingdreadful/MAL/database/DatabaseTest.java b/Atarashii/src/net/somethingdreadful/MAL/database/DatabaseTest.java index 24987c69..8f193fb0 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/database/DatabaseTest.java +++ b/Atarashii/src/net/somethingdreadful/MAL/database/DatabaseTest.java @@ -8,8 +8,8 @@ import com.crashlytics.android.Crashlytics; public class DatabaseTest extends SQLiteOpenHelper { - public static final String NAME = "MAL.db"; - public static final int VERSION = 13; + private static final String NAME = "MAL.db"; + private static final int VERSION = 13; private static DatabaseTest instance; public static final String TABLE_ANIME = "anime"; diff --git a/Atarashii/src/net/somethingdreadful/MAL/database/Query.java b/Atarashii/src/net/somethingdreadful/MAL/database/Query.java index 06f1fc87..1f72e75f 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/database/Query.java +++ b/Atarashii/src/net/somethingdreadful/MAL/database/Query.java @@ -13,7 +13,7 @@ import java.util.List; public class Query { - String queryString = ""; + private String queryString = ""; private static SQLiteDatabase db; public static Query newQuery(SQLiteDatabase db) { @@ -26,7 +26,7 @@ public Query selectFrom(String column, String table) { return this; } - public Query innerJoinOn(String table1, String column1, String column2) { + private Query innerJoinOn(String table1, String column1, String column2) { queryString += " INNER JOIN " + table1 + " ON " + column1 + " = " + column2; return this; } @@ -78,7 +78,6 @@ public Cursor run() { /** * Update or insert records. - * * @param table The table where the record should be updated * @param cv The ContentValues which should be updated * @param id The ID of the record @@ -92,7 +91,6 @@ public int updateRecord(String table, ContentValues cv, int id) { /** * Update or insert records. - * * @param table The table where the record should be updated * @param cv The ContentValues which should be updated * @param username The username of the record @@ -251,7 +249,8 @@ private void updateTitles(int id, String table, int titleType, ArrayList * @param id The anime or manga ID * @param anime True if the record is an anime * @param titleType The title type - * @return + * + * @return ArrayList with titles */ public ArrayList getTitles(int id, boolean anime, int titleType) { ArrayList result = new ArrayList<>(); @@ -364,7 +363,8 @@ public ArrayList getRelation(Integer Id, String relationTable, Strin * @param table The table which is separated in anime or manga records * @param column The column name of the id's * @param anime If the record is an anime. - * @return + * + * @return The requested arraylist */ public ArrayList getArrayList(int id, String relTable, String table, String column, boolean anime) { ArrayList result = new ArrayList<>(); diff --git a/Atarashii/src/net/somethingdreadful/MAL/database/Table.java b/Atarashii/src/net/somethingdreadful/MAL/database/Table.java index 65c20a68..333a63be 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/database/Table.java +++ b/Atarashii/src/net/somethingdreadful/MAL/database/Table.java @@ -6,7 +6,7 @@ import com.crashlytics.android.Crashlytics; public class Table { - String queryString = ""; + private String queryString = ""; private static SQLiteDatabase db; public static Table create(SQLiteDatabase db) { @@ -181,7 +181,7 @@ public void createRelation(String table, String refTable1, String refTable2) { run(); } - public void run() { + private void run() { try { db.execSQL(queryString); } catch (Exception e) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewDetails.java b/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewDetails.java index 891e3b68..a5a4eb0f 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewDetails.java +++ b/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewDetails.java @@ -1,5 +1,6 @@ package net.somethingdreadful.MAL.detailView; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.Fragment; import android.content.Intent; @@ -28,43 +29,65 @@ import butterknife.ButterKnife; public class DetailViewDetails extends Fragment implements Serializable, ExpandableListView.OnChildClickListener { - View view; - Card cardSynopsis; - Card cardMediainfo; - Card cardMediaStats; - Card cardRelations; - Card cardTitles; - Card cardNetwork; - DetailView activity; - ExpandableListView relations; - ExpandableListView titles; - DetailViewRelationsAdapter relation; - DetailViewRelationsAdapter title; - - @Bind(R.id.swiperefresh) public SwipeRefreshLayout swipeRefresh; - - @Bind(R.id.SynopsisContent) TextView synopsis; - @Bind(R.id.type) TextView type; - @Bind(R.id.episodes) TextView episodes; - @Bind(R.id.episodesLabel) TextView episodesLabel; - @Bind(R.id.volumes) TextView volumes; - @Bind(R.id.volumesLabel) TextView volumesLabel; - @Bind(R.id.status) TextView status; - @Bind(R.id.start) TextView start; - @Bind(R.id.startRow) TableRow startRow; - @Bind(R.id.end) TextView end; - @Bind(R.id.endRow) TableRow endRow; - @Bind(R.id.classification) TextView classification; - @Bind(R.id.classificationLabel) TextView classificationLabel; - @Bind(R.id.genres) TextView genres; - @Bind(R.id.producers) TextView producers; - @Bind(R.id.producersRow) TableRow producersRow; - - @Bind(R.id.score) TextView score; - @Bind(R.id.ranked) TextView ranked; - @Bind(R.id.popularity) TextView popularity; - @Bind(R.id.members) TextView members; - @Bind(R.id.favorites) TextView favorites; + private View view; + private Card cardSynopsis; + private Card cardMediainfo; + private Card cardMediaStats; + private Card cardRelations; + private Card cardTitles; + private Card cardNetwork; + private DetailView activity; + private ExpandableListView relations; + private ExpandableListView titles; + private DetailViewRelationsAdapter relation; + private DetailViewRelationsAdapter title; + + @Bind(R.id.swiperefresh) + public SwipeRefreshLayout swipeRefresh; + + @Bind(R.id.SynopsisContent) + TextView synopsis; + @Bind(R.id.type) + TextView type; + @Bind(R.id.episodes) + TextView episodes; + @Bind(R.id.episodesLabel) + TextView episodesLabel; + @Bind(R.id.volumes) + TextView volumes; + @Bind(R.id.volumesLabel) + TextView volumesLabel; + @Bind(R.id.status) + TextView status; + @Bind(R.id.start) + TextView start; + @Bind(R.id.startRow) + TableRow startRow; + @Bind(R.id.end) + TextView end; + @Bind(R.id.endRow) + TableRow endRow; + @Bind(R.id.classification) + TextView classification; + @Bind(R.id.classificationLabel) + TextView classificationLabel; + @Bind(R.id.genres) + TextView genres; + @Bind(R.id.producers) + TextView producers; + @Bind(R.id.producersRow) + TableRow producersRow; + + @Bind(R.id.score) + TextView score; + @Bind(R.id.ranked) + TextView ranked; + @Bind(R.id.popularity) + TextView popularity; + @Bind(R.id.members) + TextView members; + @Bind(R.id.favorites) + TextView favorites; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -88,7 +111,7 @@ else if (!MALApi.isNetworkAvailable(activity)) /* * The scrollview bugs when you use viewflipper in it! */ - public void toggleView(Boolean show) { + private void toggleView(Boolean show) { if (show) { cardSynopsis.setVisibility(View.VISIBLE); cardMediainfo.setVisibility(View.VISIBLE); @@ -115,7 +138,7 @@ public void onAttach(Activity activity) { /** * Set all views once */ - public void setViews() { + private void setViews() { // set all the card views cardSynopsis = (Card) view.findViewById(R.id.synopsis); cardMediainfo = (Card) view.findViewById(R.id.mediainfo); @@ -155,6 +178,7 @@ public void setViews() { /** * Place all the text in the right textview */ + @SuppressLint("SetTextI18n") public void setText() { GenericRecord record = (activity.type.equals(MALApi.ListType.ANIME) ? activity.animeRecord : activity.mangaRecord); if (record.getSynopsis() == null) @@ -243,7 +267,7 @@ public boolean onChildClick(ExpandableListView parent, View v, int groupPos, int /** * Handle the click events (expand and collapse) */ - public void clickListeners() { + private void clickListeners() { titles.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { @Override public void onGroupExpand(int i) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewGeneral.java b/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewGeneral.java index 3a4b9392..0180ce57 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewGeneral.java +++ b/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewGeneral.java @@ -9,7 +9,6 @@ import android.text.method.LinkMovementMethod; import android.util.Log; import android.view.LayoutInflater; -import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -38,26 +37,35 @@ import butterknife.ButterKnife; public class DetailViewGeneral extends Fragment implements Serializable, Card.onCardClickListener { - View view; - Menu menu; - DetailView activity; + private View view; + private DetailView activity; public SwipeRefreshLayout swipeRefresh; - Card cardMain; - Card cardSynopsis; - Card cardMediainfo; - Card cardPersonal; - - @Bind(R.id.SynopsisContent) TextView synopsis; - @Bind(R.id.mediaType) TextView mediaType; - @Bind(R.id.mediaStatus) TextView mediaStatus; - @Bind(R.id.statusText) TextView status; - @Bind(R.id.progress1Text1) TextView progress1Total; - @Bind(R.id.progress1Text2) TextView progress1Current; - @Bind(R.id.progress2Text1) TextView progress2Total; - @Bind(R.id.progress2Text2) TextView progress2Current; - @Bind(R.id.myScore) TextView myScore; - @Bind(R.id.Image) ImageView image; + private Card cardMain; + private Card cardSynopsis; + private Card cardMediainfo; + private Card cardPersonal; + + @Bind(R.id.SynopsisContent) + TextView synopsis; + @Bind(R.id.mediaType) + TextView mediaType; + @Bind(R.id.mediaStatus) + TextView mediaStatus; + @Bind(R.id.statusText) + TextView status; + @Bind(R.id.progress1Text1) + TextView progress1Total; + @Bind(R.id.progress1Text2) + TextView progress1Current; + @Bind(R.id.progress2Text1) + TextView progress2Total; + @Bind(R.id.progress2Text2) + TextView progress2Current; + @Bind(R.id.myScore) + TextView myScore; + @Bind(R.id.Image) + ImageView image; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -75,7 +83,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa /* * Set all views once */ - public void setViews() { + private void setViews() { swipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swiperefresh); // set all the card views @@ -102,16 +110,16 @@ public void setViews() { /* * set all the ClickListeners */ - public void setListener() { + private void setListener() { swipeRefresh.setOnRefreshListener(activity); - swipeRefresh.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); + swipeRefresh.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeRefresh.setEnabled(true); } /* * Manage the progress card */ - public void setCard() { + private void setCard() { if (activity.type != null && activity.type.equals(ListType.ANIME)) { TextView progress1 = (TextView) view.findViewById(R.id.progress1Label); progress1.setText(getString(R.string.card_content_episodes)); @@ -120,22 +128,6 @@ public void setCard() { } } - /* - * set the right menu items. - */ - public void setMenu() { - if (menu != null) { - if (activity.isAdded()) { - menu.findItem(R.id.action_Remove).setVisible(true); - menu.findItem(R.id.action_addToList).setVisible(false); - } else { - menu.findItem(R.id.action_Remove).setVisible(false); - menu.findItem(R.id.action_addToList).setVisible(true); - } - menu.findItem(R.id.action_Remove).setVisible(MALApi.isNetworkAvailable(activity) && menu.findItem(R.id.action_Remove).isVisible()); - } - } - /* * Place all the text in the right textview */ @@ -143,7 +135,6 @@ public void setText() { if (activity.type == null || (activity.animeRecord == null && activity.mangaRecord == null)) // not enough data to do anything return; GenericRecord record; - setMenu(); if (activity.type.equals(ListType.ANIME)) { record = activity.animeRecord; diff --git a/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewPersonal.java b/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewPersonal.java index 6778ed2c..44ccbc2c 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewPersonal.java +++ b/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewPersonal.java @@ -32,31 +32,48 @@ public class DetailViewPersonal extends Fragment implements Serializable, View.OnClickListener { public SwipeRefreshLayout swipeRefresh; - DetailView activity; - View view; - Card cardBasic; - Card cardOther; - Card cardRewatch; - - @Bind(R.id.statusText) TextView status; - @Bind(R.id.progress1Text1) TextView progress1Total; - @Bind(R.id.progress1Text2) TextView progress1Current; - @Bind(R.id.progress2Text1) TextView progress2Total; - @Bind(R.id.progress2Text2) TextView progress2Current; - @Bind(R.id.myScore) TextView myScore; - @Bind(R.id.myStartDate) TextView myStartDate; - @Bind(R.id.myEndDate) TextView myEndDate; - @Bind(R.id.myPriority) TextView myPriority; - @Bind(R.id.myTags) TextView myTags; - @Bind(R.id.comments) TextView comments; - - @Bind(R.id.fansubs) TextView fansubs; - @Bind(R.id.storage) TextView storage; - @Bind(R.id.storage_amount) TextView storageCount; - @Bind(R.id.downloaded) TextView dowloaded; - - @Bind(R.id.priority) TextView priority; - @Bind(R.id.count2Text2) TextView rewatchCount2; + private DetailView activity; + private View view; + private Card cardBasic; + private Card cardOther; + private Card cardRewatch; + + @Bind(R.id.statusText) + TextView status; + @Bind(R.id.progress1Text1) + TextView progress1Total; + @Bind(R.id.progress1Text2) + TextView progress1Current; + @Bind(R.id.progress2Text1) + TextView progress2Total; + @Bind(R.id.progress2Text2) + TextView progress2Current; + @Bind(R.id.myScore) + TextView myScore; + @Bind(R.id.myStartDate) + TextView myStartDate; + @Bind(R.id.myEndDate) + TextView myEndDate; + @Bind(R.id.myPriority) + TextView myPriority; + @Bind(R.id.myTags) + TextView myTags; + @Bind(R.id.comments) + TextView comments; + + @Bind(R.id.fansubs) + TextView fansubs; + @Bind(R.id.storage) + TextView storage; + @Bind(R.id.storage_amount) + TextView storageCount; + @Bind(R.id.downloaded) + TextView dowloaded; + + @Bind(R.id.priority) + TextView priority; + @Bind(R.id.count2Text2) + TextView rewatchCount2; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -73,7 +90,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa return view; } - public void setCard() { + private void setCard() { if (activity.type != null && activity.type.equals(MALApi.ListType.ANIME)) { TextView progress1 = (TextView) view.findViewById(R.id.progress1Label); progress1.setText(getString(R.string.card_content_episodes)); @@ -82,7 +99,7 @@ public void setCard() { } } - public void setListener() { + private void setListener() { swipeRefresh.setOnRefreshListener(activity); swipeRefresh.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeRefresh.setEnabled(true); @@ -298,7 +315,7 @@ public void onClick(View v) { } } - public Bundle bundle(int id, int title) { + private Bundle bundle(int id, int title) { Bundle bundle = new Bundle(); bundle.putInt("id", id); bundle.putString("title", getString(title)); diff --git a/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewReviews.java b/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewReviews.java index 420c6b67..656b8d11 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewReviews.java +++ b/Atarashii/src/net/somethingdreadful/MAL/detailView/DetailViewReviews.java @@ -29,14 +29,15 @@ import butterknife.ButterKnife; public class DetailViewReviews extends Fragment implements NetworkTask.NetworkTaskListener { - View view; - HtmlUtil htmlUtil; + private View view; + private HtmlUtil htmlUtil; DetailView activity; public ArrayList record; @Bind(R.id.webview) WebView webview; - @Bind(R.id.viewFlipper) ViewFlipper viewFlipper; + @Bind(R.id.viewFlipper) + ViewFlipper viewFlipper; public int id; public int page = 0; @@ -109,7 +110,7 @@ public void onAttach(Activity activity) { * * @param result The new record */ - public void apply(ArrayList result) { + private void apply(ArrayList result) { try { // The activity could be destroyed when this is being loaded because the user pressed back if (activity != null && isAdded()) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/detailView/ReviewsInterface.java b/Atarashii/src/net/somethingdreadful/MAL/detailView/ReviewsInterface.java index d7ee9ff3..12f05073 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/detailView/ReviewsInterface.java +++ b/Atarashii/src/net/somethingdreadful/MAL/detailView/ReviewsInterface.java @@ -3,8 +3,8 @@ import android.content.Intent; import android.webkit.JavascriptInterface; -public class ReviewsInterface { - DetailViewReviews reviews; +class ReviewsInterface { + private final DetailViewReviews reviews; ReviewsInterface(DetailViewReviews reviews) { this.reviews = reviews; diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/DatePickerDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/DatePickerDialogFragment.java index 0b586788..719505a4 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/DatePickerDialogFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/DatePickerDialogFragment.java @@ -19,8 +19,8 @@ import java.util.Locale; public class DatePickerDialogFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { - Boolean startDate; - DatePickerDialog mDateDialog; + private Boolean startDate; + private DatePickerDialog mDateDialog; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/ForumChildDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/ForumChildDialogFragment.java deleted file mode 100644 index d4825aae..00000000 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/ForumChildDialogFragment.java +++ /dev/null @@ -1,64 +0,0 @@ -package net.somethingdreadful.MAL.dialog; - -import android.app.AlertDialog; -import android.app.DialogFragment; -import android.content.DialogInterface; -import android.os.Bundle; - -import net.somethingdreadful.MAL.ForumActivity; -import net.somethingdreadful.MAL.api.MALModels.Forum; - -import java.util.ArrayList; - -public class ForumChildDialogFragment extends DialogFragment { - ArrayList child; - String message; - public static boolean DBModificationRequest; - - @Override - public AlertDialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - message = getArguments().getString("message"); - child = (ArrayList) getArguments().getSerializable("child"); - - if (child.size() == 2) { - message = message.replace("$child1;", child.get(0).getName()); - message = message.replace("$child2;", child.get(1).getName()); - } else { - message = message.replace("$child1;", child.get(0).getName() + ", " + child.get(1).getName()); - message = message.replace("$child2;", child.get(2).getName()); - } - - builder.setTitle(getArguments().getString("title")); - builder.setMessage(message); - - builder.setPositiveButton(child.get(0).getName(), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - DBModificationRequest = !(child.get(0).getId() == 1 || child.get(0).getId() == 4); - ((ForumActivity) getActivity()).getSubBoard(child.get(0).getId()); - dismiss(); - } - }); - builder.setNeutralButton(child.get(1).getName(), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - DBModificationRequest = !(child.get(1).getId() == 1 || child.get(1).getId() == 4); - ((ForumActivity) getActivity()).getSubBoard(child.get(1).getId()); - dismiss(); - } - }); - if (child.size() == 3) { - builder.setNegativeButton(child.get(2).getName(), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - DBModificationRequest = !(child.get(2).getId() == 1 || child.get(2).getId() == 4); - ((ForumActivity) getActivity()).getSubBoard(child.get(2).getId()); - dismiss(); - } - }); - } - - return builder.create(); - } -} \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/ListDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/ListDialogFragment.java index 58c40ca2..cbd0a581 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/ListDialogFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/ListDialogFragment.java @@ -46,7 +46,7 @@ public void onClick(DialogInterface dialog, int which) { * The interface for callback */ public interface onUpdateClickListener { - public void onUpdated(int number, int id); + void onUpdated(int number, int id); } /** diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/MangaPickerDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/MangaPickerDialogFragment.java index 2ad46def..59a23c9f 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/MangaPickerDialogFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/MangaPickerDialogFragment.java @@ -12,13 +12,13 @@ import net.somethingdreadful.MAL.R; public class MangaPickerDialogFragment extends DialogFragment { - NumberPicker chapterPicker; - NumberPicker volumePicker; - int chaptersTotal; - int chaptersRead; + private NumberPicker chapterPicker; + private NumberPicker volumePicker; + private int chaptersTotal; + private int chaptersRead; - int volumesTotal; - int volumesRead; + private int volumesTotal; + private int volumesRead; private View makeNumberPicker() { View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_manga_picker, null); diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/MessageDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/MessageDialogFragment.java index 54ee6d27..12ae7e77 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/MessageDialogFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/MessageDialogFragment.java @@ -1,5 +1,6 @@ package net.somethingdreadful.MAL.dialog; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; @@ -18,14 +19,14 @@ public class MessageDialogFragment extends DialogFragment implements View.OnClickListener, View.OnLongClickListener { - EditText subject; - EditText message; - TextView header; - ForumJob task; - int id; - View view; - onSendClickListener callback; - TextView send; + private EditText subject; + private EditText message; + private TextView header; + private ForumJob task; + private int id; + private View view; + private onSendClickListener callback; + private TextView send; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -39,7 +40,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { String title = getArguments().getString("title", null); id = getArguments().getInt("id"); - subject.setVisibility(task == ForumJob.ADDTOPIC ? View.VISIBLE : View.GONE); setHeader(title); setClickListener(); @@ -70,12 +70,6 @@ private void setHeader(String title) { header.setText(title); else switch (task) { - case UPDATECOMMENT: - header.setText(getString(R.string.dialog_title_edit_comment)); - break; - case ADDTOPIC: - header.setText(getString(R.string.dialog_title_add_topic)); - break; default: header.setText(getString(R.string.dialog_title_add_comment)); break; @@ -116,6 +110,7 @@ private View setView(View view) { * * @param BBCode The BBCode string that should be in the message field */ + @SuppressLint("SetTextI18n") private void insert(String BBCode) { int curPos = message.getSelectionStart(); String str = message.getText().toString(); @@ -195,8 +190,8 @@ public boolean onLongClick(View v) { * The interface for callback */ public interface onSendClickListener { - public void onSendClicked(String message, String subject, ForumJob task, int id); - public void onCloseClicked(String message); + void onSendClicked(String message, String subject, ForumJob task, int id); + void onCloseClicked(String message); } /** @@ -210,11 +205,6 @@ public MessageDialogFragment setOnSendClickListener(onSendClickListener callback return this; } - public MessageDialogFragment setListeners(onSendClickListener callback) { - setOnSendClickListener(callback); - return this; - } - /** * This will let the dialog remain on the sceen after an orientation. */ diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/NumberPickerDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/NumberPickerDialogFragment.java index 2c080a81..f66846c2 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/NumberPickerDialogFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/NumberPickerDialogFragment.java @@ -19,10 +19,10 @@ import net.somethingdreadful.MAL.account.AccountService; public class NumberPickerDialogFragment extends DialogFragment { - NumberPicker numberPicker; - EditText numberInput; + private NumberPicker numberPicker; + private EditText numberInput; private onUpdateClickListener callback; - boolean inputScore = false; + private boolean inputScore = false; private View makeNumberPicker() { View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_episode_picker, null); @@ -90,7 +90,7 @@ private boolean isRating() { * @param key The argument name * @return int The number of the argument */ - public int getValue(String key) { + private int getValue(String key) { try { if (getArguments().getInt("id") == R.id.scorePanel && PrefManager.getScoreType() != 3 && PrefManager.getScoreType() != 1) inputScore = true; @@ -116,6 +116,6 @@ public NumberPickerDialogFragment setOnSendClickListener(onUpdateClickListener c * The interface for callback */ public interface onUpdateClickListener { - public void onUpdated(int number, int id); + void onUpdated(int number, int id); } } \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/RecordPickerDialog.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/RecordPickerDialog.java index dc0e58e3..fade28cd 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/RecordPickerDialog.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/RecordPickerDialog.java @@ -7,7 +7,6 @@ import android.content.Intent; import android.os.Bundle; import android.support.v4.view.ViewPager; -import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; @@ -30,19 +29,16 @@ import butterknife.ButterKnife; public class RecordPickerDialog extends AppCompatActivity implements IGF.IGFCallbackListener, APIAuthenticationErrorListener, ViewPager.OnPageChangeListener { - IGF af; - IGF mf; - Menu menu; - Context context; - ActionBar actionBar; - IGFPagerAdapter mIGFPagerAdapter; + private IGF af; + private IGF mf; + private Menu menu; + private Context context; + private IGFPagerAdapter mIGFPagerAdapter; - @Bind(R.id.pager) ViewPager mViewPager; + @Bind(R.id.pager) + ViewPager mViewPager; - String username; - boolean callbackAnimeError = false; - boolean callbackMangaError = false; - int callbackCounter = 0; + private int callbackCounter = 0; private int widgetID; private int recordID; private MALApi.ListType type; @@ -53,16 +49,12 @@ public void onCreate(Bundle savedInstanceState) { setResult(RESULT_CANCELED); context = getApplicationContext(); if (AccountService.getAccount() != null) { - actionBar = getSupportActionBar(); - //The following is state handling code - setContentView(R.layout.activity_home); + // Creates the adapter to return the Animu and Mango fragments mIGFPagerAdapter = new IGFPagerAdapter(getFragmentManager(), false); ButterKnife.bind(this); - username = AccountService.getUsername(); - // Set up the ViewPager with the sections adapter. mViewPager.setAdapter(mIGFPagerAdapter); mViewPager.setPageMargin(32); @@ -140,14 +132,14 @@ public boolean onOptionsItemSelected(MenuItem item) { * On some devices the af & mf will change into null due inactivity. * This is a check to prevent any crashes and set it again. */ - public void checkIGF() { + private void checkIGF() { if (af == null || mf == null) { af = (IGF) mIGFPagerAdapter.getIGF(mViewPager, 0); mf = (IGF) mIGFPagerAdapter.getIGF(mViewPager, 1); } } - public void getRecords(boolean clear, TaskJob task, int list) { + private void getRecords(boolean clear, TaskJob task, int list) { checkIGF(); if (af != null && mf != null) { af.getRecords(clear, task, list); @@ -166,7 +158,7 @@ public void onPause() { super.onPause(); } - public void synctask(boolean clear) { + private void synctask(boolean clear) { getRecords(clear, TaskJob.FORCESYNC, af.list); } @@ -203,7 +195,7 @@ public boolean onPrepareOptionsMenu(Menu menu) { return true; } - public void setChecked(MenuItem item) { + private void setChecked(MenuItem item) { item.setChecked(true); } @@ -257,7 +249,7 @@ public void onItemClick(int id, MALApi.ListType listType, String username) { DatabaseManager db = new DatabaseManager(context); boolean succeeded; if (recordID != 0) - succeeded = db.updateWidgetRecord(recordID, type, id, listType); + succeeded = db.updateWidgetRecord(recordID, id, listType); else succeeded = db.addWidgetRecord(id, listType); diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/SearchIdDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/SearchIdDialogFragment.java index f06bd4d8..5156a904 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/SearchIdDialogFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/SearchIdDialogFragment.java @@ -14,7 +14,7 @@ public class SearchIdDialogFragment extends DialogFragment { - int query; + private int query; @Override public void onAttach(Activity activity) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/ShareDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/ShareDialogFragment.java index c73a11bb..4b738abd 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/ShareDialogFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/ShareDialogFragment.java @@ -12,8 +12,8 @@ import net.somethingdreadful.MAL.account.AccountService; public class ShareDialogFragment extends DialogFragment { - String title; - boolean share; + private String title; + private boolean share; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -71,7 +71,7 @@ public void onClick(DialogInterface dialog, int which) { return builder.create(); } - public String getWebsiteURL() { + private String getWebsiteURL() { return AccountService.isMAL() ? "http://myanimelist.net/" : "http://anilist.co/"; } } \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/StatusPickerDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/StatusPickerDialogFragment.java index 58515b27..b654e792 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/StatusPickerDialogFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/StatusPickerDialogFragment.java @@ -17,9 +17,9 @@ public class StatusPickerDialogFragment extends DialogFragment implements OnCheckedChangeListener { - RadioGroup radio; - ListType type; - String currentStatus; + private RadioGroup radio; + private ListType type; + private String currentStatus; @Override public AlertDialog onCreateDialog(Bundle savedInstanceState) { @@ -43,7 +43,7 @@ public void onClick(DialogInterface dialog, int whichButton) { return builder.create(); } - public View makeRatiobutton() { + private View makeRatiobutton() { View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_status_picker, null); radio = (RadioGroup) view.findViewById(R.id.statusRadioGroup); type = ((DetailView) getActivity()).type; diff --git a/Atarashii/src/net/somethingdreadful/MAL/dialog/UpdateImageDialogFragment.java b/Atarashii/src/net/somethingdreadful/MAL/dialog/UpdateImageDialogFragment.java index 755111bc..afea9f2b 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/dialog/UpdateImageDialogFragment.java +++ b/Atarashii/src/net/somethingdreadful/MAL/dialog/UpdateImageDialogFragment.java @@ -15,7 +15,7 @@ import net.somethingdreadful.MAL.R; public class UpdateImageDialogFragment extends DialogFragment { - EditText input; + private EditText input; private View createView() { View result = getActivity().getLayoutInflater().inflate(R.layout.dialog_update_nav_image, null); diff --git a/Atarashii/src/net/somethingdreadful/MAL/forum/ForumInterface.java b/Atarashii/src/net/somethingdreadful/MAL/forum/ForumInterface.java new file mode 100644 index 00000000..8cfe73ba --- /dev/null +++ b/Atarashii/src/net/somethingdreadful/MAL/forum/ForumInterface.java @@ -0,0 +1,332 @@ +package net.somethingdreadful.MAL.forum; + +import android.app.FragmentManager; +import android.content.Intent; +import android.os.AsyncTask; +import android.os.Bundle; +import android.webkit.JavascriptInterface; + +import net.somethingdreadful.MAL.ForumActivity; +import net.somethingdreadful.MAL.ProfileActivity; +import net.somethingdreadful.MAL.R; +import net.somethingdreadful.MAL.Theme; +import net.somethingdreadful.MAL.account.AccountService; +import net.somethingdreadful.MAL.dialog.ChooseDialogFragment; +import net.somethingdreadful.MAL.dialog.NumberPickerDialogFragment; +import net.somethingdreadful.MAL.tasks.ForumJob; +import net.somethingdreadful.MAL.tasks.ForumNetworkTask; + +public class ForumInterface { + private final ForumActivity forum; + + public ForumInterface(ForumActivity forum) { + this.forum = forum; + } + + /** + * convert HTML to BBCode + */ + @JavascriptInterface + public void convertHTML(final String username, final String messageID, String bbCode) { + if (bbCode.contains("src=\"http://youtube.com/embed/")) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + Theme.Snackbar(forum, R.string.toast_info_disabled_youtube); + } + }); + } else { + bbCode = convertMessageQuote(bbCode); + bbCode = convertUserQuote(bbCode); + bbCode = convertQuote(bbCode); + bbCode = convertQuoteSpoiler(bbCode); + bbCode = convertSpoiler(bbCode); + bbCode = bbCode.replace(" target=\"_blank", ""); //image trash + bbCode = bbCode.replaceAll("((.|\\n)+?)", "[b]$1[/b]"); //Bold text + bbCode = bbCode.replaceAll("((.|\\n)+?)", "[i]$1[/i]"); //Italics + bbCode = bbCode.replaceAll("((.|\\n)+?)", "[u]$1[/u]"); //Underlined text + bbCode = bbCode.replaceAll("
    ((.|\\n)+?)
", "[list]$1[/list]"); //list + bbCode = bbCode.replaceAll("
    ((.|\\n)+?)
", "[list=1]$1[/list]"); //list + bbCode = bbCode.replaceAll("
  • ((.|\\n)+?)
  • ", "[*]$1"); //list items + bbCode = bbCode.replaceAll("
    ((.|\\n)+?)
    ", "$1"); //unknown + bbCode = bbCode.replaceAll("\\[b]@(.+?)\\[/b](.+?)", "@$2"); //@ mention + bbCode = bbCode.replaceAll("((.|\\n)+?)", "[s]$1[/s]"); //Strike-thru text + bbCode = bbCode.replaceAll("((.|\\n)+?)", "[size=$1]$2[/size]"); //resized text + bbCode = bbCode.replaceAll("((.|\\n)+?)", "[color=$1]$2[/color]"); //colored text + bbCode = bbCode.replaceAll("
    ((.|\\n)+?)
    ", "[center]$1[/center]"); //centered text + bbCode = bbCode.replaceAll("
    ((.|\\n)+?)
    ", "[right]$1[/right]"); //right text + bbCode = bbCode.replaceAll("((.|\\n)+?)", "[url=$1]$2[/url]"); //Text link + bbCode = bbCode.replaceAll("", "[img]$1[/img]"); //image + bbCode = bbCode.replaceAll("", "[img align=left]$1[/img]"); //image left + bbCode = bbCode.replaceAll("", "[img align=right]$1[/img]"); //image right + bbCode = bbCode.replaceAll("
    ((.|\\n)+?)
    ", "[code]$[/code]"); //code + + final String finalBbCode = bbCode.replaceAll("
    ", "\n"); //new line + if (finalBbCode.contains("(.+?) said:((.|\\n)+?)
    ", "[quote=$2 message=$1]$3[/quote]"); //real quote + if (HTML.contains("", "[quote=$1]$2[/quote]"); //real quote + if (HTML.contains("
    ")) + return convertUserQuote(HTML); + convertUserQuote = 0; + } + return HTML; + } + + private int convertQuote = 0; + private String convertQuote(String HTML) { + convertQuote = convertQuote + 1; + if (convertQuote <= 8) { + HTML = HTML.replaceAll("
    ((.|\\n)+?)
    ", "[quote]$1[/quote]"); //quote + if (HTML.contains("
    ")) + return convertQuote(HTML); + convertQuote = 0; + } + return HTML; + } + + private int convertQuoteSpoiler = 0; + private String convertQuoteSpoiler(String HTML) { + convertQuoteSpoiler = convertQuoteSpoiler + 1; + if (convertQuoteSpoiler <= 8) { + HTML = HTML.replaceAll("(.+?) said:((.|\\n)+?)
    ", "[spoiler][quote=$2]$3[/quote][/spoiler]"); //quote + if (HTML.contains("spoiler quotetext\">")) + return convertQuoteSpoiler(HTML); + convertQuoteSpoiler = 0; + } + return HTML; + } + + private int convertSpoiler = 0; + private String convertSpoiler(String HTML) { + convertSpoiler = convertSpoiler + 1; + if (convertSpoiler <= 8) { + HTML = HTML.replaceAll("((.|\\n)+?)
    ", "[spoiler]$2[/spoiler]"); //quote + if (HTML.contains("spoiler quotetext\">")) + return convertSpoiler(HTML); + convertSpoiler = 0; + } + return HTML; + } + + /** + * Get the topics from a certain category. + */ + @JavascriptInterface + public void tileClick(final String id) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + forum.getRecords(ForumJob.CATEGORY, Integer.parseInt(id), "1"); + } + }); + } + + /** + * Get more pages certain category. + */ + @JavascriptInterface + public void topicList(final String page) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + String[] details = forum.webview.getTitle().split(" "); + forum.getRecords(ForumJob.CATEGORY, Integer.parseInt(details[1]), page); + } + }); + } + + /** + * Get the topics from a certain category. + */ + @JavascriptInterface + public void subTileClick(final String id) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + forum.getRecords(ForumJob.SUBCATEGORY, Integer.parseInt(id), "1"); + } + }); + } + + /** + * Get the posts from a certain topic. + */ + @JavascriptInterface + public void topicClick(final String id) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + forum.getRecords(ForumJob.TOPIC, Integer.parseInt(id), "1"); + } + }); + } + + /** + * Get next topic page. + */ + @JavascriptInterface + public void nextTopicList(final String page) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + String[] details = forum.webview.getTitle().split(" "); + forum.getRecords(ForumJob.CATEGORY, Integer.parseInt(details[1]), page); + } + }); + } + + /** + * Get topic comment page. + */ + @JavascriptInterface + public void prevTopicList(final String page) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + String[] details = forum.webview.getTitle().split(" "); + forum.getRecords(ForumJob.CATEGORY, Integer.parseInt(details[1]), page); + } + }); + } + + /** + * Send a comment. + */ + @JavascriptInterface + public void sendComment(final String comment, final String messageID) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + if (comment.length() > 16) { + forum.setLoading(true); + final String[] details = forum.webview.getTitle().split(" "); + + + ChooseDialogFragment lcdf = new ChooseDialogFragment(); + Bundle bundle = new Bundle(); + if (messageID.equals("0")) { + bundle.putString("title", forum.getString(R.string.dialog_title_add_comment)); + bundle.putString("message", forum.getString(R.string.dialog_message_add_comment)); + } else { + bundle.putString("title", forum.getString(R.string.dialog_title_edit_comment)); + bundle.putString("message", forum.getString(R.string.dialog_message_edit_comment)); + } + bundle.putString("positive", forum.getString(android.R.string.yes)); + lcdf.setArguments(bundle); + lcdf.setCallback(new ChooseDialogFragment.onClickListener() { + @Override + public void onPositiveButtonClicked() { + if (messageID.equals("0")) + new ForumNetworkTask(forum, forum, ForumJob.ADDCOMMENT, Integer.parseInt(details[1])).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, comment, details[3]); + else + new ForumNetworkTask(forum, forum, ForumJob.UPDATECOMMENT, Integer.parseInt(messageID)).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, comment, details[3]); + } + }); + lcdf.show(forum.getFragmentManager(), "fragment_sendComment"); + } else { + Theme.Snackbar(forum, R.string.toast_info_comment); + } + } + }); + } + + /** + * Get next comment page. + */ + @JavascriptInterface + public void nextCommentList(final String page) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + String[] details = forum.webview.getTitle().split(" "); + forum.getRecords(ForumJob.TOPIC, Integer.parseInt(details[1]), page); + } + }); + } + + /** + * Get comment page. + */ + @JavascriptInterface + public void pagePicker(final String page) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + String[] details = forum.webview.getTitle().split(" "); + Bundle bundle = new Bundle(); + bundle.putInt("id", Integer.parseInt(details[1])); + bundle.putString("title", forum.getString(R.string.Page_number)); + bundle.putInt("current", Integer.parseInt(page)); + bundle.putInt("max", Integer.parseInt(details[2])); + bundle.putInt("min", 1); + FragmentManager fm = forum.getFragmentManager(); + NumberPickerDialogFragment dialogFragment = new NumberPickerDialogFragment().setOnSendClickListener(forum); + dialogFragment.setArguments(bundle); + dialogFragment.show(fm, "fragment_page"); + } + }); + } + + /** + * Get previous comment page. + */ + @JavascriptInterface + public void prevCommentList(final String page) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + String[] details = forum.webview.getTitle().split(" "); + forum.getRecords(ForumJob.TOPIC, Integer.parseInt(details[1]), page); + } + }); + } + + /** + * Open the userprofile. + */ + @JavascriptInterface + public void profileClick(final String username) { + forum.runOnUiThread(new Runnable() { + @Override + public void run() { + Intent Profile = new Intent(forum, ProfileActivity.class); + Profile.putExtra("username", username); + forum.startActivity(Profile); + } + }); + } +} \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/forum/ForumsMain.java b/Atarashii/src/net/somethingdreadful/MAL/forum/ForumsMain.java deleted file mode 100644 index 3693b82c..00000000 --- a/Atarashii/src/net/somethingdreadful/MAL/forum/ForumsMain.java +++ /dev/null @@ -1,174 +0,0 @@ -package net.somethingdreadful.MAL.forum; - -import android.app.Activity; -import android.app.Fragment; -import android.os.AsyncTask; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.ScrollView; - -import com.crashlytics.android.Crashlytics; - -import net.somethingdreadful.MAL.Card; -import net.somethingdreadful.MAL.ForumActivity; -import net.somethingdreadful.MAL.R; -import net.somethingdreadful.MAL.adapters.ForumMainAdapter; -import net.somethingdreadful.MAL.api.MALApi; -import net.somethingdreadful.MAL.api.MALModels.Forum; -import net.somethingdreadful.MAL.api.MALModels.ForumMain; -import net.somethingdreadful.MAL.dialog.ForumChildDialogFragment; -import net.somethingdreadful.MAL.tasks.ForumJob; -import net.somethingdreadful.MAL.tasks.ForumNetworkTask; - -import butterknife.Bind; -import butterknife.ButterKnife; - -public class ForumsMain extends Fragment implements ForumNetworkTask.ForumNetworkTaskListener { - ForumActivity activity; - View view; - ForumMain record; - ForumMainAdapter myanimelistAdapter; - ForumMainAdapter animemangaAdapter; - ForumMainAdapter generalAdapter; - - @Bind(R.id.general) ListView general; - @Bind(R.id.scrollView) - ScrollView content; - @Bind(R.id.animemanga) ListView animeManga; - @Bind(R.id.myanimelist) ListView myAnimeList; - @Bind(R.id.network_Card) Card networkCard; - @Bind(R.id.progressBar) ProgressBar progressBar; - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - super.onCreate(bundle); - view = inflater.inflate(R.layout.activity_forum_main, container, false); - ButterKnife.bind(this, view); - - myanimelistAdapter = new ForumMainAdapter(activity, myAnimeList, getFragmentManager(), ForumJob.BOARD); - animemangaAdapter = new ForumMainAdapter(activity, animeManga, getFragmentManager(), ForumJob.BOARD); - generalAdapter = new ForumMainAdapter(activity, general, getFragmentManager(), ForumJob.BOARD); - - toggle(1); - setListener(); - - if (bundle != null && bundle.getSerializable("main") != null) - apply((ForumMain) bundle.getSerializable("main")); - else - getRecords(); - - return view; - } - - @Override - public void onSaveInstanceState(Bundle state) { - state.putSerializable("main", record); - super.onSaveInstanceState(state); - } - - /** - * Request new records. - */ - private void getRecords() { - if (MALApi.isNetworkAvailable(activity)) - new ForumNetworkTask(activity, this, activity, ForumJob.BOARD, 0).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else - toggle(2); - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - this.activity = ((ForumActivity) activity); - } - - @Override - public void onForumNetworkTaskFinished(ForumMain result, ForumJob task) { - apply(result); - } - - /** - * Refresh the UI for changes. - * - * @param result The new record that should be applied. - */ - public void apply(ForumMain result) { - try { - myAnimeList.setAdapter(myanimelistAdapter); - animeManga.setAdapter(animemangaAdapter); - general.setAdapter(generalAdapter); - - myanimelistAdapter.supportAddAll(result.getMyAnimeList()); - animemangaAdapter.supportAddAll(result.getAnimeManga()); - generalAdapter.supportAddAll(result.getGeneral()); - record = result; - toggle(0); - } catch (Exception e) { - Crashlytics.log(Log.ERROR, "MALX", "ForumMain.apply(): " + e.getMessage()); - } - } - - /** - * Set all the clicklisteners. - */ - private void setListener() { - myAnimeList.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - requestTopic((Forum) myanimelistAdapter.getItem(position)); - } - }); - animeManga.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - requestTopic((Forum) animemangaAdapter.getItem(position)); - } - }); - general.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - requestTopic((Forum) generalAdapter.getItem(position)); - } - }); - } - - /** - * Create a dialog to ask which subBoard you want to view. - * - * @param item The forum item with the subBoards - */ - private void requestTopic(Forum item) { - if (item.getId() == 0) { - ForumChildDialogFragment info = new ForumChildDialogFragment(); - Bundle args = new Bundle(); - args.putString("title", item.getName()); - args.putString("message", getString(R.string.dialog_message_forum_child)); - args.putSerializable("child", item.getChildren()); - info.setArguments(args); - info.show(getFragmentManager(), "fragment_forum"); - } else { - activity.getTopics(item.getId()); - } - } - - /** - * Handle the viewFlipper. - *

    - * 0 = The real content - * 1 = The progress indicator - * 2 = The network not available card - * - * @param number The number of the desired content - */ - private void toggle(int number) { - content.setVisibility(number == 0 ? View.VISIBLE : View.GONE); - progressBar.setVisibility(number == 1 ? View.VISIBLE : View.GONE); - networkCard.setVisibility(number == 2 ? View.VISIBLE : View.GONE); - } -} \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/forum/ForumsPosts.java b/Atarashii/src/net/somethingdreadful/MAL/forum/ForumsPosts.java deleted file mode 100644 index 75572fb0..00000000 --- a/Atarashii/src/net/somethingdreadful/MAL/forum/ForumsPosts.java +++ /dev/null @@ -1,138 +0,0 @@ -package net.somethingdreadful.MAL.forum; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.app.Fragment; -import android.os.AsyncTask; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.webkit.WebView; -import android.widget.ViewFlipper; - -import com.crashlytics.android.Crashlytics; - -import net.somethingdreadful.MAL.ForumActivity; -import net.somethingdreadful.MAL.R; -import net.somethingdreadful.MAL.Theme; -import net.somethingdreadful.MAL.account.AccountService; -import net.somethingdreadful.MAL.api.MALApi; -import net.somethingdreadful.MAL.api.MALModels.ForumMain; -import net.somethingdreadful.MAL.tasks.ForumJob; -import net.somethingdreadful.MAL.tasks.ForumNetworkTask; - -import butterknife.Bind; -import butterknife.ButterKnife; - -public class ForumsPosts extends Fragment implements ForumNetworkTask.ForumNetworkTaskListener { - View view; - HtmlUtil htmlUtil; - ForumActivity activity; - public ForumMain record; - - @Bind(R.id.webview) - WebView webview; - @Bind(R.id.viewFlipper) ViewFlipper viewFlipper; - - public int id; - public int page = 0; - - @SuppressLint({"AddJavascriptInterface", "SetJavaScriptEnabled"}) - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - super.onCreate(bundle); - view = inflater.inflate(R.layout.fragment_forum_posts, container, false); - ButterKnife.bind(this, view); - - htmlUtil = new HtmlUtil(activity); - - if (bundle != null && bundle.getSerializable("posts") != null) { - id = bundle.getInt("id"); - page = bundle.getInt("page"); - apply((ForumMain) bundle.getSerializable("posts")); - } - - webview.getSettings().setJavaScriptEnabled(true); - webview.addJavascriptInterface(new PostsInterface(this), "Posts"); - - return view; - } - - @Override - public void onSaveInstanceState(Bundle state) { - state.putSerializable("posts", record); - state.putInt("id", id); - state.putInt("page", page); - super.onSaveInstanceState(state); - } - - /** - * Change the records in this fragment. - * - * @param id The new id of the record - * @return ForumJob The task of this fragment - */ - public ForumJob setId(int id) { - if (this.id != id) { - this.id = id; - toggle(true); - getRecords(1); - } - return ForumJob.POSTS; - } - - /** - * Get the requested records. - * - * @param page The page number - */ - public void getRecords(int page) { - if (page != this.page) - toggle(true); - this.page = page; - if (MALApi.isNetworkAvailable(activity)) - new ForumNetworkTask(activity, this, activity, ForumJob.POSTS, id).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, String.valueOf(page)); - } - - /** - * Show or hide the progress indicator. - * - * @param loading True if the indicator should be shown - */ - private void toggle(boolean loading) { - viewFlipper.setDisplayedChild(loading ? 1 : 0); - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - this.activity = ((ForumActivity) activity); - } - - @Override - public void onForumNetworkTaskFinished(ForumMain result, ForumJob job) { - apply(result); - } - - /** - * Refresh the UI for changes. - * - * @param result The new record - */ - public void apply(ForumMain result) { - try { - activity.setTitle(getString(R.string.title_activity_forum)); - if (result != null) { - webview.loadDataWithBaseURL(null, htmlUtil.convertList(result, AccountService.getUsername(), page), "text/html", "utf-8", null); - toggle(false); - record = result; - } else { - Theme.Snackbar(activity, R.string.toast_error_Records); - } - } catch (Exception e) { - Crashlytics.log(Log.ERROR, "MALX", "ForumPosts.apply(): " + e.getMessage()); - } - } -} \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/forum/ForumsTopics.java b/Atarashii/src/net/somethingdreadful/MAL/forum/ForumsTopics.java deleted file mode 100644 index 101b9e8b..00000000 --- a/Atarashii/src/net/somethingdreadful/MAL/forum/ForumsTopics.java +++ /dev/null @@ -1,207 +0,0 @@ -package net.somethingdreadful.MAL.forum; - -import android.app.Activity; -import android.app.Fragment; -import android.os.AsyncTask; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AbsListView; -import android.widget.AdapterView; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.RelativeLayout; - -import com.crashlytics.android.Crashlytics; - -import net.somethingdreadful.MAL.Card; -import net.somethingdreadful.MAL.ForumActivity; -import net.somethingdreadful.MAL.R; -import net.somethingdreadful.MAL.adapters.ForumMainAdapter; -import net.somethingdreadful.MAL.api.MALApi; -import net.somethingdreadful.MAL.api.MALModels.Forum; -import net.somethingdreadful.MAL.api.MALModels.ForumMain; -import net.somethingdreadful.MAL.dialog.ForumChildDialogFragment; -import net.somethingdreadful.MAL.tasks.ForumJob; -import net.somethingdreadful.MAL.tasks.ForumNetworkTask; - -import butterknife.Bind; -import butterknife.ButterKnife; - -public class ForumsTopics extends Fragment implements ForumNetworkTask.ForumNetworkTaskListener, AbsListView.OnScrollListener, AdapterView.OnItemClickListener { - View view; - public ForumJob task; - ForumActivity activity; - public ForumMain topic; - public ForumMain subBoard; - public ForumMainAdapter topicsAdapter; - public MALApi.ListType type = MALApi.ListType.MANGA; - - @Bind(R.id.progressBar) ProgressBar progressBar; - @Bind(R.id.content) RelativeLayout content; - @Bind(R.id.network_Card) Card networkCard; - @Bind(R.id.list) ListView topics; - - public int id; - public int page = 0; - boolean loading = true; - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - super.onCreate(bundle); - view = inflater.inflate(R.layout.activity_forum_topics, container, false); - ButterKnife.bind(this, view); - - topicsAdapter = new ForumMainAdapter(activity, topics, getFragmentManager(), ForumJob.TOPICS); - - topics.setOnScrollListener(this); - topics.setOnItemClickListener(this); - topics.setAdapter(topicsAdapter); - topicsAdapter.setNotifyOnChange(true); - - toggle(1); - - if (bundle != null && bundle.getSerializable("task") != null) { - topic = (ForumMain) bundle.getSerializable("topic"); - subBoard = (ForumMain) bundle.getSerializable("subBoard"); - id = bundle.getInt("id"); - task = (ForumJob) bundle.getSerializable("task"); - type = (MALApi.ListType) bundle.getSerializable("type"); - page = bundle.getInt("page"); - apply(task == ForumJob.SUBBOARD ? subBoard : topic); - } - - return view; - } - - @Override - public void onSaveInstanceState(Bundle state) { - state.putSerializable("topic", topic); - state.putSerializable("subBoard", subBoard); - state.putInt("id", id); - state.putSerializable("task", task); - state.putSerializable("type", type); - state.putSerializable("page", page); - super.onSaveInstanceState(state); - } - - /** - * Change the records in this fragment. - * - * @param id The new id of the record - * @return ForumJob The task of this fragment - */ - public ForumJob setId(int id, ForumJob task) { - if (this.id != id || this.task != task) { - this.id = id; - this.task = task; - getRecords(1, task); - } - return task; - } - - /** - * Change the records in this fragment (search). - * - * @param query The topic title query - * @return ForumJob The task of this fragment - */ - public ForumJob setId(String query) { - toggle(1); - topicsAdapter.clear(); - if (MALApi.isNetworkAvailable(activity)) - new ForumNetworkTask(activity, this, activity, ForumJob.SEARCH, 0).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, query); - else - toggle(2); - return ForumJob.SEARCH; - } - - /** - * Get the requested records. - * - * @param page The page number - * @param task The task that should be performed - */ - public void getRecords(int page, ForumJob task) { - toggle(1); - this.page = page; - if (page == 1) - topicsAdapter.clear(); - if (MALApi.isNetworkAvailable(activity)) - new ForumNetworkTask(activity, this, activity, task, id).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, String.valueOf(page), type.toString()); - else - toggle(2); - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - this.activity = ((ForumActivity) activity); - } - - @Override - public void onForumNetworkTaskFinished(ForumMain result, ForumJob task) { - if (result != null && result.getList() != null) { - apply(result); - } - toggle(0); - activity.setTitle(getString(R.string.title_activity_forum)); - } - - public void apply(ForumMain result) { - try { - topicsAdapter.supportAddAll(result.getList()); - toggle(0); - loading = false; - activity.setTitle(getString(R.string.title_activity_forum)); - if (task == ForumJob.SUBBOARD) - subBoard = result; - else - topic = result; - } catch (Exception e) { - Crashlytics.log(Log.ERROR, "MALX", "ForumTopics.apply(): " + e.getMessage()); - } - } - - /** - * Handle the viewFlipper. - *

    - * 0 = The real content - * 1 = The progress indicator - * 2 = The network not available card - * - * @param number The number of the desired content - */ - private void toggle(int number) { - content.setVisibility(number == 0 ? View.VISIBLE : View.GONE); - progressBar.setVisibility(number == 1 ? View.VISIBLE : View.GONE); - networkCard.setVisibility(number == 2 ? View.VISIBLE : View.GONE); - } - - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) { - } - - @Override - public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - // don't do anything if there is nothing in the list - if (firstVisibleItem == 0 && visibleItemCount == 0 && totalItemCount == 0) - return; - if (totalItemCount - firstVisibleItem <= (visibleItemCount * 2) && !loading) { - loading = true; - getRecords(page + 1, task); - activity.setTitle(getString(R.string.layout_card_loading)); - } - } - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - int itemID = ((Forum) topicsAdapter.getItem(position)).getId(); - if (task == ForumJob.SUBBOARD && !ForumChildDialogFragment.DBModificationRequest) - activity.getDiscussion(itemID); - else - activity.getPosts(itemID); - } -} \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/forum/HtmlUtil.java b/Atarashii/src/net/somethingdreadful/MAL/forum/HtmlUtil.java index b1f8e724..0cd9a90a 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/forum/HtmlUtil.java +++ b/Atarashii/src/net/somethingdreadful/MAL/forum/HtmlUtil.java @@ -9,24 +9,22 @@ import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Reviews; import net.somethingdreadful.MAL.api.BaseModels.History; import net.somethingdreadful.MAL.api.BaseModels.Profile; -import net.somethingdreadful.MAL.api.MALModels.Forum; -import net.somethingdreadful.MAL.api.MALModels.ForumMain; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; public class HtmlUtil { - private Context context; - String structure; - String postStructure; - String spoilerStructure; - String pageString; + private final Context context; + private String structure; + private final String postStructure; + private String spoilerStructure; + private String pageString; public HtmlUtil(Context context) { structure = getString(context, R.raw.forum_post_structure); postStructure = getString(context, R.raw.forum_post_post_structure); - spoilerStructure = getString(context, R.raw.forum_post_spoiler_structure); + spoilerStructure = getString(context, R.raw.forum_comment_spoiler_structure); this.context = context; } @@ -124,7 +122,7 @@ public String convertMALComment(String comment) { * @param comment The HTML comment * @return String The BBCode comment */ - public String convertALComment(String comment) { + private String convertALComment(String comment) { comment = comment.replace("\n", "
    "); // New line comment = comment.replace("~~~img(", ""); // Image @@ -228,45 +226,6 @@ public String convertList(Profile record, int page) { return buildList(result, 0, page); } - /** - * Convert a forum array into a HTML list. - * - * @param record The ForumMain object that contains the list which should be converted in a HTML list - * @param username The username of the user, this is used for special rights - * @return String The HTML source - */ - public String convertList(ForumMain record, String username, int page) { - ArrayList list = record.getList(); - String result = ""; - for (int i = 0; i < list.size(); i++) { - Forum post = list.get(i); - String postreal = postStructure; - String comment = post.getComment(); - - comment = comment.replace("data-src=", "width=\"100%\" src="); - comment = comment.replace("img src=", "img width=\"100%\" src="); - - if (post.getUsername().equals(username)) - postreal = postreal.replace("", ""); - else - postreal = postreal.replace("", ""); - if (Profile.isDeveloper(post.getUsername())) - postreal = postreal.replace("=\"title\">", "=\"developer\">"); - if (!post.getProfile().getDetails().getAccessRank().equals("Member")) - postreal = postreal.replace("=\"title\">", "=\"staff\">"); - postreal = postreal.replace("image", post.getProfile().getAvatarUrl() != null ? post.getProfile().getAvatarUrl() : "http://cdn.myanimelist.net/images/na.gif"); - postreal = postreal.replace("Title", post.getUsername()); - postreal = postreal.replace("itemID", String.valueOf(post.getId())); - postreal = postreal.replace("position", String.valueOf(i)); - postreal = postreal.replace("Subhead", DateTools.parseDate(post.getTime(), true)); - postreal = postreal.replace("", comment); - - result = result + postreal; - } - pageString = context.getString(R.string.no_activity); - return buildList(result, record.getPages(), page); - } - /** * Convert a forum array into a HTML list. * diff --git a/Atarashii/src/net/somethingdreadful/MAL/forum/PostsInterface.java b/Atarashii/src/net/somethingdreadful/MAL/forum/PostsInterface.java deleted file mode 100644 index c4e6d1bf..00000000 --- a/Atarashii/src/net/somethingdreadful/MAL/forum/PostsInterface.java +++ /dev/null @@ -1,124 +0,0 @@ -package net.somethingdreadful.MAL.forum; - -import android.content.Intent; -import android.webkit.JavascriptInterface; - -import net.somethingdreadful.MAL.R; -import net.somethingdreadful.MAL.Theme; -import net.somethingdreadful.MAL.api.MALModels.Forum; -import net.somethingdreadful.MAL.tasks.ForumJob; - -public class PostsInterface { - ForumsPosts posts; - - PostsInterface(ForumsPosts posts) { - this.posts = posts; - } - - /** - * This method will be triggered when the user clicks on an HTML post. - * - * @param id The HTML post id - * @param position The array position of the post - */ - @JavascriptInterface - public void edit(final String id, String position) { - final String comment = posts.record.getList().get(Integer.parseInt(position)).getComment(); - - posts.activity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (comment.contains("embed src")) - Theme.Snackbar(posts.activity, R.string.toast_info_disabled_youtube); - else - posts.activity.getComments(Integer.parseInt(id), comment, ForumJob.UPDATECOMMENT); - } - }); - } - - /** - * This method will be triggered when the user clicks on an HTML post. - * - * @param id The HTML post id - * @param position The array position of the post - */ - @JavascriptInterface - public void quote(final String id, String position) { - Forum record = posts.record.getList().get(Integer.parseInt(position)); - final String comment = "[quote=" + record.getUsername() + "]" + record.getComment() + "[/quote]"; - posts.activity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (comment.contains("embed src")) - Theme.Snackbar(posts.activity, R.string.toast_info_disabled_youtube); - else - posts.activity.getComments(posts.id, posts.activity.message + "
    " + comment, ForumJob.ADDCOMMENT); - } - }); - } - - /** - * This method will be triggered when the user clicks on a profile image. - * - * @param position The array position of the post - */ - @JavascriptInterface - public void viewProfile(String position) { - String username = posts.record.getList().get(Integer.parseInt(position)).getUsername(); - Intent profile = new Intent(posts.activity, net.somethingdreadful.MAL.ProfileActivity.class); - profile.putExtra("username", username); - posts.startActivity(profile); - } - - /** - * Go the the previous page. - */ - @JavascriptInterface - public void previous() { - posts.activity.runOnUiThread(new Runnable() { - @Override - public void run() { - posts.activity.posts.getRecords(posts.activity.posts.page - 1); - } - }); - } - - /** - * Go to the next page. - */ - @JavascriptInterface - public void next() { - posts.activity.runOnUiThread(new Runnable() { - @Override - public void run() { - posts.activity.posts.getRecords(posts.activity.posts.page + 1); - } - }); - } - - /** - * Go to the first page. - */ - @JavascriptInterface - public void first() { - posts.activity.runOnUiThread(new Runnable() { - @Override - public void run() { - posts.activity.posts.getRecords(1); - } - }); - } - - /** - * Go to the last page. - */ - @JavascriptInterface - public void last() { - posts.activity.runOnUiThread(new Runnable() { - @Override - public void run() { - posts.activity.posts.getRecords(posts.activity.posts.record.getPages()); - } - }); - } -} \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileDetailsAL.java b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileDetailsAL.java index 3b118dd2..68a7efca 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileDetailsAL.java +++ b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileDetailsAL.java @@ -3,7 +3,6 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.app.Fragment; -import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -32,17 +31,19 @@ import butterknife.ButterKnife; public class ProfileDetailsAL extends Fragment implements SwipeRefreshLayout.OnRefreshListener { - View view; - Context context; + private View view; private HtmlUtil htmlUtil; private ProfileActivity activity; - @Bind(R.id.webview) WebView webview; - Card imagecard; - Card activitycard; + @Bind(R.id.webview) + WebView webview; + private Card imagecard; + private Card activitycard; @Bind(R.id.swiperefresh) public SwipeRefreshLayout swipeRefresh; - @Bind(R.id.progressBar) ProgressBar progressBar; - @Bind(R.id.network_Card) Card networkCard; + @Bind(R.id.progressBar) + ProgressBar progressBar; + @Bind(R.id.network_Card) + Card networkCard; @SuppressLint("SetJavaScriptEnabled") @Override @@ -62,7 +63,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle st swipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swiperefresh); swipeRefresh.setOnRefreshListener(this); - swipeRefresh.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); + swipeRefresh.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeRefresh.setEnabled(true); activity.setDetails(this); @@ -80,7 +81,7 @@ public void onAttach(Activity activity) { this.activity = (ProfileActivity) activity; } - public void card() { + private void card() { Card namecard = (Card) view.findViewById(R.id.name_card); namecard.Header.setText(WordUtils.capitalize(activity.record.getUsername())); } @@ -93,7 +94,7 @@ public void toggle(int number) { public void refresh() { if (activity.record == null) { - if (MALApi.isNetworkAvailable(context)) + if (MALApi.isNetworkAvailable(activity)) Theme.Snackbar(activity, R.string.toast_error_UserRecord); else toggle(2); @@ -103,7 +104,7 @@ public void refresh() { webview.loadDataWithBaseURL(null, htmlUtil.convertList(activity.record, 1), "text/html", "utf-8", null); - Picasso.with(context) + Picasso.with(activity) .load(activity.record.getImageUrl()) .into(new Target() { @Override diff --git a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileDetailsMAL.java b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileDetailsMAL.java index b8460ef1..f8b22ea2 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileDetailsMAL.java +++ b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileDetailsMAL.java @@ -1,5 +1,6 @@ package net.somethingdreadful.MAL.profile; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.Fragment; import android.content.Intent; @@ -38,42 +39,70 @@ import butterknife.ButterKnife; public class ProfileDetailsMAL extends Fragment implements SwipeRefreshLayout.OnRefreshListener { - View view; - Card imagecard; - Card animecard; - Card mangacard; + private View view; + private Card imagecard; + private Card animecard; + private Card mangacard; private ProfileActivity activity; @Bind(R.id.swiperefresh) public SwipeRefreshLayout swipeRefresh; - @Bind(R.id.progressBar) ProgressBar progressBar; - @Bind(R.id.network_Card) Card networkCard; - - @Bind(R.id.birthdaysmall) TextView tv1; - @Bind(R.id.locationsmall) TextView tv2; - @Bind(R.id.commentspostssmall) TextView tv3; - @Bind(R.id.forumpostssmall) TextView tv4; - @Bind(R.id.lastonlinesmall) TextView tv5; - @Bind(R.id.gendersmall) TextView tv6; - @Bind(R.id.joindatesmall) TextView tv7; - @Bind(R.id.accessranksmall) TextView tv8; - @Bind(R.id.animelistviewssmall) TextView tv9; - @Bind(R.id.mangalistviewssmall) TextView tv10; - @Bind(R.id.atimedayssmall) TextView tv11; - @Bind(R.id.awatchingsmall) TextView tv12; - @Bind(R.id.acompletedpostssmall) TextView tv13; - @Bind(R.id.aonholdsmall) TextView tv14; - @Bind(R.id.adroppedsmall) TextView tv15; - @Bind(R.id.aplantowatchsmall) TextView tv16; - @Bind(R.id.atotalentriessmall) TextView tv17; - @Bind(R.id.mtimedayssmall) TextView tv18; - @Bind(R.id.mwatchingsmall) TextView tv19; - @Bind(R.id.mcompletedpostssmall) TextView tv20; - @Bind(R.id.monholdsmall) TextView tv21; - @Bind(R.id.mdroppedsmall) TextView tv22; - @Bind(R.id.mplantowatchsmall) TextView tv23; - @Bind(R.id.mtotalentriessmall) TextView tv24; - @Bind(R.id.websitesmall) TextView tv25; - @Bind(R.id.websitefront) TextView tv26; + @Bind(R.id.progressBar) + ProgressBar progressBar; + @Bind(R.id.network_Card) + Card networkCard; + + @Bind(R.id.birthdaysmall) + TextView tv1; + @Bind(R.id.locationsmall) + TextView tv2; + @Bind(R.id.commentspostssmall) + TextView tv3; + @Bind(R.id.forumpostssmall) + TextView tv4; + @Bind(R.id.lastonlinesmall) + TextView tv5; + @Bind(R.id.gendersmall) + TextView tv6; + @Bind(R.id.joindatesmall) + TextView tv7; + @Bind(R.id.accessranksmall) + TextView tv8; + @Bind(R.id.animelistviewssmall) + TextView tv9; + @Bind(R.id.mangalistviewssmall) + TextView tv10; + @Bind(R.id.atimedayssmall) + TextView tv11; + @Bind(R.id.awatchingsmall) + TextView tv12; + @Bind(R.id.acompletedpostssmall) + TextView tv13; + @Bind(R.id.aonholdsmall) + TextView tv14; + @Bind(R.id.adroppedsmall) + TextView tv15; + @Bind(R.id.aplantowatchsmall) + TextView tv16; + @Bind(R.id.atotalentriessmall) + TextView tv17; + @Bind(R.id.mtimedayssmall) + TextView tv18; + @Bind(R.id.mwatchingsmall) + TextView tv19; + @Bind(R.id.mcompletedpostssmall) + TextView tv20; + @Bind(R.id.monholdsmall) + TextView tv21; + @Bind(R.id.mdroppedsmall) + TextView tv22; + @Bind(R.id.mplantowatchsmall) + TextView tv23; + @Bind(R.id.mtotalentriessmall) + TextView tv24; + @Bind(R.id.websitesmall) + TextView tv25; + @Bind(R.id.websitefront) + TextView tv26; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) { @@ -91,7 +120,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle st ButterKnife.bind(this, view); swipeRefresh.setOnRefreshListener(this); - swipeRefresh.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); + swipeRefresh.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeRefresh.setEnabled(true); TextView tv25 = (TextView) view.findViewById(R.id.websitesmall); @@ -118,7 +147,7 @@ public void onAttach(Activity activity) { this.activity = (ProfileActivity) activity; } - public void card() { //settings for hide a card and text userprofile + private void card() { //settings for hide a card and text userprofile if (PrefManager.getHideAnime()) animecard.setVisibility(View.GONE); if (PrefManager.getHideManga()) @@ -132,7 +161,7 @@ public void card() { //settings for hide a card and text userprofile namecard.Header.setText(WordUtils.capitalize(activity.record.getUsername())); } - public void setcolor() { + private void setcolor() { TextView tv8 = (TextView) view.findViewById(R.id.accessranksmall); String name = activity.record.getUsername(); String rank = activity.record.getDetails().getAccessRank() != null ? activity.record.getDetails().getAccessRank() : ""; @@ -155,7 +184,7 @@ public void setcolor() { } } - public void setColor(boolean type) { + private void setColor(boolean type) { int Hue; TextView textview; if (type) { @@ -170,17 +199,17 @@ public void setColor(boolean type) { textview.setTextColor(Color.HSVToColor(new float[]{Hue, 1, (float) 0.7})); } - private String getStringFromResourceArray(int resArrayId, int notFoundStringId, int index) { + private String getStringFromResourceArray(int resArrayId, int index) { try { // getResources will cause a crash if an users clicks the profile fast away Resources res = getResources(); try { String[] types = res.getStringArray(resArrayId); if (index < 0 || index >= types.length) // make sure to have a valid array index - return res.getString(notFoundStringId); + return res.getString(R.string.not_specified); else return types[index]; } catch (Exception e) { - return res.getString(notFoundStringId); + return res.getString(R.string.not_specified); } } catch (Exception e) { Crashlytics.log(Log.ERROR, "MALX", "ProfileDetailsMAL.getStringFromResourceArray(): " + e.getMessage()); @@ -194,7 +223,8 @@ public void toggle(int number) { networkCard.setVisibility(number == 2 ? View.VISIBLE : View.GONE); } - public void setText() { + @SuppressLint("SetTextI18n") + void setText() { if (activity.record.getDetails().getBirthday() == null) { tv1.setText(R.string.not_specified); } else { @@ -218,7 +248,7 @@ public void setText() { tv5.setText(lastOnline.equals("") ? activity.record.getDetails().getLastOnline() : lastOnline); } else tv5.setText("-"); - tv6.setText(getStringFromResourceArray(R.array.gender, R.string.not_specified, activity.record.getDetails().getGenderInt())); + tv6.setText(getStringFromResourceArray(R.array.gender, activity.record.getDetails().getGenderInt())); if (activity.record.getDetails().getJoinDate() != null) { String joinDate = DateTools.parseDate(activity.record.getDetails().getJoinDate(), false); tv7.setText(joinDate.equals("") ? activity.record.getDetails().getJoinDate() : joinDate); diff --git a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileFriends.java b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileFriends.java index fcae08eb..cac66f6e 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileFriends.java +++ b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileFriends.java @@ -32,16 +32,18 @@ import butterknife.ButterKnife; public class ProfileFriends extends Fragment implements FriendsNetworkTask.FriendsNetworkTaskListener, SwipeRefreshLayout.OnRefreshListener, OnItemClickListener { - GridView Gridview; + private GridView Gridview; private ProfileActivity activity; - FriendsGridviewAdapter listadapter; - ArrayList listarray = new ArrayList<>(); + private FriendsGridviewAdapter listadapter; + private ArrayList listarray = new ArrayList<>(); - @Bind(R.id.network_Card) Card networkCard; - @Bind(R.id.progressBar) ProgressBar progressBar; + @Bind(R.id.network_Card) + Card networkCard; + @Bind(R.id.progressBar) + ProgressBar progressBar; @Bind(R.id.swiperefresh) public SwipeRefreshLayout swipeRefresh; - boolean forcesync = false; + private boolean forcesync = false; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) { @@ -54,7 +56,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle st listadapter = new FriendsGridviewAdapter<>(activity, listarray); swipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swiperefresh); swipeRefresh.setOnRefreshListener(this); - swipeRefresh.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); + swipeRefresh.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeRefresh.setEnabled(true); activity.setFriends(this); @@ -74,7 +76,7 @@ private void toggle(int number) { networkCard.setVisibility(number == 2 ? View.VISIBLE : View.GONE); } - public void refresh() { + private void refresh() { Gridview.setAdapter(listadapter); try { listadapter.supportAddAll(listarray); diff --git a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileHistory.java b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileHistory.java index a1392903..58a5764a 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileHistory.java +++ b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileHistory.java @@ -27,10 +27,11 @@ public class ProfileHistory extends Fragment implements SwipeRefreshLayout.OnRef private HtmlUtil htmlUtil; public ProfileActivity activity; - @Bind(R.id.webview) WebView webview; + @Bind(R.id.webview) + WebView webview; @Bind(R.id.swiperefresh) public SwipeRefreshLayout swipeRefresh; - @SuppressLint("SetJavaScriptEnabled") + @SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"}) @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { View view = inflater.inflate(R.layout.fragment_profile_history, container, false); @@ -46,7 +47,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bu swipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swiperefresh); swipeRefresh.setOnRefreshListener(this); - swipeRefresh.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); + swipeRefresh.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeRefresh.setEnabled(true); NfcHelper.disableBeam(activity); @@ -58,7 +59,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bu * * @param result The new record */ - public void apply(Profile result) { + private void apply(Profile result) { try { if (result != null) { webview.loadDataWithBaseURL(null, htmlUtil.convertList(result, 1), "text/html", "utf-8", null); diff --git a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileHistoryInterface.java b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileHistoryInterface.java index 46c450d7..1b213300 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileHistoryInterface.java +++ b/Atarashii/src/net/somethingdreadful/MAL/profile/ProfileHistoryInterface.java @@ -7,8 +7,8 @@ import net.somethingdreadful.MAL.api.BaseModels.History; import net.somethingdreadful.MAL.api.MALApi; -public class ProfileHistoryInterface { - ProfileHistory history; +class ProfileHistoryInterface { + private final ProfileHistory history; ProfileHistoryInterface(ProfileHistory history) { this.history = history; diff --git a/Atarashii/src/net/somethingdreadful/MAL/tasks/APIAuthenticationErrorListener.java b/Atarashii/src/net/somethingdreadful/MAL/tasks/APIAuthenticationErrorListener.java index 9a238386..69196350 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/tasks/APIAuthenticationErrorListener.java +++ b/Atarashii/src/net/somethingdreadful/MAL/tasks/APIAuthenticationErrorListener.java @@ -3,5 +3,5 @@ import net.somethingdreadful.MAL.api.MALApi; public interface APIAuthenticationErrorListener { - public void onAPIAuthenticationError(MALApi.ListType type, TaskJob job); + void onAPIAuthenticationError(MALApi.ListType type, TaskJob job); } diff --git a/Atarashii/src/net/somethingdreadful/MAL/tasks/AuthenticationCheckTask.java b/Atarashii/src/net/somethingdreadful/MAL/tasks/AuthenticationCheckTask.java index 92771aad..966cae3b 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/tasks/AuthenticationCheckTask.java +++ b/Atarashii/src/net/somethingdreadful/MAL/tasks/AuthenticationCheckTask.java @@ -19,9 +19,8 @@ import retrofit.RetrofitError; public class AuthenticationCheckTask extends AsyncTask { - private AuthenticationCheckListener callback; - private String username; - Activity activity; + private final AuthenticationCheckListener callback; + private final Activity activity; public AuthenticationCheckTask(AuthenticationCheckListener callback, Activity activity) { this.callback = callback; @@ -47,7 +46,6 @@ protected Boolean doInBackground(String... params) { AccountService.setRefreshToken(auth.refresh_token); PrefManager.setNavigationBackground(profile.getImageUrlBanner()); - username = profile.getUsername(); return true; } } catch (RetrofitError re) { diff --git a/Atarashii/src/net/somethingdreadful/MAL/tasks/BackupTask.java b/Atarashii/src/net/somethingdreadful/MAL/tasks/BackupTask.java index 4f2cff3f..53889cb2 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/tasks/BackupTask.java +++ b/Atarashii/src/net/somethingdreadful/MAL/tasks/BackupTask.java @@ -30,7 +30,7 @@ public class BackupTask extends AsyncTask { private final Context context; private ArrayList animeResult; private ArrayList mangaResult; - private ArrayList files = new ArrayList<>(); + private final ArrayList files = new ArrayList<>(); public BackupTask(BackupTaskListener callback, Context context) { this.callback = callback; diff --git a/Atarashii/src/net/somethingdreadful/MAL/tasks/ForumJob.java b/Atarashii/src/net/somethingdreadful/MAL/tasks/ForumJob.java index 31f71e7f..523c2026 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/tasks/ForumJob.java +++ b/Atarashii/src/net/somethingdreadful/MAL/tasks/ForumJob.java @@ -1,14 +1,5 @@ package net.somethingdreadful.MAL.tasks; public enum ForumJob { - BOARD, - SUBBOARD, - TOPICS, - DISCUSSION, - POSTS, - ADDCOMMENT, - ADDTOPIC, - COMMENT, - SEARCH, - UPDATECOMMENT + MENU, CATEGORY, SUBCATEGORY, TOPIC, SEARCH, ADDCOMMENT, UPDATECOMMENT } \ No newline at end of file diff --git a/Atarashii/src/net/somethingdreadful/MAL/tasks/ForumNetworkTask.java b/Atarashii/src/net/somethingdreadful/MAL/tasks/ForumNetworkTask.java index 59e28109..c866c372 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/tasks/ForumNetworkTask.java +++ b/Atarashii/src/net/somethingdreadful/MAL/tasks/ForumNetworkTask.java @@ -1,7 +1,6 @@ package net.somethingdreadful.MAL.tasks; import android.app.Activity; -import android.content.Context; import android.os.AsyncTask; import android.util.Log; @@ -10,23 +9,19 @@ import net.somethingdreadful.MAL.MALManager; import net.somethingdreadful.MAL.R; import net.somethingdreadful.MAL.Theme; -import net.somethingdreadful.MAL.api.MALApi; -import net.somethingdreadful.MAL.api.MALModels.Forum; -import net.somethingdreadful.MAL.api.MALModels.ForumMain; +import net.somethingdreadful.MAL.api.BaseModels.AnimeManga.Forum; import java.util.ArrayList; import retrofit.RetrofitError; -public class ForumNetworkTask extends AsyncTask { - Context context; - ForumNetworkTaskListener callback; - ForumJob type; - int id; - Activity activity; +public class ForumNetworkTask extends AsyncTask> { + private final ForumNetworkTaskListener callback; + private final ForumJob type; + private final int id; + private final Activity activity; - public ForumNetworkTask(Context context, ForumNetworkTaskListener callback, Activity activity, ForumJob type, int id) { - this.context = context; + public ForumNetworkTask(ForumNetworkTaskListener callback, Activity activity, ForumJob type, int id) { this.callback = callback; this.type = type; this.id = id; @@ -34,18 +29,36 @@ public ForumNetworkTask(Context context, ForumNetworkTaskListener callback, Acti } @Override - protected ForumMain doInBackground(String... params) { - ForumMain result = new ForumMain(); - MALManager mManager = new MALManager(context); + protected ArrayList doInBackground(String... params) { + ArrayList result = new ArrayList<>(); + MALManager mManager = new MALManager(activity); try { switch (type) { - case BOARD: - result = mManager.getForum(); + case MENU: // list with all categories + result = mManager.getForumCategories(); break; - case SUBBOARD: - result = mManager.getSubBoards(id, Integer.parseInt(params[0])); + case CATEGORY: // list with all topics of a certain category + result = mManager.getCategoryTopics(id, Integer.parseInt(params[0])); break; + case SUBCATEGORY: + result = mManager.getSubCategory(id, Integer.parseInt(params[0])); + break; + case TOPIC: // list with all comments of users + result = mManager.getTopic(id, Integer.parseInt(params[0])); + break; + case SEARCH: + result = mManager.search(params[0]); + break; + case ADDCOMMENT: + result = mManager.addComment(id, params[0]) ? new ArrayList() : null; + if (result != null) + result = mManager.getTopic(id, Integer.parseInt(params[1])); + break; + case UPDATECOMMENT: + result = mManager.updateComment(id, params[0]) ? new ArrayList() : null; + break; + /* case DISCUSSION: if (params[1].equals(MALApi.ListType.ANIME.toString())) result = mManager.getDiscussion(id, Integer.parseInt(params[0]), MALApi.ListType.ANIME); @@ -66,10 +79,7 @@ protected ForumMain doInBackground(String... params) { break; case UPDATECOMMENT: result.setList(mManager.updateComment(id, params[0]) ? new ArrayList() : null); - break; - case SEARCH: - result = mManager.search(params[0]); - break; + break;*/ } } catch (RetrofitError re) { if (re.getResponse() != null && activity != null) { @@ -110,12 +120,12 @@ protected ForumMain doInBackground(String... params) { } @Override - protected void onPostExecute(ForumMain result) { + protected void onPostExecute(ArrayList result) { if (callback != null) callback.onForumNetworkTaskFinished(result, type); } public interface ForumNetworkTaskListener { - void onForumNetworkTaskFinished(ForumMain result, ForumJob task); + void onForumNetworkTaskFinished(ArrayList result, ForumJob task); } } diff --git a/Atarashii/src/net/somethingdreadful/MAL/tasks/FriendsNetworkTask.java b/Atarashii/src/net/somethingdreadful/MAL/tasks/FriendsNetworkTask.java index c579b7ec..29dd37d8 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/tasks/FriendsNetworkTask.java +++ b/Atarashii/src/net/somethingdreadful/MAL/tasks/FriendsNetworkTask.java @@ -19,10 +19,10 @@ import retrofit.RetrofitError; public class FriendsNetworkTask extends AsyncTask> { - FriendsNetworkTaskListener callback; - private Context context; - private boolean forcesync; - Activity activity; + private final FriendsNetworkTaskListener callback; + private final Context context; + private final boolean forcesync; + private final Activity activity; public FriendsNetworkTask(Context context, boolean forcesync, FriendsNetworkTaskListener callback, Activity activity) { this.context = context; diff --git a/Atarashii/src/net/somethingdreadful/MAL/tasks/NetworkTask.java b/Atarashii/src/net/somethingdreadful/MAL/tasks/NetworkTask.java index 0633667d..92b7f35b 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/tasks/NetworkTask.java +++ b/Atarashii/src/net/somethingdreadful/MAL/tasks/NetworkTask.java @@ -23,15 +23,15 @@ import retrofit.RetrofitError; public class NetworkTask extends AsyncTask { - TaskJob job; - MALApi.ListType type; - Activity activity; - Context context; - Bundle data; - NetworkTaskListener callback; - APIAuthenticationErrorListener authErrorCallback; - Object taskResult; - TaskJob[] arrayTasks = {TaskJob.GETLIST, TaskJob.FORCESYNC, TaskJob.GETMOSTPOPULAR, TaskJob.GETTOPRATED, + private TaskJob job; + private MALApi.ListType type; + private Activity activity; + private Context context; + private Bundle data; + private NetworkTaskListener callback; + private APIAuthenticationErrorListener authErrorCallback; + private Object taskResult; + private final TaskJob[] arrayTasks = {TaskJob.GETLIST, TaskJob.FORCESYNC, TaskJob.GETMOSTPOPULAR, TaskJob.GETTOPRATED, TaskJob.GETJUSTADDED, TaskJob.GETUPCOMING, TaskJob.SEARCH, TaskJob.REVIEWS}; diff --git a/Atarashii/src/net/somethingdreadful/MAL/tasks/UserNetworkTask.java b/Atarashii/src/net/somethingdreadful/MAL/tasks/UserNetworkTask.java index 6f3576ae..c237be0b 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/tasks/UserNetworkTask.java +++ b/Atarashii/src/net/somethingdreadful/MAL/tasks/UserNetworkTask.java @@ -20,10 +20,10 @@ import retrofit.RetrofitError; public class UserNetworkTask extends AsyncTask { - Context context; - boolean forcesync; - UserNetworkTaskListener callback; - private Activity activity; + private final Context context; + private final boolean forcesync; + private final UserNetworkTaskListener callback; + private final Activity activity; public UserNetworkTask(Context context, boolean forcesync, UserNetworkTaskListener callback, Activity activity) { this.context = context; diff --git a/Atarashii/src/net/somethingdreadful/MAL/tasks/WriteDetailTask.java b/Atarashii/src/net/somethingdreadful/MAL/tasks/WriteDetailTask.java index 241bdff1..374af411 100644 --- a/Atarashii/src/net/somethingdreadful/MAL/tasks/WriteDetailTask.java +++ b/Atarashii/src/net/somethingdreadful/MAL/tasks/WriteDetailTask.java @@ -24,11 +24,11 @@ import retrofit.RetrofitError; public class WriteDetailTask extends AsyncTask { - Context context; - ListType type = ListType.ANIME; - TaskJob job; - APIAuthenticationErrorListener authErrorCallback; - private Activity activity; + private final Context context; + private ListType type = ListType.ANIME; + private final TaskJob job; + private final APIAuthenticationErrorListener authErrorCallback; + private final Activity activity; public WriteDetailTask(ListType type, TaskJob job, Context context, APIAuthenticationErrorListener authErrorCallback, Activity activity) { this.context = context; diff --git a/build.gradle b/build.gradle index a2aadab9..7107859c 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.0.0-alpha5' + classpath 'com.android.tools.build:gradle:2.0.0-beta2' } }