1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2024-12-24 23:43:10 +01:00

fixed npe

fixed build error
This commit is contained in:
Mariotaku Lee 2016-02-26 13:24:41 +08:00
parent 4c5fd2e8de
commit 56f77bd947
4 changed files with 37 additions and 18 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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));
}

View File

@ -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 <T> 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) {