Browse Source

Code cleanup and Downloads hotfix.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
6763b4d081
  1. 1
      app/src/main/AndroidManifest.xml
  2. 16
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  3. 18
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java
  4. 33
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  5. 11
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  6. 5
      app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java
  7. 5
      app/src/main/java/gr/thmmy/mthmmy/utils/CustomLinearLayoutManager.java
  8. 22
      app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java
  9. 15
      app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java
  10. 1
      app/src/main/res/layout/dialog_topic_info.xml
  11. 1
      app/src/main/res/layout/fragment_unread_mark_read_row.xml

1
app/src/main/AndroidManifest.xml

@ -90,7 +90,6 @@
</activity>
<activity
android:name=".activities.downloads.DownloadsActivity"
android:launchMode="singleInstance"
android:parentActivityName=".activities.main.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data

16
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -26,6 +26,7 @@ import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.model.ThmmyPage;
import gr.thmmy.mthmmy.model.TopicSummary;
import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL;
@ -52,8 +53,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
redirectToActivityFromIntent(intentFilter);
setContentView(R.layout.activity_main);
if (sessionManager.isLoginScreenDefault())
{
if (sessionManager.isLoginScreenDefault()) {
//Go to login
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
@ -129,13 +129,13 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
@Override
public void onUnreadFragmentInteraction(TopicSummary topicSummary) {
if (topicSummary.getLastUser() == null && topicSummary.getDateTimeModified() == null) {
return; //TODO!
}
if (topicSummary.getTopicUrl() != null) {
Intent i = new Intent(MainActivity.this, TopicActivity.class);
i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl());
i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject());
startActivity(i);
} else
Timber.e("onUnreadFragmentInteraction TopicSummary came without a link");
}
//---------------------------------FragmentPagerAdapter---------------------------------------------
@ -185,13 +185,13 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
@Override
public int getItemPosition(Object object) {
int position = fragmentList.indexOf(object);
@SuppressWarnings("RedundantCast")
int position = fragmentList.indexOf((Fragment) object);
return position == -1 ? POSITION_NONE : position;
}
}
public void updateTabs()
{
public void updateTabs() {
if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3)
sectionsPagerAdapter.removeFragment(2);
else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2)

18
app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java

@ -58,18 +58,18 @@ class UnreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
@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<RecyclerView.ViewHolder> {
});
} 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<RecyclerView.ViewHolder> {
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<RecyclerView.ViewHolder> {
}
}
public interface MarkReadInteractionListener {
interface MarkReadInteractionListener {
void onMarkReadInteraction(String markReadLinkUrl);
}
}

33
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;

11
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)

5
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

5
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);
}
}

22
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<FloatingActionButton> {
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() {

15
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;
* <p>When a nested ScrollView is scrolled down, the view will disappear.
* When the ScrollView is scrolled back up, the view will reappear.</p>
*/
@SuppressWarnings("WeakerAccess")
@SuppressWarnings("unused")
public class ScrollAwareLinearBehavior extends CoordinatorLayout.Behavior<View> {
private static final int ANIMATION_DURATION = 100;
@ -23,15 +24,19 @@ public class ScrollAwareLinearBehavior extends CoordinatorLayout.Behavior<View>
}
@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);

1
app/src/main/res/layout/dialog_topic_info.xml

@ -8,6 +8,7 @@
<TextView
android:id="@+id/dialog_title"
android:text="@string/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"

1
app/src/main/res/layout/fragment_unread_mark_read_row.xml

@ -4,6 +4,7 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:paddingTop="7dp">
<TextView

Loading…
Cancel
Save