Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Commit

Permalink
Merge branch 'feature/list_double_click_back_to_top' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed May 5, 2016
2 parents 5aa4c21 + 0f95100 commit 5009156
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import org.cnodejs.android.md.display.adapter.MainAdapter;
import org.cnodejs.android.md.display.base.DrawerLayoutActivity;
import org.cnodejs.android.md.display.dialog.AlertDialogUtils;
import org.cnodejs.android.md.display.listener.DoubleClickBackToContentTopListener;
import org.cnodejs.android.md.display.listener.NavigationOpenClickListener;
import org.cnodejs.android.md.display.listener.RecyclerViewLoadMoreListener;
import org.cnodejs.android.md.display.view.IBackToContentTopView;
import org.cnodejs.android.md.display.view.IMainView;
import org.cnodejs.android.md.display.widget.ActivityUtils;
import org.cnodejs.android.md.display.widget.RefreshLayoutUtils;
Expand All @@ -47,7 +49,7 @@
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends DrawerLayoutActivity implements IMainView, SwipeRefreshLayout.OnRefreshListener, RecyclerViewLoadMoreListener.OnLoadMoreListener {
public class MainActivity extends DrawerLayoutActivity implements IMainView, IBackToContentTopView, SwipeRefreshLayout.OnRefreshListener, RecyclerViewLoadMoreListener.OnLoadMoreListener {

private static final int PAGE_LIMIT = 20;

Expand Down Expand Up @@ -137,6 +139,7 @@ protected void onCreate(Bundle savedInstanceState) {
drawerLayout.setDrawerShadow(R.drawable.navigation_drawer_shadow, GravityCompat.START);
drawerLayout.addDrawerListener(drawerListener);
toolbar.setNavigationOnClickListener(new NavigationOpenClickListener(drawerLayout));
toolbar.setOnClickListener(new DoubleClickBackToContentTopListener(this));

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(linearLayoutManager);
Expand Down Expand Up @@ -478,4 +481,9 @@ public void updateMessageCountViews(@NonNull Result.Data<Integer> result) {
}
}

@Override
public void backToContentTop() {
recyclerView.scrollToPosition(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.cnodejs.android.md.R;
import org.cnodejs.android.md.display.adapter.NotificationAdapter;
import org.cnodejs.android.md.display.base.StatusBarActivity;
import org.cnodejs.android.md.display.listener.DoubleClickBackToContentTopListener;
import org.cnodejs.android.md.display.listener.NavigationFinishClickListener;
import org.cnodejs.android.md.display.view.IBackToContentTopView;
import org.cnodejs.android.md.display.view.INotificationView;
import org.cnodejs.android.md.display.widget.ActivityUtils;
import org.cnodejs.android.md.display.widget.RefreshLayoutUtils;
Expand All @@ -29,7 +31,7 @@
import butterknife.Bind;
import butterknife.ButterKnife;

public class NotificationActivity extends StatusBarActivity implements INotificationView, Toolbar.OnMenuItemClickListener, SwipeRefreshLayout.OnRefreshListener {
public class NotificationActivity extends StatusBarActivity implements INotificationView, IBackToContentTopView, Toolbar.OnMenuItemClickListener, SwipeRefreshLayout.OnRefreshListener {

@Bind(R.id.notification_toolbar)
protected Toolbar toolbar;
Expand Down Expand Up @@ -58,6 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
toolbar.inflateMenu(R.menu.notification);
toolbar.setOnMenuItemClickListener(this);
toolbar.setOnClickListener(new DoubleClickBackToContentTopListener(this));

recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new NotificationAdapter(this, messageList);
Expand Down Expand Up @@ -121,4 +124,9 @@ public boolean onMarkAllMessageReadResultOk() {
}
}

@Override
public void backToContentTop() {
recyclerView.scrollToPosition(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import org.cnodejs.android.md.display.adapter.TopicAdapter;
import org.cnodejs.android.md.display.base.StatusBarActivity;
import org.cnodejs.android.md.display.dialog.TopicReplyDialog;
import org.cnodejs.android.md.display.listener.DoubleClickBackToContentTopListener;
import org.cnodejs.android.md.display.listener.NavigationFinishClickListener;
import org.cnodejs.android.md.display.view.IBackToContentTopView;
import org.cnodejs.android.md.display.view.ITopicHeaderView;
import org.cnodejs.android.md.display.view.ITopicReplyView;
import org.cnodejs.android.md.display.view.ITopicView;
Expand Down Expand Up @@ -46,7 +48,7 @@
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TopicActivity extends StatusBarActivity implements ITopicView, SwipeRefreshLayout.OnRefreshListener, Toolbar.OnMenuItemClickListener {
public class TopicActivity extends StatusBarActivity implements ITopicView, IBackToContentTopView, SwipeRefreshLayout.OnRefreshListener, Toolbar.OnMenuItemClickListener {

private static final String EXTRA_TOPIC_ID = "topicId";
private static final String EXTRA_TOPIC = "topic";
Expand Down Expand Up @@ -119,6 +121,7 @@ protected void onCreate(Bundle savedInstanceState) {
toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
toolbar.inflateMenu(R.menu.topic);
toolbar.setOnMenuItemClickListener(this);
toolbar.setOnClickListener(new DoubleClickBackToContentTopListener(this));

topicReplyView = TopicReplyDialog.createWithAutoTheme(this, topicId, this);
topicHeaderView = new TopicHeaderViewHolder(this, listView);
Expand Down Expand Up @@ -204,4 +207,9 @@ public void appendReplyAndUpdateViews(@NonNull Reply reply) {
listView.smoothScrollToPosition(replyList.size());
}

@Override
public void backToContentTop() {
listView.setSelection(0);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.cnodejs.android.md.display.listener;

import android.support.annotation.NonNull;
import android.view.View;

import org.cnodejs.android.md.display.view.IBackToContentTopView;

public class DoubleClickBackToContentTopListener extends OnDoubleClickListener {

private final IBackToContentTopView backToContentTopView;

public DoubleClickBackToContentTopListener(@NonNull IBackToContentTopView backToContentTopView) {
super(300);
this.backToContentTopView = backToContentTopView;
}

@Override
public void onDoubleClick(View v) {
backToContentTopView.backToContentTop();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cnodejs.android.md.display.listener;

import android.view.View;

public abstract class OnDoubleClickListener implements View.OnClickListener {

private final long delayTime;
private long lastClickTime = 0;

public OnDoubleClickListener(long delayTime) {
this.delayTime = delayTime;
}

@Override
public final void onClick(View v) {
long nowClickTime = System.currentTimeMillis();
if (nowClickTime - lastClickTime > delayTime) {
lastClickTime = nowClickTime;
} else {
onDoubleClick(v);
}
}

public abstract void onDoubleClick(View v);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.cnodejs.android.md.display.view;

public interface IBackToContentTopView {

void backToContentTop();

}

0 comments on commit 5009156

Please sign in to comment.