Last active
April 25, 2019 15:19
-
-
Save bichotll/5563926 to your computer and use it in GitHub Desktop.
Load disqus comments with a htmlview in Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_comments); | |
String htmlComments = getHtmlComment("yourId", "yourShortName"); | |
webDisqus = (WebView) findViewById(R.id.disqus); | |
// set up disqus | |
WebSettings webSettings2 = webDisqus.getSettings(); | |
webSettings2.setJavaScriptEnabled(true); | |
webSettings2.setBuiltInZoomControls(true); | |
webDisqus.requestFocusFromTouch(); | |
webDisqus.setWebViewClient(new WebViewClient()); | |
webDisqus.setWebChromeClient(new WebChromeClient()); | |
webDisqus.loadData(htmlComments, "text/html", null); | |
} | |
public String getHtmlComment(String idPost, String shortName) { | |
return "<div id='disqus_thread'></div>" | |
+ "<script type='text/javascript'>" | |
+ "var disqus_identifier = '" | |
+ idPost | |
+ "';" | |
+ "var disqus_shortname = '" | |
+ shortName | |
+ "';" | |
+ " (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;" | |
+ "dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';" | |
+ "(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();" | |
+ "</script>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment