From 185cfb181e6c6ba3073f8e6b6ef39e6ee78dcbb1 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Tue, 2 Oct 2018 18:05:11 +0300 Subject: [PATCH 001/104] androidx refactor, bottom navigation --- app/build.gradle | 27 ++++++++-------- app/src/main/AndroidManifest.xml | 2 +- .../mthmmy/activities/AboutActivity.java | 8 ++--- .../mthmmy/activities/LoginActivity.java | 4 +-- .../activities/board/BoardActivity.java | 10 +++--- .../mthmmy/activities/board/BoardAdapter.java | 2 +- .../bookmarks/BoardBookmarksFragment.java | 4 +-- .../bookmarks/BookmarkActivity.java | 13 ++++---- .../bookmarks/TopicBookmarksFragment.java | 6 ++-- .../create_content/CreateContentActivity.java | 2 +- .../downloads/DownloadsActivity.java | 8 ++--- .../downloads/DownloadsAdapter.java | 2 +- .../mthmmy/activities/main/MainActivity.java | 15 +++++---- .../activities/main/forum/ForumAdapter.java | 4 +-- .../activities/main/forum/ForumFragment.java | 6 ++-- .../activities/main/recent/RecentAdapter.java | 4 +-- .../main/recent/RecentFragment.java | 6 ++-- .../activities/main/unread/UnreadAdapter.java | 4 +-- .../main/unread/UnreadFragment.java | 8 ++--- .../activities/profile/ProfileActivity.java | 16 +++++----- .../latestPosts/LatestPostsAdapter.java | 2 +- .../latestPosts/LatestPostsFragment.java | 6 ++-- .../profile/stats/StatsFragment.java | 2 +- .../profile/summary/SummaryFragment.java | 2 +- .../activities/settings/SettingsActivity.java | 2 +- .../activities/settings/SettingsFragment.java | 8 ++--- .../activities/topic/TopicActivity.java | 17 ++++------ .../mthmmy/activities/topic/TopicAdapter.java | 16 +++++----- .../activities/upload/UploadActivity.java | 10 +++--- .../upload/UploadFieldsBuilderActivity.java | 6 ++-- .../activities/upload/UploadsHelper.java | 4 +-- .../gr/thmmy/mthmmy/base/BaseActivity.java | 16 +++++----- .../gr/thmmy/mthmmy/base/BaseApplication.java | 2 +- .../gr/thmmy/mthmmy/base/BaseFragment.java | 4 +-- .../thmmy/mthmmy/editorview/EditorView.java | 12 +++---- .../mthmmy/editorview/EmojiKeyboard.java | 6 ++-- .../editorview/EmojiKeyboardAdapter.java | 6 ++-- .../editorview/FormatButtonsAdapter.java | 6 ++-- .../java/gr/thmmy/mthmmy/model/Bookmark.java | 4 +-- .../main/java/gr/thmmy/mthmmy/model/Post.java | 2 +- .../mthmmy/services/NotificationService.java | 8 ++--- .../thmmy/mthmmy/session/SessionManager.java | 4 +-- .../utils/AppCompatSpinnerWithoutDefault.java | 2 +- .../mthmmy/utils/CenterVerticalSpan.java | 2 +- .../utils/CustomLinearLayoutManager.java | 4 +-- .../mthmmy/utils/CustomRecyclerView.java | 6 ++-- .../java/gr/thmmy/mthmmy/utils/FileUtils.java | 2 +- .../mthmmy/utils/ScrollAwareFABBehavior.java | 10 +++--- .../utils/ScrollAwareLinearBehavior.java | 10 +++--- .../thmmy/mthmmy/viewmodel/BaseViewModel.java | 6 ++-- .../mthmmy/viewmodel/TopicViewModel.java | 2 +- .../res/color/bottom_navigation_selector.xml | 5 +++ .../drawable/ic_access_time_white_24dp.xml | 5 +++ app/src/main/res/drawable/ic_announcement.xml | 6 ++++ .../res/drawable/ic_fiber_new_white_24dp.xml | 5 +++ .../main/res/drawable/ic_forum_white_24dp.xml | 5 +++ .../main/res/layout-v21/activity_profile.xml | 22 ++++++------- .../layout-v21/activity_topic_post_row.xml | 4 +-- app/src/main/res/layout/activity_about.xml | 10 +++--- app/src/main/res/layout/activity_board.xml | 18 +++++------ app/src/main/res/layout/activity_bookmark.xml | 16 +++++----- .../res/layout/activity_create_content.xml | 18 +++++------ .../main/res/layout/activity_downloads.xml | 18 +++++------ app/src/main/res/layout/activity_login.xml | 12 +++---- app/src/main/res/layout/activity_main.xml | 23 +++++++++---- app/src/main/res/layout/activity_profile.xml | 22 ++++++------- app/src/main/res/layout/activity_settings.xml | 10 +++--- app/src/main/res/layout/activity_topic.xml | 16 +++++----- .../res/layout/activity_topic_edit_row.xml | 4 +-- .../main/res/layout/activity_topic_poll.xml | 8 ++--- .../res/layout/activity_topic_post_row.xml | 4 +-- .../layout/activity_topic_quick_reply_row.xml | 4 +-- app/src/main/res/layout/activity_upload.xml | 32 +++++++++---------- .../layout/activity_upload_fields_builder.xml | 28 ++++++++-------- .../main/res/layout/dialog_create_link.xml | 12 +++---- app/src/main/res/layout/editor_view.xml | 12 +++---- app/src/main/res/layout/emoji_keyboard.xml | 4 +-- .../res/layout/emoji_keyboard_grid_cell.xml | 2 +- .../res/layout/format_button_grid_cell.xml | 2 +- .../main/res/layout/fragment_bookmarks.xml | 4 +-- app/src/main/res/layout/fragment_forum.xml | 4 +-- .../main/res/layout/fragment_latest_posts.xml | 4 +-- app/src/main/res/layout/fragment_recent.xml | 4 +-- app/src/main/res/layout/fragment_stats.xml | 4 +-- app/src/main/res/layout/fragment_summary.xml | 4 +-- app/src/main/res/layout/fragment_unread.xml | 4 +-- app/src/main/res/menu/bottom_navigation.xml | 21 ++++++++++++ app/src/main/res/values/strings.xml | 6 ++++ app/src/main/res/xml/app_preferences.xml | 20 ++++++------ gradle.properties | 2 ++ 90 files changed, 405 insertions(+), 339 deletions(-) create mode 100644 app/src/main/res/color/bottom_navigation_selector.xml create mode 100644 app/src/main/res/drawable/ic_access_time_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_announcement.xml create mode 100644 app/src/main/res/drawable/ic_fiber_new_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_forum_white_24dp.xml create mode 100644 app/src/main/res/menu/bottom_navigation.xml diff --git a/app/build.gradle b/app/build.gradle index 5baea52e..f6b7c4fa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,13 +4,13 @@ apply plugin: 'com.android.application' apply plugin: 'io.fabric' android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { vectorDrawables.useSupportLibrary = true applicationId "gr.thmmy.mthmmy" minSdkVersion 19 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 13 versionName "1.4.1" archivesBaseName = "mTHMMY-v$versionName" @@ -25,7 +25,7 @@ android { def date = new Date().format('ddMMyy_HHmmss') archivesBaseName = archivesBaseName + "-$date" // Disable fabric build ID generation for debug builds - ext.enableCrashlytics = false; + ext.enableCrashlytics = false } } @@ -48,15 +48,15 @@ tasks.whenTaskAdded { task -> dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:27.1.1' - implementation 'com.android.support:design:27.1.1' - implementation 'com.android.support:preference-v7:27.1.1' - implementation 'com.android.support:preference-v14:27.1.1' - implementation 'com.android.support:support-v4:27.1.1' - implementation 'com.android.support:cardview-v7:27.1.1' - implementation 'com.android.support:recyclerview-v7:27.1.1' + implementation 'androidx.appcompat:appcompat:1.0.0' + implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.preference:preference:1.0.0' + implementation 'androidx.legacy:legacy-preference-v14:1.0.0' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'androidx.cardview:cardview:1.0.0' + implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'com.google.firebase:firebase-core:16.0.3' - implementation 'com.google.firebase:firebase-messaging:17.3.1' + implementation 'com.google.firebase:firebase-messaging:17.3.2' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' implementation 'com.squareup.okhttp3:okhttp:3.10.0' implementation 'com.squareup.picasso:picasso:2.5.2' @@ -72,10 +72,11 @@ dependencies { implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15' implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated! implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2' - implementation 'com.jakewharton.timber:timber:4.7.0' + implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'net.gotev:uploadservice:3.4.2' implementation 'net.gotev:uploadservice-okhttp:3.4.2' - implementation 'android.arch.lifecycle:extensions:1.1.1' + implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' + implementation 'com.google.android.material:material:1.0.0' } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3b37c299..3e37e398 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -132,7 +132,7 @@ 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 896a5fb5..9b6537c1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -2,10 +2,10 @@ package gr.thmmy.mthmmy.activities; import android.content.pm.ActivityInfo; import android.os.Bundle; -import android.support.design.widget.AppBarLayout; -import android.support.design.widget.CoordinatorLayout; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.AlertDialog; +import com.google.android.material.appbar.AppBarLayout; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.appcompat.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.webkit.WebView; 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 f950a1d3..4a923c52 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java @@ -3,8 +3,8 @@ package gr.thmmy.mthmmy.activities; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; -import android.support.v7.preference.PreferenceManager; -import android.support.v7.widget.AppCompatButton; +import androidx.preference.PreferenceManager; +import androidx.appcompat.widget.AppCompatButton; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; 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 c2541c7a..5747d0b1 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 @@ -4,11 +4,11 @@ import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v7.app.AlertDialog; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import androidx.appcompat.app.AlertDialog; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.View; import android.widget.ImageButton; import android.widget.ProgressBar; 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 09734606..6b0c7267 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 @@ -5,7 +5,7 @@ import android.content.Intent; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java index 6b7dee26..facf9202 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java @@ -4,8 +4,8 @@ import android.app.Activity; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java index 5dce5ed0..414606d3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java @@ -2,11 +2,12 @@ package gr.thmmy.mthmmy.activities.bookmarks; import android.content.Intent; import android.os.Bundle; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.view.ViewPager; +import com.google.android.material.tabs.TabLayout; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.fragment.app.FragmentStatePagerAdapter; +import androidx.viewpager.widget.ViewPager; import android.widget.Toast; import java.util.ArrayList; @@ -104,7 +105,7 @@ public class BookmarkActivity extends BaseActivity { * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. If it becomes too memory intensive, * it may be best to switch to a - * {@link android.support.v4.app.FragmentStatePagerAdapter}. + * {@link FragmentStatePagerAdapter}. */ private class SectionsPagerAdapter extends FragmentPagerAdapter { private final List fragmentList = new ArrayList<>(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java index 7679ad2f..55113ae3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java @@ -5,9 +5,9 @@ import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.graphics.drawable.VectorDrawableCompat; -import android.support.v4.app.Fragment; +import androidx.annotation.NonNull; +import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; +import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java index b0b6a11b..1c260085 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java @@ -4,7 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.design.widget.TextInputLayout; +import com.google.android.material.textfield.TextInputLayout; import android.text.InputType; import android.view.View; import android.view.inputmethod.EditorInfo; 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 e67ed73a..58fdfb17 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 @@ -4,10 +4,10 @@ import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.Menu; import android.view.MenuItem; import android.view.View; 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 34a583e0..5f38aea5 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 @@ -5,7 +5,7 @@ import android.content.Intent; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; 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 4ffc3dff..8a5b4110 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 @@ -4,12 +4,13 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.preference.PreferenceManager; +import com.google.android.material.tabs.TabLayout; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.fragment.app.FragmentStatePagerAdapter; +import androidx.viewpager.widget.ViewPager; +import androidx.preference.PreferenceManager; import android.widget.Toast; import java.util.ArrayList; @@ -160,7 +161,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. If it becomes too memory intensive, * it may be best to switch to a - * {@link android.support.v4.app.FragmentStatePagerAdapter}. + * {@link FragmentStatePagerAdapter}. */ private class SectionsPagerAdapter extends FragmentPagerAdapter { private final List fragmentList = new ArrayList<>(); 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 5b2f4c93..1890ff8f 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 @@ -1,8 +1,8 @@ package gr.thmmy.mthmmy.activities.main.forum; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; 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 a85eca23..5b1aa286 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 @@ -2,9 +2,9 @@ package gr.thmmy.mthmmy.activities.main.forum; import android.os.AsyncTask; import android.os.Bundle; -import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java index de128cb1..7a05cb3e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java @@ -1,8 +1,8 @@ package gr.thmmy.mthmmy.activities.main.recent; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 65b0d315..34175435 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -2,9 +2,9 @@ package gr.thmmy.mthmmy.activities.main.recent; import android.os.AsyncTask; import android.os.Bundle; -import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java index 65100922..826e37fb 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java @@ -1,7 +1,7 @@ package gr.thmmy.mthmmy.activities.main.unread; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; 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 0747b4bf..18ff8039 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 @@ -2,10 +2,10 @@ package gr.thmmy.mthmmy.activities.main.unread; import android.os.AsyncTask; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; +import androidx.annotation.NonNull; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; 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 19680329..ce19849d 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 @@ -7,14 +7,14 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.content.res.ResourcesCompat; -import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatDelegate; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.tabs.TabLayout; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.core.content.res.ResourcesCompat; +import androidx.viewpager.widget.ViewPager; +import androidx.appcompat.app.AppCompatDelegate; import android.text.Spannable; import android.text.SpannableString; import android.text.Spanned; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java index b7162495..31ec223d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java @@ -1,6 +1,6 @@ package gr.thmmy.mthmmy.activities.profile.latestPosts; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index 277b01a0..356fbab7 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -2,9 +2,9 @@ package gr.thmmy.mthmmy.activities.profile.latestPosts; import android.os.AsyncTask; import android.os.Bundle; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; 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 5822d635..2ae7140a 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 @@ -4,7 +4,7 @@ import android.graphics.Color; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.support.v4.app.Fragment; +import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; 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 8993fcf0..a0356cb3 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 @@ -4,7 +4,7 @@ import android.graphics.Color; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.support.v4.app.Fragment; +import androidx.fragment.app.Fragment; import android.text.Html; import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java index 433ba13c..9c1e5f24 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java @@ -1,7 +1,7 @@ package gr.thmmy.mthmmy.activities.settings; import android.os.Bundle; -import android.support.v4.app.FragmentTransaction; +import androidx.fragment.app.FragmentTransaction; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; 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 19a47dd1..bb6c27ca 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 @@ -8,10 +8,10 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import android.provider.Settings; -import android.support.annotation.NonNull; -import android.support.v7.preference.ListPreference; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceFragmentCompat; +import androidx.annotation.NonNull; +import androidx.preference.ListPreference; +import androidx.preference.Preference; +import androidx.preference.PreferenceFragmentCompat; import android.view.View; import java.util.ArrayList; 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 8b581a05..27c28a1c 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 @@ -2,21 +2,20 @@ package gr.thmmy.mthmmy.activities.topic; import android.annotation.SuppressLint; import android.app.NotificationManager; -import android.arch.lifecycle.ViewModelProviders; +import androidx.lifecycle.ViewModelProviders; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.graphics.Rect; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; -import android.support.v4.content.res.ResourcesCompat; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatDelegate; -import android.support.v7.widget.RecyclerView; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; +import androidx.core.content.res.ResourcesCompat; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatDelegate; +import androidx.recyclerview.widget.RecyclerView; import android.text.Spannable; import android.text.SpannableString; import android.text.SpannableStringBuilder; @@ -37,7 +36,6 @@ import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; -import java.util.function.Consumer; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.topic.tasks.EditTask; @@ -60,7 +58,6 @@ import gr.thmmy.mthmmy.viewmodel.TopicViewModel; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import timber.log.Timber; -import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; import static gr.thmmy.mthmmy.services.NotificationService.NEW_POST_TAG; /** 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 13d50f9d..764b0161 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 @@ -2,7 +2,7 @@ package gr.thmmy.mthmmy.activities.topic; import android.annotation.SuppressLint; import android.annotation.TargetApi; -import android.arch.lifecycle.ViewModelProviders; +import androidx.lifecycle.ViewModelProviders; import android.content.Context; import android.content.Intent; import android.graphics.Color; @@ -11,12 +11,12 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.content.res.ResourcesCompat; -import android.support.v7.app.AlertDialog; -import android.support.v7.content.res.AppCompatResources; -import android.support.v7.widget.AppCompatButton; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.core.content.res.ResourcesCompat; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.appcompat.widget.AppCompatButton; +import androidx.recyclerview.widget.RecyclerView; import android.text.InputType; import android.text.TextUtils; import android.util.DisplayMetrics; @@ -80,7 +80,7 @@ import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_YELLOW; import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager; /** - * Custom {@link android.support.v7.widget.RecyclerView.Adapter} used for topics. + * Custom {@link RecyclerView.Adapter} used for topics. */ class TopicAdapter extends RecyclerView.Adapter { /** 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 ce93b6b1..a7d7dc22 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 @@ -11,11 +11,11 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.MediaStore; -import android.support.design.widget.FloatingActionButton; -import android.support.v7.content.res.AppCompatResources; -import android.support.v7.preference.PreferenceManager; -import android.support.v7.widget.AppCompatButton; -import android.support.v7.widget.AppCompatTextView; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.preference.PreferenceManager; +import androidx.appcompat.widget.AppCompatButton; +import androidx.appcompat.widget.AppCompatTextView; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java index c5ab4829..fffb5064 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java @@ -3,9 +3,9 @@ package gr.thmmy.mthmmy.activities.upload; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import android.text.Editable; import android.text.TextWatcher; import android.view.View; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java index 9529d402..0da38a6e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java @@ -10,8 +10,8 @@ import android.media.ExifInterface; import android.net.Uri; import android.os.Environment; import android.provider.OpenableColumns; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import android.widget.Toast; import java.io.BufferedInputStream; 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 df678e29..752a1c52 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -2,7 +2,7 @@ package gr.thmmy.mthmmy.base; import android.Manifest; import android.app.ProgressDialog; -import android.arch.lifecycle.ViewModelProviders; +import androidx.lifecycle.ViewModelProviders; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -11,13 +11,13 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.design.widget.BottomSheetDialog; -import android.support.v4.content.ContextCompat; -import android.support.v4.content.FileProvider; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.preference.PreferenceManager; -import android.support.v7.widget.Toolbar; +import androidx.annotation.NonNull; +import com.google.android.material.bottomsheet.BottomSheetDialog; +import androidx.core.content.ContextCompat; +import androidx.core.content.FileProvider; +import androidx.appcompat.app.AppCompatActivity; +import androidx.preference.PreferenceManager; +import androidx.appcompat.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.widget.Button; 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 dbd760a7..4b4a86e6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -6,7 +6,7 @@ import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; -import android.support.v4.content.ContextCompat; +import androidx.core.content.ContextCompat; import android.util.DisplayMetrics; import android.widget.ImageView; 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 d6f69297..960834e0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java @@ -2,8 +2,8 @@ package gr.thmmy.mthmmy.base; import android.content.Context; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; import okhttp3.OkHttpClient; diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java index 0cb17141..1710ba90 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java @@ -6,12 +6,12 @@ import android.app.AlertDialog; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; -import android.support.annotation.Nullable; -import android.support.design.widget.TextInputEditText; -import android.support.design.widget.TextInputLayout; -import android.support.v7.widget.AppCompatImageButton; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.Nullable; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.text.Editable; import android.text.TextUtils; import android.util.AttributeSet; diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboard.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboard.java index 14a63438..2b11f68e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboard.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboard.java @@ -2,9 +2,9 @@ package gr.thmmy.mthmmy.editorview; import android.content.Context; import android.os.Handler; -import android.support.v7.widget.AppCompatImageButton; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboardAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboardAdapter.java index 40fe4db5..39e81c06 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboardAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboardAdapter.java @@ -1,9 +1,9 @@ package gr.thmmy.mthmmy.editorview; import android.graphics.drawable.AnimationDrawable; -import android.support.annotation.NonNull; -import android.support.v7.widget.AppCompatImageButton; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/FormatButtonsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/FormatButtonsAdapter.java index 469cf2f6..6daa6ccc 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/FormatButtonsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/FormatButtonsAdapter.java @@ -1,8 +1,8 @@ package gr.thmmy.mthmmy.editorview; -import android.support.annotation.NonNull; -import android.support.v7.widget.AppCompatImageButton; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java b/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java index 9e2aae95..baf09ff3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java @@ -1,7 +1,7 @@ package gr.thmmy.mthmmy.model; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Objects; diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java index 1113ffbc..ce212d3b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java @@ -1,6 +1,6 @@ package gr.thmmy.mthmmy.model; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Objects; 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 8f27c963..e1c10f6f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java @@ -12,9 +12,9 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.service.notification.StatusBarNotification; -import android.support.annotation.RequiresApi; -import android.support.v4.app.NotificationCompat; -import android.support.v7.preference.PreferenceManager; +import androidx.annotation.RequiresApi; +import androidx.core.app.NotificationCompat; +import androidx.preference.PreferenceManager; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; @@ -28,7 +28,7 @@ import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.PostNotification; import timber.log.Timber; -import static android.support.v4.app.NotificationCompat.PRIORITY_MAX; +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; 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 9168ebf3..c82ecaab 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -1,8 +1,8 @@ package gr.thmmy.mthmmy.session; import android.content.SharedPreferences; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/AppCompatSpinnerWithoutDefault.java b/app/src/main/java/gr/thmmy/mthmmy/utils/AppCompatSpinnerWithoutDefault.java index 74bed048..e4848661 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/AppCompatSpinnerWithoutDefault.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/AppCompatSpinnerWithoutDefault.java @@ -2,7 +2,7 @@ package gr.thmmy.mthmmy.utils; import android.annotation.SuppressLint; import android.content.Context; -import android.support.v7.widget.AppCompatSpinner; +import androidx.appcompat.widget.AppCompatSpinner; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; 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 12f0a9e6..5038fe19 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java @@ -3,7 +3,7 @@ package gr.thmmy.mthmmy.utils; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.text.style.ReplacementSpan; public class CenterVerticalSpan extends ReplacementSpan { diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java index 52a5302e..8e8cf800 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java @@ -1,8 +1,8 @@ package gr.thmmy.mthmmy.utils; import android.content.Context; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import timber.log.Timber; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CustomRecyclerView.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CustomRecyclerView.java index af29a9bd..828b7dab 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CustomRecyclerView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CustomRecyclerView.java @@ -1,9 +1,9 @@ package gr.thmmy.mthmmy.utils; import android.content.Context; -import android.support.annotation.Nullable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.util.AttributeSet; //Custom RecyclerView, so EdgeEffect and SwipeRefresh both work 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 9f2d4757..b9121a7b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java @@ -1,6 +1,6 @@ package gr.thmmy.mthmmy.utils; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.webkit.MimeTypeMap; import java.io.File; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java index 9f843c20..d832c6f2 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java @@ -1,11 +1,11 @@ package gr.thmmy.mthmmy.utils; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.design.widget.CoordinatorLayout; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; -import android.support.v4.view.ViewCompat; +import androidx.annotation.NonNull; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; +import androidx.core.view.ViewCompat; import android.util.AttributeSet; import android.view.View; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java index 2f9fb5b9..c5dfa227 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java @@ -2,11 +2,11 @@ package gr.thmmy.mthmmy.utils; import android.animation.Animator; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.design.widget.CoordinatorLayout; -import android.support.design.widget.Snackbar; -import android.support.v4.view.ViewCompat; -import android.support.v4.view.animation.FastOutSlowInInterpolator; +import androidx.annotation.NonNull; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import com.google.android.material.snackbar.Snackbar; +import androidx.core.view.ViewCompat; +import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import android.util.AttributeSet; import android.view.View; import android.view.ViewPropertyAnimator; diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/BaseViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/BaseViewModel.java index 53ed84ef..5787b36d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/BaseViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/BaseViewModel.java @@ -1,8 +1,8 @@ package gr.thmmy.mthmmy.viewmodel; -import android.arch.lifecycle.LiveData; -import android.arch.lifecycle.MutableLiveData; -import android.arch.lifecycle.ViewModel; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; import gr.thmmy.mthmmy.model.Bookmark; diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index 0e5997e0..c73c57a2 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -1,6 +1,6 @@ package gr.thmmy.mthmmy.viewmodel; -import android.arch.lifecycle.MutableLiveData; +import androidx.lifecycle.MutableLiveData; import android.content.Context; import android.content.SharedPreferences; import android.os.AsyncTask; diff --git a/app/src/main/res/color/bottom_navigation_selector.xml b/app/src/main/res/color/bottom_navigation_selector.xml new file mode 100644 index 00000000..e8c22ee2 --- /dev/null +++ b/app/src/main/res/color/bottom_navigation_selector.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_access_time_white_24dp.xml b/app/src/main/res/drawable/ic_access_time_white_24dp.xml new file mode 100644 index 00000000..87e8fdaa --- /dev/null +++ b/app/src/main/res/drawable/ic_access_time_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_announcement.xml b/app/src/main/res/drawable/ic_announcement.xml new file mode 100644 index 00000000..7d965a41 --- /dev/null +++ b/app/src/main/res/drawable/ic_announcement.xml @@ -0,0 +1,6 @@ + + + diff --git a/app/src/main/res/drawable/ic_fiber_new_white_24dp.xml b/app/src/main/res/drawable/ic_fiber_new_white_24dp.xml new file mode 100644 index 00000000..be966efc --- /dev/null +++ b/app/src/main/res/drawable/ic_fiber_new_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_forum_white_24dp.xml b/app/src/main/res/drawable/ic_forum_white_24dp.xml new file mode 100644 index 00000000..55b04ab1 --- /dev/null +++ b/app/src/main/res/drawable/ic_forum_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout-v21/activity_profile.xml b/app/src/main/res/layout-v21/activity_profile.xml index 22f819cc..85b16af6 100644 --- a/app/src/main/res/layout-v21/activity_profile.xml +++ b/app/src/main/res/layout-v21/activity_profile.xml @@ -1,5 +1,5 @@ - - - - + - - + - - + - - - + diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml index ad66a8a7..a71a353d 100644 --- a/app/src/main/res/layout-v21/activity_topic_post_row.xml +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -9,7 +9,7 @@ android:paddingStart="4dp" tools:ignore="SmallSp"> - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 020c6e03..f7f3061e 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -1,5 +1,5 @@ - - - - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_board.xml b/app/src/main/res/layout/activity_board.xml index 517c48a3..d538bdf7 100644 --- a/app/src/main/res/layout/activity_board.xml +++ b/app/src/main/res/layout/activity_board.xml @@ -1,5 +1,5 @@ - - - - - + + - - + - - + diff --git a/app/src/main/res/layout/activity_bookmark.xml b/app/src/main/res/layout/activity_bookmark.xml index d35191dd..8aeccae1 100644 --- a/app/src/main/res/layout/activity_bookmark.xml +++ b/app/src/main/res/layout/activity_bookmark.xml @@ -1,5 +1,5 @@ - - - - + - - + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_create_content.xml b/app/src/main/res/layout/activity_create_content.xml index 60028c0c..7e6a9b40 100644 --- a/app/src/main/res/layout/activity_create_content.xml +++ b/app/src/main/res/layout/activity_create_content.xml @@ -1,5 +1,5 @@ - - - - - + + - - - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_downloads.xml b/app/src/main/res/layout/activity_downloads.xml index 85fbe0ea..5f986f06 100644 --- a/app/src/main/res/layout/activity_downloads.xml +++ b/app/src/main/res/layout/activity_downloads.xml @@ -1,5 +1,5 @@ - - - - - + + - - + - - + diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 52bdc281..9ac472f0 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -41,7 +41,7 @@ android:layout_weight="0.45"/> - @@ -51,7 +51,7 @@ android:layout_height="wrap_content" android:hint="@string/hint_username" android:inputType="textPersonName"/> - + - @@ -70,7 +70,7 @@ android:layout_height="wrap_content" android:hint="@string/hint_password" android:inputType="textPassword"/> - + - - - - - - + - - + + + diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml index dcd3770c..1c6cdb6d 100644 --- a/app/src/main/res/layout/activity_profile.xml +++ b/app/src/main/res/layout/activity_profile.xml @@ -1,5 +1,5 @@ - - - - + - - + - - + - - - + diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 76fea163..97676cc6 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,5 +1,5 @@ - - - - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_topic.xml b/app/src/main/res/layout/activity_topic.xml index ac653015..aaa13e4b 100644 --- a/app/src/main/res/layout/activity_topic.xml +++ b/app/src/main/res/layout/activity_topic.xml @@ -1,5 +1,5 @@ - - - - - + + - - - + diff --git a/app/src/main/res/layout/activity_topic_edit_row.xml b/app/src/main/res/layout/activity_topic_edit_row.xml index 2feeaa0d..60d2953d 100644 --- a/app/src/main/res/layout/activity_topic_edit_row.xml +++ b/app/src/main/res/layout/activity_topic_edit_row.xml @@ -8,7 +8,7 @@ android:paddingEnd="4dp" android:paddingStart="4dp"> - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_topic_poll.xml b/app/src/main/res/layout/activity_topic_poll.xml index 60b7c96d..056ae2ca 100644 --- a/app/src/main/res/layout/activity_topic_poll.xml +++ b/app/src/main/res/layout/activity_topic_poll.xml @@ -41,7 +41,7 @@ android:layout_height="wrap_content" android:layout_weight="1"/> - - - - - - + \ No newline at end of file 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 84ff1b6a..fa677c33 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 @@ -8,7 +8,7 @@ android:paddingEnd="4dp" android:paddingStart="4dp"> - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_upload.xml b/app/src/main/res/layout/activity_upload.xml index d2f81b4c..8639fd8c 100644 --- a/app/src/main/res/layout/activity_upload.xml +++ b/app/src/main/res/layout/activity_upload.xml @@ -1,5 +1,5 @@ - - - - + - - - + - - + - - - - - + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_upload_fields_builder.xml b/app/src/main/res/layout/activity_upload_fields_builder.xml index af3daae6..0583b601 100644 --- a/app/src/main/res/layout/activity_upload_fields_builder.xml +++ b/app/src/main/res/layout/activity_upload_fields_builder.xml @@ -1,5 +1,5 @@ - - - - + - - - - - - - - + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_create_link.xml b/app/src/main/res/layout/dialog_create_link.xml index 1901ed8b..e4283781 100644 --- a/app/src/main/res/layout/dialog_create_link.xml +++ b/app/src/main/res/layout/dialog_create_link.xml @@ -5,23 +5,23 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - + - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/editor_view.xml b/app/src/main/res/layout/editor_view.xml index b95ecc61..3f47e85a 100644 --- a/app/src/main/res/layout/editor_view.xml +++ b/app/src/main/res/layout/editor_view.xml @@ -4,7 +4,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - @@ -15,7 +15,7 @@ android:orientation="horizontal" android:layout_marginTop="4dp"> - - - + - - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_forum.xml b/app/src/main/res/layout/fragment_forum.xml index 04c4ec4e..2f5de239 100644 --- a/app/src/main/res/layout/fragment_forum.xml +++ b/app/src/main/res/layout/fragment_forum.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - @@ -21,7 +21,7 @@ android:paddingTop="4dp" app:layoutManager="LinearLayoutManager" tools:context=".activities.main.forum.ForumFragment" /> - + - - + - @@ -22,7 +22,7 @@ app:layoutManager="LinearLayoutManager" tools:context=".activities.main.recent.RecentFragment" tools:listitem="@layout/fragment_recent_row"/> - + - - + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_unread.xml b/app/src/main/res/layout/fragment_unread.xml index 846fb7cb..fc412190 100644 --- a/app/src/main/res/layout/fragment_unread.xml +++ b/app/src/main/res/layout/fragment_unread.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - @@ -22,7 +22,7 @@ app:layoutManager="LinearLayoutManager" tools:context=".activities.main.unread.UnreadFragment" tools:listitem="@layout/fragment_unread_row"/> - + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 310c407f..21c96257 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,6 +15,12 @@ OK Cancel + + Recent + Forum + Unread + Shoutbox + thmmy.gr Username diff --git a/app/src/main/res/xml/app_preferences.xml b/app/src/main/res/xml/app_preferences.xml index 806ba3a8..7351616c 100644 --- a/app/src/main/res/xml/app_preferences.xml +++ b/app/src/main/res/xml/app_preferences.xml @@ -1,7 +1,7 @@ - + - + - + - + - - - - Date: Sat, 6 Oct 2018 11:03:18 +0300 Subject: [PATCH 013/104] minor fixes --- .../thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java index 095e5b1a..82e28bf3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java @@ -94,6 +94,7 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj swipeRefreshLayout = rootView.findViewById(R.id.swiperefresh); swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.primary); + swipeRefreshLayout.setColorSchemeResources(R.color.accent); swipeRefreshLayout.setOnRefreshListener(() -> { shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); shoutboxTask.execute("https://www.thmmy.gr/smf/index.php?action=forum"); @@ -105,6 +106,7 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj InputConnection ic = editorView.getInputConnection(); setEmojiKeyboardInputConnection(ic); editorView.setOnSubmitListener(view -> { + if (shoutbox == null) return; if (editorView.getText().toString().isEmpty()) { editorView.setError("Required"); return; From 7199c982c620dc7d3fdb11f1349db26a67db5a1a Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 6 Oct 2018 13:50:17 +0300 Subject: [PATCH 014/104] Shoutbox improvements --- .../main/shoutbox/ShoutAdapter.java | 2 +- .../main/shoutbox/ShoutboxFragment.java | 7 +++-- .../main/shoutbox/ShoutboxTask.java | 5 ++-- .../thmmy/mthmmy/session/SessionManager.java | 1 + app/src/main/res/layout/fragment_shoutbox.xml | 22 +++++++-------- ...ut.xml => fragment_shoutbox_shout_row.xml} | 28 +++++++++++-------- 6 files changed, 37 insertions(+), 28 deletions(-) rename app/src/main/res/layout/{shout.xml => fragment_shoutbox_shout_row.xml} (84%) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java index 80d91fae..164d4105 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java @@ -48,7 +48,7 @@ public class ShoutAdapter extends CustomRecyclerView.Adapter { shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); - shoutboxTask.execute("https://www.thmmy.gr/smf/index.php?action=forum"); + shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); }); emojiKeyboard = rootView.findViewById(R.id.emoji_keyboard); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java index 69cfd819..289ec0fb 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java @@ -21,8 +21,8 @@ public class ShoutboxTask extends NewParseTask { @Override protected Shoutbox parse(Document document, Response response) throws ParseException { - // shout container: document.select("div[class=smalltext]" && div.text().contains("Τελευταίες 75 φωνές:") η στα αγγλικα - Element shoutboxContainer = document.select("div[style=width: 99%; height: 600px; overflow: auto;]").first(); + // fragment_shoutbox_shout_row container: document.select("div[class=smalltext]" && div.text().contains("Τελευταίες 75 φωνές:") η στα αγγλικα + Element shoutboxContainer = document.select("table.windowbg").first(); ArrayList shouts = new ArrayList<>(); for (Element shout : shoutboxContainer.select("div[style=margin: 4px;]")) { Element user = shout.child(0); @@ -35,6 +35,7 @@ public class ShoutboxTask extends NewParseTask { String dateString = date.text(); Element content = shout.child(2); + content.removeAttr("style"); String shoutContent = "" + ParseHelpers.youtubeEmbeddedFix(content); shouts.add(new Shout(profileName, profileUrl, dateString, shoutContent, memberOfTheMonth)); 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 c82ecaab..4811195d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -37,6 +37,7 @@ public class SessionManager { public static final HttpUrl forumUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=forum;theme=4"); private static final HttpUrl loginUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=login2"); public static final HttpUrl unreadUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=unread;all;start=0;theme=4"); + public static final HttpUrl shoutboxUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=tpmod;sa=shoutbox;theme=4"); private static final String guestName = "Guest"; //Response Codes diff --git a/app/src/main/res/layout/fragment_shoutbox.xml b/app/src/main/res/layout/fragment_shoutbox.xml index 1c602602..c7f8485c 100644 --- a/app/src/main/res/layout/fragment_shoutbox.xml +++ b/app/src/main/res/layout/fragment_shoutbox.xml @@ -1,8 +1,7 @@ - @@ -15,7 +14,7 @@ android:indeterminate="true" android:visibility="invisible" app:mpb_indeterminateTint="@color/accent" - app:mpb_progressStyle="horizontal"/> + app:mpb_progressStyle="horizontal" /> - + @@ -36,12 +35,13 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="8dp" - android:layout_marginEnd="8dp"/> + android:layout_marginEnd="8dp" + android:paddingTop="8dp" /> + android:visibility="gone" /> \ No newline at end of file diff --git a/app/src/main/res/layout/shout.xml b/app/src/main/res/layout/fragment_shoutbox_shout_row.xml similarity index 84% rename from app/src/main/res/layout/shout.xml rename to app/src/main/res/layout/fragment_shoutbox_shout_row.xml index c9f17aa7..9d606e5d 100644 --- a/app/src/main/res/layout/shout.xml +++ b/app/src/main/res/layout/fragment_shoutbox_shout_row.xml @@ -1,14 +1,13 @@ - + + android:paddingTop="9dp" + android:textColor="@color/accent" + android:textStyle="bold" + tools:text="author" /> + android:textSize="11sp" + tools:text="date & time" /> + tools:ignore="WebViewLayout" /> + + \ No newline at end of file From ad7d4f2ff355929b5204ebec09b63aed7b249310 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 10 Oct 2018 14:27:32 +0300 Subject: [PATCH 015/104] bottom nav->tabs+icons --- .../mthmmy/activities/main/MainActivity.java | 85 ++++++++----------- .../res/color/activity_main_tabs_selector.xml | 6 ++ .../res/color/bottom_navigation_selector.xml | 5 -- app/src/main/res/drawable/ic_announcement.xml | 5 +- app/src/main/res/layout/activity_main.xml | 33 ++++--- .../main/res/menu/bottom_navigation_basic.xml | 12 --- .../res/menu/bottom_navigation_logged_in.xml | 11 --- 7 files changed, 62 insertions(+), 95 deletions(-) create mode 100644 app/src/main/res/color/activity_main_tabs_selector.xml delete mode 100644 app/src/main/res/color/bottom_navigation_selector.xml delete mode 100644 app/src/main/res/menu/bottom_navigation_basic.xml delete mode 100644 app/src/main/res/menu/bottom_navigation_logged_in.xml 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 8b7ccd60..3ba361df 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 @@ -4,11 +4,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuInflater; import android.widget.Toast; -import com.google.android.material.bottomnavigation.BottomNavigationView; +import com.google.android.material.tabs.TabLayout; import java.util.ArrayList; import java.util.List; @@ -17,8 +15,8 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter; -import androidx.fragment.app.FragmentTransaction; import androidx.preference.PreferenceManager; +import androidx.viewpager.widget.ViewPager; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.board.BoardActivity; @@ -28,6 +26,7 @@ import gr.thmmy.mthmmy.activities.main.recent.RecentFragment; import gr.thmmy.mthmmy.activities.main.shoutbox.ShoutboxFragment; import gr.thmmy.mthmmy.activities.main.unread.UnreadFragment; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; +import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.Board; @@ -53,7 +52,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF private static final String DRAWER_INTRO = "DRAWER_INTRO"; private long mBackPressed; private SectionsPagerAdapter sectionsPagerAdapter; - private BottomNavigationView bottomNavigation; + private ViewPager viewPager; + private TabLayout tabLayout; @Override protected void onCreate(Bundle savedInstanceState) { @@ -79,46 +79,33 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); sectionsPagerAdapter.addFragment(RecentFragment.newInstance(1), "RECENT"); sectionsPagerAdapter.addFragment(ForumFragment.newInstance(2), "FORUM"); - if (sessionManager.isLoggedIn()) + if (sessionManager.isLoggedIn()) { sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); + sectionsPagerAdapter.addFragment(ShoutboxFragment.newInstance(4), "SHOUTBOX"); + } - FragmentTransaction initialFragmentTransaction = getSupportFragmentManager().beginTransaction(); - RecentFragment initialRecentFragment = RecentFragment.newInstance(1); - initialFragmentTransaction.add(R.id.fragment_container, initialRecentFragment); - initialFragmentTransaction.commit(); - - bottomNavigation = findViewById(R.id.main_bottom_navigation); - if (sessionManager.isLoggedIn()) bottomNavigation.inflateMenu(R.menu.bottom_navigation_logged_in); - bottomNavigation.setOnNavigationItemSelectedListener(menuItem -> { - FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); - switch (menuItem.getItemId()) { - case R.id.action_recent: - fragmentTransaction = getSupportFragmentManager().beginTransaction(); - RecentFragment recentFragment = RecentFragment.newInstance(1); - fragmentTransaction.replace(R.id.fragment_container, recentFragment); - fragmentTransaction.commit(); - return true; - case R.id.action_forum: - ForumFragment forumFragment = ForumFragment.newInstance(2); - fragmentTransaction.replace(R.id.fragment_container, forumFragment); - fragmentTransaction.commit(); - return true; - case R.id.action_unread: - UnreadFragment unreadFragment = UnreadFragment.newInstance(3); - fragmentTransaction.replace(R.id.fragment_container, unreadFragment); - fragmentTransaction.commit(); - return true; - case R.id.action_shoutbox: - ShoutboxFragment shoutboxFragment = ShoutboxFragment.newInstance(4); - fragmentTransaction.replace(R.id.fragment_container, shoutboxFragment); - fragmentTransaction.commit(); - return true; - default: - return false; - } - }); + //Set up the ViewPager with the sections adapter. + viewPager = findViewById(R.id.container); + viewPager.setAdapter(sectionsPagerAdapter); + tabLayout = findViewById(R.id.tabs); + tabLayout.setupWithViewPager(viewPager); sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); + int preferredTab = Integer.parseInt(sharedPrefs.getString(SettingsActivity.DEFAULT_HOME_TAB, "0")); + if ((preferredTab != 3 && preferredTab != 4) || sessionManager.isLoggedIn()) { + tabLayout.getTabAt(preferredTab).select(); + } + for (int i = 0; i < tabLayout.getTabCount(); i++) { + if (i == 0) { + tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_access_time_white_24dp)); + } else if (i == 1) { + tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_forum_white_24dp)); + }else if (i == 2) { + tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp)); + } else if (i == 3) { + tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_announcement)); + } + } setMainActivity(this); } @@ -209,6 +196,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF fragmentList.remove(position); fragmentTitleList.remove(position); notifyDataSetChanged(); + if (viewPager.getCurrentItem() == position) + viewPager.setCurrentItem(position - 1); } @Override @@ -235,15 +224,15 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF } public void updateTabs() { - if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3) + if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 4) { + sectionsPagerAdapter.removeFragment(3); sectionsPagerAdapter.removeFragment(2); - else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) + } + else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) { sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); - if (!sessionManager.isLoggedIn() && bottomNavigation.getMenu().size() > 2) { - bottomNavigation.getMenu().removeItem(R.id.action_shoutbox); - bottomNavigation.getMenu().removeItem(R.id.action_unread); - } else if (sessionManager.isLoggedIn() && bottomNavigation.getMenu().size() < 4) { - bottomNavigation.inflateMenu(R.menu.bottom_navigation_logged_in); + sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(4), "SHOUTBOX"); + tabLayout.getTabAt(3).setIcon(R.drawable.ic_fiber_new_white_24dp); + tabLayout.getTabAt(4).setIcon(R.drawable.ic_announcement); } } //-------------------------------FragmentPagerAdapter END------------------------------------------- diff --git a/app/src/main/res/color/activity_main_tabs_selector.xml b/app/src/main/res/color/activity_main_tabs_selector.xml new file mode 100644 index 00000000..c1433b72 --- /dev/null +++ b/app/src/main/res/color/activity_main_tabs_selector.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/color/bottom_navigation_selector.xml b/app/src/main/res/color/bottom_navigation_selector.xml deleted file mode 100644 index e8c22ee2..00000000 --- a/app/src/main/res/color/bottom_navigation_selector.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_announcement.xml b/app/src/main/res/drawable/ic_announcement.xml index 7d965a41..8a402416 100644 --- a/app/src/main/res/drawable/ic_announcement.xml +++ b/app/src/main/res/drawable/ic_announcement.xml @@ -1,6 +1,7 @@ - + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8277e571..053c2fb7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - + - - - - + android:layout_height="match_parent" + app:layout_behavior="@string/appbar_scrolling_view_behavior"/> + diff --git a/app/src/main/res/menu/bottom_navigation_basic.xml b/app/src/main/res/menu/bottom_navigation_basic.xml deleted file mode 100644 index 2ec0c775..00000000 --- a/app/src/main/res/menu/bottom_navigation_basic.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/bottom_navigation_logged_in.xml b/app/src/main/res/menu/bottom_navigation_logged_in.xml deleted file mode 100644 index 5884a579..00000000 --- a/app/src/main/res/menu/bottom_navigation_logged_in.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - \ No newline at end of file From 9a7f99be3765cb9bb39890a9ebc7042eb87488ee Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 10 Oct 2018 23:52:22 +0300 Subject: [PATCH 016/104] focus aware editor view --- .../main/shoutbox/ShoutboxFragment.java | 27 +++++++++++-------- .../thmmy/mthmmy/editorview/EditorView.java | 24 ++++++++++++----- app/src/main/res/layout/fragment_shoutbox.xml | 24 +++++++---------- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java index d883ff56..30f61dfc 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java @@ -1,16 +1,17 @@ package gr.thmmy.mthmmy.activities.main.shoutbox; +import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputConnection; +import android.view.inputmethod.InputMethodManager; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.editorview.EditorView; @@ -29,7 +30,6 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj private MaterialProgressBar progressBar; private ShoutboxTask shoutboxTask; private ShoutAdapter shoutAdapter; - private SwipeRefreshLayout swipeRefreshLayout; private EmojiKeyboard emojiKeyboard; private EditorView editorView; private Shoutbox shoutbox; @@ -66,7 +66,6 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) { progressBar.setVisibility(View.INVISIBLE); - swipeRefreshLayout.setRefreshing(false); if (resultCode == NetworkResultCodes.SUCCESSFUL) { shoutAdapter.setShouts(shoutbox.getShouts()); shoutAdapter.notifyDataSetChanged(); @@ -90,17 +89,16 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); layoutManager.setReverseLayout(true); recyclerView.setLayoutManager(layoutManager); + recyclerView.setOnTouchListener((view, motionEvent) -> { + editorView.setMarkdownVisible(false); + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0); + return false; + }); + shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished); shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); - swipeRefreshLayout = rootView.findViewById(R.id.swiperefresh); - swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.primary); - swipeRefreshLayout.setColorSchemeResources(R.color.accent); - swipeRefreshLayout.setOnRefreshListener(() -> { - shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); - shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); - }); - emojiKeyboard = rootView.findViewById(R.id.emoji_keyboard); editorView = rootView.findViewById(R.id.edior_view); editorView.setEmojiKeyboardOwner(this); @@ -119,6 +117,13 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj .execute(shoutbox.getSendShoutUrl(), editorView.getText().toString(), shoutbox.getSc(), shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl()); }); + editorView.setMarkdownVisible(false); + editorView.setOnTouchListener((view, motionEvent) -> { + editorView.setMarkdownVisible(true); + return false; + }); + editorView.setMarkdownVisible(false); + editorView.showMarkdownOnfocus(); return rootView; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java index 1710ba90..a7da9420 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java @@ -6,12 +6,6 @@ import android.app.AlertDialog; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; -import androidx.annotation.Nullable; -import com.google.android.material.textfield.TextInputEditText; -import com.google.android.material.textfield.TextInputLayout; -import androidx.appcompat.widget.AppCompatImageButton; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.text.Editable; import android.text.TextUtils; import android.util.AttributeSet; @@ -26,8 +20,15 @@ import android.widget.PopupWindow; import android.widget.ScrollView; import android.widget.TextView; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + import java.util.Objects; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; public class EditorView extends LinearLayout { @@ -275,6 +276,17 @@ public class EditorView extends LinearLayout { submitButton = findViewById(R.id.submit_button); } + public void setMarkdownVisible(boolean visible) { + findViewById(R.id.buttons_recyclerview).setVisibility(visible ? VISIBLE : GONE); + } + + public void showMarkdownOnfocus() { + edittextWrapper.setOnClickListener(view -> setMarkdownVisible(true)); + editText.setOnClickListener(view -> setMarkdownVisible(true)); + edittextWrapper.setOnFocusChangeListener((view, b) -> setMarkdownVisible(b)); + editText.setOnFocusChangeListener((view, b) -> setMarkdownVisible(b)); + } + public TextInputEditText getEditText() { return editText; } diff --git a/app/src/main/res/layout/fragment_shoutbox.xml b/app/src/main/res/layout/fragment_shoutbox.xml index c7f8485c..625c2b88 100644 --- a/app/src/main/res/layout/fragment_shoutbox.xml +++ b/app/src/main/res/layout/fragment_shoutbox.xml @@ -1,5 +1,6 @@ - - - - - - + android:layout_weight="1" + tools:listitem="@layout/fragment_shoutbox_shout_row" /> + android:paddingTop="8dp" + app:layout_anchor="@id/shoutbox_recyclerview" + app:layout_anchorGravity="bottom" + app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareLinearBehavior" /> - \ No newline at end of file From bcfdcbe6cd4a6760fdc53cd6ab7e481a0a9a2cce Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Thu, 11 Oct 2018 18:01:55 +0300 Subject: [PATCH 017/104] add animations for markdown button expand/collapse, prevent edittext from going full screen on landscape --- .../main/shoutbox/ShoutboxFragment.java | 6 +- .../thmmy/mthmmy/editorview/EditorView.java | 104 ++++++++++++++++-- 2 files changed, 96 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java index 30f61dfc..eb3c2133 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java @@ -90,7 +90,7 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj layoutManager.setReverseLayout(true); recyclerView.setLayoutManager(layoutManager); recyclerView.setOnTouchListener((view, motionEvent) -> { - editorView.setMarkdownVisible(false); + editorView.hideMarkdown(); InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0); return false; @@ -117,9 +117,9 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj .execute(shoutbox.getSendShoutUrl(), editorView.getText().toString(), shoutbox.getSc(), shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl()); }); - editorView.setMarkdownVisible(false); + editorView.hideMarkdown(); editorView.setOnTouchListener((view, motionEvent) -> { - editorView.setMarkdownVisible(true); + editorView.showMarkdown(); return false; }); editorView.setMarkdownVisible(false); diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java index a7da9420..d190ec4c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java @@ -1,5 +1,6 @@ package gr.thmmy.mthmmy.editorview; +import android.animation.Animator; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; @@ -12,6 +13,8 @@ import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.SparseArray; import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewPropertyAnimator; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; @@ -27,12 +30,14 @@ import java.util.Objects; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatImageButton; +import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; public class EditorView extends LinearLayout { + private static final int ANIMATION_DURATION = 100; private SparseArray colors = new SparseArray<>(); private TextInputLayout edittextWrapper; @@ -40,6 +45,7 @@ public class EditorView extends LinearLayout { private AppCompatImageButton emojiButton; private AppCompatImageButton submitButton; private EmojiKeyboard.EmojiKeyboardOwner emojiKeyboardOwner; + private RecyclerView formatButtonsRecyclerview; public EditorView(Context context) { super(context); @@ -61,8 +67,14 @@ public class EditorView extends LinearLayout { LayoutInflater.from(context).inflate(R.layout.editor_view, this, true); setOrientation(VERTICAL); + formatButtonsRecyclerview = findViewById(R.id.buttons_recyclerview); edittextWrapper = findViewById(R.id.editor_edittext_wrapper); editText = findViewById(R.id.editor_edittext); + editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); + editText.setOnTouchListener((v, event) -> { + if (emojiKeyboardOwner.isEmojiKeyboardVisible()) return true; + return false; + }); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EditorView, 0, 0); try { @@ -79,11 +91,6 @@ public class EditorView extends LinearLayout { emojiButton = findViewById(R.id.emoji_keyboard_button); - editText.setOnTouchListener((v, event) -> { - if (emojiKeyboardOwner.isEmojiKeyboardVisible()) return true; - return false; - }); - colors.append(R.id.black, "black"); colors.append(R.id.red, "red"); colors.append(R.id.yellow, "yellow"); @@ -99,7 +106,6 @@ public class EditorView extends LinearLayout { colors.append(R.id.maroon, "maroon"); colors.append(R.id.lime_green, "limegreen"); - RecyclerView formatButtonsRecyclerview = findViewById(R.id.buttons_recyclerview); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); float itemWidth = getResources().getDimension(R.dimen.editor_format_button_size) + getResources().getDimension(R.dimen.editor_format_button_margin_between); @@ -277,14 +283,90 @@ public class EditorView extends LinearLayout { } public void setMarkdownVisible(boolean visible) { - findViewById(R.id.buttons_recyclerview).setVisibility(visible ? VISIBLE : GONE); + formatButtonsRecyclerview.setVisibility(visible ? VISIBLE : GONE); } public void showMarkdownOnfocus() { - edittextWrapper.setOnClickListener(view -> setMarkdownVisible(true)); - editText.setOnClickListener(view -> setMarkdownVisible(true)); - edittextWrapper.setOnFocusChangeListener((view, b) -> setMarkdownVisible(b)); - editText.setOnFocusChangeListener((view, b) -> setMarkdownVisible(b)); + edittextWrapper.setOnClickListener(view -> { + showMarkdown(); + }); + editText.setOnClickListener(view -> { + showMarkdown(); + }); + edittextWrapper.setOnFocusChangeListener((view, b) -> { + if (b) showMarkdown(); + else hideMarkdown(); + }); + editText.setOnFocusChangeListener((view, b) -> { + if (b) showMarkdown(); + else hideMarkdown(); + }); + } + + /** + * Animates the hiding of the markdown options. + * + */ + public void hideMarkdown() { + if (formatButtonsRecyclerview.getVisibility() == GONE) return; + ViewPropertyAnimator animator = formatButtonsRecyclerview.animate() + .translationY(formatButtonsRecyclerview.getHeight()) + .setInterpolator(new FastOutSlowInInterpolator()) + .setDuration(ANIMATION_DURATION); + + animator.setListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animator) { + } + + @Override + public void onAnimationEnd(Animator animator) { + formatButtonsRecyclerview.setVisibility(View.GONE); + } + + @Override + public void onAnimationCancel(Animator animator) { + } + + @Override + public void onAnimationRepeat(Animator animator) { + } + }); + + animator.start(); + } + + /** + * Animates the showing of the markdown options. + * + */ + public void showMarkdown() { + if (formatButtonsRecyclerview.getVisibility() == VISIBLE) return; + ViewPropertyAnimator animator = formatButtonsRecyclerview.animate() + .translationY(0) + .setInterpolator(new FastOutSlowInInterpolator()) + .setDuration(ANIMATION_DURATION); + + animator.setListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animator) { + formatButtonsRecyclerview.setVisibility(View.VISIBLE); + } + + @Override + public void onAnimationEnd(Animator animator) { + } + + @Override + public void onAnimationCancel(Animator animator) { + } + + @Override + public void onAnimationRepeat(Animator animator) { + } + }); + + animator.start(); } public TextInputEditText getEditText() { From 8beb66b35b5ce0fe91da84277202e2eea02c1584 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Thu, 11 Oct 2018 18:05:41 +0300 Subject: [PATCH 018/104] add logs in shoutbox tasks --- .../mthmmy/activities/main/shoutbox/ShoutboxFragment.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java index eb3c2133..8a373375 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java @@ -22,6 +22,7 @@ import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.utils.CustomRecyclerView; import gr.thmmy.mthmmy.utils.NetworkResultCodes; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; +import timber.log.Timber; public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.EmojiKeyboardOwner { @@ -44,10 +45,12 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj } private void onShoutboxTaskSarted() { + Timber.i("Starting shoutbox task..."); progressBar.setVisibility(View.VISIBLE); } private void onSendShoutTaskStarted() { + Timber.i("Start sending a shout..."); progressBar.setVisibility(View.VISIBLE); } @@ -56,10 +59,12 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj editorView.setEnabled(true); progressBar.setVisibility(View.INVISIBLE); if (resultCode == NetworkResultCodes.SUCCESSFUL) { + Timber.i("Shout was sent successfully"); editorView.getEditText().getText().clear(); shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { + Timber.w("Failed to send shout"); Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); } } @@ -67,12 +72,15 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) { progressBar.setVisibility(View.INVISIBLE); if (resultCode == NetworkResultCodes.SUCCESSFUL) { + Timber.i("Shoutbox loaded successfully"); shoutAdapter.setShouts(shoutbox.getShouts()); shoutAdapter.notifyDataSetChanged(); this.shoutbox = shoutbox; } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { + Timber.w("Failed to retreive shoutbox due to network error"); Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); } else { + Timber.wtf("Failed to retreive shoutbox due to unknown error"); Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show(); } } From 9bed06fb7c23bbb8df2a278636b64b6a1b1bc237 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Thu, 11 Oct 2018 20:32:37 +0300 Subject: [PATCH 019/104] add refresh label --- .../main/shoutbox/ShoutboxFragment.java | 50 +++++++++++++++++++ .../res/drawable/refresh_label_background.xml | 16 ++++++ app/src/main/res/layout/fragment_shoutbox.xml | 34 ++++++++++--- app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/drawable/refresh_label_background.xml diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java index 8a373375..ceff90e5 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java @@ -1,5 +1,6 @@ package gr.thmmy.mthmmy.activities.main.shoutbox; +import android.animation.ValueAnimator; import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; @@ -7,11 +8,14 @@ import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; +import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.editorview.EditorView; @@ -29,11 +33,13 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj private static final String TAG = "ShoutboxFragment"; private MaterialProgressBar progressBar; + private TextView refreshLabel; private ShoutboxTask shoutboxTask; private ShoutAdapter shoutAdapter; private EmojiKeyboard emojiKeyboard; private EditorView editorView; private Shoutbox shoutbox; + private ValueAnimator animator; public static ShoutboxFragment newInstance(int sectionNumber) { ShoutboxFragment fragment = new ShoutboxFragment(); @@ -46,6 +52,7 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj private void onShoutboxTaskSarted() { Timber.i("Starting shoutbox task..."); + hideRefreshLabel(); progressBar.setVisibility(View.VISIBLE); } @@ -58,6 +65,7 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj editorView.setAlpha(1f); editorView.setEnabled(true); progressBar.setVisibility(View.INVISIBLE); + showRefreshLabel(); if (resultCode == NetworkResultCodes.SUCCESSFUL) { Timber.i("Shout was sent successfully"); editorView.getEditText().getText().clear(); @@ -90,6 +98,12 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_shoutbox, container, false); + refreshLabel = rootView.findViewById(R.id.refresh_label); + refreshLabel.setOnClickListener(v -> { + shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished); + shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); + }); + progressBar = rootView.findViewById(R.id.progressBar); CustomRecyclerView recyclerView = rootView.findViewById(R.id.shoutbox_recyclerview); shoutAdapter = new ShoutAdapter(getContext(), new Shout[0]); @@ -103,6 +117,16 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0); return false; }); + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + if (dy > 0) { + showRefreshLabel(); + } else { + hideRefreshLabel(); + } + } + }); shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished); shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); @@ -136,6 +160,32 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj return rootView; } + private void hideRefreshLabel() { + if (refreshLabel.getVisibility() == View.GONE) return; + if (animator != null) animator.cancel(); + animator = getRefreshLabelAnimation(); + animator.start(); + } + + private void showRefreshLabel() { + if (refreshLabel.getVisibility() == View.VISIBLE) return; + if (animator != null) animator.cancel(); + animator = getRefreshLabelAnimation(); + animator.reverse(); + } + + private ValueAnimator getRefreshLabelAnimation() { + ValueAnimator animator = ValueAnimator.ofFloat(-200, 0); + animator.addUpdateListener(valueAnimator -> { + if (((Float) valueAnimator.getAnimatedValue()).intValue() == 1) refreshLabel.setVisibility(View.VISIBLE); + if (((Float) valueAnimator.getAnimatedValue()).intValue() == -199) refreshLabel.setVisibility(View.GONE); + refreshLabel.setTranslationY((float) valueAnimator.getAnimatedValue()); + }); + animator.setInterpolator(new FastOutSlowInInterpolator()); + animator.setDuration(200); + return animator; + } + @Override public void setEmojiKeyboardVisible(boolean visible) { emojiKeyboard.setVisibility(visible ? View.VISIBLE : View.GONE); diff --git a/app/src/main/res/drawable/refresh_label_background.xml b/app/src/main/res/drawable/refresh_label_background.xml new file mode 100644 index 00000000..14379c28 --- /dev/null +++ b/app/src/main/res/drawable/refresh_label_background.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_shoutbox.xml b/app/src/main/res/layout/fragment_shoutbox.xml index 625c2b88..b52a034f 100644 --- a/app/src/main/res/layout/fragment_shoutbox.xml +++ b/app/src/main/res/layout/fragment_shoutbox.xml @@ -17,12 +17,33 @@ app:mpb_indeterminateTint="@color/accent" app:mpb_progressStyle="horizontal" /> - + android:layout_weight="1"> + + + + + + + android:paddingTop="8dp" /> 24sp 24dp 6dp + 12dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 21c96257..7f2a5619 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,6 +20,7 @@ Forum Unread Shoutbox + REFRESH thmmy.gr From 019728c12a0ab04a4d6fc3e64685698ad4e49bc4 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Thu, 11 Oct 2018 23:18:23 +0300 Subject: [PATCH 020/104] move shoutbox to drawer --- app/build.gradle | 3 +- app/src/main/AndroidManifest.xml | 8 + .../mthmmy/activities/main/MainActivity.java | 12 +- .../{main => }/shoutbox/SendShoutTask.java | 2 +- .../{main => }/shoutbox/ShoutAdapter.java | 2 +- .../activities/shoutbox/ShoutboxActivity.java | 39 ++++ .../{main => }/shoutbox/ShoutboxFragment.java | 174 +++++++----------- .../{main => }/shoutbox/ShoutboxTask.java | 2 +- .../gr/thmmy/mthmmy/base/BaseActivity.java | 152 ++++++++------- .../mthmmy/viewmodel/ShoutboxViewModel.java | 58 ++++++ .../res/drawable/refresh_label_background.xml | 16 -- app/src/main/res/layout/activity_shoutbox.xml | 32 ++++ app/src/main/res/layout/fragment_shoutbox.xml | 32 +--- 13 files changed, 296 insertions(+), 236 deletions(-) rename app/src/main/java/gr/thmmy/mthmmy/activities/{main => }/shoutbox/SendShoutTask.java (97%) rename app/src/main/java/gr/thmmy/mthmmy/activities/{main => }/shoutbox/ShoutAdapter.java (99%) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java rename app/src/main/java/gr/thmmy/mthmmy/activities/{main => }/shoutbox/ShoutboxFragment.java (58%) rename app/src/main/java/gr/thmmy/mthmmy/activities/{main => }/shoutbox/ShoutboxTask.java (98%) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java delete mode 100644 app/src/main/res/drawable/refresh_label_background.xml create mode 100644 app/src/main/res/layout/activity_shoutbox.xml diff --git a/app/build.gradle b/app/build.gradle index f6b7c4fa..0231fc74 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,7 +40,7 @@ tasks.whenTaskAdded { task -> task.getDependsOn().add({ def inputFile = new File("app/google-services.json") def json = new JsonSlurper().parseText(inputFile.text) - if(json.project_info.project_id != "mthmmy-release-3aef0") + if (json.project_info.project_id != "mthmmy-release-3aef0") throw new GradleException('Please supply the correct google-services.json for release or manually change the id above!') }) } @@ -77,6 +77,7 @@ dependencies { implementation 'net.gotev:uploadservice-okhttp:3.4.2' implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.2' } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3e37e398..f621a7d2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -154,6 +154,14 @@ android:configChanges="orientation|screenSize" android:parentActivityName=".activities.main.MainActivity" android:theme="@style/AppTheme.NoActionBar" /> + + + \ No newline at end of file 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 3ba361df..f74811d7 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 @@ -23,7 +23,6 @@ import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.main.forum.ForumFragment; import gr.thmmy.mthmmy.activities.main.recent.RecentFragment; -import gr.thmmy.mthmmy.activities.main.shoutbox.ShoutboxFragment; import gr.thmmy.mthmmy.activities.main.unread.UnreadFragment; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.activities.settings.SettingsActivity; @@ -79,10 +78,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); sectionsPagerAdapter.addFragment(RecentFragment.newInstance(1), "RECENT"); sectionsPagerAdapter.addFragment(ForumFragment.newInstance(2), "FORUM"); - if (sessionManager.isLoggedIn()) { + if (sessionManager.isLoggedIn()) sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); - sectionsPagerAdapter.addFragment(ShoutboxFragment.newInstance(4), "SHOUTBOX"); - } //Set up the ViewPager with the sections adapter. viewPager = findViewById(R.id.container); @@ -102,8 +99,6 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_forum_white_24dp)); }else if (i == 2) { tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp)); - } else if (i == 3) { - tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_announcement)); } } @@ -224,15 +219,12 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF } public void updateTabs() { - if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 4) { - sectionsPagerAdapter.removeFragment(3); + if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3) { sectionsPagerAdapter.removeFragment(2); } else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) { sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); - sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(4), "SHOUTBOX"); tabLayout.getTabAt(3).setIcon(R.drawable.ic_fiber_new_white_24dp); - tabLayout.getTabAt(4).setIcon(R.drawable.ic_announcement); } } //-------------------------------FragmentPagerAdapter END------------------------------------------- diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/SendShoutTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/SendShoutTask.java similarity index 97% rename from app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/SendShoutTask.java rename to app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/SendShoutTask.java index bfe9350e..3b2af22f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/SendShoutTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/SendShoutTask.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.activities.main.shoutbox; +package gr.thmmy.mthmmy.activities.shoutbox; import org.jsoup.nodes.Document; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java similarity index 99% rename from app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java rename to app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java index 164d4105..7d041a32 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.activities.main.shoutbox; +package gr.thmmy.mthmmy.activities.shoutbox; import android.annotation.TargetApi; import android.content.Context; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java new file mode 100644 index 00000000..fffc8079 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java @@ -0,0 +1,39 @@ +package gr.thmmy.mthmmy.activities.shoutbox; + +import android.os.Bundle; + +import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.base.BaseActivity; + +public class ShoutboxActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_shoutbox); + + //Initialize toolbar + toolbar = findViewById(R.id.toolbar); + toolbar.setTitle("Shoutbox"); + setSupportActionBar(toolbar); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } + + createDrawer(); + drawer.setSelection(SHOUTBOX_ID); + + if (savedInstanceState == null) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.container, ShoutboxFragment.newInstance()) + .commitNow(); + } + } + + @Override + protected void onResume() { + drawer.setSelection(SHOUTBOX_ID); + super.onResume(); + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java similarity index 58% rename from app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java rename to app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java index ceff90e5..85c20615 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java @@ -1,6 +1,5 @@ -package gr.thmmy.mthmmy.activities.main.shoutbox; +package gr.thmmy.mthmmy.activities.shoutbox; -import android.animation.ValueAnimator; import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; @@ -8,16 +7,14 @@ import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.editorview.EditorView; import gr.thmmy.mthmmy.editorview.EmojiKeyboard; import gr.thmmy.mthmmy.model.Shout; @@ -25,85 +22,30 @@ import gr.thmmy.mthmmy.model.Shoutbox; import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.utils.CustomRecyclerView; import gr.thmmy.mthmmy.utils.NetworkResultCodes; +import gr.thmmy.mthmmy.viewmodel.ShoutboxViewModel; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import timber.log.Timber; -public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.EmojiKeyboardOwner { - - private static final String TAG = "ShoutboxFragment"; +public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKeyboardOwner { private MaterialProgressBar progressBar; - private TextView refreshLabel; private ShoutboxTask shoutboxTask; private ShoutAdapter shoutAdapter; private EmojiKeyboard emojiKeyboard; private EditorView editorView; - private Shoutbox shoutbox; - private ValueAnimator animator; - - public static ShoutboxFragment newInstance(int sectionNumber) { - ShoutboxFragment fragment = new ShoutboxFragment(); - Bundle args = new Bundle(); - args.putString(ARG_TAG, TAG); - args.putInt(ARG_SECTION_NUMBER, sectionNumber); - fragment.setArguments(args); - return fragment; - } - - private void onShoutboxTaskSarted() { - Timber.i("Starting shoutbox task..."); - hideRefreshLabel(); - progressBar.setVisibility(View.VISIBLE); - } - - private void onSendShoutTaskStarted() { - Timber.i("Start sending a shout..."); - progressBar.setVisibility(View.VISIBLE); - } - private void onSendShoutTaskFinished(int resultCode, Void ignored) { - editorView.setAlpha(1f); - editorView.setEnabled(true); - progressBar.setVisibility(View.INVISIBLE); - showRefreshLabel(); - if (resultCode == NetworkResultCodes.SUCCESSFUL) { - Timber.i("Shout was sent successfully"); - editorView.getEditText().getText().clear(); - shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); - shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); - } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { - Timber.w("Failed to send shout"); - Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); - } - } + private ShoutboxViewModel mViewModel; - private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) { - progressBar.setVisibility(View.INVISIBLE); - if (resultCode == NetworkResultCodes.SUCCESSFUL) { - Timber.i("Shoutbox loaded successfully"); - shoutAdapter.setShouts(shoutbox.getShouts()); - shoutAdapter.notifyDataSetChanged(); - this.shoutbox = shoutbox; - } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { - Timber.w("Failed to retreive shoutbox due to network error"); - Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); - } else { - Timber.wtf("Failed to retreive shoutbox due to unknown error"); - Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show(); - } + public static ShoutboxFragment newInstance() { + return new ShoutboxFragment(); } @Nullable @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_shoutbox, container, false); - refreshLabel = rootView.findViewById(R.id.refresh_label); - refreshLabel.setOnClickListener(v -> { - shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished); - shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); - }); - progressBar = rootView.findViewById(R.id.progressBar); CustomRecyclerView recyclerView = rootView.findViewById(R.id.shoutbox_recyclerview); shoutAdapter = new ShoutAdapter(getContext(), new Shout[0]); @@ -117,19 +59,6 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0); return false; }); - recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - if (dy > 0) { - showRefreshLabel(); - } else { - hideRefreshLabel(); - } - } - }); - - shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished); - shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); emojiKeyboard = rootView.findViewById(R.id.emoji_keyboard); editorView = rootView.findViewById(R.id.edior_view); @@ -137,17 +66,12 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj InputConnection ic = editorView.getInputConnection(); setEmojiKeyboardInputConnection(ic); editorView.setOnSubmitListener(view -> { - if (shoutbox == null) return; + if (mViewModel.getShoutboxMutableLiveData().getValue() == null) return; if (editorView.getText().toString().isEmpty()) { editorView.setError("Required"); return; } - editorView.setAlpha(0.5f); - editorView.setEnabled(false); - setEmojiKeyboardVisible(false); - new SendShoutTask(this::onSendShoutTaskStarted, this::onSendShoutTaskFinished) - .execute(shoutbox.getSendShoutUrl(), editorView.getText().toString(), shoutbox.getSc(), - shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl()); + mViewModel.sendShout(editorView.getText().toString()); }); editorView.hideMarkdown(); editorView.setOnTouchListener((view, motionEvent) -> { @@ -160,30 +84,64 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj return rootView; } - private void hideRefreshLabel() { - if (refreshLabel.getVisibility() == View.GONE) return; - if (animator != null) animator.cancel(); - animator = getRefreshLabelAnimation(); - animator.start(); + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + mViewModel = ViewModelProviders.of(this).get(ShoutboxViewModel.class); + mViewModel.getShoutboxMutableLiveData().observe(this, shoutbox -> { + if (shoutbox != null) { + Timber.i("Shoutbox loaded successfully"); + shoutAdapter.setShouts(shoutbox.getShouts()); + shoutAdapter.notifyDataSetChanged(); + } + }); + mViewModel.setOnShoutboxTaskStarted(this::onShoutboxTaskSarted); + mViewModel.setOnShoutboxTaskFinished(this::onShoutboxTaskFinished); + mViewModel.setOnSendShoutTaskStarted(this::onSendShoutTaskStarted); + mViewModel.setOnSendShoutTaskFinished(this::onSendShoutTaskFinished); + + mViewModel.loadShoutbox(); } - private void showRefreshLabel() { - if (refreshLabel.getVisibility() == View.VISIBLE) return; - if (animator != null) animator.cancel(); - animator = getRefreshLabelAnimation(); - animator.reverse(); + private void onShoutboxTaskSarted() { + Timber.i("Starting shoutbox task..."); + progressBar.setVisibility(View.VISIBLE); } - private ValueAnimator getRefreshLabelAnimation() { - ValueAnimator animator = ValueAnimator.ofFloat(-200, 0); - animator.addUpdateListener(valueAnimator -> { - if (((Float) valueAnimator.getAnimatedValue()).intValue() == 1) refreshLabel.setVisibility(View.VISIBLE); - if (((Float) valueAnimator.getAnimatedValue()).intValue() == -199) refreshLabel.setVisibility(View.GONE); - refreshLabel.setTranslationY((float) valueAnimator.getAnimatedValue()); - }); - animator.setInterpolator(new FastOutSlowInInterpolator()); - animator.setDuration(200); - return animator; + private void onSendShoutTaskStarted() { + Timber.i("Start sending a shout..."); + editorView.setAlpha(0.5f); + editorView.setEnabled(false); + setEmojiKeyboardVisible(false); + progressBar.setVisibility(View.VISIBLE); + } + + private void onSendShoutTaskFinished(int resultCode, Void ignored) { + editorView.setAlpha(1f); + editorView.setEnabled(true); + progressBar.setVisibility(View.INVISIBLE); + if (resultCode == NetworkResultCodes.SUCCESSFUL) { + Timber.i("Shout was sent successfully"); + editorView.getEditText().getText().clear(); + shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); + shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); + } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { + Timber.w("Failed to send shout"); + Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); + } + } + + private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) { + progressBar.setVisibility(View.INVISIBLE); + if (resultCode == NetworkResultCodes.SUCCESSFUL) { + mViewModel.setShoutbox(shoutbox); + } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { + Timber.w("Failed to retreive shoutbox due to network error"); + Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); + } else { + Timber.wtf("Failed to retreive shoutbox due to unknown error"); + Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show(); + } } @Override diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java similarity index 98% rename from app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java rename to app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java index 289ec0fb..5368248c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.activities.main.shoutbox; +package gr.thmmy.mthmmy.activities.shoutbox; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; 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 752a1c52..442c4199 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -49,6 +49,7 @@ import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; 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.model.Bookmark; import gr.thmmy.mthmmy.model.ThmmyFile; @@ -145,6 +146,7 @@ public abstract class BaseActivity extends AppCompatActivity { protected static final int LOG_ID = 4; protected static final int ABOUT_ID = 5; protected static final int SETTINGS_ID = 6; + protected static final int SHOUTBOX_ID = 7; private AccountHeader accountHeader; private ProfileDrawerItem profileDrawerItem; @@ -159,7 +161,7 @@ public abstract class BaseActivity extends AppCompatActivity { final int selectedPrimaryColor = ContextCompat.getColor(this, R.color.primary_dark); final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.accent); - PrimaryDrawerItem homeItem, bookmarksItem, settingsItem, aboutItem; + PrimaryDrawerItem homeItem, bookmarksItem, settingsItem, aboutItem, shoutboxItem; IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, uploadIcon, uploadIconSelected, settingsIcon, settingsIconSelected, bookmarksIcon, bookmarksIconSelected, aboutIcon, aboutIconSelected; @@ -230,6 +232,15 @@ public abstract class BaseActivity extends AppCompatActivity { .withIcon(homeIcon) .withSelectedIcon(homeIconSelected); + shoutboxItem = new PrimaryDrawerItem() + .withTextColor(primaryColor) + .withSelectedColor(selectedPrimaryColor) + .withSelectedTextColor(selectedSecondaryColor) + .withIdentifier(SHOUTBOX_ID) + .withName(R.string.shoutbox) + .withIcon(R.drawable.ic_announcement) + .withIconColor(primaryColor) + .withSelectedIconColor(selectedSecondaryColor); if (sessionManager.isLoggedIn()) //When logged in { @@ -301,26 +312,23 @@ public abstract class BaseActivity extends AppCompatActivity { .withSelectionListEnabledForSingleProfile(false) .withHeaderBackground(R.color.primary) .addProfiles(profileDrawerItem) - .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { - @Override - public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) { - if (sessionManager.isLoggedIn()) { - Intent intent = new Intent(BaseActivity.this, ProfileActivity.class); - Bundle extras = new Bundle(); - extras.putString(BUNDLE_PROFILE_URL, "https://www.thmmy.gr/smf/index.php?action=profile"); - if (!sessionManager.hasAvatar()) - extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, ""); - else - extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, sessionManager.getAvatarLink()); - extras.putString(BUNDLE_PROFILE_USERNAME, sessionManager.getUsername()); - intent.putExtras(extras); - intent.setFlags(FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); - return false; - } - return true; - + .withOnAccountHeaderListener((view, profile, currentProfile) -> { + if (sessionManager.isLoggedIn()) { + Intent intent = new Intent(BaseActivity.this, ProfileActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_PROFILE_URL, "https://www.thmmy.gr/smf/index.php?action=profile"); + if (!sessionManager.hasAvatar()) + extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, ""); + else + extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, sessionManager.getAvatarLink()); + extras.putString(BUNDLE_PROFILE_USERNAME, sessionManager.getUsername()); + intent.putExtras(extras); + intent.setFlags(FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + return false; } + return true; + }) .build(); @@ -331,63 +339,65 @@ public abstract class BaseActivity extends AppCompatActivity { .withDrawerWidthDp((int) BaseApplication.getInstance().getDpWidth() / 2) .withSliderBackgroundColor(ContextCompat.getColor(this, R.color.primary_light)) .withAccountHeader(accountHeader) - .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { - @Override - public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { - if (drawerItem.equals(HOME_ID)) { - if (!(BaseActivity.this instanceof MainActivity)) { - Intent intent = new Intent(BaseActivity.this, MainActivity.class); - startActivity(intent); - } - } else if (drawerItem.equals(DOWNLOADS_ID)) { - if (!(BaseActivity.this instanceof DownloadsActivity)) { - Intent intent = new Intent(BaseActivity.this, DownloadsActivity.class); - Bundle extras = new Bundle(); - extras.putString(BUNDLE_DOWNLOADS_URL, ""); - extras.putString(BUNDLE_DOWNLOADS_TITLE, null); - intent.putExtras(extras); - startActivity(intent); - } - } else if (drawerItem.equals(UPLOAD_ID)) { - if (!(BaseActivity.this instanceof UploadActivity)) { - Intent intent = new Intent(BaseActivity.this, UploadActivity.class); - startActivity(intent); - } - } else if (drawerItem.equals(BOOKMARKS_ID)) { - if (!(BaseActivity.this instanceof BookmarkActivity)) { - Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class); - startActivity(intent); - } - } else if (drawerItem.equals(LOG_ID)) { - if (!sessionManager.isLoggedIn()) //When logged out or if user is guest - { - Intent intent = new Intent(BaseActivity.this, LoginActivity.class); - startActivity(intent); - finish(); - overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); - } else - new LogoutTask().execute(); - } else if (drawerItem.equals(ABOUT_ID)) { - if (!(BaseActivity.this instanceof AboutActivity)) { - Intent intent = new Intent(BaseActivity.this, AboutActivity.class); - startActivity(intent); - } - } else if (drawerItem.equals(SETTINGS_ID)) { - if (!(BaseActivity.this instanceof SettingsActivity)) { - Intent intent = new Intent(BaseActivity.this, SettingsActivity.class); - startActivity(intent); - } + .withOnDrawerItemClickListener((view, position, drawerItem) -> { + if (drawerItem.equals(HOME_ID)) { + if (!(BaseActivity.this instanceof MainActivity)) { + Intent intent = new Intent(BaseActivity.this, MainActivity.class); + startActivity(intent); + } + } else if (drawerItem.equals(SHOUTBOX_ID)) { + if (!(BaseActivity.this instanceof ShoutboxActivity)) { + Intent intent = new Intent(BaseActivity.this, ShoutboxActivity.class); + startActivity(intent); + } + } else if (drawerItem.equals(DOWNLOADS_ID)) { + if (!(BaseActivity.this instanceof DownloadsActivity)) { + Intent intent = new Intent(BaseActivity.this, DownloadsActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_DOWNLOADS_URL, ""); + extras.putString(BUNDLE_DOWNLOADS_TITLE, null); + intent.putExtras(extras); + startActivity(intent); + } + } else if (drawerItem.equals(UPLOAD_ID)) { + if (!(BaseActivity.this instanceof UploadActivity)) { + Intent intent = new Intent(BaseActivity.this, UploadActivity.class); + startActivity(intent); + } + } else if (drawerItem.equals(BOOKMARKS_ID)) { + if (!(BaseActivity.this instanceof BookmarkActivity)) { + Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class); + startActivity(intent); + } + } else if (drawerItem.equals(LOG_ID)) { + if (!sessionManager.isLoggedIn()) //When logged out or if user is guest + { + Intent intent = new Intent(BaseActivity.this, LoginActivity.class); + startActivity(intent); + finish(); + overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); + } else + new LogoutTask().execute(); + } else if (drawerItem.equals(ABOUT_ID)) { + if (!(BaseActivity.this instanceof AboutActivity)) { + Intent intent = new Intent(BaseActivity.this, AboutActivity.class); + startActivity(intent); + } + } else if (drawerItem.equals(SETTINGS_ID)) { + if (!(BaseActivity.this instanceof SettingsActivity)) { + Intent intent = new Intent(BaseActivity.this, SettingsActivity.class); + startActivity(intent); } - - drawer.closeDrawer(); - return true; } + + drawer.closeDrawer(); + return true; }); if (sessionManager.isLoggedIn()) - drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, uploadItem, settingsItem, loginLogoutItem, aboutItem); + drawerBuilder.addDrawerItems(homeItem, shoutboxItem, bookmarksItem, downloadsItem, uploadItem, settingsItem, loginLogoutItem, aboutItem); else - drawerBuilder.addDrawerItems(homeItem, bookmarksItem, settingsItem, loginLogoutItem, aboutItem); + drawerBuilder.addDrawerItems(homeItem, shoutboxItem, bookmarksItem, settingsItem, loginLogoutItem, aboutItem); drawer = drawerBuilder.build(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java new file mode 100644 index 00000000..5aa92f65 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java @@ -0,0 +1,58 @@ +package gr.thmmy.mthmmy.viewmodel; + +import android.os.AsyncTask; + +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; +import gr.thmmy.mthmmy.activities.shoutbox.SendShoutTask; +import gr.thmmy.mthmmy.activities.shoutbox.ShoutboxTask; +import gr.thmmy.mthmmy.model.Shoutbox; +import gr.thmmy.mthmmy.session.SessionManager; + +public class ShoutboxViewModel extends ViewModel { + private MutableLiveData shoutboxMutableLiveData = new MutableLiveData<>(); + private ShoutboxTask shoutboxTask; + private ShoutboxTask.OnTaskStartedListener onShoutboxTaskStarted; + private ShoutboxTask.OnNetworkTaskFinishedListener onShoutboxTaskFinished; + private SendShoutTask.OnTaskStartedListener onSendShoutTaskStarted; + private SendShoutTask.OnNetworkTaskFinishedListener onSendShoutTaskFinished; + + public void loadShoutbox() { + if (shoutboxTask != null && shoutboxTask.getStatus() == AsyncTask.Status.RUNNING) + shoutboxTask.cancel(true); + shoutboxTask = new ShoutboxTask(onShoutboxTaskStarted, onShoutboxTaskFinished); + shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); + } + + public void sendShout(String shout) { + if (shoutboxMutableLiveData.getValue() == null) throw new IllegalStateException("Shoutbox task has not finished yet!"); + Shoutbox shoutbox = shoutboxMutableLiveData.getValue(); + new SendShoutTask(onSendShoutTaskStarted, onSendShoutTaskFinished) + .execute(shoutbox.getSendShoutUrl(), shout, shoutbox.getSc(), + shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl()); + } + + public void setShoutbox(Shoutbox shoutbox) { + shoutboxMutableLiveData.setValue(shoutbox); + } + + public MutableLiveData getShoutboxMutableLiveData() { + return shoutboxMutableLiveData; + } + + public void setOnSendShoutTaskFinished(SendShoutTask.OnNetworkTaskFinishedListener onSendShoutTaskFinished) { + this.onSendShoutTaskFinished = onSendShoutTaskFinished; + } + + public void setOnSendShoutTaskStarted(SendShoutTask.OnTaskStartedListener onSendShoutTaskStarted) { + this.onSendShoutTaskStarted = onSendShoutTaskStarted; + } + + public void setOnShoutboxTaskFinished(ShoutboxTask.OnNetworkTaskFinishedListener onShoutboxTaskFinished) { + this.onShoutboxTaskFinished = onShoutboxTaskFinished; + } + + public void setOnShoutboxTaskStarted(ShoutboxTask.OnTaskStartedListener onShoutboxTaskStarted) { + this.onShoutboxTaskStarted = onShoutboxTaskStarted; + } +} diff --git a/app/src/main/res/drawable/refresh_label_background.xml b/app/src/main/res/drawable/refresh_label_background.xml deleted file mode 100644 index 14379c28..00000000 --- a/app/src/main/res/drawable/refresh_label_background.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_shoutbox.xml b/app/src/main/res/layout/activity_shoutbox.xml new file mode 100644 index 00000000..e341b84d --- /dev/null +++ b/app/src/main/res/layout/activity_shoutbox.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_shoutbox.xml b/app/src/main/res/layout/fragment_shoutbox.xml index b52a034f..cf6dc7a0 100644 --- a/app/src/main/res/layout/fragment_shoutbox.xml +++ b/app/src/main/res/layout/fragment_shoutbox.xml @@ -1,6 +1,5 @@ - - - - - - - - + android:layout_weight="1" + tools:listitem="@layout/fragment_shoutbox_shout_row" /> Date: Fri, 12 Oct 2018 14:39:31 +0300 Subject: [PATCH 021/104] add refresh shoutbox button --- .../activities/shoutbox/ShoutboxFragment.java | 41 ++++++++++++++----- .../activities/shoutbox/ShoutboxTask.java | 1 + .../res/drawable/ic_refresh_white_24dp.xml | 5 +++ app/src/main/res/layout/activity_shoutbox.xml | 3 +- app/src/main/res/menu/shoutbox_menu.xml | 10 +++++ app/src/main/res/values/strings.xml | 2 +- 6 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 app/src/main/res/drawable/ic_refresh_white_24dp.xml create mode 100644 app/src/main/res/menu/shoutbox_menu.xml diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java index 85c20615..11e2d2d4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java @@ -3,6 +3,9 @@ package gr.thmmy.mthmmy.activities.shoutbox; import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputConnection; @@ -34,7 +37,7 @@ public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKey private EmojiKeyboard emojiKeyboard; private EditorView editorView; - private ShoutboxViewModel mViewModel; + private ShoutboxViewModel shoutboxViewModel; public static ShoutboxFragment newInstance() { return new ShoutboxFragment(); @@ -45,6 +48,7 @@ public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKey public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_shoutbox, container, false); + setHasOptionsMenu(true); progressBar = rootView.findViewById(R.id.progressBar); CustomRecyclerView recyclerView = rootView.findViewById(R.id.shoutbox_recyclerview); @@ -66,12 +70,12 @@ public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKey InputConnection ic = editorView.getInputConnection(); setEmojiKeyboardInputConnection(ic); editorView.setOnSubmitListener(view -> { - if (mViewModel.getShoutboxMutableLiveData().getValue() == null) return; + if (shoutboxViewModel.getShoutboxMutableLiveData().getValue() == null) return; if (editorView.getText().toString().isEmpty()) { editorView.setError("Required"); return; } - mViewModel.sendShout(editorView.getText().toString()); + shoutboxViewModel.sendShout(editorView.getText().toString()); }); editorView.hideMarkdown(); editorView.setOnTouchListener((view, motionEvent) -> { @@ -84,23 +88,38 @@ public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKey return rootView; } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.shoutbox_menu, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.menu_refresh) { + shoutboxViewModel.loadShoutbox(); + return true; + } else { + return false; + } + } + @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - mViewModel = ViewModelProviders.of(this).get(ShoutboxViewModel.class); - mViewModel.getShoutboxMutableLiveData().observe(this, shoutbox -> { + shoutboxViewModel = ViewModelProviders.of(this).get(ShoutboxViewModel.class); + shoutboxViewModel.getShoutboxMutableLiveData().observe(this, shoutbox -> { if (shoutbox != null) { Timber.i("Shoutbox loaded successfully"); shoutAdapter.setShouts(shoutbox.getShouts()); shoutAdapter.notifyDataSetChanged(); } }); - mViewModel.setOnShoutboxTaskStarted(this::onShoutboxTaskSarted); - mViewModel.setOnShoutboxTaskFinished(this::onShoutboxTaskFinished); - mViewModel.setOnSendShoutTaskStarted(this::onSendShoutTaskStarted); - mViewModel.setOnSendShoutTaskFinished(this::onSendShoutTaskFinished); + shoutboxViewModel.setOnShoutboxTaskStarted(this::onShoutboxTaskSarted); + shoutboxViewModel.setOnShoutboxTaskFinished(this::onShoutboxTaskFinished); + shoutboxViewModel.setOnSendShoutTaskStarted(this::onSendShoutTaskStarted); + shoutboxViewModel.setOnSendShoutTaskFinished(this::onSendShoutTaskFinished); - mViewModel.loadShoutbox(); + shoutboxViewModel.loadShoutbox(); } private void onShoutboxTaskSarted() { @@ -134,7 +153,7 @@ public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKey private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) { progressBar.setVisibility(View.INVISIBLE); if (resultCode == NetworkResultCodes.SUCCESSFUL) { - mViewModel.setShoutbox(shoutbox); + shoutboxViewModel.setShoutbox(shoutbox); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Timber.w("Failed to retreive shoutbox due to network error"); Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java index 5368248c..23181d35 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java @@ -45,6 +45,7 @@ public class ShoutboxTask extends NewParseTask { String formUrl = shoutboxForm.attr("action"); String sc = shoutboxForm.select("input[name=sc]").first().attr("value"); String shoutName = shoutboxForm.select("input[name=tp-shout-name]").first().attr("value"); + // TODO: make shout send nullable and disable shouting String shoutSend = shoutboxForm.select("input[name=shout_send]").first().attr("value"); String shoutUrl = shoutboxForm.select("input[name=tp-shout-url]").first().attr("value"); return new Shoutbox(shouts.toArray(new Shout[0]), sc, formUrl, shoutName, shoutSend, shoutUrl); diff --git a/app/src/main/res/drawable/ic_refresh_white_24dp.xml b/app/src/main/res/drawable/ic_refresh_white_24dp.xml new file mode 100644 index 00000000..cc2d1e04 --- /dev/null +++ b/app/src/main/res/drawable/ic_refresh_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_shoutbox.xml b/app/src/main/res/layout/activity_shoutbox.xml index e341b84d..e98e8fd6 100644 --- a/app/src/main/res/layout/activity_shoutbox.xml +++ b/app/src/main/res/layout/activity_shoutbox.xml @@ -10,13 +10,12 @@ android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingTop="@dimen/appbar_padding_top" android:theme="@style/ToolbarTheme"> diff --git a/app/src/main/res/menu/shoutbox_menu.xml b/app/src/main/res/menu/shoutbox_menu.xml new file mode 100644 index 00000000..8f3a16ca --- /dev/null +++ b/app/src/main/res/menu/shoutbox_menu.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7f2a5619..bc0a8552 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,7 +20,7 @@ Forum Unread Shoutbox - REFRESH + Refresh thmmy.gr From 72cd619dd1a9cfa13412bcf4abf63f2140e9af1a Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Fri, 12 Oct 2018 14:55:03 +0300 Subject: [PATCH 022/104] diasble shouting for guests --- .../java/gr/thmmy/mthmmy/activities/main/MainActivity.java | 2 +- .../thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java | 2 ++ .../gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java | 5 ++++- app/src/main/res/layout/fragment_shoutbox.xml | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) 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 f74811d7..173bd9e0 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 @@ -224,7 +224,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF } else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) { sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); - tabLayout.getTabAt(3).setIcon(R.drawable.ic_fiber_new_white_24dp); + tabLayout.getTabAt(2).setIcon(R.drawable.ic_fiber_new_white_24dp); } } //-------------------------------FragmentPagerAdapter END------------------------------------------- diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java index 11e2d2d4..22d3dbf3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java @@ -154,6 +154,8 @@ public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKey progressBar.setVisibility(View.INVISIBLE); if (resultCode == NetworkResultCodes.SUCCESSFUL) { shoutboxViewModel.setShoutbox(shoutbox); + if (shoutbox.getShoutSend() != null) + editorView.setVisibility(View.VISIBLE); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Timber.w("Failed to retreive shoutbox due to network error"); Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java index 23181d35..59797774 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java @@ -46,7 +46,10 @@ public class ShoutboxTask extends NewParseTask { String sc = shoutboxForm.select("input[name=sc]").first().attr("value"); String shoutName = shoutboxForm.select("input[name=tp-shout-name]").first().attr("value"); // TODO: make shout send nullable and disable shouting - String shoutSend = shoutboxForm.select("input[name=shout_send]").first().attr("value"); + Element shoutSendInput = shoutboxForm.select("input[name=shout_send]").first(); + String shoutSend = null; + if (shoutSendInput != null) + shoutSend = shoutSendInput.attr("value"); String shoutUrl = shoutboxForm.select("input[name=tp-shout-url]").first().attr("value"); return new Shoutbox(shouts.toArray(new Shout[0]), sc, formUrl, shoutName, shoutSend, shoutUrl); } diff --git a/app/src/main/res/layout/fragment_shoutbox.xml b/app/src/main/res/layout/fragment_shoutbox.xml index cf6dc7a0..c593aeb0 100644 --- a/app/src/main/res/layout/fragment_shoutbox.xml +++ b/app/src/main/res/layout/fragment_shoutbox.xml @@ -29,7 +29,8 @@ android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" - android:paddingTop="8dp" /> + android:paddingTop="8dp" + android:visibility="gone"/> Date: Fri, 12 Oct 2018 15:15:40 +0300 Subject: [PATCH 023/104] fix: drawer uploads, downloads index update --- .../gr/thmmy/mthmmy/base/BaseActivity.java | 22 +++++++++---------- build.gradle | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) 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 442c4199..1d3647d8 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.base; import android.Manifest; import android.app.ProgressDialog; -import androidx.lifecycle.ViewModelProviders; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -11,13 +10,6 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import androidx.annotation.NonNull; -import com.google.android.material.bottomsheet.BottomSheetDialog; -import androidx.core.content.ContextCompat; -import androidx.core.content.FileProvider; -import androidx.appcompat.app.AppCompatActivity; -import androidx.preference.PreferenceManager; -import androidx.appcompat.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.widget.Button; @@ -25,6 +17,7 @@ import android.widget.ImageButton; import android.widget.TextView; import android.widget.Toast; +import com.google.android.material.bottomsheet.BottomSheetDialog; import com.google.firebase.messaging.FirebaseMessaging; import com.mikepenz.fontawesome_typeface_library.FontAwesome; import com.mikepenz.google_material_typeface_library.GoogleMaterial; @@ -35,12 +28,17 @@ import com.mikepenz.materialdrawer.Drawer; import com.mikepenz.materialdrawer.DrawerBuilder; import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.ProfileDrawerItem; -import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; -import com.mikepenz.materialdrawer.model.interfaces.IProfile; import java.io.File; import java.util.ArrayList; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.core.content.FileProvider; +import androidx.lifecycle.ViewModelProviders; +import androidx.preference.PreferenceManager; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.AboutActivity; import gr.thmmy.mthmmy.activities.LoginActivity; @@ -424,10 +422,10 @@ public abstract class BaseActivity extends AppCompatActivity { setDefaultAvatar(); } else { if (!drawer.getDrawerItems().contains(downloadsItem)) { - drawer.addItemAtPosition(downloadsItem, 2); + drawer.addItemAtPosition(downloadsItem, 3); } if (!drawer.getDrawerItems().contains(uploadItem)) { - drawer.addItemAtPosition(uploadItem, 3); + drawer.addItemAtPosition(uploadItem, 4); } loginLogoutItem.withName(R.string.logout).withIcon(logoutIcon); //Swap login with logout profileDrawerItem.withName(sessionManager.getUsername()); diff --git a/build.gradle b/build.gradle index 65178d9a..4c88fd4c 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0' + classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.google.gms:google-services:4.0.1' classpath 'io.fabric.tools:gradle:1.25.4' } From 7d517fd8ed9efdee3d0a1d1e1c3f3d261c2462b9 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Tue, 16 Oct 2018 14:58:12 +0300 Subject: [PATCH 024/104] fix --- .../activities/shoutbox/ShoutboxFragment.java | 25 +++---------------- .../main/res/layout/activity_downloads.xml | 1 - 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java index 22d3dbf3..499e2017 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java @@ -8,7 +8,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.widget.Toast; @@ -29,7 +28,7 @@ import gr.thmmy.mthmmy.viewmodel.ShoutboxViewModel; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import timber.log.Timber; -public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKeyboardOwner { +public class ShoutboxFragment extends Fragment { private MaterialProgressBar progressBar; private ShoutboxTask shoutboxTask; @@ -66,9 +65,8 @@ public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKey emojiKeyboard = rootView.findViewById(R.id.emoji_keyboard); editorView = rootView.findViewById(R.id.edior_view); - editorView.setEmojiKeyboardOwner(this); - InputConnection ic = editorView.getInputConnection(); - setEmojiKeyboardInputConnection(ic); + editorView.setEmojiKeyboard(emojiKeyboard); + emojiKeyboard.registerEmojiInputField(editorView); editorView.setOnSubmitListener(view -> { if (shoutboxViewModel.getShoutboxMutableLiveData().getValue() == null) return; if (editorView.getText().toString().isEmpty()) { @@ -131,7 +129,7 @@ public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKey Timber.i("Start sending a shout..."); editorView.setAlpha(0.5f); editorView.setEnabled(false); - setEmojiKeyboardVisible(false); + emojiKeyboard.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE); } @@ -164,19 +162,4 @@ public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKey Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show(); } } - - @Override - public void setEmojiKeyboardVisible(boolean visible) { - emojiKeyboard.setVisibility(visible ? View.VISIBLE : View.GONE); - } - - @Override - public boolean isEmojiKeyboardVisible() { - return emojiKeyboard.getVisibility() == View.VISIBLE; - } - - @Override - public void setEmojiKeyboardInputConnection(InputConnection ic) { - emojiKeyboard.setInputConnection(ic); - } } diff --git a/app/src/main/res/layout/activity_downloads.xml b/app/src/main/res/layout/activity_downloads.xml index 0473b34f..dc92a274 100644 --- a/app/src/main/res/layout/activity_downloads.xml +++ b/app/src/main/res/layout/activity_downloads.xml @@ -1,4 +1,3 @@ - Date: Tue, 16 Oct 2018 18:07:09 +0300 Subject: [PATCH 025/104] fix crash when replying fails --- .../java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ae692219..d7284ae8 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 @@ -542,8 +542,8 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo default: Timber.w("Post reply unsuccessful"); Toast.makeText(getBaseContext(), "Post failed!", Toast.LENGTH_SHORT).show(); - recyclerView.getChildAt(topicItems.size() - 1).setAlpha(1); - recyclerView.getChildAt(topicItems.size() - 1).setEnabled(true); + recyclerView.getChildAt(recyclerView.getChildCount() - 1).setAlpha(1f); + recyclerView.getChildAt(recyclerView.getChildCount() - 1).setEnabled(true); } } }); From 278d9875c4ca04c71fa3db6a96058545d366b379 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 17 Oct 2018 12:45:47 +0300 Subject: [PATCH 026/104] bbparser init --- app/build.gradle | 2 +- .../gr/thmmy/mthmmy/session/SessionManager.java | 14 ++++++++------ .../gr/thmmy/mthmmy/utils/parsing/BBParser.java | 12 ++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java diff --git a/app/build.gradle b/app/build.gradle index 11baff14..a239de87 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,7 +65,7 @@ dependencies { implementation 'org.jsoup:jsoup:1.10.3' //TODO: Warning: upgrading from 1.10.3 will break stuff! implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' - implementation("com.mikepenz:materialdrawer:6.0.7@aar") { + implementation("com.mikepenz:materialdrawer:6.1.1@aar") { transitive = true } implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar' 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 4811195d..ffb11416 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -117,16 +117,18 @@ public class SessionManager { setPersistentCookieSession(); //Store cookies //Edit SharedPreferences, save session's data + SharedPreferences.Editor editor = sharedPrefs.edit(); setLoginScreenAsDefault(false); - sharedPrefs.edit().putBoolean(LOGGED_IN, true).apply(); - sharedPrefs.edit().putString(USERNAME, extractUserName(document)).apply(); - sharedPrefs.edit().putInt(USER_ID, extractUserId(document)).apply(); + editor.putBoolean(LOGGED_IN, true); + editor.putString(USERNAME, extractUserName(document)); + editor.putInt(USER_ID, extractUserId(document)); String avatar = extractAvatarLink(document); if (avatar != null) { - sharedPrefs.edit().putBoolean(HAS_AVATAR, true).apply(); - sharedPrefs.edit().putString(AVATAR_LINK, extractAvatarLink(document)).apply(); + editor.putBoolean(HAS_AVATAR, true); + editor.putString(AVATAR_LINK, avatar); } else - sharedPrefs.edit().putBoolean(HAS_AVATAR, false).apply(); + editor.putBoolean(HAS_AVATAR, false); + editor.apply(); sharedPrefs.edit().putString(LOGOUT_LINK, extractLogoutLink(document)).apply(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java new file mode 100644 index 00000000..9719eb83 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java @@ -0,0 +1,12 @@ +package gr.thmmy.mthmmy.utils.parsing; + +import android.text.SpannableStringBuilder; +import android.text.SpannedString; + +public class BBParser { + public static final String[] supportedTags = {"b"}; + + public SpannedString bb2span(String bb) { + SpannableStringBuilder builder = new SpannableStringBuilder(bb); + } +} From 76fdac8afc760b46247053d5aa53087382e969ab Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 17 Oct 2018 12:49:24 +0300 Subject: [PATCH 027/104] drawer upgrade --- app/build.gradle | 2 +- .../thmmy/mthmmy/session/SessionManager.java | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 11baff14..a239de87 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,7 +65,7 @@ dependencies { implementation 'org.jsoup:jsoup:1.10.3' //TODO: Warning: upgrading from 1.10.3 will break stuff! implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' - implementation("com.mikepenz:materialdrawer:6.0.7@aar") { + implementation("com.mikepenz:materialdrawer:6.1.1@aar") { transitive = true } implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar' 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 4811195d..560c7089 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -117,19 +117,17 @@ public class SessionManager { setPersistentCookieSession(); //Store cookies //Edit SharedPreferences, save session's data + SharedPreferences.Editor editor = sharedPrefs.edit(); setLoginScreenAsDefault(false); - sharedPrefs.edit().putBoolean(LOGGED_IN, true).apply(); - sharedPrefs.edit().putString(USERNAME, extractUserName(document)).apply(); - sharedPrefs.edit().putInt(USER_ID, extractUserId(document)).apply(); + editor.putBoolean(LOGGED_IN, true); + editor.putString(USERNAME, extractUserName(document)); + editor.putInt(USER_ID, extractUserId(document)); String avatar = extractAvatarLink(document); - if (avatar != null) { - sharedPrefs.edit().putBoolean(HAS_AVATAR, true).apply(); - sharedPrefs.edit().putString(AVATAR_LINK, extractAvatarLink(document)).apply(); - } else - sharedPrefs.edit().putBoolean(HAS_AVATAR, false).apply(); - - - sharedPrefs.edit().putString(LOGOUT_LINK, extractLogoutLink(document)).apply(); + if (avatar != null) + editor.putString(AVATAR_LINK, avatar); + editor.putBoolean(HAS_AVATAR, avatar != null); + editor.putString(LOGOUT_LINK, extractLogoutLink(document)); + editor.apply(); return SUCCESS; } else { From c9c3e0312353356871268d58826e6b792e518e37 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 17 Oct 2018 13:14:08 +0300 Subject: [PATCH 028/104] parse tag starts --- .../java/gr/thmmy/mthmmy/model/BBTag.java | 35 +++++++++++++++++++ .../thmmy/mthmmy/session/SessionManager.java | 10 ++---- .../thmmy/mthmmy/utils/parsing/BBParser.java | 33 +++++++++++++++++ 3 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java b/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java new file mode 100644 index 00000000..65a183fd --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java @@ -0,0 +1,35 @@ +package gr.thmmy.mthmmy.model; + +public class BBTag { + private int start, end; + private String name; + + public BBTag(int start, String name) { + this.start = start; + this.name = name; + } + + public int getStart() { + return start; + } + + public void setStart(int start) { + this.start = start; + } + + public int getEnd() { + return end; + } + + public void setEnd(int end) { + this.end = end; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} 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 ffb11416..560c7089 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -123,16 +123,12 @@ public class SessionManager { editor.putString(USERNAME, extractUserName(document)); editor.putInt(USER_ID, extractUserId(document)); String avatar = extractAvatarLink(document); - if (avatar != null) { - editor.putBoolean(HAS_AVATAR, true); + if (avatar != null) editor.putString(AVATAR_LINK, avatar); - } else - editor.putBoolean(HAS_AVATAR, false); + editor.putBoolean(HAS_AVATAR, avatar != null); + editor.putString(LOGOUT_LINK, extractLogoutLink(document)); editor.apply(); - - sharedPrefs.edit().putString(LOGOUT_LINK, extractLogoutLink(document)).apply(); - return SUCCESS; } else { Timber.i("Login failed."); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java index 9719eb83..1986c1af 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java @@ -2,11 +2,44 @@ package gr.thmmy.mthmmy.utils.parsing; import android.text.SpannableStringBuilder; import android.text.SpannedString; +import android.text.TextUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import gr.thmmy.mthmmy.model.BBTag; +import timber.log.Timber; public class BBParser { public static final String[] supportedTags = {"b"}; public SpannedString bb2span(String bb) { SpannableStringBuilder builder = new SpannableStringBuilder(bb); + BBTag[] tags = getTags(bb); + } + + public BBTag[] getTags(String bb) { + Pattern bbtagPattern = Pattern.compile("[*+]"); + + LinkedList tags = new LinkedList<>(); + String searcingString = bb; + Matcher bbMatcher = bbtagPattern.matcher(searcingString); + while (bbMatcher.find()) { + String name = bbMatcher.group(0); + if (!isSupported(name)) continue; + tags.add(new BBTag(bbMatcher.start(), name)); + searcingString = searcingString.substring(bbMatcher.start() + name.length()); + bbMatcher = bbtagPattern.matcher(searcingString); + } + return tags.toArray(new BBTag[0]); + } + + public boolean isSupported(String tagName) { + for (String tag : supportedTags) + if (TextUtils.equals(tag, tagName)) return true; + return false; } } From 2a950aa752721e89e335ec1203354a8116bb41f0 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 17 Oct 2018 13:17:06 +0300 Subject: [PATCH 029/104] drawer update 2 --- app/build.gradle | 4 +--- app/src/main/assets/apache_libraries.html | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a239de87..c7f02045 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,9 +65,7 @@ dependencies { implementation 'org.jsoup:jsoup:1.10.3' //TODO: Warning: upgrading from 1.10.3 will break stuff! implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' - implementation("com.mikepenz:materialdrawer:6.1.1@aar") { - transitive = true - } + implementation "com.mikepenz:materialdrawer:6.1.1" implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar' implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15' diff --git a/app/src/main/assets/apache_libraries.html b/app/src/main/assets/apache_libraries.html index a8ff5d90..226615b6 100644 --- a/app/src/main/assets/apache_libraries.html +++ b/app/src/main/assets/apache_libraries.html @@ -51,7 +51,7 @@
MPAndroidChart v3.0.3 (Copyright ©2018 Philipp Jahoda)
  • -
    MaterialDrawer v6.0.7 (Copyright ©2018 Mike Penz)
    +
    MaterialDrawer v6.1.1 (Copyright ©2018 Mike Penz)
  • Android-Iconics v2.9.5 (Copyright ©2016 Mike Penz)
    From ca3281387bb472cfeea9ca61c742b0ea0cc2ad03 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 17 Oct 2018 13:39:36 +0300 Subject: [PATCH 030/104] progress --- .../thmmy/mthmmy/utils/parsing/BBParser.java | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java index 1986c1af..18d70d49 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java @@ -1,9 +1,13 @@ package gr.thmmy.mthmmy.utils.parsing; +import android.graphics.Typeface; +import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.SpannedString; import android.text.TextUtils; +import android.text.style.StyleSpan; +import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; @@ -14,30 +18,47 @@ import gr.thmmy.mthmmy.model.BBTag; import timber.log.Timber; public class BBParser { - public static final String[] supportedTags = {"b"}; + private static final String[] supportedTags = {"b"}; - public SpannedString bb2span(String bb) { + public static SpannedString bb2span(String bb) { SpannableStringBuilder builder = new SpannableStringBuilder(bb); BBTag[] tags = getTags(bb); + for (BBTag tag : tags) { + switch (tag.getName()) { + case "b": + builder.setSpan(new StyleSpan(Typeface.BOLD), tag.getStart(), tag.getEnd(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + break; + default: + throw new UnsupportedCharsetException("Tag not supported"); + } + } } - public BBTag[] getTags(String bb) { - Pattern bbtagPattern = Pattern.compile("[*+]"); + public static BBTag[] getTags(String bb) { + Pattern bbtagPattern = Pattern.compile("\\[(.+?)\\]"); LinkedList tags = new LinkedList<>(); - String searcingString = bb; - Matcher bbMatcher = bbtagPattern.matcher(searcingString); + Matcher bbMatcher = bbtagPattern.matcher(bb); while (bbMatcher.find()) { String name = bbMatcher.group(0); - if (!isSupported(name)) continue; - tags.add(new BBTag(bbMatcher.start(), name)); - searcingString = searcingString.substring(bbMatcher.start() + name.length()); - bbMatcher = bbtagPattern.matcher(searcingString); + if (name.startsWith("/")) { + //closing tag + name = name.substring(1); + for (int i = tags.size() - 1; i >= 0; i--) { + if (tags.get(i).getName().equals(name)) { + tags.get(i).setEnd(bbMatcher.start()); + break; + } + } + continue; + } + if (isSupported(name)) + tags.add(new BBTag(bbMatcher.start(), name)); } return tags.toArray(new BBTag[0]); } - public boolean isSupported(String tagName) { + public static boolean isSupported(String tagName) { for (String tag : supportedTags) if (TextUtils.equals(tag, tagName)) return true; return false; From 907998d59d6155972866acf93d39576362b7b939 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 17 Oct 2018 13:51:18 +0300 Subject: [PATCH 031/104] AndroidX refactoring fix --- app/build.gradle | 2 +- .../gr/thmmy/mthmmy/base/BaseActivity.java | 1 + .../res/xml-v26/app_preferences_guest.xml | 18 +++++------ .../main/res/xml-v26/app_preferences_user.xml | 30 +++++++++---------- .../main/res/xml/app_preferences_guest.xml | 26 ++++++++-------- 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c7f02045..71169d70 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,6 +56,7 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'com.google.firebase:firebase-core:16.0.4' implementation 'com.google.firebase:firebase-messaging:17.3.3' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' @@ -75,7 +76,6 @@ dependencies { implementation "ru.noties:markwon:2.0.0" implementation 'net.gotev:uploadservice:3.4.2' implementation 'net.gotev:uploadservice-okhttp:3.4.2' - implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' } 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 485596fe..a44a0b99 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -323,6 +323,7 @@ public abstract class BaseActivity extends AppCompatActivity { .withCompactStyle(true) .withSelectionListEnabledForSingleProfile(false) .withHeaderBackground(R.color.primary) + .withTextColor(getResources().getColor(R.color.iron)) .addProfiles(profileDrawerItem) .withOnAccountHeaderListener((view, profile, currentProfile) -> { if (sessionManager.isLoggedIn()) { diff --git a/app/src/main/res/xml-v26/app_preferences_guest.xml b/app/src/main/res/xml-v26/app_preferences_guest.xml index ee4ff969..2aa3e166 100644 --- a/app/src/main/res/xml-v26/app_preferences_guest.xml +++ b/app/src/main/res/xml-v26/app_preferences_guest.xml @@ -1,8 +1,8 @@ - + - - + - + - - - - + - + diff --git a/app/src/main/res/xml-v26/app_preferences_user.xml b/app/src/main/res/xml-v26/app_preferences_user.xml index 4b62ebdb..6010320f 100644 --- a/app/src/main/res/xml-v26/app_preferences_user.xml +++ b/app/src/main/res/xml-v26/app_preferences_user.xml @@ -1,8 +1,8 @@ - + - - + - + - - - + - + --> - - - - + - + diff --git a/app/src/main/res/xml/app_preferences_guest.xml b/app/src/main/res/xml/app_preferences_guest.xml index 4aa2227f..364ad5a1 100644 --- a/app/src/main/res/xml/app_preferences_guest.xml +++ b/app/src/main/res/xml/app_preferences_guest.xml @@ -1,8 +1,8 @@ - + - - + - + - - + - - + - - - - + - \ No newline at end of file + From de3c5643259c20454c75c72ad46d6847aa67d043 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 17 Oct 2018 13:59:35 +0300 Subject: [PATCH 032/104] Drawer icon order fix --- app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 a44a0b99..85b12555 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -408,9 +408,9 @@ public abstract class BaseActivity extends AppCompatActivity { }); if (sessionManager.isLoggedIn()) - drawerBuilder.addDrawerItems(homeItem, shoutboxItem, bookmarksItem, downloadsItem, settingsItem, loginLogoutItem, aboutItem); + drawerBuilder.addDrawerItems(homeItem, bookmarksItem, shoutboxItem, downloadsItem, settingsItem, loginLogoutItem, aboutItem); else - drawerBuilder.addDrawerItems(homeItem, shoutboxItem, bookmarksItem, settingsItem, loginLogoutItem, aboutItem); + drawerBuilder.addDrawerItems(homeItem, bookmarksItem, shoutboxItem, settingsItem, loginLogoutItem, aboutItem); drawer = drawerBuilder.build(); @@ -434,10 +434,10 @@ public abstract class BaseActivity extends AppCompatActivity { setDefaultAvatar(); } else { if (!drawer.getDrawerItems().contains(downloadsItem)) { - drawer.addItemAtPosition(downloadsItem, 3); + drawer.addItemAtPosition(downloadsItem, 4); } // if (!drawer.getDrawerItems().contains(uploadItem)) { -// drawer.addItemAtPosition(uploadItem, 4); +// drawer.addItemAtPosition(uploadItem, 5); // } loginLogoutItem.withName(R.string.logout).withIcon(logoutIcon); //Swap login with logout profileDrawerItem.withName(sessionManager.getUsername()); From ebff5cee34a7340d3776d43f93e0a06bde8c6dcb Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 17 Oct 2018 15:08:32 +0300 Subject: [PATCH 033/104] Added more version info in About for debug builds --- app/build.gradle | 25 +++++++++++++++ .../mthmmy/activities/AboutActivity.java | 31 +++++++++++++++---- build.gradle | 1 + 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 71169d70..a5e0cbee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ import groovy.json.JsonSlurper +import org.ajoberstar.grgit.Grgit apply plugin: 'com.android.application' apply plugin: 'io.fabric' @@ -14,6 +15,8 @@ android { versionCode 14 versionName "1.5.0" archivesBaseName = "mTHMMY-v$versionName" + buildConfigField "String", "CURRENT_BRANCH", "\"" + getCurrentBranch() + "\"" + buildConfigField "String", "COMMIT_HASH", "\"" + getCommitHash() + "\"" } buildTypes { @@ -47,6 +50,28 @@ tasks.whenTaskAdded { task -> } } +static def getCurrentBranch() { + try { + def grgit = Grgit.open() + def curBranch = grgit.branch.getCurrent().name + grgit.close() + return curBranch + } catch (Exception ignored) { + return "" + } +} + +static def getCommitHash() { + try { + def grgit = Grgit.open() + def commitHash = grgit.head().id + grgit.close() + return commitHash + } catch (Exception ignored) { + return "" + } +} + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0' 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 0fac281f..741e11f3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -1,6 +1,8 @@ package gr.thmmy.mthmmy.activities; +import android.content.Intent; import android.content.pm.ActivityInfo; +import android.net.Uri; import android.os.Bundle; import com.google.android.material.appbar.AppBarLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; @@ -38,6 +40,18 @@ public class AboutActivity extends BaseActivity { setContentView(R.layout.activity_about); String versionName = BuildConfig.VERSION_NAME; + boolean gitExists = true; + + String commitHash = BuildConfig.COMMIT_HASH; + if (commitHash.length() > 8) + commitHash = commitHash.substring(0, 8); + else + gitExists = false; + + String versionInfo = ""; + if(gitExists) + versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash; + //Initialize appbar appBar = findViewById(R.id.appbar); coordinatorLayout = findViewById(R.id.main_content); @@ -59,14 +73,19 @@ public class AboutActivity extends BaseActivity { TextView tv = findViewById(R.id.version); if (tv != null) { if (BuildConfig.DEBUG) - tv.setText(getString(R.string.version, versionName + "-debug")); + tv.setText(getString(R.string.version, versionName + versionInfo)); else tv.setText(getString(R.string.version, versionName)); - tv.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + if(BuildConfig.DEBUG && gitExists){ + tv.setOnClickListener(view -> { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/ThmmyNoLife/mTHMMY/commit/" + BuildConfig.COMMIT_HASH)); + startActivity(intent); + }); + } + else{ // Easter Egg + tv.setOnClickListener(view -> { if (mVersionLastPressedTime + TIME_INTERVAL > System.currentTimeMillis()) { if (mVersionPressedCounter == TIMES_TO_PRESS) { appBar.setVisibility(View.INVISIBLE); @@ -81,8 +100,8 @@ public class AboutActivity extends BaseActivity { mVersionLastPressedTime = System.currentTimeMillis(); mVersionPressedCounter = 0; } - } - }); + }); + } } TextView privacyPolicy = findViewById(R.id.privacy_policy_header); diff --git a/build.gradle b/build.gradle index 11cbc2e0..74c7bcf9 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,7 @@ buildscript { classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.google.gms:google-services:4.1.0' classpath 'io.fabric.tools:gradle:1.26.1' + classpath 'org.ajoberstar.grgit:grgit-core:3.0.0-rc.2' } } From 9acc409f3e01b6a6819a9067c029245538da672f Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 17 Oct 2018 15:17:01 +0300 Subject: [PATCH 034/104] Added missing library reference --- app/src/main/assets/apache_libraries.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/apache_libraries.html b/app/src/main/assets/apache_libraries.html index 226615b6..cd224e39 100644 --- a/app/src/main/assets/apache_libraries.html +++ b/app/src/main/assets/apache_libraries.html @@ -68,6 +68,9 @@
  • Markwon v2.0.0 (Copyright ©2017 Dimitry Ivanov)
  • +
  • +
    Grgit v3.0.0-rc.2 (Copyright ©2018 Andrew Oberstar)
    +
  • From 11d8a4eb83cae74df93c99a38bb23da827fd54f1 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 17 Oct 2018 17:33:15 +0300 Subject: [PATCH 035/104] fix tab icons --- .../mthmmy/activities/main/MainActivity.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) 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 4a64499f..a4e4449e 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 @@ -75,6 +75,9 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF //Initialize drawer createDrawer(); + tabLayout = findViewById(R.id.tabs); + viewPager = findViewById(R.id.container); + //Create the adapter that will return a fragment for each section of the activity sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); sectionsPagerAdapter.addFragment(RecentFragment.newInstance(1), "RECENT"); @@ -83,9 +86,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); //Set up the ViewPager with the sections adapter. - viewPager = findViewById(R.id.container); viewPager.setAdapter(sectionsPagerAdapter); - tabLayout = findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -94,13 +95,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF tabLayout.getTabAt(preferredTab).select(); } for (int i = 0; i < tabLayout.getTabCount(); i++) { - if (i == 0) { - tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_access_time_white_24dp)); - } else if (i == 1) { - tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_forum_white_24dp)); - }else if (i == 2) { - tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp)); - } + updateTabIcon(i); } setMainActivity(this); @@ -186,6 +181,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF fragmentList.add(fragment); fragmentTitleList.add(title); notifyDataSetChanged(); + updateTabIcon(fragmentList.size() - 1); } void removeFragment(int position) { @@ -219,13 +215,26 @@ 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)); + } else if (position == 1) { + tabLayout.getTabAt(1).setIcon(getResources().getDrawable(R.drawable.ic_forum_white_24dp)); + } else if (position == 2) { + tabLayout.getTabAt(2).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp)); + } + } + + public void updateTabs() { if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3) { sectionsPagerAdapter.removeFragment(2); - } - else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) { + } else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) { sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); - tabLayout.getTabAt(2).setIcon(R.drawable.ic_fiber_new_white_24dp); + } + for (int i = 0; i < tabLayout.getTabCount(); i++) { + updateTabIcon(i); } } //-------------------------------FragmentPagerAdapter END------------------------------------------- From c181507fd4ebd8a91d09cde2a390bbfb5cc2879a Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 17 Oct 2018 17:40:12 +0300 Subject: [PATCH 036/104] enable shoutbox icon tinting --- app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java | 3 ++- app/src/main/res/drawable/ic_announcement.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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 85b12555..39713ffc 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -268,7 +268,8 @@ public abstract class BaseActivity extends AppCompatActivity { .withName(R.string.shoutbox) .withIcon(R.drawable.ic_announcement) .withIconColor(primaryColor) - .withSelectedIconColor(selectedSecondaryColor); + .withSelectedIconColor(selectedSecondaryColor) + .withIconTintingEnabled(true); if (sessionManager.isLoggedIn()) //When logged in { diff --git a/app/src/main/res/drawable/ic_announcement.xml b/app/src/main/res/drawable/ic_announcement.xml index 8a402416..c7878be2 100644 --- a/app/src/main/res/drawable/ic_announcement.xml +++ b/app/src/main/res/drawable/ic_announcement.xml @@ -3,5 +3,5 @@ android:tint="#FFFFFF"> + android:strokeColor="#000000" android:strokeWidth="1"/> From d52178d793df693db7899c5e070ba3108907848e Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 18 Oct 2018 13:15:24 +0300 Subject: [PATCH 037/104] Reduced size of username in drawer --- app/build.gradle | 5 ++--- .../thmmy/mthmmy/activities/AboutActivity.java | 12 ++++++------ .../thmmy/mthmmy/activities/LoginActivity.java | 4 ++-- .../mthmmy/activities/board/BoardActivity.java | 11 ++++++----- .../mthmmy/activities/board/BoardAdapter.java | 2 +- .../bookmarks/BoardBookmarksFragment.java | 4 ++-- .../activities/bookmarks/BookmarkActivity.java | 11 ++++++----- .../bookmarks/TopicBookmarksFragment.java | 6 +++--- .../create_content/CreateContentActivity.java | 3 ++- .../activities/downloads/DownloadsAdapter.java | 2 +- .../activities/main/forum/ForumAdapter.java | 4 ++-- .../activities/main/forum/ForumFragment.java | 6 +++--- .../activities/main/recent/RecentAdapter.java | 4 ++-- .../activities/main/recent/RecentFragment.java | 6 +++--- .../activities/main/unread/UnreadAdapter.java | 4 ++-- .../activities/main/unread/UnreadFragment.java | 8 ++++---- .../activities/profile/ProfileActivity.java | 16 ++++++++-------- .../profile/latestPosts/LatestPostsAdapter.java | 2 +- .../profile/latestPosts/LatestPostsFragment.java | 6 +++--- .../activities/profile/stats/StatsFragment.java | 2 +- .../profile/summary/SummaryFragment.java | 2 +- .../activities/settings/SettingsActivity.java | 2 +- .../activities/settings/SettingsFragment.java | 8 ++++---- .../mthmmy/activities/topic/TopicActivity.java | 15 ++++++++------- .../mthmmy/activities/topic/TopicAdapter.java | 15 +++++++-------- .../mthmmy/activities/upload/UploadActivity.java | 11 ++++++----- .../upload/UploadFieldsBuilderActivity.java | 6 +++--- .../mthmmy/activities/upload/UploadsHelper.java | 4 ++-- .../gr/thmmy/mthmmy/base/BaseApplication.java | 2 +- .../java/gr/thmmy/mthmmy/base/BaseFragment.java | 2 +- .../thmmy/mthmmy/editorview/EmojiKeyboard.java | 6 +++--- .../mthmmy/editorview/EmojiKeyboardAdapter.java | 6 +++--- .../mthmmy/editorview/FormatButtonsAdapter.java | 6 +++--- .../java/gr/thmmy/mthmmy/model/Bookmark.java | 6 +++--- .../main/java/gr/thmmy/mthmmy/model/Post.java | 4 ++-- .../java/gr/thmmy/mthmmy/model/Shoutbox.java | 3 --- .../mthmmy/services/NotificationService.java | 6 +++--- .../gr/thmmy/mthmmy/session/SessionManager.java | 4 ++-- .../utils/AppCompatSpinnerWithoutDefault.java | 3 ++- .../thmmy/mthmmy/utils/CenterVerticalSpan.java | 3 ++- .../mthmmy/utils/CustomLinearLayoutManager.java | 2 +- .../thmmy/mthmmy/utils/CustomRecyclerView.java | 3 ++- .../java/gr/thmmy/mthmmy/utils/FileUtils.java | 3 ++- .../mthmmy/utils/ScrollAwareFABBehavior.java | 10 ++++++---- .../mthmmy/utils/ScrollAwareLinearBehavior.java | 10 ++++++---- .../gr/thmmy/mthmmy/viewmodel/BaseViewModel.java | 1 - .../thmmy/mthmmy/viewmodel/TopicViewModel.java | 2 +- app/src/main/res/values/dimens.xml | 1 + 48 files changed, 136 insertions(+), 128 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a5e0cbee..be0f9541 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -75,13 +75,14 @@ static def getCommitHash() { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0' - implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.preference:preference:1.0.0' implementation 'androidx.legacy:legacy-preference-v14:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.firebase:firebase-core:16.0.4' implementation 'com.google.firebase:firebase-messaging:17.3.3' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' @@ -101,8 +102,6 @@ dependencies { implementation "ru.noties:markwon:2.0.0" implementation 'net.gotev:uploadservice:3.4.2' implementation 'net.gotev:uploadservice-okhttp:3.4.2' - implementation 'com.google.android.material:material:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' } apply plugin: 'com.google.gms.google-services' 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 741e11f3..93016bc0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -4,11 +4,6 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.net.Uri; import android.os.Bundle; -import com.google.android.material.appbar.AppBarLayout; -import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.drawerlayout.widget.DrawerLayout; -import androidx.appcompat.app.AlertDialog; - import android.text.SpannableString; import android.text.method.LinkMovementMethod; import android.text.style.UnderlineSpan; @@ -19,6 +14,11 @@ import android.widget.FrameLayout; import android.widget.ScrollView; import android.widget.TextView; +import com.google.android.material.appbar.AppBarLayout; + +import androidx.appcompat.app.AlertDialog; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.drawerlayout.widget.DrawerLayout; import gr.thmmy.mthmmy.BuildConfig; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; @@ -50,7 +50,7 @@ public class AboutActivity extends BaseActivity { String versionInfo = ""; if(gitExists) - versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash; + versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash + " "; //Initialize appbar appBar = findViewById(R.id.appbar); 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 ba423202..29ab9b1b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java @@ -3,8 +3,6 @@ package gr.thmmy.mthmmy.activities; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; -import androidx.preference.PreferenceManager; -import androidx.appcompat.widget.AppCompatButton; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; @@ -14,6 +12,8 @@ import android.widget.Toast; import com.google.firebase.analytics.FirebaseAnalytics; +import androidx.appcompat.widget.AppCompatButton; +import androidx.preference.PreferenceManager; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.base.BaseActivity; 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 addf7ff5..ae6852fb 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 @@ -4,15 +4,12 @@ import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import androidx.appcompat.app.AlertDialog; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.view.View; import android.widget.ProgressBar; import android.widget.Toast; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; @@ -20,6 +17,10 @@ import org.jsoup.select.Elements; import java.util.ArrayList; import java.util.Objects; +import androidx.appcompat.app.AlertDialog; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.create_content.CreateContentActivity; 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 6b0c7267..7467c408 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 @@ -5,7 +5,6 @@ import android.content.Intent; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -16,6 +15,7 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.Objects; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.model.Board; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java index b191aebd..8a14611c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java @@ -5,8 +5,6 @@ import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -16,6 +14,8 @@ import android.widget.TextView; import java.util.ArrayList; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.model.Bookmark; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java index 57cec031..d6ba695c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java @@ -2,17 +2,18 @@ package gr.thmmy.mthmmy.activities.bookmarks; import android.content.Intent; import android.os.Bundle; +import android.widget.Toast; + import com.google.android.material.tabs.TabLayout; + +import java.util.ArrayList; +import java.util.List; + import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.viewpager.widget.ViewPager; -import android.widget.Toast; - -import java.util.ArrayList; -import java.util.List; - import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java index d57cba4e..77992b2d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java @@ -5,9 +5,6 @@ import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; -import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,6 +14,9 @@ import android.widget.TextView; import java.util.ArrayList; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.model.Bookmark; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java index bc9b3382..920a03b9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java @@ -4,13 +4,14 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import com.google.android.material.textfield.TextInputLayout; import android.text.InputType; import android.text.TextUtils; import android.view.View; import android.view.inputmethod.EditorInfo; import android.widget.Toast; +import com.google.android.material.textfield.TextInputLayout; + import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.base.BaseActivity; 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 5f38aea5..5b6ec26e 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 @@ -5,7 +5,6 @@ import android.content.Intent; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -18,6 +17,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Objects; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.Download; 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 1890ff8f..718c1b8d 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 @@ -1,8 +1,6 @@ package gr.thmmy.mthmmy.activities.main.forum; import android.content.Context; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -14,6 +12,8 @@ import com.bignerdranch.expandablerecyclerview.ParentViewHolder; import java.util.List; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.Board; 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 5b1aa286..782ffb71 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 @@ -2,9 +2,6 @@ package gr.thmmy.mthmmy.activities.main.forum; import android.os.AsyncTask; import android.os.Bundle; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -22,6 +19,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseApplication; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java index 7a05cb3e..31871069 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java @@ -1,8 +1,6 @@ package gr.thmmy.mthmmy.activities.main.recent; import android.content.Context; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -10,6 +8,8 @@ import android.widget.TextView; import java.util.List; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.TopicSummary; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 34175435..01f84261 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -2,9 +2,6 @@ package gr.thmmy.mthmmy.activities.main.recent; import android.os.AsyncTask; import android.os.Bundle; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,6 +17,9 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseFragment; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java index 826e37fb..8810da1a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java @@ -1,7 +1,5 @@ package gr.thmmy.mthmmy.activities.main.unread; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -9,6 +7,8 @@ import android.widget.TextView; import java.util.List; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.TopicSummary; 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 18ff8039..76b595dd 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 @@ -2,10 +2,6 @@ package gr.thmmy.mthmmy.activities.main.unread; import android.os.AsyncTask; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -21,6 +17,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseFragment; 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 ce19849d..99015a2b 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 @@ -7,14 +7,6 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.material.tabs.TabLayout; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentPagerAdapter; -import androidx.core.content.res.ResourcesCompat; -import androidx.viewpager.widget.ViewPager; -import androidx.appcompat.app.AppCompatDelegate; import android.text.Spannable; import android.text.SpannableString; import android.text.Spanned; @@ -26,6 +18,8 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.tabs.TabLayout; import com.squareup.picasso.Picasso; import org.jsoup.Jsoup; @@ -39,6 +33,12 @@ import java.util.Objects; import javax.net.ssl.SSLHandshakeException; +import androidx.appcompat.app.AppCompatDelegate; +import androidx.core.content.res.ResourcesCompat; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.profile.latestPosts.LatestPostsFragment; import gr.thmmy.mthmmy.activities.profile.stats.StatsFragment; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java index 31ec223d..e3c3ec8d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java @@ -1,6 +1,5 @@ package gr.thmmy.mthmmy.activities.profile.latestPosts; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -10,6 +9,7 @@ import android.widget.TextView; import java.util.ArrayList; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.PostSummary; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index 356fbab7..9736d3fd 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -2,9 +2,6 @@ package gr.thmmy.mthmmy.activities.profile.latestPosts; import android.os.AsyncTask; import android.os.Bundle; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,6 +17,9 @@ import java.util.ArrayList; import javax.net.ssl.SSLHandshakeException; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseFragment; 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 2ae7140a..eca17c0e 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 @@ -4,7 +4,6 @@ import android.graphics.Color; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -38,6 +37,7 @@ import java.util.List; import javax.net.ssl.SSLHandshakeException; +import androidx.fragment.app.Fragment; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; 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 f3d68fe4..867707ee 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 @@ -4,7 +4,6 @@ import android.graphics.Color; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import androidx.fragment.app.Fragment; import android.text.Html; import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; @@ -22,6 +21,7 @@ import org.jsoup.select.Elements; import java.util.ArrayList; import java.util.Objects; +import androidx.fragment.app.Fragment; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import timber.log.Timber; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java index cc2a7f6d..a884d3a6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java @@ -1,8 +1,8 @@ package gr.thmmy.mthmmy.activities.settings; import android.os.Bundle; -import androidx.fragment.app.FragmentTransaction; +import androidx.fragment.app.FragmentTransaction; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; 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 5956e79a..eb0a2070 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 @@ -8,15 +8,15 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import android.provider.Settings; -import androidx.annotation.NonNull; -import androidx.preference.ListPreference; -import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import android.view.View; import android.widget.Toast; import java.util.ArrayList; +import androidx.annotation.NonNull; +import androidx.preference.ListPreference; +import androidx.preference.Preference; +import androidx.preference.PreferenceFragmentCompat; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseApplication; import timber.log.Timber; 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 d7284ae8..88be719c 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 @@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.topic; import android.annotation.SuppressLint; import android.app.NotificationManager; -import androidx.lifecycle.ViewModelProviders; import android.content.Context; import android.content.Intent; import android.graphics.Rect; @@ -10,12 +9,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.material.snackbar.Snackbar; -import androidx.core.content.res.ResourcesCompat; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatDelegate; -import androidx.recyclerview.widget.RecyclerView; import android.text.Spannable; import android.text.SpannableString; import android.text.SpannableStringBuilder; @@ -34,8 +27,16 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; + import java.util.ArrayList; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatDelegate; +import androidx.core.content.res.ResourcesCompat; +import androidx.lifecycle.ViewModelProviders; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.topic.tasks.EditTask; import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditTask; 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 1c32ce2d..53ef01cc 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 @@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.topic; import android.annotation.SuppressLint; import android.annotation.TargetApi; -import androidx.lifecycle.ViewModelProviders; import android.content.Context; import android.content.Intent; import android.graphics.Color; @@ -11,13 +10,6 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.core.content.res.ResourcesCompat; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.content.res.AppCompatResources; -import androidx.appcompat.widget.AppCompatButton; -import androidx.recyclerview.widget.RecyclerView; - import android.text.Html; import android.text.InputType; import android.text.TextUtils; @@ -54,6 +46,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.appcompat.widget.AppCompatButton; +import androidx.core.content.res.ResourcesCompat; +import androidx.lifecycle.ViewModelProviders; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; 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 a7d7dc22..44988402 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 @@ -11,11 +11,6 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.MediaStore; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import androidx.appcompat.content.res.AppCompatResources; -import androidx.preference.PreferenceManager; -import androidx.appcompat.widget.AppCompatButton; -import androidx.appcompat.widget.AppCompatTextView; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -24,6 +19,8 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.Toast; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + import net.gotev.uploadservice.MultipartUploadRequest; import net.gotev.uploadservice.ServerResponse; import net.gotev.uploadservice.UploadInfo; @@ -43,6 +40,10 @@ import java.util.Date; import java.util.List; import java.util.Locale; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.appcompat.widget.AppCompatButton; +import androidx.appcompat.widget.AppCompatTextView; +import androidx.preference.PreferenceManager; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseApplication; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java index fffb5064..f9fd9407 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java @@ -3,9 +3,6 @@ package gr.thmmy.mthmmy.activities.upload; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; import android.text.Editable; import android.text.TextWatcher; import android.view.View; @@ -16,6 +13,9 @@ import android.widget.Toast; import java.util.Calendar; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import gr.thmmy.mthmmy.R; import timber.log.Timber; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java index 0da38a6e..e5f5301b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java @@ -10,8 +10,6 @@ import android.media.ExifInterface; import android.net.Uri; import android.os.Environment; import android.provider.OpenableColumns; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import android.widget.Toast; import java.io.BufferedInputStream; @@ -22,6 +20,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import timber.log.Timber; class UploadsHelper { 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 a6cf97eb..d181301d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -6,7 +6,6 @@ import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; -import androidx.core.content.ContextCompat; import android.util.DisplayMetrics; import android.widget.ImageView; @@ -29,6 +28,7 @@ import net.gotev.uploadservice.okhttp.OkHttpStack; import java.util.Objects; import java.util.concurrent.TimeUnit; +import androidx.core.content.ContextCompat; import androidx.preference.PreferenceManager; import gr.thmmy.mthmmy.BuildConfig; import gr.thmmy.mthmmy.R; 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 960834e0..03622e83 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java @@ -2,9 +2,9 @@ package gr.thmmy.mthmmy.base; import android.content.Context; import android.os.Bundle; + import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; - import okhttp3.OkHttpClient; public abstract class BaseFragment extends Fragment { diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboard.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboard.java index 717aedf0..cd57fb5e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboard.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboard.java @@ -2,9 +2,6 @@ package gr.thmmy.mthmmy.editorview; import android.content.Context; import android.os.Handler; -import androidx.appcompat.widget.AppCompatImageButton; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -14,6 +11,9 @@ import android.widget.LinearLayout; import java.util.HashSet; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; public class EmojiKeyboard extends LinearLayout implements IEmojiKeyboard { diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboardAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboardAdapter.java index 39e81c06..c3b0758b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboardAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EmojiKeyboardAdapter.java @@ -1,13 +1,13 @@ package gr.thmmy.mthmmy.editorview; import android.graphics.drawable.AnimationDrawable; -import androidx.annotation.NonNull; -import androidx.appcompat.widget.AppCompatImageButton; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; public class EmojiKeyboardAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/FormatButtonsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/FormatButtonsAdapter.java index 6daa6ccc..98277550 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/FormatButtonsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/FormatButtonsAdapter.java @@ -1,12 +1,12 @@ package gr.thmmy.mthmmy.editorview; -import androidx.annotation.NonNull; -import androidx.appcompat.widget.AppCompatImageButton; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; public class FormatButtonsAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java b/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java index 6c07448b..de35e0d0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java @@ -1,11 +1,11 @@ package gr.thmmy.mthmmy.model; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import java.util.ArrayList; import java.util.Objects; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + public class Bookmark implements java.io.Serializable { private final String title, id; private boolean isNotificationsEnabled; diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java index ce212d3b..f3c9bd8d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java @@ -1,10 +1,10 @@ package gr.thmmy.mthmmy.model; -import androidx.annotation.Nullable; - import java.util.ArrayList; import java.util.Objects; +import androidx.annotation.Nullable; + /** * Class that defines a topic's post. All member variables are declared final (thus no setters are * supplied). Class has two constructors and getter methods for all variables. diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Shoutbox.java b/app/src/main/java/gr/thmmy/mthmmy/model/Shoutbox.java index 73f0cc3e..0bc13d30 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Shoutbox.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Shoutbox.java @@ -1,8 +1,5 @@ package gr.thmmy.mthmmy.model; -import androidx.annotation.NonNull; -import timber.log.Timber; - public class Shoutbox { private Shout[] shouts; private String sc, sendShoutUrl, shoutName, shoutSend, shoutUrl; 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 eadda267..6d254021 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java @@ -12,9 +12,6 @@ import android.net.Uri; 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; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; @@ -22,6 +19,9 @@ import com.google.firebase.messaging.RemoteMessage; import org.json.JSONException; import org.json.JSONObject; +import androidx.annotation.RequiresApi; +import androidx.core.app.NotificationCompat; +import androidx.preference.PreferenceManager; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.base.BaseApplication; 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 560c7089..97e1dddb 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -1,8 +1,6 @@ package gr.thmmy.mthmmy.session; import android.content.SharedPreferences; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; @@ -17,6 +15,8 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import gr.thmmy.mthmmy.utils.parsing.ParseException; import okhttp3.Cookie; import okhttp3.FormBody; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/AppCompatSpinnerWithoutDefault.java b/app/src/main/java/gr/thmmy/mthmmy/utils/AppCompatSpinnerWithoutDefault.java index e4848661..b64bb57d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/AppCompatSpinnerWithoutDefault.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/AppCompatSpinnerWithoutDefault.java @@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.utils; import android.annotation.SuppressLint; import android.content.Context; -import androidx.appcompat.widget.AppCompatSpinner; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -15,6 +14,8 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import androidx.appcompat.widget.AppCompatSpinner; + public class AppCompatSpinnerWithoutDefault extends AppCompatSpinner { public AppCompatSpinnerWithoutDefault(Context context) { super(context); 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 5038fe19..104dd01e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java @@ -3,9 +3,10 @@ package gr.thmmy.mthmmy.utils; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; -import androidx.annotation.NonNull; import android.text.style.ReplacementSpan; +import androidx.annotation.NonNull; + public class CenterVerticalSpan extends ReplacementSpan { @Override public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java index 8e8cf800..de9abfd0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java @@ -1,9 +1,9 @@ package gr.thmmy.mthmmy.utils; import android.content.Context; + import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; - import timber.log.Timber; public class CustomLinearLayoutManager extends LinearLayoutManager { diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CustomRecyclerView.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CustomRecyclerView.java index 828b7dab..766e7207 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CustomRecyclerView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CustomRecyclerView.java @@ -1,10 +1,11 @@ package gr.thmmy.mthmmy.utils; import android.content.Context; +import android.util.AttributeSet; + import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import android.util.AttributeSet; //Custom RecyclerView, so EdgeEffect and SwipeRefresh both work public class CustomRecyclerView extends RecyclerView { 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 b9121a7b..1c8eb0b0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java @@ -1,10 +1,11 @@ package gr.thmmy.mthmmy.utils; -import androidx.annotation.NonNull; import android.webkit.MimeTypeMap; import java.io.File; +import androidx.annotation.NonNull; + import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR; public class FileUtils { diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java index d832c6f2..46d412bc 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java @@ -1,13 +1,15 @@ package gr.thmmy.mthmmy.utils; import android.content.Context; -import androidx.annotation.NonNull; -import androidx.coordinatorlayout.widget.CoordinatorLayout; +import android.util.AttributeSet; +import android.view.View; + import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; + +import androidx.annotation.NonNull; +import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.ViewCompat; -import android.util.AttributeSet; -import android.view.View; /** * Extends FloatingActionButton's behavior so the button will hide when scrolling down and show diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java index c5dfa227..91e2305c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java @@ -2,14 +2,16 @@ package gr.thmmy.mthmmy.utils; import android.animation.Animator; import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewPropertyAnimator; + +import com.google.android.material.snackbar.Snackbar; + import androidx.annotation.NonNull; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import com.google.android.material.snackbar.Snackbar; import androidx.core.view.ViewCompat; import androidx.interpolator.view.animation.FastOutSlowInInterpolator; -import android.util.AttributeSet; -import android.view.View; -import android.view.ViewPropertyAnimator; /** * Extends LinearLayout's behavior. Used for bottom navigation bar. diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/BaseViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/BaseViewModel.java index 5787b36d..a038c033 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/BaseViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/BaseViewModel.java @@ -3,7 +3,6 @@ package gr.thmmy.mthmmy.viewmodel; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; - import gr.thmmy.mthmmy.model.Bookmark; public class BaseViewModel extends ViewModel { diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index 200ac80d..e68dcfb0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -1,6 +1,5 @@ package gr.thmmy.mthmmy.viewmodel; -import androidx.lifecycle.MutableLiveData; import android.content.Context; import android.content.SharedPreferences; import android.os.AsyncTask; @@ -11,6 +10,7 @@ import android.widget.RadioGroup; import java.util.ArrayList; +import androidx.lifecycle.MutableLiveData; import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.activities.topic.tasks.DeleteTask; import gr.thmmy.mthmmy.activities.topic.tasks.EditTask; diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index f8c62284..40501360 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -12,4 +12,5 @@ 24dp 6dp 12dp + 16sp From 28e2bdfe740883a60a782f59f50a9accbde76510 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Thu, 18 Oct 2018 17:21:47 +0300 Subject: [PATCH 038/104] maybe finish the parse/modify string logic --- app/src/main/AndroidManifest.xml | 22 ++++++--- .../thmmy/mthmmy/activities/TestActivity.java | 28 +++++++++++ .../mthmmy/activities/main/MainActivity.java | 3 ++ .../java/gr/thmmy/mthmmy/model/BBTag.java | 8 ++++ .../thmmy/mthmmy/utils/parsing/BBParser.java | 46 +++++++++++++++++-- app/src/main/res/layout/activity_test.xml | 20 ++++++++ 6 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/TestActivity.java create mode 100644 app/src/main/res/layout/activity_test.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index eef46aad..cf3aaef0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,11 +17,18 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - - - - - + + + + + \ No newline at end of file diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/TestActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/TestActivity.java new file mode 100644 index 00000000..1ac4c05c --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/TestActivity.java @@ -0,0 +1,28 @@ +package gr.thmmy.mthmmy.activities; + +import androidx.appcompat.app.AppCompatActivity; +import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.utils.parsing.BBParser; +import timber.log.Timber; + +import android.os.Bundle; +import android.text.SpannableStringBuilder; +import android.widget.TextView; + +public class TestActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_test); + + String bb = "[b]An [i]elep[u]hant[/i][/b] swi[/u]ms in [s]the[/s] tree"; + SpannableStringBuilder result = BBParser.bb2span(bb); + + TextView bbRaw = findViewById(R.id.bb_raw); + TextView bb2Text = findViewById(R.id.bb2text); + + bbRaw.setText(bb); + bb2Text.setText(result); + } +} 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 4a64499f..8b0476a0 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 @@ -19,6 +19,7 @@ import androidx.preference.PreferenceManager; import androidx.viewpager.widget.ViewPager; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; +import gr.thmmy.mthmmy.activities.TestActivity; import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.main.forum.ForumFragment; @@ -137,6 +138,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF , Toast.LENGTH_SHORT).show(); } mBackPressed = System.currentTimeMillis(); + + startActivity(new Intent(this, TestActivity.class)); } @Override diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java b/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java index 65a183fd..af8db970 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.model; +import androidx.annotation.NonNull; + public class BBTag { private int start, end; private String name; @@ -9,6 +11,12 @@ public class BBTag { this.name = name; } + @NonNull + @Override + public String toString() { + return "start:" + start + ",end:" + end + ",name:" + name; + } + public int getStart() { return start; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java index 18d70d49..89e177c5 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java @@ -5,12 +5,17 @@ import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.SpannedString; import android.text.TextUtils; +import android.text.style.StrikethroughSpan; import android.text.style.StyleSpan; +import android.text.style.UnderlineSpan; + +import org.commonmark.node.Link; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -18,20 +23,49 @@ import gr.thmmy.mthmmy.model.BBTag; import timber.log.Timber; public class BBParser { - private static final String[] supportedTags = {"b"}; + private static final String[] supportedTags = {"b", "i", "u", "s"}; - public static SpannedString bb2span(String bb) { + public static SpannableStringBuilder bb2span(String bb) { SpannableStringBuilder builder = new SpannableStringBuilder(bb); + // store the original indices of the string + LinkedList stringIndices = new LinkedList<>(); + for (int i = 0; i < builder.length(); i++) { + stringIndices.add(i); + } + BBTag[] tags = getTags(bb); for (BBTag tag : tags) { + int start = stringIndices.indexOf(tag.getStart()); + int end = stringIndices.indexOf(tag.getEnd()); + int startTagLength = tag.getName().length() + 2; + int endTagLength = tag.getName().length() + 3; switch (tag.getName()) { case "b": - builder.setSpan(new StyleSpan(Typeface.BOLD), tag.getStart(), tag.getEnd(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + builder.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + break; + case "i": + builder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + break; + case "u": + builder.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + break; + case "s": + builder.setSpan(new StrikethroughSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); break; default: throw new UnsupportedCharsetException("Tag not supported"); } + //remove starting and ending tag and and do the same changes in the list + builder.delete(start, start + startTagLength); + for (int i = start; i < start + startTagLength; i++) { + stringIndices.remove(start); + } + builder.delete(end - startTagLength, end - startTagLength + endTagLength); + for (int i = end - startTagLength; i < end - startTagLength + endTagLength; i++) { + stringIndices.remove(end - startTagLength); + } } + return builder; } public static BBTag[] getTags(String bb) { @@ -40,7 +74,7 @@ public class BBParser { LinkedList tags = new LinkedList<>(); Matcher bbMatcher = bbtagPattern.matcher(bb); while (bbMatcher.find()) { - String name = bbMatcher.group(0); + String name = bbMatcher.group(1); if (name.startsWith("/")) { //closing tag name = name.substring(1); @@ -55,6 +89,10 @@ public class BBParser { if (isSupported(name)) tags.add(new BBTag(bbMatcher.start(), name)); } + // remove parsed tags with no end tag + for (BBTag bbTag : tags) + if (bbTag.getEnd() == 0) + tags.remove(bbTag); return tags.toArray(new BBTag[0]); } diff --git a/app/src/main/res/layout/activity_test.xml b/app/src/main/res/layout/activity_test.xml new file mode 100644 index 00000000..16accea6 --- /dev/null +++ b/app/src/main/res/layout/activity_test.xml @@ -0,0 +1,20 @@ + + + + + + + + \ No newline at end of file From eb1a7f7889b8bbab9644bca00f3cf4d4e3f78b31 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 20 Oct 2018 21:02:21 +0300 Subject: [PATCH 039/104] Grgit improvements --- app/build.gradle | 26 ++-------- app/gradle/grgit.gradle | 51 +++++++++++++++++++ .../mthmmy/activities/AboutActivity.java | 4 +- 3 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 app/gradle/grgit.gradle diff --git a/app/build.gradle b/app/build.gradle index be0f9541..d13093bf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,6 @@ import groovy.json.JsonSlurper -import org.ajoberstar.grgit.Grgit + +apply from: 'gradle/grgit.gradle' apply plugin: 'com.android.application' apply plugin: 'io.fabric' @@ -17,6 +18,7 @@ android { archivesBaseName = "mTHMMY-v$versionName" buildConfigField "String", "CURRENT_BRANCH", "\"" + getCurrentBranch() + "\"" buildConfigField "String", "COMMIT_HASH", "\"" + getCommitHash() + "\"" + buildConfigField "boolean", "IS_CLEAN", String.valueOf(isClean()) } buildTypes { @@ -50,28 +52,6 @@ tasks.whenTaskAdded { task -> } } -static def getCurrentBranch() { - try { - def grgit = Grgit.open() - def curBranch = grgit.branch.getCurrent().name - grgit.close() - return curBranch - } catch (Exception ignored) { - return "" - } -} - -static def getCommitHash() { - try { - def grgit = Grgit.open() - def commitHash = grgit.head().id - grgit.close() - return commitHash - } catch (Exception ignored) { - return "" - } -} - dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0' diff --git a/app/gradle/grgit.gradle b/app/gradle/grgit.gradle new file mode 100644 index 00000000..d04a9a40 --- /dev/null +++ b/app/gradle/grgit.gradle @@ -0,0 +1,51 @@ +import org.ajoberstar.grgit.Grgit + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath 'org.ajoberstar.grgit:grgit-core:3.0.0-rc.2' + } +} + +static def getCurrentBranch() { + try { + def grgit = Grgit.open() + def currentBranch = grgit.branch.getCurrent().name + grgit.close() + return currentBranch + } catch (Exception ignored) { + return "" + } +} + +static def getCommitHash() { + try { + def grgit = Grgit.open() + def commitHash = grgit.head().id + grgit.close() + return commitHash + } catch (Exception ignored) { + return "" + } +} + +//Will return true if there are no uncommitted changes +static def isClean() { + try { + def grgit = Grgit.open() + def isClean = grgit.status().isClean() + grgit.close() + return isClean + } catch (Exception ignored) { + return true + } +} + +ext { + getCurrentBranch = this.&getCurrentBranch + getCommitHash = this.&getCommitHash + isClean = this.&isClean +} \ No newline at end of file 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 93016bc0..77a6aebd 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -50,7 +50,9 @@ public class AboutActivity extends BaseActivity { String versionInfo = ""; if(gitExists) - versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash + " "; + versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash + + (BuildConfig.IS_CLEAN ? "" : "-dirty") + + " "; // Avoid last letter being cut in italics styled TextView //Initialize appbar appBar = findViewById(R.id.appbar); From 546241e98f790fcd9b9d8b58f72acb360bd3aa84 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Mon, 22 Oct 2018 17:42:45 +0300 Subject: [PATCH 040/104] add attribute parsing --- app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java | 12 +++++++++++- .../java/gr/thmmy/mthmmy/utils/parsing/BBParser.java | 12 ++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java b/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java index af8db970..77504761 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java @@ -4,13 +4,19 @@ import androidx.annotation.NonNull; public class BBTag { private int start, end; - private String name; + private String name, attribute; public BBTag(int start, String name) { this.start = start; this.name = name; } + public BBTag(int start, String name, String attribute) { + this.start = start; + this.name = name; + this.attribute = attribute; + } + @NonNull @Override public String toString() { @@ -40,4 +46,8 @@ public class BBTag { public void setName(String name) { this.name = name; } + + public String getAttribute() { + return attribute; + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java index 89e177c5..e596d85f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java @@ -74,7 +74,15 @@ public class BBParser { LinkedList tags = new LinkedList<>(); Matcher bbMatcher = bbtagPattern.matcher(bb); while (bbMatcher.find()) { - String name = bbMatcher.group(1); + String startTag = bbMatcher.group(1); + int separatorIndex = startTag.indexOf('='); + String name, attribute = null; + if (separatorIndex > 0) { + attribute = startTag.substring(separatorIndex); + name = startTag.substring(0, separatorIndex); + } else + name = startTag; + if (name.startsWith("/")) { //closing tag name = name.substring(1); @@ -87,7 +95,7 @@ public class BBParser { continue; } if (isSupported(name)) - tags.add(new BBTag(bbMatcher.start(), name)); + tags.add(new BBTag(bbMatcher.start(), name, attribute)); } // remove parsed tags with no end tag for (BBTag bbTag : tags) From be481ed4a07f0027d653617ee0f48bc174eeed3e Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Mon, 22 Oct 2018 17:55:36 +0300 Subject: [PATCH 041/104] maybe fix parallel posting --- .../mthmmy/activities/topic/TopicActivity.java | 6 +----- .../mthmmy/activities/topic/TopicAdapter.java | 14 ++++++++++++-- app/src/main/java/gr/thmmy/mthmmy/model/Post.java | 5 +++++ 3 files changed, 18 insertions(+), 7 deletions(-) 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 88be719c..46c8678b 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 @@ -522,15 +522,11 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo String message = replyHolder.replyEditor.getText().toString(); Runnable addReply = () -> { viewModel.setWritingReply(true); - topicItems.add(Post.newQuickReply()); + topicItems.add(Post.newQuickReply(subject, message)); topicAdapter.notifyItemInserted(topicItems.size()); recyclerView.scrollToPosition(topicItems.size() - 1); replyFAB.hide(); bottomNavBar.setVisibility(View.GONE); - TopicAdapter.QuickReplyViewHolder newReplyHolder = (TopicAdapter.QuickReplyViewHolder) - recyclerView.findViewHolderForAdapterPosition(topicItems.size() - 1); - newReplyHolder.quickReplySubject.setText(subject); - newReplyHolder.replyEditor.setText(message); AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this, R.style.AppCompatAlertDialogStyleAccent); builder.setMessage("A new reply was posted before you completed your new post." + 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 53ef01cc..23073331 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 @@ -572,6 +572,7 @@ class TopicAdapter extends RecyclerView.Adapter { } } else if (currentHolder instanceof QuickReplyViewHolder) { final QuickReplyViewHolder holder = (QuickReplyViewHolder) currentHolder; + Post reply = (Post) topicItems.get(position); //noinspection ConstantConditions Picasso.with(context) @@ -585,7 +586,11 @@ class TopicAdapter extends RecyclerView.Adapter { .transform(new CircleTransform()) .into(holder.thumbnail); holder.username.setText(getSessionManager().getUsername()); - holder.quickReplySubject.setText("Re: " + viewModel.getTopicTitle().getValue()); + if (reply.getSubject() != null) { + holder.quickReplySubject.setText(reply.getSubject()); + } else { + holder.quickReplySubject.setText("Re: " + viewModel.getTopicTitle().getValue()); + } holder.quickReplySubject.setRawInputType(InputType.TYPE_CLASS_TEXT); holder.quickReplySubject.setImeOptions(EditorInfo.IME_ACTION_DONE); @@ -593,7 +598,6 @@ class TopicAdapter extends RecyclerView.Adapter { holder.replyEditor.requestEditTextFocus(); emojiKeyboard.registerEmojiInputField(holder.replyEditor); - holder.replyEditor.setText(viewModel.getBuildedQuotes()); holder.replyEditor.setOnSubmitListener(view -> { if (holder.quickReplySubject.getText().toString().isEmpty()) return; if (holder.replyEditor.getText().toString().isEmpty()) { @@ -611,6 +615,12 @@ class TopicAdapter extends RecyclerView.Adapter { }); holder.replyEditor.setOnClickListener(view -> holder.replyEditor.setError(null)); + if (reply.getContent() != null) { + holder.replyEditor.setText(reply.getContent()); + } else { + holder.replyEditor.setText(viewModel.getBuildedQuotes()); + } + if (backPressHidden) { holder.replyEditor.requestFocus(); backPressHidden = false; diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java index f3c9bd8d..da68d1e6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java @@ -185,6 +185,11 @@ public class Post extends TopicItem { 0, null, null, null, null, null, false, TYPE_QUICK_REPLY); } + public static Post newQuickReply(String subject, String content) { + return new Post(null, null, subject, content, 0, 0, null, + 0, null, null, null, null, null, false, TYPE_QUICK_REPLY); + } + //Getters /** From afd1c6fc796e9ab853a24b2adc26832b6bf11136 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 22 Oct 2018 19:57:09 +0300 Subject: [PATCH 042/104] Deobfuscate Cloudflare-obfuscated emails --- app/build.gradle | 2 +- .../gr/thmmy/mthmmy/base/BaseApplication.java | 11 ++++- .../thmmy/mthmmy/utils/EmailDeobfuscator.java | 44 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java diff --git a/app/build.gradle b/app/build.gradle index d13093bf..cfb58070 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -64,7 +64,7 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.firebase:firebase-core:16.0.4' - implementation 'com.google.firebase:firebase-messaging:17.3.3' + implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' implementation 'com.squareup.okhttp3:okhttp:3.11.0' implementation 'com.squareup.picasso:picasso:2.5.2' 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 d181301d..e218c9f4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -38,8 +38,11 @@ import io.fabric.sdk.android.Fabric; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; +import okhttp3.Response; import timber.log.Timber; +import static gr.thmmy.mthmmy.utils.EmailDeobfuscator.deobfuscate; + public class BaseApplication extends Application { private static BaseApplication baseApplication; //BaseApplication singleton @@ -100,8 +103,14 @@ public class BaseApplication extends Application { request = request.newBuilder().url(newUrl).build(); } } - return chain.proceed(request); + Response response = chain.proceed(request); + try { + response = deobfuscate(response); + } catch (Exception e) { + Timber.e(e, "Email deobfuscation error."); + } + return response; }) .connectTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java b/app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java new file mode 100644 index 00000000..56ee76ad --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java @@ -0,0 +1,44 @@ +package gr.thmmy.mthmmy.utils; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.nodes.TextNode; +import org.jsoup.select.Elements; + +import java.io.IOException; + +import okhttp3.MediaType; +import okhttp3.Response; +import okhttp3.ResponseBody; + +//Deobfuscates Cloudflare-obfuscated emails +public class EmailDeobfuscator { + public static Response deobfuscate(Response response) throws IOException { + String responseBody = response.body().string(); + Document document = Jsoup.parse(responseBody); + Elements obfuscatedEmails = document.select("span.__cf_email__"); + for (Element obfuscatedEmail : obfuscatedEmails) { + String email = deobfuscateEmail(obfuscatedEmail.attr("data-cfemail")); + Element parent = obfuscatedEmail.parent(); + if (parent.is("a")&&parent.attr("href").contains("email-protection")) + parent.attr("href", "mailto:"+email); + obfuscatedEmail.replaceWith(new TextNode(email, "")); + } + + MediaType contentType = response.body().contentType(); + ResponseBody body = ResponseBody.create(contentType, document.toString()); + return response.newBuilder().body(body).build(); + } + + + private static String deobfuscateEmail(final String encodedString) { + final StringBuilder email = new StringBuilder(); + final int r = Integer.parseInt(encodedString.substring(0, 2), 16); + for (int n = 2; n < encodedString.length(); n += 2) { + final int i = Integer.parseInt(encodedString.substring(n, n+2), 16) ^ r; + email.append(Character.toString ((char) i)); + } + return email.toString(); + } +} From b4f830a5a5c22638658d2dbd50a7c8898bcc2862 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 22 Oct 2018 20:32:59 +0300 Subject: [PATCH 043/104] Moved email deobfuscation in ParseHelpers --- .../create_content/NewTopicTask.java | 4 +- .../activities/profile/ProfileActivity.java | 3 +- .../latestPosts/LatestPostsFragment.java | 3 +- .../profile/stats/StatsFragment.java | 4 +- .../profile/summary/SummaryFragment.java | 3 +- .../mthmmy/activities/topic/Posting.java | 4 +- .../topic/tasks/PrepareForEditTask.java | 4 +- .../topic/tasks/PrepareForReply.java | 4 +- .../activities/topic/tasks/TopicTask.java | 3 +- .../gr/thmmy/mthmmy/base/BaseApplication.java | 12 +---- .../thmmy/mthmmy/session/SessionManager.java | 6 +-- .../thmmy/mthmmy/utils/EmailDeobfuscator.java | 44 ------------------- .../gr/thmmy/mthmmy/utils/NetworkTask.java | 4 +- .../mthmmy/utils/parsing/ParseHelpers.java | 36 ++++++++++++++- .../thmmy/mthmmy/utils/parsing/ParseTask.java | 3 +- 15 files changed, 57 insertions(+), 80 deletions(-) delete mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java 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 985e0930..2cb321c1 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 @@ -2,12 +2,12 @@ package gr.thmmy.mthmmy.activities.create_content; import android.os.AsyncTask; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; import gr.thmmy.mthmmy.base.BaseApplication; +import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -44,7 +44,7 @@ public class NewTopicTask extends AsyncTask { String seqnum, sc, topic, createTopicUrl; try { Response response = client.newCall(request).execute(); - document = Jsoup.parse(response.body().string()); + document = ParseHelpers.parse(response.body().string()); seqnum = document.select("input[name=seqnum]").first().attr("value"); sc = document.select("input[name=sc]").first().attr("value"); 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 99015a2b..70f95ac4 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 @@ -49,6 +49,7 @@ import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.utils.CenterVerticalSpan; import gr.thmmy.mthmmy.utils.CircleTransform; +import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import okhttp3.Request; import okhttp3.Response; @@ -241,7 +242,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment .build(); try { Response response = client.newCall(request).execute(); - profilePage = Jsoup.parse(response.body().string()); + profilePage = ParseHelpers.parse(response.body().string()); Elements contentsTable = profilePage. select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tbody"); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index 9736d3fd..a0d0c05a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -8,7 +8,6 @@ import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.Toast; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; @@ -164,7 +163,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap .build(); try { Response response = BaseActivity.getClient().newCall(request).execute(); - return parseLatestPosts(Jsoup.parse(response.body().string())); + return parseLatestPosts(ParseHelpers.parse(response.body().string())); } catch (SSLHandshakeException e) { Timber.w("Certificate problem (please switch to unsafe connection)."); } catch (Exception e) { 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 eca17c0e..4b3d661f 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 @@ -26,7 +26,6 @@ import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.formatter.PercentFormatter; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; @@ -40,6 +39,7 @@ import javax.net.ssl.SSLHandshakeException; import androidx.fragment.app.Fragment; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import okhttp3.Request; import okhttp3.Response; @@ -138,7 +138,7 @@ public class StatsFragment extends Fragment { .build(); try { Response response = BaseActivity.getClient().newCall(request).execute(); - return parseStats(Jsoup.parse(response.body().string())); + return parseStats(ParseHelpers.parse(response.body().string())); } catch (SSLHandshakeException e) { Timber.w("Certificate problem (please switch to unsafe connection)."); } catch (Exception e) { 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 867707ee..cec78eda 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 @@ -13,7 +13,6 @@ import android.webkit.WebView; import android.widget.LinearLayout; import android.widget.TextView; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; @@ -69,7 +68,7 @@ public class SummaryFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - profileSummaryDocument = Jsoup.parse(getArguments().getString(PROFILE_DOCUMENT)); + profileSummaryDocument = ParseHelpers.parse(getArguments().getString(PROFILE_DOCUMENT)); parsedProfileSummaryData = new ArrayList<>(); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java index 88c2f8a3..1a184d15 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java @@ -1,10 +1,10 @@ package gr.thmmy.mthmmy.activities.topic; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; +import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.Response; import timber.log.Timber; @@ -59,7 +59,7 @@ public class Posting { if (response.code() < 200 || response.code() >= 400) return REPLY_STATUS.OTHER_ERROR; String finalUrl = response.request().url().toString(); if (finalUrl.contains("action=post")) { - Document postErrorPage = Jsoup.parse(response.body().string()); + Document postErrorPage = ParseHelpers.parse(response.body().string()); String[] errors = postErrorPage.select("tr[id=errors] div[id=error_list]").first() .toString().split("
    "); for (int i = 0; i < errors.length; ++i) { //TODO test diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java index 5864e635..6efc2c03 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java @@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.topic.tasks; import android.os.AsyncTask; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Selector; @@ -10,6 +9,7 @@ import org.jsoup.select.Selector; import java.io.IOException; import gr.thmmy.mthmmy.base.BaseApplication; +import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -45,7 +45,7 @@ public class PrepareForEditTask extends AsyncTask { .build(); try { Response response = BaseApplication.getInstance().getClient().newCall(request).execute(); - topic = Jsoup.parse(response.body().string()); + topic = ParseHelpers.parse(response.body().string()); ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic); 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 e218c9f4..0c0eda0e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -38,11 +38,8 @@ import io.fabric.sdk.android.Fabric; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.Response; import timber.log.Timber; -import static gr.thmmy.mthmmy.utils.EmailDeobfuscator.deobfuscate; - public class BaseApplication extends Application { private static BaseApplication baseApplication; //BaseApplication singleton @@ -103,14 +100,7 @@ public class BaseApplication extends Application { request = request.newBuilder().url(newUrl).build(); } } - - Response response = chain.proceed(request); - try { - response = deobfuscate(response); - } catch (Exception e) { - Timber.e(e, "Email deobfuscation error."); - } - return response; + return chain.proceed(request); }) .connectTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) 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 97e1dddb..4121c1de 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -5,7 +5,6 @@ import android.content.SharedPreferences; import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; @@ -18,6 +17,7 @@ import java.util.regex.Pattern; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import gr.thmmy.mthmmy.utils.parsing.ParseException; +import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.Cookie; import okhttp3.FormBody; import okhttp3.HttpUrl; @@ -109,7 +109,7 @@ public class SessionManager { try { //Make request & handle response Response response = client.newCall(request).execute(); - Document document = Jsoup.parse(response.body().string()); + Document document = ParseHelpers.parse(response.body().string()); if (validateRetrievedCookies()) { @@ -215,7 +215,7 @@ public class SessionManager { try { //Make request & handle response Response response = client.newCall(request).execute(); - Document document = Jsoup.parse(response.body().string()); + Document document = ParseHelpers.parse(response.body().string()); Elements loginButton = document.select("[value=Login]"); //Attempt to find login button if (!loginButton.isEmpty()) //If login button exists, logout was successful diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java b/app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java deleted file mode 100644 index 56ee76ad..00000000 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java +++ /dev/null @@ -1,44 +0,0 @@ -package gr.thmmy.mthmmy.utils; - -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.jsoup.nodes.TextNode; -import org.jsoup.select.Elements; - -import java.io.IOException; - -import okhttp3.MediaType; -import okhttp3.Response; -import okhttp3.ResponseBody; - -//Deobfuscates Cloudflare-obfuscated emails -public class EmailDeobfuscator { - public static Response deobfuscate(Response response) throws IOException { - String responseBody = response.body().string(); - Document document = Jsoup.parse(responseBody); - Elements obfuscatedEmails = document.select("span.__cf_email__"); - for (Element obfuscatedEmail : obfuscatedEmails) { - String email = deobfuscateEmail(obfuscatedEmail.attr("data-cfemail")); - Element parent = obfuscatedEmail.parent(); - if (parent.is("a")&&parent.attr("href").contains("email-protection")) - parent.attr("href", "mailto:"+email); - obfuscatedEmail.replaceWith(new TextNode(email, "")); - } - - MediaType contentType = response.body().contentType(); - ResponseBody body = ResponseBody.create(contentType, document.toString()); - return response.newBuilder().body(body).build(); - } - - - private static String deobfuscateEmail(final String encodedString) { - final StringBuilder email = new StringBuilder(); - final int r = Integer.parseInt(encodedString.substring(0, 2), 16); - for (int n = 2; n < encodedString.length(); n += 2) { - final int i = Integer.parseInt(encodedString.substring(n, n+2), 16) ^ r; - email.append(Character.toString ((char) i)); - } - return email.toString(); - } -} diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java index cb613f26..c61dbb72 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java @@ -1,12 +1,12 @@ package gr.thmmy.mthmmy.utils; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.utils.parsing.ParseException; +import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -49,7 +49,7 @@ public abstract class NetworkTask extends ExternalAsyncTask return new Parcel<>(NetworkResultCodes.NETWORK_ERROR, null); } try { - T data = performTask(Jsoup.parse(responseBodyString), response); + T data = performTask(ParseHelpers.parse(responseBodyString), response); int resultCode = getResultCode(response, data); return new Parcel<>(resultCode, data); } catch (ParseException pe) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index 2208ff04..2aecee04 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -1,7 +1,9 @@ package gr.thmmy.mthmmy.utils.parsing; +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import org.jsoup.nodes.TextNode; import org.jsoup.select.Elements; import java.util.ArrayList; @@ -10,7 +12,8 @@ import java.util.regex.Pattern; /** * This class consists exclusively of static classes (enums) and methods (excluding methods of inner - * classes). It can be used to resolve a page's language and state or fix embedded videos html code. + * classes). It can be used to resolve a page's language and state or fix embedded videos html code + * and obfuscated emails. */ public class ParseHelpers { /** @@ -185,4 +188,35 @@ public class ParseHelpers { return forumUrl + topicURL.substring(baseUrlMatcher.start(), baseUrlMatcher.end()); else return ""; } + + /** + * Method that adds email deobfuscation functionality to Jsoup.parse. + * Replace Jsoup.parse with this wherever needed + * + * @param html html to parse + * @return a document with deobfuscated emails + */ + public static Document parse(String html){ + Document document = Jsoup.parse(html); + Elements obfuscatedEmails = document.select("span.__cf_email__"); + for (Element obfuscatedEmail : obfuscatedEmails) { + String obfuscatedEmailStr = obfuscatedEmail.attr("data-cfemail"); + + //Deobfuscate + final StringBuilder stringBuilder = new StringBuilder(); + final int r = Integer.parseInt(obfuscatedEmailStr.substring(0, 2), 16); + for (int n = 2; n < obfuscatedEmailStr.length(); n += 2) { + final int i = Integer.parseInt(obfuscatedEmailStr.substring(n, n + 2), 16) ^ r; + stringBuilder.append(Character.toString((char) i)); + } + + String deobfuscatedEmail = stringBuilder.toString(); + + Element parent = obfuscatedEmail.parent(); + if (parent.is("a")&&parent.attr("href").contains("email-protection")) + parent.attr("href", "mailto:"+deobfuscatedEmail); + obfuscatedEmail.replaceWith(new TextNode(deobfuscatedEmail, "")); + } + return document; + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java index 4f335025..6936100f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java @@ -3,7 +3,6 @@ package gr.thmmy.mthmmy.utils.parsing; import android.os.AsyncTask; import android.widget.Toast; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; @@ -42,7 +41,7 @@ public abstract class ParseTask extends AsyncTask Date: Tue, 23 Oct 2018 23:19:00 +0300 Subject: [PATCH 044/104] fix parallel posting, add/fix behavior when profile task fails --- .../activities/profile/ProfileActivity.java | 202 +++++++++--------- .../activities/topic/TopicActivity.java | 2 +- .../mthmmy/activities/topic/TopicAdapter.java | 2 + 3 files changed, 106 insertions(+), 100 deletions(-) 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 70f95ac4..a9b11c7f 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 @@ -31,8 +31,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import javax.net.ssl.SSLHandshakeException; - import androidx.appcompat.app.AppCompatDelegate; import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.Fragment; @@ -49,9 +47,11 @@ import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.utils.CenterVerticalSpan; import gr.thmmy.mthmmy.utils.CircleTransform; -import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; +import gr.thmmy.mthmmy.utils.NetworkResultCodes; +import gr.thmmy.mthmmy.utils.Parcel; +import gr.thmmy.mthmmy.utils.parsing.NewParseTask; +import gr.thmmy.mthmmy.utils.parsing.ParseException; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; -import okhttp3.Request; import okhttp3.Response; import timber.log.Timber; @@ -195,7 +195,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment } profileTask = new ProfileTask(); - profileTask.execute(profileUrl); //Attempts data parsing + profileTask.execute(profileUrl + ";wap"); //Attempts data parsing } @Override @@ -214,6 +214,11 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment startActivity(i); } + public void onProfileTaskStarted() { + progressBar.setVisibility(ProgressBar.VISIBLE); + if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(false); + } + /** * An {@link AsyncTask} that handles asynchronous fetching of a profile page and parsing this * user's personal text. The {@link Document} resulting from the parse is stored for use in @@ -223,120 +228,119 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment * * @see Jsoup */ - public class ProfileTask extends AsyncTask { + public class ProfileTask extends NewParseTask { //Class variables Document profilePage; Spannable usernameSpan; Boolean isOnline = false; - protected void onPreExecute() { - progressBar.setVisibility(ProgressBar.VISIBLE); - if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(false); + public ProfileTask() { + super(ProfileActivity.this::onProfileTaskStarted, null); } - protected Boolean doInBackground(String... profileUrl) { - String pageUrl = profileUrl[0] + ";wap"; //Profile's page wap url - - Request request = new Request.Builder() - .url(pageUrl) - .build(); - try { - Response response = client.newCall(request).execute(); - profilePage = ParseHelpers.parse(response.body().string()); - Elements contentsTable = profilePage. - select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tbody"); - - //Finds username if missing - if (username == null || Objects.equals(username, "")) { - username = contentsTable.select("tr").first().select("td").last().text(); - } - if (thumbnailUrl == null || Objects.equals(thumbnailUrl, "")) { //Maybe there is an avatar - Element profileAvatar = profilePage.select("img.avatar").first(); - if (profileAvatar != null) thumbnailUrl = profileAvatar.attr("abs:src"); - } - { //Finds personal text - Element tmpEl = profilePage.select("td.windowbg:nth-child(2)").first(); - if (tmpEl != null) { - personalText = tmpEl.text().trim(); - } else { - //Should never get here! - //Something is wrong. - Timber.e("An error occurred while trying to find profile's personal text."); - personalText = null; - } + @Override + protected Void parse(Document document, Response response) throws ParseException { + profilePage = document; + Elements contentsTable = profilePage. + select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tbody"); + + //Finds username if missing + if (username == null || Objects.equals(username, "")) { + username = contentsTable.select("tr").first().select("td").last().text(); + } + if (thumbnailUrl == null || Objects.equals(thumbnailUrl, "")) { //Maybe there is an avatar + Element profileAvatar = profilePage.select("img.avatar").first(); + if (profileAvatar != null) thumbnailUrl = profileAvatar.attr("abs:src"); + } + { //Finds personal text + Element tmpEl = profilePage.select("td.windowbg:nth-child(2)").first(); + if (tmpEl != null) { + personalText = tmpEl.text().trim(); + } else { + //Should never get here! + //Something is wrong. + Timber.e("An error occurred while trying to find profile's personal text."); + personalText = null; } - { //Finds status - usernameSpan = new SpannableString(getResources() - .getString(R.string.fa_circle) + " " + username); - usernameSpan.setSpan(new CenterVerticalSpan(), 0, 2, - Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - usernameSpan.setSpan(new RelativeSizeSpan(0.45f) - , 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - - if (contentsTable.toString().contains("Online") - || contentsTable.toString().contains("Συνδεδεμένος")) { - isOnline = true; - } else { - isOnline = false; + } + { //Finds status + usernameSpan = new SpannableString(getResources() + .getString(R.string.fa_circle) + " " + username); + usernameSpan.setSpan(new CenterVerticalSpan(), 0, 2, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + usernameSpan.setSpan(new RelativeSizeSpan(0.45f) + , 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + + if (contentsTable.toString().contains("Online") + || contentsTable.toString().contains("Συνδεδεμένος")) { + isOnline = true; + } else { + isOnline = false; /*usernameSpan.setSpan(new ForegroundColorSpan(Color.GRAY) , 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);*/ - } - usernameSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#26A69A")) - , 2, usernameSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } - return true; - } catch (SSLHandshakeException e) { - Timber.w("Certificate problem (please switch to unsafe connection)."); - } catch (Exception e) { - Timber.e(e, "Exception"); + usernameSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#26A69A")) + , 2, usernameSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } - return false; + return null; } - //TODO: better parse error handling (ParseException etc.) - protected void onPostExecute(Boolean result) { - if (!result) { //Parse failed! //TODO report as ParseException? + @Override + protected void onPostExecute(Parcel parcel) { + int result = parcel.getResultCode(); + if (result == NetworkResultCodes.SUCCESSFUL) { + //Parse was successful + if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(true); + progressBar.setVisibility(ProgressBar.INVISIBLE); + + if (usernameSpan != null) { + if (isOnline) { + usernameView.setTextColor(Color.parseColor("#4CAF50")); + } else { + usernameView.setTextColor(Color.GRAY); + } + usernameView.setText(usernameSpan); + } else if (usernameView.getText() != username) usernameView.setText(username); + if (thumbnailUrl != null && !Objects.equals(thumbnailUrl, "")) + //noinspection ConstantConditions + Picasso.with(getApplicationContext()) + .load(thumbnailUrl) + .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) + .centerCrop() + .error(ResourcesCompat.getDrawable(getResources() + , R.drawable.ic_default_user_thumbnail_white_24dp, null)) + .placeholder(ResourcesCompat.getDrawable(getResources() + , R.drawable.ic_default_user_thumbnail_white_24dp, null)) + .transform(new CircleTransform()) + .into(thumbnailView); + if (personalText != null) { + personalTextView.setText(personalText); + personalTextView.setVisibility(View.VISIBLE); + } + + setupViewPager(viewPager, profilePage); + TabLayout tabLayout = findViewById(R.id.profile_tabs); + tabLayout.setupWithViewPager(viewPager); + if (tabSelect != 0) { + TabLayout.Tab tab = tabLayout.getTabAt(tabSelect); + if (tab != null) tab.select(); + } + } else if (result == NetworkResultCodes.NETWORK_ERROR) { + Timber.w("Network error while excecuting profile activity"); + Toast.makeText(getBaseContext(), "Network error" + , Toast.LENGTH_LONG).show(); + finish(); + } else { Timber.d("Parse failed!"); Toast.makeText(getBaseContext(), "Fatal error!\n Aborting..." , Toast.LENGTH_LONG).show(); finish(); } - //Parse was successful - if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(true); - progressBar.setVisibility(ProgressBar.INVISIBLE); - - if (usernameSpan != null) { - if (isOnline) { - usernameView.setTextColor(Color.parseColor("#4CAF50")); - } else { - usernameView.setTextColor(Color.GRAY); - } - usernameView.setText(usernameSpan); - } else if (usernameView.getText() != username) usernameView.setText(username); - if (thumbnailUrl != null && !Objects.equals(thumbnailUrl, "")) - //noinspection ConstantConditions - Picasso.with(getApplicationContext()) - .load(thumbnailUrl) - .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) - .centerCrop() - .error(ResourcesCompat.getDrawable(getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) - .placeholder(ResourcesCompat.getDrawable(getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) - .transform(new CircleTransform()) - .into(thumbnailView); - if (personalText != null) { - personalTextView.setText(personalText); - personalTextView.setVisibility(View.VISIBLE); - } + } - setupViewPager(viewPager, profilePage); - TabLayout tabLayout = findViewById(R.id.profile_tabs); - tabLayout.setupWithViewPager(viewPager); - if (tabSelect != 0) { - TabLayout.Tab tab = tabLayout.getTabAt(tabSelect); - if (tab != null) tab.select(); - } + @Override + protected int getResultCode(Response response, Void data) { + return NetworkResultCodes.SUCCESSFUL; } } 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 46c8678b..6f1935b9 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 @@ -528,7 +528,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo replyFAB.hide(); bottomNavBar.setVisibility(View.GONE); AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this, - R.style.AppCompatAlertDialogStyleAccent); + R.style.AppTheme_Dark_Dialog); builder.setMessage("A new reply was posted before you completed your new post." + " Please review it and send your reply again") .setNeutralButton(getString(R.string.ok), (dialog, which) -> dialog.dismiss()) 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 23073331..5a1fdc5a 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 @@ -586,6 +586,8 @@ class TopicAdapter extends RecyclerView.Adapter { .transform(new CircleTransform()) .into(holder.thumbnail); holder.username.setText(getSessionManager().getUsername()); + holder.itemView.setAlpha(1f); + holder.itemView.setEnabled(true); if (reply.getSubject() != null) { holder.quickReplySubject.setText(reply.getSubject()); } else { From eeb5757a887a8101b54b8ed1c065d1938ff7367d Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 24 Oct 2018 13:22:56 +0300 Subject: [PATCH 045/104] Email deobfuscation optimizations --- .../create_content/NewTopicTask.java | 4 +- .../latestPosts/LatestPostsFragment.java | 6 ++- .../profile/stats/StatsFragment.java | 7 ++- .../profile/summary/SummaryFragment.java | 6 ++- .../mthmmy/activities/topic/Posting.java | 4 +- .../mthmmy/utils/parsing/ParseHelpers.java | 50 +++++++++++++------ 6 files changed, 53 insertions(+), 24 deletions(-) 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 2cb321c1..985e0930 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 @@ -2,12 +2,12 @@ package gr.thmmy.mthmmy.activities.create_content; import android.os.AsyncTask; +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; import gr.thmmy.mthmmy.base.BaseApplication; -import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -44,7 +44,7 @@ public class NewTopicTask extends AsyncTask { String seqnum, sc, topic, createTopicUrl; try { Response response = client.newCall(request).execute(); - document = ParseHelpers.parse(response.body().string()); + document = Jsoup.parse(response.body().string()); seqnum = document.select("input[name=seqnum]").first().attr("value"); sc = document.select("input[name=sc]").first().attr("value"); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index a0d0c05a..b2fb112c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -8,6 +8,7 @@ import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.Toast; +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; @@ -29,6 +30,8 @@ import okhttp3.Request; import okhttp3.Response; import timber.log.Timber; +import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.deobfuscateElements; + /** * Use the {@link LatestPostsFragment#newInstance} factory method to create an instance of this fragment. */ @@ -163,7 +166,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap .build(); try { Response response = BaseActivity.getClient().newCall(request).execute(); - return parseLatestPosts(ParseHelpers.parse(response.body().string())); + return parseLatestPosts(Jsoup.parse(response.body().string())); } catch (SSLHandshakeException e) { Timber.w("Certificate problem (please switch to unsafe connection)."); } catch (Exception e) { @@ -206,6 +209,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap return true; } + deobfuscateElements(latestPostsRows, false); for (Element row : latestPostsRows) { String pTopicUrl, pTopicTitle, pDateTime, pPost; if (Integer.parseInt(row.attr("cellpadding")) == 4) { 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 4b3d661f..70e82fba 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 @@ -26,6 +26,7 @@ import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.formatter.PercentFormatter; +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; @@ -39,12 +40,13 @@ import javax.net.ssl.SSLHandshakeException; import androidx.fragment.app.Fragment; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; -import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import okhttp3.Request; import okhttp3.Response; import timber.log.Timber; +import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.deobfuscateElements; + public class StatsFragment extends Fragment { /** * The key to use when putting profile's url String to {@link StatsFragment}'s Bundle. @@ -138,7 +140,7 @@ public class StatsFragment extends Fragment { .build(); try { Response response = BaseActivity.getClient().newCall(request).execute(); - return parseStats(ParseHelpers.parse(response.body().string())); + return parseStats(Jsoup.parse(response.body().string())); } catch (SSLHandshakeException e) { Timber.w("Certificate problem (please switch to unsafe connection)."); } catch (Exception e) { @@ -173,6 +175,7 @@ public class StatsFragment extends Fragment { return false; { Elements titleRows = statsPage.select("table.bordercolor[align]>tbody>tr.titlebg"); + deobfuscateElements(titleRows, false); generalStatisticsTitle = titleRows.first().text(); if (userHasPosts) { postingActivityByTimeTitle = titleRows.get(1).text(); 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 cec78eda..264f7842 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 @@ -13,6 +13,7 @@ import android.webkit.WebView; import android.widget.LinearLayout; import android.widget.TextView; +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; @@ -25,6 +26,8 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import timber.log.Timber; +import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.deobfuscateElements; + /** * Use the {@link SummaryFragment#newInstance} factory method to create an instance of this fragment. @@ -68,7 +71,7 @@ public class SummaryFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - profileSummaryDocument = ParseHelpers.parse(getArguments().getString(PROFILE_DOCUMENT)); + profileSummaryDocument = Jsoup.parse(getArguments().getString(PROFILE_DOCUMENT)); parsedProfileSummaryData = new ArrayList<>(); } @@ -131,6 +134,7 @@ public class SummaryFragment extends Fragment { //Contains all summary's rows Elements summaryRows = profile.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tr"); + deobfuscateElements(summaryRows, false); for (Element summaryRow : summaryRows) { String rowText = summaryRow.text(), pHtml = ""; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java index 1a184d15..88c2f8a3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java @@ -1,10 +1,10 @@ package gr.thmmy.mthmmy.activities.topic; +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; -import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.Response; import timber.log.Timber; @@ -59,7 +59,7 @@ public class Posting { if (response.code() < 200 || response.code() >= 400) return REPLY_STATUS.OTHER_ERROR; String finalUrl = response.request().url().toString(); if (finalUrl.contains("action=post")) { - Document postErrorPage = ParseHelpers.parse(response.body().string()); + Document postErrorPage = Jsoup.parse(response.body().string()); String[] errors = postErrorPage.select("tr[id=errors] div[id=error_list]").first() .toString().split("
    "); for (int i = 0; i < errors.length; ++i) { //TODO test diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index 2aecee04..022d9896 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -10,6 +10,8 @@ import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; +import timber.log.Timber; + /** * This class consists exclusively of static classes (enums) and methods (excluding methods of inner * classes). It can be used to resolve a page's language and state or fix embedded videos html code @@ -190,7 +192,7 @@ public class ParseHelpers { } /** - * Method that adds email deobfuscation functionality to Jsoup.parse. + * Method that replaces CloudFlare-obfuscated emails with deobfuscated ones * Replace Jsoup.parse with this wherever needed * * @param html html to parse @@ -198,25 +200,41 @@ public class ParseHelpers { */ public static Document parse(String html){ Document document = Jsoup.parse(html); - Elements obfuscatedEmails = document.select("span.__cf_email__"); - for (Element obfuscatedEmail : obfuscatedEmails) { - String obfuscatedEmailStr = obfuscatedEmail.attr("data-cfemail"); - - //Deobfuscate - final StringBuilder stringBuilder = new StringBuilder(); - final int r = Integer.parseInt(obfuscatedEmailStr.substring(0, 2), 16); - for (int n = 2; n < obfuscatedEmailStr.length(); n += 2) { - final int i = Integer.parseInt(obfuscatedEmailStr.substring(n, n + 2), 16) ^ r; - stringBuilder.append(Character.toString((char) i)); - } + deobfuscateElements(document.select("span.__cf_email__"), true); + return document; + } - String deobfuscatedEmail = stringBuilder.toString(); + /** + * Use this method instead of parse() if you are targetting specific elements + */ + public static void deobfuscateElements(Elements elements, boolean found){ + if(!found) + elements = elements.select("span.__cf_email__"); - Element parent = obfuscatedEmail.parent(); + for (Element obfuscatedElement : elements) { + String deobfuscatedEmail = deobfuscateEmail(obfuscatedElement.attr("data-cfemail")); + Element parent = obfuscatedElement.parent(); if (parent.is("a")&&parent.attr("href").contains("email-protection")) parent.attr("href", "mailto:"+deobfuscatedEmail); - obfuscatedEmail.replaceWith(new TextNode(deobfuscatedEmail, "")); + obfuscatedElement.replaceWith(new TextNode(deobfuscatedEmail, "")); } - return document; + } + + + /** + * @param obfuscatedEmail CloudFlare-obfuscated email + * @return deobfuscated email + */ + private static String deobfuscateEmail(String obfuscatedEmail){ + //Deobfuscate + final StringBuilder stringBuilder = new StringBuilder(); + final int r = Integer.parseInt(obfuscatedEmail.substring(0, 2), 16); + for (int n = 2; n < obfuscatedEmail.length(); n += 2) { + final int i = Integer.parseInt(obfuscatedEmail.substring(n, n + 2), 16) ^ r; + stringBuilder.append(Character.toString((char) i)); + } + + Timber.i("Email deobfuscated."); + return stringBuilder.toString(); } } From 8605b9b4c18b2519d904d07b60865ad6dd37019a Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 24 Oct 2018 14:44:55 +0300 Subject: [PATCH 046/104] Hopefully prevent multiple TopicActivities from spawning simultaneously (RecentFragment, UnreadFragment) --- .../mthmmy/activities/board/BoardAdapter.java | 123 ++++++++---------- .../mthmmy/activities/main/MainActivity.java | 2 + .../gr/thmmy/mthmmy/base/BaseActivity.java | 4 +- build.gradle | 4 +- 4 files changed, 58 insertions(+), 75 deletions(-) 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 7467c408..97857440 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 @@ -22,7 +22,6 @@ import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.Topic; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; -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.topic.TopicActivity.BUNDLE_TOPIC_TITLE; @@ -133,17 +132,14 @@ class BoardAdapter extends RecyclerView.Adapter { boardExpandableVisibility.add(false); } - subBoardViewHolder.boardRow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(context, BoardActivity.class); - Bundle extras = new Bundle(); - extras.putString(BUNDLE_BOARD_URL, subBoard.getUrl()); - extras.putString(BUNDLE_BOARD_TITLE, subBoard.getTitle()); - intent.putExtras(extras); - intent.setFlags(FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); - } + subBoardViewHolder.boardRow.setOnClickListener(view -> { + Intent intent = new Intent(context, BoardActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_BOARD_URL, subBoard.getUrl()); + extras.putString(BUNDLE_BOARD_TITLE, subBoard.getTitle()); + intent.putExtras(extras); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); }); if (boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1)) { subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE); @@ -152,36 +148,30 @@ class BoardAdapter extends RecyclerView.Adapter { subBoardViewHolder.boardExpandable.setVisibility(View.GONE); subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); } - subBoardViewHolder.showHideExpandable.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1); - if (visible) { - subBoardViewHolder.boardExpandable.setVisibility(View.GONE); - subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); - } else { - subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE); - subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); - } - boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible); + subBoardViewHolder.showHideExpandable.setOnClickListener(view -> { + final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1); + if (visible) { + subBoardViewHolder.boardExpandable.setVisibility(View.GONE); + subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); + } else { + subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE); + subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); } + boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible); }); subBoardViewHolder.boardTitle.setText(subBoard.getTitle()); subBoardViewHolder.boardMods.setText(subBoard.getMods()); subBoardViewHolder.boardStats.setText(subBoard.getStats()); subBoardViewHolder.boardLastPost.setText(subBoard.getLastPost()); if (!Objects.equals(subBoard.getLastPostUrl(), "")) { - subBoardViewHolder.boardLastPost.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(context, TopicActivity.class); - Bundle extras = new Bundle(); - extras.putString(BUNDLE_TOPIC_URL, subBoard.getLastPostUrl()); - //Doesn't put an already ellipsized topic title in Bundle - intent.putExtras(extras); - intent.setFlags(FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); - } + subBoardViewHolder.boardLastPost.setOnClickListener(view -> { + Intent intent = new Intent(context, TopicActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_TOPIC_URL, subBoard.getLastPostUrl()); + //Doesn't put an already ellipsized topic title in Bundle + intent.putExtras(extras); + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + context.startActivity(intent); }); } } else if (holder instanceof TopicViewHolder) { @@ -193,17 +183,14 @@ class BoardAdapter extends RecyclerView.Adapter { topicExpandableVisibility.add(false); } - topicViewHolder.topicRow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(context, TopicActivity.class); - Bundle extras = new Bundle(); - extras.putString(BUNDLE_TOPIC_URL, topic.getUrl()); - extras.putString(BUNDLE_TOPIC_TITLE, topic.getSubject()); - intent.putExtras(extras); - intent.setFlags(FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); - } + topicViewHolder.topicRow.setOnClickListener(view -> { + Intent intent = new Intent(context, TopicActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_TOPIC_URL, topic.getUrl()); + extras.putString(BUNDLE_TOPIC_TITLE, topic.getSubject()); + intent.putExtras(extras); + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + context.startActivity(intent); }); if (topicExpandableVisibility.get(topicViewHolder.getAdapterPosition() - parsedSubBoards .size() - 2)) { @@ -213,21 +200,18 @@ class BoardAdapter extends RecyclerView.Adapter { topicViewHolder.topicExpandable.setVisibility(View.GONE); topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); } - topicViewHolder.showHideExpandable.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - final boolean visible = topicExpandableVisibility.get(topicViewHolder. - getAdapterPosition() - parsedSubBoards.size() - 2); - if (visible) { - topicViewHolder.topicExpandable.setVisibility(View.GONE); - topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); - } else { - topicViewHolder.topicExpandable.setVisibility(View.VISIBLE); - topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); - } - topicExpandableVisibility.set(topicViewHolder.getAdapterPosition() - - parsedSubBoards.size() - 2, !visible); + topicViewHolder.showHideExpandable.setOnClickListener(view -> { + final boolean visible = topicExpandableVisibility.get(topicViewHolder. + getAdapterPosition() - parsedSubBoards.size() - 2); + if (visible) { + topicViewHolder.topicExpandable.setVisibility(View.GONE); + topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); + } else { + topicViewHolder.topicExpandable.setVisibility(View.VISIBLE); + topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); } + topicExpandableVisibility.set(topicViewHolder.getAdapterPosition() - + parsedSubBoards.size() - 2, !visible); }); topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets() , "fonts/fontawesome-webfont.ttf")); @@ -248,17 +232,14 @@ class BoardAdapter extends RecyclerView.Adapter { topicViewHolder.topicStartedBy.setText(context.getString(R.string.topic_started_by, topic.getStarter())); topicViewHolder.topicStats.setText(topic.getStats()); topicViewHolder.topicLastPost.setText(context.getString(R.string.topic_last_post, topic.getLastPostDateAndTime())); - topicViewHolder.topicLastPost.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(context, TopicActivity.class); - Bundle extras = new Bundle(); - extras.putString(BUNDLE_TOPIC_URL, topic.getLastPostUrl()); - //Doesn't put an already ellipsized topic title in Bundle - intent.putExtras(extras); - intent.setFlags(FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); - } + topicViewHolder.topicLastPost.setOnClickListener(view -> { + Intent intent = new Intent(context, TopicActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_TOPIC_URL, topic.getLastPostUrl()); + //Doesn't put an already ellipsized topic title in Bundle + intent.putExtras(extras); + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + context.startActivity(intent); }); } else if (holder instanceof LoadingViewHolder) { LoadingViewHolder loadingViewHolder = (LoadingViewHolder) holder; 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 a4e4449e..85cb4a9c 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 @@ -139,6 +139,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF Intent i = new Intent(MainActivity.this, TopicActivity.class); i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl()); i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject()); + i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(i); } @@ -156,6 +157,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF Intent i = new Intent(MainActivity.this, TopicActivity.class); i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl()); i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject()); + i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(i); } else Timber.e("onUnreadFragmentInteraction TopicSummary came without a link"); 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 39713ffc..75c7d081 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -457,8 +457,8 @@ public abstract class BaseActivity extends AppCompatActivity { profileDrawerItem.withIcon(new IconicsDrawable(this) .icon(FontAwesome.Icon.faw_user) .paddingDp(10) - .color(ContextCompat.getColor(this, R.color.primary_light)) - .backgroundColor(ContextCompat.getColor(this, R.color.primary))); + .color(ContextCompat.getColor(this, R.color.iron)) + .backgroundColor(ContextCompat.getColor(this, R.color.primary_light))); } //-------------------------------------------LOGOUT------------------------------------------------- diff --git a/build.gradle b/build.gradle index 74c7bcf9..0a1a117a 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,10 @@ buildscript { repositories { - jcenter() maven { url "https://jitpack.io" } maven { url "https://maven.fabric.io/public" } google() + jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' @@ -17,9 +17,9 @@ buildscript { allprojects { repositories { - jcenter() maven { url "https://jitpack.io" } maven { url "https://maven.google.com" } + jcenter() } } From 1f9a0d74b51456a4bfd08423a0bc31f14438efbb Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 25 Oct 2018 23:42:14 +0300 Subject: [PATCH 047/104] fix crash when opening topics from BoardActivity --- .../main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java | 1 + 1 file changed, 1 insertion(+) 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 97857440..15829451 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 @@ -190,6 +190,7 @@ class BoardAdapter extends RecyclerView.Adapter { extras.putString(BUNDLE_TOPIC_TITLE, topic.getSubject()); intent.putExtras(extras); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }); if (topicExpandableVisibility.get(topicViewHolder.getAdapterPosition() - parsedSubBoards From eef6caf28e2bfc5fc90bc056f8c962914fa30022 Mon Sep 17 00:00:00 2001 From: oogee Date: Fri, 26 Oct 2018 15:11:58 +0300 Subject: [PATCH 048/104] fix last fix --- .../java/gr/thmmy/mthmmy/activities/board/BoardActivity.java | 2 +- .../java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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 ae6852fb..e916a339 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 @@ -125,7 +125,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo }); } - boardAdapter = new BoardAdapter(getApplicationContext(), parsedSubBoards, parsedTopics); + boardAdapter = new BoardAdapter(this, parsedSubBoards, parsedTopics); RecyclerView mainContent = findViewById(R.id.board_recycler_view); mainContent.setAdapter(boardAdapter); final LinearLayoutManager layoutManager = new LinearLayoutManager(this); 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 15829451..97857440 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 @@ -190,7 +190,6 @@ class BoardAdapter extends RecyclerView.Adapter { extras.putString(BUNDLE_TOPIC_TITLE, topic.getSubject()); intent.putExtras(extras); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }); if (topicExpandableVisibility.get(topicViewHolder.getAdapterPosition() - parsedSubBoards From 3a17710531ad2563b076be8b8e4748e025113e63 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Tue, 6 Nov 2018 14:29:21 +0200 Subject: [PATCH 049/104] Removed margin from Settings --- app/build.gradle | 6 +-- .../activities/settings/SettingsFragment.java | 6 +-- .../res/xml-v26/app_preferences_guest.xml | 19 +++++--- .../main/res/xml-v26/app_preferences_user.xml | 32 +++++++++----- .../main/res/xml/app_preferences_guest.xml | 32 +++++++++----- app/src/main/res/xml/app_preferences_user.xml | 44 +++++++++++++------ 6 files changed, 92 insertions(+), 47 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cfb58070..545832f3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,8 +54,8 @@ tasks.whenTaskAdded { task -> dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.0.0' - implementation 'androidx.preference:preference:1.0.0' + implementation 'androidx.appcompat:appcompat:1.0.1' + implementation 'androidx.preference:preference:1.1.0-alpha01' implementation 'androidx.legacy:legacy-preference-v14:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' @@ -63,7 +63,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' - implementation 'com.google.firebase:firebase-core:16.0.4' + implementation 'com.google.firebase:firebase-core:16.0.5' implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' implementation 'com.squareup.okhttp3:okhttp:3.11.0' 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 eb0a2070..a66f91ae 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 @@ -28,7 +28,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared NOT_SET, USER, GUEST } - public static final String ARG_IS_LOGGED_IN = "selectedRingtoneKey"; + private static final String ARG_IS_LOGGED_IN = "selectedRingtoneKey"; //Preferences xml keys private static final String SELECTED_NOTIFICATIONS_SOUND = "pref_notifications_select_sound_key"; @@ -44,7 +44,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared private SharedPreferences settingsFile; private PREFS_TYPE prefs_type = PREFS_TYPE.NOT_SET; - private boolean isLoggedIn = false; + private boolean isLoggedIn; private ArrayList defaultHomeTabEntries = new ArrayList<>(); private ArrayList defaultHomeTabValues = new ArrayList<>(); @@ -161,7 +161,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared } } - public void updateUserLoginState(boolean isLoggedIn) { + void updateUserLoginState(boolean isLoggedIn) { this.isLoggedIn = isLoggedIn; updatePreferenceVisibility(); } diff --git a/app/src/main/res/xml-v26/app_preferences_guest.xml b/app/src/main/res/xml-v26/app_preferences_guest.xml index 2aa3e166..942c2692 100644 --- a/app/src/main/res/xml-v26/app_preferences_guest.xml +++ b/app/src/main/res/xml-v26/app_preferences_guest.xml @@ -1,7 +1,10 @@ - + - + + android:summary="@string/pref_summary_app_main_default_tab" + app:iconSpaceReserved="false" /> + android:title="@string/pref_category_privacy" + app:iconSpaceReserved="false"> + android:summary="@string/pref_summary_privacy_crashlytics_enable" + app:iconSpaceReserved="false" /> + android:summary="@string/pref_summary_privacy_analytics_enable" + app:iconSpaceReserved="false" /> diff --git a/app/src/main/res/xml-v26/app_preferences_user.xml b/app/src/main/res/xml-v26/app_preferences_user.xml index 6010320f..fe301eb3 100644 --- a/app/src/main/res/xml-v26/app_preferences_user.xml +++ b/app/src/main/res/xml-v26/app_preferences_user.xml @@ -1,7 +1,10 @@ - + - + + android:summary="@string/pref_summary_app_main_default_tab" + app:iconSpaceReserved="false" /> + android:title="@string/pref_category_posting" + app:iconSpaceReserved="false"> + android:summary="@string/pref_summary_posting_app_signature_enable" + app:iconSpaceReserved="false" /> + android:title="@string/pref_category_privacy" + app:iconSpaceReserved="false"> + android:summary="@string/pref_summary_privacy_crashlytics_enable" + app:iconSpaceReserved="false" /> + android:summary="@string/pref_summary_privacy_analytics_enable" + app:iconSpaceReserved="false" /> - diff --git a/app/src/main/res/xml/app_preferences_guest.xml b/app/src/main/res/xml/app_preferences_guest.xml index 364ad5a1..ebfeaa26 100644 --- a/app/src/main/res/xml/app_preferences_guest.xml +++ b/app/src/main/res/xml/app_preferences_guest.xml @@ -1,7 +1,10 @@ - + - + + android:summary="@string/pref_summary_app_main_default_tab" + app:iconSpaceReserved="false" /> - + + android:title="@string/pref_title_notification_vibration_enable" + app:iconSpaceReserved="false" /> + android:summary="@string/pref_summary_notification_led_enable" + app:iconSpaceReserved="false" /> + android:summary="@string/pref_summary_notifications_sound" + app:iconSpaceReserved="false" /> + android:title="@string/pref_category_privacy" + app:iconSpaceReserved="false"> + android:summary="@string/pref_summary_privacy_crashlytics_enable" + app:iconSpaceReserved="false" /> + android:summary="@string/pref_summary_privacy_analytics_enable" + app:iconSpaceReserved="false" /> diff --git a/app/src/main/res/xml/app_preferences_user.xml b/app/src/main/res/xml/app_preferences_user.xml index 9778f340..2599df44 100644 --- a/app/src/main/res/xml/app_preferences_user.xml +++ b/app/src/main/res/xml/app_preferences_user.xml @@ -1,7 +1,10 @@ - + - + + android:summary="@string/pref_summary_app_main_default_tab" + app:iconSpaceReserved="false" /> - + + android:title="@string/pref_title_notification_vibration_enable" + app:iconSpaceReserved="false" /> + android:summary="@string/pref_summary_notification_led_enable" + app:iconSpaceReserved="false" /> + android:summary="@string/pref_summary_notifications_sound" + app:iconSpaceReserved="false" /> + android:title="@string/pref_category_posting" + app:iconSpaceReserved="false"> + android:summary="@string/pref_summary_posting_app_signature_enable" + app:iconSpaceReserved="false" /> + android:title="@string/pref_category_privacy" + app:iconSpaceReserved="false"> + android:summary="@string/pref_summary_privacy_crashlytics_enable" + app:iconSpaceReserved="false" /> + android:summary="@string/pref_summary_privacy_analytics_enable" + app:iconSpaceReserved="false"/> \ No newline at end of file From a6578b0830e05c75b1185a519eeecb4f423ffc29 Mon Sep 17 00:00:00 2001 From: oogee Date: Tue, 6 Nov 2018 15:12:53 +0200 Subject: [PATCH 050/104] html2span progress --- .../mthmmy/activities/topic/TopicParser.java | 6 +- .../java/gr/thmmy/mthmmy/model/HtmlTag.java | 58 ++++++++++++ .../thmmy/mthmmy/utils/parsing/BBParser.java | 90 +++++++++++++++++-- 3 files changed, 142 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/model/HtmlTag.java 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 5a411e12..4ebbba5a 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 @@ -156,9 +156,9 @@ public class TopicParser { ArrayList parsedPostsList = new ArrayList<>(); -// Poll poll = findPoll(topic); -// if (poll != null) -// parsedPostsList.add(poll); + Poll poll = findPoll(topic); + if (poll != null) + parsedPostsList.add(poll); Elements postRows; diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/HtmlTag.java b/app/src/main/java/gr/thmmy/mthmmy/model/HtmlTag.java new file mode 100644 index 00000000..b7e13021 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/model/HtmlTag.java @@ -0,0 +1,58 @@ +package gr.thmmy.mthmmy.model; + +import androidx.annotation.NonNull; + +public class HtmlTag { + private int start, end; + private String name, attributeKey, attributeValue; + + public HtmlTag(int start, String name) { + this.start = start; + this.name = name; + } + + public HtmlTag(int start, String name, String attributeKey, String attributeValue) { + this.start = start; + this.name = name; + this.attributeKey = attributeKey; + this.attributeValue = attributeValue; + } + + @NonNull + @Override + public String toString() { + return "start:" + start + ",end:" + end + ",name:" + name; + } + + public int getStart() { + return start; + } + + public void setStart(int start) { + this.start = start; + } + + public int getEnd() { + return end; + } + + public void setEnd(int end) { + this.end = end; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAttributeKey() { + return attributeKey; + } + + public String getAttributeValue() { + return attributeValue; + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java index e596d85f..618366ff 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java @@ -3,27 +3,24 @@ package gr.thmmy.mthmmy.utils.parsing; import android.graphics.Typeface; import android.text.Spannable; import android.text.SpannableStringBuilder; -import android.text.SpannedString; import android.text.TextUtils; import android.text.style.StrikethroughSpan; import android.text.style.StyleSpan; import android.text.style.UnderlineSpan; -import org.commonmark.node.Link; - import java.nio.charset.UnsupportedCharsetException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.LinkedList; -import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import gr.thmmy.mthmmy.model.BBTag; -import timber.log.Timber; +import gr.thmmy.mthmmy.model.HtmlTag; public class BBParser { - private static final String[] supportedTags = {"b", "i", "u", "s"}; + private static final String[] ALL_TAGS = {"b", "i", "u", "s", "glow", "shadow", "move", "pre", "lefter", + "center", "right", "hr", "size", "font", "color", "youtube", "flash", "img", "url" + , "email", "ftp", "table", "tr", "td", "sup", "sub", "tt", "code", "quote", "tex", "list", "li"}; + private static final String[] SUPPORTED_TAGS = {"b", "i", "u", "s"}; public static SpannableStringBuilder bb2span(String bb) { SpannableStringBuilder builder = new SpannableStringBuilder(bb); @@ -68,6 +65,38 @@ public class BBParser { return builder; } + public static SpannableStringBuilder html2span(String html) { + SpannableStringBuilder builder = new SpannableStringBuilder(html); + // store the original indices of the string + LinkedList stringIndices = new LinkedList<>(); + for (int i = 0; i < builder.length(); i++) { + stringIndices.add(i); + } + + HtmlTag[] tags = getHtmlTags(html); + for (HtmlTag tag : tags) { + int start = stringIndices.indexOf(tag.getStart()); + int end = stringIndices.indexOf(tag.getEnd()); + int startTagLength = tag.getName().length() + 2; + int endTagLength = tag.getName().length() + 3; + + switch (tag.getName()) { + + } + + //remove starting and ending tag and and do the same changes in the list + builder.delete(start, start + startTagLength); + for (int i = start; i < start + startTagLength; i++) { + stringIndices.remove(start); + } + builder.delete(end - startTagLength, end - startTagLength + endTagLength); + for (int i = end - startTagLength; i < end - startTagLength + endTagLength; i++) { + stringIndices.remove(end - startTagLength); + } + } + return builder; + } + public static BBTag[] getTags(String bb) { Pattern bbtagPattern = Pattern.compile("\\[(.+?)\\]"); @@ -104,8 +133,51 @@ public class BBParser { return tags.toArray(new BBTag[0]); } + public static HtmlTag[] getHtmlTags(String html) { + Pattern htmlPattern = Pattern.compile("<(.+?)>"); + + LinkedList tags = new LinkedList<>(); + Matcher htmlMatcher = htmlPattern.matcher(html); + while (htmlMatcher.find()) { + String startTag = htmlMatcher.group(1); + int separatorIndex = startTag.indexOf(' '); + String name, attribute = null, attributeValue = null; + if (separatorIndex > 0) { + String fullAttribute = startTag.substring(separatorIndex); + int equalsIndex = fullAttribute.indexOf('='); + attribute = fullAttribute.substring(0, equalsIndex); + attributeValue = fullAttribute.substring(equalsIndex); + name = startTag.substring(0, separatorIndex); + } else + name = startTag; + + if (name.startsWith("/")) { + //closing tag + name = name.substring(1); + for (int i = tags.size() - 1; i >= 0; i--) { + if (tags.get(i).getName().equals(name)) { + tags.get(i).setEnd(htmlMatcher.start()); + break; + } + } + continue; + } + if (isHtmlTagSupported(name, attribute, attributeValue)) + tags.add(new HtmlTag(htmlMatcher.start(), name, attribute, attributeValue)); + } + // remove parsed tags with no end tag + for (HtmlTag htmlTag : tags) + if (htmlTag.getEnd() == 0) + tags.remove(htmlTag); + return tags.toArray(new HtmlTag[0]); + } + + private static boolean isHtmlTagSupported(String name, String attribute, String attributeValue) { + return false; + } + public static boolean isSupported(String tagName) { - for (String tag : supportedTags) + for (String tag : SUPPORTED_TAGS) if (TextUtils.equals(tag, tagName)) return true; return false; } From 9b22f1da6a09336b602ae5c52724ddad79031599 Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 8 Nov 2018 18:33:34 +0200 Subject: [PATCH 051/104] support not supporting html tags in polls --- .../thmmy/mthmmy/activities/TestActivity.java | 5 +- .../mthmmy/activities/topic/TopicAdapter.java | 38 +++++++++-- .../java/gr/thmmy/mthmmy/utils/HTMLUtils.java | 19 ++++-- .../{BBParser.java => ThmmyParser.java} | 67 ++++++++++++++----- 4 files changed, 99 insertions(+), 30 deletions(-) rename app/src/main/java/gr/thmmy/mthmmy/utils/parsing/{BBParser.java => ThmmyParser.java} (70%) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/TestActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/TestActivity.java index 1ac4c05c..28ba7c77 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/TestActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/TestActivity.java @@ -2,8 +2,7 @@ package gr.thmmy.mthmmy.activities; import androidx.appcompat.app.AppCompatActivity; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.utils.parsing.BBParser; -import timber.log.Timber; +import gr.thmmy.mthmmy.utils.parsing.ThmmyParser; import android.os.Bundle; import android.text.SpannableStringBuilder; @@ -17,7 +16,7 @@ public class TestActivity extends AppCompatActivity { setContentView(R.layout.activity_test); String bb = "[b]An [i]elep[u]hant[/i][/b] swi[/u]ms in [s]the[/s] tree"; - SpannableStringBuilder result = BBParser.bb2span(bb); + SpannableStringBuilder result = ThmmyParser.bb2span(bb); TextView bbRaw = findViewById(R.id.bb_raw); TextView bb2Text = findViewById(R.id.bb2text); 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 1c32ce2d..44658316 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 @@ -66,6 +66,7 @@ import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.TopicItem; import gr.thmmy.mthmmy.utils.CircleTransform; +import gr.thmmy.mthmmy.utils.parsing.ThmmyParser; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import gr.thmmy.mthmmy.viewmodel.TopicViewModel; import timber.log.Timber; @@ -166,9 +167,34 @@ class TopicAdapter extends RecyclerView.Adapter { Poll poll = (Poll) topicItems.get(position); Poll.Entry[] entries = poll.getEntries(); PollViewHolder holder = (PollViewHolder) currentHolder; + + boolean pollSupported = true; + for (Poll.Entry entry : entries) { + if (ThmmyParser.containsHtml(entry.getEntryName())) pollSupported = false; + break; + } + if (ThmmyParser.containsHtml(poll.getQuestion())) pollSupported = false; + if (!pollSupported) { + holder.optionsLayout.setVisibility(View.GONE); + holder.voteChart.setVisibility(View.GONE); + holder.removeVotesButton.setVisibility(View.GONE); + holder.showPollResultsButton.setVisibility(View.GONE); + holder.hidePollResultsButton.setVisibility(View.GONE); + // use the submit vote button to open poll on browser + holder.submitButton.setText("Open in browser"); + holder.submitButton.setOnClickListener(v -> { + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(viewModel.getTopicUrl())); + context.startActivity(browserIntent); + }); + holder.submitButton.setVisibility(View.VISIBLE); + // put a warning instead of a question + holder.question.setText("This topic contains a poll that is not supported in mthmmy"); + return; + } + holder.question.setText(poll.getQuestion()); holder.optionsLayout.removeAllViews(); - holder.errorTooManySelected.setVisibility(View.GONE); + holder.errorTextview.setVisibility(View.GONE); if (poll.getAvailableVoteCount() > 1) { for (Poll.Entry entry : entries) { LinearLayout container = new LinearLayout(context); @@ -183,6 +209,7 @@ class TopicAdapter extends RecyclerView.Adapter { //noinspection deprecation label.setText(Html.fromHtml(entry.getEntryName())); } + label.setText(ThmmyParser.html2span(context, entry.getEntryName())); checkBox.setTextColor(context.getResources().getColor(R.color.primary_text)); container.addView(checkBox); container.addView(label); @@ -202,6 +229,7 @@ class TopicAdapter extends RecyclerView.Adapter { //noinspection deprecation radioButton.setText(Html.fromHtml(entries[i].getEntryName())); } + radioButton.setText(ThmmyParser.html2span(context, entries[i].getEntryName())); radioButton.setTextColor(context.getResources().getColor(R.color.primary_text)); radioGroup.addView(radioButton); } @@ -261,10 +289,10 @@ class TopicAdapter extends RecyclerView.Adapter { if (poll.getPollFormUrl() != null) { holder.submitButton.setOnClickListener(v -> { if (!viewModel.submitVote(holder.optionsLayout)) { - holder.errorTooManySelected.setText(context.getResources() + holder.errorTextview.setText(context.getResources() .getQuantityString(R.plurals.error_too_many_checked, poll.getAvailableVoteCount(), poll.getAvailableVoteCount())); - holder.errorTooManySelected.setVisibility(View.VISIBLE); + holder.errorTextview.setVisibility(View.VISIBLE); } }); holder.submitButton.setVisibility(View.VISIBLE); @@ -754,7 +782,7 @@ class TopicAdapter extends RecyclerView.Adapter { } static class PollViewHolder extends RecyclerView.ViewHolder { - final TextView question, errorTooManySelected; + final TextView question, errorTextview; final LinearLayout optionsLayout; final AppCompatButton submitButton; final AppCompatButton removeVotesButton, showPollResultsButton, hidePollResultsButton; @@ -769,7 +797,7 @@ class TopicAdapter extends RecyclerView.Adapter { removeVotesButton = itemView.findViewById(R.id.remove_vote_button); showPollResultsButton = itemView.findViewById(R.id.show_poll_results_button); hidePollResultsButton = itemView.findViewById(R.id.show_poll_options_button); - errorTooManySelected = itemView.findViewById(R.id.error_too_many_checked); + errorTextview = itemView.findViewById(R.id.error_too_many_checked); voteChart = itemView.findViewById(R.id.vote_chart); } } 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 2713a2a8..8ca4ede6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/HTMLUtils.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/HTMLUtils.java @@ -1,6 +1,7 @@ package gr.thmmy.mthmmy.utils; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; @@ -12,6 +13,7 @@ import android.text.style.URLSpan; import android.view.View; import gr.thmmy.mthmmy.activities.board.BoardActivity; +import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.model.ThmmyPage; @@ -41,7 +43,7 @@ public class HTMLUtils { return strBuilder; } - private static void makeLinkClickable(Activity activity, SpannableStringBuilder strBuilder, final URLSpan span) { + public static void makeLinkClickable(Context context, SpannableStringBuilder strBuilder, final URLSpan span) { int start = strBuilder.getSpanStart(span); int end = strBuilder.getSpanEnd(span); int flags = strBuilder.getSpanFlags(span); @@ -50,24 +52,27 @@ public class HTMLUtils { public void onClick(View view) { ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(span.getURL())); if (target.is(ThmmyPage.PageCategory.BOARD)) { - Intent intent = new Intent(activity.getApplicationContext(), BoardActivity.class); + Intent intent = new Intent(context, BoardActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_BOARD_URL, span.getURL()); extras.putString(BUNDLE_BOARD_TITLE, ""); intent.putExtras(extras); intent.setFlags(FLAG_ACTIVITY_NEW_TASK); - activity.getApplicationContext().startActivity(intent); + context.startActivity(intent); } else if (target.is(ThmmyPage.PageCategory.PROFILE)) { - Intent intent = new Intent(activity.getApplicationContext(), ProfileActivity.class); + Intent intent = new Intent(context, ProfileActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_PROFILE_URL, span.getURL()); extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, ""); extras.putString(BUNDLE_PROFILE_USERNAME, ""); intent.putExtras(extras); intent.setFlags(FLAG_ACTIVITY_NEW_TASK); - activity.getApplicationContext().startActivity(intent); - } else if (target.is(ThmmyPage.PageCategory.INDEX)) - activity.finish(); + context.startActivity(intent); + } else if (target.is(ThmmyPage.PageCategory.INDEX)) { + Intent intent = new Intent(context, MainActivity.class); + intent.setFlags(FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } } }; strBuilder.setSpan(clickable, start, end, flags); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyParser.java similarity index 70% rename from app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java rename to app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyParser.java index 618366ff..f900290f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyParser.java @@ -1,11 +1,13 @@ package gr.thmmy.mthmmy.utils.parsing; +import android.content.Context; import android.graphics.Typeface; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.style.StrikethroughSpan; import android.text.style.StyleSpan; +import android.text.style.URLSpan; import android.text.style.UnderlineSpan; import java.nio.charset.UnsupportedCharsetException; @@ -15,12 +17,14 @@ import java.util.regex.Pattern; import gr.thmmy.mthmmy.model.BBTag; import gr.thmmy.mthmmy.model.HtmlTag; +import gr.thmmy.mthmmy.utils.HTMLUtils; -public class BBParser { - private static final String[] ALL_TAGS = {"b", "i", "u", "s", "glow", "shadow", "move", "pre", "lefter", +public class ThmmyParser { + private static final String[] ALL_BB_TAGS = {"b", "i", "u", "s", "glow", "shadow", "move", "pre", "lefter", "center", "right", "hr", "size", "font", "color", "youtube", "flash", "img", "url" , "email", "ftp", "table", "tr", "td", "sup", "sub", "tt", "code", "quote", "tex", "list", "li"}; - private static final String[] SUPPORTED_TAGS = {"b", "i", "u", "s"}; + private static final String[] ALL_HTML_TAGS = {"b", "br", "span", "i", "div", "del", "marquee", "pre", + "hr", "embed", "noembed", "a", "img", "table", "tr", "td", "sup", "sub", "tt", "pre", "ul", "li"}; public static SpannableStringBuilder bb2span(String bb) { SpannableStringBuilder builder = new SpannableStringBuilder(bb); @@ -30,7 +34,7 @@ public class BBParser { stringIndices.add(i); } - BBTag[] tags = getTags(bb); + BBTag[] tags = getBBTags(bb); for (BBTag tag : tags) { int start = stringIndices.indexOf(tag.getStart()); int end = stringIndices.indexOf(tag.getEnd()); @@ -65,7 +69,7 @@ public class BBParser { return builder; } - public static SpannableStringBuilder html2span(String html) { + public static SpannableStringBuilder html2span(Context context, String html) { SpannableStringBuilder builder = new SpannableStringBuilder(html); // store the original indices of the string LinkedList stringIndices = new LinkedList<>(); @@ -78,10 +82,35 @@ public class BBParser { int start = stringIndices.indexOf(tag.getStart()); int end = stringIndices.indexOf(tag.getEnd()); int startTagLength = tag.getName().length() + 2; + if (tag.getAttributeKey() != null) { + startTagLength += tag.getAttributeKey().length() + tag.getAttributeValue().length() + 4; + } int endTagLength = tag.getName().length() + 3; - switch (tag.getName()) { - + if (isHtmlTagSupported(tag.getName(), tag.getAttributeKey(), tag.getAttributeValue())) { + switch (tag.getName()) { + case "b": + builder.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + break; + case "i": + builder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + break; + case "span": + if (tag.getAttributeKey().equals("style") && tag.getAttributeValue().equals("text-decoration: underline;")) { + builder.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } + break; + case "del": + builder.setSpan(new StrikethroughSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + break; + case "a": + URLSpan urlSpan = new URLSpan(tag.getAttributeValue()); + builder.setSpan(urlSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + HTMLUtils.makeLinkClickable(context, builder, urlSpan); + break; + default: + throw new UnsupportedCharsetException("Tag not supported"); + } } //remove starting and ending tag and and do the same changes in the list @@ -97,7 +126,7 @@ public class BBParser { return builder; } - public static BBTag[] getTags(String bb) { + public static BBTag[] getBBTags(String bb) { Pattern bbtagPattern = Pattern.compile("\\[(.+?)\\]"); LinkedList tags = new LinkedList<>(); @@ -123,7 +152,7 @@ public class BBParser { } continue; } - if (isSupported(name)) + if (isBBTagSupported(name)) tags.add(new BBTag(bbMatcher.start(), name, attribute)); } // remove parsed tags with no end tag @@ -145,8 +174,8 @@ public class BBParser { if (separatorIndex > 0) { String fullAttribute = startTag.substring(separatorIndex); int equalsIndex = fullAttribute.indexOf('='); - attribute = fullAttribute.substring(0, equalsIndex); - attributeValue = fullAttribute.substring(equalsIndex); + attribute = fullAttribute.substring(1, equalsIndex); + attributeValue = fullAttribute.substring(equalsIndex + 2, fullAttribute.length() - 1); name = startTag.substring(0, separatorIndex); } else name = startTag; @@ -162,7 +191,7 @@ public class BBParser { } continue; } - if (isHtmlTagSupported(name, attribute, attributeValue)) + if (isHtmlTag(name)) tags.add(new HtmlTag(htmlMatcher.start(), name, attribute, attributeValue)); } // remove parsed tags with no end tag @@ -173,12 +202,20 @@ public class BBParser { } private static boolean isHtmlTagSupported(String name, String attribute, String attributeValue) { - return false; + return name.equals("b") || name.equals("i") || name.equals("span") || name.equals("del") || name.equals("a"); } - public static boolean isSupported(String tagName) { - for (String tag : SUPPORTED_TAGS) + public static boolean isBBTagSupported(String name) { + return name.equals("b") || name.equals("i") || name.equals("u") || name.equals("s"); + } + + public static boolean isHtmlTag(String tagName) { + for (String tag : ALL_HTML_TAGS) if (TextUtils.equals(tag, tagName)) return true; return false; } + + public static boolean containsHtml(String s) { + return getHtmlTags(s).length > 0; + } } From 9ba1408055c7386bb270d56028bac7c7e5d5e5ac Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 8 Nov 2018 18:44:13 +0200 Subject: [PATCH 052/104] Merge branch 'bbparser' into develop # Conflicts: # app/build.gradle --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 1 - .../java/gr/thmmy/mthmmy/activities/main/MainActivity.java | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cfb58070..da33451c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' - implementation 'com.google.firebase:firebase-core:16.0.4' + implementation 'com.google.firebase:firebase-core:16.0.5' implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' implementation 'com.squareup.okhttp3:okhttp:3.11.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cf3aaef0..fb7c2b6a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -173,7 +173,6 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activities.main.MainActivity" />
    - \ No newline at end of file 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 f8d87263..85cb4a9c 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 @@ -19,7 +19,6 @@ import androidx.preference.PreferenceManager; import androidx.viewpager.widget.ViewPager; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; -import gr.thmmy.mthmmy.activities.TestActivity; import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.main.forum.ForumFragment; @@ -133,8 +132,6 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF , Toast.LENGTH_SHORT).show(); } mBackPressed = System.currentTimeMillis(); - - startActivity(new Intent(this, TestActivity.class)); } @Override From ebe2990d0c7211b5a3c45b337b9f7680fc1a2185 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sun, 11 Nov 2018 11:47:02 +0200 Subject: [PATCH 053/104] Shoutbox white flickering fix --- .../gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 7d041a32..82a3389e 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 @@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.activities.shoutbox; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; +import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -35,12 +36,12 @@ public class ShoutAdapter extends CustomRecyclerView.Adapter Date: Sun, 11 Nov 2018 12:46:17 +0200 Subject: [PATCH 054/104] Bookmarks navigation fix, up libs --- app/build.gradle | 4 ++-- .../activities/board/BoardActivity.java | 6 ++--- .../bookmarks/BoardBookmarksFragment.java | 23 ++++++++----------- .../bookmarks/BookmarkActivity.java | 2 -- .../mthmmy/activities/topic/TopicAdapter.java | 2 +- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 545832f3..52284b18 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,7 +54,7 @@ tasks.whenTaskAdded { task -> dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.0.1' + implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.preference:preference:1.1.0-alpha01' implementation 'androidx.legacy:legacy-preference-v14:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' @@ -65,7 +65,7 @@ dependencies { implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.firebase:firebase-core:16.0.5' implementation 'com.google.firebase:firebase-messaging:17.3.4' - implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' + implementation 'com.crashlytics.sdk.android:crashlytics:2.9.6' implementation 'com.squareup.okhttp3:okhttp:3.11.0' implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' 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 e916a339..dfd1d38e 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 @@ -197,9 +197,9 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo tempSubboards.addAll(parsedSubBoards); tempTopics.addAll(parsedTopics); //Removes loading item - if (isLoadingMore) { - if (tempTopics.size() > 0) tempTopics.remove(tempTopics.size() - 1); - } + if (isLoadingMore && tempTopics.size() > 0) + tempTopics.remove(tempTopics.size() - 1); + parsedTitle = boardPage.select("div.nav a.nav").last().text(); //Finds number of pages diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java index 8a14611c..913d2ce7 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java @@ -26,21 +26,20 @@ import gr.thmmy.mthmmy.model.Bookmark; * create an instance of this fragment. */ public class BoardBookmarksFragment extends Fragment { - protected static final String ARG_SECTION_NUMBER = "SECTION_NUMBER"; - protected static final String ARG_BOARD_BOOKMARKS = "BOARD_BOOKMARKS"; + private static final String ARG_SECTION_NUMBER = "SECTION_NUMBER"; + private static final String ARG_BOARD_BOOKMARKS = "BOARD_BOOKMARKS"; - public static final String INTERACTION_CLICK_BOARD_BOOKMARK = "CLICK_BOARD_BOOKMARK"; - public static final String INTERACTION_TOGGLE_BOARD_NOTIFICATION = "TOGGLE_BOARD_NOTIFICATION"; - public static final String INTERACTION_REMOVE_BOARD_BOOKMARK= "REMOVE_BOARD_BOOKMARK"; + static final String INTERACTION_CLICK_BOARD_BOOKMARK = "CLICK_BOARD_BOOKMARK"; + static final String INTERACTION_TOGGLE_BOARD_NOTIFICATION = "TOGGLE_BOARD_NOTIFICATION"; + static final String INTERACTION_REMOVE_BOARD_BOOKMARK= "REMOVE_BOARD_BOOKMARK"; - ArrayList boardBookmarks = null; + private ArrayList boardBookmarks = null; private static Drawable notificationsEnabledButtonImage; private static Drawable notificationsDisabledButtonImage; // Required empty public constructor - public BoardBookmarksFragment() { - } + public BoardBookmarksFragment() { } /** * Use ONLY this factory method to create a new instance of @@ -130,10 +129,8 @@ public class BoardBookmarksFragment extends Fragment { bookmarksLinearView.addView(row); } } - } else { - + } else bookmarksLinearView.addView(bookmarksListEmptyMessage()); - } return rootView; } @@ -146,9 +143,9 @@ public class BoardBookmarksFragment extends Fragment { emptyBookmarksCategory.setLayoutParams(params); emptyBookmarksCategory.setText(getString(R.string.empty_board_bookmarks)); emptyBookmarksCategory.setTypeface(emptyBookmarksCategory.getTypeface(), Typeface.BOLD); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) emptyBookmarksCategory.setTextColor(this.getContext().getColor(R.color.primary_text)); - } else { + else { //noinspection deprecation emptyBookmarksCategory.setTextColor(this.getContext().getResources().getColor(R.color.primary_text)); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java index d6ba695c..20ecfd28 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java @@ -74,7 +74,6 @@ public class BookmarkActivity extends BaseActivity { extras.putString(BUNDLE_TOPIC_TITLE, bookmarkedTopic.getTitle()); intent.putExtras(extras); startActivity(intent); - finish(); break; case TopicBookmarksFragment.INTERACTION_TOGGLE_TOPIC_NOTIFICATION: return toggleNotification(bookmarkedTopic); @@ -96,7 +95,6 @@ public class BookmarkActivity extends BaseActivity { extras.putString(BUNDLE_BOARD_TITLE, bookmarkedBoard.getTitle()); intent.putExtras(extras); startActivity(intent); - finish(); break; case BoardBookmarksFragment.INTERACTION_TOGGLE_BOARD_NOTIFICATION: return toggleNotification(bookmarkedBoard); 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 f5bcb761..fa56eec1 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 @@ -65,8 +65,8 @@ import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.TopicItem; import gr.thmmy.mthmmy.utils.CircleTransform; -import gr.thmmy.mthmmy.utils.parsing.ThmmyParser; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; +import gr.thmmy.mthmmy.utils.parsing.ThmmyParser; import gr.thmmy.mthmmy.viewmodel.TopicViewModel; import timber.log.Timber; From 3de864e6ebe81faf37c4f9f57c0d293aa7e7f2a7 Mon Sep 17 00:00:00 2001 From: oogee Date: Sun, 11 Nov 2018 17:28:14 +0200 Subject: [PATCH 055/104] default user icon switch --- .../activities/profile/ProfileActivity.java | 31 +++++++++---- .../mthmmy/activities/topic/TopicAdapter.java | 46 ++++++++++++++----- .../gr/thmmy/mthmmy/base/BaseActivity.java | 2 +- .../ic_default_user_thumbnail_white_24dp.xml | 5 -- .../main/res/layout-v21/activity_profile.xml | 1 - .../layout-v21/activity_topic_post_row.xml | 1 - app/src/main/res/layout/activity_profile.xml | 1 - .../res/layout/activity_topic_edit_row.xml | 3 +- .../res/layout/activity_topic_post_row.xml | 3 +- .../layout/activity_topic_quick_reply_row.xml | 3 +- 10 files changed, 61 insertions(+), 35 deletions(-) delete mode 100644 app/src/main/res/drawable/ic_default_user_thumbnail_white_24dp.xml 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 a9b11c7f..a7729cd7 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 @@ -20,6 +20,8 @@ import android.widget.Toast; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; +import com.mikepenz.fontawesome_typeface_library.FontAwesome; +import com.mikepenz.iconics.IconicsDrawable; import com.squareup.picasso.Picasso; import org.jsoup.Jsoup; @@ -32,6 +34,7 @@ import java.util.List; import java.util.Objects; import androidx.appcompat.app.AppCompatDelegate; +import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -133,10 +136,16 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment .load(thumbnailUrl) .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) .centerCrop() - .error(ResourcesCompat.getDrawable(this.getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) - .placeholder(ResourcesCompat.getDrawable(this.getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) + .error(new IconicsDrawable(ProfileActivity.this) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(ProfileActivity.this, R.color.iron)) + .backgroundColor(ContextCompat.getColor(ProfileActivity.this, R.color.primary)) + .sizePx(THUMBNAIL_SIZE)) + .placeholder(new IconicsDrawable(ProfileActivity.this) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(ProfileActivity.this, R.color.iron)) + .backgroundColor(ContextCompat.getColor(ProfileActivity.this, R.color.primary)) + .sizePx(THUMBNAIL_SIZE)) .transform(new CircleTransform()) .into(thumbnailView); usernameView = findViewById(R.id.profile_activity_username); @@ -307,10 +316,16 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment .load(thumbnailUrl) .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) .centerCrop() - .error(ResourcesCompat.getDrawable(getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) - .placeholder(ResourcesCompat.getDrawable(getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) + .error(new IconicsDrawable(ProfileActivity.this) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(ProfileActivity.this, R.color.iron)) + .backgroundColor(ContextCompat.getColor(ProfileActivity.this, R.color.primary)) + .sizePx(THUMBNAIL_SIZE)) + .placeholder(new IconicsDrawable(ProfileActivity.this) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(ProfileActivity.this, R.color.iron)) + .backgroundColor(ContextCompat.getColor(ProfileActivity.this, R.color.primary)) + .sizePx(THUMBNAIL_SIZE)) .transform(new CircleTransform()) .into(thumbnailView); if (personalText != null) { 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 fa56eec1..d890a30a 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 @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; +import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; @@ -40,6 +41,8 @@ import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarEntry; +import com.mikepenz.fontawesome_typeface_library.FontAwesome; +import com.mikepenz.iconics.IconicsDrawable; import com.squareup.picasso.Picasso; import java.util.ArrayList; @@ -50,6 +53,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.AppCompatButton; +import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.RecyclerView; @@ -317,11 +321,17 @@ class TopicAdapter extends RecyclerView.Adapter { .load(currentPost.getThumbnailURL()) .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) .centerCrop() - .error(ResourcesCompat.getDrawable(context.getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) - .placeholder(ResourcesCompat.getDrawable(context.getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) .transform(new CircleTransform()) + .error(new IconicsDrawable(context) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(context, R.color.iron)) + .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) + .sizeDp(THUMBNAIL_SIZE)) + .placeholder(new IconicsDrawable(context) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(context, R.color.iron)) + .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) + .sizeDp(THUMBNAIL_SIZE)) .into(holder.thumbnail); //Sets username,submit date, index number, subject, post's and attached files texts @@ -607,10 +617,16 @@ class TopicAdapter extends RecyclerView.Adapter { .load(getSessionManager().getAvatarLink()) .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) .centerCrop() - .error(ResourcesCompat.getDrawable(context.getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) - .placeholder(ResourcesCompat.getDrawable(context.getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) + .error(new IconicsDrawable(context) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(context, R.color.iron)) + .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) + .sizeDp(THUMBNAIL_SIZE)) + .placeholder(new IconicsDrawable(context) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(context, R.color.iron)) + .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) + .sizeDp(THUMBNAIL_SIZE)) .transform(new CircleTransform()) .into(holder.thumbnail); holder.username.setText(getSessionManager().getUsername()); @@ -663,10 +679,16 @@ class TopicAdapter extends RecyclerView.Adapter { .load(getSessionManager().getAvatarLink()) .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) .centerCrop() - .error(ResourcesCompat.getDrawable(context.getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) - .placeholder(ResourcesCompat.getDrawable(context.getResources() - , R.drawable.ic_default_user_thumbnail_white_24dp, null)) + .error(new IconicsDrawable(context) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(context, R.color.iron)) + .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) + .sizeDp(THUMBNAIL_SIZE)) + .placeholder(new IconicsDrawable(context) + .icon(FontAwesome.Icon.faw_user_circle) + .color(ContextCompat.getColor(context, R.color.iron)) + .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) + .sizeDp(THUMBNAIL_SIZE)) .transform(new CircleTransform()) .into(holder.thumbnail); holder.username.setText(getSessionManager().getUsername()); 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 75c7d081..ee81418c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -455,7 +455,7 @@ public abstract class BaseActivity extends AppCompatActivity { private void setDefaultAvatar() { profileDrawerItem.withIcon(new IconicsDrawable(this) - .icon(FontAwesome.Icon.faw_user) + .icon(FontAwesome.Icon.faw_user_circle) .paddingDp(10) .color(ContextCompat.getColor(this, R.color.iron)) .backgroundColor(ContextCompat.getColor(this, R.color.primary_light))); diff --git a/app/src/main/res/drawable/ic_default_user_thumbnail_white_24dp.xml b/app/src/main/res/drawable/ic_default_user_thumbnail_white_24dp.xml deleted file mode 100644 index d7366bda..00000000 --- a/app/src/main/res/drawable/ic_default_user_thumbnail_white_24dp.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/app/src/main/res/layout-v21/activity_profile.xml b/app/src/main/res/layout-v21/activity_profile.xml index 85b16af6..00fc8430 100644 --- a/app/src/main/res/layout-v21/activity_profile.xml +++ b/app/src/main/res/layout-v21/activity_profile.xml @@ -41,7 +41,6 @@ android:adjustViewBounds="true" android:contentDescription="@string/post_thumbnail" android:fitsSystemWindows="true" - app:srcCompat="@drawable/ic_default_user_thumbnail_white_24dp" android:transitionName="user_thumbnail" app:layout_collapseMode="parallax"/> diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml index a71a353d..6218e2ff 100644 --- a/app/src/main/res/layout-v21/activity_topic_post_row.xml +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -60,7 +60,6 @@ android:contentDescription="@string/post_thumbnail" android:maxHeight="@dimen/thumbnail_size" android:maxWidth="@dimen/thumbnail_size" - app:srcCompat="@drawable/ic_default_user_thumbnail_white_24dp" android:transitionName="user_thumbnail" /> diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml index 1c6cdb6d..e5a935cf 100644 --- a/app/src/main/res/layout/activity_profile.xml +++ b/app/src/main/res/layout/activity_profile.xml @@ -41,7 +41,6 @@ android:adjustViewBounds="true" android:contentDescription="@string/post_thumbnail" android:fitsSystemWindows="true" - app:srcCompat="@drawable/ic_default_user_thumbnail_white_24dp" app:layout_collapseMode="parallax"/> + android:maxWidth="@dimen/thumbnail_size" /> + android:maxWidth="@dimen/thumbnail_size" /> + android:maxWidth="@dimen/thumbnail_size" /> Date: Sun, 11 Nov 2018 22:21:52 +0200 Subject: [PATCH 056/104] Default avatars fix --- .../activities/profile/ProfileActivity.java | 83 +++++++------------ .../mthmmy/activities/topic/TopicAdapter.java | 80 ++++-------------- .../gr/thmmy/mthmmy/base/BaseActivity.java | 2 +- .../thmmy/mthmmy/utils/CircleTransform.java | 7 +- .../res/drawable/ic_default_user_avatar.xml | 5 ++ .../ic_default_user_avatar_darker.xml | 5 ++ .../main/res/layout-v21/activity_profile.xml | 5 +- .../layout-v21/activity_topic_post_row.xml | 7 +- app/src/main/res/layout/activity_profile.xml | 5 +- .../res/layout/activity_topic_edit_row.xml | 7 +- .../res/layout/activity_topic_post_row.xml | 7 +- .../layout/activity_topic_quick_reply_row.xml | 7 +- app/src/main/res/values/dimens.xml | 1 + 13 files changed, 81 insertions(+), 140 deletions(-) create mode 100644 app/src/main/res/drawable/ic_default_user_avatar.xml create mode 100644 app/src/main/res/drawable/ic_default_user_avatar_darker.xml 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 a7729cd7..162ea1f6 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 @@ -20,8 +20,6 @@ import android.widget.Toast; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; -import com.mikepenz.fontawesome_typeface_library.FontAwesome; -import com.mikepenz.iconics.IconicsDrawable; import com.squareup.picasso.Picasso; import org.jsoup.Jsoup; @@ -34,7 +32,6 @@ import java.util.List; import java.util.Objects; import androidx.appcompat.app.AppCompatDelegate; -import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -82,10 +79,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment * If username is not available put an empty string or leave it null. */ public static final String BUNDLE_PROFILE_USERNAME = "USERNAME"; - private static final int THUMBNAIL_SIZE = 200; private TextView usernameView; - private ImageView thumbnailView; + private ImageView avatarView; private TextView personalTextView; private MaterialProgressBar progressBar; private FloatingActionButton pmFAB; @@ -94,7 +90,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment private ProfileTask profileTask; private String personalText; private String profileUrl; - private String thumbnailUrl; + private String avatarUrl; private String username; private int tabSelect; @@ -111,8 +107,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment setContentView(R.layout.activity_profile); Bundle extras = getIntent().getExtras(); - thumbnailUrl = extras.getString(BUNDLE_PROFILE_THUMBNAIL_URL); - if (thumbnailUrl == null) thumbnailUrl = ""; + avatarUrl = extras.getString(BUNDLE_PROFILE_THUMBNAIL_URL); + if (avatarUrl == null) avatarUrl = ""; username = extras.getString(BUNDLE_PROFILE_USERNAME); profileUrl = extras.getString(BUNDLE_PROFILE_URL); @@ -129,25 +125,10 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment progressBar = findViewById(R.id.progressBar); - thumbnailView = findViewById(R.id.user_thumbnail); - if (!Objects.equals(thumbnailUrl, "")) + avatarView = findViewById(R.id.user_thumbnail); + if (!Objects.equals(avatarUrl, "")) //noinspection ConstantConditions - Picasso.with(this) - .load(thumbnailUrl) - .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) - .centerCrop() - .error(new IconicsDrawable(ProfileActivity.this) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(ProfileActivity.this, R.color.iron)) - .backgroundColor(ContextCompat.getColor(ProfileActivity.this, R.color.primary)) - .sizePx(THUMBNAIL_SIZE)) - .placeholder(new IconicsDrawable(ProfileActivity.this) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(ProfileActivity.this, R.color.iron)) - .backgroundColor(ContextCompat.getColor(ProfileActivity.this, R.color.primary)) - .sizePx(THUMBNAIL_SIZE)) - .transform(new CircleTransform()) - .into(thumbnailView); + loadAvatar(); usernameView = findViewById(R.id.profile_activity_username); usernameView.setTypeface(Typeface.createFromAsset(this.getAssets() , "fonts/fontawesome-webfont.ttf")); @@ -228,6 +209,19 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(false); } + private void loadAvatar(){ + Picasso.with(this) + .load(avatarUrl) + .fit() + .centerCrop() + .error(Objects.requireNonNull(ResourcesCompat.getDrawable(this.getResources() + , R.drawable.ic_default_user_avatar, null))) + .placeholder(Objects.requireNonNull(ResourcesCompat.getDrawable(this.getResources() + , R.drawable.ic_default_user_avatar, null))) + .transform(new CircleTransform()) + .into(avatarView); + } + /** * An {@link AsyncTask} that handles asynchronous fetching of a profile page and parsing this * user's personal text. The {@link Document} resulting from the parse is stored for use in @@ -243,7 +237,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment Spannable usernameSpan; Boolean isOnline = false; - public ProfileTask() { + ProfileTask() { super(ProfileActivity.this::onProfileTaskStarted, null); } @@ -257,9 +251,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment if (username == null || Objects.equals(username, "")) { username = contentsTable.select("tr").first().select("td").last().text(); } - if (thumbnailUrl == null || Objects.equals(thumbnailUrl, "")) { //Maybe there is an avatar + if (avatarUrl == null || Objects.equals(avatarUrl, "")) { //Maybe there is an avatar Element profileAvatar = profilePage.select("img.avatar").first(); - if (profileAvatar != null) thumbnailUrl = profileAvatar.attr("abs:src"); + if (profileAvatar != null) avatarUrl = profileAvatar.attr("abs:src"); } { //Finds personal text Element tmpEl = profilePage.select("td.windowbg:nth-child(2)").first(); @@ -280,14 +274,10 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment usernameSpan.setSpan(new RelativeSizeSpan(0.45f) , 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - if (contentsTable.toString().contains("Online") - || contentsTable.toString().contains("Συνδεδεμένος")) { - isOnline = true; - } else { - isOnline = false; - /*usernameSpan.setSpan(new ForegroundColorSpan(Color.GRAY) - , 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);*/ - } + /*usernameSpan.setSpan(new ForegroundColorSpan(Color.GRAY) + , 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);*/ + isOnline = contentsTable.toString().contains("Online") + || contentsTable.toString().contains("Συνδεδεμένος"); usernameSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#26A69A")) , 2, usernameSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } @@ -310,24 +300,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment } usernameView.setText(usernameSpan); } else if (usernameView.getText() != username) usernameView.setText(username); - if (thumbnailUrl != null && !Objects.equals(thumbnailUrl, "")) + if (avatarUrl != null && !Objects.equals(avatarUrl, "")) //noinspection ConstantConditions - Picasso.with(getApplicationContext()) - .load(thumbnailUrl) - .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) - .centerCrop() - .error(new IconicsDrawable(ProfileActivity.this) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(ProfileActivity.this, R.color.iron)) - .backgroundColor(ContextCompat.getColor(ProfileActivity.this, R.color.primary)) - .sizePx(THUMBNAIL_SIZE)) - .placeholder(new IconicsDrawable(ProfileActivity.this) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(ProfileActivity.this, R.color.iron)) - .backgroundColor(ContextCompat.getColor(ProfileActivity.this, R.color.primary)) - .sizePx(THUMBNAIL_SIZE)) - .transform(new CircleTransform()) - .into(thumbnailView); + loadAvatar(); if (personalText != null) { personalTextView.setText(personalText); personalTextView.setVisibility(View.VISIBLE); 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 d890a30a..577b272f 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 @@ -4,7 +4,6 @@ import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; -import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; @@ -41,8 +40,6 @@ import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarEntry; -import com.mikepenz.fontawesome_typeface_library.FontAwesome; -import com.mikepenz.iconics.IconicsDrawable; import com.squareup.picasso.Picasso; import java.util.ArrayList; @@ -53,7 +50,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.AppCompatButton; -import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.RecyclerView; @@ -92,7 +88,6 @@ class TopicAdapter extends RecyclerView.Adapter { /** * Int that holds thumbnail's size defined in R.dimen */ - private static int THUMBNAIL_SIZE; private final Context context; private final OnPostFocusChangeListener postFocusListener; private final IEmojiKeyboard emojiKeyboard; @@ -110,8 +105,6 @@ class TopicAdapter extends RecyclerView.Adapter { this.emojiKeyboard = emojiKeyboard; viewModel = ViewModelProviders.of(context).get(TopicViewModel.class); - - THUMBNAIL_SIZE = (int) context.getResources().getDimension(R.dimen.thumbnail_size); } @Override @@ -309,30 +302,8 @@ class TopicAdapter extends RecyclerView.Adapter { holder.post.setClickable(true); holder.post.setWebViewClient(new LinkLauncher()); - //Avoids errors about layout having 0 width/height - holder.thumbnail.setMinimumWidth(1); - holder.thumbnail.setMinimumHeight(1); - //Sets thumbnail size - holder.thumbnail.setMaxWidth(THUMBNAIL_SIZE); - holder.thumbnail.setMaxHeight(THUMBNAIL_SIZE); - //noinspection ConstantConditions - Picasso.with(context) - .load(currentPost.getThumbnailURL()) - .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) - .centerCrop() - .transform(new CircleTransform()) - .error(new IconicsDrawable(context) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(context, R.color.iron)) - .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) - .sizeDp(THUMBNAIL_SIZE)) - .placeholder(new IconicsDrawable(context) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(context, R.color.iron)) - .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) - .sizeDp(THUMBNAIL_SIZE)) - .into(holder.thumbnail); + loadAvatar(currentPost.getThumbnailURL(), holder.thumbnail); //Sets username,submit date, index number, subject, post's and attached files texts holder.username.setText(currentPost.getAuthor()); @@ -613,22 +584,8 @@ class TopicAdapter extends RecyclerView.Adapter { Post reply = (Post) topicItems.get(position); //noinspection ConstantConditions - Picasso.with(context) - .load(getSessionManager().getAvatarLink()) - .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) - .centerCrop() - .error(new IconicsDrawable(context) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(context, R.color.iron)) - .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) - .sizeDp(THUMBNAIL_SIZE)) - .placeholder(new IconicsDrawable(context) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(context, R.color.iron)) - .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) - .sizeDp(THUMBNAIL_SIZE)) - .transform(new CircleTransform()) - .into(holder.thumbnail); + loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail); + holder.username.setText(getSessionManager().getUsername()); holder.itemView.setAlpha(1f); holder.itemView.setEnabled(true); @@ -675,22 +632,8 @@ class TopicAdapter extends RecyclerView.Adapter { final EditMessageViewHolder holder = (EditMessageViewHolder) currentHolder; //noinspection ConstantConditions - Picasso.with(context) - .load(getSessionManager().getAvatarLink()) - .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) - .centerCrop() - .error(new IconicsDrawable(context) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(context, R.color.iron)) - .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) - .sizeDp(THUMBNAIL_SIZE)) - .placeholder(new IconicsDrawable(context) - .icon(FontAwesome.Icon.faw_user_circle) - .color(ContextCompat.getColor(context, R.color.iron)) - .backgroundColor(ContextCompat.getColor(context, R.color.primary_light)) - .sizeDp(THUMBNAIL_SIZE)) - .transform(new CircleTransform()) - .into(holder.thumbnail); + loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail); + holder.username.setText(getSessionManager().getUsername()); holder.editSubject.setText(currentPost.getSubject()); holder.editSubject.setRawInputType(InputType.TYPE_CLASS_TEXT); @@ -723,6 +666,19 @@ class TopicAdapter extends RecyclerView.Adapter { } } + private void loadAvatar(String imageUrl, ImageView imageView){ + Picasso.with(context) + .load(imageUrl) + .fit() + .centerCrop() + .error(Objects.requireNonNull(ResourcesCompat.getDrawable(context.getResources() + , R.drawable.ic_default_user_avatar_darker, null))) + .placeholder(Objects.requireNonNull(ResourcesCompat.getDrawable(context.getResources() + , R.drawable.ic_default_user_avatar_darker, null))) + .transform(new CircleTransform()) + .into(imageView); + } + @Override public int getItemCount() { return topicItems.size(); 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 ee81418c..75c7d081 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -455,7 +455,7 @@ public abstract class BaseActivity extends AppCompatActivity { private void setDefaultAvatar() { profileDrawerItem.withIcon(new IconicsDrawable(this) - .icon(FontAwesome.Icon.faw_user_circle) + .icon(FontAwesome.Icon.faw_user) .paddingDp(10) .color(ContextCompat.getColor(this, R.color.iron)) .backgroundColor(ContextCompat.getColor(this, R.color.primary_light))); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CircleTransform.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CircleTransform.java index 2294b83e..c6da6010 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CircleTransform.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CircleTransform.java @@ -20,11 +20,12 @@ public class CircleTransform implements Transformation { int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); - if (squaredBitmap != source) { + if (squaredBitmap != source) source.recycle(); - } - Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig()); + // For GIF images + Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; + Bitmap bitmap = Bitmap.createBitmap(size, size, config); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); diff --git a/app/src/main/res/drawable/ic_default_user_avatar.xml b/app/src/main/res/drawable/ic_default_user_avatar.xml new file mode 100644 index 00000000..aa4a9116 --- /dev/null +++ b/app/src/main/res/drawable/ic_default_user_avatar.xml @@ -0,0 +1,5 @@ + + + + diff --git a/app/src/main/res/drawable/ic_default_user_avatar_darker.xml b/app/src/main/res/drawable/ic_default_user_avatar_darker.xml new file mode 100644 index 00000000..44169fa1 --- /dev/null +++ b/app/src/main/res/drawable/ic_default_user_avatar_darker.xml @@ -0,0 +1,5 @@ + + + + diff --git a/app/src/main/res/layout-v21/activity_profile.xml b/app/src/main/res/layout-v21/activity_profile.xml index 00fc8430..3db974f5 100644 --- a/app/src/main/res/layout-v21/activity_profile.xml +++ b/app/src/main/res/layout-v21/activity_profile.xml @@ -35,12 +35,13 @@ diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml index 6218e2ff..5147852f 100644 --- a/app/src/main/res/layout-v21/activity_topic_post_row.xml +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -53,13 +53,12 @@ diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml index e5a935cf..5ca3cbbb 100644 --- a/app/src/main/res/layout/activity_profile.xml +++ b/app/src/main/res/layout/activity_profile.xml @@ -35,12 +35,13 @@ + app:srcCompat="@drawable/ic_default_user_avatar_darker" /> + app:srcCompat="@drawable/ic_default_user_avatar_darker" /> + app:srcCompat="@drawable/ic_default_user_avatar_darker" /> 6dp 12dp 16sp + 90dp From bab4847dca62da8e2170f68feae173bc8eadd24c Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sun, 11 Nov 2018 23:26:18 +0200 Subject: [PATCH 057/104] Avatar loading optimizations --- app/src/main/AndroidManifest.xml | 2 +- ...rkActivity.java => BookmarksActivity.java} | 28 ++++++++-------- ...gment.java => BookmarksBoardFragment.java} | 22 ++++++------- ...gment.java => BookmarksTopicFragment.java} | 32 +++++++++---------- .../activities/profile/ProfileActivity.java | 17 ++++++++++ .../gr/thmmy/mthmmy/base/BaseActivity.java | 6 ++-- .../main/res/layout-v21/activity_profile.xml | 2 +- .../layout-v21/activity_topic_post_row.xml | 1 - ...ty_bookmark.xml => activity_bookmarks.xml} | 0 app/src/main/res/layout/activity_profile.xml | 2 +- .../res/layout/activity_topic_edit_row.xml | 3 +- .../res/layout/activity_topic_post_row.xml | 3 +- .../layout/activity_topic_quick_reply_row.xml | 3 +- 13 files changed, 67 insertions(+), 54 deletions(-) rename app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/{BookmarkActivity.java => BookmarksActivity.java} (83%) rename app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/{BoardBookmarksFragment.java => BookmarksBoardFragment.java} (87%) rename app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/{TopicBookmarksFragment.java => BookmarksTopicFragment.java} (82%) rename app/src/main/res/layout/{activity_bookmark.xml => activity_bookmarks.xml} (100%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fb7c2b6a..7620bcf7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -124,7 +124,7 @@ android:value=".activities.upload.UploadActivity" />
    diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java similarity index 83% rename from app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java rename to app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java index 20ecfd28..0a65da94 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java @@ -27,11 +27,11 @@ import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; //TODO proper handling with adapter etc. //TODO after clicking bookmark and then back button should return to this activity -public class BookmarkActivity extends BaseActivity { +public class BookmarksActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_bookmark); + setContentView(R.layout.activity_bookmarks); //Initialize toolbar toolbar = findViewById(R.id.toolbar); @@ -47,8 +47,8 @@ public class BookmarkActivity extends BaseActivity { //Creates the adapter that will return a fragment for each section of the activity SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); - sectionsPagerAdapter.addFragment(TopicBookmarksFragment.newInstance(1, Bookmark.arrayToString(getTopicsBookmarked())), "Topics"); - sectionsPagerAdapter.addFragment(BoardBookmarksFragment.newInstance(2, Bookmark.arrayToString(getBoardsBookmarked())), "Boards"); + sectionsPagerAdapter.addFragment(BookmarksTopicFragment.newInstance(1, Bookmark.arrayToString(getTopicsBookmarked())), "Topics"); + sectionsPagerAdapter.addFragment(BookmarksBoardFragment.newInstance(2, Bookmark.arrayToString(getBoardsBookmarked())), "Boards"); //Sets up the ViewPager with the sections adapter. ViewPager viewPager = findViewById(R.id.bookmarks_container); @@ -66,8 +66,8 @@ public class BookmarkActivity extends BaseActivity { public boolean onTopicInteractionListener(String interactionType, Bookmark bookmarkedTopic) { switch (interactionType) { - case TopicBookmarksFragment.INTERACTION_CLICK_TOPIC_BOOKMARK: - Intent intent = new Intent(BookmarkActivity.this, TopicActivity.class); + case BookmarksTopicFragment.INTERACTION_CLICK_TOPIC_BOOKMARK: + Intent intent = new Intent(BookmarksActivity.this, TopicActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic=" + bookmarkedTopic.getId() + "." + 2147483647); @@ -75,11 +75,11 @@ public class BookmarkActivity extends BaseActivity { intent.putExtras(extras); startActivity(intent); break; - case TopicBookmarksFragment.INTERACTION_TOGGLE_TOPIC_NOTIFICATION: + case BookmarksTopicFragment.INTERACTION_TOGGLE_TOPIC_NOTIFICATION: return toggleNotification(bookmarkedTopic); - case TopicBookmarksFragment.INTERACTION_REMOVE_TOPIC_BOOKMARK: + case BookmarksTopicFragment.INTERACTION_REMOVE_TOPIC_BOOKMARK: removeBookmark(bookmarkedTopic); - Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(BookmarksActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); break; } return true; @@ -87,8 +87,8 @@ public class BookmarkActivity extends BaseActivity { public boolean onBoardInteractionListener(String interactionType, Bookmark bookmarkedBoard) { switch (interactionType) { - case BoardBookmarksFragment.INTERACTION_CLICK_BOARD_BOOKMARK: - Intent intent = new Intent(BookmarkActivity.this, BoardActivity.class); + case BookmarksBoardFragment.INTERACTION_CLICK_BOARD_BOOKMARK: + Intent intent = new Intent(BookmarksActivity.this, BoardActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_BOARD_URL, "https://www.thmmy.gr/smf/index.php?board=" + bookmarkedBoard.getId() + ".0"); @@ -96,11 +96,11 @@ public class BookmarkActivity extends BaseActivity { intent.putExtras(extras); startActivity(intent); break; - case BoardBookmarksFragment.INTERACTION_TOGGLE_BOARD_NOTIFICATION: + case BookmarksBoardFragment.INTERACTION_TOGGLE_BOARD_NOTIFICATION: return toggleNotification(bookmarkedBoard); - case BoardBookmarksFragment.INTERACTION_REMOVE_BOARD_BOOKMARK: + case BookmarksBoardFragment.INTERACTION_REMOVE_BOARD_BOOKMARK: removeBookmark(bookmarkedBoard); - Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(BookmarksActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); break; } return true; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksBoardFragment.java similarity index 87% rename from app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java rename to app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksBoardFragment.java index 913d2ce7..a73bbe6a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksBoardFragment.java @@ -22,10 +22,10 @@ import gr.thmmy.mthmmy.model.Bookmark; /** * A {@link Fragment} subclass. - * Use the {@link BoardBookmarksFragment#newInstance} factory method to + * Use the {@link BookmarksBoardFragment#newInstance} factory method to * create an instance of this fragment. */ -public class BoardBookmarksFragment extends Fragment { +public class BookmarksBoardFragment extends Fragment { private static final String ARG_SECTION_NUMBER = "SECTION_NUMBER"; private static final String ARG_BOARD_BOOKMARKS = "BOARD_BOOKMARKS"; @@ -39,7 +39,7 @@ public class BoardBookmarksFragment extends Fragment { private static Drawable notificationsDisabledButtonImage; // Required empty public constructor - public BoardBookmarksFragment() { } + public BookmarksBoardFragment() { } /** * Use ONLY this factory method to create a new instance of @@ -47,8 +47,8 @@ public class BoardBookmarksFragment extends Fragment { * * @return A new instance of fragment Forum. */ - public static BoardBookmarksFragment newInstance(int sectionNumber, String boardBookmarks) { - BoardBookmarksFragment fragment = new BoardBookmarksFragment(); + public static BookmarksBoardFragment newInstance(int sectionNumber, String boardBookmarks) { + BookmarksBoardFragment fragment = new BookmarksBoardFragment(); Bundle args = new Bundle(); args.putInt(ARG_SECTION_NUMBER, sectionNumber); args.putString(ARG_BOARD_BOOKMARKS, boardBookmarks); @@ -92,8 +92,8 @@ public class BoardBookmarksFragment extends Fragment { R.layout.fragment_bookmarks_row, bookmarksLinearView, false); row.setOnClickListener(view -> { Activity activity = getActivity(); - if (activity instanceof BookmarkActivity){ - ((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_CLICK_BOARD_BOOKMARK, bookmarkedBoard); + if (activity instanceof BookmarksActivity){ + ((BookmarksActivity) activity).onBoardInteractionListener(INTERACTION_CLICK_BOARD_BOOKMARK, bookmarkedBoard); } }); ((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedBoard.getTitle()); @@ -105,8 +105,8 @@ public class BoardBookmarksFragment extends Fragment { notificationsEnabledButton.setOnClickListener(view -> { Activity activity = getActivity(); - if (activity instanceof BookmarkActivity) { - if (((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_TOGGLE_BOARD_NOTIFICATION, bookmarkedBoard)) { + if (activity instanceof BookmarksActivity) { + if (((BookmarksActivity) activity).onBoardInteractionListener(INTERACTION_TOGGLE_BOARD_NOTIFICATION, bookmarkedBoard)) { notificationsEnabledButton.setImageDrawable(notificationsEnabledButtonImage); } else { notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); @@ -116,8 +116,8 @@ public class BoardBookmarksFragment extends Fragment { (row.findViewById(R.id.remove_bookmark)).setOnClickListener(view -> { Activity activity = getActivity(); - if (activity instanceof BookmarkActivity){ - ((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_REMOVE_BOARD_BOOKMARK, bookmarkedBoard); + if (activity instanceof BookmarksActivity){ + ((BookmarksActivity) activity).onBoardInteractionListener(INTERACTION_REMOVE_BOARD_BOOKMARK, bookmarkedBoard); boardBookmarks.remove(bookmarkedBoard); } row.setVisibility(View.GONE); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksTopicFragment.java similarity index 82% rename from app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java rename to app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksTopicFragment.java index 77992b2d..5c6232b7 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksTopicFragment.java @@ -22,16 +22,16 @@ import gr.thmmy.mthmmy.model.Bookmark; /** * A {@link Fragment} subclass. - * Use the {@link TopicBookmarksFragment#newInstance} factory method to + * Use the {@link BookmarksTopicFragment#newInstance} factory method to * create an instance of this fragment. */ -public class TopicBookmarksFragment extends Fragment { - protected static final String ARG_SECTION_NUMBER = "SECTION_NUMBER"; - protected static final String ARG_TOPIC_BOOKMARKS = "TOPIC_BOOKMARKS"; +public class BookmarksTopicFragment extends Fragment { + private static final String ARG_SECTION_NUMBER = "SECTION_NUMBER"; + private static final String ARG_TOPIC_BOOKMARKS = "TOPIC_BOOKMARKS"; - public static final String INTERACTION_CLICK_TOPIC_BOOKMARK = "CLICK_TOPIC_BOOKMARK"; - public static final String INTERACTION_TOGGLE_TOPIC_NOTIFICATION = "TOGGLE_TOPIC_NOTIFICATION"; - public static final String INTERACTION_REMOVE_TOPIC_BOOKMARK = "REMOVE_TOPIC_BOOKMARK"; + static final String INTERACTION_CLICK_TOPIC_BOOKMARK = "CLICK_TOPIC_BOOKMARK"; + static final String INTERACTION_TOGGLE_TOPIC_NOTIFICATION = "TOGGLE_TOPIC_NOTIFICATION"; + static final String INTERACTION_REMOVE_TOPIC_BOOKMARK = "REMOVE_TOPIC_BOOKMARK"; ArrayList topicBookmarks = null; @@ -39,7 +39,7 @@ public class TopicBookmarksFragment extends Fragment { private static Drawable notificationsDisabledButtonImage; // Required empty public constructor - public TopicBookmarksFragment() { + public BookmarksTopicFragment() { } /** @@ -48,8 +48,8 @@ public class TopicBookmarksFragment extends Fragment { * * @return A new instance of fragment Forum. */ - public static TopicBookmarksFragment newInstance(int sectionNumber, String topicBookmarks) { - TopicBookmarksFragment fragment = new TopicBookmarksFragment(); + public static BookmarksTopicFragment newInstance(int sectionNumber, String topicBookmarks) { + BookmarksTopicFragment fragment = new BookmarksTopicFragment(); Bundle args = new Bundle(); args.putInt(ARG_SECTION_NUMBER, sectionNumber); args.putString(ARG_TOPIC_BOOKMARKS, topicBookmarks); @@ -93,8 +93,8 @@ public class TopicBookmarksFragment extends Fragment { R.layout.fragment_bookmarks_row, bookmarksLinearView, false); row.setOnClickListener(view -> { Activity activity = getActivity(); - if (activity instanceof BookmarkActivity) { - ((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_CLICK_TOPIC_BOOKMARK, bookmarkedTopic); + if (activity instanceof BookmarksActivity) { + ((BookmarksActivity) activity).onTopicInteractionListener(INTERACTION_CLICK_TOPIC_BOOKMARK, bookmarkedTopic); } }); ((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedTopic.getTitle()); @@ -106,8 +106,8 @@ public class TopicBookmarksFragment extends Fragment { notificationsEnabledButton.setOnClickListener(view -> { Activity activity = getActivity(); - if (activity instanceof BookmarkActivity) { - if (((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_TOGGLE_TOPIC_NOTIFICATION, bookmarkedTopic)) { + if (activity instanceof BookmarksActivity) { + if (((BookmarksActivity) activity).onTopicInteractionListener(INTERACTION_TOGGLE_TOPIC_NOTIFICATION, bookmarkedTopic)) { notificationsEnabledButton.setImageDrawable(notificationsEnabledButtonImage); } else { notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); @@ -116,8 +116,8 @@ public class TopicBookmarksFragment extends Fragment { }); (row.findViewById(R.id.remove_bookmark)).setOnClickListener(view -> { Activity activity = getActivity(); - if (activity instanceof BookmarkActivity) { - ((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_REMOVE_TOPIC_BOOKMARK, bookmarkedTopic); + if (activity instanceof BookmarksActivity) { + ((BookmarksActivity) activity).onTopicInteractionListener(INTERACTION_REMOVE_TOPIC_BOOKMARK, bookmarkedTopic); topicBookmarks.remove(bookmarkedTopic); } row.setVisibility(View.GONE); 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 162ea1f6..db6d9238 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 @@ -129,6 +129,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment if (!Objects.equals(avatarUrl, "")) //noinspection ConstantConditions loadAvatar(); + else + loadDefaultAvatar(); usernameView = findViewById(R.id.profile_activity_username); usernameView.setTypeface(Typeface.createFromAsset(this.getAssets() , "fonts/fontawesome-webfont.ttf")); @@ -222,6 +224,19 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment .into(avatarView); } + private void loadDefaultAvatar(){ + Picasso.with(this) + .load(R.drawable.ic_default_user_avatar) + .fit() + .centerCrop() + .error(Objects.requireNonNull(ResourcesCompat.getDrawable(this.getResources() + , R.drawable.ic_default_user_avatar, null))) + .placeholder(Objects.requireNonNull(ResourcesCompat.getDrawable(this.getResources() + , R.drawable.ic_default_user_avatar, null))) + .transform(new CircleTransform()) + .into(avatarView); + } + /** * An {@link AsyncTask} that handles asynchronous fetching of a profile page and parsing this * user's personal text. The {@link Document} resulting from the parse is stored for use in @@ -303,6 +318,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment if (avatarUrl != null && !Objects.equals(avatarUrl, "")) //noinspection ConstantConditions loadAvatar(); + else + loadDefaultAvatar(); if (personalText != null) { personalTextView.setText(personalText); personalTextView.setVisibility(View.VISIBLE); 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 75c7d081..86b2e367 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -46,7 +46,7 @@ import androidx.preference.PreferenceManager; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.AboutActivity; import gr.thmmy.mthmmy.activities.LoginActivity; -import gr.thmmy.mthmmy.activities.bookmarks.BookmarkActivity; +import gr.thmmy.mthmmy.activities.bookmarks.BookmarksActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; @@ -380,8 +380,8 @@ public abstract class BaseActivity extends AppCompatActivity { // startActivity(intent); // } } else if (drawerItem.equals(BOOKMARKS_ID)) { - if (!(BaseActivity.this instanceof BookmarkActivity)) { - Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class); + if (!(BaseActivity.this instanceof BookmarksActivity)) { + Intent intent = new Intent(BaseActivity.this, BookmarksActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent); } diff --git a/app/src/main/res/layout-v21/activity_profile.xml b/app/src/main/res/layout-v21/activity_profile.xml index 3db974f5..c5da47d9 100644 --- a/app/src/main/res/layout-v21/activity_profile.xml +++ b/app/src/main/res/layout-v21/activity_profile.xml @@ -37,11 +37,11 @@ android:id="@+id/user_thumbnail" android:layout_width="@dimen/profile_activity_avatar_size" android:layout_height="@dimen/profile_activity_avatar_size" + android:layout_marginBottom="5dp" android:layout_gravity="center" android:adjustViewBounds="true" android:contentDescription="@string/post_thumbnail" android:fitsSystemWindows="true" - app:srcCompat="@drawable/ic_default_user_avatar" android:transitionName="user_thumbnail" app:layout_collapseMode="parallax"/> diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml index 5147852f..1cdb357c 100644 --- a/app/src/main/res/layout-v21/activity_topic_post_row.xml +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -58,7 +58,6 @@ android:layout_gravity="center" android:adjustViewBounds="true" android:contentDescription="@string/post_thumbnail" - app:srcCompat="@drawable/ic_default_user_avatar_darker" android:transitionName="user_thumbnail" /> diff --git a/app/src/main/res/layout/activity_bookmark.xml b/app/src/main/res/layout/activity_bookmarks.xml similarity index 100% rename from app/src/main/res/layout/activity_bookmark.xml rename to app/src/main/res/layout/activity_bookmarks.xml diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml index 5ca3cbbb..8a51cbd9 100644 --- a/app/src/main/res/layout/activity_profile.xml +++ b/app/src/main/res/layout/activity_profile.xml @@ -37,11 +37,11 @@ android:id="@+id/user_thumbnail" android:layout_width="@dimen/profile_activity_avatar_size" android:layout_height="@dimen/profile_activity_avatar_size" + android:layout_marginBottom="5dp" android:layout_gravity="center" android:adjustViewBounds="true" android:contentDescription="@string/post_thumbnail" android:fitsSystemWindows="true" - app:srcCompat="@drawable/ic_default_user_avatar" app:layout_collapseMode="parallax"/> + android:contentDescription="@string/post_thumbnail" /> + android:contentDescription="@string/post_thumbnail" /> + android:contentDescription="@string/post_thumbnail" /> Date: Mon, 12 Nov 2018 00:35:35 +0200 Subject: [PATCH 058/104] Voting chart & email deobfuscation improvements --- .../mthmmy/activities/topic/TopicAdapter.java | 4 +++- .../activities/topic/tasks/TopicTask.java | 6 ++---- .../activities/topic/tasks/TopicTaskResult.java | 8 ++++---- .../mthmmy/utils/parsing/ParseHelpers.java | 17 +++++++++++------ 4 files changed, 20 insertions(+), 15 deletions(-) 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 577b272f..cbf6f9d4 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 @@ -184,7 +184,7 @@ class TopicAdapter extends RecyclerView.Adapter { }); holder.submitButton.setVisibility(View.VISIBLE); // put a warning instead of a question - holder.question.setText("This topic contains a poll that is not supported in mthmmy"); + holder.question.setText("This topic contains a poll that is not supported in mTHMMY"); return; } @@ -788,6 +788,8 @@ class TopicAdapter extends RecyclerView.Adapter { hidePollResultsButton = itemView.findViewById(R.id.show_poll_options_button); errorTextview = itemView.findViewById(R.id.error_too_many_checked); voteChart = itemView.findViewById(R.id.vote_chart); + voteChart.setScaleEnabled(false); + voteChart.setTouchEnabled(false); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java index b711698a..a4aeef61 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java @@ -77,14 +77,12 @@ public class TopicTask extends AsyncTask { //Finds topic title if missing String topicTitle = topic.select("td[id=top_subject]").first().text(); - if (topicTitle.contains("Topic:")) { + if (topicTitle.contains("Topic:")) topicTitle = topicTitle.substring(topicTitle.indexOf("Topic:") + 7 , topicTitle.indexOf("(Read") - 2); - } else { + else topicTitle = topicTitle.substring(topicTitle.indexOf("Θέμα:") + 6 , topicTitle.indexOf("(Αναγνώστηκε") - 2); - Timber.d("Parsed title: %s", topicTitle); - } //Finds current page's index int currentPageIndex = TopicParser.parseCurrentPageIndex(topic, language); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java index 9381ada8..89d5cb5c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java @@ -37,10 +37,10 @@ public class TopicTaskResult { private final String topicTreeAndMods; private final String topicViewers; - public TopicTaskResult(TopicTask.ResultCode resultCode, String topicTitle, - String replyPageUrl, ArrayList newPostsList, int loadedPageTopicId, - int currentPageIndex, int pageCount, int focusedPostIndex, String topicTreeAndMods, - String topicViewers) { + TopicTaskResult(TopicTask.ResultCode resultCode, String topicTitle, + String replyPageUrl, ArrayList newPostsList, int loadedPageTopicId, + int currentPageIndex, int pageCount, int focusedPostIndex, String topicTreeAndMods, + String topicViewers) { this.resultCode = resultCode; this.topicTitle = topicTitle; this.replyPageUrl = replyPageUrl; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index 022d9896..fe5d2ac3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -200,22 +200,27 @@ public class ParseHelpers { */ public static Document parse(String html){ Document document = Jsoup.parse(html); - deobfuscateElements(document.select("span.__cf_email__"), true); + deobfuscateElements(document.select("span.__cf_email__,a.__cf_email__"), true); return document; } /** - * Use this method instead of parse() if you are targetting specific elements + * Use this method instead of parse() if you are targeting specific elements */ public static void deobfuscateElements(Elements elements, boolean found){ if(!found) - elements = elements.select("span.__cf_email__"); + elements = elements.select("span.__cf_email__,a.__cf_email__"); for (Element obfuscatedElement : elements) { String deobfuscatedEmail = deobfuscateEmail(obfuscatedElement.attr("data-cfemail")); - Element parent = obfuscatedElement.parent(); - if (parent.is("a")&&parent.attr("href").contains("email-protection")) - parent.attr("href", "mailto:"+deobfuscatedEmail); + if(obfuscatedElement.is("span")){ + Element parent = obfuscatedElement.parent(); + if (parent.is("a")&&parent.attr("href").contains("email-protection")) + parent.attr("href", "mailto:"+deobfuscatedEmail); + } + else if (obfuscatedElement.attr("href").contains("email-protection")) + obfuscatedElement.attr("href", "mailto:"+deobfuscatedEmail); + obfuscatedElement.replaceWith(new TextNode(deobfuscatedEmail, "")); } } From 51f6d14253caf50340d16093745c99cc73f94d89 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 12 Nov 2018 01:11:12 +0200 Subject: [PATCH 059/104] Mentions regex fix --- .../main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4ebbba5a..c2cdee07 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 @@ -37,7 +37,7 @@ import timber.log.Timber; public class TopicParser { private static Pattern mentionsPattern = Pattern. compile("
    \\n\\s+?(Quote from|Παράθεση από): " - + BaseActivity.getSessionManager().getUsername()); + + BaseActivity.getSessionManager().getUsername() +"\\s(στις|on)"); //User colors private static final int USER_COLOR_BLACK = Color.parseColor("#000000"); From f1ce09595ba93a364ce2cbf64c96e6583128a957 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Tue, 13 Nov 2018 01:38:17 +0200 Subject: [PATCH 060/104] Polls improvements --- .../mthmmy/activities/topic/TopicAdapter.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) 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 cbf6f9d4..8fcaaae6 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 @@ -191,13 +191,16 @@ class TopicAdapter extends RecyclerView.Adapter { holder.question.setText(poll.getQuestion()); holder.optionsLayout.removeAllViews(); holder.errorTextview.setVisibility(View.GONE); + + final int primaryTextColor = context.getResources().getColor(R.color.primary_text); + if (poll.getAvailableVoteCount() > 1) { for (Poll.Entry entry : entries) { LinearLayout container = new LinearLayout(context); container.setOrientation(LinearLayout.HORIZONTAL); CheckBox checkBox = new CheckBox(context); TextView label = new TextView(context); - label.setTextColor(context.getResources().getColor(R.color.primary_text)); + label.setTextColor(primaryTextColor); label.setMovementMethod(LinkMovementMethod.getInstance()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { label.setText(Html.fromHtml(entry.getEntryName(), Html.FROM_HTML_MODE_LEGACY)); @@ -206,7 +209,7 @@ class TopicAdapter extends RecyclerView.Adapter { label.setText(Html.fromHtml(entry.getEntryName())); } label.setText(ThmmyParser.html2span(context, entry.getEntryName())); - checkBox.setTextColor(context.getResources().getColor(R.color.primary_text)); + checkBox.setTextColor(primaryTextColor); container.addView(checkBox); container.addView(label); holder.optionsLayout.addView(container); @@ -226,7 +229,7 @@ class TopicAdapter extends RecyclerView.Adapter { radioButton.setText(Html.fromHtml(entries[i].getEntryName())); } radioButton.setText(ThmmyParser.html2span(context, entries[i].getEntryName())); - radioButton.setTextColor(context.getResources().getColor(R.color.primary_text)); + radioButton.setTextColor(primaryTextColor); radioGroup.addView(radioButton); } holder.optionsLayout.addView(radioGroup); @@ -239,27 +242,29 @@ class TopicAdapter extends RecyclerView.Adapter { for (int i = 0; i < entries.length; i++) { valuesToCompare.add(new BarEntry(i, entries[i].getVotes())); } - BarDataSet data = new BarDataSet(valuesToCompare, "Vote Results"); - data.setColor(context.getResources().getColor(R.color.accent)); + BarDataSet dataSet = new BarDataSet(valuesToCompare, "Vote Results"); + dataSet.setDrawValues(true); + dataSet.setColor(context.getResources().getColor(R.color.accent)); + dataSet.setValueTextColor(primaryTextColor); YAxis yAxisLeft = holder.voteChart.getAxisLeft(); yAxisLeft.setGranularity(1); - yAxisLeft.setTextColor(context.getResources().getColor(R.color.primary_text)); + yAxisLeft.setTextColor(primaryTextColor); yAxisLeft.setAxisMinimum(0); + yAxisLeft.setSpaceTop(30f); YAxis yAxisRight = holder.voteChart.getAxisRight(); yAxisRight.setEnabled(false); XAxis xAxis = holder.voteChart.getXAxis(); xAxis.setValueFormatter((value, axis) -> Html.fromHtml(entries[(int) value].getEntryName()).toString()); - xAxis.setTextColor(context.getResources().getColor(R.color.primary_text)); + xAxis.setTextColor(primaryTextColor); xAxis.setGranularity(1f); xAxis.setLabelCount(entries.length); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(false); - xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); + xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE); - BarData barData = new BarData(data); - barData.setValueTextColor(context.getResources().getColor(R.color.accent)); + BarData barData = new BarData(dataSet); holder.voteChart.setData(barData); holder.voteChart.getLegend().setEnabled(false); holder.voteChart.getDescription().setEnabled(false); @@ -790,6 +795,7 @@ class TopicAdapter extends RecyclerView.Adapter { voteChart = itemView.findViewById(R.id.vote_chart); voteChart.setScaleEnabled(false); voteChart.setTouchEnabled(false); + voteChart.setDrawValueAboveBar(false); } } From 92f4b062964c824e44e0f1a251df37be501fbb76 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Tue, 13 Nov 2018 14:20:29 +0200 Subject: [PATCH 061/104] Polls improvements again --- .../mthmmy/activities/topic/TopicAdapter.java | 30 +++++++++++++------ .../mthmmy/utils/parsing/ThmmyParser.java | 6 ++-- 2 files changed, 24 insertions(+), 12 deletions(-) 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 8fcaaae6..f0e7b572 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 @@ -42,6 +42,7 @@ import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarEntry; import com.squareup.picasso.Picasso; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -166,10 +167,13 @@ class TopicAdapter extends RecyclerView.Adapter { boolean pollSupported = true; for (Poll.Entry entry : entries) { - if (ThmmyParser.containsHtml(entry.getEntryName())) pollSupported = false; - break; + if (ThmmyParser.containsHtml(entry.getEntryName())){ + pollSupported = false; + break; + } } - if (ThmmyParser.containsHtml(poll.getQuestion())) pollSupported = false; + if (ThmmyParser.containsHtml(poll.getQuestion())) + pollSupported = false; if (!pollSupported) { holder.optionsLayout.setVisibility(View.GONE); holder.voteChart.setVisibility(View.GONE); @@ -193,6 +197,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.errorTextview.setVisibility(View.GONE); final int primaryTextColor = context.getResources().getColor(R.color.primary_text); + final int accentColor = context.getResources().getColor(R.color.accent); if (poll.getAvailableVoteCount() > 1) { for (Poll.Entry entry : entries) { @@ -239,19 +244,21 @@ class TopicAdapter extends RecyclerView.Adapter { //Showing results holder.optionsLayout.setVisibility(View.GONE); List valuesToCompare = new ArrayList<>(); + int totalVotes = 0; for (int i = 0; i < entries.length; i++) { valuesToCompare.add(new BarEntry(i, entries[i].getVotes())); + totalVotes += entries[i].getVotes(); } BarDataSet dataSet = new BarDataSet(valuesToCompare, "Vote Results"); dataSet.setDrawValues(true); - dataSet.setColor(context.getResources().getColor(R.color.accent)); - dataSet.setValueTextColor(primaryTextColor); + dataSet.setColor(accentColor); + dataSet.setValueTextColor(accentColor); YAxis yAxisLeft = holder.voteChart.getAxisLeft(); yAxisLeft.setGranularity(1); yAxisLeft.setTextColor(primaryTextColor); yAxisLeft.setAxisMinimum(0); - yAxisLeft.setSpaceTop(30f); + yAxisLeft.setSpaceTop(40f); YAxis yAxisRight = holder.voteChart.getAxisRight(); yAxisRight.setEnabled(false); @@ -265,6 +272,12 @@ class TopicAdapter extends RecyclerView.Adapter { xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE); BarData barData = new BarData(dataSet); + int finalSum = totalVotes; + barData.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> { + DecimalFormat format = new DecimalFormat("###.#%"); + double percentage = ((double) value / (double) finalSum); + return "" + (int) value + " (" + format.format(percentage) + ")"; + }); holder.voteChart.setData(barData); holder.voteChart.getLegend().setEnabled(false); holder.voteChart.getDescription().setEnabled(false); @@ -509,9 +522,9 @@ class TopicAdapter extends RecyclerView.Adapter { holder.overflowButton.setOnClickListener(view -> { //Inflates the popup menu content LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - if (layoutInflater == null) { + if (layoutInflater == null) return; - } + View popUpContent = layoutInflater.inflate(R.layout.activity_topic_overflow_menu, null); //Creates the PopupWindow @@ -795,7 +808,6 @@ class TopicAdapter extends RecyclerView.Adapter { voteChart = itemView.findViewById(R.id.vote_chart); voteChart.setScaleEnabled(false); voteChart.setTouchEnabled(false); - voteChart.setDrawValueAboveBar(false); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyParser.java index f900290f..cc47b140 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyParser.java @@ -162,7 +162,7 @@ public class ThmmyParser { return tags.toArray(new BBTag[0]); } - public static HtmlTag[] getHtmlTags(String html) { + private static HtmlTag[] getHtmlTags(String html) { Pattern htmlPattern = Pattern.compile("<(.+?)>"); LinkedList tags = new LinkedList<>(); @@ -205,11 +205,11 @@ public class ThmmyParser { return name.equals("b") || name.equals("i") || name.equals("span") || name.equals("del") || name.equals("a"); } - public static boolean isBBTagSupported(String name) { + private static boolean isBBTagSupported(String name) { return name.equals("b") || name.equals("i") || name.equals("u") || name.equals("s"); } - public static boolean isHtmlTag(String tagName) { + private static boolean isHtmlTag(String tagName) { for (String tag : ALL_HTML_TAGS) if (TextUtils.equals(tag, tagName)) return true; return false; From dd1fb88a947ff3998a8d2dcaa3a0d1095b8849cb Mon Sep 17 00:00:00 2001 From: Ezerous Date: Tue, 13 Nov 2018 21:30:04 +0200 Subject: [PATCH 062/104] More poll improvements --- .../thmmy/mthmmy/activities/topic/TopicAdapter.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 f0e7b572..efb0192e 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 @@ -44,6 +44,7 @@ import com.squareup.picasso.Picasso; import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -243,6 +244,7 @@ class TopicAdapter extends RecyclerView.Adapter { } else { //Showing results holder.optionsLayout.setVisibility(View.GONE); + Arrays.sort(entries, (p1, p2) -> p1.getVotes() - p2.getVotes()); List valuesToCompare = new ArrayList<>(); int totalVotes = 0; for (int i = 0; i < entries.length; i++) { @@ -250,7 +252,6 @@ class TopicAdapter extends RecyclerView.Adapter { totalVotes += entries[i].getVotes(); } BarDataSet dataSet = new BarDataSet(valuesToCompare, "Vote Results"); - dataSet.setDrawValues(true); dataSet.setColor(accentColor); dataSet.setValueTextColor(accentColor); @@ -281,9 +282,9 @@ class TopicAdapter extends RecyclerView.Adapter { holder.voteChart.setData(barData); holder.voteChart.getLegend().setEnabled(false); holder.voteChart.getDescription().setEnabled(false); - int chartHeightdp = 10 + 30 * entries.length; + int chartHeightDp = 10 + 30 * entries.length; DisplayMetrics metrics = context.getResources().getDisplayMetrics(); - holder.voteChart.setMinimumHeight((int) (chartHeightdp * (metrics.densityDpi / 160f))); + holder.voteChart.setMinimumHeight((int) (chartHeightDp * (metrics.densityDpi / 160f))); holder.voteChart.invalidate(); holder.voteChart.setVisibility(View.VISIBLE); } @@ -806,8 +807,8 @@ class TopicAdapter extends RecyclerView.Adapter { hidePollResultsButton = itemView.findViewById(R.id.show_poll_options_button); errorTextview = itemView.findViewById(R.id.error_too_many_checked); voteChart = itemView.findViewById(R.id.vote_chart); - voteChart.setScaleEnabled(false); - voteChart.setTouchEnabled(false); + voteChart.setScaleYEnabled(false); + voteChart.setDoubleTapToZoomEnabled(false); } } From 499241d5e2f5a99d6d20d11f972a2fb65c61a22b Mon Sep 17 00:00:00 2001 From: oogee Date: Wed, 14 Nov 2018 22:44:00 +0200 Subject: [PATCH 063/104] handle OTHER_ERROR on main activity tasks --- .../activities/main/forum/ForumFragment.java | 3 ++ .../main/recent/RecentFragment.java | 3 ++ .../main/unread/UnreadFragment.java | 3 ++ .../activities/topic/TopicActivity.java | 2 +- .../gr/thmmy/mthmmy/utils/CrashReporter.java | 34 +++++++++++++++++++ .../gr/thmmy/mthmmy/utils/NetworkTask.java | 9 +++++ .../mthmmy/utils/parsing/ParseHelpers.java | 22 ++++++++++++ 7 files changed, 75 insertions(+), 1 deletion(-) 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 782ffb71..d2ddcfb5 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 @@ -176,6 +176,9 @@ public class ForumFragment extends BaseFragment { forumAdapter.notifyParentDataSetChanged(false); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Unexpected error," + + " please contact the developers with the details", Toast.LENGTH_LONG).show(); } progressBar.setVisibility(ProgressBar.INVISIBLE); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 01f84261..c344213b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -148,6 +148,9 @@ public class RecentFragment extends BaseFragment { recentAdapter.notifyDataSetChanged(); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Unexpected error," + + " please contact the developers with the details", Toast.LENGTH_LONG).show(); } progressBar.setVisibility(ProgressBar.INVISIBLE); 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 76b595dd..7f5ed74a 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 @@ -180,6 +180,9 @@ public class UnreadFragment extends BaseFragment { swipeRefreshLayout.setRefreshing(false); if (resultCode == NetworkResultCodes.NETWORK_ERROR) Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error", Toast.LENGTH_SHORT).show(); + else + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Unexpected error," + + " please contact the developers with the details", Toast.LENGTH_LONG).show(); } } 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 6f1935b9..ddf48d9f 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 @@ -663,7 +663,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo progressBar.setVisibility(ProgressBar.GONE); switch (resultCode) { case SUCCESS: - Timber.i("Successfully loaded topic with URL %s", viewModel.getTopicUrl()); + Timber.i("Successfully loaded a topic"); paginationEnabled(true); break; case NETWORK_ERROR: diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java index 81b06769..8f16fdc4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java @@ -13,6 +13,40 @@ public class CrashReporter { private CrashReporter() {} + public static void reportForumInfo(Document document) { + ParseHelpers.Theme theme = ParseHelpers.parseTheme(document); + ParseHelpers.Language language = ParseHelpers.Language.getLanguage(document); + String themeKey = "forum theme", themeValue = null; + String languageKey = "forum language", languageValue = null; + switch (theme) { + case SCRIBBLES2: + themeValue = "Scribbles2"; + break; + case SMF_DEFAULT: + themeValue = "SMF Default Theme"; + break; + case SMFONE_BLUE: + themeValue = "SMFone_Blue"; + break; + case HELIOS_MULTI: + themeValue = "Helios_Multi"; + break; + case THEME_UNKNOWN: + themeValue = "Unknown theme"; + break; + } + switch (language) { + case GREEK: + languageValue = "Greek"; + break; + case ENGLISH: + languageValue = "English"; + break; + } + Crashlytics.setString(themeKey, themeValue); + Crashlytics.setString(languageKey, languageValue); + } + public static void reportDocument(Document document, String key) { String documentString = document.toString(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java index c61dbb72..524a4033 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java @@ -1,9 +1,14 @@ package gr.thmmy.mthmmy.utils; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; +import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.utils.parsing.ParseException; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; @@ -54,6 +59,10 @@ public abstract class NetworkTask extends ExternalAsyncTask return new Parcel<>(resultCode, data); } catch (ParseException pe) { Timber.e(pe); + SharedPreferences settingsPreferences = PreferenceManager.getDefaultSharedPreferences(BaseApplication.getInstance()); + if (settingsPreferences.getBoolean(BaseApplication.getInstance() + .getString(R.string.pref_privacy_crashlytics_enable_key), false)) + CrashReporter.reportForumInfo(Jsoup.parse(responseBodyString)); return new Parcel<>(NetworkResultCodes.PARSE_ERROR, null); } catch (Exception e) { Timber.e(e); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index fe5d2ac3..3d694da6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -92,6 +92,28 @@ public class ParseHelpers { } } + public enum Theme { + SCRIBBLES2, + SMF_DEFAULT, + SMFONE_BLUE, + HELIOS_MULTI, + THEME_UNKNOWN + } + + public static Theme parseTheme(Document page) { + Element stylesheet = page.select("link[rel=stylesheet]").first(); + if (stylesheet.attr("href").contains("scribbles2")) + return Theme.SCRIBBLES2; + else if (stylesheet.attr("href").contains("helios_multi")) + return Theme.HELIOS_MULTI; + else if (stylesheet.attr("href").contains("smfone")) + return Theme.SMFONE_BLUE; + else if (stylesheet.attr("href").contains("default")) + return Theme.SMF_DEFAULT; + else + return Theme.THEME_UNKNOWN; + } + /** * An enum describing the state of a forum page by defining the types:
      *
    • {@link #UNAUTHORIZED_OR_MISSING}
    • From a8762d66298e6c8d52235ab230a3b78c01e8e7cd Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 15 Nov 2018 11:17:42 +0200 Subject: [PATCH 064/104] cleanup --- .../mthmmy/activities/topic/TopicParser.java | 12 ++++---- .../gr/thmmy/mthmmy/utils/CrashReporter.java | 5 +++- .../mthmmy/utils/parsing/ParseHelpers.java | 28 +------------------ 3 files changed, 11 insertions(+), 34 deletions(-) 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 c2cdee07..f383793e 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 @@ -59,7 +59,7 @@ public class TopicParser { * @see org.jsoup.Jsoup Jsoup */ public static String parseUsersViewingThisTopic(Document topic, ParseHelpers.Language language) { - if (language.is(ParseHelpers.Language.GREEK)) + if (language == ParseHelpers.Language.GREEK) return topic.select("td:containsOwn(διαβάζουν αυτό το θέμα)").first().html(); return topic.select("td:containsOwn(are viewing this topic)").first().html(); } @@ -77,7 +77,7 @@ public class TopicParser { public static int parseCurrentPageIndex(Document topic, ParseHelpers.Language language) { int parsedPage = 1; - if (language.is(ParseHelpers.Language.GREEK)) { + if (language == ParseHelpers.Language.GREEK) { Elements findCurrentPage = topic.select("td:contains(Σελίδες:)>b"); for (Element item : findCurrentPage) { @@ -115,7 +115,7 @@ public class TopicParser { public static int parseTopicNumberOfPages(Document topic, int currentPage, ParseHelpers.Language language) { int returnPages = 1; - if (language.is(ParseHelpers.Language.GREEK)) { + if (language == ParseHelpers.Language.GREEK) { Elements pages = topic.select("td:contains(Σελίδες:)>a.navPages"); if (pages.size() != 0) { @@ -163,7 +163,7 @@ public class TopicParser { Elements postRows; //Each row is a post - if (language.is(ParseHelpers.Language.GREEK)) + if (language == ParseHelpers.Language.GREEK) postRows = topic.select("form[id=quickModForm]>table>tbody>tr:matches(στις)"); else { postRows = topic.select("form[id=quickModForm]>table>tbody>tr:matches(on)"); @@ -236,7 +236,7 @@ public class TopicParser { //Language dependent parsing Element userName; - if (language.is(ParseHelpers.Language.GREEK)) { + if (language == ParseHelpers.Language.GREEK) { //Finds username and profile's url userName = thisRow.select("a[title^=Εμφάνιση προφίλ του μέλους]").first(); if (userName == null) { //Deleted profile @@ -388,7 +388,7 @@ public class TopicParser { Element usersExtraInfo = userName.parent().nextElementSibling(); //Get sibling "div" List infoList = Arrays.asList(usersExtraInfo.html().split("
      ")); - if (language.is(ParseHelpers.Language.GREEK)) { + if (language == ParseHelpers.Language.GREEK) { for (String line : infoList) { if (line.contains("Μηνύματα:")) { postsLineIndex = infoList.indexOf(line); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java index 8f16fdc4..b9907e93 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java @@ -6,6 +6,7 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; +import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; public class CrashReporter { @@ -43,8 +44,10 @@ public class CrashReporter { languageValue = "English"; break; } + Crashlytics.setString(themeKey, themeValue); Crashlytics.setString(languageKey, languageValue); + Crashlytics.setBool("isLoggedIn", BaseApplication.getInstance().getSessionManager().isLoggedIn()); } public static void reportDocument(Document document, String key) { @@ -52,7 +55,7 @@ public class CrashReporter { ParseHelpers.Language language = ParseHelpers.Language.getLanguage(document); Elements postRows; - if (language.is(ParseHelpers.Language.GREEK)) + if (language == ParseHelpers.Language.GREEK) postRows = document.select("form[id=quickModForm]>table>tbody>tr:matches(στις)"); else postRows = document.select("form[id=quickModForm]>table>tbody>tr:matches(on)"); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index 3d694da6..976ff387 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -18,18 +18,12 @@ import timber.log.Timber; * and obfuscated emails. */ public class ParseHelpers { - /** - * Debug Tag for logging debug output to LogCat - */ - @SuppressWarnings("unused") - private static final String TAG = "ParseHelpers"; /** * An enum describing a forum page's language by defining the types:
        *
      • {@link #PAGE_INCOMPLETE}
      • *
      • {@link #UNDEFINED_LANGUAGE}
      • *
      • {@link #ENGLISH}
      • - *
      • {@link #ENGLISH_GUEST}
      • *
      • {@link #GREEK}
      • *
      */ @@ -42,10 +36,6 @@ public class ParseHelpers { * Page language is english. */ ENGLISH, - /** - * Page language is english and the user is guest. - */ - ENGLISH_GUEST, /** * Page is incomplete. Data are not enough to determine the language. */ @@ -67,29 +57,13 @@ public class ParseHelpers { if (welcoming == null) { Element welcomingGuest = page.select("div[id=myuser]").first(); if (welcomingGuest != null) { - if (welcomingGuest.text().contains("Welcome")) return ENGLISH_GUEST; + if (welcomingGuest.text().contains("Welcome")) return ENGLISH; } return PAGE_INCOMPLETE; } else if (welcoming.text().contains("Καλώς ορίσατε")) return GREEK; else if (welcoming.text().contains("Hey")) return ENGLISH; else return UNDEFINED_LANGUAGE; } - - /** - * This method defines a custom equality check for {@link Language} enums. - *

      Method returns true if parameter's Target is the same as the object and in the specific - * cases described below, false otherwise.

      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 6da2b530..849067f2 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 @@ -651,12 +651,11 @@ class TopicAdapter extends RecyclerView.Adapter { if (reply.getContent() != null) replyText += reply.getContent(); else { - if (viewModel.getBuildedQuotes() != null && !viewModel.getBuildedQuotes().isEmpty()) - replyText += viewModel.getBuildedQuotes(); SharedPreferences drafts = context.getSharedPreferences(context.getString(R.string.pref_topic_drafts_key), Context.MODE_PRIVATE); replyText += drafts.getString(String.valueOf(viewModel.getTopicId()), ""); - + if (viewModel.getBuildedQuotes() != null && !viewModel.getBuildedQuotes().isEmpty()) + replyText += viewModel.getBuildedQuotes(); } holder.replyEditor.setText(replyText); holder.replyEditor.getEditText().setSelection(holder.replyEditor.getText().length()); diff --git a/app/src/main/res/layout/activity_topic_edit_row.xml b/app/src/main/res/layout/activity_topic_edit_row.xml index 5140d584..3c29ae33 100644 --- a/app/src/main/res/layout/activity_topic_edit_row.xml +++ b/app/src/main/res/layout/activity_topic_edit_row.xml @@ -1,6 +1,5 @@ Date: Tue, 20 Nov 2018 22:08:47 +0200 Subject: [PATCH 071/104] draft fixes --- .../mthmmy/activities/topic/TopicActivity.java | 15 ++++++--------- .../mthmmy/activities/topic/TopicAdapter.java | 4 ++-- .../main/java/gr/thmmy/mthmmy/model/Post.java | 12 ++++++++++-- .../thmmy/mthmmy/viewmodel/TopicViewModel.java | 17 ----------------- 4 files changed, 18 insertions(+), 30 deletions(-) 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 ead5b63e..af4586c1 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 @@ -274,9 +274,8 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo } else if (viewModel.isWritingReply()) { // persist reply SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); - Editable cachedReply = viewModel.getCachedReply(); - if (cachedReply != null) - drafts.edit().putString(String.valueOf(viewModel.getTopicId()), cachedReply.toString()).apply(); + Post reply = (Post) topicItems.get(topicItems.size() - 1); + drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply(); topicItems.remove(topicItems.size() - 1); topicAdapter.notifyItemRemoved(topicItems.size()); @@ -317,9 +316,8 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo // persist reply if (viewModel.isWritingReply()) { SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); - Editable cachedReply = viewModel.getCachedReply(); - if (cachedReply != null) - drafts.edit().putString(String.valueOf(viewModel.getTopicId()), cachedReply.toString()).apply(); + Post reply = (Post) topicItems.get(topicItems.size() - 1); + drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply(); } } @@ -536,11 +534,10 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo break; case NEW_REPLY_WHILE_POSTING: Timber.i("New reply while writing a reply"); - Editable subject = viewModel.getCachedSubject(); - Editable message = viewModel.getCachedReply(); + Post reply = (Post) topicItems.get(topicItems.size() - 1); Runnable addReply = () -> { viewModel.setWritingReply(true); - topicItems.add(Post.newQuickReply(subject.toString(), message.toString())); + topicItems.add(Post.newQuickReply(reply.getSubject(), reply.getContent())); topicAdapter.notifyItemInserted(topicItems.size()); recyclerView.scrollToPosition(topicItems.size() - 1); replyFAB.hide(); 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 849067f2..bb8bdeb2 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 @@ -672,7 +672,7 @@ class TopicAdapter extends RecyclerView.Adapter { @Override public void afterTextChanged(Editable editable) { - viewModel.setCachedReply(editable); + ((Post) topicItems.get(holder.getAdapterPosition())).setContent(editable.toString()); } }); @@ -693,7 +693,7 @@ class TopicAdapter extends RecyclerView.Adapter { @Override public void afterTextChanged(Editable editable) { - viewModel.setCachedSubject(editable); + ((Post) topicItems.get(holder.getAdapterPosition())).setSubject(editable.toString()); } }); } else if (currentHolder instanceof EditMessageViewHolder) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java index da68d1e6..9560ef49 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java @@ -23,8 +23,8 @@ public class Post extends TopicItem { //Standard info (exists in every post) private final String thumbnailUrl; private final String author; - private final String subject; - private final String content; + private String subject; + private String content; private final int postIndex; private final int postNumber; private final String postDate; @@ -408,4 +408,12 @@ public class Post extends TopicItem { public void setPostType(int postType) { this.postType = postType; } + + public void setContent(String content) { + this.content = content; + } + + public void setSubject(String subject) { + this.subject = subject; + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index a4816479..5663fe5b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -41,7 +41,6 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa */ private boolean editingPost = false; private boolean writingReply = false; - private Editable cachedSubject, cachedReply; /** * A list of {@link Post#getPostIndex()} for building quotes for replying */ @@ -488,20 +487,4 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa throw new NullPointerException("No page has been loaded yet!"); return topicItems.getValue().size(); } - - public Editable getCachedSubject() { - return cachedSubject; - } - - public void setCachedSubject(Editable cachedSubject) { - this.cachedSubject = cachedSubject; - } - - public Editable getCachedReply() { - return cachedReply; - } - - public void setCachedReply(Editable cachedReply) { - this.cachedReply = cachedReply; - } } From 894381a33c3e6b1cb1c34a1d041606519f00dd0e Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 21 Nov 2018 13:52:28 +0200 Subject: [PATCH 072/104] Remove saved drafts when logging out --- app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java | 3 ++- .../main/java/gr/thmmy/mthmmy/session/SessionManager.java | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 0c0eda0e..407409d9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -72,6 +72,7 @@ public class BaseApplication extends Application { //Shared Preferences SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE); SharedPreferences settingsSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); + SharedPreferences draftsPrefs = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); if (settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_crashlytics_enable_key), false)) startFirebaseCrashlyticsCollection(); @@ -106,7 +107,7 @@ public class BaseApplication extends Application { .writeTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .build(); - sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs); + sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs,draftsPrefs); Picasso picasso = new Picasso.Builder(getApplicationContext()) .downloader(new OkHttp3Downloader(client)) .build(); 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 4121c1de..42f02375 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -57,6 +57,7 @@ public class SessionManager { //Shared Preferences & its keys private final SharedPreferences sharedPrefs; + private final SharedPreferences draftsPrefs; private static final String USERNAME = "Username"; private static final String USER_ID = "UserID"; private static final String AVATAR_LINK = "AvatarLink"; @@ -67,11 +68,12 @@ public class SessionManager { //Constructor public SessionManager(OkHttpClient client, PersistentCookieJar cookieJar, - SharedPrefsCookiePersistor cookiePersistor, SharedPreferences sharedPrefs) { + SharedPrefsCookiePersistor cookiePersistor, SharedPreferences sharedPrefs, SharedPreferences draftsPrefs) { this.client = client; this.cookiePersistor = cookiePersistor; this.cookieJar = cookieJar; this.sharedPrefs = sharedPrefs; + this.draftsPrefs = draftsPrefs; } //------------------------------------AUTH BEGINS---------------------------------------------- @@ -309,6 +311,7 @@ public class SessionManager { sharedPrefs.edit().putString(USERNAME, guestName).apply(); sharedPrefs.edit().putInt(USER_ID, -1).apply(); sharedPrefs.edit().putBoolean(LOGGED_IN, false).apply(); //User logs out + draftsPrefs.edit().clear().apply(); //Clear saved drafts Timber.i("Session data cleared."); } From 4e5e61692a601750b8bc0821b3b0e3f4d4396840 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 21 Nov 2018 16:09:08 +0200 Subject: [PATCH 073/104] Up OkHttp, Google services --- app/build.gradle | 2 +- app/src/main/assets/apache_libraries.html | 2 +- .../java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java | 1 - app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java | 4 +--- .../main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java | 1 - build.gradle | 2 +- 6 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6714fc8c..85f9bba6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -66,7 +66,7 @@ dependencies { implementation 'com.google.firebase:firebase-core:16.0.5' implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.6' - implementation 'com.squareup.okhttp3:okhttp:3.11.0' + implementation 'com.squareup.okhttp3:okhttp:3.12.0' implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' implementation 'org.jsoup:jsoup:1.10.3' //TODO: Warning: upgrading from 1.10.3 will break stuff! diff --git a/app/src/main/assets/apache_libraries.html b/app/src/main/assets/apache_libraries.html index b8a4c500..360546d4 100644 --- a/app/src/main/assets/apache_libraries.html +++ b/app/src/main/assets/apache_libraries.html @@ -39,7 +39,7 @@
      • -
        OkHttp v3.11.0 (Copyright ©2016 Square, Inc.)
        +
        OkHttp v3.12.0 (Copyright ©2016 Square, Inc.)
      • Picasso v2.5.2 (Copyright ©2013 Square, Inc.)
        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 af4586c1..619e0e12 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 @@ -10,7 +10,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import android.text.Editable; import android.text.Spannable; import android.text.SpannableString; import android.text.SpannableStringBuilder; 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 407409d9..7f0caa7e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -103,9 +103,7 @@ public class BaseApplication extends Application { } return chain.proceed(request); }) - .connectTimeout(30, TimeUnit.SECONDS) - .writeTimeout(30, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + .callTimeout(30, TimeUnit.SECONDS) .build(); sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs,draftsPrefs); Picasso picasso = new Picasso.Builder(getApplicationContext()) diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index 5663fe5b..eebd1ad6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.AsyncTask; import android.preference.PreferenceManager; -import android.text.Editable; import android.widget.CheckBox; import android.widget.LinearLayout; import android.widget.RadioGroup; diff --git a/build.gradle b/build.gradle index f222f5bf..98ef0687 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' - classpath 'com.google.gms:google-services:4.1.0' + classpath 'com.google.gms:google-services:4.2.0' classpath 'io.fabric.tools:gradle:1.26.1' classpath 'org.ajoberstar.grgit:grgit-core:3.0.0' } From 5acaea6dce96c6d17b2db3c9c96a64490519b8f7 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Wed, 21 Nov 2018 21:43:51 +0200 Subject: [PATCH 074/104] Kitkat specific fixes --- .../mthmmy/activities/main/MainActivity.java | 9 +++++ .../gr/thmmy/mthmmy/base/BaseActivity.java | 18 ++++----- .../gr/thmmy/mthmmy/base/BaseApplication.java | 39 ++++++++++++++----- 3 files changed, 48 insertions(+), 18 deletions(-) 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 85cb4a9c..efd323ef 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 @@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.activities.main; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.widget.Toast; @@ -11,6 +12,7 @@ import com.google.android.material.tabs.TabLayout; import java.util.ArrayList; import java.util.List; +import androidx.appcompat.app.AppCompatDelegate; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; @@ -54,6 +56,13 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF private ViewPager viewPager; private TabLayout tabLayout; + //Fix for vector drawables on android <21 + static { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); + } + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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 86b2e367..74dda5ee 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -118,7 +118,7 @@ public abstract class BaseActivity extends AppCompatActivity { loadSavedBookmarks(); } - sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); BaseViewModel baseViewModel = ViewModelProviders.of(this).get(BaseViewModel.class); baseViewModel.getCurrentPageBookmark().observe(this, thisPageBookmark -> setTopicBookmark(thisPageBookmarkMenuButton)); @@ -128,7 +128,7 @@ public abstract class BaseActivity extends AppCompatActivity { protected void onResume() { super.onResume(); updateDrawer(); - if(!sharedPreferences.getBoolean(getString(R.string.user_consent_shared_preference_key),false)) + if (!sharedPreferences.getBoolean(getString(R.string.user_consent_shared_preference_key), false)) showUserConsentDialog(); } @@ -646,7 +646,7 @@ public abstract class BaseActivity extends AppCompatActivity { FirebaseMessaging.getInstance().unsubscribeFromTopic(bookmark.getId()); return topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).isNotificationsEnabled(); - } else if (bookmark.matchExists(boardsBookmarked)) { + } else if (bookmark.matchExists(boardsBookmarked)) { boardsBookmarked.get(bookmark.findIndex(boardsBookmarked)).toggleNotificationsEnabled(); updateBoardBookmarks(); @@ -760,7 +760,7 @@ public abstract class BaseActivity extends AppCompatActivity { } //----------------------------PRIVACY POLICY------------------ - private void showUserConsentDialog(){ + private void showUserConsentDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle); builder.setTitle("User Agreement"); builder.setMessage(R.string.user_agreement_dialog_text); @@ -788,7 +788,7 @@ public abstract class BaseActivity extends AppCompatActivity { protected void showPrivacyPolicyDialog() { TextView privacyPolicyTextView = new TextView(this); - privacyPolicyTextView.setPadding(30,20,30,20); + privacyPolicyTextView.setPadding(30, 20, 30, 20); privacyPolicyTextView.setTextColor(ContextCompat.getColor(this, R.color.primary_text)); SpannableConfiguration configuration = SpannableConfiguration.builder(this).linkResolver(new LinkResolverDef()).build(); StringBuilder stringBuilder = new StringBuilder(); @@ -812,7 +812,7 @@ public abstract class BaseActivity extends AppCompatActivity { Timber.e(e, "Error in Privacy Policy dialog."); } finally { try { - if(reader!=null) + if (reader != null) reader.close(); } catch (IOException e) { Timber.e(e, "Error in Privacy Policy dialog (closing reader)."); @@ -820,12 +820,12 @@ public abstract class BaseActivity extends AppCompatActivity { } } - private void addUserConsent(){ + private void addUserConsent() { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean(getString(R.string.user_consent_shared_preference_key), true).apply(); } - private void setUserDataShareEnabled(boolean enabled){ + private void setUserDataShareEnabled(boolean enabled) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean(getString(R.string.pref_privacy_crashlytics_enable_key), enabled).apply(); editor.putBoolean(getString(R.string.pref_privacy_analytics_enable_key), enabled).apply(); @@ -836,7 +836,7 @@ public abstract class BaseActivity extends AppCompatActivity { this.mainActivity = mainActivity; } - private void startLoginActivity(){ + private void startLoginActivity() { Intent intent = new Intent(BaseActivity.this, LoginActivity.class); startActivity(intent); overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); 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 7f0caa7e..42e907b8 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.util.DisplayMetrics; import android.widget.ImageView; @@ -25,6 +26,9 @@ import com.squareup.picasso.Picasso; import net.gotev.uploadservice.UploadService; import net.gotev.uploadservice.okhttp.OkHttpStack; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -35,6 +39,8 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.utils.CrashReportingTree; import io.fabric.sdk.android.Fabric; +import okhttp3.CipherSuite; +import okhttp3.ConnectionSpec; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -82,14 +88,14 @@ public class BaseApplication extends Application { firebaseAnalytics = FirebaseAnalytics.getInstance(this); boolean enableAnalytics = settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_analytics_enable_key), false); firebaseAnalytics.setAnalyticsCollectionEnabled(enableAnalytics); - if(enableAnalytics) + if (enableAnalytics) Timber.i("Starting app with Analytics enabled."); else Timber.i("Starting app with Analytics disabled."); SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); - client = new OkHttpClient.Builder() + OkHttpClient.Builder builder = new OkHttpClient.Builder() .cookieJar(cookieJar) .addInterceptor(chain -> { Request request = chain.request(); @@ -103,9 +109,25 @@ public class BaseApplication extends Application { } return chain.proceed(request); }) - .callTimeout(30, TimeUnit.SECONDS) - .build(); - sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs,draftsPrefs); + .callTimeout(30, TimeUnit.SECONDS); + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Just for KitKats + // Necessary because our servers don't have the right cipher suites. + // https://github.com/square/okhttp/issues/4053 + List cipherSuites = new ArrayList<>(ConnectionSpec.MODERN_TLS.cipherSuites()); + cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA); + cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA); + + ConnectionSpec legacyTls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) + .cipherSuites(cipherSuites.toArray(new CipherSuite[0])) + .build(); + + builder.connectionSpecs(Arrays.asList(legacyTls, ConnectionSpec.CLEARTEXT)); + } + + client = builder.build(); + + sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs, draftsPrefs); Picasso picasso = new Picasso.Builder(getApplicationContext()) .downloader(new OkHttp3Downloader(client)) .build(); @@ -170,13 +192,13 @@ public class BaseApplication extends Application { public void setFirebaseAnalyticsCollection(boolean enabled) { firebaseAnalytics.setAnalyticsCollectionEnabled(enabled); - if(!enabled) + if (!enabled) firebaseAnalytics.resetAnalyticsData(); } // Set up Crashlytics, disabled for debug builds public void startFirebaseCrashlyticsCollection() { - if(!Fabric.isInitialized()){ + if (!Fabric.isInitialized()) { Crashlytics crashlyticsKit = new Crashlytics.Builder() .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()) .build(); @@ -184,8 +206,7 @@ public class BaseApplication extends Application { Fabric.with(this, crashlyticsKit); Timber.plant(new CrashReportingTree()); Timber.i("Crashlytics enabled."); - } - else + } else Timber.i("Crashlytics were already initialized for this app session."); } } From 2300e86b64dd3ca5328230dea861f1e6e7d960b3 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 22 Nov 2018 14:00:09 +0200 Subject: [PATCH 075/104] UnreadFragment possible fixes --- .../mthmmy/activities/main/MainActivity.java | 24 +++--- .../main/recent/RecentFragment.java | 8 +- .../main/unread/UnreadFragment.java | 76 ++++++++++--------- .../thmmy/mthmmy/utils/ExternalAsyncTask.java | 4 + 4 files changed, 61 insertions(+), 51 deletions(-) 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 efd323ef..a9842f9c 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 @@ -100,12 +100,11 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); int preferredTab = Integer.parseInt(sharedPrefs.getString(SettingsActivity.DEFAULT_HOME_TAB, "0")); - if ((preferredTab != 3 && preferredTab != 4) || sessionManager.isLoggedIn()) { + if ((preferredTab != 3 && preferredTab != 4) || sessionManager.isLoggedIn()) tabLayout.getTabAt(preferredTab).select(); - } - for (int i = 0; i < tabLayout.getTabCount(); i++) { + + for (int i = 0; i < tabLayout.getTabCount(); i++) updateTabIcon(i); - } setMainActivity(this); } @@ -196,6 +195,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF } void removeFragment(int position) { + getSupportFragmentManager().beginTransaction().remove(fragmentList.get(position)).commit(); fragmentList.remove(position); fragmentTitleList.remove(position); notifyDataSetChanged(); @@ -228,25 +228,23 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF public void updateTabIcon(int position) { if (position >= tabLayout.getTabCount()) return; - if (position == 0) { + if (position == 0) tabLayout.getTabAt(0).setIcon(getResources().getDrawable(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)); - } else if (position == 2) { + else if (position == 2) tabLayout.getTabAt(2).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp)); - } } public void updateTabs() { - if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3) { + if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3) sectionsPagerAdapter.removeFragment(2); - } else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) { + else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); - } - for (int i = 0; i < tabLayout.getTabCount(); i++) { + + for (int i = 0; i < tabLayout.getTabCount(); i++) updateTabIcon(i); - } } //-------------------------------FragmentPagerAdapter END------------------------------------------- diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index c344213b..1ecbd360 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -114,7 +114,7 @@ public class RecentFragment extends BaseFragment { swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.primary); swipeRefreshLayout.setColorSchemeResources(R.color.accent); swipeRefreshLayout.setOnRefreshListener(() -> { - if (recentTask != null && recentTask.getStatus() != AsyncTask.Status.RUNNING) { + if (!recentTask.isRunning()) { recentTask = new RecentTask(this::onRecentTaskStarted, this::onRecentTaskFinished); recentTask.execute(SessionManager.indexUrl.toString()); } @@ -128,7 +128,7 @@ public class RecentFragment extends BaseFragment { @Override public void onDestroy() { super.onDestroy(); - if (recentTask != null && recentTask.getStatus() != AsyncTask.Status.RUNNING) + if (recentTask.isRunning()) recentTask.cancel(true); } @@ -160,8 +160,8 @@ public class RecentFragment extends BaseFragment { //---------------------------------------ASYNC TASK----------------------------------- private class RecentTask extends NewParseTask> { - public RecentTask(OnTaskStartedListener onTaskStartedListener, - OnNetworkTaskFinishedListener> onParseTaskFinishedListener) { + RecentTask(OnTaskStartedListener onTaskStartedListener, + OnNetworkTaskFinishedListener> onParseTaskFinishedListener) { super(onTaskStartedListener, onParseTaskFinishedListener); } 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 7f5ed74a..6f0cc15d 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 @@ -1,3 +1,4 @@ + package gr.thmmy.mthmmy.activities.main.unread; import android.os.AsyncTask; @@ -59,8 +60,7 @@ public class UnreadFragment extends BaseFragment { private MarkReadTask markReadTask; // Required empty public constructor - public UnreadFragment() { - } + public UnreadFragment() {} /** * Use ONLY this factory method to create a new instance of @@ -107,11 +107,11 @@ public class UnreadFragment extends BaseFragment { progressBar = rootView.findViewById(R.id.progressBar); unreadAdapter = new UnreadAdapter(topicSummaries, fragmentInteractionListener, markReadLinkUrl -> { - if (markReadTask != null && markReadTask.getStatus() != AsyncTask.Status.RUNNING) { - markReadTask = new MarkReadTask(); - markReadTask.execute(markReadLinkUrl); - } - }); + if (!markReadTask.isRunning() && !unreadTask.isRunning()) { + markReadTask = new MarkReadTask(); + markReadTask.execute(markReadLinkUrl); + } + }); CustomRecyclerView recyclerView = rootView.findViewById(R.id.list); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(recyclerView.getContext()); @@ -126,8 +126,7 @@ public class UnreadFragment extends BaseFragment { swipeRefreshLayout.setColorSchemeResources(R.color.accent); swipeRefreshLayout.setOnRefreshListener( () -> { - if (unreadTask != null && unreadTask.getStatus() != AsyncTask.Status.RUNNING) { - topicSummaries.clear(); + if (!unreadTask.isRunning()) { numberOfPages = 0; loadedPages = 0; unreadTask = new UnreadTask(this::onUnreadTaskStarted, this::onUnreadTaskFinished); @@ -144,10 +143,11 @@ public class UnreadFragment extends BaseFragment { @Override public void onDestroy() { super.onDestroy(); - if (unreadTask != null && unreadTask.getStatus() != AsyncTask.Status.RUNNING) + if (unreadTask.isRunning()) unreadTask.cancel(true); - if (markReadTask != null && markReadTask.getStatus() != AsyncTask.Status.RUNNING) + if (markReadTask.isRunning()) markReadTask.cancel(true); + topicSummaries.clear(); } public interface UnreadFragmentInteractionListener extends FragmentInteractionListener { @@ -160,11 +160,15 @@ public class UnreadFragment extends BaseFragment { progressBar.setVisibility(ProgressBar.VISIBLE); } - private void onUnreadTaskFinished(int resultCode, Void data) { + private void onUnreadTaskFinished(int resultCode, ArrayList fetchedUnread) { if (resultCode == NetworkResultCodes.SUCCESSFUL) { - unreadAdapter.notifyDataSetChanged(); - - ++loadedPages; + if(fetchedUnread!=null && !fetchedUnread.isEmpty()){ + if(loadedPages==0) + topicSummaries.clear(); + topicSummaries.addAll(fetchedUnread); + unreadAdapter.notifyDataSetChanged(); + } + loadedPages++; if (loadedPages < numberOfPages) { unreadTask = new UnreadTask(this::onUnreadTaskStarted, this::onUnreadTaskFinished); assert SessionManager.unreadUrl != null; @@ -186,15 +190,16 @@ public class UnreadFragment extends BaseFragment { } } - private class UnreadTask extends NewParseTask { + private class UnreadTask extends NewParseTask> { - UnreadTask(OnTaskStartedListener onTaskStartedListener, OnNetworkTaskFinishedListener onParseTaskFinishedListener) { + UnreadTask(OnTaskStartedListener onTaskStartedListener, OnNetworkTaskFinishedListener> onParseTaskFinishedListener) { super(onTaskStartedListener, onParseTaskFinishedListener); } @Override - protected Void parse(Document document, Response response) throws ParseException { + protected ArrayList parse(Document document, Response response) throws ParseException { Elements unread = document.select("table.bordercolor[cellspacing=1] tr:not(.titlebg)"); + ArrayList fetchedTopicSummaries = new ArrayList<>(); if (!unread.isEmpty()) { //topicSummaries.clear(); for (Element row : unread) { @@ -210,16 +215,14 @@ public class UnreadFragment extends BaseFragment { dateTime = dateTime.replace("", ""); dateTime = dateTime.replace("", ""); if (dateTime.contains(" am") || dateTime.contains(" pm") || - dateTime.contains(" πμ") || dateTime.contains(" μμ")) { + dateTime.contains(" πμ") || dateTime.contains(" μμ")) dateTime = dateTime.replaceAll(":[0-5][0-9] ", " "); - } else { + else dateTime = dateTime.substring(0, dateTime.lastIndexOf(":")); - } - if (!dateTime.contains(",")) { + if (!dateTime.contains(",")) dateTime = dateTime.replaceAll(".+? ([0-9])", "$1"); - } - topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime)); + fetchedTopicSummaries.add(new TopicSummary(link, title, lastUser, dateTime)); } Element topBar = document.select("table:not(.bordercolor):not(#bodyarea):has(td.middletext)").first(); @@ -233,31 +236,29 @@ public class UnreadFragment extends BaseFragment { if (numberOfPages == 0 && pagesElement != null) { Elements pages = pagesElement.select("a"); - if (!pages.isEmpty()) { + if (!pages.isEmpty()) numberOfPages = Integer.parseInt(pages.last().text()); - } else { + else numberOfPages = 1; - } } if (markRead != null && loadedPages == numberOfPages - 1) - topicSummaries.add(new TopicSummary(markRead.attr("href"), markRead.text(), null, + fetchedTopicSummaries.add(new TopicSummary(markRead.attr("href"), markRead.text(), null, null)); } else { - topicSummaries.clear(); String message = document.select("table.bordercolor[cellspacing=1]").first().text(); if (message.contains("No messages")) { //It's english message = "No unread posts!"; } else { //It's greek - message = "Δεν υπάρχουν μη διαβασμένα μηνύματα!"; + message = "Δεν υπάρχουν μη αναγνωσμένα μηνύματα!"; } - topicSummaries.add(new TopicSummary(null, null, null, message)); + fetchedTopicSummaries.add(new TopicSummary(null, null, null, message)); } - return null; + return fetchedTopicSummaries; } @Override - protected int getResultCode(Response response, Void data) { + protected int getResultCode(Response response, ArrayList data) { return NetworkResultCodes.SUCCESSFUL; } } @@ -301,12 +302,19 @@ public class UnreadFragment extends BaseFragment { Toast.makeText(getContext() , "Fatal error!\n Task aborted...", Toast.LENGTH_LONG).show(); } else { - if (unreadTask != null && unreadTask.getStatus() != AsyncTask.Status.RUNNING) { + if (!unreadTask.isRunning()) { + numberOfPages = 0; + loadedPages = 0; unreadTask = new UnreadTask(UnreadFragment.this::onUnreadTaskStarted, UnreadFragment.this::onUnreadTaskFinished); assert SessionManager.unreadUrl != null; unreadTask.execute(SessionManager.unreadUrl.toString()); } } } + + //TODO: Maybe extend this task and use isRunning() from ExternalAsyncTask instead (?) + public boolean isRunning(){ + return getStatus() == AsyncTask.Status.RUNNING; + } } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ExternalAsyncTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ExternalAsyncTask.java index d20d29dc..88621314 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ExternalAsyncTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ExternalAsyncTask.java @@ -77,4 +77,8 @@ public abstract class ExternalAsyncTask extends AsyncTask { public interface OnTaskFinishedListener { void onTaskFinished(V result); } + + public boolean isRunning(){ + return getStatus() == AsyncTask.Status.RUNNING; + } } From ea8649515cfedb50b50b4c102718bef51631e09f Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 22 Nov 2018 15:30:27 +0200 Subject: [PATCH 076/104] fix shoutbox keyboard issues --- .../activities/shoutbox/ShoutboxActivity.java | 17 +++++++++++- .../activities/shoutbox/ShoutboxFragment.java | 16 ++++++++---- .../thmmy/mthmmy/editorview/EditorView.java | 26 ++++++++++++------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java index fffc8079..bdd026ad 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java @@ -7,6 +7,8 @@ import gr.thmmy.mthmmy.base.BaseActivity; public class ShoutboxActivity extends BaseActivity { + private ShoutboxFragment shoutboxFragment; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -25,8 +27,9 @@ public class ShoutboxActivity extends BaseActivity { drawer.setSelection(SHOUTBOX_ID); if (savedInstanceState == null) { + shoutboxFragment = ShoutboxFragment.newInstance(); getSupportFragmentManager().beginTransaction() - .replace(R.id.container, ShoutboxFragment.newInstance()) + .replace(R.id.container, shoutboxFragment) .commitNow(); } } @@ -36,4 +39,16 @@ public class ShoutboxActivity extends BaseActivity { drawer.setSelection(SHOUTBOX_ID); super.onResume(); } + + @Override + public void onBackPressed() { + int count = getSupportFragmentManager().getBackStackEntryCount(); + + if (count == 0) { + if (!shoutboxFragment.onBackPressed()) + super.onBackPressed(); + } else { + getSupportFragmentManager().popBackStack(); + } + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java index 499e2017..5bf34d6c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java @@ -76,11 +76,6 @@ public class ShoutboxFragment extends Fragment { shoutboxViewModel.sendShout(editorView.getText().toString()); }); editorView.hideMarkdown(); - editorView.setOnTouchListener((view, motionEvent) -> { - editorView.showMarkdown(); - return false; - }); - editorView.setMarkdownVisible(false); editorView.showMarkdownOnfocus(); return rootView; @@ -162,4 +157,15 @@ public class ShoutboxFragment extends Fragment { Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show(); } } + + /** + * @return whether or not {@link ShoutboxFragment#onBackPressed()} consumed the event or not + */ + public boolean onBackPressed() { + if (emojiKeyboard.isVisible()) { + emojiKeyboard.setVisibility(View.GONE); + return true; + } + return false; + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java index 5adf4aa7..55df571c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java @@ -38,7 +38,7 @@ import gr.thmmy.mthmmy.R; public class EditorView extends LinearLayout implements EmojiInputField { - private static final int ANIMATION_DURATION = 100; + private static final int ANIMATION_DURATION = 200; private SparseArray colors = new SparseArray<>(); private TextInputLayout edittextWrapper; @@ -308,24 +308,32 @@ public class EditorView extends LinearLayout implements EmojiInputField { this.emojiKeyboard = emojiKeyboard; } - public void setMarkdownVisible(boolean visible) { - formatButtonsRecyclerview.setVisibility(visible ? VISIBLE : GONE); - } - public void showMarkdownOnfocus() { edittextWrapper.setOnClickListener(view -> { showMarkdown(); }); editText.setOnClickListener(view -> { + if (!emojiKeyboard.isVisible()) { + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); + } else { + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(getWindowToken(), 0); + requestEditTextFocus(); + } showMarkdown(); }); edittextWrapper.setOnFocusChangeListener((view, b) -> { - if (b) showMarkdown(); - else hideMarkdown(); + if (b) { + emojiKeyboard.onEmojiInputFieldFocused(EditorView.this); + showMarkdown(); + } else hideMarkdown(); }); editText.setOnFocusChangeListener((view, b) -> { - if (b) showMarkdown(); - else hideMarkdown(); + if (b) { + emojiKeyboard.onEmojiInputFieldFocused(EditorView.this); + showMarkdown(); + } else hideMarkdown(); }); } From b3230e75a67c8df0a7277bd5e8f7c34c8e6fed55 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 22 Nov 2018 15:53:25 +0200 Subject: [PATCH 077/104] BoardActivity arrows enlargement --- .../activities/board/BoardActivity.java | 2 +- .../mthmmy/activities/board/BoardAdapter.java | 4 ++-- .../main/recent/RecentFragment.java | 9 +++------ .../main/unread/UnreadFragment.java | 5 ++--- .../ic_arrow_drop_down_accent_24dp.xml | 4 ++-- .../drawable/ic_arrow_drop_up_accent_24dp.xml | 4 ++-- ...d.xml => activity_board_sub_board_row.xml} | 20 ++++++++++--------- ...topic.xml => activity_board_topic_row.xml} | 8 +++++--- 8 files changed, 28 insertions(+), 28 deletions(-) rename app/src/main/res/layout/{activity_board_sub_board.xml => activity_board_sub_board_row.xml} (92%) rename app/src/main/res/layout/{activity_board_topic.xml => activity_board_topic_row.xml} (95%) 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 dfd1d38e..69739514 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 @@ -290,7 +290,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo pUnread = true; } pStartedBy = topicColumns.get(3).text(); - pStats = "Replies " + topicColumns.get(4).text() + ", Views " + topicColumns.get(5).text(); + pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text(); pLastPost = topicColumns.last().text(); if (pLastPost.contains("by")) { 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 97857440..6c5e50db 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 @@ -90,7 +90,7 @@ class BoardAdapter extends RecyclerView.Adapter { return new TitlesViewHolder(subBoardTitle); } else if (viewType == VIEW_TYPE_SUB_BOARD) { View subBoard = LayoutInflater.from(parent.getContext()). - inflate(R.layout.activity_board_sub_board, parent, false); + inflate(R.layout.activity_board_sub_board_row, parent, false); return new SubBoardViewHolder(subBoard); } else if (viewType == VIEW_TYPE_TOPIC_TITLE) { TextView topicTitle = new TextView(context); @@ -111,7 +111,7 @@ class BoardAdapter extends RecyclerView.Adapter { return new TitlesViewHolder(topicTitle); } else if (viewType == VIEW_TYPE_TOPIC) { View topic = LayoutInflater.from(parent.getContext()). - inflate(R.layout.activity_board_topic, parent, false); + inflate(R.layout.activity_board_topic_row, parent, false); return new TopicViewHolder(topic); } else if (viewType == VIEW_TYPE_LOADING) { View loading = LayoutInflater.from(parent.getContext()). diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 1ecbd360..70a0eed9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -1,6 +1,5 @@ package gr.thmmy.mthmmy.activities.main.recent; -import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -21,7 +20,6 @@ import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.session.SessionManager; @@ -55,8 +53,7 @@ public class RecentFragment extends BaseFragment { private RecentTask recentTask; // Required empty public constructor - public RecentFragment() { - } + public RecentFragment() {} /** * Use ONLY this factory method to create a new instance of @@ -147,9 +144,9 @@ public class RecentFragment extends BaseFragment { topicSummaries.addAll(fetchedRecent); recentAdapter.notifyDataSetChanged(); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { - Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), "Network error", Toast.LENGTH_SHORT).show(); } else { - Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Unexpected error," + + Toast.makeText(getContext(), "Unexpected error," + " please contact the developers with the details", Toast.LENGTH_LONG).show(); } 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 6f0cc15d..79b21b03 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 @@ -23,7 +23,6 @@ import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.session.SessionManager; @@ -183,9 +182,9 @@ public class UnreadFragment extends BaseFragment { progressBar.setVisibility(ProgressBar.INVISIBLE); swipeRefreshLayout.setRefreshing(false); if (resultCode == NetworkResultCodes.NETWORK_ERROR) - Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), "Network error", Toast.LENGTH_SHORT).show(); else - Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Unexpected error," + + Toast.makeText(getContext(), "Unexpected error," + " please contact the developers with the details", Toast.LENGTH_LONG).show(); } } diff --git a/app/src/main/res/drawable/ic_arrow_drop_down_accent_24dp.xml b/app/src/main/res/drawable/ic_arrow_drop_down_accent_24dp.xml index f100d7d9..0e9dc941 100644 --- a/app/src/main/res/drawable/ic_arrow_drop_down_accent_24dp.xml +++ b/app/src/main/res/drawable/ic_arrow_drop_down_accent_24dp.xml @@ -1,5 +1,5 @@ - + android:width="30dp" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/app/src/main/res/drawable/ic_arrow_drop_up_accent_24dp.xml b/app/src/main/res/drawable/ic_arrow_drop_up_accent_24dp.xml index ff9c29f4..3924bc11 100644 --- a/app/src/main/res/drawable/ic_arrow_drop_up_accent_24dp.xml +++ b/app/src/main/res/drawable/ic_arrow_drop_up_accent_24dp.xml @@ -1,5 +1,5 @@ - + android:width="30dp" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/app/src/main/res/layout/activity_board_sub_board.xml b/app/src/main/res/layout/activity_board_sub_board_row.xml similarity index 92% rename from app/src/main/res/layout/activity_board_sub_board.xml rename to app/src/main/res/layout/activity_board_sub_board_row.xml index eadcd8b4..880ae31d 100644 --- a/app/src/main/res/layout/activity_board_sub_board.xml +++ b/app/src/main/res/layout/activity_board_sub_board_row.xml @@ -3,25 +3,25 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@color/card_background" - android:orientation="vertical"> + android:background="@color/card_background"> + android:paddingStart="16dp" + android:paddingEnd="0dp"> + android:paddingStart="0dp" + android:paddingEnd="16dp" + app:srcCompat="@drawable/ic_arrow_drop_down_accent_24dp"/> @@ -77,8 +79,8 @@ android:id="@+id/child_board_last_post" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="1dp" android:layout_marginTop="1dp" + android:layout_marginBottom="1dp" android:clickable="true" android:focusable="true" android:text="@string/child_board_last_post" diff --git a/app/src/main/res/layout/activity_board_topic.xml b/app/src/main/res/layout/activity_board_topic_row.xml similarity index 95% rename from app/src/main/res/layout/activity_board_topic.xml rename to app/src/main/res/layout/activity_board_topic_row.xml index 4888f6aa..6c816409 100644 --- a/app/src/main/res/layout/activity_board_topic.xml +++ b/app/src/main/res/layout/activity_board_topic_row.xml @@ -9,8 +9,8 @@ android:clickable="true" android:focusable="true" android:orientation="vertical" - android:paddingLeft="16dp" - android:paddingRight="16dp"> + android:paddingStart="16dp" + android:paddingEnd="0dp"> + android:paddingStart="0dp" + android:paddingEnd="16dp" + app:srcCompat="@drawable/ic_arrow_drop_down_accent_24dp"/> Date: Thu, 22 Nov 2018 17:51:17 +0200 Subject: [PATCH 078/104] Minor fixes e.g. Avoid showing consent dialog more than once --- .../gr/thmmy/mthmmy/activities/main/MainActivity.java | 1 + app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java | 8 ++++++-- app/src/main/res/layout/activity_board_sub_board_row.xml | 5 ++--- app/src/main/res/layout/activity_board_topic_row.xml | 7 ++++--- 4 files changed, 13 insertions(+), 8 deletions(-) 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 a9842f9c..af1a4cf2 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 @@ -79,6 +79,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF startActivity(intent); finish(); overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); + return; //Avoid executing the code below } //Initialize drawer 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 74dda5ee..b953c032 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -99,6 +99,7 @@ public abstract class BaseActivity extends AppCompatActivity { private MainActivity mainActivity; private boolean isMainActivity; + private boolean isUserConsentDialogShown; //Needed because sometimes onResume is being called twice @Override protected void onCreate(Bundle savedInstanceState) { @@ -128,8 +129,10 @@ public abstract class BaseActivity extends AppCompatActivity { protected void onResume() { super.onResume(); updateDrawer(); - if (!sharedPreferences.getBoolean(getString(R.string.user_consent_shared_preference_key), false)) + if (!sharedPreferences.getBoolean(getString(R.string.user_consent_shared_preference_key), false) && !isUserConsentDialogShown){ + isUserConsentDialogShown=true; showUserConsentDialog(); + } } @Override @@ -389,7 +392,7 @@ public abstract class BaseActivity extends AppCompatActivity { if (!sessionManager.isLoggedIn()) //When logged out or if user is guest startLoginActivity(); else - new LogoutTask().execute(); + new LogoutTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); //Avoid delays between onPreExecute() and doInBackground() } else if (drawerItem.equals(ABOUT_ID)) { if (!(BaseActivity.this instanceof AboutActivity)) { Intent intent = new Intent(BaseActivity.this, AboutActivity.class); @@ -496,6 +499,7 @@ public abstract class BaseActivity extends AppCompatActivity { if (mainActivity != null) mainActivity.updateTabs(); progressDialog.dismiss(); + //TODO: Redirect to Main only for some Activities (e.g. Topic, Board, Downloads) //if (BaseActivity.this instanceof TopicActivity){ Intent intent = new Intent(BaseActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); diff --git a/app/src/main/res/layout/activity_board_sub_board_row.xml b/app/src/main/res/layout/activity_board_sub_board_row.xml index 880ae31d..bcbe3ec7 100644 --- a/app/src/main/res/layout/activity_board_sub_board_row.xml +++ b/app/src/main/res/layout/activity_board_sub_board_row.xml @@ -20,8 +20,6 @@ diff --git a/app/src/main/res/layout/activity_board_topic_row.xml b/app/src/main/res/layout/activity_board_topic_row.xml index 6c816409..0c9207bf 100644 --- a/app/src/main/res/layout/activity_board_topic_row.xml +++ b/app/src/main/res/layout/activity_board_topic_row.xml @@ -15,8 +15,6 @@ @@ -37,7 +37,8 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" - android:paddingBottom="2dp" + android:paddingTop="5dp" + android:paddingBottom="7dp" android:text="@string/topic_subject" android:textColor="@color/primary_text" android:textSize="18sp" /> From fe7e97e29135eb68cb5311ac010409ccb9a0d352 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 22 Nov 2018 18:29:21 +0200 Subject: [PATCH 079/104] Added margin to BoardActivity's bookmark button --- app/src/main/res/layout/activity_board.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/activity_board.xml b/app/src/main/res/layout/activity_board.xml index d538bdf7..9a51aa92 100644 --- a/app/src/main/res/layout/activity_board.xml +++ b/app/src/main/res/layout/activity_board.xml @@ -28,7 +28,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|end" - android:layout_marginEnd="4dp" + android:layout_marginEnd="19dp" android:background="@null" android:contentDescription="@string/bookmark" app:srcCompat="@drawable/ic_bookmark_false_accent_24dp"/> From e29c2ecfdb7d120ff8e3dd0e397b316a069076ca Mon Sep 17 00:00:00 2001 From: Ezerous Date: Fri, 23 Nov 2018 10:50:17 +0200 Subject: [PATCH 080/104] Avoid running in debug with release google-services.json --- app/build.gradle | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 85f9bba6..d36a6fee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,14 @@ tasks.whenTaskAdded { task -> def inputFile = new File("app/google-services.json") def json = new JsonSlurper().parseText(inputFile.text) if (json.project_info.project_id != "mthmmy-release-3aef0") - throw new GradleException('Please supply the correct google-services.json for release or manually change the id above!') + throw new GradleException('Please supply the correct google-services.json for release (or manually change the id above)!') + }) + } else if (task.name.contains("assembleDebug")) { + task.getDependsOn().add({ + def inputFile = new File("app/google-services.json") + def json = new JsonSlurper().parseText(inputFile.text) + if (json.project_info.project_id == "mthmmy-release-3aef0") + throw new GradleException('Please replace the release google-services.json with a debug one!') }) } } From 6f94d984c6097de9f9fae0e1e9895497bb1c9046 Mon Sep 17 00:00:00 2001 From: oogee Date: Fri, 23 Nov 2018 21:03:46 +0200 Subject: [PATCH 081/104] hide emoji keyboard when shouting --- .../gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java index 5bf34d6c..0bcf9a75 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java @@ -124,7 +124,8 @@ public class ShoutboxFragment extends Fragment { Timber.i("Start sending a shout..."); editorView.setAlpha(0.5f); editorView.setEnabled(false); - emojiKeyboard.setVisibility(View.VISIBLE); + if (emojiKeyboard.isVisible()) + emojiKeyboard.setVisibility(View.GONE); progressBar.setVisibility(View.VISIBLE); } From f6ca688660506a1aff66df2d453ed645e59d79da Mon Sep 17 00:00:00 2001 From: oogee Date: Fri, 23 Nov 2018 21:24:11 +0200 Subject: [PATCH 082/104] edit post viewholder style changes --- .../java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java | 3 ++- app/src/main/res/layout/activity_topic_edit_row.xml | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) 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 bb8bdeb2..11a668d6 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 @@ -711,6 +711,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.editEditor.requestEditTextFocus(); emojiKeyboard.registerEmojiInputField(holder.editEditor); holder.editEditor.setText(viewModel.getPostBeingEditedText()); + holder.editEditor.getEditText().setSelection(holder.editEditor.getText().length()); holder.editEditor.setOnSubmitListener(view -> { if (holder.editSubject.getText().toString().isEmpty()) return; if (holder.editEditor.getText().toString().isEmpty()) { @@ -727,7 +728,7 @@ class TopicAdapter extends RecyclerView.Adapter { }); if (backPressHidden) { - holder.editEditor.requestFocus(); + holder.editEditor.requestEditTextFocus(); backPressHidden = false; } } diff --git a/app/src/main/res/layout/activity_topic_edit_row.xml b/app/src/main/res/layout/activity_topic_edit_row.xml index 3c29ae33..39b67582 100644 --- a/app/src/main/res/layout/activity_topic_edit_row.xml +++ b/app/src/main/res/layout/activity_topic_edit_row.xml @@ -80,8 +80,10 @@ android:id="@+id/edit_editorview" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" android:background="@color/card_background" - card_view:hint="Post message"/> + card_view:hint="Post message" /> \ No newline at end of file From 16983332a0e8ebbebf668e9e104a7fc1139cb3fd Mon Sep 17 00:00:00 2001 From: oogee Date: Sat, 24 Nov 2018 13:08:32 +0200 Subject: [PATCH 083/104] fix reply fab visibility issues --- .../activities/topic/TopicActivity.java | 22 +++++++++++++++---- .../mthmmy/utils/ScrollAwareFABBehavior.java | 7 +++--- 2 files changed, 21 insertions(+), 8 deletions(-) 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 619e0e12..64b9fcdd 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 @@ -185,13 +185,17 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo replyFAB = findViewById(R.id.topic_fab); replyFAB.hide(); + replyFAB.setTag(false); bottomNavBar = findViewById(R.id.bottom_navigation_bar); - if (!sessionManager.isLoggedIn()) replyFAB.hide(); - else { + if (!sessionManager.isLoggedIn()) { + replyFAB.hide(); + replyFAB.setTag(false); + } else { replyFAB.setOnClickListener(view -> { if (sessionManager.isLoggedIn()) viewModel.prepareForReply(); }); + replyFAB.setTag(true); } //Sets bottom navigation bar @@ -281,6 +285,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo topicAdapter.setBackButtonHidden(); viewModel.setWritingReply(false); replyFAB.show(); + replyFAB.setTag(true); bottomNavBar.setVisibility(View.VISIBLE); return; } else if (viewModel.isEditingPost()) { @@ -289,6 +294,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo topicAdapter.setBackButtonHidden(); viewModel.setEditingPost(false); replyFAB.show(); + replyFAB.setTag(true); bottomNavBar.setVisibility(View.VISIBLE); return; } @@ -522,6 +528,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo BaseApplication.getInstance().logFirebaseAnalyticsEvent("post_creation", null); Timber.i("Post reply successful"); replyFAB.show(); + replyFAB.setTag(true); bottomNavBar.setVisibility(View.VISIBLE); viewModel.setWritingReply(false); if ((((Post) topicItems.get(topicItems.size() - 1)).getPostNumber() + 1) % 15 == 0) { @@ -540,6 +547,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo topicAdapter.notifyItemInserted(topicItems.size()); recyclerView.scrollToPosition(topicItems.size() - 1); replyFAB.hide(); + replyFAB.setTag(false); bottomNavBar.setVisibility(View.GONE); AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this, R.style.AppTheme_Dark_Dialog); @@ -590,6 +598,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo ((Post) topicItems.get(position)).setPostType(Post.TYPE_POST); topicAdapter.notifyItemChanged(position); replyFAB.show(); + replyFAB.setTag(true); bottomNavBar.setVisibility(View.VISIBLE); viewModel.setEditingPost(false); viewModel.reloadPage(); @@ -656,10 +665,13 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo } }); viewModel.getReplyPageUrl().observe(this, replyPageUrl -> { - if (replyPageUrl == null) + if (replyPageUrl == null) { replyFAB.hide(); - else + replyFAB.setTag(false); + } else { replyFAB.show(); + replyFAB.setTag(true); + } }); viewModel.getTopicItems().observe(this, postList -> { if (postList == null) progressBar.setVisibility(ProgressBar.VISIBLE); @@ -744,6 +756,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo topicAdapter.notifyItemInserted(topicItems.size()); recyclerView.scrollToPosition(topicItems.size() - 1); replyFAB.hide(); + replyFAB.setTag(false); bottomNavBar.setVisibility(View.GONE); } else { Timber.i("Prepare for reply unsuccessful"); @@ -759,6 +772,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo topicAdapter.notifyItemChanged(result.getPosition()); recyclerView.scrollToPosition(result.getPosition()); replyFAB.hide(); + replyFAB.setTag(false); bottomNavBar.setVisibility(View.GONE); } else { Timber.i("Prepare for edit unsuccessful"); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java index 46d412bc..6902ab52 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java @@ -37,8 +37,7 @@ public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior 0 - || (!target.canScrollVertically(-1) && dyConsumed == 0 && dyUnconsumed > 50))) { + if (dyConsumed > 0 || (!target.canScrollVertically(-1) && dyConsumed == 0 && dyUnconsumed > 50)) { child.hide(new FloatingActionButton.OnVisibilityChangedListener() { @Override public void onHidden(FloatingActionButton fab) { @@ -46,8 +45,8 @@ public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior Date: Sat, 24 Nov 2018 14:04:45 +0200 Subject: [PATCH 084/104] OkHttpProfiler --- app/build.gradle | 1 + app/src/main/assets/apache_libraries.html | 3 +++ app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index d36a6fee..d414755a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -89,6 +89,7 @@ dependencies { implementation "ru.noties:markwon:2.0.0" implementation 'net.gotev:uploadservice:3.4.2' implementation 'net.gotev:uploadservice-okhttp:3.4.2' + debugImplementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.4' //Plugin: https://plugins.jetbrains.com/plugin/11249-okhttp-profiler } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/assets/apache_libraries.html b/app/src/main/assets/apache_libraries.html index 360546d4..b0e33882 100644 --- a/app/src/main/assets/apache_libraries.html +++ b/app/src/main/assets/apache_libraries.html @@ -71,6 +71,9 @@
      • Grgit v3.0.0 (Copyright ©2018 Andrew Oberstar)
      • +
      • +
        OkHttpProfiler v1.0.4
        +
      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 42e907b8..02984c53 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -16,6 +16,7 @@ import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.cache.SetCookieCache; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; import com.google.firebase.analytics.FirebaseAnalytics; +import com.itkacher.okhttpprofiler.OkHttpProfilerInterceptor; import com.jakewharton.picasso.OkHttp3Downloader; import com.mikepenz.fontawesome_typeface_library.FontAwesome; import com.mikepenz.iconics.IconicsDrawable; @@ -125,6 +126,9 @@ public class BaseApplication extends Application { builder.connectionSpecs(Arrays.asList(legacyTls, ConnectionSpec.CLEARTEXT)); } + if (BuildConfig.DEBUG) + builder.addInterceptor(new OkHttpProfilerInterceptor()); + client = builder.build(); sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs, draftsPrefs); From 063fc7bd00d80b2afc5762bcd89ad47aa385ba3c Mon Sep 17 00:00:00 2001 From: oogee Date: Sat, 24 Nov 2018 16:27:34 +0200 Subject: [PATCH 085/104] null check reply fab tag --- .../main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java index 6902ab52..a45e1a3f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java @@ -45,7 +45,7 @@ public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior Date: Sat, 24 Nov 2018 16:48:12 +0200 Subject: [PATCH 086/104] fix poll checkboxes --- .../mthmmy/activities/topic/TopicAdapter.java | 16 +++++----------- .../thmmy/mthmmy/viewmodel/TopicViewModel.java | 6 +++--- 2 files changed, 8 insertions(+), 14 deletions(-) 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 11a668d6..1fee9e01 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 @@ -205,23 +205,17 @@ class TopicAdapter extends RecyclerView.Adapter { if (poll.getAvailableVoteCount() > 1) { for (Poll.Entry entry : entries) { - LinearLayout container = new LinearLayout(context); - container.setOrientation(LinearLayout.HORIZONTAL); CheckBox checkBox = new CheckBox(context); - TextView label = new TextView(context); - label.setTextColor(primaryTextColor); - label.setMovementMethod(LinkMovementMethod.getInstance()); + checkBox.setTextColor(primaryTextColor); + checkBox.setMovementMethod(LinkMovementMethod.getInstance()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - label.setText(Html.fromHtml(entry.getEntryName(), Html.FROM_HTML_MODE_LEGACY)); + checkBox.setText(Html.fromHtml(entry.getEntryName(), Html.FROM_HTML_MODE_LEGACY)); } else { //noinspection deprecation - label.setText(Html.fromHtml(entry.getEntryName())); + checkBox.setText(Html.fromHtml(entry.getEntryName())); } - label.setText(ThmmyParser.html2span(context, entry.getEntryName())); checkBox.setTextColor(primaryTextColor); - container.addView(checkBox); - container.addView(label); - holder.optionsLayout.addView(container); + holder.optionsLayout.addView(checkBox); } holder.voteChart.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index eebd1ad6..a9e255f6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -144,10 +144,10 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa if (optionsLayout.getChildAt(0) instanceof RadioGroup) { RadioGroup optionsRadioGroup = (RadioGroup) optionsLayout.getChildAt(0); votes.add(optionsRadioGroup.getCheckedRadioButtonId()); - } else if (optionsLayout.getChildAt(0) instanceof LinearLayout) { + } else if (optionsLayout.getChildAt(0) instanceof CheckBox) { for (int i = 0; i < optionsLayout.getChildCount(); i++) { - LinearLayout container = (LinearLayout) optionsLayout.getChildAt(i); - if (((CheckBox) container.getChildAt(0)).isChecked()) + CheckBox checkBox = (CheckBox) optionsLayout.getChildAt(i); + if (checkBox.isChecked()) votes.add(i); } } From 26560c6abc24368918d0a2578396c0019bb3152d Mon Sep 17 00:00:00 2001 From: oogee Date: Sat, 24 Nov 2018 21:45:22 +0200 Subject: [PATCH 087/104] improve poll parsing --- .../main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f383793e..40d2aadf 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 @@ -540,7 +540,7 @@ public class TopicParser { entries.add(0, new Poll.Entry(optionName, voteCount)); } - Elements links = pollColumn.child(0).child(0).child(0).child(1).select("a"); + Elements links = pollColumn.select("td[style=padding-left: 15px;] > a"); if (links != null && links.size() > 0) { if (links.first().text().equals("Remove Vote") || links.first().text().equals("Αφαίρεση ψήφου")) removeVoteUrl = links.first().attr("href"); From d46535035825da2f0043ed64a9fc7c13727ae585 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 29 Nov 2018 18:15:55 +0200 Subject: [PATCH 088/104] LatestPosts flickering and wrong avatars fixes --- .../latestPosts/LatestPostsAdapter.java | 26 +++++++++---------- .../latestPosts/LatestPostsFragment.java | 14 +++++----- .../layout-v21/activity_topic_post_row.xml | 3 ++- .../res/layout/activity_topic_post_row.xml | 3 ++- build.gradle | 2 +- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java index e3c3ec8d..6054a05f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java @@ -1,5 +1,6 @@ package gr.thmmy.mthmmy.activities.profile.latestPosts; +import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -21,10 +22,10 @@ import me.zhanghai.android.materialprogressbar.MaterialProgressBar; * specified {@link LatestPostsFragment.LatestPostsFragmentInteractionListener}. */ class LatestPostsAdapter extends RecyclerView.Adapter { - private final int VIEW_TYPE_EMPTY = -1; - private final int VIEW_TYPE_ITEM = 0; - private final int VIEW_TYPE_LOADING = 1; - final private LatestPostsFragment.LatestPostsFragmentInteractionListener interactionListener; + private static final int VIEW_TYPE_EMPTY = -1; + private static final int VIEW_TYPE_ITEM = 0; + private static final int VIEW_TYPE_LOADING = 1; + private final LatestPostsFragment.LatestPostsFragmentInteractionListener interactionListener; private final ArrayList parsedTopicSummaries; LatestPostsAdapter(BaseFragment.FragmentInteractionListener interactionListener, @@ -70,19 +71,16 @@ class LatestPostsAdapter extends RecyclerView.Adapter { latestPostViewHolder.postTitle.setText(topic.getSubject()); latestPostViewHolder.postDate.setText(topic.getDateTime()); + latestPostViewHolder.post.setBackgroundColor(Color.argb(1, 255, 255, 255)); latestPostViewHolder.post.loadDataWithBaseURL("file:///android_asset/" , topic.getPost(), "text/html", "UTF-8", null); - latestPostViewHolder.latestPostsRow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (interactionListener != null) { - // Notify the active callbacks interface (the activity, if the - // fragment is attached to one) that a post has been selected. - interactionListener.onLatestPostsFragmentInteraction( - parsedTopicSummaries.get(holder.getAdapterPosition())); - } - + latestPostViewHolder.latestPostsRow.setOnClickListener(v -> { + if (interactionListener != null) { + // Notify the active callbacks interface (the activity, if the + // fragment is attached to one) that a post has been selected. + interactionListener.onLatestPostsFragmentInteraction( + parsedTopicSummaries.get(holder.getAdapterPosition())); } }); } else if (holder instanceof LoadingViewHolder) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index b2fb112c..04f20b60 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -135,7 +135,6 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap profileLatestPostsTask.execute(profileUrl + ";sa=showPosts"); pagesLoaded = 1; } - Timber.d("onActivityCreated"); } @Override @@ -193,14 +192,13 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap //td:contains( Sorry, no matches were found) Elements latestPostsRows = latestPostsPage. select("td:has(table:Contains(Show Posts)):not([style]) > table"); - if (latestPostsRows.isEmpty()) { + if (latestPostsRows.isEmpty()) latestPostsRows = latestPostsPage. select("td:has(table:Contains(Εμφάνιση μηνυμάτων)):not([style]) > table"); - } + //Removes loading item - if (isLoadingMore) { + if (isLoadingMore) parsedTopicSummaries.remove(parsedTopicSummaries.size() - 1); - } if (!latestPostsRows.select("td:contains(Sorry, no matches were found)").isEmpty() || !latestPostsRows.select("td:contains(Δυστυχώς δεν βρέθηκε τίποτα)").isEmpty()){ @@ -222,10 +220,10 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap } } else { Elements rowHeader = row.select("td.middletext"); - if (rowHeader.size() != 2) { + if (rowHeader.size() != 2) return false; - } else { - pTopicTitle = rowHeader.first().text().trim(); + else { + pTopicTitle = rowHeader.first().text().replaceAll("\\u00a0","").trim(); pTopicUrl = rowHeader.first().select("a").last().attr("href"); pDateTime = rowHeader.last().text(); } diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml index 1cdb357c..d1464a61 100644 --- a/app/src/main/res/layout-v21/activity_topic_post_row.xml +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -58,7 +58,8 @@ android:layout_gravity="center" android:adjustViewBounds="true" android:contentDescription="@string/post_thumbnail" - android:transitionName="user_thumbnail" /> + android:transitionName="user_thumbnail" + app:srcCompat="@drawable/ic_default_user_avatar_darker" />
      + android:contentDescription="@string/post_thumbnail" + app:srcCompat="@drawable/ic_default_user_avatar_darker" />
      Date: Thu, 29 Nov 2018 20:31:12 +0200 Subject: [PATCH 089/104] fix RWPB --- .../activities/topic/TopicActivity.java | 12 +++------- .../mthmmy/viewmodel/TopicViewModel.java | 24 +++++++++---------- 2 files changed, 15 insertions(+), 21 deletions(-) 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 64b9fcdd..5602bacb 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 @@ -540,23 +540,17 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo break; case NEW_REPLY_WHILE_POSTING: Timber.i("New reply while writing a reply"); - Post reply = (Post) topicItems.get(topicItems.size() - 1); + Runnable addReply = () -> { - viewModel.setWritingReply(true); - topicItems.add(Post.newQuickReply(reply.getSubject(), reply.getContent())); - topicAdapter.notifyItemInserted(topicItems.size()); - recyclerView.scrollToPosition(topicItems.size() - 1); - replyFAB.hide(); - replyFAB.setTag(false); - bottomNavBar.setVisibility(View.GONE); AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this, R.style.AppTheme_Dark_Dialog); builder.setMessage("A new reply was posted before you completed your new post." + " Please review it and send your reply again") .setNeutralButton(getString(R.string.ok), (dialog, which) -> dialog.dismiss()) .show(); + viewModel.prepareForReply(); }; - viewModel.reloadPageThen(addReply); + viewModel.resetPageThen(addReply); break; default: Timber.w("Post reply unsuccessful"); diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index a9e255f6..1bbfa9c8 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -104,27 +104,27 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa loadUrl(topicUrl); } - public void reloadPageThen(Runnable runnable) { - if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!"); - Timber.i("Reloading page"); - stopLoading(); - currentTopicTask = new TopicTask(topicTaskObserver, result -> { - TopicViewModel.this.onTopicTaskCompleted(result); - runnable.run(); - }); - currentTopicTask.execute(topicUrl); - } - /** * In contrast to {@link TopicViewModel#reloadPage()} this method gets rid of any arguments * in the url before refreshing */ public void resetPage() { if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!"); - Timber.i("Reseting page"); + Timber.i("Resetting page"); loadUrl(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15)); } + public void resetPageThen(Runnable runnable) { + if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!"); + Timber.i("Resetting page"); + stopLoading(); + currentTopicTask = new TopicTask(topicTaskObserver, result -> { + TopicViewModel.this.onTopicTaskCompleted(result); + runnable.run(); + }); + currentTopicTask.execute(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15)); + } + public void loadPageIndicated() { if (pageIndicatorIndex.getValue() == null) throw new NullPointerException("No page has been loaded yet!"); From be7e0c83826cd2fef7ed8885bba5737f00e90e2f Mon Sep 17 00:00:00 2001 From: oogee Date: Sun, 2 Dec 2018 14:06:01 +0200 Subject: [PATCH 090/104] fix not deleting draft when stopping activity after clicking send; fix edits not being saved when editing a post and scrolling up and down --- .../activities/topic/TopicActivity.java | 13 ++++++++ .../mthmmy/activities/topic/TopicAdapter.java | 32 +++++++++++++++++++ 2 files changed, 45 insertions(+) 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 5602bacb..ddc80ed8 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 @@ -531,6 +531,11 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo replyFAB.setTag(true); bottomNavBar.setVisibility(View.VISIBLE); viewModel.setWritingReply(false); + + SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), + Context.MODE_PRIVATE); + drafts.edit().remove(String.valueOf(viewModel.getTopicId())).apply(); + if ((((Post) topicItems.get(topicItems.size() - 1)).getPostNumber() + 1) % 15 == 0) { Timber.i("Reply was posted in new page. Switching to last page."); viewModel.loadUrl(ParseHelpers.getBaseURL(viewModel.getTopicUrl()) + "." + 2147483647); @@ -541,6 +546,14 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo case NEW_REPLY_WHILE_POSTING: Timber.i("New reply while writing a reply"); + //cache reply + if (viewModel.isWritingReply()) { + SharedPreferences drafts2 = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); + Post reply = (Post) topicItems.get(topicItems.size() - 1); + drafts2.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply(); + viewModel.setWritingReply(false); + } + Runnable addReply = () -> { AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this, R.style.AppTheme_Dark_Dialog); 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 1fee9e01..6eecba83 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 @@ -721,6 +721,38 @@ class TopicAdapter extends RecyclerView.Adapter { viewModel.editPost(position, holder.editSubject.getText().toString(), holder.editEditor.getText().toString()); }); + holder.editSubject.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void afterTextChanged(Editable editable) { + ((Post) topicItems.get(holder.getAdapterPosition())).setSubject(editable.toString()); + } + }); + holder.editEditor.getEditText().addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void afterTextChanged(Editable editable) { + ((Post) topicItems.get(holder.getAdapterPosition())).setContent(editable.toString()); + } + }); if (backPressHidden) { holder.editEditor.requestEditTextFocus(); backPressHidden = false; From d61600dfba70da411764b76454c7ac437df5b0b2 Mon Sep 17 00:00:00 2001 From: oogee Date: Sun, 2 Dec 2018 16:43:53 +0200 Subject: [PATCH 091/104] save post content and bbcontent in a separate variable --- .../activities/topic/TopicActivity.java | 6 ++-- .../mthmmy/activities/topic/TopicAdapter.java | 13 +++++--- .../mthmmy/activities/topic/TopicParser.java | 4 +-- .../main/java/gr/thmmy/mthmmy/model/Post.java | 31 +++++++++++++------ 4 files changed, 35 insertions(+), 19 deletions(-) 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 ddc80ed8..639ab3c7 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 @@ -278,7 +278,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo // persist reply SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); Post reply = (Post) topicItems.get(topicItems.size() - 1); - drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply(); + drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getBbContent()).apply(); topicItems.remove(topicItems.size() - 1); topicAdapter.notifyItemRemoved(topicItems.size()); @@ -322,7 +322,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo if (viewModel.isWritingReply()) { SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); Post reply = (Post) topicItems.get(topicItems.size() - 1); - drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply(); + drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getBbContent()).apply(); } } @@ -550,7 +550,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo if (viewModel.isWritingReply()) { SharedPreferences drafts2 = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); Post reply = (Post) topicItems.get(topicItems.size() - 1); - drafts2.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply(); + drafts2.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getBbContent()).apply(); viewModel.setWritingReply(false); } 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 6eecba83..eb87fcdc 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 @@ -642,8 +642,8 @@ class TopicAdapter extends RecyclerView.Adapter { String replyText = ""; - if (reply.getContent() != null) - replyText += reply.getContent(); + if (reply.getBbContent() != null) + replyText += reply.getBbContent(); else { SharedPreferences drafts = context.getSharedPreferences(context.getString(R.string.pref_topic_drafts_key), Context.MODE_PRIVATE); @@ -666,7 +666,7 @@ class TopicAdapter extends RecyclerView.Adapter { @Override public void afterTextChanged(Editable editable) { - ((Post) topicItems.get(holder.getAdapterPosition())).setContent(editable.toString()); + ((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(editable.toString()); } }); @@ -704,7 +704,10 @@ class TopicAdapter extends RecyclerView.Adapter { holder.editEditor.setEmojiKeyboard(emojiKeyboard); holder.editEditor.requestEditTextFocus(); emojiKeyboard.registerEmojiInputField(holder.editEditor); - holder.editEditor.setText(viewModel.getPostBeingEditedText()); + if (currentPost.getBbContent() == null) + holder.editEditor.setText(viewModel.getPostBeingEditedText()); + else + holder.editEditor.setText(currentPost.getBbContent()); holder.editEditor.getEditText().setSelection(holder.editEditor.getText().length()); holder.editEditor.setOnSubmitListener(view -> { if (holder.editSubject.getText().toString().isEmpty()) return; @@ -750,7 +753,7 @@ class TopicAdapter extends RecyclerView.Adapter { @Override public void afterTextChanged(Editable editable) { - ((Post) topicItems.get(holder.getAdapterPosition())).setContent(editable.toString()); + ((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(editable.toString()); } }); if (backPressHidden) { 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 40d2aadf..5cfcc2db 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 @@ -461,7 +461,7 @@ public class TopicParser { } //Add new post in postsList, extended information needed - parsedPostsList.add(new Post(p_thumbnailURL, p_userName, p_subject, p_post, p_postIndex + parsedPostsList.add(new Post(p_thumbnailURL, p_userName, p_subject, p_post, null, p_postIndex , p_postNum, p_postDate, p_profileURL, p_rank, p_specialRank, p_gender , p_numberOfPosts, p_personalText, p_numberOfStars, p_userColor , p_attachedFiles, p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL @@ -470,7 +470,7 @@ public class TopicParser { } else { //Deleted user //Add new post in postsList, only standard information needed parsedPostsList.add(new Post(p_thumbnailURL, p_userName, p_subject, p_post - , p_postIndex, p_postNum, p_postDate, p_userColor, p_attachedFiles + , null, p_postIndex, p_postNum, p_postDate, p_userColor, p_attachedFiles , p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL , p_isUserMentionedInPost, Post.TYPE_POST)); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java index 9560ef49..0c66ba83 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java @@ -25,6 +25,7 @@ public class Post extends TopicItem { private final String author; private String subject; private String content; + private String bbContent; private final int postIndex; private final int postNumber; private final String postDate; @@ -49,7 +50,8 @@ public class Post extends TopicItem { // Suppresses default constructor @SuppressWarnings("unused") - private Post() { + private Post(String bbContent) { + this.bbContent = bbContent; thumbnailUrl = ""; author = null; subject = null; @@ -79,11 +81,11 @@ public class Post extends TopicItem { * Constructor for active user's posts. All variables are declared final, once assigned they * can not change. Parameters notated as {@link Nullable} can either pass null or empty * (strings/ArrayList). - * - * @param thumbnailUrl author's thumbnail url + * @param thumbnailUrl author's thumbnail url * @param author author's username * @param subject post's subject * @param content post itself + * @param bbContent * @param postIndex post's index on the forum * @param postNumber posts index number on this topic * @param postDate date of submission @@ -100,12 +102,13 @@ public class Post extends TopicItem { * @param postURL post's URL */ public Post(@Nullable String thumbnailUrl, String author, String subject, String content - , int postIndex, int postNumber, String postDate, String profileURl, @Nullable String rank + , String bbContent, int postIndex, int postNumber, String postDate, String profileURl, @Nullable String rank , @Nullable String special_rank, @Nullable String gender, @Nullable String numberOfPosts , @Nullable String personalText, int numberOfStars, int userColor , @Nullable ArrayList attachedFiles, @Nullable String lastEdit, String postURL , @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost , int postType) { + this.bbContent = bbContent; if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null; else this.thumbnailUrl = thumbnailUrl; this.author = author; @@ -136,11 +139,11 @@ public class Post extends TopicItem { * Constructor for deleted user's posts. All variables are declared final, once assigned they * can not change. Parameters notated as {@link Nullable} can either pass null or empty * (strings/ArrayList). - * - * @param thumbnailUrl author's thumbnail url + * @param thumbnailUrl author's thumbnail url * @param author author's username * @param subject post's subject * @param content post itself + * @param bbContent post content in bb form * @param postIndex post's index on the forum * @param postNumber posts index number on this topic * @param postDate date of submission @@ -150,10 +153,11 @@ public class Post extends TopicItem { * @param postURL post's URL */ public Post(@Nullable String thumbnailUrl, String author, String subject, String content - , int postIndex, int postNumber, String postDate, int userColor + , String bbContent, int postIndex, int postNumber, String postDate, int userColor , @Nullable ArrayList attachedFiles, @Nullable String lastEdit, String postURL , @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost , int postType) { + this.bbContent = bbContent; if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null; else this.thumbnailUrl = thumbnailUrl; this.author = author; @@ -181,12 +185,12 @@ public class Post extends TopicItem { } public static Post newQuickReply() { - return new Post(null, null, null, null, 0, 0, null, + return new Post(null, null, null, null, null, 0, 0, null, 0, null, null, null, null, null, false, TYPE_QUICK_REPLY); } public static Post newQuickReply(String subject, String content) { - return new Post(null, null, subject, content, 0, 0, null, + return new Post(null, null, subject, null, content, 0, 0, null, 0, null, null, null, null, null, false, TYPE_QUICK_REPLY); } @@ -212,11 +216,20 @@ public class Post extends TopicItem { return content; } + public String getBbContent() { + return bbContent; + } + + public void setBbContent(String bbContent) { + this.bbContent = bbContent; + } + /** * Gets this post's author. * * @return post's author */ + @Nullable public String getAuthor() { return author; From 96798736e5cd9e84cc82514cb4ed86fb8ae5acdd Mon Sep 17 00:00:00 2001 From: oogee Date: Sun, 2 Dec 2018 17:09:34 +0200 Subject: [PATCH 092/104] fix bug when applying color to selected text --- .../thmmy/mthmmy/editorview/EditorView.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java index 55df571c..660dfd93 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java @@ -7,6 +7,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; +import android.os.AsyncTask; import android.text.Editable; import android.text.TextUtils; import android.util.AttributeSet; @@ -35,6 +36,7 @@ import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; +import timber.log.Timber; public class EditorView extends LinearLayout implements EmojiInputField { @@ -155,6 +157,9 @@ public class EditorView extends LinearLayout implements EmojiInputField { break; } case R.drawable.ic_format_color_text: { + boolean hadTextSelection = editText.hasSelection(); + int selectionStart = editText.getSelectionStart(); + int selectionEnd = editText.getSelectionEnd(); PopupWindow popupWindow = new PopupWindow(view.getContext()); popupWindow.setHeight(LayoutParams.WRAP_CONTENT); popupWindow.setWidth(LayoutParams.WRAP_CONTENT); @@ -165,14 +170,30 @@ public class EditorView extends LinearLayout implements EmojiInputField { for (int i = 0; i < colorPicker.getChildCount(); i++) { TextView child = (TextView) colorPicker.getChildAt(i); child.setOnClickListener(v -> { - boolean hadTextSelection = editText.hasSelection(); + boolean hadTextSelection2 = editText.hasSelection(); getText().insert(editText.getSelectionStart(), "[color=" + colors.get(v.getId()) + "]"); getText().insert(editText.getSelectionEnd(), "[/color]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); + editText.setSelection(hadTextSelection2 ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); popupWindow.dismiss(); }); } popupWindow.showAsDropDown(view); + 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); + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); break; } case R.drawable.ic_format_size: { From 275970492147ca1a1adede839763945ab9a3e39e Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 6 Dec 2018 19:12:03 +0200 Subject: [PATCH 093/104] support poll state after voting and with results hidden --- .../mthmmy/activities/topic/TopicAdapter.java | 38 ++++++++++++++++--- .../mthmmy/activities/topic/TopicParser.java | 29 +++++++++----- .../main/java/gr/thmmy/mthmmy/model/Poll.java | 9 ++++- .../main/res/layout/activity_topic_poll.xml | 1 + 4 files changed, 61 insertions(+), 16 deletions(-) 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 eb87fcdc..4258d00f 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 @@ -14,9 +14,11 @@ import android.os.Bundle; import android.text.Editable; import android.text.Html; import android.text.InputType; +import android.text.SpannableString; import android.text.TextUtils; import android.text.TextWatcher; import android.text.method.LinkMovementMethod; +import android.text.style.StyleSpan; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; @@ -171,7 +173,7 @@ class TopicAdapter extends RecyclerView.Adapter { boolean pollSupported = true; for (Poll.Entry entry : entries) { - if (ThmmyParser.containsHtml(entry.getEntryName())){ + if (ThmmyParser.containsHtml(entry.getEntryName())) { pollSupported = false; break; } @@ -204,9 +206,9 @@ class TopicAdapter extends RecyclerView.Adapter { final int accentColor = context.getResources().getColor(R.color.accent); if (poll.getAvailableVoteCount() > 1) { + // vote multiple options for (Poll.Entry entry : entries) { CheckBox checkBox = new CheckBox(context); - checkBox.setTextColor(primaryTextColor); checkBox.setMovementMethod(LinkMovementMethod.getInstance()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { checkBox.setText(Html.fromHtml(entry.getEntryName(), Html.FROM_HTML_MODE_LEGACY)); @@ -220,6 +222,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.voteChart.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.VISIBLE); } else if (poll.getAvailableVoteCount() == 1) { + // vote single option RadioGroup radioGroup = new RadioGroup(context); for (int i = 0; i < entries.length; i++) { RadioButton radioButton = new RadioButton(context); @@ -238,8 +241,33 @@ class TopicAdapter extends RecyclerView.Adapter { holder.optionsLayout.addView(radioGroup); holder.voteChart.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.VISIBLE); + } else if (poll.getSelectedEntryIndex() != -1) { + // vote already submitted but results are hidden + Poll.Entry[] entries1 = poll.getEntries(); + for (int i = 0; i < entries1.length; i++) { + Poll.Entry entry = entries1[i]; + TextView textView = new TextView(context); + textView.setMovementMethod(LinkMovementMethod.getInstance()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + textView.setText(Html.fromHtml(entry.getEntryName(), Html.FROM_HTML_MODE_LEGACY)); + } else { + //noinspection deprecation + textView.setText(Html.fromHtml(entry.getEntryName())); + } + textView.setTextColor(primaryTextColor); + if (poll.getSelectedEntryIndex() == i) { + // apply bold to the selected entry + SpannableString spanString = new SpannableString(textView.getText() + " ✓"); + spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString.length(), 0); + textView.setText(spanString); + textView.setTextColor(accentColor); + } + holder.optionsLayout.addView(textView); + } + holder.voteChart.setVisibility(View.GONE); + holder.optionsLayout.setVisibility(View.VISIBLE); } else { - //Showing results + // Showing results holder.optionsLayout.setVisibility(View.GONE); Arrays.sort(entries, (p1, p2) -> p1.getVotes() - p2.getVotes()); List valuesToCompare = new ArrayList<>(); @@ -274,7 +302,7 @@ class TopicAdapter extends RecyclerView.Adapter { barData.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> { DecimalFormat format = new DecimalFormat("###.#%"); double percentage = 0; - if(finalSum!=0) + if (finalSum != 0) percentage = ((double) value / (double) finalSum); return "" + (int) value + " (" + format.format(percentage) + ")"; }); @@ -764,7 +792,7 @@ class TopicAdapter extends RecyclerView.Adapter { } } - private void loadAvatar(String imageUrl, ImageView imageView){ + private void loadAvatar(String imageUrl, ImageView imageView) { Picasso.with(context) .load(imageUrl) .fit() 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 5cfcc2db..ca67957b 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 @@ -484,7 +484,7 @@ public class TopicParser { try { String question; ArrayList entries = new ArrayList<>(); - int availableVoteCount = 0; + int availableVoteCount = 0, selectedEntryIndex = -1; String pollFormUrl = null, sc = null, removeVoteUrl = null, showVoteResultsUrl = null, showOptionsUrl = null; @@ -525,19 +525,30 @@ public class TopicParser { } } else { // poll in results mode + boolean pollResultsHidden = false; Elements entryRows = pollColumn.select("table[cellspacing] tr"); - for (Element entryRow : entryRows) { + for (int i = 0; i < entryRows.size(); i++) { + Element entryRow = entryRows.get(i); Elements entryColumns = entryRow.select("td"); + + if (entryColumns.size() < 2) pollResultsHidden = true; + String optionName = entryColumns.first().html(); - String voteCountDescription = entryColumns.last().text(); - Matcher integerMatcher = integerPattern.matcher(voteCountDescription); int voteCount = 0; - if (integerMatcher.find()) { - voteCount = Integer.parseInt(voteCountDescription.substring(integerMatcher.start(), - integerMatcher.end())); + + if (pollResultsHidden) { + if (entryColumns.first().attr("style").contains("font-weight: bold;")) + selectedEntryIndex = i; + } else { + String voteCountDescription = entryColumns.last().text(); + Matcher integerMatcher = integerPattern.matcher(voteCountDescription); + if (integerMatcher.find()) { + voteCount = Integer.parseInt(voteCountDescription.substring(integerMatcher.start(), + integerMatcher.end())); + } } - entries.add(0, new Poll.Entry(optionName, voteCount)); + entries.add(new Poll.Entry(optionName, voteCount)); } Elements links = pollColumn.select("td[style=padding-left: 15px;] > a"); @@ -549,7 +560,7 @@ public class TopicParser { } } return new Poll(question, entries.toArray(new Poll.Entry[0]), availableVoteCount, - pollFormUrl, sc, removeVoteUrl, showVoteResultsUrl, showOptionsUrl); + pollFormUrl, sc, removeVoteUrl, showVoteResultsUrl, showOptionsUrl, selectedEntryIndex); } catch (Exception e) { Timber.v(e, "Could not parse a poll"); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java b/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java index e0d544f6..ffd98e4d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java @@ -7,11 +7,11 @@ public class Poll extends TopicItem { private final String question; private Entry[] entries; - private int availableVoteCount; + private int availableVoteCount, selectedEntryIndex = -1; private String pollFormUrl, sc, removeVoteUrl, showVoteResultsUrl, showOptionsUrl; public Poll(String question, Entry[] entries, int availableVoteCount, String pollFormUrl, String sc, - String removeVoteUrl, String showVoteResultsUrl, String showOptionsUrl) { + String removeVoteUrl, String showVoteResultsUrl, String showOptionsUrl, int selectedEntryIndex) { this.question = question; this.entries = entries; this.availableVoteCount = availableVoteCount; @@ -20,6 +20,7 @@ public class Poll extends TopicItem { this.removeVoteUrl = removeVoteUrl; this.showVoteResultsUrl = showVoteResultsUrl; this.showOptionsUrl = showOptionsUrl; + this.selectedEntryIndex = selectedEntryIndex; } private int totalVotes() { @@ -68,6 +69,10 @@ public class Poll extends TopicItem { return showOptionsUrl; } + public int getSelectedEntryIndex() { + return selectedEntryIndex; + } + public static class Entry { private final String entryName; private int votes; diff --git a/app/src/main/res/layout/activity_topic_poll.xml b/app/src/main/res/layout/activity_topic_poll.xml index 056ae2ca..285c740b 100644 --- a/app/src/main/res/layout/activity_topic_poll.xml +++ b/app/src/main/res/layout/activity_topic_poll.xml @@ -16,6 +16,7 @@ android:id="@+id/options_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="8dp" android:orientation="vertical" /> Date: Mon, 10 Dec 2018 22:58:35 +0200 Subject: [PATCH 094/104] don't support polls with more than 30 options --- .../java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java | 2 ++ 1 file changed, 2 insertions(+) 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 4258d00f..2c80ae68 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 @@ -180,6 +180,8 @@ class TopicAdapter extends RecyclerView.Adapter { } if (ThmmyParser.containsHtml(poll.getQuestion())) pollSupported = false; + if (entries.length > 30) + pollSupported = false; if (!pollSupported) { holder.optionsLayout.setVisibility(View.GONE); holder.voteChart.setVisibility(View.GONE); From 36a67fa902f2d2e7aa3312b04b3c1a6e1b1f0241 Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 13 Dec 2018 12:59:18 +0200 Subject: [PATCH 095/104] rollback okhttp timeouts --- app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 02984c53..12e019d3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -110,7 +110,9 @@ public class BaseApplication extends Application { } return chain.proceed(request); }) - .callTimeout(30, TimeUnit.SECONDS); + .connectTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Just for KitKats // Necessary because our servers don't have the right cipher suites. From 2ebff4eda8413a98de2d20472a039e1318cb5a22 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 13 Dec 2018 14:19:29 +0200 Subject: [PATCH 096/104] Suppressed redundant color selection fix for newer devices increased OkHttp timeouts, up libs --- app/build.gradle | 10 +- .../gr/thmmy/mthmmy/base/BaseApplication.java | 6 +- .../thmmy/mthmmy/editorview/EditorView.java | 401 ++++++++++-------- 3 files changed, 239 insertions(+), 178 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d414755a..323b170b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -70,26 +70,26 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' - implementation 'com.google.firebase:firebase-core:16.0.5' + implementation 'com.google.firebase:firebase-core:16.0.6' implementation 'com.google.firebase:firebase-messaging:17.3.4' - implementation 'com.crashlytics.sdk.android:crashlytics:2.9.6' + implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7' implementation 'com.squareup.okhttp3:okhttp:3.12.0' implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' implementation 'org.jsoup:jsoup:1.10.3' //TODO: Warning: upgrading from 1.10.3 will break stuff! implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' - implementation "com.mikepenz:materialdrawer:6.1.1" + implementation 'com.mikepenz:materialdrawer:6.1.1' implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar' implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15' implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated! implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2' implementation 'com.jakewharton.timber:timber:4.7.1' - implementation "ru.noties:markwon:2.0.0" + implementation 'ru.noties:markwon:2.0.0' implementation 'net.gotev:uploadservice:3.4.2' implementation 'net.gotev:uploadservice-okhttp:3.4.2' - debugImplementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.4' //Plugin: https://plugins.jetbrains.com/plugin/11249-okhttp-profiler + debugImplementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.4' //Plugin: https://plugins.jetbrains.com/plugin/11249-okhttp-profiler } apply plugin: 'com.google.gms.google-services' 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 12e019d3..ce4e4068 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -110,9 +110,9 @@ public class BaseApplication extends Application { } return chain.proceed(request); }) - .connectTimeout(30, TimeUnit.SECONDS) - .writeTimeout(30, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS); + .connectTimeout(40, TimeUnit.SECONDS) + .writeTimeout(40, TimeUnit.SECONDS) + .readTimeout(40, TimeUnit.SECONDS); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Just for KitKats // Necessary because our servers don't have the right cipher suites. diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java index 660dfd93..3b41d07c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java @@ -8,6 +8,7 @@ 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; @@ -126,184 +127,244 @@ public class EditorView extends LinearLayout implements EmojiInputField { getResources().getDimension(R.dimen.editor_format_button_margin_between); int columns = (int) Math.floor(displayMetrics.widthPixels / itemWidth); formatButtonsRecyclerview.setLayoutManager(new GridLayoutManager(context, columns)); - formatButtonsRecyclerview.setAdapter(new FormatButtonsAdapter((view, drawableId) -> { - switch (drawableId) { - case R.drawable.ic_format_bold: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[b]"); - getText().insert(editText.getSelectionEnd(), "[/b]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); - break; - } - case R.drawable.ic_format_italic: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[i]"); - getText().insert(editText.getSelectionEnd(), "[/i]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); - break; - } - case R.drawable.ic_format_underlined: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[u]"); - getText().insert(editText.getSelectionEnd(), "[/u]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); - break; - } - case R.drawable.ic_strikethrough_s: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[s]"); - getText().insert(editText.getSelectionEnd(), "[/s]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); - break; - } - case R.drawable.ic_format_color_text: { - boolean hadTextSelection = editText.hasSelection(); - int selectionStart = editText.getSelectionStart(); - int selectionEnd = editText.getSelectionEnd(); - PopupWindow popupWindow = new PopupWindow(view.getContext()); - popupWindow.setHeight(LayoutParams.WRAP_CONTENT); - popupWindow.setWidth(LayoutParams.WRAP_CONTENT); - popupWindow.setFocusable(true); - ScrollView colorPickerScrollview = (ScrollView) LayoutInflater.from(context).inflate(R.layout.editor_view_color_picker, null); - LinearLayout colorPicker = (LinearLayout) colorPickerScrollview.getChildAt(0); - popupWindow.setContentView(colorPickerScrollview); - for (int i = 0; i < colorPicker.getChildCount(); i++) { - TextView child = (TextView) colorPicker.getChildAt(i); - child.setOnClickListener(v -> { - boolean hadTextSelection2 = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[color=" + colors.get(v.getId()) + "]"); - getText().insert(editText.getSelectionEnd(), "[/color]"); - editText.setSelection(hadTextSelection2 ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); - popupWindow.dismiss(); + formatButtonsRecyclerview.setAdapter( + new FormatButtonsAdapter( + (view, drawableId) -> { + boolean hadTextSelection; + switch (drawableId) { + case R.drawable.ic_format_bold: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[b]"); + getText().insert(editText.getSelectionEnd(), "[/b]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 4); + break; + case R.drawable.ic_format_italic: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[i]"); + getText().insert(editText.getSelectionEnd(), "[/i]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 4); + break; + case R.drawable.ic_format_underlined: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[u]"); + getText().insert(editText.getSelectionEnd(), "[/u]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 4); + break; + case R.drawable.ic_strikethrough_s: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[s]"); + getText().insert(editText.getSelectionEnd(), "[/s]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 4); + break; + case R.drawable.ic_format_color_text: + int selectionStart = editText.getSelectionStart(); + int selectionEnd = editText.getSelectionEnd(); + PopupWindow popupWindow = new PopupWindow(view.getContext()); + popupWindow.setHeight(LayoutParams.WRAP_CONTENT); + popupWindow.setWidth(LayoutParams.WRAP_CONTENT); + popupWindow.setFocusable(true); + ScrollView colorPickerScrollview = + (ScrollView) + LayoutInflater.from(context) + .inflate(R.layout.editor_view_color_picker, null); + LinearLayout colorPicker = (LinearLayout) colorPickerScrollview.getChildAt(0); + popupWindow.setContentView(colorPickerScrollview); + for (int i = 0; i < colorPicker.getChildCount(); i++) { + TextView child = (TextView) colorPicker.getChildAt(i); + child.setOnClickListener( + v -> { + boolean hadTextSelection2 = editText.hasSelection(); + getText() + .insert( + editText.getSelectionStart(), + "[color=" + colors.get(v.getId()) + "]"); + getText().insert(editText.getSelectionEnd(), "[/color]"); + editText.setSelection( + hadTextSelection2 + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 8); + popupWindow.dismiss(); }); - } - popupWindow.showAsDropDown(view); + } + 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 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); - } + @Override + protected void onPostExecute(Void aVoid) { + editText.setSelection(selectionStart, selectionEnd); + } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - break; - } - case R.drawable.ic_format_size: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[size=10pt]"); - getText().insert(editText.getSelectionEnd(), "[/size]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); - break; - } - case R.drawable.ic_text_format: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[font=Verdana]"); - getText().insert(editText.getSelectionEnd(), "[/font]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); - break; - } - case R.drawable.ic_format_list_bulleted: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[list]\n[li]"); - getText().insert(editText.getSelectionEnd(), "[/li]\n[li][/li]\n[/list]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() - 13 : editText.getSelectionStart() - 23); - break; - } - case R.drawable.ic_format_align_left: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[left]"); - getText().insert(editText.getSelectionEnd(), "[/left]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); - break; - } - case R.drawable.ic_format_align_center: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[center]"); - getText().insert(editText.getSelectionEnd(), "[/center]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 9); - break; - } - case R.drawable.ic_format_align_right: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[right]"); - getText().insert(editText.getSelectionEnd(), "[/right]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); - break; - } - case R.drawable.ic_insert_link: { - LinearLayout dialogBody = (LinearLayout) LayoutInflater.from(context) - .inflate(R.layout.dialog_create_link, null); - TextInputLayout linkUrl = dialogBody.findViewById(R.id.link_url_input); - linkUrl.setOnClickListener(view1 -> linkUrl.setError(null)); - TextInputLayout linkText = dialogBody.findViewById(R.id.link_text_input); - linkText.setOnClickListener(view2 -> linkText.setError(null)); - boolean hadTextSelection = editText.hasSelection(); - int start = editText.getSelectionStart(), end = editText.getSelectionEnd(); - if (editText.hasSelection()) { - linkText.getEditText().setText( - editText.getText().toString().substring(editText.getSelectionStart(), editText.getSelectionEnd())); - } - AlertDialog linkDialog = new AlertDialog.Builder(context, R.style.AppTheme_Dark_Dialog) - .setTitle(R.string.dialog_create_link_title) - .setView(dialogBody) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()) - .create(); - linkDialog.setOnShowListener(dialogInterface -> { + } + break; + case R.drawable.ic_format_size: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[size=10pt]"); + getText().insert(editText.getSelectionEnd(), "[/size]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 7); + break; + case R.drawable.ic_text_format: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[font=Verdana]"); + getText().insert(editText.getSelectionEnd(), "[/font]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 7); + break; + case R.drawable.ic_format_list_bulleted: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[list]\n[li]"); + getText().insert(editText.getSelectionEnd(), "[/li]\n[li][/li]\n[/list]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() - 13 + : editText.getSelectionStart() - 23); + break; + case R.drawable.ic_format_align_left: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[left]"); + getText().insert(editText.getSelectionEnd(), "[/left]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 7); + break; + case R.drawable.ic_format_align_center: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[center]"); + getText().insert(editText.getSelectionEnd(), "[/center]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 9); + break; + case R.drawable.ic_format_align_right: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[right]"); + getText().insert(editText.getSelectionEnd(), "[/right]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 8); + break; + case R.drawable.ic_insert_link: + LinearLayout dialogBody = + (LinearLayout) + LayoutInflater.from(context).inflate(R.layout.dialog_create_link, null); + TextInputLayout linkUrl = dialogBody.findViewById(R.id.link_url_input); + linkUrl.setOnClickListener(view1 -> linkUrl.setError(null)); + TextInputLayout linkText = dialogBody.findViewById(R.id.link_text_input); + linkText.setOnClickListener(view2 -> linkText.setError(null)); + hadTextSelection = editText.hasSelection(); + int start = editText.getSelectionStart(), end = editText.getSelectionEnd(); + if (editText.hasSelection()) { + linkText + .getEditText() + .setText( + editText + .getText() + .toString() + .substring( + editText.getSelectionStart(), editText.getSelectionEnd())); + } + AlertDialog linkDialog = + new AlertDialog.Builder(context, R.style.AppTheme_Dark_Dialog) + .setTitle(R.string.dialog_create_link_title) + .setView(dialogBody) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()) + .create(); + linkDialog.setOnShowListener( + dialogInterface -> { Button button = linkDialog.getButton(AlertDialog.BUTTON_POSITIVE); - button.setOnClickListener(view12 -> { - if (TextUtils.isEmpty(Objects.requireNonNull(linkUrl.getEditText()).getText().toString())) { + button.setOnClickListener( + view12 -> { + if (TextUtils.isEmpty( + Objects.requireNonNull(linkUrl.getEditText()) + .getText() + .toString())) { linkUrl.setError(context.getString(R.string.input_field_required)); return; - } - - if (hadTextSelection) editText.getText().delete(start, end); - if (!TextUtils.isEmpty(linkText.getEditText().getText())) { - getText().insert(editText.getSelectionStart(), "[url=" + - linkUrl.getEditText().getText().toString() + "]" + - linkText.getEditText().getText().toString() + "[/url]"); - } - else - getText().insert(editText.getSelectionStart(), "[url]" + - linkUrl.getEditText().getText().toString() + "[/url]"); - linkDialog.dismiss(); - }); - }); - linkDialog.show(); - break; - } - case R.drawable.ic_format_quote: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[quote]"); - getText().insert(editText.getSelectionEnd(), "[/quote]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); - break; - } - case R.drawable.ic_code: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[code]"); - getText().insert(editText.getSelectionEnd(), "[/code]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); - break; - } - case R.drawable.ic_functions: { - boolean hadTextSelection = editText.hasSelection(); - getText().insert(editText.getSelectionStart(), "[tex]"); - getText().insert(editText.getSelectionEnd(), "[/tex]"); - editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 6); - break; - } - default: throw new IllegalArgumentException("Unknown format button click"); - } - })); + } + + if (hadTextSelection) editText.getText().delete(start, end); + if (!TextUtils.isEmpty(linkText.getEditText().getText())) { + getText() + .insert( + editText.getSelectionStart(), + "[url=" + + linkUrl.getEditText().getText().toString() + + "]" + + linkText.getEditText().getText().toString() + + "[/url]"); + } else + getText() + .insert( + editText.getSelectionStart(), + "[url]" + + linkUrl.getEditText().getText().toString() + + "[/url]"); + linkDialog.dismiss(); + }); + }); + linkDialog.show(); + break; + case R.drawable.ic_format_quote: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[quote]"); + getText().insert(editText.getSelectionEnd(), "[/quote]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 8); + break; + case R.drawable.ic_code: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[code]"); + getText().insert(editText.getSelectionEnd(), "[/code]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 7); + break; + case R.drawable.ic_functions: + hadTextSelection = editText.hasSelection(); + getText().insert(editText.getSelectionStart(), "[tex]"); + getText().insert(editText.getSelectionEnd(), "[/tex]"); + editText.setSelection( + hadTextSelection + ? editText.getSelectionEnd() + : editText.getSelectionStart() - 6); + break; + default: + throw new IllegalArgumentException("Unknown format button click"); + } + })); emojiButton.setOnClickListener(view -> { InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); From 3bda253ec4a2d33b5da18f3c11a264b4020be31a Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 13 Dec 2018 16:28:16 +0200 Subject: [PATCH 097/104] use thread pool executor on most async tasks --- .../mthmmy/activities/board/BoardActivity.java | 2 +- .../activities/downloads/DownloadsActivity.java | 6 +++--- .../activities/main/forum/ForumFragment.java | 8 ++++---- .../activities/main/recent/RecentFragment.java | 5 +++-- .../activities/main/unread/UnreadFragment.java | 10 +++++----- .../activities/profile/ProfileActivity.java | 2 +- .../profile/latestPosts/LatestPostsFragment.java | 4 ++-- .../activities/profile/stats/StatsFragment.java | 2 +- .../profile/summary/SummaryFragment.java | 2 +- .../activities/shoutbox/ShoutboxFragment.java | 3 ++- .../mthmmy/activities/upload/UploadActivity.java | 2 +- .../mthmmy/viewmodel/ShoutboxViewModel.java | 2 +- .../thmmy/mthmmy/viewmodel/TopicViewModel.java | 16 ++++++++-------- 13 files changed, 33 insertions(+), 31 deletions(-) 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 69739514..54d2b226 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 @@ -149,7 +149,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo }); boardTask = new BoardTask(); - boardTask.execute(boardUrl); + boardTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, boardUrl); } @Override 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 0d9cfd26..addccf35 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 @@ -118,7 +118,7 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter. // uploadFAB.hide(); parseDownloadPageTask = new ParseDownloadPageTask(); - parseDownloadPageTask.execute(downloadsUrl); + parseDownloadPageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, downloadsUrl); } // @Override @@ -154,9 +154,9 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter. //Load data parseDownloadPageTask = new ParseDownloadPageTask(); if (downloadsUrl.contains("tpstart")) - parseDownloadPageTask.execute(downloadsUrl.substring(0 + parseDownloadPageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, downloadsUrl.substring(0 , downloadsUrl.lastIndexOf(";tpstart=")) + ";tpstart=" + pagesLoaded * 10); - else parseDownloadPageTask.execute(downloadsUrl + ";tpstart=" + pagesLoaded * 10); + else parseDownloadPageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, downloadsUrl + ";tpstart=" + pagesLoaded * 10); } } 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 d2ddcfb5..70e78af5 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 @@ -90,7 +90,7 @@ public class ForumFragment extends BaseFragment { super.onActivityCreated(savedInstanceState); if (categories.isEmpty()) { forumTask = new ForumTask(this::onForumTaskStarted, this::onForumTaskFinished); - forumTask.execute(); + forumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } Timber.d("onActivityCreated"); @@ -114,7 +114,7 @@ public class ForumFragment extends BaseFragment { forumTask.cancel(true); forumTask = new ForumTask(ForumFragment.this::onForumTaskStarted, ForumFragment.this::onForumTaskFinished); forumTask.setUrl(categories.get(parentPosition).getCategoryURL()); - forumTask.execute(); + forumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } @@ -125,7 +125,7 @@ public class ForumFragment extends BaseFragment { forumTask.cancel(true); forumTask = new ForumTask(ForumFragment.this::onForumTaskStarted, ForumFragment.this::onForumTaskFinished); forumTask.setUrl(categories.get(parentPosition).getCategoryURL()); - forumTask.execute(); + forumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } }); @@ -145,7 +145,7 @@ public class ForumFragment extends BaseFragment { if (forumTask != null && forumTask.getStatus() != AsyncTask.Status.RUNNING) { forumTask = new ForumTask(ForumFragment.this::onForumTaskStarted, ForumFragment.this::onForumTaskFinished); //forumTask.execute(SessionManager.indexUrl.toString()); - forumTask.execute(); + forumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } ); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 70a0eed9..6c194c0e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -1,5 +1,6 @@ package gr.thmmy.mthmmy.activities.main.recent; +import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -81,7 +82,7 @@ public class RecentFragment extends BaseFragment { super.onActivityCreated(savedInstanceState); if (topicSummaries.isEmpty()) { recentTask = new RecentTask(this::onRecentTaskStarted, this::onRecentTaskFinished); - recentTask.execute(SessionManager.indexUrl.toString()); + recentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.indexUrl.toString()); } Timber.d("onActivityCreated"); @@ -113,7 +114,7 @@ public class RecentFragment extends BaseFragment { swipeRefreshLayout.setOnRefreshListener(() -> { if (!recentTask.isRunning()) { recentTask = new RecentTask(this::onRecentTaskStarted, this::onRecentTaskFinished); - recentTask.execute(SessionManager.indexUrl.toString()); + recentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.indexUrl.toString()); } } ); 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 79b21b03..0c47bac5 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 @@ -88,7 +88,7 @@ public class UnreadFragment extends BaseFragment { if (topicSummaries.isEmpty()) { unreadTask = new UnreadTask(this::onUnreadTaskStarted, this::onUnreadTaskFinished); assert SessionManager.unreadUrl != null; - unreadTask.execute(SessionManager.unreadUrl.toString()); + unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl.toString()); } markReadTask = new MarkReadTask(); Timber.d("onActivityCreated"); @@ -108,7 +108,7 @@ public class UnreadFragment extends BaseFragment { fragmentInteractionListener, markReadLinkUrl -> { if (!markReadTask.isRunning() && !unreadTask.isRunning()) { markReadTask = new MarkReadTask(); - markReadTask.execute(markReadLinkUrl); + markReadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, markReadLinkUrl); } }); @@ -130,7 +130,7 @@ public class UnreadFragment extends BaseFragment { loadedPages = 0; unreadTask = new UnreadTask(this::onUnreadTaskStarted, this::onUnreadTaskFinished); assert SessionManager.unreadUrl != null; - unreadTask.execute(SessionManager.unreadUrl.toString()); + unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl.toString()); } } ); @@ -171,7 +171,7 @@ public class UnreadFragment extends BaseFragment { if (loadedPages < numberOfPages) { unreadTask = new UnreadTask(this::onUnreadTaskStarted, this::onUnreadTaskFinished); assert SessionManager.unreadUrl != null; - unreadTask.execute(SessionManager.unreadUrl.toString() + ";start=" + loadedPages * 20); + unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl.toString() + ";start=" + loadedPages * 20); } else { progressBar.setVisibility(ProgressBar.INVISIBLE); @@ -306,7 +306,7 @@ public class UnreadFragment extends BaseFragment { loadedPages = 0; unreadTask = new UnreadTask(UnreadFragment.this::onUnreadTaskStarted, UnreadFragment.this::onUnreadTaskFinished); assert SessionManager.unreadUrl != null; - unreadTask.execute(SessionManager.unreadUrl.toString()); + unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl.toString()); } } } 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 db6d9238..247365c8 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 @@ -187,7 +187,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment } profileTask = new ProfileTask(); - profileTask.execute(profileUrl + ";wap"); //Attempts data parsing + profileTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";wap"); //Attempts data parsing } @Override diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index 04f20b60..f2c17ff2 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -122,7 +122,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap //Load data profileLatestPostsTask = new LatestPostsTask(); - profileLatestPostsTask.execute(profileUrl + ";sa=showPosts;start=" + pagesLoaded * 15); + profileLatestPostsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";sa=showPosts;start=" + pagesLoaded * 15); ++pagesLoaded; } } @@ -132,7 +132,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap super.onActivityCreated(savedInstanceState); if (parsedTopicSummaries.isEmpty() && userHasPosts) { profileLatestPostsTask = new LatestPostsTask(); - profileLatestPostsTask.execute(profileUrl + ";sa=showPosts"); + profileLatestPostsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";sa=showPosts"); pagesLoaded = 1; } } 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 70e82fba..fbf498c5 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 @@ -105,7 +105,7 @@ public class StatsFragment extends Fragment { super.onActivityCreated(savedInstanceState); if (!haveParsed) { profileStatsTask = new ProfileStatsTask(); - profileStatsTask.execute(profileUrl + ";sa=statPanel"); + profileStatsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";sa=statPanel"); } Timber.d("onActivityCreated"); } 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 264f7842..12e93a60 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 @@ -90,7 +90,7 @@ public class SummaryFragment extends Fragment { super.onActivityCreated(savedInstanceState); if (parsedProfileSummaryData.isEmpty()) { summaryTask = new SummaryTask(); - summaryTask.execute(profileSummaryDocument); + summaryTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileSummaryDocument); } Timber.d("onActivityCreated"); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java index 0bcf9a75..4c2590b5 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java @@ -1,6 +1,7 @@ package gr.thmmy.mthmmy.activities.shoutbox; import android.app.Activity; +import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; @@ -137,7 +138,7 @@ public class ShoutboxFragment extends Fragment { Timber.i("Shout was sent successfully"); editorView.getEditText().getText().clear(); shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); - shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); + shoutboxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.shoutboxUrl.toString()); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Timber.w("Failed to send shout"); Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); 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 44988402..974b8b20 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 @@ -332,7 +332,7 @@ public class UploadActivity extends BaseActivity { if (uploadRootCategories.isEmpty()) { //Parses the uploads page parseUploadPageTask = new ParseUploadPageTask(); - parseUploadPageTask.execute(uploadIndexUrl); + parseUploadPageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, uploadIndexUrl); } else { //Renders the already parsed data updateUIElements(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java index 5aa92f65..88e34386 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java @@ -21,7 +21,7 @@ public class ShoutboxViewModel extends ViewModel { if (shoutboxTask != null && shoutboxTask.getStatus() == AsyncTask.Status.RUNNING) shoutboxTask.cancel(true); shoutboxTask = new ShoutboxTask(onShoutboxTaskStarted, onShoutboxTaskFinished); - shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); + shoutboxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.shoutboxUrl.toString()); } public void sendShout(String shout) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index 1bbfa9c8..4c6310d6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -95,7 +95,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa stopLoading(); topicUrl = pageUrl; currentTopicTask = new TopicTask(topicTaskObserver, this); - currentTopicTask.execute(pageUrl); + currentTopicTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, pageUrl); } public void reloadPage() { @@ -122,7 +122,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa TopicViewModel.this.onTopicTaskCompleted(result); runnable.run(); }); - currentTopicTask.execute(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15)); + currentTopicTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15)); } public void loadPageIndicated() { @@ -158,7 +158,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa SubmitVoteTask submitVoteTask = new SubmitVoteTask(votesArray); submitVoteTask.setOnTaskStartedListener(voteTaskStartedListener); submitVoteTask.setOnNetworkTaskFinishedListener(voteTaskFinishedListener); - submitVoteTask.execute(poll.getPollFormUrl(), poll.getSc()); + submitVoteTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, poll.getPollFormUrl(), poll.getSc()); return true; } @@ -167,7 +167,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa RemoveVoteTask removeVoteTask = new RemoveVoteTask(); removeVoteTask.setOnTaskStartedListener(removeVoteTaskStartedListener); removeVoteTask.setOnNetworkTaskFinishedListener(removeVoteTaskFinishedListener); - removeVoteTask.execute(((Poll) topicItems.getValue().get(0)).getRemoveVoteUrl()); + removeVoteTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ((Poll) topicItems.getValue().get(0)).getRemoveVoteUrl()); } public void prepareForReply() { @@ -194,13 +194,13 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa } toQuoteList.clear(); Timber.i("Posting reply"); - new ReplyTask(replyFinishListener, includeAppSignature).execute(subject, reply, + new ReplyTask(replyFinishListener, includeAppSignature).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, subject, reply, replyForm.getNumReplies(), replyForm.getSeqnum(), replyForm.getSc(), replyForm.getTopic()); } public void deletePost(String postDeleteUrl) { Timber.i("Deleting post"); - new DeleteTask(deleteTaskStartedListener, deleteTaskFinishedListener).execute(postDeleteUrl); + new DeleteTask(deleteTaskStartedListener, deleteTaskFinishedListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, postDeleteUrl); } public void prepareForEdit(int position, String postEditURL) { @@ -210,7 +210,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa Timber.i("Preparing for edit"); currentPrepareForEditTask = new PrepareForEditTask(prepareForEditCallbacks, this, position, replyPageUrl.getValue()); - currentPrepareForEditTask.execute(postEditURL); + currentPrepareForEditTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, postEditURL); } public void editPost(int position, String subject, String message) { @@ -218,7 +218,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa throw new NullPointerException("Edit preparation was not found!"); PrepareForEditResult editResult = prepareForEditResult.getValue(); Timber.i("Editing post"); - new EditTask(editTaskCallbacks, position).execute(editResult.getCommitEditUrl(), message, + new EditTask(editTaskCallbacks, position).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, editResult.getCommitEditUrl(), message, editResult.getNumReplies(), editResult.getSeqnum(), editResult.getSc(), subject, editResult.getTopic()); } From a23c61a475ad1336c510b17021adde587b4b75f5 Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 13 Dec 2018 16:30:45 +0200 Subject: [PATCH 098/104] move text changes saving in onTextChanged() rather that afterTextChanged() --- .../gr/thmmy/mthmmy/activities/topic/TopicAdapter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 2c80ae68..c45a7524 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 @@ -691,12 +691,12 @@ class TopicAdapter extends RecyclerView.Adapter { @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - + ((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(charSequence.toString()); } @Override public void afterTextChanged(Editable editable) { - ((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(editable.toString()); + } }); @@ -712,12 +712,12 @@ class TopicAdapter extends RecyclerView.Adapter { @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - + ((Post) topicItems.get(holder.getAdapterPosition())).setSubject(charSequence.toString()); } @Override public void afterTextChanged(Editable editable) { - ((Post) topicItems.get(holder.getAdapterPosition())).setSubject(editable.toString()); + } }); } else if (currentHolder instanceof EditMessageViewHolder) { From 627f5210b21e1b0c0fdb303ce5382f8d6cda612c Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 13 Dec 2018 18:04:03 +0200 Subject: [PATCH 099/104] serially execute topic's UI changing tasks --- .../mthmmy/activities/shoutbox/ShoutboxFragment.java | 2 +- .../gr/thmmy/mthmmy/activities/topic/TopicAdapter.java | 8 ++++---- .../java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java | 2 +- .../java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java index 4c2590b5..0c2d8ae5 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java @@ -138,7 +138,7 @@ public class ShoutboxFragment extends Fragment { Timber.i("Shout was sent successfully"); editorView.getEditText().getText().clear(); shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); - shoutboxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.shoutboxUrl.toString()); + shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Timber.w("Failed to send shout"); Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); 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 c45a7524..f3557d8e 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 @@ -762,12 +762,12 @@ class TopicAdapter extends RecyclerView.Adapter { @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - + ((Post) topicItems.get(holder.getAdapterPosition())).setSubject(charSequence.toString()); } @Override public void afterTextChanged(Editable editable) { - ((Post) topicItems.get(holder.getAdapterPosition())).setSubject(editable.toString()); + } }); holder.editEditor.getEditText().addTextChangedListener(new TextWatcher() { @@ -778,12 +778,12 @@ class TopicAdapter extends RecyclerView.Adapter { @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - + ((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(charSequence.toString()); } @Override public void afterTextChanged(Editable editable) { - ((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(editable.toString()); + } }); if (backPressHidden) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java index 88e34386..5aa92f65 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java @@ -21,7 +21,7 @@ public class ShoutboxViewModel extends ViewModel { if (shoutboxTask != null && shoutboxTask.getStatus() == AsyncTask.Status.RUNNING) shoutboxTask.cancel(true); shoutboxTask = new ShoutboxTask(onShoutboxTaskStarted, onShoutboxTaskFinished); - shoutboxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.shoutboxUrl.toString()); + shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); } public void sendShout(String shout) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index 4c6310d6..a7e72883 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -95,7 +95,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa stopLoading(); topicUrl = pageUrl; currentTopicTask = new TopicTask(topicTaskObserver, this); - currentTopicTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, pageUrl); + currentTopicTask.execute(pageUrl); } public void reloadPage() { @@ -122,7 +122,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa TopicViewModel.this.onTopicTaskCompleted(result); runnable.run(); }); - currentTopicTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15)); + currentTopicTask.execute(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15)); } public void loadPageIndicated() { @@ -210,7 +210,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa Timber.i("Preparing for edit"); currentPrepareForEditTask = new PrepareForEditTask(prepareForEditCallbacks, this, position, replyPageUrl.getValue()); - currentPrepareForEditTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, postEditURL); + currentPrepareForEditTask.execute(postEditURL); } public void editPost(int position, String subject, String message) { From de01968fc7d6ae63cce012682cc3a0b6c2bf79a2 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Fri, 14 Dec 2018 15:29:26 +0200 Subject: [PATCH 100/104] Color contrast fixes --- app/src/main/assets/style.css | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/style.css b/app/src/main/assets/style.css index d870a911..7415c141 100644 --- a/app/src/main/assets/style.css +++ b/app/src/main/assets/style.css @@ -520,4 +520,21 @@ img .customSignature{ background: #323232; -} \ No newline at end of file +} + +[style="color: blue;"] +{ + color: #3452fe !important; +} + +[style="color: purple;"] +{ + color: #a511a5 !important; +} + +[style="color: maroon;"] +{ + color: #a51111 !important; +} + + From 7f4ee627778b92f31496ccbbf181a86f24b4673c Mon Sep 17 00:00:00 2001 From: oogee Date: Sun, 16 Dec 2018 14:16:16 +0200 Subject: [PATCH 101/104] show voted option in results --- .../mthmmy/activities/topic/TopicAdapter.java | 15 +++++++++++++-- .../mthmmy/activities/topic/TopicParser.java | 13 ++++++------- app/src/main/java/gr/thmmy/mthmmy/model/Poll.java | 8 +++++++- app/src/main/res/layout/activity_topic_poll.xml | 8 ++++++++ 4 files changed, 34 insertions(+), 10 deletions(-) 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 f3557d8e..345fa9e2 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 @@ -185,6 +185,7 @@ class TopicAdapter extends RecyclerView.Adapter { if (!pollSupported) { holder.optionsLayout.setVisibility(View.GONE); holder.voteChart.setVisibility(View.GONE); + holder.selectedEntry.setVisibility(View.GONE); holder.removeVotesButton.setVisibility(View.GONE); holder.showPollResultsButton.setVisibility(View.GONE); holder.hidePollResultsButton.setVisibility(View.GONE); @@ -222,6 +223,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.optionsLayout.addView(checkBox); } holder.voteChart.setVisibility(View.GONE); + holder.selectedEntry.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.VISIBLE); } else if (poll.getAvailableVoteCount() == 1) { // vote single option @@ -242,8 +244,9 @@ class TopicAdapter extends RecyclerView.Adapter { } holder.optionsLayout.addView(radioGroup); holder.voteChart.setVisibility(View.GONE); + holder.selectedEntry.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.VISIBLE); - } else if (poll.getSelectedEntryIndex() != -1) { + } else if (poll.isPollResultsHidden()) { // vote already submitted but results are hidden Poll.Entry[] entries1 = poll.getEntries(); for (int i = 0; i < entries1.length; i++) { @@ -267,6 +270,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.optionsLayout.addView(textView); } holder.voteChart.setVisibility(View.GONE); + holder.selectedEntry.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.VISIBLE); } else { // Showing results @@ -316,6 +320,12 @@ class TopicAdapter extends RecyclerView.Adapter { holder.voteChart.setMinimumHeight((int) (chartHeightDp * (metrics.densityDpi / 160f))); holder.voteChart.invalidate(); holder.voteChart.setVisibility(View.VISIBLE); + + if (poll.getSelectedEntryIndex() != -1) { + holder.selectedEntry.setText("You voted \"" + + poll.getEntries()[poll.getSelectedEntryIndex()].getEntryName() + "\""); + holder.selectedEntry.setVisibility(View.VISIBLE); + } } if (poll.getRemoveVoteUrl() != null) { holder.removeVotesButton.setOnClickListener(v -> viewModel.removeVote()); @@ -899,7 +909,7 @@ class TopicAdapter extends RecyclerView.Adapter { } static class PollViewHolder extends RecyclerView.ViewHolder { - final TextView question, errorTextview; + final TextView question, errorTextview, selectedEntry; final LinearLayout optionsLayout; final AppCompatButton submitButton; final AppCompatButton removeVotesButton, showPollResultsButton, hidePollResultsButton; @@ -916,6 +926,7 @@ class TopicAdapter extends RecyclerView.Adapter { hidePollResultsButton = itemView.findViewById(R.id.show_poll_options_button); errorTextview = itemView.findViewById(R.id.error_too_many_checked); voteChart = itemView.findViewById(R.id.vote_chart); + selectedEntry = itemView.findViewById(R.id.selected_entry_textview); voteChart.setScaleYEnabled(false); voteChart.setDoubleTapToZoomEnabled(false); } 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 ca67957b..1a7922ff 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 @@ -487,6 +487,7 @@ public class TopicParser { int availableVoteCount = 0, selectedEntryIndex = -1; String pollFormUrl = null, sc = null, removeVoteUrl = null, showVoteResultsUrl = null, showOptionsUrl = null; + boolean pollResultsHidden = false; Element pollColumn = table.select("tr[class=windowbg]").first().child(1); question = pollColumn.ownText().trim(); @@ -525,21 +526,19 @@ public class TopicParser { } } else { // poll in results mode - boolean pollResultsHidden = false; Elements entryRows = pollColumn.select("table[cellspacing] tr"); for (int i = 0; i < entryRows.size(); i++) { Element entryRow = entryRows.get(i); Elements entryColumns = entryRow.select("td"); - if (entryColumns.size() < 2) pollResultsHidden = true; + if (entryColumns.first().attr("style").contains("font-weight: bold;")) + selectedEntryIndex = i; String optionName = entryColumns.first().html(); int voteCount = 0; - if (pollResultsHidden) { - if (entryColumns.first().attr("style").contains("font-weight: bold;")) - selectedEntryIndex = i; - } else { + if (entryColumns.size() < 2) pollResultsHidden = true; + if (!pollResultsHidden) { String voteCountDescription = entryColumns.last().text(); Matcher integerMatcher = integerPattern.matcher(voteCountDescription); if (integerMatcher.find()) { @@ -560,7 +559,7 @@ public class TopicParser { } } return new Poll(question, entries.toArray(new Poll.Entry[0]), availableVoteCount, - pollFormUrl, sc, removeVoteUrl, showVoteResultsUrl, showOptionsUrl, selectedEntryIndex); + pollFormUrl, sc, removeVoteUrl, showVoteResultsUrl, showOptionsUrl, selectedEntryIndex, pollResultsHidden); } catch (Exception e) { Timber.v(e, "Could not parse a poll"); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java b/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java index ffd98e4d..407a357e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Poll.java @@ -9,9 +9,10 @@ public class Poll extends TopicItem { private Entry[] entries; private int availableVoteCount, selectedEntryIndex = -1; private String pollFormUrl, sc, removeVoteUrl, showVoteResultsUrl, showOptionsUrl; + private boolean pollResultsHidden; public Poll(String question, Entry[] entries, int availableVoteCount, String pollFormUrl, String sc, - String removeVoteUrl, String showVoteResultsUrl, String showOptionsUrl, int selectedEntryIndex) { + String removeVoteUrl, String showVoteResultsUrl, String showOptionsUrl, int selectedEntryIndex, boolean pollResultsHidden) { this.question = question; this.entries = entries; this.availableVoteCount = availableVoteCount; @@ -21,6 +22,7 @@ public class Poll extends TopicItem { this.showVoteResultsUrl = showVoteResultsUrl; this.showOptionsUrl = showOptionsUrl; this.selectedEntryIndex = selectedEntryIndex; + this.pollResultsHidden = pollResultsHidden; } private int totalVotes() { @@ -73,6 +75,10 @@ public class Poll extends TopicItem { return selectedEntryIndex; } + public boolean isPollResultsHidden() { + return pollResultsHidden; + } + public static class Entry { private final String entryName; private int votes; diff --git a/app/src/main/res/layout/activity_topic_poll.xml b/app/src/main/res/layout/activity_topic_poll.xml index 285c740b..7b77f29a 100644 --- a/app/src/main/res/layout/activity_topic_poll.xml +++ b/app/src/main/res/layout/activity_topic_poll.xml @@ -25,6 +25,14 @@ android:layout_height="wrap_content" android:visibility="gone"/> + + Date: Sun, 16 Dec 2018 22:15:23 +0200 Subject: [PATCH 102/104] unescape entities --- .../gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReply.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReply.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReply.java index 3d4f229a..bf5e12e0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReply.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReply.java @@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.activities.topic.tasks; import android.os.AsyncTask; import org.jsoup.nodes.Document; +import org.jsoup.parser.Parser; import org.jsoup.select.Selector; import java.io.IOException; @@ -62,6 +63,7 @@ public class PrepareForReply extends AsyncTask") + 7, body.indexOf(""))); buildedQuotes.append("\n\n"); } catch (IOException | Selector.SelectorParseException e) { From d84b125cb48e7b475387898a7e13c847c8d97e50 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sun, 16 Dec 2018 22:41:25 +0200 Subject: [PATCH 103/104] Add OkHttpProfiler package to release (won't be initialized) --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 323b170b..a1c8c82c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -89,7 +89,7 @@ dependencies { implementation 'ru.noties:markwon:2.0.0' implementation 'net.gotev:uploadservice:3.4.2' implementation 'net.gotev:uploadservice-okhttp:3.4.2' - debugImplementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.4' //Plugin: https://plugins.jetbrains.com/plugin/11249-okhttp-profiler + implementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.4' //Plugin: https://plugins.jetbrains.com/plugin/11249-okhttp-profiler } apply plugin: 'com.google.gms.google-services' From d65539808cde6144c3db5cee0a9bc69b3104ef98 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 17 Dec 2018 10:35:28 +0200 Subject: [PATCH 104/104] Fixed subBoard double parsing --- .../activities/board/BoardActivity.java | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) 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 54d2b226..61fc45e6 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 @@ -224,8 +224,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo if (newTopicButton == null) newTopicButton = boardPage.select("a:has(img[alt=Νέο θέμα])").first(); if (newTopicButton != null) newTopicUrl = newTopicButton.attr("href"); - - { //Finds sub boards + if(pagesLoaded == 0) { //Finds sub boards Elements subBoardRows = boardPage.select("div.tborder>table>tbody>tr"); if (subBoardRows != null && !subBoardRows.isEmpty()) { for (Element subBoardRow : subBoardRows) { @@ -269,46 +268,46 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo } } } - { //Finds topics - Elements topicRows = boardPage.select("table.bordercolor>tbody>tr"); - if (topicRows != null && !topicRows.isEmpty()) { - for (Element topicRow : topicRows) { - if (!Objects.equals(topicRow.className(), "titlebg")) { - String pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, pStats; - boolean pLocked = false, pSticky = false, pUnread = false; - Elements topicColumns = topicRow.select(">td"); - { - Element column = topicColumns.get(2); - Element tmp = column.select("span[id^=msg_] a").first(); - pTopicUrl = tmp.attr("href"); - pSubject = tmp.text(); - if (column.select("img[id^=stickyicon]").first() != null) - pSticky = true; - if (column.select("img[id^=lockicon]").first() != null) - pLocked = true; - if (column.select("a[id^=newicon]").first() != null) - pUnread = true; - } - pStartedBy = topicColumns.get(3).text(); - pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text(); - - pLastPost = topicColumns.last().text(); - if (pLastPost.contains("by")) { - pLastPost = pLastPost.substring(0, pLastPost.indexOf("by")) + - "\n" + pLastPost.substring(pLastPost.indexOf("by")); - } else if (pLastPost.contains("από")) { - pLastPost = pLastPost.substring(0, pLastPost.indexOf("από")) + - "\n" + pLastPost.substring(pLastPost.indexOf("από")); - } else { - Timber.wtf("Board parsing about to fail. pLastPost came with: %s", pLastPost); - } - pLastPostUrl = topicColumns.last().select("a:has(img)").first().attr("href"); - tempTopics.add(new Topic(pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, - pStats, pLocked, pSticky, pUnread)); + //Finds topics + Elements topicRows = boardPage.select("table.bordercolor>tbody>tr"); + if (topicRows != null && !topicRows.isEmpty()) { + for (Element topicRow : topicRows) { + if (!Objects.equals(topicRow.className(), "titlebg")) { + String pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, pStats; + boolean pLocked = false, pSticky = false, pUnread = false; + Elements topicColumns = topicRow.select(">td"); + { + Element column = topicColumns.get(2); + Element tmp = column.select("span[id^=msg_] a").first(); + pTopicUrl = tmp.attr("href"); + pSubject = tmp.text(); + if (column.select("img[id^=stickyicon]").first() != null) + pSticky = true; + if (column.select("img[id^=lockicon]").first() != null) + pLocked = true; + if (column.select("a[id^=newicon]").first() != null) + pUnread = true; } + pStartedBy = topicColumns.get(3).text(); + pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text(); + + pLastPost = topicColumns.last().text(); + if (pLastPost.contains("by")) { + pLastPost = pLastPost.substring(0, pLastPost.indexOf("by")) + + "\n" + pLastPost.substring(pLastPost.indexOf("by")); + } else if (pLastPost.contains("από")) { + pLastPost = pLastPost.substring(0, pLastPost.indexOf("από")) + + "\n" + pLastPost.substring(pLastPost.indexOf("από")); + } else { + Timber.wtf("Board parsing about to fail. pLastPost came with: %s", pLastPost); + } + pLastPostUrl = topicColumns.last().select("a:has(img)").first().attr("href"); + tempTopics.add(new Topic(pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, + pStats, pLocked, pSticky, pUnread)); } } } + } @Override