diff --git a/README.md b/README.md index 7d0fd105..d0abfee1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ A mobile app for [thmmy.gr](https://www.thmmy.gr). ## Requirements -mTHMMY can be installed on any smartphone with Android 5.0 Lollipop or newer. +mTHMMY can be installed on any smartphone with Android 6.0 (M) or newer. ## Download diff --git a/app/build.gradle b/app/build.gradle index 777af2d6..2245efc8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,13 +7,12 @@ apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' android { - compileSdkVersion 31 - buildToolsVersion = '30.0.2' + compileSdkVersion 33 defaultConfig { applicationId "gr.thmmy.mthmmy" - minSdkVersion 21 - targetSdkVersion 30 + minSdkVersion 23 + targetSdkVersion 33 versionCode 31 versionName "2.1.0" archivesBaseName = "mTHMMY-v$versionName" @@ -45,6 +44,8 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + + namespace 'gr.thmmy.mthmmy' } def firebaseReleaseProjectId = "mthmmy-release-3aef0" @@ -92,7 +93,7 @@ dependencies { implementation 'com.google.firebase:firebase-crashlytics' implementation 'com.google.firebase:firebase-messaging' implementation 'com.google.code.gson:gson:2.8.8' - implementation 'com.snatik:storage:2.1.0' + implementation 'com.snatik:storage:2.1.0' //TODO: Replace (e.g. with https://github.com/anggrayudi/SimpleStorage) implementation 'com.squareup.okhttp3:okhttp:3.14.9' implementation 'org.jsoup:jsoup:1.14.2' implementation 'joda-time:joda-time:2.10.10' diff --git a/app/gradle/grgit.gradle b/app/gradle/grgit.gradle index da262dd7..53ae4204 100644 --- a/app/gradle/grgit.gradle +++ b/app/gradle/grgit.gradle @@ -2,11 +2,11 @@ import org.ajoberstar.grgit.Grgit buildscript { repositories { - jcenter() + mavenCentral() } dependencies { - classpath 'org.ajoberstar.grgit:grgit-core:3.1.1' + classpath 'org.ajoberstar.grgit:grgit-core:5.0.0' } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index be988ad9..db813036 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,11 +1,11 @@ + diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java index bd75f6d5..5c2d3e18 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java @@ -1,5 +1,13 @@ package gr.thmmy.mthmmy.activities; +import static gr.thmmy.mthmmy.session.SessionManager.BANNED_USER; +import static gr.thmmy.mthmmy.session.SessionManager.CONNECTION_ERROR; +import static gr.thmmy.mthmmy.session.SessionManager.EXCEPTION; +import static gr.thmmy.mthmmy.session.SessionManager.FAILURE; +import static gr.thmmy.mthmmy.session.SessionManager.SUCCESS; +import static gr.thmmy.mthmmy.session.SessionManager.WRONG_PASSWORD; +import static gr.thmmy.mthmmy.session.SessionManager.WRONG_USER; + import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; @@ -22,14 +30,6 @@ import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseApplication; -import static gr.thmmy.mthmmy.session.SessionManager.BANNED_USER; -import static gr.thmmy.mthmmy.session.SessionManager.CONNECTION_ERROR; -import static gr.thmmy.mthmmy.session.SessionManager.EXCEPTION; -import static gr.thmmy.mthmmy.session.SessionManager.FAILURE; -import static gr.thmmy.mthmmy.session.SessionManager.SUCCESS; -import static gr.thmmy.mthmmy.session.SessionManager.WRONG_PASSWORD; -import static gr.thmmy.mthmmy.session.SessionManager.WRONG_USER; - public class LoginActivity extends BaseActivity { //-----------------------------------------CLASS VARIABLES------------------------------------------ diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java index a7eac058..6f8a33ce 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java @@ -1,5 +1,10 @@ package gr.thmmy.mthmmy.activities.board; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; + import android.content.Context; import android.content.Intent; import android.graphics.Typeface; @@ -22,11 +27,6 @@ import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.Topic; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; - /** * {@link RecyclerView.Adapter} that can display a {@link gr.thmmy.mthmmy.model.Board}. */ diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java index c8f70b5e..09c918f5 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java @@ -1,5 +1,10 @@ package gr.thmmy.mthmmy.activities.bookmarks; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; + import android.content.Intent; import android.os.Bundle; import android.widget.Toast; @@ -23,11 +28,6 @@ import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.Bookmark; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; - public class BookmarksActivity extends BaseActivity { private static final String TOPIC_URL = forumUrl + "index.php?topic="; private static final String BOARD_URL = forumUrl + "index.php?board="; 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 7925d315..5255dc15 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 @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.activities.create_content; +import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; + import android.os.AsyncTask; import org.jsoup.Jsoup; @@ -15,8 +17,6 @@ import okhttp3.RequestBody; import okhttp3.Response; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; - public class NewTopicTask extends AsyncTask { private NewTopicTaskCallbacks listener; 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 0b6196e4..0ffdaf9c 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 @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.activities.downloads; +import static gr.thmmy.mthmmy.activities.upload.UploadActivity.BUNDLE_UPLOAD_CATEGORY; + import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; @@ -37,8 +39,6 @@ import okhttp3.Request; import okhttp3.Response; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.upload.UploadActivity.BUNDLE_UPLOAD_CATEGORY; - public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.OnLoadMoreListener { /** * The key to use when putting download's url String to {@link DownloadsActivity}'s Bundle. 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 19413074..293fa457 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 @@ -1,9 +1,12 @@ package gr.thmmy.mthmmy.activities.downloads; +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_TITLE; +import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_URL; + import android.content.Context; import android.content.Intent; import android.graphics.Typeface; -import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -25,10 +28,6 @@ import gr.thmmy.mthmmy.model.Download; import gr.thmmy.mthmmy.model.ThmmyFile; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_TITLE; -import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_URL; - class DownloadsAdapter extends RecyclerView.Adapter { private final int VIEW_TYPE_DOWNLOAD = 0; private final int VIEW_TYPE_LOADING = 1; @@ -132,13 +131,7 @@ class DownloadsAdapter extends RecyclerView.Adapter { } }); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - downloadViewHolder.upperLinear.setBackgroundColor(context.getResources().getColor(R.color.background, null)); - } - else { - //noinspection deprecation - downloadViewHolder.upperLinear.setBackgroundColor(context.getResources().getColor(R.color.background)); - } + downloadViewHolder.upperLinear.setBackgroundColor(context.getResources().getColor(R.color.background, null)); downloadViewHolder.informationExpandable.setVisibility(View.VISIBLE); downloadViewHolder.informationExpandableBtn.setVisibility(View.GONE); downloadViewHolder.informationExpandableBtn.setEnabled(false); 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 34ddfc59..1b6468d1 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 @@ -1,5 +1,15 @@ package gr.thmmy.mthmmy.activities.main; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; +import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_TITLE; +import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; + import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; @@ -37,16 +47,6 @@ import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.TopicSummary; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; -import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_TITLE; -import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; - public class MainActivity extends BaseActivity implements RecentFragment.RecentFragmentInteractionListener, ForumFragment.ForumFragmentInteractionListener, UnreadFragment.UnreadFragmentInteractionListener { //-----------------------------------------CLASS VARIABLES------------------------------------------ diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java index 7b10e79d..32412749 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java @@ -244,7 +244,7 @@ public class UnreadFragment extends BaseFragment { if (loadedPages < numberOfPages) { unreadTask = new UnreadTask(this::onUnreadTaskStarted, UnreadFragment.this::onUnreadTaskCancelled, this::onUnreadTaskFinished); assert SessionManager.unreadUrl != null; - unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl.toString() + ";start=" + loadedPages * 20); + unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl + ";start=" + loadedPages * 20); } else hideProgressUI(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java index 7af974d8..5de4c1c1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java @@ -1,5 +1,11 @@ package gr.thmmy.mthmmy.activities.profile; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; +import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.emojiTagToHtml; +import static gr.thmmy.mthmmy.utils.ui.GlideUtils.isValidContextForGlide; +import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage; + import android.content.Intent; import android.graphics.Color; import android.graphics.Typeface; @@ -54,12 +60,6 @@ import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import okhttp3.Response; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; -import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.emojiTagToHtml; -import static gr.thmmy.mthmmy.utils.ui.GlideUtils.isValidContextForGlide; -import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage; - /** * Activity for user profile. When creating an Intent of this activity you need to bundle a String * containing this user's profile url using the key {@link #BUNDLE_PROFILE_URL}, a String containing diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java index 03bd5ba1..6ea1d4e4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java @@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.profile.stats; import android.graphics.Color; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -230,7 +229,6 @@ public class StatsFragment extends Fragment { private void populateLayout() { onLoadingListener.onLoadingStats(true); - ; ((TextView) mainContent.findViewById(R.id.general_statistics_title)) .setText(generalStatisticsTitle); ((TextView) mainContent.findViewById(R.id.general_statistics)) @@ -296,14 +294,9 @@ public class StatsFragment extends Fragment { mostPopularBoardsByPostsChartYAxis.setGranularity(1f); BarDataSet mostPopularBoardsByPostsDataSet = new BarDataSet(mostPopularBoardsByPosts, null); - if (isAdded()) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - mostPopularBoardsByPostsDataSet.setColors(getResources().getColor(R.color.accent, null)); - } - else - //noinspection deprecation - mostPopularBoardsByPostsDataSet.setColors(getResources().getColor(R.color.accent)); - } + if (isAdded()) + mostPopularBoardsByPostsDataSet.setColors(getResources().getColor(R.color.accent, null)); + mostPopularBoardsByPostsDataSet.setDrawValues(false); mostPopularBoardsByPostsDataSet.setValueTextColor(Color.WHITE); @@ -338,14 +331,8 @@ public class StatsFragment extends Fragment { mostPopularBoardsByActivityChartYAxis.setLabelCount(10, false); BarDataSet mostPopularBoardsByActivityDataSet = new BarDataSet(mostPopularBoardsByActivity, null); - if (isAdded()) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - mostPopularBoardsByActivityDataSet.setColors(getResources().getColor(R.color.accent, null)); - } - else - //noinspection deprecation - mostPopularBoardsByActivityDataSet.setColors(getResources().getColor(R.color.accent)); - } + if (isAdded()) + mostPopularBoardsByActivityDataSet.setColors(getResources().getColor(R.color.accent, null)); mostPopularBoardsByActivityDataSet.setDrawValues(false); mostPopularBoardsByActivityDataSet.setValueTextColor(Color.WHITE); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java index 1b1e99c4..034f1f2a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java @@ -189,10 +189,7 @@ public class SummaryFragment extends Fragment { && value.contains("@")) || key.startsWith("Website") || key.startsWith("Ιστοτόπος")) textView.setMovementMethod(LinkMovementMethod.getInstance()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - textView.setTextColor(getResources().getColor(R.color.primary_text, null)); - else - textView.setTextColor(getResources().getColor(R.color.primary_text)); + textView.setTextColor(getResources().getColor(R.color.primary_text, null)); String textViewContent = "" + key + " " + value; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java index a639c199..355fa8eb 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.activities.settings; +import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -22,8 +24,6 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseApplication; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB; - public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { private enum PREFS_TYPE { NOT_SET, USER, GUEST diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java index b2bdff0a..425ad188 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java @@ -1,5 +1,13 @@ package gr.thmmy.mthmmy.activities.shoutbox; +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; + import android.content.Context; import android.content.Intent; import android.graphics.Color; @@ -24,14 +32,6 @@ import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.views.CustomRecyclerView; import gr.thmmy.mthmmy.views.ReactiveWebView; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; - public class ShoutAdapter extends CustomRecyclerView.Adapter { private Context context; private Shout[] shouts; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index bd47aa4d..9b953d0b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.activities.topic; +import static gr.thmmy.mthmmy.services.NotificationService.NEW_POST_TAG; + import android.annotation.SuppressLint; import android.app.NotificationManager; import android.content.ClipData; @@ -60,8 +62,6 @@ import gr.thmmy.mthmmy.views.editorview.EmojiKeyboard; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import timber.log.Timber; -import static gr.thmmy.mthmmy.services.NotificationService.NEW_POST_TAG; - /** * Activity for parsing and rendering topics. When creating an Intent of this activity you need to * bundle a String containing this topic's url using the key {@link #BUNDLE_TOPIC_URL}. diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 076414f8..ea5ce606 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -1,5 +1,18 @@ package gr.thmmy.mthmmy.activities.topic; +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; +import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_WHITE; +import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_YELLOW; +import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager; +import static gr.thmmy.mthmmy.utils.FileUtils.faIconFromFilename; +import static gr.thmmy.mthmmy.utils.ui.GlideUtils.isValidContextForGlide; + import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; @@ -77,19 +90,6 @@ import gr.thmmy.mthmmy.views.editorview.EditorView; import gr.thmmy.mthmmy.views.editorview.IEmojiKeyboard; import timber.log.Timber; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; -import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_WHITE; -import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_YELLOW; -import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager; -import static gr.thmmy.mthmmy.utils.FileUtils.faIconFromFilename; -import static gr.thmmy.mthmmy.utils.ui.GlideUtils.isValidContextForGlide; - /** * Custom {@link RecyclerView.Adapter} used for topics. */ @@ -393,11 +393,7 @@ class TopicAdapter extends RecyclerView.Adapter { if (currentPost.getAttachedFiles() != null && currentPost.getAttachedFiles().size() != 0) { int filesTextColor; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - filesTextColor = context.getResources().getColor(R.color.accent, null); - } - else - filesTextColor = context.getResources().getColor(R.color.accent); + filesTextColor = context.getResources().getColor(R.color.accent, null); for (final ThmmyFile attachedFile : currentPost.getAttachedFiles()) { final TextView attached = new TextView(context); @@ -417,11 +413,8 @@ class TopicAdapter extends RecyclerView.Adapter { } if (currentPost.getLastEdit() != null && currentPost.getLastEdit().length() > 0) { int lastEditTextColor; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - lastEditTextColor = context.getResources().getColor(R.color.white, null); - } - else - lastEditTextColor = context.getResources().getColor(R.color.white); + + lastEditTextColor = context.getResources().getColor(R.color.white, null); final TextView lastEdit = new TextView(context); lastEdit.setTextSize(12f); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java index 2d49a5a5..8e8645f0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.activities.topic.tasks; +import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; + import android.os.AsyncTask; import java.io.IOException; @@ -12,8 +14,6 @@ import okhttp3.RequestBody; import okhttp3.Response; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; - public class EditTask extends AsyncTask { private EditTaskCallbacks listener; private int position; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java index 7da9e5cb..19ee5ba5 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.activities.topic.tasks; +import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; + import android.os.AsyncTask; import java.io.IOException; @@ -13,8 +15,6 @@ import okhttp3.RequestBody; import okhttp3.Response; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; - public class ReplyTask extends AsyncTask { private ReplyTaskCallbacks listener; private boolean includeAppSignature; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java index cfb27028..3f64a81c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java @@ -1,5 +1,15 @@ package gr.thmmy.mthmmy.activities.upload; +import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.UPLOADING_APP_SIGNATURE_ENABLE_KEY; +import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_COURSE_GREEKLISH_NAME; +import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_COURSE_MINIFIED_NAME; +import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_COURSE_NAME; +import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER; +import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_DESCRIPTION; +import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_FILENAME; +import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_TITLE; +import static gr.thmmy.mthmmy.utils.FileUtils.faIconFromFilename; + import android.app.Activity; import android.app.PendingIntent; import android.content.Context; @@ -74,16 +84,6 @@ import gr.thmmy.mthmmy.views.AppCompatSpinnerWithoutDefault; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.UPLOADING_APP_SIGNATURE_ENABLE_KEY; -import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_COURSE_GREEKLISH_NAME; -import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_COURSE_MINIFIED_NAME; -import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_COURSE_NAME; -import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER; -import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_DESCRIPTION; -import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_FILENAME; -import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_TITLE; -import static gr.thmmy.mthmmy.utils.FileUtils.faIconFromFilename; - public class UploadActivity extends BaseActivity { /** * The key to use when putting upload's category String to {@link UploadActivity}'s Bundle. diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/multipart/MultipartUploadTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/multipart/MultipartUploadTask.java index d1b5f7b5..655176be 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/multipart/MultipartUploadTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/multipart/MultipartUploadTask.java @@ -11,6 +11,7 @@ import net.gotev.uploadservice.http.BodyWriter; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; /** * Extended MultipartUploadTask from gotev/android-upload-service to include a fix for the parameter @@ -21,7 +22,7 @@ public class MultipartUploadTask extends HttpUploadTask { static final String PARAM_UTF8_CHARSET = "multipartUtf8Charset"; private static final String BOUNDARY_SIGNATURE = "-------AndroidUploadService"; - private static final Charset US_ASCII = Charset.forName("US-ASCII"); + private static final Charset US_ASCII = StandardCharsets.US_ASCII; private static final String NEW_LINE = "\r\n"; private static final String TWO_HYPHENS = "--"; @@ -42,7 +43,7 @@ public class MultipartUploadTask extends HttpUploadTask { boundaryBytes = (TWO_HYPHENS + boundary + NEW_LINE).getBytes(US_ASCII); trailerBytes = (TWO_HYPHENS + boundary + TWO_HYPHENS + NEW_LINE).getBytes(US_ASCII); charset = intent.getBooleanExtra(PARAM_UTF8_CHARSET, false) ? - Charset.forName("UTF-8") : US_ASCII; + StandardCharsets.UTF_8 : US_ASCII; httpParams.addHeader("Connection", "Keep-Alive"); httpParams.addHeader("Content-Type", "multipart/form-data; boundary=" + boundary); 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 e983bb8d..7c3a009c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -1,5 +1,15 @@ package gr.thmmy.mthmmy.base; +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_TITLE; +import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; +import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB; +import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR; +import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType; + import android.Manifest; import android.app.ProgressDialog; import android.content.Context; @@ -8,7 +18,6 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.net.Uri; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.view.MenuItem; import android.view.View; @@ -67,16 +76,6 @@ import ru.noties.markwon.Markwon; import ru.noties.markwon.SpannableConfiguration; import timber.log.Timber; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_TITLE; -import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; -import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB; -import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR; -import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType; - public abstract class BaseActivity extends AppCompatActivity { // Client & Cookies protected static OkHttpClient client; @@ -695,29 +694,23 @@ public abstract class BaseActivity extends AppCompatActivity { //True if permissions are OK protected boolean checkPerms() { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { - Timber.i("Checking storage permissions."); - String[] PERMISSIONS_STORAGE = { - Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE}; - - return !(checkSelfPermission(PERMISSIONS_STORAGE[0]) == PackageManager.PERMISSION_DENIED || - checkSelfPermission(PERMISSIONS_STORAGE[1]) == PackageManager.PERMISSION_DENIED); - } - return true; + Timber.i("Checking storage permissions."); + String[] PERMISSIONS_STORAGE = { + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE}; + + return !(checkSelfPermission(PERMISSIONS_STORAGE[0]) == PackageManager.PERMISSION_DENIED || + checkSelfPermission(PERMISSIONS_STORAGE[1]) == PackageManager.PERMISSION_DENIED); } //Display popup for user to grant permission protected void requestPerms(int code) { - //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, - Manifest.permission.WRITE_EXTERNAL_STORAGE}; - - Timber.i("Requesting storage permissions (code %d).", code); - requestPermissions(PERMISSIONS_STORAGE, code); - } + String[] PERMISSIONS_STORAGE = { + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE}; + + Timber.i("Requesting storage permissions (code %d).", code); + requestPermissions(PERMISSIONS_STORAGE, code); } @Override diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java index e38f4472..228b67d3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -1,5 +1,10 @@ package gr.thmmy.mthmmy.base; +import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DISPLAY_COMPACT_TABS; +import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DISPLAY_RELATIVE_TIME; +import static gr.thmmy.mthmmy.activities.upload.UploadActivity.firebaseConfigUploadsCoursesKey; +import static gr.thmmy.mthmmy.utils.io.ResourceUtils.readJSONResourceToString; + import android.app.Application; import android.content.Context; import android.content.SharedPreferences; @@ -45,16 +50,16 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DISPLAY_COMPACT_TABS; -import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DISPLAY_RELATIVE_TIME; -import static gr.thmmy.mthmmy.activities.upload.UploadActivity.firebaseConfigUploadsCoursesKey; -import static gr.thmmy.mthmmy.utils.io.ResourceUtils.readJSONResourceToString; - public class BaseApplication extends Application implements Executor{ private static BaseApplication baseApplication; //BaseApplication singleton private CrashReportingTree crashReportingTree; + //Global variables + private static String forumUrl; + private static String forumHost; + private static String forumHostSimple; + //Firebase private static String firebaseProjectId; private FirebaseAnalytics firebaseAnalytics; @@ -71,27 +76,6 @@ public class BaseApplication extends Application implements Executor{ private static float widthDp; private static int widthPxl, heightPxl; - private static String forumUrl; - private static String forumHost; - private static String forumHostSimple; - - public static BaseApplication getInstance() { - return baseApplication; - } - - public static String getForumUrl() { - return forumUrl; - } - - public static String getForumHost() { - return forumHost; - } - - - public static String getForumHostSimple() { - return forumHostSimple; - } - @Override public void onCreate() { super.onCreate(); @@ -231,6 +215,22 @@ public class BaseApplication extends Application implements Executor{ //-------------------- Getters -------------------- + public static BaseApplication getInstance() { + return baseApplication; + } + + public static String getForumUrl() { + return forumUrl; + } + + public static String getForumHost() { + return forumHost; + } + + public static String getForumHostSimple() { + return forumHostSimple; + } + public Context getContext() { return getApplicationContext(); } 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 862b3a61..7c2d4ad0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java @@ -31,7 +31,7 @@ public abstract class BaseFragment extends Fragment { if (context instanceof FragmentInteractionListener) fragmentInteractionListener = (FragmentInteractionListener) context; else - throw new RuntimeException(context.toString() + throw new RuntimeException(context + " must implement OnFragmentInteractionListener"); } 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 46142bbf..851da46b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Category.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Category.java @@ -1,12 +1,12 @@ package gr.thmmy.mthmmy.model; +import static android.R.attr.id; + import com.bignerdranch.expandablerecyclerview.model.Parent; import java.util.ArrayList; import java.util.List; -import static android.R.attr.id; - public class Category implements Parent { private final String title; private final String categoryURL; diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java index b98b21d3..77a006fa 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadHelper.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.services; +import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType; + import android.app.DownloadManager; import android.content.Context; import android.net.Uri; @@ -15,8 +17,6 @@ import gr.thmmy.mthmmy.model.ThmmyFile; import okhttp3.Cookie; import timber.log.Timber; -import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType; - /** * Not an actual service, but simply a helper class that adds a download to the queue of Android's * DownloadManager system service. diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java index 07ea15af..ad8b23be 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java @@ -1,5 +1,17 @@ package gr.thmmy.mthmmy.services; +import static androidx.core.app.NotificationCompat.PRIORITY_MAX; +import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.NOTIFICATION_LED_KEY; +import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.NOTIFICATION_VIBRATION_KEY; +import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SELECTED_RINGTONE; +import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SETTINGS_SHARED_PREFS; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; +import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKED_BOARDS_KEY; +import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKED_TOPICS_KEY; +import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKS_SHARED_PREFS; +import static gr.thmmy.mthmmy.model.Bookmark.matchExistsById; + import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -13,7 +25,6 @@ import android.os.Build; import android.os.Bundle; import android.service.notification.StatusBarNotification; -import androidx.annotation.RequiresApi; import androidx.core.app.NotificationCompat; import androidx.preference.PreferenceManager; @@ -34,18 +45,6 @@ import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.PostNotification; import timber.log.Timber; -import static androidx.core.app.NotificationCompat.PRIORITY_MAX; -import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.NOTIFICATION_LED_KEY; -import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.NOTIFICATION_VIBRATION_KEY; -import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SELECTED_RINGTONE; -import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SETTINGS_SHARED_PREFS; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; -import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; -import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKED_BOARDS_KEY; -import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKED_TOPICS_KEY; -import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKS_SHARED_PREFS; -import static gr.thmmy.mthmmy.model.Bookmark.matchExistsById; - public class NotificationService extends FirebaseMessagingService { private static final int buildVersion = Build.VERSION.SDK_INT; private static final int disabledNotifiationsLedColor = Color.argb(0, 0, 0, 0); @@ -204,15 +203,13 @@ public class NotificationService extends FirebaseMessagingService { int newPostsCount = 1; - if (buildVersion >= Build.VERSION_CODES.M) { - Notification existingNotification = getActiveNotification(notificationId); - if (existingNotification != null) { - newPostsCount = existingNotification.extras.getInt(NEW_POSTS_COUNT) + 1; - if (isTopicNotification) - contentText = newPostsCount + " new posts"; - else - contentText = newPostsCount + " new posts in " + postNotification.getTopicTitle(); - } + Notification existingNotification = getActiveNotification(notificationId); + if (existingNotification != null) { + newPostsCount = existingNotification.extras.getInt(NEW_POSTS_COUNT) + 1; + if (isTopicNotification) + contentText = newPostsCount + " new posts"; + else + contentText = newPostsCount + " new posts in " + postNotification.getTopicTitle(); } Bundle notificationExtras = new Bundle(); @@ -250,10 +247,7 @@ public class NotificationService extends FirebaseMessagingService { if (buildVersion < Build.VERSION_CODES.O) notificationBuilder.setPriority(PRIORITY_MAX); - boolean createSummaryNotification = false; - if (buildVersion >= Build.VERSION_CODES.M) - createSummaryNotification = otherNotificationsExist(notificationId); - + boolean createSummaryNotification = otherNotificationsExist(notificationId); NotificationCompat.Builder summaryNotificationBuilder = null; if (createSummaryNotification) { @@ -281,7 +275,6 @@ public class NotificationService extends FirebaseMessagingService { notificationManager.notify(SUMMARY_TAG, 0, summaryNotificationBuilder.build()); } - @RequiresApi(api = Build.VERSION_CODES.M) private Notification getActiveNotification(int notificationId) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { @@ -295,7 +288,6 @@ public class NotificationService extends FirebaseMessagingService { return null; } - @RequiresApi(api = Build.VERSION_CODES.M) private boolean otherNotificationsExist(int notificationId) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/session/LogoutTask.java b/app/src/main/java/gr/thmmy/mthmmy/session/LogoutTask.java index 70674dc1..ac952be4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/LogoutTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/LogoutTask.java @@ -1,5 +1,8 @@ package gr.thmmy.mthmmy.session; +import static gr.thmmy.mthmmy.session.SessionManager.baseLogoutLink; +import static gr.thmmy.mthmmy.session.SessionManager.indexUrl; + import org.jsoup.nodes.Document; import org.jsoup.select.Elements; @@ -11,9 +14,6 @@ import gr.thmmy.mthmmy.utils.parsing.ParseException; import okhttp3.Response; import timber.log.Timber; -import static gr.thmmy.mthmmy.session.SessionManager.baseLogoutLink; -import static gr.thmmy.mthmmy.session.SessionManager.indexUrl; - public class LogoutTask extends NetworkTask { private String logoutLink; diff --git a/app/src/main/java/gr/thmmy/mthmmy/session/MarkAsReadTask.java b/app/src/main/java/gr/thmmy/mthmmy/session/MarkAsReadTask.java index e815d295..58940e53 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/MarkAsReadTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/MarkAsReadTask.java @@ -1,5 +1,8 @@ package gr.thmmy.mthmmy.session; +import static gr.thmmy.mthmmy.session.SessionManager.baseMarkAllAsReadLink; +import static gr.thmmy.mthmmy.session.SessionManager.unreadUrl; + import org.jsoup.nodes.Document; import org.jsoup.select.Elements; @@ -9,9 +12,6 @@ import gr.thmmy.mthmmy.utils.networking.NetworkTask; import gr.thmmy.mthmmy.utils.parsing.ParseException; import okhttp3.Response; -import static gr.thmmy.mthmmy.session.SessionManager.baseMarkAllAsReadLink; -import static gr.thmmy.mthmmy.session.SessionManager.unreadUrl; - public class MarkAsReadTask extends NetworkTask { private String markAsReadLink; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java b/app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java index deae8522..4064311b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java @@ -1,13 +1,13 @@ package gr.thmmy.mthmmy.utils; -import androidx.annotation.VisibleForTesting; - import static android.text.format.DateUtils.DAY_IN_MILLIS; import static android.text.format.DateUtils.HOUR_IN_MILLIS; import static android.text.format.DateUtils.MINUTE_IN_MILLIS; import static android.text.format.DateUtils.SECOND_IN_MILLIS; import static android.text.format.DateUtils.YEAR_IN_MILLIS; +import androidx.annotation.VisibleForTesting; + public class DateTimeUtils { private static final long MONTH_IN_MILLIS = 30 * DAY_IN_MILLIS; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java b/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java index 34a4f831..d5ea88e8 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.utils; +import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR; + import android.content.Context; import android.database.Cursor; import android.net.Uri; @@ -10,18 +12,17 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import java.io.File; +import java.util.Locale; import gr.thmmy.mthmmy.R; -import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR; - public class FileUtils { @NonNull public static String getMimeType(@NonNull String fileName) { String type = null; final String extension = MimeTypeMap.getFileExtensionFromUrl(fileName); if (extension != null) - type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase()); + type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase(Locale.ROOT)); if (type == null) type = "*/*"; @@ -39,7 +40,7 @@ public class FileUtils { if (!filename.contains(".")) { return null; } - if (filename.toLowerCase().endsWith(".tar.gz")) { + if (filename.toLowerCase(Locale.ROOT).endsWith(".tar.gz")) { fileExtension = filename.substring(filename.length() - 7); } else { @@ -63,7 +64,9 @@ public class FileUtils { if (uri.getScheme().equals("content")) { try (Cursor cursor = context.getContentResolver().query(uri, null, null, null, null)) { if (cursor != null && cursor.moveToFirst()) { - filename = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); + final int columnIndex = (cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); + if(columnIndex>=0) + filename = cursor.getString(columnIndex); } } } @@ -81,7 +84,9 @@ public class FileUtils { public static long sizeFromUri(Context context, @NonNull Uri uri) { try (Cursor cursor = context.getContentResolver().query(uri, null, null, null, null)) { if (cursor != null && cursor.moveToFirst()) { - return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE)); + final int columnIndex = (cursor.getColumnIndex(OpenableColumns.SIZE)); + if(columnIndex>=0) + return cursor.getLong(columnIndex); } } return -1; @@ -97,7 +102,7 @@ public class FileUtils { */ @NonNull public static String faIconFromFilename(Context context, String filename) { - filename = filename.toLowerCase(); + filename = filename.toLowerCase(Locale.ROOT); if (filename.contains("jpg") || filename.contains("gif") || filename.contains("jpeg") || filename.contains("png")) diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/HTMLUtils.java b/app/src/main/java/gr/thmmy/mthmmy/utils/HTMLUtils.java index cc2773e6..600fd9ee 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/HTMLUtils.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/HTMLUtils.java @@ -1,5 +1,12 @@ package gr.thmmy.mthmmy.utils; +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; +import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -17,13 +24,6 @@ import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.model.ThmmyPage; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; -import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; -import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; - public class HTMLUtils { private HTMLUtils() { } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ui/ImageDownloadDialogBuilder.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ui/ImageDownloadDialogBuilder.java index 0b80d646..da800021 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ui/ImageDownloadDialogBuilder.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ui/ImageDownloadDialogBuilder.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.utils.ui; +import static android.content.Context.CLIPBOARD_SERVICE; + import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -18,8 +20,6 @@ import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.ThmmyFile; import timber.log.Timber; -import static android.content.Context.CLIPBOARD_SERVICE; - public class ImageDownloadDialogBuilder extends AlertDialog.Builder { private static final String[] colors = {"Copy image location", "Save Image"}; diff --git a/app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java b/app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java index c81675e3..a96eeb93 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java @@ -1,5 +1,9 @@ package gr.thmmy.mthmmy.views; +import static android.content.Context.CLIPBOARD_SERVICE; +import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.VIDEO_ID_PARAMETER; +import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage; + import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -13,10 +17,6 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.utils.ui.ImageDownloadDialogBuilder; -import static android.content.Context.CLIPBOARD_SERVICE; -import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.VIDEO_ID_PARAMETER; -import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage; - public class ReactiveWebView extends WebView { private final static long MAX_TOUCH_DURATION = 100; private final Context context; diff --git a/app/src/main/java/gr/thmmy/mthmmy/views/RelativeTimeTextView.java b/app/src/main/java/gr/thmmy/mthmmy/views/RelativeTimeTextView.java index b0678633..f6517228 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/views/RelativeTimeTextView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/views/RelativeTimeTextView.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.views; +import static gr.thmmy.mthmmy.utils.DateTimeUtils.getRelativeTimeSpanString; + import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; @@ -15,8 +17,6 @@ import java.lang.ref.WeakReference; import gr.thmmy.mthmmy.R; -import static gr.thmmy.mthmmy.utils.DateTimeUtils.getRelativeTimeSpanString; - /** * A modified version of https://github.com/curioustechizen/android-ago */ diff --git a/app/src/main/java/gr/thmmy/mthmmy/views/editorview/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/views/editorview/EditorView.java index b5c65f0a..f3831397 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/views/editorview/EditorView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/views/editorview/EditorView.java @@ -8,7 +8,6 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.AsyncTask; -import android.os.Build; import android.text.Editable; import android.text.TextUtils; import android.util.AttributeSet; @@ -201,24 +200,24 @@ public class EditorView extends LinearLayout implements EmojiInputField { }); } popupWindow.showAsDropDown(view); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - new AsyncTask() { - @Override - protected Void doInBackground(Void... voids) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - Timber.e(e); - } - return null; - } - @Override - protected void onPostExecute(Void aVoid) { - editText.setSelection(selectionStart, selectionEnd); + new AsyncTask() { + @Override + protected Void doInBackground(Void... voids) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + Timber.e(e); } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + editText.setSelection(selectionStart, selectionEnd); + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + break; case R.drawable.ic_format_size: hadTextSelection = editText.hasSelection(); diff --git a/app/src/main/res/layout-v23/activity_topic_overflow_menu.xml b/app/src/main/res/layout-v23/activity_topic_overflow_menu.xml deleted file mode 100644 index 63fd97a2..00000000 --- a/app/src/main/res/layout-v23/activity_topic_overflow_menu.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_topic_overflow_menu.xml b/app/src/main/res/layout/activity_topic_overflow_menu.xml index 2b7f1634..63fd97a2 100644 --- a/app/src/main/res/layout/activity_topic_overflow_menu.xml +++ b/app/src/main/res/layout/activity_topic_overflow_menu.xml @@ -2,13 +2,15 @@ + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 68581bed..98c614f8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Dec 03 14:56:57 EET 2020 +#Sun Apr 02 13:22:00 EEST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip