diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java index d3d38870..ddc604b4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java @@ -9,7 +9,6 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; -import android.util.Log; import android.widget.Toast; import gr.thmmy.mthmmy.R; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java index 40f14c93..9f896b29 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java @@ -36,7 +36,7 @@ class ForumAdapter extends ExpandableRecyclerAdapter { private String[] replyDataHolder = new String[2]; private int replySubject = 0, replyText = 1; + private String loadedPageUrl = ""; /** * @param context the context of the {@link RecyclerView} * @param postsList List of {@link Post} objects to use */ TopicAdapter(Context context, List postsList, TopicActivity.TopicTask topicTask - , String topicTitle) { + , String topicTitle, String loadedPageUrl) { this.context = context; this.postsList = postsList; @@ -122,12 +123,18 @@ class TopicAdapter extends RecyclerView.Adapter { } this.topicTask = topicTask; this.topicTitle = topicTitle; + this.loadedPageUrl = loadedPageUrl; } void prepareForReply(TopicActivity.ReplyTask replyTask) { this.replyTask = replyTask; } + void setTopicInfo(String topicTitle, String loadedPageUrl) { + this.topicTitle = topicTitle; + this.loadedPageUrl = loadedPageUrl; + } + @Override public int getItemViewType(int position) { return postsList.get(position) == null ? VIEW_TYPE_QUICK_REPLY : VIEW_TYPE_POST; @@ -712,7 +719,7 @@ class TopicAdapter extends RecyclerView.Adapter { } private class CustomEditTextListener implements TextWatcher { - private int positionInDataHolder; + private final int positionInDataHolder; CustomEditTextListener(int positionInDataHolder) { this.positionInDataHolder = positionInDataHolder; @@ -777,7 +784,8 @@ class TopicAdapter extends RecyclerView.Adapter { if (postsList.get(quotePosition).getPostIndex() != 0) { if (postDate != null) { return "[quote author=" + postsList.get(quotePosition).getAuthor() - + " link=topic=68525.msg" + postsList.get(quotePosition).getPostIndex() + + " link=topic=" + ThmmyPage.getTopicId(loadedPageUrl) + ".msg" + + postsList.get(quotePosition).getPostIndex() + "#msg" + postsList.get(quotePosition).getPostIndex() + " date=" + postDate.getTime() / 1000 + "]" + "\n" + postsList.get(quotePosition).getContent() diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java index efff957e..3ce9c24d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java @@ -200,8 +200,6 @@ class TopicParser { p_postIndex = Integer.parseInt(tmp.substring(tmp.indexOf("msg") + 3)); } else{ postIndex = thisRow.select("div[id^=subject]").first(); - Log.d("TAG", "got"); - Log.d("TAG", postIndex.toString()); if (postIndex == null) p_postIndex = NO_INDEX; else{ diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 9e2a3023..3be339d3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -64,8 +64,8 @@ public abstract class BaseActivity extends AppCompatActivity { private static final String BOOKMARKED_TOPICS_KEY = "bookmarkedTopicsKey"; private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey"; protected Bookmark thisPageBookmark; - protected MenuItem thisPageBookmarkMenuButton; - protected ImageButton thisPageBookmarkImageButton; + private MenuItem thisPageBookmarkMenuButton; + private ImageButton thisPageBookmarkImageButton; private SharedPreferences bookmarksFile; private ArrayList topicsBookmarked; private ArrayList boardsBookmarked; @@ -347,7 +347,7 @@ public abstract class BaseActivity extends AppCompatActivity { }); } - protected void updateDrawer() { + private void updateDrawer() { if (drawer != null) { if (!sessionManager.isLoggedIn()) //When logged out or if user is guest { @@ -376,7 +376,7 @@ public abstract class BaseActivity extends AppCompatActivity { * Result toast will always display a success, because when user chooses logout all data are * cleared regardless of the actual outcome */ - protected class LogoutTask extends AsyncTask { //Attempt logout + private class LogoutTask extends AsyncTask { //Attempt logout ProgressDialog progressDialog; protected Integer doInBackground(Void... voids) { @@ -419,7 +419,7 @@ public abstract class BaseActivity extends AppCompatActivity { } } - protected void topicMenuBookmarkClick(){ + protected void topicMenuBookmarkClick() { if (thisPageBookmark.matchExists(topicsBookmarked)) { thisPageBookmarkMenuButton.setIcon(notBookmarked); toggleTopicToBookmarks(thisPageBookmark); @@ -524,7 +524,7 @@ public abstract class BaseActivity extends AppCompatActivity { } //Display popup gor user to grant permission - public void requestPerms() { //Runtime permissions request for devices with API >= 23 + private void requestPerms() { //Runtime permissions request for devices with API >= 23 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { String[] PERMISSIONS_STORAGE = { Manifest.permission.READ_EXTERNAL_STORAGE, @@ -559,7 +559,7 @@ public abstract class BaseActivity extends AppCompatActivity { } //Uses temp file - called after permission grant - public void launchDownloadService() { + private void launchDownloadService() { if (checkPerms()) DownloadService.startActionDownload(this, tempThmmyFile.getFileUrl().toString()); diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java index c33ffdf6..20bd8da2 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java @@ -15,7 +15,7 @@ public abstract class BaseFragment extends Fragment { protected FragmentInteractionListener fragmentInteractionListener; private String TAG; - protected int sectionNumber; + private int sectionNumber; protected static OkHttpClient client; @Override @@ -23,7 +23,7 @@ public abstract class BaseFragment extends Fragment { super.onCreate(savedInstanceState); TAG = getArguments().getString(ARG_TAG); sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER); - if(client==null) + if (client == null) client = BaseApplication.getInstance().getClient(); //must check every time - e.g. // becomes null when app restarts after crash Timber.d("onCreate"); @@ -76,5 +76,6 @@ public abstract class BaseFragment extends Fragment { * the activity that contains it, to allow communication upon interaction, * between the fragment and the activity/ other fragments */ - public interface FragmentInteractionListener {} + public interface FragmentInteractionListener { + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Category.java b/app/src/main/java/gr/thmmy/mthmmy/model/Category.java index ce43c42d..46142bbf 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Category.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Category.java @@ -7,8 +7,7 @@ import java.util.List; import static android.R.attr.id; -public class Category implements Parent -{ +public class Category implements Parent { private final String title; private final String categoryURL; private boolean expanded = false; diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java b/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java index 12c94f95..9e935f69 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java @@ -1,7 +1,6 @@ package gr.thmmy.mthmmy.model; import android.net.Uri; -import android.util.Log; import java.util.Objects; diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java index cd878b25..52883ef4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java @@ -27,7 +27,7 @@ import timber.log.Timber; */ public class DownloadService extends IntentService { private static final String TAG = "DownloadService"; - private static int sDownloadId =0; + private static int sDownloadId = 0; private Receiver receiver; @@ -48,7 +48,6 @@ public class DownloadService extends IntentService { public static final String FAILED = "Failed"; - public DownloadService() { super("DownloadService"); } @@ -109,14 +108,12 @@ public class DownloadService extends IntentService { Response response = client.newCall(request).execute(); String contentType = response.headers("Content-Type").toString(); //check if link provides a binary file - if(contentType.equals("[application/octet-stream]")) - { + if (contentType.equals("[application/octet-stream]")) { fileName = response.headers("Content-Disposition").toString().split("\"")[1]; File dirPath = new File(SAVE_DIR); - if(!dirPath.isDirectory()) - { - if(dirPath.mkdirs()) + if (!dirPath.isDirectory()) { + if (dirPath.mkdirs()) Timber.i("mTHMMY's directory created successfully!"); else Timber.e("Couldn't create mTHMMY's directory..."); @@ -126,20 +123,16 @@ public class DownloadService extends IntentService { String nameFormat; String[] tokens = fileName.split("\\.(?=[^\\.]+$)"); - if(tokens.length!=2) - { + if (tokens.length != 2) { Timber.w("Couldn't get file extension..."); nameFormat = fileName + "(%d)"; - } - else + } else nameFormat = tokens[0] + "(%d)." + tokens[1]; - - File file = new File(dirPath, fileName); - for (int i = 1;;i++) { + for (int i = 1; ; i++) { if (!file.exists()) { break; } @@ -157,21 +150,18 @@ public class DownloadService extends IntentService { sink.flush(); Timber.i("Download OK!"); sendNotification(downloadId, COMPLETED, fileName); - } - else + } else Timber.e("Response not a binary file!"); - } - catch (FileNotFoundException e){ + } catch (FileNotFoundException e) { Timber.i("Download failed..."); Timber.e("FileNotFound", e); sendNotification(downloadId, FAILED, fileName); - } - catch (IOException e){ + } catch (IOException e) { Timber.i("Download failed..."); Timber.e("IOException", e); sendNotification(downloadId, FAILED, fileName); } finally { - if (sink!= null) { + if (sink != null) { try { sink.close(); } catch (IOException e) { @@ -181,9 +171,8 @@ public class DownloadService extends IntentService { } } - private void sendNotification(int downloadId, String type, @NonNull String fileName) - { - Intent intent = new Intent(ACTION_DOWNLOAD); + private void sendNotification(int downloadId, String type, @NonNull String fileName) { + Intent intent = new Intent(ACTION_DOWNLOAD); switch (type) { case STARTED: { intent.putExtra(EXTRA_NOTIFICATION_TITLE, "Download Started"); @@ -203,7 +192,7 @@ public class DownloadService extends IntentService { intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Download Failed"); break; } - default:{ + default: { Timber.e("Invalid notification case!"); return; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java index ce0f9228..1455fb27 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -48,12 +48,12 @@ public class SessionManager { public static final int EXCEPTION = 6; // Client & Cookies - private OkHttpClient client; - private PersistentCookieJar cookieJar; - private SharedPrefsCookiePersistor cookiePersistor; //Used to explicitly edit cookies in cookieJar + private final OkHttpClient client; + private final PersistentCookieJar cookieJar; + private final SharedPrefsCookiePersistor cookiePersistor; //Used to explicitly edit cookies in cookieJar //Shared Preferences & its keys - private SharedPreferences sharedPrefs; + private final SharedPreferences sharedPrefs; private static final String USERNAME = "Username"; private static final String AVATAR_LINK = "AvatarLink"; private static final String HAS_AVATAR = "HasAvatar"; @@ -109,7 +109,7 @@ public class SessionManager { Elements unreadRepliesLinks = document.select("a[href=https://www.thmmy.gr/smf/index.php?action=unreadreplies]"); - if (unreadRepliesLinks.size()>=2) //Normally it's just == 2, but who knows what can be posted by users + if (unreadRepliesLinks.size() >= 2) //Normally it's just == 2, but who knows what can be posted by users { Timber.i("Login successful!"); setPersistentCookieSession(); //Store cookies @@ -289,7 +289,7 @@ public class SessionManager { } @NonNull - private String extractUserName(@NonNull Document doc){ + private String extractUserName(@NonNull Document doc) { //Scribbles2 Theme Elements user = doc.select("div[id=myuser] > h3"); String userName = null; @@ -301,8 +301,7 @@ public class SessionManager { Matcher matcher = pattern.matcher(txt); if (matcher.find()) userName = matcher.group(1); - } - else { + } else { //Helios_Multi and SMF_oneBlue user = doc.select("td.smalltext[width=100%] b"); if (user.size() == 1) @@ -314,20 +313,20 @@ public class SessionManager { userName = user.first().ownText(); } } - - if(userName != null && !userName.isEmpty()) + + if (userName != null && !userName.isEmpty()) return userName; Timber.e("ParseException", new ParseException("Parsing failed(username extraction)")); - return "User"; //return a default username + return "User"; //return a default username } @Nullable private String extractAvatarLink(@NonNull Document doc) { - Elements avatar = doc.getElementsByClass("avatar"); - if (!avatar.isEmpty()) - return avatar.first().attr("src"); + Elements avatar = doc.getElementsByClass("avatar"); + if (!avatar.isEmpty()) + return avatar.first().attr("src"); Timber.i("Extracting avatar's link failed!"); return null; @@ -337,14 +336,13 @@ public class SessionManager { private String extractLogoutLink(@NonNull Document doc) { Elements logoutLink = doc.select("a[href^=https://www.thmmy.gr/smf/index.php?action=logout;sesc=]"); - if (!logoutLink.isEmpty()) - { + if (!logoutLink.isEmpty()) { String link = logoutLink.first().attr("href"); - if(link != null && !link.isEmpty()) + if (link != null && !link.isEmpty()) return link; } Timber.e("ParseException", new ParseException("Parsing failed(logoutLink extraction)")); - return "https://www.thmmy.gr/smf/index.php?action=logout"; //return a default link + return "https://www.thmmy.gr/smf/index.php?action=logout"; //return a default link } //----------------------------------OTHER FUNCTIONS END----------------------------------------- diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java index cc98fe90..12f0a9e6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java @@ -14,7 +14,7 @@ public class CenterVerticalSpan extends ReplacementSpan { } @Override - public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { + public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom,@NonNull Paint paint) { text = text.subSequence(start, end); Rect charSize = new Rect(); paint.getTextBounds(text.toString(), 0, 1, charSize); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java index 2e8867f5..75a9fa72 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java @@ -1,7 +1,5 @@ package gr.thmmy.mthmmy.utils; -import android.util.Log; - import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java b/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java index fc0e7f65..81c890ad 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java @@ -5,10 +5,10 @@ package gr.thmmy.mthmmy.utils.exceptions; * exception is set, to report to FireBase. */ public class UnknownException extends Exception { - public UnknownException() {} + public UnknownException() { + } - public UnknownException(String message) - { + public UnknownException(String message) { super(message); } } diff --git a/app/src/main/res/layout/activity_topic_quick_reply_row.xml b/app/src/main/res/layout/activity_topic_quick_reply_row.xml index 602654ee..870d0a8c 100644 --- a/app/src/main/res/layout/activity_topic_quick_reply_row.xml +++ b/app/src/main/res/layout/activity_topic_quick_reply_row.xml @@ -1,6 +1,7 @@ + android:textSize="10sp" + tools:ignore="SmallSp"/>