private void checkDisableTouch() { mCheckDisableTouch = true; mRoot.postDelayed( new Runnable() { @Override public void run() { Log.d("TEST", "activeDownloaders = " + activeDownloaders); if (mRoot != null) mRoot.setDisableTouch(activeDownloaders > 0); if (activeDownloaders == 0) { if (!(getListView() != null && getListView().getLastVisiblePosition() == mAdapter.getCount() - 1)) { Log.d("TEST", "smoothScrollBy"); if (getListView() != null) getListView().smoothScrollBy(getListView().getHeight(), 700); } else { Log.d("TEST", "setImageDownloaded true"); UtilHelper.setImageDownloaded(getActivity(), true); } } mCheckDisableTouch = false; } }, 250); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = (DisableTouchFrameLayout) inflater.inflate(R.layout.start_fragment, null); mProgressBar = (ProgressBar) mRoot.findViewById(R.id.start_fragment_pb); mLoginBtn = (LoginButton) mRoot.findViewById(android.R.id.empty); mLoginBtn.setFragment(this); mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.layout_item_friend, null, from, to, 0); mAdapter.setViewBinder( new ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int index) { int viewId = view.getId(); if (viewId == R.id.item_friend_image) { ImageView avatar = (ImageView) view; String photoUrl = cursor.getString(cursor.getColumnIndex(DBHelper.KEY_COLUMN_PICTURE)); if (mImageLoader != null && mOptions != null && photoUrl != null && !TextUtils.isEmpty(photoUrl)) mImageLoader.displayImage( photoUrl, avatar, mOptions, new ImageLoadingListener() { @Override public void onLoadingStarted(String arg0, View arg1) { activeDownloaders++; if (!UtilHelper.isImageDownloaded()) {} } @Override public void onLoadingFailed(String arg0, View arg1, FailReason arg2) { activeDownloaders--; if (!UtilHelper.isImageDownloaded() && !mCheckDisableTouch) { checkDisableTouch(); } } @Override public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) { activeDownloaders--; if (!UtilHelper.isImageDownloaded() && !mCheckDisableTouch) { checkDisableTouch(); } } @Override public void onLoadingCancelled(String arg0, View arg1) { activeDownloaders--; if (!UtilHelper.isImageDownloaded() && !mCheckDisableTouch) { checkDisableTouch(); } } }); return true; } return false; } }); setListAdapter(mAdapter); getLoaderManager().restartLoader(FRIENDS_LOADER_ID, null, this); return mRoot; }