From 185cfb181e6c6ba3073f8e6b6ef39e6ee78dcbb1 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Tue, 2 Oct 2018 18:05:11 +0300 Subject: [PATCH 01/23] 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 13/23] 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 14/23] 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 15/23] 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 16/23] 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 17/23] 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 18/23] 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 19/23] 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 20/23] 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 21/23] 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 22/23] 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 23/23] 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' }