diff options
Diffstat (limited to 'app/src')
9 files changed, 57 insertions, 62 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java index 67f5a04c..29ef9e82 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java @@ -335,7 +335,6 @@ public class MainActivity extends Activity { public int addListPage(String name, Class<? extends CustomListFragment> fragmentClass, CustomListAdapter<?> adapter, AdapterID adapterId, boolean visible) { if (visible) { Bundle args = new Bundle(); - args.putInt(CustomListFragment.ADAPTER_INDEX, adapterId.ordinal()); adapterMap.put(adapterId, adapter); return addPage(name, fragmentClass, args, false); } else { 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 91a77cbc..33474c2d 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java @@ -41,18 +41,21 @@ import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; -public class CustomListFragment extends Fragment implements AbsListView.OnScrollListener, +public abstract class CustomListFragment extends Fragment implements AbsListView.OnScrollListener, PullToRefreshBase.OnRefreshListener2<ListView> { // ------------------------------ FIELDS ------------------------------ - public static final String ADAPTER_INDEX = "fragmentIndex"; public static final int SCROLL_DURATION = 1500; - private MainActivity.AdapterID fragmentIndex; - // --------------------- GETTER / SETTER METHODS --------------------- + protected abstract MainActivity.AdapterID getAdapterIndex(); + + protected CustomListAdapter<?> getListAdapter() { + return ((MainActivity) getActivity()).getListAdapter(getAdapterIndex()); + } + protected PullToRefreshBase.Mode getRefreshMode() { return PullToRefreshBase.Mode.DISABLED; } @@ -76,9 +79,7 @@ public class CustomListFragment extends Fragment implements AbsListView.OnScroll @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { - Bundle args = getArguments(); - fragmentIndex = MainActivity.AdapterID.get(args.getInt(ADAPTER_INDEX)); - CustomListAdapter<?> adapter = getListAdapter(fragmentIndex); + CustomListAdapter<?> adapter = getListAdapter(); adapter.setNotifiable(false); if (absListView.getFirstVisiblePosition() == 0 && absListView.getChildAt(0) != null && absListView.getChildAt(0).getTop() == 0) { @@ -97,17 +98,13 @@ public class CustomListFragment extends Fragment implements AbsListView.OnScroll @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Bundle args = getArguments(); - fragmentIndex = MainActivity.AdapterID.get(args.getInt(ADAPTER_INDEX)); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View page = inflater.inflate(R.layout.fragment_list, container, false); - Bundle args = getArguments(); - MainActivity.AdapterID fragmentIndex = MainActivity.AdapterID.get(args.getInt(ADAPTER_INDEX)); PullToRefreshListView listView = getListView(page); - ListAdapter adapter = getListAdapter(fragmentIndex); + ListAdapter adapter = getListAdapter(); listView.setAdapter(adapter); listView.setOnScrollListener(this); listView.setOnRefreshListener(this); @@ -118,21 +115,15 @@ public class CustomListFragment extends Fragment implements AbsListView.OnScroll @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt(ADAPTER_INDEX, fragmentIndex.ordinal()); } @Override public void onViewStateRestored(Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); if (savedInstanceState != null) { - fragmentIndex = MainActivity.AdapterID.get(savedInstanceState.getInt(ADAPTER_INDEX)); } } - protected CustomListAdapter<?> getListAdapter(MainActivity.AdapterID fragmentIndex) { - return ((MainActivity) getActivity()).getListAdapter(fragmentIndex); - } - protected PullToRefreshListView getListView(View page) { return (PullToRefreshListView) page.findViewById(R.id.fragment_list_listview); } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/HistoryFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/HistoryFragment.java index 3bdb001d..e1d0dcdb 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/HistoryFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/HistoryFragment.java @@ -27,6 +27,7 @@ package net.lacolaco.smileessence.view; import android.widget.ListView; import com.handmark.pulltorefresh.library.PullToRefreshBase; +import net.lacolaco.smileessence.activity.MainActivity; /** * Fragment for notice history @@ -36,6 +37,11 @@ public class HistoryFragment extends CustomListFragment { // --------------------- GETTER / SETTER METHODS --------------------- @Override + protected MainActivity.AdapterID getAdapterIndex() { + return MainActivity.AdapterID.History; + } + + @Override protected PullToRefreshBase.Mode getRefreshMode() { return PullToRefreshBase.Mode.DISABLED; } 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 f4af80ec..dfadebaf 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java @@ -46,6 +46,11 @@ public class HomeFragment extends CustomListFragment { // --------------------- GETTER / SETTER METHODS --------------------- @Override + protected MainActivity.AdapterID getAdapterIndex() { + return MainActivity.AdapterID.Home; + } + + @Override protected PullToRefreshBase.Mode getRefreshMode() { return PullToRefreshBase.Mode.BOTH; } @@ -62,7 +67,7 @@ public class HomeFragment extends CustomListFragment { new UIHandler() { @Override public void run() { - StatusListAdapter adapter = getListAdapter(activity); + StatusListAdapter adapter = (StatusListAdapter) getListAdapter(); updateListViewWithNotice(refreshView.getRefreshableView(), adapter, true); refreshView.onRefreshComplete(); } @@ -71,7 +76,7 @@ public class HomeFragment extends CustomListFragment { } final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); - final StatusListAdapter adapter = getListAdapter(activity); + final StatusListAdapter adapter = (StatusListAdapter) getListAdapter(); Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity)); if (adapter.getCount() > 0) { paging.setSinceId(adapter.getTopID()); @@ -97,7 +102,7 @@ public class HomeFragment extends CustomListFragment { final MainActivity activity = (MainActivity) getActivity(); final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); - final StatusListAdapter adapter = getListAdapter(activity); + final StatusListAdapter adapter = (StatusListAdapter) getListAdapter(); Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity)); if (adapter.getCount() > 0) { paging.setMaxId(adapter.getLastID() - 1); @@ -116,8 +121,4 @@ public class HomeFragment extends CustomListFragment { } }.execute(); } - - private StatusListAdapter getListAdapter(MainActivity activity) { - return (StatusListAdapter) activity.getListAdapter(MainActivity.AdapterID.Home); - } } 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 3a453a7a..3cbdfd4b 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java @@ -44,6 +44,11 @@ public class MentionsFragment extends CustomListFragment { // --------------------- GETTER / SETTER METHODS --------------------- @Override + protected MainActivity.AdapterID getAdapterIndex() { + return MainActivity.AdapterID.Mentions; + } + + @Override protected PullToRefreshBase.Mode getRefreshMode() { return PullToRefreshBase.Mode.BOTH; } @@ -58,7 +63,7 @@ public class MentionsFragment extends CustomListFragment { final MainActivity activity = (MainActivity) getActivity(); final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); - final StatusListAdapter adapter = getListAdapter(activity); + final StatusListAdapter adapter = (StatusListAdapter) getListAdapter(); Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity)); if (adapter.getCount() > 0) { paging.setSinceId(adapter.getTopID()); @@ -82,7 +87,7 @@ public class MentionsFragment extends CustomListFragment { final MainActivity activity = (MainActivity) getActivity(); final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); - final StatusListAdapter adapter = getListAdapter(activity); + final StatusListAdapter adapter = (StatusListAdapter) getListAdapter(); Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity)); if (adapter.getCount() > 0) { paging.setMaxId(adapter.getLastID() - 1); @@ -99,8 +104,4 @@ public class MentionsFragment extends CustomListFragment { } }.execute(); } - - private StatusListAdapter getListAdapter(MainActivity activity) { - return (StatusListAdapter) activity.getListAdapter(MainActivity.AdapterID.Mentions); - } } 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 f4968c7d..0a10ba53 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java @@ -48,6 +48,11 @@ public class MessagesFragment extends CustomListFragment { // --------------------- GETTER / SETTER METHODS --------------------- @Override + protected MainActivity.AdapterID getAdapterIndex() { + return MainActivity.AdapterID.Messages; + } + + @Override protected PullToRefreshBase.Mode getRefreshMode() { return PullToRefreshBase.Mode.BOTH; } @@ -62,7 +67,7 @@ public class MessagesFragment extends CustomListFragment { final MainActivity activity = (MainActivity) getActivity(); final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); - final MessageListAdapter adapter = getListAdapter(activity); + final MessageListAdapter adapter = (MessageListAdapter) getListAdapter(); Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity)); if (adapter.getCount() > 0) { paging.setSinceId(adapter.getTopID()); @@ -85,7 +90,7 @@ public class MessagesFragment extends CustomListFragment { final MainActivity activity = (MainActivity) getActivity(); final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); - final MessageListAdapter adapter = getListAdapter(activity); + final MessageListAdapter adapter = (MessageListAdapter) getListAdapter(); Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity)); if (adapter.getCount() > 0) { paging.setMaxId(adapter.getLastID() - 1); @@ -102,8 +107,4 @@ public class MessagesFragment extends CustomListFragment { } }.execute(); } - - private MessageListAdapter getListAdapter(MainActivity activity) { - return (MessageListAdapter) activity.getListAdapter(MainActivity.AdapterID.Messages); - } } 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 bf847653..9372a5a1 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java @@ -72,12 +72,9 @@ public class SearchFragment extends CustomListFragment implements View.OnClickLi // --------------------- GETTER / SETTER METHODS --------------------- - private MainActivity.AdapterID getAdapterIndex() { - return MainActivity.AdapterID.get(getArguments().getInt(ADAPTER_INDEX)); - } - - private MainActivity getMainActivity() { - return (MainActivity) getActivity(); + @Override + protected MainActivity.AdapterID getAdapterIndex() { + return MainActivity.AdapterID.Search; } @Override @@ -94,7 +91,7 @@ public class SearchFragment extends CustomListFragment implements View.OnClickLi public void onClick(View v) { switch (v.getId()) { case R.id.button_search_queries: { - openSearchQueryDialog(getMainActivity()); + openSearchQueryDialog((MainActivity) getActivity()); break; } case R.id.button_search_execute: { @@ -129,7 +126,7 @@ public class SearchFragment extends CustomListFragment implements View.OnClickLi @Override public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) { - final MainActivity activity = getMainActivity(); + final MainActivity activity = (MainActivity) getActivity(); final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); final SearchListAdapter adapter = getListAdapter(activity); @@ -172,7 +169,7 @@ public class SearchFragment extends CustomListFragment implements View.OnClickLi @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { - final MainActivity activity = getMainActivity(); + final MainActivity activity = (MainActivity) getActivity(); final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); final SearchListAdapter adapter = getListAdapter(activity); @@ -233,9 +230,8 @@ public class SearchFragment extends CustomListFragment implements View.OnClickLi @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View page = inflater.inflate(R.layout.fragment_search, container, false); - MainActivity.AdapterID fragmentIndex = getAdapterIndex(); PullToRefreshListView listView = getListView(page); - SearchListAdapter adapter = (SearchListAdapter) getListAdapter(fragmentIndex); + SearchListAdapter adapter = (SearchListAdapter) getListAdapter(); listView.setAdapter(adapter); listView.setOnScrollListener(this); listView.setOnRefreshListener(this); @@ -326,10 +322,10 @@ public class SearchFragment extends CustomListFragment implements View.OnClickLi private void saveQuery() { String text = editText.getText().toString(); if (TextUtils.isEmpty(text)) { - Notificator.publish(getMainActivity(), R.string.notice_query_is_empty, NotificationType.ALERT); + Notificator.publish(getActivity(), R.string.notice_query_is_empty, NotificationType.ALERT); } else { SearchQuery.saveIfNotFound(text); - Notificator.publish(getMainActivity(), R.string.notice_query_saved); + Notificator.publish(getActivity(), R.string.notice_query_saved); } } @@ -337,9 +333,9 @@ public class SearchFragment extends CustomListFragment implements View.OnClickLi if (editText != null) { String text = editText.getText().toString(); if (TextUtils.isEmpty(text)) { - Notificator.publish(getMainActivity(), R.string.notice_query_is_empty, NotificationType.ALERT); + Notificator.publish(getActivity(), R.string.notice_query_is_empty, NotificationType.ALERT); } else { - getMainActivity().openSearchPage(text); + ((MainActivity) getActivity()).openSearchPage(text); hideIME(); } } 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 82163102..89fe984f 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java @@ -66,6 +66,11 @@ public class UserListFragment extends CustomListFragment implements View.OnClick } @Override + protected MainActivity.AdapterID getAdapterIndex() { + return MainActivity.AdapterID.UserList; + } + + @Override protected PullToRefreshBase.Mode getRefreshMode() { return PullToRefreshBase.Mode.BOTH; } @@ -93,7 +98,7 @@ public class UserListFragment extends CustomListFragment implements View.OnClick final MainActivity activity = getMainActivity(); final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); - final UserListListAdapter adapter = getListAdapter(activity); + final UserListListAdapter adapter = (UserListListAdapter) getListAdapter(); String listFullName = adapter.getListFullName(); if (TextUtils.isEmpty(listFullName)) { new UIHandler() { @@ -130,7 +135,7 @@ public class UserListFragment extends CustomListFragment implements View.OnClick final MainActivity activity = getMainActivity(); final Account currentAccount = activity.getCurrentAccount(); Twitter twitter = TwitterApi.getTwitter(currentAccount); - final UserListListAdapter adapter = getListAdapter(activity); + final UserListListAdapter adapter = (UserListListAdapter) getListAdapter(); String listFullName = adapter.getListFullName(); if (TextUtils.isEmpty(listFullName)) { new UIHandler() { @@ -173,7 +178,7 @@ public class UserListFragment extends CustomListFragment implements View.OnClick public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View page = inflater.inflate(R.layout.fragment_userlist, container, false); PullToRefreshListView listView = getListView(page); - UserListListAdapter adapter = getListAdapter((MainActivity) getActivity()); + UserListListAdapter adapter = (UserListListAdapter) getListAdapter(); listView.setAdapter(adapter); listView.setOnScrollListener(this); listView.setOnRefreshListener(this); @@ -185,10 +190,6 @@ public class UserListFragment extends CustomListFragment implements View.OnClick return page; } - private UserListListAdapter getListAdapter(MainActivity activity) { - return (UserListListAdapter) getListAdapter(MainActivity.AdapterID.UserList); - } - private TextView getTextListName(View page) { return (TextView) page.findViewById(R.id.textview_userlist_name); } @@ -206,7 +207,7 @@ public class UserListFragment extends CustomListFragment implements View.OnClick @Override public void onDismiss(DialogInterface dialog) { super.onDismiss(dialog); - textListName.setText(getListAdapter(mainActivity).getListFullName()); + textListName.setText(((UserListListAdapter) getListAdapter()).getListFullName()); } }); } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java index 3f4acbb6..e2e07b80 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java @@ -74,7 +74,6 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements // ------------------------------ FIELDS ------------------------------ private static final String KEY_USER_ID = "userID"; - private static final int ADAPTER_INDEX = 100; private StatusListAdapter adapter; private TextView textViewScreenName; private TextView textViewName; |