diff --git a/twidere/src/google/java/org/mariotaku/twidere/fragment/support/GoogleMapFragment.java b/twidere/src/google/java/org/mariotaku/twidere/fragment/support/GoogleMapFragment.java index 471dfebae..ec8ae11c5 100644 --- a/twidere/src/google/java/org/mariotaku/twidere/fragment/support/GoogleMapFragment.java +++ b/twidere/src/google/java/org/mariotaku/twidere/fragment/support/GoogleMapFragment.java @@ -43,6 +43,7 @@ import org.mariotaku.twidere.fragment.iface.IMapFragment; public class GoogleMapFragment extends SupportMapFragment implements Constants, IMapFragment, IBaseFragment { private GoogleMap mMapView; + private ActionHelper mActionHelper = new ActionHelper(this); @Override public void onActivityCreated(final Bundle savedInstanceState) { @@ -59,6 +60,18 @@ public class GoogleMapFragment extends SupportMapFragment implements Constants, center(false); } + @Override + public void onPause() { + mActionHelper.dispatchOnPause(); + super.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + mActionHelper.dispatchOnResumeFragments(); + } + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_google_maps_viewer, menu); @@ -135,6 +148,11 @@ public class GoogleMapFragment extends SupportMapFragment implements Constants, } + @Override + public void executeAfterFragmentResumed(Action action) { + mActionHelper.executeAfterFragmentResumed(action); + } + protected void fitSystemWindows(Rect insets) { final View view = getView(); if (view != null) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java index 1e6f12bf8..5c4a78250 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java @@ -28,6 +28,7 @@ import android.graphics.Rect; import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; @@ -99,10 +100,11 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On @Override public void onDismiss(ListView listView, int[] reverseSortedPositions) { - final Long[] ids = new Long[reverseSortedPositions.length]; + final long[] ids = new long[reverseSortedPositions.length]; for (int i = 0, j = reverseSortedPositions.length; i < j; i++) { final int position = reverseSortedPositions[i]; final SuggestionItem item = mUsersSearchAdapter.getSuggestionItem(position); + if (item == null) return; ids[i] = item._id; } mUsersSearchAdapter.addRemovedPositions(reverseSortedPositions); @@ -334,6 +336,8 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On private final UserColorNameManager mUserColorNameManager; private final QuickSearchBarActivity mActivity; private final SortableIntList mRemovedPositions; + + @Nullable private Indices mIndices; SuggestionsAdapter(QuickSearchBarActivity activity) { @@ -368,11 +372,13 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On public SuggestionItem getSuggestionItem(int position) { final Cursor cursor = (Cursor) getItem(position); + if (cursor == null || mIndices == null) return null; return new SuggestionItem(cursor, mIndices); } @Override public void bindView(View view, Context context, Cursor cursor) { + if (mIndices == null) throw new NullPointerException(); switch (getActualItemViewType(cursor.getPosition())) { case VIEW_TYPE_SEARCH_HISTORY: { final SearchViewHolder holder = (SearchViewHolder) view.getTag(); @@ -419,6 +425,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On public int getActualItemViewType(int position) { final Cursor cursor = (Cursor) super.getItem(position); + if (cursor == null || mIndices == null) throw new NullPointerException(); switch (cursor.getString(mIndices.type)) { case Suggestions.Search.TYPE_SAVED_SEARCH: { return VIEW_TYPE_SAVED_SEARCH; @@ -542,7 +549,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On private final int icon; private final int extra_id; - public Indices(Cursor cursor) { + public Indices(@NonNull Cursor cursor) { _id = cursor.getColumnIndex(Suggestions._ID); type = cursor.getColumnIndex(Suggestions.TYPE); title = cursor.getColumnIndex(Suggestions.TITLE); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereArrayUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereArrayUtils.java index d49b3f817..02a9871bd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereArrayUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereArrayUtils.java @@ -160,23 +160,17 @@ public final class TwidereArrayUtils { return builder.toString(); } - public static String[] toStringArray(final Object[] array, int start, int end) { + public static String[] toStringArray(final Object array, int start, int end) { if (array == null) return null; final String[] stringArray = new String[end - start]; for (int i = start; i < end; i++) { - stringArray[i - start] = ParseUtils.parseString(array[i]); + stringArray[i - start] = ParseUtils.parseString(Array.get(array, i)); } return stringArray; } - public static String[] toStringArray(final long[] array) { - if (array == null) return null; - final int length = array.length; - final String[] stringArray = new String[length]; - for (int i = 0; i < length; i++) { - stringArray[i] = ParseUtils.parseString(array[i]); - } - return stringArray; + public static String[] toStringArray(final Object array) { + return toStringArray(array, 0, Array.getLength(array)); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/content/ContentResolverUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/content/ContentResolverUtils.java index bc61a26f1..bf09aae1c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/content/ContentResolverUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/content/ContentResolverUtils.java @@ -27,6 +27,7 @@ import android.text.TextUtils; import org.mariotaku.twidere.util.TwidereArrayUtils; +import java.lang.reflect.Array; import java.util.Collection; public class ContentResolverUtils { @@ -40,14 +41,13 @@ public class ContentResolverUtils { return bulkDelete(resolver, uri, inColumn, colValues.toArray(), extraWhere, valuesIsString); } - public static int bulkDelete(@NonNull final ContentResolver resolver, @NonNull final Uri uri, - @NonNull final String inColumn, final T[] colValues, + public static int bulkDelete(@NonNull final ContentResolver resolver, @NonNull final Uri uri, + @NonNull final String inColumn, final Object colValues, final String extraWhere, final boolean valuesIsString) { - if (colValues == null || colValues.length == 0) - return 0; - final int colValuesLength = colValues.length, blocks_count = colValuesLength / MAX_BULK_COUNT + 1; + if (colValues == null) return 0; + final int colValuesLength = Array.getLength(colValues), blocksCount = colValuesLength / MAX_BULK_COUNT + 1; int rowsDeleted = 0; - for (int i = 0; i < blocks_count; i++) { + for (int i = 0; i < blocksCount; i++) { final int start = i * MAX_BULK_COUNT, end = Math.min(start + MAX_BULK_COUNT, colValuesLength); final String[] block = TwidereArrayUtils.toStringArray(colValues, start, end); if (valuesIsString) {