Browse Source

refactor: cleanup

develop
Ezerous 3 months ago
parent
commit
8008159c12
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java
  2. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  3. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/create_content/NewTopicTask.java
  4. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  5. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsAdapter.java
  6. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  7. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  8. 4
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  9. 2
      app/src/main/res/values/strings.xml

2
app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java

@ -60,7 +60,7 @@ public class AboutActivity extends BaseActivity {
String versionInfo = ""; String versionInfo = "";
if (gitExists) if (gitExists)
versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash
+ (BuildConfig.IS_CLEAN ? "" : "-dirty") + (BuildConfig.IS_CLEAN ? "" : "~")
+ " "; // Avoid last letter being cut in italics styled TextView + " "; // Avoid last letter being cut in italics styled TextView
//Initialize appbar //Initialize appbar

6
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -219,7 +219,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
try { try {
Elements pages = boardPage.select("table.tborder td.catbg[height=30]").first() Elements pages = boardPage.select("table.tborder td.catbg[height=30]").first()
.select("a.navPages"); .select("a.navPages");
if (pages != null && !pages.isEmpty()) { if (!pages.isEmpty()) {
for (Element page : pages) { for (Element page : pages) {
if (Integer.parseInt(page.text()) > numberOfPages) if (Integer.parseInt(page.text()) > numberOfPages)
numberOfPages = Integer.parseInt(page.text()); numberOfPages = Integer.parseInt(page.text());
@ -240,7 +240,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
if (pagesLoaded == 0) { //Finds sub boards if (pagesLoaded == 0) { //Finds sub boards
Elements subBoardRows = boardPage.select("div.tborder>table>tbody>tr"); Elements subBoardRows = boardPage.select("div.tborder>table>tbody>tr");
if (subBoardRows != null && !subBoardRows.isEmpty()) { if (!subBoardRows.isEmpty()) {
for (Element subBoardRow : subBoardRows) { for (Element subBoardRow : subBoardRows) {
if (!Objects.equals(subBoardRow.className(), "titlebg")) { if (!Objects.equals(subBoardRow.className(), "titlebg")) {
String pUrl = "", pTitle = "", pMods = "", pStats = "", String pUrl = "", pTitle = "", pMods = "", pStats = "",
@ -314,7 +314,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
} }
//Finds topics //Finds topics
Elements topicRows = boardPage.select("table.bordercolor>tbody>tr"); Elements topicRows = boardPage.select("table.bordercolor>tbody>tr");
if (topicRows != null && !topicRows.isEmpty()) { if (!topicRows.isEmpty()) {
for (Element topicRow : topicRows) { for (Element topicRow : topicRows) {
if (!Objects.equals(topicRow.className(), "titlebg")) { if (!Objects.equals(topicRow.className(), "titlebg")) {
String pTopicUrl, pSubject, pStarter, pLastUser = "", pLastPostDateTime = "00:00:00", pLastPost, pLastPostUrl, pStats; String pTopicUrl, pSubject, pStarter, pLastUser = "", pLastPostDateTime = "00:00:00", pLastPost, pLastPostUrl, pStats;

14
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 org.jsoup.nodes.Document;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
import gr.thmmy.mthmmy.activities.topic.Posting;
import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseApplication;
import okhttp3.MultipartBody; import okhttp3.MultipartBody;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
@ -73,14 +75,12 @@ public class NewTopicTask extends AsyncTask<String, Void, Boolean> {
try { try {
client.newCall(post).execute(); client.newCall(post).execute();
Response response2 = client.newCall(post).execute(); Response response2 = client.newCall(post).execute();
switch (replyStatus(response2)) { if (Objects.requireNonNull(replyStatus(response2)) == Posting.REPLY_STATUS.SUCCESSFUL) {
case SUCCESSFUL: BaseApplication.getInstance().logFirebaseAnalyticsEvent("new_topic_creation", null);
BaseApplication.getInstance().logFirebaseAnalyticsEvent("new_topic_creation", null); return true;
return true;
default:
Timber.e("Malformed post. Request string: %s", post.toString());
return false;
} }
Timber.e("Malformed post. Request string: %s", post.toString());
return false;
} catch (IOException e) { } catch (IOException e) {
return false; return false;
} }

9
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; type = Download.DownloadItemType.DOWNLOADS_FILE;
Elements pages = downloadPage.select("a.navPages"); Elements pages = downloadPage.select("a.navPages");
if (pages != null) { for (Element page : pages) {
for (Element page : pages) { int pageNumber = Integer.parseInt(page.text());
int pageNumber = Integer.parseInt(page.text()); if (pageNumber > numberOfPages) numberOfPages = pageNumber;
if (pageNumber > numberOfPages) numberOfPages = pageNumber;
}
} }
else numberOfPages = 1;
Elements rows = downloadPage.select("table.tborder>tbody>tr"); Elements rows = downloadPage.select("table.tborder>tbody>tr");
if (type == Download.DownloadItemType.DOWNLOADS_CATEGORY) { if (type == Download.DownloadItemType.DOWNLOADS_CATEGORY) {

3
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.Download;
import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyFile;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber;
class DownloadsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { class DownloadsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final int VIEW_TYPE_DOWNLOAD = 0; private final int VIEW_TYPE_DOWNLOAD = 0;
@ -134,7 +135,7 @@ class DownloadsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
((BaseActivity) context).downloadFile(new ThmmyFile( ((BaseActivity) context).downloadFile(new ThmmyFile(
new URL(download.getUrl()), download.getFileName(), null)); new URL(download.getUrl()), download.getFileName(), null));
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Timber.e(e, "MalformedURLException");
} }
}); });

7
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.LinearLayout;
import android.widget.Toast; import android.widget.Toast;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentPagerAdapter;
@ -228,11 +229,11 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
public void updateTabIcon(int position) { public void updateTabIcon(int position) {
if (position >= tabLayout.getTabCount()) return; if (position >= tabLayout.getTabCount()) return;
if (position == 0) 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) 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) 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() { private void updateTabIcons() {

2
app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java

@ -209,7 +209,7 @@ public class ForumFragment extends BaseFragment {
@Override @Override
protected ArrayList<Category> parse(Document document, Response response) throws ParseException { protected ArrayList<Category> parse(Document document, Response response) throws ParseException {
Elements categoryBlocks = document.select(".tborder:not([style])>table[cellpadding=5]"); Elements categoryBlocks = document.select(".tborder:not([style])>table[cellpadding=5]");
if (categoryBlocks.size() != 0) { if (!categoryBlocks.isEmpty()) {
ArrayList<Category> fetchedCategories = new ArrayList<>(); ArrayList<Category> fetchedCategories = new ArrayList<>();
for (Element categoryBlock : categoryBlocks) { for (Element categoryBlock : categoryBlocks) {
Element categoryElement = categoryBlock.select("td[colspan=2]>[name]").first(); Element categoryElement = categoryBlock.select("td[colspan=2]>[name]").first();

4
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.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; // import android.text.Html;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button; 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.profile.ProfileActivity;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
import gr.thmmy.mthmmy.activities.shoutbox.ShoutboxActivity; 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.Bookmark;
import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyFile;
import gr.thmmy.mthmmy.services.DownloadHelper; import gr.thmmy.mthmmy.services.DownloadHelper;

2
app/src/main/res/values/strings.xml

@ -182,7 +182,7 @@
<string name="pref_summary_display_relative_time">Considering that you haven\'t set some weird custom time format</string> <string name="pref_summary_display_relative_time">Considering that you haven\'t set some weird custom time format</string>
<string name="pref_app_use_greek_timezone_key">pref_app_use_greek_timezone_key</string> <string name="pref_app_use_greek_timezone_key">pref_app_use_greek_timezone_key</string>
<string name="pref_title_use_greek_timezone">Use Greek timezone</string> <string name="pref_title_use_greek_timezone">Use Greek timezone</string>
<string name="pref_summary_use_greek_timezone">For relative time only. Disable this if you have also set a custom displayed time in your profile</string> <string name="pref_summary_use_greek_timezone">For relative time only. Disable this if you have also set a custom displayed time in your profile.</string>
<string name="pref_app_display_compact_tabs_key">pref_app_display_compact_tabs_key</string> <string name="pref_app_display_compact_tabs_key">pref_app_display_compact_tabs_key</string>
<string name="pref_title_display_compact_tabs">Display compact tabs</string> <string name="pref_title_display_compact_tabs">Display compact tabs</string>
<string name="pref_summary_display_compact_tabs">Home screen tabs will occupy less space</string> <string name="pref_summary_display_compact_tabs">Home screen tabs will occupy less space</string>

Loading…
Cancel
Save