mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Merge pull request #567 from manderson23/swiperefresh
Android: Swipe to refresh
This commit is contained in:
commit
4caee4fb7b
6 changed files with 92 additions and 42 deletions
Binary file not shown.
|
@ -1,42 +1,50 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/swipe_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fragment_feedintelligenceselector"
|
||||
android:name="com.newsblur.fragment.FeedIntelligenceSelectorFragment"
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:tag="feedIntelligenceSelector" />
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fragment_folderfeedlist"
|
||||
android:name="com.newsblur.fragment.FolderListFragment"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_above="@id/fragment_feedintelligenceselector"
|
||||
android:layout_alignParentTop="true"
|
||||
android:tag="folderFeedListFragment" />
|
||||
<fragment
|
||||
android:id="@+id/fragment_feedintelligenceselector"
|
||||
android:name="com.newsblur.fragment.FeedIntelligenceSelectorFragment"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:tag="feedIntelligenceSelector" />
|
||||
|
||||
<View
|
||||
android:id="@+id/feedintelligenceselector_border"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/midgray"
|
||||
android:layout_below="@id/fragment_folderfeedlist" />
|
||||
<fragment
|
||||
android:id="@+id/fragment_folderfeedlist"
|
||||
android:name="com.newsblur.fragment.FolderListFragment"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_above="@id/fragment_feedintelligenceselector"
|
||||
android:layout_alignParentTop="true"
|
||||
android:tag="folderFeedListFragment" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/main_sync_status"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@+id/fragment_feedintelligenceselector"
|
||||
android:padding="3dp"
|
||||
android:textSize="14sp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/status_overlay_text"
|
||||
android:background="@color/status_overlay_background"
|
||||
android:text="SYNC STATUS" />
|
||||
<View
|
||||
android:id="@+id/feedintelligenceselector_border"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/midgray"
|
||||
android:layout_below="@id/fragment_folderfeedlist" />
|
||||
|
||||
</RelativeLayout>
|
||||
<TextView
|
||||
android:id="@+id/main_sync_status"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@+id/fragment_feedintelligenceselector"
|
||||
android:padding="3dp"
|
||||
android:textSize="14sp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/status_overlay_text"
|
||||
android:background="@color/status_overlay_background"
|
||||
android:text="SYNC STATUS" />
|
||||
|
||||
</RelativeLayout>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<item android:id="@+id/menu_refresh"
|
||||
android:icon="@drawable/barbutton_refresh"
|
||||
android:title="@string/menu_refresh"
|
||||
android:showAsAction="always" />
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/menu_profile"
|
||||
android:title="@string/menu_profile"
|
||||
|
|
|
@ -109,6 +109,11 @@
|
|||
|
||||
<color name="story_buttons_dark">#90928b</color>
|
||||
|
||||
<color name="refresh_1">#c56125</color>
|
||||
<color name="refresh_2">#db8d36</color>
|
||||
<color name="refresh_3">#e9a941</color>
|
||||
<color name="refresh_4">#fae576</color>
|
||||
|
||||
<!-- To use a selector on a bg color, the options must be drawables, not colors. -->
|
||||
<drawable name="toggle_bg_selected">#fdfdfd</drawable>
|
||||
<drawable name="toggle_bg_normal">#dfe1dd</drawable>
|
||||
|
|
|
@ -6,11 +6,13 @@ import android.os.Bundle;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.newsblur.R;
|
||||
|
@ -18,12 +20,11 @@ import com.newsblur.fragment.FolderListFragment;
|
|||
import com.newsblur.fragment.LogoutDialogFragment;
|
||||
import com.newsblur.service.BootReceiver;
|
||||
import com.newsblur.service.NBSyncService;
|
||||
import com.newsblur.util.FeedUtils;
|
||||
import com.newsblur.util.PrefsUtils;
|
||||
import com.newsblur.util.UIUtils;
|
||||
import com.newsblur.view.StateToggleButton.StateChangedListener;
|
||||
|
||||
public class Main extends NbActivity implements StateChangedListener {
|
||||
public class Main extends NbActivity implements StateChangedListener, SwipeRefreshLayout.OnRefreshListener, AbsListView.OnScrollListener {
|
||||
|
||||
private ActionBar actionBar;
|
||||
private FolderListFragment folderFeedList;
|
||||
|
@ -31,8 +32,9 @@ public class Main extends NbActivity implements StateChangedListener {
|
|||
private Menu menu;
|
||||
private TextView overlayStatusText;
|
||||
private boolean isLightTheme;
|
||||
private SwipeRefreshLayout swipeLayout;
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
PreferenceManager.setDefaultValues(this, R.layout.activity_settings, false);
|
||||
|
@ -46,6 +48,10 @@ public class Main extends NbActivity implements StateChangedListener {
|
|||
setContentView(R.layout.activity_main);
|
||||
setupActionBar();
|
||||
|
||||
swipeLayout = (SwipeRefreshLayout)findViewById(R.id.swipe_container);
|
||||
swipeLayout.setColorScheme(R.color.refresh_1, R.color.refresh_2, R.color.refresh_3, R.color.refresh_4);
|
||||
swipeLayout.setOnRefreshListener(this);
|
||||
|
||||
fragmentManager = getFragmentManager();
|
||||
folderFeedList = (FolderListFragment) fragmentManager.findFragmentByTag("folderFeedListFragment");
|
||||
folderFeedList.setRetainInstance(true);
|
||||
|
@ -127,10 +133,10 @@ public class Main extends NbActivity implements StateChangedListener {
|
|||
|
||||
private void updateStatusIndicators() {
|
||||
if (NBSyncService.isFeedFolderSyncRunning()) {
|
||||
setProgressBarIndeterminateVisibility(true);
|
||||
swipeLayout.setRefreshing(true);
|
||||
setRefreshEnabled(false);
|
||||
} else {
|
||||
setProgressBarIndeterminateVisibility(false);
|
||||
swipeLayout.setRefreshing(false);
|
||||
setRefreshEnabled(true);
|
||||
}
|
||||
|
||||
|
@ -153,6 +159,33 @@ public class Main extends NbActivity implements StateChangedListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
NBSyncService.forceFeedsFolders();
|
||||
triggerSync();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView absListView, int i) {
|
||||
// not required
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(AbsListView absListView, int i, int i2, int i3) {
|
||||
boolean enable = false;
|
||||
|
||||
if( absListView.getChildCount() > 0){
|
||||
// check if the first item of the list is visible
|
||||
boolean firstItemVisible = absListView.getFirstVisiblePosition() == 0;
|
||||
// check if the top of the first item is visible
|
||||
boolean topOfFirstItemVisible = absListView.getChildAt(0).getTop() == 0;
|
||||
// enabling or disabling the refresh layout
|
||||
enable = firstItemVisible && topOfFirstItemVisible;
|
||||
}
|
||||
|
||||
if (swipeLayout != null) {
|
||||
swipeLayout.setEnabled(enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ public class FolderListFragment extends Fragment implements OnGroupClickListener
|
|||
folderAdapter = new MixedExpandableListAdapter(getActivity(), folderCursor, socialFeedCursor, countCursor, sharedCountCursor, savedCountCursor);
|
||||
folderAdapter.setViewBinders(groupViewBinder, blogViewBinder);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -117,6 +118,9 @@ public class FolderListFragment extends Fragment implements OnGroupClickListener
|
|||
list.setOnGroupClickListener(this);
|
||||
list.setOnChildClickListener(this);
|
||||
|
||||
// Main activity needs to listen for scrolls to prevent refresh from firing unnecessarily
|
||||
list.setOnScrollListener((android.widget.AbsListView.OnScrollListener) getActivity());
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue