diff options
10 files changed, 23 insertions, 53 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 3fe3370c..4ac1824e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java @@ -332,19 +332,19 @@ public class MainActivity extends Activity { // -------------------------- OTHER METHODS -------------------------- - public int addListPage(Class<? extends CustomListFragment> fragmentClass, CustomListAdapter<?> adapter, AdapterID adapterId, boolean visible) { + public int addListPage(Class<? extends CustomListFragment> fragmentClass, String name, CustomListAdapter<?> adapter, AdapterID adapterId, boolean visible) { if (visible) { Bundle args = new Bundle(); adapterMap.put(adapterId, adapter); - return addPage(fragmentClass, args, false); + return addPage(fragmentClass, name, args, false); } else { return PAGE_INDEX_GONE; } } @Deprecated - public int addPage(Class<? extends PageFragment> fragmentClass, Bundle args, boolean withNotify) { - pagerAdapter.addPage(fragmentClass, args, withNotify); + public int addPage(Class<? extends PageFragment> fragmentClass, String name, Bundle args, boolean withNotify) { + pagerAdapter.addPage(fragmentClass, name, args, withNotify); return pagerAdapter.getCount() - 1; } @@ -499,45 +499,41 @@ public class MainActivity extends Activity { } private void addPostPage() { - pageIndexPost = addPage(PostFragment.class, null, true); + pageIndexPost = addPage(PostFragment.class, getString(R.string.page_name_post), null, true); } private void addHomePage() { StatusListAdapter homeAdapter = new StatusListAdapter(this); - pageIndexHome = addListPage( HomeFragment.class, homeAdapter, AdapterID.Home, true); + pageIndexHome = addListPage( HomeFragment.class, getString(R.string.page_name_home), homeAdapter, AdapterID.Home, true); } private void addMentionsPage() { StatusListAdapter mentionsAdapter = new StatusListAdapter(this); - pageIndexMentions = addListPage(MentionsFragment.class, mentionsAdapter, AdapterID.Mentions, true); + pageIndexMentions = addListPage(MentionsFragment.class, getString(R.string.page_name_mentions), mentionsAdapter, AdapterID.Mentions, true); } private void addHistoryPage() { boolean visible = getUserPreferenceHelper().getValue(R.string.key_page_history_visibility, true); - getUserPreferenceHelper().putValue(R.string.key_page_history_visibility, visible); EventListAdapter historyAdapter = new EventListAdapter(this); - pageIndexHistory = addListPage(HistoryFragment.class, historyAdapter, AdapterID.History, visible); + pageIndexHistory = addListPage(HistoryFragment.class, getString(R.string.page_name_history), historyAdapter, AdapterID.History, visible); } private void addMessagesPage() { boolean visible = getUserPreferenceHelper().getValue(R.string.key_page_messages_visibility, true); - getUserPreferenceHelper().putValue(R.string.key_page_messages_visibility, visible); MessageListAdapter messagesAdapter = new MessageListAdapter(this); - pageIndexMessages = addListPage(MessagesFragment.class, messagesAdapter, AdapterID.Messages, visible); + pageIndexMessages = addListPage(MessagesFragment.class, getString(R.string.page_name_messages), messagesAdapter, AdapterID.Messages, visible); } private void addSearchPage() { boolean visible = getUserPreferenceHelper().getValue(R.string.key_page_search_visibility, true); - getUserPreferenceHelper().putValue(R.string.key_page_search_visibility, visible); SearchListAdapter searchAdapter = new SearchListAdapter(this); - pageIndexSearch = addListPage(SearchFragment.class, searchAdapter, AdapterID.Search, visible); + pageIndexSearch = addListPage(SearchFragment.class, getString(R.string.page_name_search), searchAdapter, AdapterID.Search, visible); } private void addUserListPage() { boolean visible = getUserPreferenceHelper().getValue(R.string.key_page_list_visibility, true); - getUserPreferenceHelper().putValue(R.string.key_page_list_visibility, visible); UserListListAdapter userListAdapter = new UserListListAdapter(this); - pageIndexUserList = addListPage(UserListFragment.class, userListAdapter, AdapterID.UserList, visible); + pageIndexUserList = addListPage(UserListFragment.class, getString(R.string.page_name_list), userListAdapter, AdapterID.UserList, visible); } private void getImageUri(int requestCode, int resultCode, Intent data) { 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 a0e05283..a26832c1 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/HistoryFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/HistoryFragment.java @@ -35,11 +35,6 @@ import net.lacolaco.smileessence.activity.MainActivity; */ public class HistoryFragment extends CustomListFragment { - @Override - public String getName() { - return getString(R.string.page_name_history); - } - // --------------------- GETTER / SETTER METHODS --------------------- @Override 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 f9b8262a..23b1339b 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java @@ -47,10 +47,6 @@ import java.util.List; import java.util.ListIterator; public class HomeFragment extends CustomListFragment { - @Override - public String getName() { - return getString(R.string.page_name_home); - } // --------------------- GETTER / SETTER METHODS --------------------- 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 2b0e95ef..831bd41e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/MentionsFragment.java @@ -44,10 +44,6 @@ import twitter4j.Twitter; import java.util.List; public class MentionsFragment extends CustomListFragment { - @Override - public String getName() { - return getString(R.string.page_name_mentions); - } // --------------------- GETTER / SETTER METHODS --------------------- 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 8f0232c5..ac0e8067 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/MessagesFragment.java @@ -47,10 +47,6 @@ import java.util.List; * Fragment of messages list */ public class MessagesFragment extends CustomListFragment { - @Override - public String getName() { - return getString(R.string.page_name_messages); - } // --------------------- GETTER / SETTER METHODS --------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/view/PageFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/PageFragment.java index 335b4328..b5f54474 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/PageFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/PageFragment.java @@ -3,5 +3,4 @@ package net.lacolaco.smileessence.view; import android.app.Fragment; public abstract class PageFragment extends Fragment { - public abstract String getName(); } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java index 22daa18c..91e0b05f 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java @@ -62,11 +62,6 @@ import java.io.File; public class PostFragment extends PageFragment implements TextWatcher, View.OnFocusChangeListener, View.OnClickListener, PostState.OnPostStateChangeListener { - @Override - public String getName() { - return getString(R.string.page_name_post); - } - // ------------------------------ FIELDS ------------------------------ private EditText editText; 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 381affba..f1a069bc 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java @@ -66,10 +66,6 @@ import java.util.List; public class SearchFragment extends CustomListFragment implements View.OnClickListener, View.OnFocusChangeListener, SearchListAdapter.OnQueryChangeListener { - @Override - public String getName() { - return getString(R.string.page_name_search); - } // ------------------------------ FIELDS ------------------------------ 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 620584eb..3733358a 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java @@ -57,10 +57,6 @@ import twitter4j.Twitter; import java.util.List; public class UserListFragment extends CustomListFragment implements View.OnClickListener { - @Override - public String getName() { - return getString(R.string.page_name_list); - } // ------------------------------ FIELDS ------------------------------ diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java index 71b00124..bc933e88 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java @@ -36,6 +36,8 @@ import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.view.PageFragment; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @@ -102,13 +104,12 @@ public class PageListAdapter extends FragmentPagerAdapter implements ViewPager.O return Fragment.instantiate(context, info.getFragmentClass().getName(), info.getArgs()); } - public void addPage(Class<? extends PageFragment> klass, Bundle args) { - this.addPage(klass, args, true); + public void addPage(Class<? extends PageFragment> klass, String name, Bundle args) { + this.addPage(klass, name, args, true); } - public void addPage(Class<? extends PageFragment> klass, Bundle args, boolean notifyChanged) { - PageInfo info = new PageInfo(klass, args); - pages.add(info); + public void addPage(Class<? extends PageFragment> klass, String name, Bundle args, boolean notifyChanged) { + pages.add(new PageInfo(klass, name, args)); if (notifyChanged) notifyDataSetChanged(); } @@ -124,7 +125,7 @@ public class PageListAdapter extends FragmentPagerAdapter implements ViewPager.O public void notifyDataSetChanged() { ArrayList<String> itemList = new ArrayList<>(); for (PageInfo f : pages) { - itemList.add(f.getFragmentClass().getName()); //TODO + itemList.add(f.getName()); } ArrayAdapter<String> adapter = new ArrayAdapter<>(context, R.layout.navigation_list_item, R.id.navigation_list_item_text, itemList); actionBar.setListNavigationCallbacks(adapter, this); @@ -134,9 +135,11 @@ public class PageListAdapter extends FragmentPagerAdapter implements ViewPager.O private static final class PageInfo { private final Class<? extends PageFragment> fragmentClass; private final Bundle args; + private final String name; - PageInfo(Class<? extends PageFragment> _fragmentClass, Bundle _args) { + PageInfo(Class<? extends PageFragment> _fragmentClass, String _name, Bundle _args) { fragmentClass = _fragmentClass; + name = _name; args = _args; } @@ -144,6 +147,8 @@ public class PageListAdapter extends FragmentPagerAdapter implements ViewPager.O return fragmentClass; } + public String getName() { return name; } + public Bundle getArgs() { return args; } |