mirror of
https://github.com/viq/NewsBlur.git
synced 2025-11-01 09:09:16 +00:00
Add on-post-load hook to webview.
This commit is contained in:
parent
c6ff21dc91
commit
5d0ca3b247
3 changed files with 63 additions and 13 deletions
|
|
@ -96,6 +96,13 @@ public class ReadingItemFragment extends NbFragment implements ClassifierDialogF
|
|||
private String sourceUserId;
|
||||
private int contentHash;
|
||||
|
||||
// these three flags are progressively set by async callbacks and unioned
|
||||
// to set isLoadFinished, when we trigger any final UI tricks.
|
||||
private boolean isContentLoadFinished;
|
||||
private boolean isWebLoadFinished;
|
||||
private boolean isSocialLoadFinished;
|
||||
private Boolean isLoadFinished = false;
|
||||
|
||||
private final Object WEBVIEW_CONTENT_MUTEX = new Object();
|
||||
|
||||
public static ReadingItemFragment newInstance(Story story, String feedTitle, String feedFaviconColor, String feedFaviconFade, String feedFaviconBorder, String faviconText, String faviconUrl, Classifier classifier, boolean displayFeedDetails, DefaultFeedView defaultFeedView, String sourceUserId) {
|
||||
|
|
@ -191,12 +198,12 @@ public class ReadingItemFragment extends NbFragment implements ClassifierDialogF
|
|||
registerForContextMenu(web);
|
||||
web.setCustomViewLayout(webviewCustomViewLayout);
|
||||
web.setWebviewWrapperLayout(fragmentScrollview);
|
||||
web.setActivity(activity);
|
||||
web.fragment = this;
|
||||
web.activity = activity;
|
||||
|
||||
setupItemMetadata();
|
||||
updateShareButton();
|
||||
updateSaveButton();
|
||||
|
||||
setupItemCommentsAndShares();
|
||||
|
||||
NonfocusScrollview scrollView = (NonfocusScrollview) view.findViewById(R.id.reading_scrollview);
|
||||
|
|
@ -292,9 +299,9 @@ public class ReadingItemFragment extends NbFragment implements ClassifierDialogF
|
|||
shareButton.setText(R.string.share_this);
|
||||
}
|
||||
|
||||
private void setupItemCommentsAndShares() {
|
||||
new SetupCommentSectionTask(getActivity(), view, getFragmentManager(), inflater, story, imageLoader).execute();
|
||||
}
|
||||
private void setupItemCommentsAndShares() {
|
||||
new SetupCommentSectionTask(this, view, inflater, story, imageLoader).execute();
|
||||
}
|
||||
|
||||
private void setupItemMetadata() {
|
||||
View feedHeader = view.findViewById(R.id.row_item_feed_header);
|
||||
|
|
@ -415,6 +422,7 @@ public class ReadingItemFragment extends NbFragment implements ClassifierDialogF
|
|||
loadStoryContent();
|
||||
} else {
|
||||
setupWebview(storyContent);
|
||||
onContentLoadFinished();
|
||||
}
|
||||
} else {
|
||||
if (originalText == null) {
|
||||
|
|
@ -422,6 +430,7 @@ public class ReadingItemFragment extends NbFragment implements ClassifierDialogF
|
|||
loadOriginalText();
|
||||
} else {
|
||||
setupWebview(originalText);
|
||||
onContentLoadFinished();
|
||||
enableProgress(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -565,6 +574,41 @@ public class ReadingItemFragment extends NbFragment implements ClassifierDialogF
|
|||
return html;
|
||||
}
|
||||
|
||||
/** We have pushed our desired content into the WebView. */
|
||||
private void onContentLoadFinished() {
|
||||
isContentLoadFinished = true;
|
||||
checkLoadStatus();
|
||||
}
|
||||
|
||||
/** The webview has finished loading our desired content. */
|
||||
public void onWebLoadFinished() {
|
||||
isWebLoadFinished = true;
|
||||
checkLoadStatus();
|
||||
}
|
||||
|
||||
/** The social UI has finished loading from the DB. */
|
||||
public void onSocialLoadFinished() {
|
||||
isSocialLoadFinished = true;
|
||||
checkLoadStatus();
|
||||
}
|
||||
|
||||
private void checkLoadStatus() {
|
||||
synchronized (isLoadFinished) {
|
||||
if (isContentLoadFinished && isWebLoadFinished && isSocialLoadFinished) {
|
||||
// iff this is the first time all content has finished loading, trigger any UI
|
||||
// behaviour that is position-dependent
|
||||
if (!isLoadFinished) {
|
||||
onLoadFinished();
|
||||
}
|
||||
isLoadFinished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onLoadFinished() {
|
||||
// TODO: perform any position-dependent UI behaviours here (@manderson23)
|
||||
}
|
||||
|
||||
private class TextSizeReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
|
|||
private ArrayList<View> friendCommentViews;
|
||||
private ArrayList<View> friendShareViews;
|
||||
|
||||
private final ReadingItemFragment fragment;
|
||||
private final Story story;
|
||||
private final LayoutInflater inflater;
|
||||
private final ImageLoader imageLoader;
|
||||
|
|
@ -51,9 +52,10 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
|
|||
private final FragmentManager manager;
|
||||
private List<Comment> comments;
|
||||
|
||||
public SetupCommentSectionTask(Context context, View view, FragmentManager manager, LayoutInflater inflater, Story story, ImageLoader imageLoader) {
|
||||
this.context = context;
|
||||
this.manager = manager;
|
||||
public SetupCommentSectionTask(ReadingItemFragment fragment, View view, LayoutInflater inflater, Story story, ImageLoader imageLoader) {
|
||||
this.fragment = fragment;
|
||||
this.context = fragment.getActivity();
|
||||
this.manager = fragment.getFragmentManager();
|
||||
this.inflater = inflater;
|
||||
this.story = story;
|
||||
this.imageLoader = imageLoader;
|
||||
|
|
@ -337,6 +339,8 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
|
|||
}
|
||||
friendShareListContainer.addView(friendShareViews.get(i));
|
||||
}
|
||||
|
||||
fragment.onSocialLoadFinished();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import android.webkit.WebViewClient;
|
|||
import android.widget.FrameLayout;
|
||||
|
||||
import com.newsblur.activity.Reading;
|
||||
import com.newsblur.fragment.ReadingItemFragment;
|
||||
import com.newsblur.util.AppConstants;
|
||||
|
||||
public class NewsblurWebview extends WebView {
|
||||
|
|
@ -25,8 +26,9 @@ public class NewsblurWebview extends WebView {
|
|||
private NewsblurWebChromeClient webChromeClient;
|
||||
private boolean isCustomViewShowing;
|
||||
|
||||
public ReadingItemFragment fragment;
|
||||
// we need the less-abstract activity class in order to manipulate the overlay widgets
|
||||
private Reading activity;
|
||||
public Reading activity;
|
||||
|
||||
public NewsblurWebview(final Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
|
@ -99,10 +101,6 @@ public class NewsblurWebview extends WebView {
|
|||
this.webChromeClient.webviewWrapperLayout = webviewWrapperLayout;
|
||||
}
|
||||
|
||||
public void setActivity(Reading activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
// this WCC implements the bare minimum callbacks to get HTML5 fullscreen video working
|
||||
class NewsblurWebChromeClient extends WebChromeClient {
|
||||
public View customView;
|
||||
|
|
@ -158,6 +156,10 @@ public class NewsblurWebview extends WebView {
|
|||
customView = null;
|
||||
isCustomViewShowing = false;
|
||||
}
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
if (newProgress == 100) fragment.onWebLoadFinished();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue