2016-11-25 05:59:16 +00:00
|
|
|
package telegra.ph
|
|
|
|
|
|
|
|
import android.content.Intent
|
2016-11-26 07:58:37 +00:00
|
|
|
import android.graphics.Bitmap
|
2016-11-25 05:59:16 +00:00
|
|
|
import android.os.Bundle
|
2016-11-26 10:37:27 +00:00
|
|
|
import android.support.v7.app.AlertDialog
|
2016-11-25 05:59:16 +00:00
|
|
|
import android.support.v7.app.AppCompatActivity
|
2016-11-26 10:37:27 +00:00
|
|
|
import android.text.Html
|
2016-11-25 05:59:16 +00:00
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuItem
|
2016-11-26 10:37:27 +00:00
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
2016-11-26 07:58:37 +00:00
|
|
|
import im.delight.android.webview.AdvancedWebView
|
2016-11-25 05:59:16 +00:00
|
|
|
|
2016-11-26 07:58:37 +00:00
|
|
|
class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
|
2016-11-25 05:59:16 +00:00
|
|
|
|
|
|
|
private val TELEGRAPH = "http://telegra.ph/"
|
|
|
|
|
2016-11-26 07:58:37 +00:00
|
|
|
private val webView: AdvancedWebView? by lazy { findViewById(R.id.webView) as AdvancedWebView }
|
2016-11-25 05:59:16 +00:00
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_main)
|
|
|
|
|
2016-11-26 07:58:37 +00:00
|
|
|
webView?.setListener(this, this)
|
2016-11-25 05:59:16 +00:00
|
|
|
|
2016-11-26 07:58:37 +00:00
|
|
|
webView?.apply {
|
|
|
|
setMixedContentAllowed(true)
|
|
|
|
setCookiesEnabled(true)
|
|
|
|
setThirdPartyCookiesEnabled(true)
|
|
|
|
addPermittedHostname("telegra.ph")
|
|
|
|
}
|
2016-11-25 05:59:16 +00:00
|
|
|
|
|
|
|
// Check if app is opened to show special page
|
|
|
|
var urlToLoad = TELEGRAPH
|
|
|
|
if (intent.action == Intent.ACTION_VIEW && !intent.dataString.isNullOrBlank() && intent.dataString.contains("telegra.ph"))
|
|
|
|
urlToLoad = intent.dataString
|
|
|
|
|
|
|
|
// Load URL
|
|
|
|
webView?.loadUrl(urlToLoad)
|
2016-11-26 07:58:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPageFinished(url: String?) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPageStarted(url: String?, favicon: Bitmap?) {
|
|
|
|
}
|
2016-11-25 05:59:16 +00:00
|
|
|
|
2016-11-26 07:58:37 +00:00
|
|
|
override fun onPageError(errorCode: Int, description: String?, failingUrl: String?) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDownloadRequested(url: String?, suggestedFilename: String?, mimeType: String?, contentLength: Long, contentDisposition: String?, userAgent: String?) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onExternalPageRequest(url: String?) {
|
|
|
|
AdvancedWebView.Browsers.openUrl(this, url)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
webView?.onResume()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPause() {
|
|
|
|
webView?.onPause()
|
|
|
|
super.onPause()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
webView?.onDestroy()
|
|
|
|
super.onDestroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
|
webView?.onActivityResult(requestCode, resultCode, data)
|
2016-11-25 05:59:16 +00:00
|
|
|
}
|
|
|
|
|
2016-11-26 09:15:37 +00:00
|
|
|
override fun onBackPressed() {
|
|
|
|
if (webView?.onBackPressed() == false) return
|
|
|
|
else super.onBackPressed()
|
|
|
|
}
|
|
|
|
|
2016-11-25 05:59:16 +00:00
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
|
super.onCreateOptionsMenu(menu)
|
|
|
|
menuInflater.inflate(R.menu.activity_main, menu)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
2016-11-26 07:58:37 +00:00
|
|
|
return when (item.itemId) {
|
2016-11-25 05:59:16 +00:00
|
|
|
R.id.share -> {
|
|
|
|
val shareIntent = Intent()
|
|
|
|
shareIntent.action = Intent.ACTION_SEND
|
|
|
|
shareIntent.type = "text/plain"
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_TITLE, webView?.title)
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, webView?.url)
|
|
|
|
startActivity(Intent.createChooser(shareIntent, getString(R.string.share)))
|
2016-11-26 07:58:37 +00:00
|
|
|
true
|
2016-11-25 05:59:16 +00:00
|
|
|
}
|
2016-11-26 10:37:27 +00:00
|
|
|
R.id.help -> {
|
|
|
|
MaterialDialog.Builder(this)
|
|
|
|
.title(R.string.help)
|
|
|
|
.content(R.string.help_text)
|
|
|
|
.show()
|
|
|
|
true
|
|
|
|
}
|
2016-11-26 07:58:37 +00:00
|
|
|
else -> super.onOptionsItemSelected(item)
|
2016-11-25 05:59:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|