mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
Added basic loading view when initially loading content.
This commit is contained in:
parent
3bb3ca3eed
commit
d1a7c366aa
6 changed files with 79 additions and 26 deletions
21
media/android/NewsBlur/res/layout/fragment_loadingitems.xml
Normal file
21
media/android/NewsBlur/res/layout/fragment_loadingitems.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/list_background">
|
||||
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/loading"
|
||||
android:textSize="20dp"
|
||||
android:textColor="@color/white"
|
||||
android:textStyle="bold"
|
||||
android:shadowColor="@color/darkgray"
|
||||
android:shadowDx="0"
|
||||
android:shadowDy="0"
|
||||
android:shadowRadius="4" />
|
||||
|
||||
</LinearLayout>
|
|
@ -17,6 +17,7 @@
|
|||
<string name="hello">Hello World!</string>
|
||||
|
||||
<string name="dialog_title">Alert</string>
|
||||
<string name="loading">Loading…</string>
|
||||
|
||||
<string name="follow_error">There was a problem following the user. Check your internet connection and try again.</string>
|
||||
<string name="unfollow_error">There was a problem unfollowing the user. Check your internet connection and try again.</string>
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.actionbarsherlock.view.Window;
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.database.FeedProvider;
|
||||
import com.newsblur.database.ReadingAdapter;
|
||||
|
@ -39,6 +40,9 @@ public class Reading extends SherlockFragmentActivity {
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceBundle) {
|
||||
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||
|
||||
super.onCreate(savedInstanceBundle);
|
||||
setContentView(R.layout.activity_reading);
|
||||
|
||||
|
@ -47,14 +51,15 @@ public class Reading extends SherlockFragmentActivity {
|
|||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
readingAdapter = new ReadingAdapter(fragmentManager, this, feedId);
|
||||
getSupportLoaderManager().initLoader(READING_LOADER , null, readingAdapter);
|
||||
|
||||
|
||||
contentResolver = getContentResolver();
|
||||
final Uri feedUri = FeedProvider.FEEDS_URI.buildUpon().appendPath(feedId).build();
|
||||
|
||||
feed = Feed.fromCursor(contentResolver.query(feedUri, null, null, null, null));
|
||||
setTitle(feed.title);
|
||||
|
||||
getSupportLoaderManager().initLoader(READING_LOADER , null, readingAdapter);
|
||||
|
||||
syncFragment = (SyncReadingUpdaterFragment) fragmentManager.findFragmentByTag(SyncReadingUpdaterFragment.TAG);
|
||||
if (syncFragment == null) {
|
||||
syncFragment = new SyncReadingUpdaterFragment();
|
||||
|
@ -64,16 +69,17 @@ public class Reading extends SherlockFragmentActivity {
|
|||
|
||||
pager = (ViewPager) findViewById(R.id.reading_pager);
|
||||
pager.setAdapter(readingAdapter);
|
||||
setProgressBarVisibility(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
MenuInflater inflater = getSupportMenuInflater();
|
||||
inflater.inflate(R.menu.reading, menu);
|
||||
return true;
|
||||
inflater.inflate(R.menu.reading, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void triggerRefresh() {
|
||||
final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class);
|
||||
intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, syncFragment.receiver);
|
||||
|
@ -85,13 +91,14 @@ public class Reading extends SherlockFragmentActivity {
|
|||
public void redrawUI() {
|
||||
Log.d(TAG, "Redrawing reading pager...");
|
||||
getSupportLoaderManager().restartLoader(READING_LOADER, null, readingAdapter);
|
||||
setProgressBarVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int currentItem = pager.getCurrentItem();
|
||||
Story story = readingAdapter.getStory(currentItem);
|
||||
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
|
@ -154,7 +161,6 @@ public class Reading extends SherlockFragmentActivity {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,25 +13,28 @@ import android.support.v4.content.Loader;
|
|||
import android.util.Log;
|
||||
|
||||
import com.newsblur.domain.Story;
|
||||
import com.newsblur.fragment.LoadingFragment;
|
||||
import com.newsblur.fragment.ReadingItemFragment;
|
||||
|
||||
public class ReadingAdapter extends FragmentStatePagerAdapter implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
|
||||
|
||||
private Context context;
|
||||
private Cursor cursor;
|
||||
private Uri feedUri;
|
||||
private String TAG = "ReadingAdapter";
|
||||
|
||||
private String TAG = "ReadingAdapter";
|
||||
private LoadingFragment loadingFragment;
|
||||
|
||||
public ReadingAdapter(final FragmentManager fragmentManager, final Context context, final String feedId) {
|
||||
super(fragmentManager);
|
||||
this.context = context;
|
||||
feedUri = FeedProvider.STORIES_URI.buildUpon().appendPath(feedId).build();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
if (cursor == null || cursor.getCount() == 0) {
|
||||
loadingFragment = new LoadingFragment();
|
||||
return loadingFragment;
|
||||
} else {
|
||||
cursor.moveToPosition(position);
|
||||
return new ReadingItemFragment(Story.fromCursor(cursor));
|
||||
|
@ -40,14 +43,14 @@ public class ReadingAdapter extends FragmentStatePagerAdapter implements LoaderM
|
|||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (cursor != null) {
|
||||
if (cursor != null && cursor.getCount() > 0) {
|
||||
return cursor.getCount();
|
||||
} else {
|
||||
Log.d(TAG , "No cursor");
|
||||
return 0;
|
||||
Log.d(TAG , "No cursor - use loading view.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Story getStory(int position) {
|
||||
if (cursor == null || position > cursor.getCount()) {
|
||||
return null;
|
||||
|
@ -56,11 +59,20 @@ public class ReadingAdapter extends FragmentStatePagerAdapter implements LoaderM
|
|||
return Story.fromCursor(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemPosition(Object object) {
|
||||
if (object instanceof LoadingFragment) {
|
||||
return POSITION_NONE;
|
||||
} else {
|
||||
return POSITION_UNCHANGED;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int loaderId, Bundle bundle) {
|
||||
CursorLoader cursorLoader = new CursorLoader(context, feedUri, null, null, null, null);
|
||||
return cursorLoader;
|
||||
return cursorLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,7 +85,7 @@ public class ReadingAdapter extends FragmentStatePagerAdapter implements LoaderM
|
|||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.newsblur.fragment;
|
||||
|
||||
import com.newsblur.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class LoadingFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_loadingitems, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,18 +7,14 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.domain.Feed;
|
||||
import com.newsblur.domain.Story;
|
||||
import com.newsblur.util.ImageLoader;
|
||||
|
||||
public class ReadingItemFragment extends Fragment {
|
||||
|
||||
final Story story;
|
||||
private ImageLoader imageLoader;
|
||||
|
||||
public ReadingItemFragment() {
|
||||
story = null;
|
||||
|
@ -32,7 +28,6 @@ public class ReadingItemFragment extends Fragment {
|
|||
View view = inflater.inflate(R.layout.fragment_readingitem, null);
|
||||
|
||||
WebView web = (WebView) view.findViewById(R.id.reading_webview);
|
||||
imageLoader = new ImageLoader(getActivity());
|
||||
setupWebview(web);
|
||||
setupItemMetadata(view);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue