2014-07-03 07:48:39 +02:00
|
|
|
/*
|
|
|
|
* Twidere - Twitter client for Android
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.mariotaku.twidere.fragment.support;
|
|
|
|
|
|
|
|
import android.app.ActionBar;
|
2014-12-01 17:04:55 +01:00
|
|
|
import android.graphics.Rect;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.provider.SearchRecentSuggestions;
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.FragmentActivity;
|
2014-12-01 17:04:55 +01:00
|
|
|
import android.support.v4.view.ViewPager;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
2014-11-01 17:57:31 +01:00
|
|
|
import android.view.MenuInflater;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import org.mariotaku.twidere.R;
|
|
|
|
import org.mariotaku.twidere.activity.support.LinkHandlerActivity;
|
|
|
|
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
|
2014-12-01 17:04:55 +01:00
|
|
|
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback;
|
2014-07-03 07:48:39 +02:00
|
|
|
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
|
|
|
|
import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback;
|
|
|
|
import org.mariotaku.twidere.provider.RecentSearchProvider;
|
|
|
|
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
2014-12-12 14:53:18 +01:00
|
|
|
import org.mariotaku.twidere.view.TabPagerIndicator;
|
2014-07-03 07:48:39 +02:00
|
|
|
|
2014-12-01 17:04:55 +01:00
|
|
|
public class SearchFragment extends BaseSupportFragment implements RefreshScrollTopInterface,
|
|
|
|
SupportFragmentCallback, SystemWindowsInsetsCallback {
|
2014-07-03 09:58:09 +02:00
|
|
|
|
2014-12-01 17:04:55 +01:00
|
|
|
private ViewPager mViewPager;
|
2014-07-03 09:58:09 +02:00
|
|
|
|
|
|
|
private SupportTabsAdapter mAdapter;
|
2014-12-12 14:53:18 +01:00
|
|
|
private TabPagerIndicator mPagerIndicator;
|
2014-07-03 09:58:09 +02:00
|
|
|
|
|
|
|
private Fragment mCurrentVisibleFragment;
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
@Override
|
|
|
|
protected void fitSystemWindows(Rect insets) {
|
|
|
|
super.fitSystemWindows(insets);
|
|
|
|
final View view = getView();
|
|
|
|
if (view != null) {
|
|
|
|
view.setPadding(insets.left, insets.top, insets.right, insets.bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 09:58:09 +02:00
|
|
|
@Override
|
|
|
|
public Fragment getCurrentVisibleFragment() {
|
|
|
|
return mCurrentVisibleFragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideIndicator() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(final Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
final Bundle args = getArguments();
|
|
|
|
final FragmentActivity activity = getActivity();
|
|
|
|
mAdapter = new SupportTabsAdapter(activity, getChildFragmentManager(), null, 1);
|
2014-12-05 14:25:27 +01:00
|
|
|
mAdapter.addTab(StatusesSearchFragment.class, args, getString(R.string.statuses),
|
2014-10-22 09:36:41 +02:00
|
|
|
R.drawable.ic_action_twitter, 0);
|
|
|
|
mAdapter.addTab(SearchUsersFragment.class, args, getString(R.string.users), R.drawable.ic_action_user, 1);
|
2014-07-03 09:58:09 +02:00
|
|
|
mViewPager.setAdapter(mAdapter);
|
|
|
|
mViewPager.setOffscreenPageLimit(2);
|
|
|
|
mPagerIndicator.setViewPager(mViewPager);
|
|
|
|
if (savedInstanceState == null && args != null && args.containsKey(EXTRA_QUERY)) {
|
|
|
|
final String query = args.getString(EXTRA_QUERY);
|
|
|
|
final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(),
|
|
|
|
RecentSearchProvider.AUTHORITY, RecentSearchProvider.MODE);
|
|
|
|
suggestions.saveRecentQuery(query, null);
|
|
|
|
if (activity instanceof LinkHandlerActivity) {
|
|
|
|
final ActionBar ab = activity.getActionBar();
|
|
|
|
if (ab != null) {
|
|
|
|
ab.setSubtitle(query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-01 17:57:31 +01:00
|
|
|
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
2014-07-03 09:58:09 +02:00
|
|
|
inflater.inflate(R.menu.menu_search, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
2014-12-01 17:04:55 +01:00
|
|
|
return inflater.inflate(R.layout.fragment_content_pages, container, false);
|
2014-07-03 09:58:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDetachFragment(final Fragment fragment) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case MENU_SAVE: {
|
|
|
|
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
|
|
|
final Bundle args = getArguments();
|
|
|
|
if (twitter != null && args != null) {
|
|
|
|
final long accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);
|
|
|
|
final String query = args.getString(EXTRA_QUERY);
|
|
|
|
twitter.createSavedSearchAsync(accountId, query);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetUserVisibleHint(final Fragment fragment, final boolean isVisibleToUser) {
|
|
|
|
if (isVisibleToUser) {
|
|
|
|
mCurrentVisibleFragment = fragment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewCreated(final View view, final Bundle savedInstanceState) {
|
|
|
|
super.onViewCreated(view, savedInstanceState);
|
2014-12-01 17:04:55 +01:00
|
|
|
mViewPager = (ViewPager) view.findViewById(R.id.view_pager);
|
2014-12-12 14:53:18 +01:00
|
|
|
mPagerIndicator = (TabPagerIndicator) view.findViewById(R.id.view_pager_tabs);
|
2014-07-03 09:58:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean scrollToStart() {
|
|
|
|
if (!(mCurrentVisibleFragment instanceof RefreshScrollTopInterface)) return false;
|
|
|
|
((RefreshScrollTopInterface) mCurrentVisibleFragment).scrollToStart();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showIndicator() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean triggerRefresh() {
|
|
|
|
if (!(mCurrentVisibleFragment instanceof RefreshScrollTopInterface)) return false;
|
|
|
|
((RefreshScrollTopInterface) mCurrentVisibleFragment).triggerRefresh();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean triggerRefresh(final int position) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-03 07:48:39 +02:00
|
|
|
|
2014-12-01 17:04:55 +01:00
|
|
|
@Override
|
|
|
|
public boolean getSystemWindowsInsets(Rect insets) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-03 07:48:39 +02:00
|
|
|
}
|