diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-09-14 13:54:10 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-09-14 13:54:10 +0900 |
commit | 93b315a3ac7536b007e385bba4434bbda9410de8 (patch) | |
tree | 14473c0fcdbbb5c0b1e7b41e6d3990d02a3ea4f6 /app/src/main/java/net/lacolaco/smileessence | |
parent | c65ed04aa1e9e727a68df99dc5d12920751fc4f1 (diff) | |
download | SmileEssence-93b315a3ac7536b007e385bba4434bbda9410de8.tar.gz |
CustomListFragment<T> をリファクタリング。updateListViewWithNotice はパラメータの adapter は不要だし、notifyListUpdated を分ける意味はない
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence')
6 files changed, 16 insertions, 20 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java index 51dd6477..464d75c2 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java @@ -29,7 +29,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; -import android.widget.ListAdapter; import android.widget.ListView; import com.handmark.pulltorefresh.library.PullToRefreshBase; @@ -75,7 +74,7 @@ public abstract class CustomListFragment<T extends CustomListAdapter> extends Pa if (absListView.getFirstVisiblePosition() == 0 && absListView.getChildAt(0) != null && absListView.getChildAt(0).getTop() == 0) { if (scrollState == SCROLL_STATE_IDLE) { - updateListViewWithNotice(absListView, adapter, true); + updateListViewWithNotice(absListView, true); } } } @@ -95,7 +94,7 @@ public abstract class CustomListFragment<T extends CustomListAdapter> extends Pa public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View page = inflater.inflate(R.layout.fragment_list, container, false); PullToRefreshListView listView = getListView(page); - ListAdapter adapter = getAdapter(); + T adapter = getAdapter(); listView.setAdapter(adapter); listView.setOnScrollListener(this); listView.setOnRefreshListener(this); @@ -119,18 +118,15 @@ public abstract class CustomListFragment<T extends CustomListAdapter> extends Pa return (PullToRefreshListView) page.findViewById(R.id.fragment_list_listview); } - protected void notifyListUpdated(int increments) { - Notificator.getInstance().publish(getString(R.string.notice_timeline_new, increments)); - } - - protected void updateListViewWithNotice(AbsListView absListView, CustomListAdapter<?> adapter, boolean addedToTop) { + protected void updateListViewWithNotice(AbsListView absListView, boolean addedToTop) { + T adapter = getAdapter(); int before = adapter.getCount(); adapter.notifyDataSetChanged(); // synchronized call (not adapter#updateForce()) int after = adapter.getCount(); int increments = after - before; if (increments > 0) { adapter.setNotifiable(false); - notifyListUpdated(increments); + Notificator.getInstance().publish(getString(R.string.notice_timeline_new, increments)); if (addedToTop) { absListView.setSelection(increments + 1); absListView.smoothScrollToPositionFromTop(increments, 0); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java index 09015113..3aece899 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java @@ -93,7 +93,7 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { new UIHandler() { @Override public void run() { - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, true); + updateListViewWithNotice(refreshView.getRefreshableView(), true); refreshView.onRefreshComplete(); } }.post(); @@ -115,7 +115,7 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { adapter.addToTop(viewModel); StatusFilter.getInstance().filter(viewModel); } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, true); + updateListViewWithNotice(refreshView.getRefreshableView(), true); refreshView.onRefreshComplete(); } }.execute(); @@ -140,7 +140,7 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { adapter.addToBottom(viewModel); StatusFilter.getInstance().filter(viewModel); } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, false); + updateListViewWithNotice(refreshView.getRefreshableView(), false); refreshView.onRefreshComplete(); } }.execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java index a3cf6ea0..3b1e8904 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java @@ -107,7 +107,7 @@ public class MentionsFragment extends CustomListFragment<StatusListAdapter> { for (int i = tweets.size() - 1; i >= 0; i--) { adapter.addToTop(new StatusViewModel(tweets.get(i))); } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, true); + updateListViewWithNotice(refreshView.getRefreshableView(), true); refreshView.onRefreshComplete(); } }.execute(); @@ -130,7 +130,7 @@ public class MentionsFragment extends CustomListFragment<StatusListAdapter> { for (Tweet tweet : tweets) { adapter.addToBottom(new StatusViewModel(tweet)); } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, false); + updateListViewWithNotice(refreshView.getRefreshableView(), false); refreshView.onRefreshComplete(); } }.execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java index 7d43a21c..3ae2a958 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java @@ -111,7 +111,7 @@ public class MessagesFragment extends CustomListFragment<MessageListAdapter> { for (int i = directMessages.size() - 1; i >= 0; i--) { adapter.addToTop(new MessageViewModel(directMessages.get(i))); } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, true); + updateListViewWithNotice(refreshView.getRefreshableView(), true); refreshView.onRefreshComplete(); } }.execute(); @@ -134,7 +134,7 @@ public class MessagesFragment extends CustomListFragment<MessageListAdapter> { for (DirectMessage directMessage : directMessages) { adapter.addToBottom(new MessageViewModel(directMessage)); } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, false); + updateListViewWithNotice(refreshView.getRefreshableView(), false); refreshView.onRefreshComplete(); } }.execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java index 454c1311..faa56dac 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java @@ -171,7 +171,7 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem StatusFilter.getInstance().filter(viewModel); } } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, true); + updateListViewWithNotice(refreshView.getRefreshableView(), true); adapter.setTopID(queryResult.getMaxId()); refreshView.onRefreshComplete(); } @@ -216,7 +216,7 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem StatusFilter.getInstance().filter(viewModel); } } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, false); + updateListViewWithNotice(refreshView.getRefreshableView(), false); refreshView.onRefreshComplete(); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java index 317a1105..9e8fd65b 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java @@ -131,7 +131,7 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im adapter.addToTop(statusViewModel); StatusFilter.getInstance().filter(statusViewModel); } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, true); + updateListViewWithNotice(refreshView.getRefreshableView(), true); refreshView.onRefreshComplete(); } }.execute(); @@ -167,7 +167,7 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im adapter.addToBottom(statusViewModel); StatusFilter.getInstance().filter(statusViewModel); } - updateListViewWithNotice(refreshView.getRefreshableView(), adapter, false); + updateListViewWithNotice(refreshView.getRefreshableView(), false); refreshView.onRefreshComplete(); } }.execute(); |