use of org.wordpress.android.util.widgets.CustomSwipeRefreshLayout in project WordPress-Android by wordpress-mobile.
the class ReaderCommentListActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((WordPress) getApplication()).component().inject(this);
setContentView(R.layout.reader_activity_comment_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
if (savedInstanceState != null) {
mBlogId = savedInstanceState.getLong(ReaderConstants.ARG_BLOG_ID);
mPostId = savedInstanceState.getLong(ReaderConstants.ARG_POST_ID);
mRestorePosition = savedInstanceState.getInt(ReaderConstants.KEY_RESTORE_POSITION);
mHasUpdatedComments = savedInstanceState.getBoolean(KEY_HAS_UPDATED_COMMENTS);
mInterceptedUri = savedInstanceState.getString(ReaderConstants.ARG_INTERCEPTED_URI);
} else {
mBlogId = getIntent().getLongExtra(ReaderConstants.ARG_BLOG_ID, 0);
mPostId = getIntent().getLongExtra(ReaderConstants.ARG_POST_ID, 0);
mDirectOperation = (DirectOperation) getIntent().getSerializableExtra(ReaderConstants.ARG_DIRECT_OPERATION);
mCommentId = getIntent().getLongExtra(ReaderConstants.ARG_COMMENT_ID, 0);
mInterceptedUri = getIntent().getStringExtra(ReaderConstants.ARG_INTERCEPTED_URI);
// connection so we can show existing comments while offline
if (NetworkUtils.isNetworkAvailable(this)) {
ReaderCommentTable.purgeCommentsForPost(mBlogId, mPostId);
}
}
mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.swipe_to_refresh), new SwipeToRefreshHelper.RefreshListener() {
@Override
public void onRefreshStarted() {
updatePostAndComments();
}
});
mRecyclerView = (ReaderRecyclerView) findViewById(R.id.recycler_view);
int spacingHorizontal = 0;
int spacingVertical = DisplayUtils.dpToPx(this, 1);
mRecyclerView.addItemDecoration(new RecyclerItemDecoration(spacingHorizontal, spacingVertical));
mCommentBox = (ViewGroup) findViewById(R.id.layout_comment_box);
mEditComment = (SuggestionAutoCompleteText) mCommentBox.findViewById(R.id.edit_comment);
mEditComment.getAutoSaveTextHelper().setUniqueId(String.format(Locale.US, "%d%d", mPostId, mBlogId));
mSubmitReplyBtn = mCommentBox.findViewById(R.id.btn_submit_reply);
if (!loadPost()) {
ToastUtils.showToast(this, R.string.reader_toast_err_get_post);
finish();
return;
}
mRecyclerView.setAdapter(getCommentAdapter());
if (savedInstanceState != null) {
setReplyToCommentId(savedInstanceState.getLong(KEY_REPLY_TO_COMMENT_ID), false);
}
refreshComments();
mSuggestionServiceConnectionManager = new SuggestionServiceConnectionManager(this, mBlogId);
mSuggestionAdapter = SuggestionUtils.setupSuggestions(mBlogId, this, mSuggestionServiceConnectionManager, mPost.isWP());
if (mSuggestionAdapter != null) {
mEditComment.setAdapter(mSuggestionAdapter);
}
AnalyticsUtils.trackWithReaderPostDetails(AnalyticsTracker.Stat.READER_ARTICLE_COMMENTS_OPENED, mPost);
}
use of org.wordpress.android.util.widgets.CustomSwipeRefreshLayout in project WordPress-Android by wordpress-mobile.
the class ThemeBrowserFragment method configureSwipeToRefresh.
protected void configureSwipeToRefresh(View view) {
mSwipeToRefreshHelper = new SwipeToRefreshHelper(mThemeBrowserActivity, (CustomSwipeRefreshLayout) view.findViewById(R.id.ptr_layout), new RefreshListener() {
@Override
public void onRefreshStarted() {
if (!isAdded()) {
return;
}
if (!NetworkUtils.checkConnection(mThemeBrowserActivity)) {
mSwipeToRefreshHelper.setRefreshing(false);
mEmptyTextView.setText(R.string.no_network_title);
return;
}
mThemeBrowserActivity.fetchThemes();
}
});
mSwipeToRefreshHelper.setRefreshing(mShouldRefreshOnStart);
}
use of org.wordpress.android.util.widgets.CustomSwipeRefreshLayout in project WordPress-Android by wordpress-mobile.
the class PostsListFragment method initSwipeToRefreshHelper.
private void initSwipeToRefreshHelper() {
mSwipeToRefreshHelper = new SwipeToRefreshHelper(getActivity(), (CustomSwipeRefreshLayout) getView().findViewById(R.id.ptr_layout), new RefreshListener() {
@Override
public void onRefreshStarted() {
if (!isAdded()) {
return;
}
if (!NetworkUtils.checkConnection(getActivity())) {
setRefreshing(false);
updateEmptyView(EmptyViewMessageType.NETWORK_ERROR);
return;
}
requestPosts(false);
}
});
}
use of org.wordpress.android.util.widgets.CustomSwipeRefreshLayout in project WordPress-Android by wordpress-mobile.
the class StatsActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((WordPress) getApplication()).component().inject(this);
if (WordPress.wpDB == null) {
Toast.makeText(this, R.string.fatal_db_error, Toast.LENGTH_LONG).show();
finish();
return;
}
if (savedInstanceState == null) {
mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE);
} else {
mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
}
if (mSite == null) {
ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT);
finish();
return;
}
setContentView(R.layout.stats_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setElevation(0);
actionBar.setTitle(R.string.stats);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new RefreshListener() {
@Override
public void onRefreshStarted() {
if (!NetworkUtils.checkConnection(getBaseContext())) {
mSwipeToRefreshHelper.setRefreshing(false);
return;
}
refreshStatsFromCurrentDate();
}
});
setTitle(R.string.stats);
mOuterScrollView = (NestedScrollViewExt) findViewById(R.id.scroll_view_stats);
mOuterScrollView.setScrollViewListener(this);
if (savedInstanceState != null) {
mResultCode = savedInstanceState.getInt(SAVED_WP_LOGIN_STATE);
mCurrentTimeframe = (StatsTimeframe) savedInstanceState.getSerializable(SAVED_STATS_TIMEFRAME);
mRequestedDate = savedInstanceState.getString(SAVED_STATS_REQUESTED_DATE);
mThereWasAnErrorLoadingStats = savedInstanceState.getBoolean(SAVED_THERE_WAS_AN_ERROR_LOADING_STATS);
final int yScrollPosition = savedInstanceState.getInt(SAVED_STATS_SCROLL_POSITION);
if (yScrollPosition != 0) {
mOuterScrollView.postDelayed(new Runnable() {
public void run() {
if (!isFinishing()) {
mOuterScrollView.scrollTo(0, yScrollPosition);
}
}
}, StatsConstants.STATS_SCROLL_TO_DELAY);
}
} else if (getIntent() != null) {
if (getIntent().hasExtra(SAVED_STATS_TIMEFRAME)) {
mCurrentTimeframe = (StatsTimeframe) getIntent().getSerializableExtra(SAVED_STATS_TIMEFRAME);
} else if (getIntent().hasExtra(ARG_DESIRED_TIMEFRAME)) {
mCurrentTimeframe = (StatsTimeframe) getIntent().getSerializableExtra(ARG_DESIRED_TIMEFRAME);
} else {
// Read the value from app preferences here. Default to 0 - Insights
mCurrentTimeframe = AppPrefs.getStatsTimeframe();
}
mRequestedDate = StatsUtils.getCurrentDateTZ(mSite);
if (getIntent().hasExtra(ARG_LAUNCHED_FROM)) {
StatsLaunchedFrom from = (StatsLaunchedFrom) getIntent().getSerializableExtra(ARG_LAUNCHED_FROM);
if (from == StatsLaunchedFrom.STATS_WIDGET) {
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.STATS_WIDGET_TAPPED, mSite);
}
}
}
if (!mAccountStore.hasAccessToken()) {
// If the user is not connected to WordPress.com, ask him to connect first.
startWPComLoginActivity();
return;
}
checkIfSiteHasAccessibleStats(mSite);
// create the fragments without forcing the re-creation. If the activity is restarted fragments can already
// be there, and ready to be displayed without making any network connections. A fragment calls the stats service
// if its internal datamodel is empty.
createFragments(false);
if (mSpinner == null) {
mSpinner = (Spinner) findViewById(R.id.filter_spinner);
mTimeframeSpinnerAdapter = new TimeframeSpinnerAdapter(this, timeframes);
mSpinner.setAdapter(mTimeframeSpinnerAdapter);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (isFinishing()) {
return;
}
final StatsTimeframe selectedTimeframe = (StatsTimeframe) mTimeframeSpinnerAdapter.getItem(position);
if (mCurrentTimeframe == selectedTimeframe) {
AppLog.d(T.STATS, "The selected TIME FRAME is already active: " + selectedTimeframe.getLabel());
return;
}
AppLog.d(T.STATS, "NEW TIME FRAME : " + selectedTimeframe.getLabel());
mCurrentTimeframe = selectedTimeframe;
AppPrefs.setStatsTimeframe(mCurrentTimeframe);
mRequestedDate = StatsUtils.getCurrentDateTZ(mSite);
// Need to recreate fragment here, since a new timeline was selected.
createFragments(true);
mSpinner.postDelayed(new Runnable() {
@Override
public void run() {
if (!isFinishing()) {
scrollToTop();
}
}
}, StatsConstants.STATS_SCROLL_TO_DELAY);
trackStatsAnalytics();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// nop
}
});
Toolbar spinnerToolbar = (Toolbar) findViewById(R.id.toolbar_filter);
spinnerToolbar.setBackgroundColor(getResources().getColor(R.color.blue_medium));
}
selectCurrentTimeframeInActionBar();
TextView otherRecentStatsMovedLabel = (TextView) findViewById(R.id.stats_other_recent_stats_moved);
otherRecentStatsMovedLabel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < timeframes.length; i++) {
if (timeframes[i] == StatsTimeframe.INSIGHTS) {
mSpinner.setSelection(i);
break;
}
}
mSpinner.postDelayed(new Runnable() {
@Override
public void run() {
if (!isFinishing()) {
scrollToTop();
}
}
}, StatsConstants.STATS_SCROLL_TO_DELAY);
}
});
// Track usage here
if (savedInstanceState == null) {
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.STATS_ACCESSED, mSite);
trackStatsAnalytics();
}
}
use of org.wordpress.android.util.widgets.CustomSwipeRefreshLayout in project WordPress-Android by wordpress-mobile.
the class StatsViewAllActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stats_activity_view_all);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
setTitle(R.string.stats);
mOuterScrollView = (ScrollViewExt) findViewById(R.id.scroll_view_stats);
// pull to refresh setup
mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new SwipeToRefreshHelper.RefreshListener() {
@Override
public void onRefreshStarted() {
if (!NetworkUtils.checkConnection(getBaseContext())) {
mSwipeToRefreshHelper.setRefreshing(false);
mIsUpdatingStats = false;
return;
}
if (mIsUpdatingStats) {
AppLog.w(AppLog.T.STATS, "stats are already updating, refresh cancelled");
return;
}
refreshStats();
}
});
if (savedInstanceState != null) {
mLocalBlogID = savedInstanceState.getInt(StatsActivity.ARG_LOCAL_TABLE_SITE_ID, -1);
Serializable oldData = savedInstanceState.getSerializable(StatsAbstractFragment.ARG_REST_RESPONSE);
if (oldData != null && oldData instanceof Serializable[]) {
mRestResponse = (Serializable[]) oldData;
}
mTimeframe = (StatsTimeframe) savedInstanceState.getSerializable(StatsAbstractFragment.ARGS_TIMEFRAME);
mDate = savedInstanceState.getString(StatsAbstractFragment.ARGS_SELECTED_DATE);
mStatsViewType = (StatsViewType) savedInstanceState.getSerializable(StatsAbstractFragment.ARGS_VIEW_TYPE);
mOuterPagerSelectedButtonIndex = savedInstanceState.getInt(StatsAbstractListFragment.ARGS_TOP_PAGER_SELECTED_BUTTON_INDEX, 0);
final int yScrollPosition = savedInstanceState.getInt(SAVED_STATS_SCROLL_POSITION);
if (yScrollPosition != 0) {
mOuterScrollView.postDelayed(new Runnable() {
public void run() {
if (!isFinishing()) {
mOuterScrollView.scrollTo(0, yScrollPosition);
}
}
}, StatsConstants.STATS_SCROLL_TO_DELAY);
}
} else if (getIntent() != null) {
Bundle extras = getIntent().getExtras();
mLocalBlogID = extras.getInt(StatsActivity.ARG_LOCAL_TABLE_SITE_ID, -1);
mTimeframe = (StatsTimeframe) extras.getSerializable(StatsAbstractFragment.ARGS_TIMEFRAME);
mDate = extras.getString(StatsAbstractFragment.ARGS_SELECTED_DATE);
mStatsViewType = (StatsViewType) extras.getSerializable(StatsAbstractFragment.ARGS_VIEW_TYPE);
mOuterPagerSelectedButtonIndex = extras.getInt(StatsAbstractListFragment.ARGS_TOP_PAGER_SELECTED_BUTTON_INDEX, 0);
// Set a custom activity title if one was passed
if (!TextUtils.isEmpty(extras.getString(ARG_STATS_VIEW_ALL_TITLE))) {
setTitle(extras.getString(ARG_STATS_VIEW_ALL_TITLE));
}
}
if (mStatsViewType == null || mTimeframe == null || mDate == null) {
Toast.makeText(this, getResources().getText(R.string.stats_generic_error), Toast.LENGTH_SHORT).show();
finish();
}
// Setup the top date label. It's available on those fragments that are affected by the top date selector.
TextView dateTextView = (TextView) findViewById(R.id.stats_summary_date);
switch(mStatsViewType) {
case TOP_POSTS_AND_PAGES:
case REFERRERS:
case CLICKS:
case GEOVIEWS:
case AUTHORS:
case VIDEO_PLAYS:
case SEARCH_TERMS:
dateTextView.setText(getDateForDisplayInLabels(mDate, mTimeframe));
dateTextView.setVisibility(View.VISIBLE);
break;
default:
dateTextView.setVisibility(View.GONE);
break;
}
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
mFragment = (StatsAbstractListFragment) fm.findFragmentByTag("ViewAll-Fragment");
if (mFragment == null) {
mFragment = getInnerFragment();
ft.replace(R.id.stats_single_view_fragment, mFragment, "ViewAll-Fragment");
ft.commitAllowingStateLoss();
}
if (savedInstanceState == null) {
AnalyticsTracker.track(Stat.STATS_VIEW_ALL_ACCESSED);
}
}
Aggregations