From 8008159c12d4e6dea461dbb8bd0f70461f969332 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 18 Sep 2024 12:49:32 +0300 Subject: [PATCH] refactor: cleanup --- .../gr/thmmy/mthmmy/activities/AboutActivity.java | 2 +- .../mthmmy/activities/board/BoardActivity.java | 6 +++--- .../activities/create_content/NewTopicTask.java | 14 +++++++------- .../activities/downloads/DownloadsActivity.java | 9 +++------ .../activities/downloads/DownloadsAdapter.java | 3 ++- .../thmmy/mthmmy/activities/main/MainActivity.java | 7 ++++--- .../activities/main/forum/ForumFragment.java | 2 +- .../java/gr/thmmy/mthmmy/base/BaseActivity.java | 4 ++-- app/src/main/res/values/strings.xml | 2 +- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java index b0af3c94..be0977cf 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -60,7 +60,7 @@ public class AboutActivity extends BaseActivity { String versionInfo = ""; if (gitExists) versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash - + (BuildConfig.IS_CLEAN ? "" : "-dirty") + + (BuildConfig.IS_CLEAN ? "" : "~") + " "; // Avoid last letter being cut in italics styled TextView //Initialize appbar diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java index 6a427b53..5a074973 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java @@ -219,7 +219,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo try { Elements pages = boardPage.select("table.tborder td.catbg[height=30]").first() .select("a.navPages"); - if (pages != null && !pages.isEmpty()) { + if (!pages.isEmpty()) { for (Element page : pages) { if (Integer.parseInt(page.text()) > numberOfPages) numberOfPages = Integer.parseInt(page.text()); @@ -240,7 +240,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo if (pagesLoaded == 0) { //Finds sub boards Elements subBoardRows = boardPage.select("div.tborder>table>tbody>tr"); - if (subBoardRows != null && !subBoardRows.isEmpty()) { + if (!subBoardRows.isEmpty()) { for (Element subBoardRow : subBoardRows) { if (!Objects.equals(subBoardRow.className(), "titlebg")) { String pUrl = "", pTitle = "", pMods = "", pStats = "", @@ -314,7 +314,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo } //Finds topics Elements topicRows = boardPage.select("table.bordercolor>tbody>tr"); - if (topicRows != null && !topicRows.isEmpty()) { + if (!topicRows.isEmpty()) { for (Element topicRow : topicRows) { if (!Objects.equals(topicRow.className(), "titlebg")) { String pTopicUrl, pSubject, pStarter, pLastUser = "", pLastPostDateTime = "00:00:00", pLastPost, pLastPostUrl, pStats; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/NewTopicTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/NewTopicTask.java index 5255dc15..2b1abfc1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/NewTopicTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/NewTopicTask.java @@ -8,7 +8,9 @@ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; +import java.util.Objects; +import gr.thmmy.mthmmy.activities.topic.Posting; import gr.thmmy.mthmmy.base.BaseApplication; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; @@ -73,14 +75,12 @@ public class NewTopicTask extends AsyncTask { try { client.newCall(post).execute(); Response response2 = client.newCall(post).execute(); - switch (replyStatus(response2)) { - case SUCCESSFUL: - BaseApplication.getInstance().logFirebaseAnalyticsEvent("new_topic_creation", null); - return true; - default: - Timber.e("Malformed post. Request string: %s", post.toString()); - return false; + if (Objects.requireNonNull(replyStatus(response2)) == Posting.REPLY_STATUS.SUCCESSFUL) { + BaseApplication.getInstance().logFirebaseAnalyticsEvent("new_topic_creation", null); + return true; } + Timber.e("Malformed post. Request string: %s", post.toString()); + return false; } catch (IOException e) { return false; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java index 793a6bba..924c35f4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java @@ -234,13 +234,10 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter. type = Download.DownloadItemType.DOWNLOADS_FILE; Elements pages = downloadPage.select("a.navPages"); - if (pages != null) { - for (Element page : pages) { - int pageNumber = Integer.parseInt(page.text()); - if (pageNumber > numberOfPages) numberOfPages = pageNumber; - } + for (Element page : pages) { + int pageNumber = Integer.parseInt(page.text()); + if (pageNumber > numberOfPages) numberOfPages = pageNumber; } - else numberOfPages = 1; Elements rows = downloadPage.select("table.tborder>tbody>tr"); if (type == Download.DownloadItemType.DOWNLOADS_CATEGORY) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsAdapter.java index b085b1d8..3cb67fdf 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsAdapter.java @@ -28,6 +28,7 @@ import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.Download; import gr.thmmy.mthmmy.model.ThmmyFile; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; +import timber.log.Timber; class DownloadsAdapter extends RecyclerView.Adapter { private final int VIEW_TYPE_DOWNLOAD = 0; @@ -134,7 +135,7 @@ class DownloadsAdapter extends RecyclerView.Adapter { ((BaseActivity) context).downloadFile(new ThmmyFile( new URL(download.getUrl()), download.getFileName(), null)); } catch (MalformedURLException e) { - e.printStackTrace(); + Timber.e(e, "MalformedURLException"); } }); 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 1b6468d1..45363319 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 @@ -18,6 +18,7 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.Toast; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; @@ -228,11 +229,11 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF public void updateTabIcon(int position) { if (position >= tabLayout.getTabCount()) return; if (position == 0) - tabLayout.getTabAt(0).setIcon(getResources().getDrawable(R.drawable.ic_access_time_white_24dp)); + tabLayout.getTabAt(0).setIcon(ContextCompat.getDrawable(this, R.drawable.ic_access_time_white_24dp)); else if (position == 1) - tabLayout.getTabAt(1).setIcon(getResources().getDrawable(R.drawable.ic_forum_white_24dp)); + tabLayout.getTabAt(1).setIcon(ContextCompat.getDrawable(this, R.drawable.ic_forum_white_24dp)); else if (position == 2) - tabLayout.getTabAt(2).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp)); + tabLayout.getTabAt(2).setIcon(ContextCompat.getDrawable(this, R.drawable.ic_fiber_new_white_24dp)); } private void updateTabIcons() { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java index f5851ac0..826a2f9d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java @@ -209,7 +209,7 @@ public class ForumFragment extends BaseFragment { @Override protected ArrayList parse(Document document, Response response) throws ParseException { Elements categoryBlocks = document.select(".tborder:not([style])>table[cellpadding=5]"); - if (categoryBlocks.size() != 0) { + if (!categoryBlocks.isEmpty()) { ArrayList fetchedCategories = new ArrayList<>(); for (Element categoryBlock : categoryBlocks) { Element categoryElement = categoryBlock.select("td[colspan=2]>[name]").first(); 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 2b2d2b4e..4a40e67e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -20,7 +20,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.text.Html; +// import android.text.Html; import android.view.MenuItem; import android.view.View; import android.widget.Button; @@ -62,7 +62,7 @@ import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.activities.shoutbox.ShoutboxActivity; -import gr.thmmy.mthmmy.activities.upload.UploadActivity; +// import gr.thmmy.mthmmy.activities.upload.UploadActivity; import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.services.DownloadHelper; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bd2180ea..777469dc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -182,7 +182,7 @@ Considering that you haven\'t set some weird custom time format pref_app_use_greek_timezone_key Use Greek timezone - For relative time only. Disable this if you have also set a custom displayed time in your profile + For relative time only. Disable this if you have also set a custom displayed time in your profile. pref_app_display_compact_tabs_key Display compact tabs Home screen tabs will occupy less space