From 6763b4d08192f140a538ccae7e9db19d32d540e0 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Tue, 25 Jul 2017 20:14:56 +0300 Subject: [PATCH] Code cleanup and Downloads hotfix. --- app/src/main/AndroidManifest.xml | 1 - .../mthmmy/activities/main/MainActivity.java | 36 +++++++++---------- .../activities/main/unread/UnreadAdapter.java | 18 +++++----- .../latestPosts/LatestPostsFragment.java | 2 +- .../activities/topic/TopicActivity.java | 33 +++++++++-------- .../gr/thmmy/mthmmy/base/BaseActivity.java | 11 +++--- .../gr/thmmy/mthmmy/base/BaseFragment.java | 5 +-- .../utils/CustomLinearLayoutManager.java | 5 +-- .../mthmmy/utils/ScrollAwareFABBehavior.java | 22 ++++++------ .../utils/ScrollAwareLinearBehavior.java | 15 +++++--- app/src/main/res/layout/dialog_topic_info.xml | 1 + .../layout/fragment_unread_mark_read_row.xml | 1 + 12 files changed, 77 insertions(+), 73 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e78f4e6..0ed23714 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -90,7 +90,6 @@ { } @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) { + public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) { if (holder instanceof UnreadAdapter.EmptyViewHolder) { final UnreadAdapter.EmptyViewHolder emptyViewHolder = (UnreadAdapter.EmptyViewHolder) holder; - emptyViewHolder.text.setText(unreadList.get(position).getDateTimeModified()); + emptyViewHolder.text.setText(unreadList.get(holder.getAdapterPosition()).getDateTimeModified()); } else if (holder instanceof UnreadAdapter.ViewHolder) { final UnreadAdapter.ViewHolder viewHolder = (UnreadAdapter.ViewHolder) holder; - viewHolder.mTitleView.setText(unreadList.get(position).getSubject()); - viewHolder.mDateTimeView.setText(unreadList.get(position).getDateTimeModified()); + viewHolder.mTitleView.setText(unreadList.get(holder.getAdapterPosition()).getSubject()); + viewHolder.mDateTimeView.setText(unreadList.get(holder.getAdapterPosition()).getDateTimeModified()); viewHolder.mUserView.setText(context.getString(R.string.byUser, unreadList.get(position).getLastUser())); - viewHolder.topic = unreadList.get(position); + viewHolder.topic = unreadList.get(holder.getAdapterPosition()); viewHolder.mView.setOnClickListener(new View.OnClickListener() { @Override @@ -83,8 +83,8 @@ class UnreadAdapter extends RecyclerView.Adapter { }); } else if (holder instanceof UnreadAdapter.MarkReadViewHolder) { final UnreadAdapter.MarkReadViewHolder markReadViewHolder = (UnreadAdapter.MarkReadViewHolder) holder; - markReadViewHolder.text.setText(unreadList.get(position).getSubject()); - markReadViewHolder.topic = unreadList.get(position); + markReadViewHolder.text.setText(unreadList.get(holder.getAdapterPosition()).getSubject()); + markReadViewHolder.topic = unreadList.get(holder.getAdapterPosition()); markReadViewHolder.mView.setOnClickListener(new View.OnClickListener() { @Override @@ -92,7 +92,7 @@ class UnreadAdapter extends RecyclerView.Adapter { if (null != mListener) { // Notify the active callbacks interface (the activity, if the // fragment is attached to one) that an item has been selected. - markReadListener.onMarkReadInteraction(unreadList.get(position).getTopicUrl()); + markReadListener.onMarkReadInteraction(unreadList.get(holder.getAdapterPosition()).getTopicUrl()); } } }); @@ -141,7 +141,7 @@ class UnreadAdapter extends RecyclerView.Adapter { } } - public interface MarkReadInteractionListener { + interface MarkReadInteractionListener { void onMarkReadInteraction(String markReadLinkUrl); } } 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 2ec45dde..11cb671e 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 @@ -33,7 +33,7 @@ import timber.log.Timber; /** * Use the {@link LatestPostsFragment#newInstance} factory method to create an instance of this fragment. */ -public class LatestPostsFragment extends BaseFragment implements LatestPostsAdapter.OnLoadMoreListener{ +public class LatestPostsFragment extends BaseFragment implements LatestPostsAdapter.OnLoadMoreListener { /** * The key to use when putting profile's url String to {@link LatestPostsFragment}'s Bundle. */ 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 2cc534fc..d95b5a7d 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 @@ -241,7 +241,6 @@ public class TopicActivity extends BaseActivity { LayoutInflater inflater = this.getLayoutInflater(); LinearLayout infoDialog = (LinearLayout) inflater.inflate(R.layout.dialog_topic_info , null); - ((TextView) infoDialog.findViewById(R.id.dialog_title)).setText("Info"); TextView treeAndMods = infoDialog.findViewById(R.id.topic_tree_and_mods); treeAndMods.setText(topicTreeAndMods); treeAndMods.setMovementMethod(LinkMovementMethod.getInstance()); @@ -317,25 +316,25 @@ public class TopicActivity extends BaseActivity { lastPage.setEnabled(enabled); } - private void paginationEnabledExcept(boolean enabled, View exception) { + private void paginationDisable(View exception) { if (exception == firstPage) { - previousPage.setEnabled(enabled); - nextPage.setEnabled(enabled); - lastPage.setEnabled(enabled); + previousPage.setEnabled(false); + nextPage.setEnabled(false); + lastPage.setEnabled(false); } else if (exception == previousPage) { - firstPage.setEnabled(enabled); - nextPage.setEnabled(enabled); - lastPage.setEnabled(enabled); + firstPage.setEnabled(false); + nextPage.setEnabled(false); + lastPage.setEnabled(false); } else if (exception == nextPage) { - firstPage.setEnabled(enabled); - previousPage.setEnabled(enabled); - lastPage.setEnabled(enabled); + firstPage.setEnabled(false); + previousPage.setEnabled(false); + lastPage.setEnabled(false); } else if (exception == lastPage) { - firstPage.setEnabled(enabled); - previousPage.setEnabled(enabled); - nextPage.setEnabled(enabled); + firstPage.setEnabled(false); + previousPage.setEnabled(false); + nextPage.setEnabled(false); } else { - paginationEnabled(enabled); + paginationEnabled(false); } } @@ -356,7 +355,7 @@ public class TopicActivity extends BaseActivity { increment.setOnLongClickListener( new View.OnLongClickListener() { public boolean onLongClick(View arg0) { - paginationEnabledExcept(false, arg0); + paginationDisable(arg0); autoIncrement = true; repeatUpdateHandler.postDelayed(new RepetitiveUpdater(step), INITIAL_DELAY); return false; @@ -404,7 +403,7 @@ public class TopicActivity extends BaseActivity { decrement.setOnLongClickListener( new View.OnLongClickListener() { public boolean onLongClick(View arg0) { - paginationEnabledExcept(false, arg0); + paginationDisable(arg0); autoDecrement = true; repeatUpdateHandler.postDelayed(new RepetitiveUpdater(step), INITIAL_DELAY); return false; 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 f844573d..6a837038 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -138,10 +138,8 @@ public abstract class BaseActivity extends AppCompatActivity { private AccountHeader accountHeader; private ProfileDrawerItem profileDrawerItem; - private PrimaryDrawerItem homeItem, downloadsItem, bookmarksItem, loginLogoutItem, aboutItem; - private IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, - bookmarksIcon, bookmarksIconSelected, loginIcon, logoutIcon, aboutIcon, - aboutIconSelected; + private PrimaryDrawerItem downloadsItem, loginLogoutItem; + private IconicsDrawable loginIcon, logoutIcon; /** * Call only after initializing Toolbar @@ -151,6 +149,11 @@ 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, aboutItem; + IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, + bookmarksIcon, bookmarksIconSelected, aboutIcon, + aboutIconSelected; + //Drawer Icons homeIcon = new IconicsDrawable(this) .icon(FontAwesome.Icon.faw_home) 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 0f3487d9..d6f69297 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java @@ -13,15 +13,12 @@ public abstract class BaseFragment extends Fragment { protected FragmentInteractionListener fragmentInteractionListener; - private String TAG; - private int sectionNumber; protected static OkHttpClient client; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - TAG = getArguments().getString(ARG_TAG); - sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER); + //int sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER); if (client == null) client = BaseApplication.getInstance().getClient(); //must check every time - e.g. // becomes null when app restarts after crash 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 cc03225c..52a5302e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java @@ -3,12 +3,11 @@ package gr.thmmy.mthmmy.utils; import android.content.Context; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.util.Log; import timber.log.Timber; public class CustomLinearLayoutManager extends LinearLayoutManager { - private String pageUrl; + private final String pageUrl; public CustomLinearLayoutManager(Context context, String pageUrl) { super(context); @@ -21,8 +20,6 @@ public class CustomLinearLayoutManager extends LinearLayoutManager { super.onLayoutChildren(recycler, state); } catch (IndexOutOfBoundsException e) { Timber.wtf(e, "Inconsistency detected: topic_requested = \"" + pageUrl + "\""); - Log.d("CustomLinearLayoutMan", "Inconsistency detected: topic_requested = \"" - + pageUrl + "\"", e); } } 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 f49fe28d..0d336ae3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java @@ -1,6 +1,7 @@ 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.v4.view.ViewCompat; @@ -11,27 +12,28 @@ import android.view.View; * Extends FloatingActionButton's behavior so the button will hide when scrolling down and show * otherwise. */ -@SuppressWarnings("WeakerAccess") +@SuppressWarnings("unused") public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior { - String TAG = "ScrollAwareFABBehavior"; - @SuppressWarnings("UnusedParameters") public ScrollAwareFABBehavior(Context context, AttributeSet attrs) { super(); } @Override - public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, - final View directTargetChild, final View target, final int nestedScrollAxes) { + public boolean onStartNestedScroll(@NonNull final CoordinatorLayout coordinatorLayout, + @NonNull final FloatingActionButton child, + @NonNull final View directTargetChild, @NonNull final View target, + final int nestedScrollAxes, int type) { return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL; } @Override - public void onNestedScroll(final CoordinatorLayout coordinatorLayout, - final FloatingActionButton child, - final View target, final int dxConsumed, final int dyConsumed, - final int dxUnconsumed, final int dyUnconsumed) { - super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); + public void onNestedScroll(@NonNull final CoordinatorLayout coordinatorLayout, + @NonNull final FloatingActionButton child, + @NonNull final View target, final int dxConsumed, final int dyConsumed, + final int dxUnconsumed, final int dyUnconsumed, int type) { + super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, + dyUnconsumed, type); if ((dyConsumed > 0 || (!target.canScrollVertically(-1) && dyConsumed == 0 && dyUnconsumed < 40)) && child.getVisibility() == View.VISIBLE) { child.hide(new FloatingActionButton.OnVisibilityChangedListener() { 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 834cbe34..57166700 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java @@ -2,6 +2,7 @@ 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.v4.view.ViewCompat; import android.support.v4.view.animation.FastOutSlowInInterpolator; @@ -14,7 +15,7 @@ import android.view.ViewPropertyAnimator; *

When a nested ScrollView is scrolled down, the view will disappear. * When the ScrollView is scrolled back up, the view will reappear.

*/ -@SuppressWarnings("WeakerAccess") +@SuppressWarnings("unused") public class ScrollAwareLinearBehavior extends CoordinatorLayout.Behavior { private static final int ANIMATION_DURATION = 100; @@ -23,15 +24,19 @@ public class ScrollAwareLinearBehavior extends CoordinatorLayout.Behavior } @Override - public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) { + public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, + @NonNull View child, @NonNull View directTargetChild, + @NonNull View target, int nestedScrollAxes, int type) { return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0; } @Override - public void onNestedScroll(CoordinatorLayout coordinatorLayout, View bottomNavBar, View target, + public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, + @NonNull View bottomNavBar, @NonNull View target, int dxConsumed, int dyConsumed, - int dxUnconsumed, int dyUnconsumed) { - super.onNestedScroll(coordinatorLayout, bottomNavBar, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); + int dxUnconsumed, int dyUnconsumed, int type) { + super.onNestedScroll(coordinatorLayout, bottomNavBar, target, dxConsumed, dyConsumed, + dxUnconsumed, dyUnconsumed, type); if ((dyConsumed > 0 || (!target.canScrollVertically(-1) && dyConsumed == 0 && dyUnconsumed < 40)) && bottomNavBar.getVisibility() == View.VISIBLE) { hide(bottomNavBar); diff --git a/app/src/main/res/layout/dialog_topic_info.xml b/app/src/main/res/layout/dialog_topic_info.xml index 47b8ec31..047c0a23 100644 --- a/app/src/main/res/layout/dialog_topic_info.xml +++ b/app/src/main/res/layout/dialog_topic_info.xml @@ -8,6 +8,7 @@