Skip to content

Commit

Permalink
Switched to using progress dialog when retrieving cookie.
Browse files Browse the repository at this point in the history
  • Loading branch information
khaykov committed Apr 10, 2020
1 parent 33e7ec2 commit 33851fa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ protected void loadContent() {
long privateAtSiteId = extras.getLong(PRIVATE_AT_SITE_ID);

if (privateAtSiteId > 0) {
PrivateAtCookieRefreshProgressDialog.Companion.showIfNecessary(getSupportFragmentManager());
mDispatcher.dispatch(
SiteActionBuilder.newFetchAccessCookieAction(new FetchAccessCookiePayload(privateAtSiteId)));
return;
Expand Down Expand Up @@ -946,6 +947,7 @@ public void onStop() {
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onAccessCookieFetched(OnAccessCookieFetched event) {
PrivateAtCookieRefreshProgressDialog.Companion.dismissIfNecessary(getSupportFragmentManager());
if (!event.isError()) {
CookieManager.getInstance().setCookie(mPrivateAtomicCookie.getDomain(),
mPrivateAtomicCookie.getName() + "=" + mPrivateAtomicCookie.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.wordpress.android.fluxc.action.AccountAction;
import org.wordpress.android.fluxc.generated.AccountActionBuilder;
import org.wordpress.android.fluxc.generated.PostActionBuilder;
import org.wordpress.android.fluxc.generated.SiteActionBuilder;
import org.wordpress.android.fluxc.model.AccountModel;
import org.wordpress.android.fluxc.model.CauseOfOnPostChanged;
import org.wordpress.android.fluxc.model.CauseOfOnPostChanged.RemoteAutoSavePost;
Expand All @@ -94,12 +95,15 @@
import org.wordpress.android.fluxc.store.PostStore.RemotePostPayload;
import org.wordpress.android.fluxc.store.QuickStartStore;
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.fluxc.store.SiteStore.FetchAccessCookiePayload;
import org.wordpress.android.fluxc.store.SiteStore.OnAccessCookieFetched;
import org.wordpress.android.fluxc.store.UploadStore;
import org.wordpress.android.fluxc.tools.FluxCImageLoader;
import org.wordpress.android.ui.ActivityId;
import org.wordpress.android.ui.ActivityLauncher;
import org.wordpress.android.ui.LocaleAwareActivity;
import org.wordpress.android.ui.PagePostCreationSourcesDetail;
import org.wordpress.android.ui.PrivateAtCookieRefreshProgressDialog;
import org.wordpress.android.ui.RequestCodes;
import org.wordpress.android.ui.Shortcut;
import org.wordpress.android.ui.history.HistoryListItem.Revision;
Expand Down Expand Up @@ -552,11 +556,23 @@ protected void onCreate(Bundle savedInstanceState) {
setTitle(SiteUtils.getSiteNameOrHomeURL(mSite));
mSectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager);

setupViewPager();

if (mSite.isPrivateWPComAtomic() && mPrivateAtomicCookie.isExpired()) {
PrivateAtCookieRefreshProgressDialog.Companion.showIfNecessary(fragmentManager);
mDispatcher.dispatch(
SiteActionBuilder.newFetchAccessCookieAction(new FetchAccessCookiePayload(mSite.getSiteId())));
} else {
setupViewPager();
}
ActivityId.trackLastActivity(ActivityId.POST_EDITOR);
}

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onAccessCookieFetched(OnAccessCookieFetched event) {
PrivateAtCookieRefreshProgressDialog.Companion.dismissIfNecessary(getSupportFragmentManager());
setupViewPager();
}

private void setupViewPager() {
// Set up the ViewPager with the sections adapter.
mViewPager = findViewById(R.id.pager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.content.res.Resources
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.os.AsyncTask
import android.os.Bundle
import android.text.Html
Expand All @@ -23,13 +25,14 @@ import android.widget.ProgressBar
import android.widget.TextView
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import com.google.android.material.elevation.ElevationOverlayProvider
import com.google.android.material.snackbar.Snackbar
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.greenrobot.eventbus.ThreadMode.MAIN
import org.wordpress.android.R
import org.wordpress.android.WordPress
import org.wordpress.android.analytics.AnalyticsTracker
Expand Down Expand Up @@ -62,6 +65,7 @@ import org.wordpress.android.fluxc.store.SiteStore.OnAccessCookieFetched
import org.wordpress.android.models.ReaderPost
import org.wordpress.android.models.ReaderPostDiscoverData
import org.wordpress.android.ui.ActivityLauncher
import org.wordpress.android.ui.PrivateAtCookieRefreshProgressDialog
import org.wordpress.android.ui.main.WPMainActivity
import org.wordpress.android.ui.posts.BasicFragmentDialog
import org.wordpress.android.ui.prefs.AppPrefs
Expand Down Expand Up @@ -96,6 +100,8 @@ import org.wordpress.android.ui.reader.views.ReaderWebView.ReaderWebViewUrlClick
import org.wordpress.android.util.AniUtils
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T
import org.wordpress.android.util.AppLog.T.READER
import org.wordpress.android.util.CrashLoggingUtils
import org.wordpress.android.util.DateTimeUtils
import org.wordpress.android.util.HtmlUtils
import org.wordpress.android.util.NetworkUtils
Expand Down Expand Up @@ -287,8 +293,9 @@ class ReaderPostDetailFragment : Fragment(),

readerBookmarkButton = view.findViewById(R.id.bookmark_button)

val progress = view.findViewById<ProgressBar>(R.id.progress_loading)
if (postSlugsResolutionUnderway) {
showProgress()
progress.visibility = View.VISIBLE
}

showPost()
Expand Down Expand Up @@ -1001,13 +1008,15 @@ class ReaderPostDetailFragment : Fragment(),
* called when the post doesn't exist in local db, need to get it from server
*/
private fun requestPost() {
showProgress()
val progress = view!!.findViewById<ProgressBar>(R.id.progress_loading)
progress.visibility = View.VISIBLE
progress.bringToFront()

val listener = object : ReaderActions.OnRequestListener {
override fun onSuccess() {
hasAlreadyRequestedPost = true
if (isAdded) {
hideProgress()
progress.visibility = View.GONE
showPost()
EventBus.getDefault().post(ReaderEvents.SinglePostDownloaded())
}
Expand All @@ -1016,7 +1025,7 @@ class ReaderPostDetailFragment : Fragment(),
override fun onFailure(statusCode: Int) {
hasAlreadyRequestedPost = true
if (isAdded) {
hideProgress()
progress.visibility = View.GONE
onRequestFailure(statusCode)
}
}
Expand All @@ -1040,7 +1049,8 @@ class ReaderPostDetailFragment : Fragment(),
return
}

hideProgress()
val progress = view!!.findViewById<ProgressBar>(R.id.progress_loading)
progress.visibility = View.GONE

if (event.statusCode == 200) {
replacePost(event.blogId, event.postId, false)
Expand Down Expand Up @@ -1119,20 +1129,9 @@ class ReaderPostDetailFragment : Fragment(),
ShowPostTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
}

private fun showProgress() {
val progress = view!!.findViewById<ProgressBar>(R.id.progress_loading)
progress.visibility = View.VISIBLE
progress.bringToFront()
}

private fun hideProgress() {
val progress = view!!.findViewById<ProgressBar>(R.id.progress_loading)
progress.visibility = View.GONE
}

@Subscribe(threadMode = MAIN)
@Subscribe(threadMode = ThreadMode.MAIN)
fun onAccessCookieFetched(event: OnAccessCookieFetched?) {
hideProgress()
PrivateAtCookieRefreshProgressDialog.dismissIfNecessary(fragmentManager)
if (!event!!.isError) {
CookieManager.getInstance().setCookie(
privateAtomicCookie.getDomain(),
Expand Down Expand Up @@ -1260,9 +1259,10 @@ class ReaderPostDetailFragment : Fragment(),

// if the post if from private atomic site postpone render until we have a special access cookie
if (post!!.isPrivate && post!!.isPrivate) {
showProgress()
PrivateAtCookieRefreshProgressDialog.showIfNecessary(fragmentManager)
dispatcher.dispatch(
SiteActionBuilder.newFetchAccessCookieAction( FetchAccessCookiePayload(post!!.blogId)));
SiteActionBuilder.newFetchAccessCookieAction(FetchAccessCookiePayload(post!!.blogId))
)
} else {
renderer!!.beginRender()
}
Expand Down
1 change: 1 addition & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<string name="media_upload_error">Media upload error occurred</string>
<string name="media_generic_error">Media error occurred</string>
<string name="media_space_used">%1$s used</string>
<string name="media_accessing_progress">Accessing media</string>

<string name="media_upload_state_queued">Queued</string>
<string name="media_upload_state_uploading">Uploading</string>
Expand Down

0 comments on commit 33851fa

Please sign in to comment.