This commit is contained in:
Mariotaku Lee 2016-02-05 02:49:44 +08:00
parent c505dcc43c
commit bcd1d81d72
3 changed files with 48 additions and 71 deletions

View File

@ -17,17 +17,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.mariotaku.twidere.fragment; package org.mariotaku.twidere.fragment.support;
import android.app.Dialog; import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
@ -60,8 +58,6 @@ import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.support.UserListSelectorActivity; import org.mariotaku.twidere.activity.support.UserListSelectorActivity;
import org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter; import org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter;
import org.mariotaku.twidere.adapter.SourceAutoCompleteAdapter; import org.mariotaku.twidere.adapter.SourceAutoCompleteAdapter;
import org.mariotaku.twidere.fragment.support.AbsContentListViewFragment;
import org.mariotaku.twidere.fragment.support.BaseSupportDialogFragment;
import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
import org.mariotaku.twidere.util.ContentValuesCreator; import org.mariotaku.twidere.util.ContentValuesCreator;
@ -76,23 +72,11 @@ import javax.inject.Inject;
import static org.mariotaku.twidere.util.Utils.getDefaultAccountId; import static org.mariotaku.twidere.util.Utils.getDefaultAccountId;
public abstract class BaseFiltersFragment extends AbsContentListViewFragment<SimpleCursorAdapter> implements LoaderManager.LoaderCallbacks<Cursor>, public abstract class BaseFiltersFragment extends AbsContentListViewFragment<SimpleCursorAdapter>
MultiChoiceModeListener { implements LoaderManager.LoaderCallbacks<Cursor>, MultiChoiceModeListener {
private static final String EXTRA_AUTO_COMPLETE_TYPE = "auto_complete_type"; private static final String EXTRA_AUTO_COMPLETE_TYPE = "auto_complete_type";
private static final int AUTO_COMPLETE_TYPE_SOURCES = 2; private static final int AUTO_COMPLETE_TYPE_SOURCES = 2;
private final BroadcastReceiver mStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
if (getActivity() == null || !isAdded() || isDetached()) return;
final String action = intent.getAction();
if (BROADCAST_FILTERS_UPDATED.equals(action)) {
getLoaderManager().restartLoader(0, null, BaseFiltersFragment.this);
}
}
};
private ContentResolver mResolver; private ContentResolver mResolver;
private ActionMode mActionMode; private ActionMode mActionMode;
@ -123,19 +107,6 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment<Sim
return view; return view;
} }
@Override
public void onStart() {
super.onStart();
final IntentFilter filter = new IntentFilter(BROADCAST_FILTERS_UPDATED);
registerReceiver(mStateReceiver, filter);
}
@Override
public void onStop() {
unregisterReceiver(mStateReceiver);
super.onStop();
}
@Override @Override
public void setUserVisibleHint(final boolean isVisibleToUser) { public void setUserVisibleHint(final boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser); super.setUserVisibleHint(isVisibleToUser);
@ -256,7 +227,6 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment<Sim
public static final class AddItemFragment extends BaseSupportDialogFragment implements OnClickListener { public static final class AddItemFragment extends BaseSupportDialogFragment implements OnClickListener {
@Override @Override
public void onClick(final DialogInterface dialog, final int which) { public void onClick(final DialogInterface dialog, final int which) {
switch (which) { switch (which) {
@ -413,14 +383,43 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment<Sim
} }
} }
@Override
public String[] getContentColumns() {
return Filters.Users.COLUMNS;
}
@Override
public Uri getContentUri() {
return Filters.Users.CONTENT_URI;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.add: {
final Intent intent = new Intent(INTENT_ACTION_SELECT_USER);
intent.setClass(getContext(), UserListSelectorActivity.class);
intent.putExtra(EXTRA_ACCOUNT_ID, getDefaultAccountId(getActivity()));
startActivityForResult(intent, REQUEST_SELECT_USER);
return true;
}
}
return super.onOptionsItemSelected(item);
}
@NonNull
@Override
protected SimpleCursorAdapter onCreateAdapter(Context context, boolean isCompact) {
return new FilterUsersListAdapter(getActivity());
}
public static final class FilterUsersListAdapter extends SimpleCursorAdapter { public static final class FilterUsersListAdapter extends SimpleCursorAdapter {
private final boolean mNameFirst;
@Inject @Inject
UserColorNameManager mUserColorNameManager; UserColorNameManager mUserColorNameManager;
@Inject @Inject
SharedPreferencesWrapper mPreferences; SharedPreferencesWrapper mPreferences;
private final boolean mNameFirst;
private int mUserIdIdx, mNameIdx, mScreenNameIdx; private int mUserIdIdx, mNameIdx, mScreenNameIdx;
FilterUsersListAdapter(final Context context) { FilterUsersListAdapter(final Context context) {
@ -454,35 +453,5 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment<Sim
} }
@Override
public String[] getContentColumns() {
return Filters.Users.COLUMNS;
}
@Override
public Uri getContentUri() {
return Filters.Users.CONTENT_URI;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.add: {
final Intent intent = new Intent(INTENT_ACTION_SELECT_USER);
intent.setClass(getActivity(), UserListSelectorActivity.class);
intent.putExtra(EXTRA_ACCOUNT_ID, getDefaultAccountId(getActivity()));
startActivityForResult(intent, REQUEST_SELECT_USER);
return true;
}
}
return super.onOptionsItemSelected(item);
}
@NonNull
@Override
protected SimpleCursorAdapter onCreateAdapter(Context context, boolean isCompact) {
return new FilterUsersListAdapter(getActivity());
}
} }
} }

View File

@ -19,6 +19,7 @@
package org.mariotaku.twidere.fragment.support; package org.mariotaku.twidere.fragment.support;
import android.content.Intent;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -32,14 +33,13 @@ import android.view.ViewGroup;
import org.mariotaku.twidere.R; import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.iface.IThemedActivity; import org.mariotaku.twidere.activity.iface.IThemedActivity;
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter; import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
import org.mariotaku.twidere.fragment.BaseFiltersFragment.FilteredKeywordsFragment;
import org.mariotaku.twidere.fragment.BaseFiltersFragment.FilteredLinksFragment;
import org.mariotaku.twidere.fragment.BaseFiltersFragment.FilteredSourcesFragment;
import org.mariotaku.twidere.fragment.BaseFiltersFragment.FilteredUsersFragment;
import org.mariotaku.twidere.fragment.iface.IBaseFragment; import org.mariotaku.twidere.fragment.iface.IBaseFragment;
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface; import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback; import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback;
import org.mariotaku.twidere.fragment.support.BaseSupportFragment; import org.mariotaku.twidere.fragment.support.BaseFiltersFragment.FilteredKeywordsFragment;
import org.mariotaku.twidere.fragment.support.BaseFiltersFragment.FilteredLinksFragment;
import org.mariotaku.twidere.fragment.support.BaseFiltersFragment.FilteredSourcesFragment;
import org.mariotaku.twidere.fragment.support.BaseFiltersFragment.FilteredUsersFragment;
import org.mariotaku.twidere.graphic.EmptyDrawable; import org.mariotaku.twidere.graphic.EmptyDrawable;
import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.view.TabPagerIndicator; import org.mariotaku.twidere.view.TabPagerIndicator;
@ -96,6 +96,14 @@ public class FiltersFragment extends BaseSupportFragment implements RefreshScrol
mPagerOverlay = view.findViewById(R.id.pager_window_overlay); mPagerOverlay = view.findViewById(R.id.pager_window_overlay);
} }
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
final Object o = mPagerAdapter.instantiateItem(mViewPager, mViewPager.getCurrentItem());
if (o instanceof Fragment) {
((Fragment) o).onActivityResult(requestCode, resultCode, data);
}
}
@Override @Override
public boolean scrollToStart() { public boolean scrollToStart() {
final Fragment fragment = getCurrentVisibleFragment(); final Fragment fragment = getCurrentVisibleFragment();

View File

@ -36,7 +36,7 @@ import org.mariotaku.twidere.adapter.DraftsAdapter;
import org.mariotaku.twidere.adapter.DummyStatusHolderAdapter; import org.mariotaku.twidere.adapter.DummyStatusHolderAdapter;
import org.mariotaku.twidere.adapter.UserAutoCompleteAdapter; import org.mariotaku.twidere.adapter.UserAutoCompleteAdapter;
import org.mariotaku.twidere.fragment.BaseDialogFragment; import org.mariotaku.twidere.fragment.BaseDialogFragment;
import org.mariotaku.twidere.fragment.BaseFiltersFragment; import org.mariotaku.twidere.fragment.support.BaseFiltersFragment;
import org.mariotaku.twidere.fragment.BaseFragment; import org.mariotaku.twidere.fragment.BaseFragment;
import org.mariotaku.twidere.fragment.BaseListFragment; import org.mariotaku.twidere.fragment.BaseListFragment;
import org.mariotaku.twidere.fragment.BasePreferenceFragment; import org.mariotaku.twidere.fragment.BasePreferenceFragment;