Created
March 30, 2020 16:22
-
-
Save eristoddle/30b5d39459d1c2a4ff11ebad92e831af to your computer and use it in GitHub Desktop.
This file contains 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
package com.eristoddle.boilerplate | |
import android.content.Context | |
import android.content.Intent | |
import android.content.SharedPreferences | |
import android.os.Bundle | |
import android.text.Spanned | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.core.text.HtmlCompat | |
import com.google.android.material.snackbar.Snackbar | |
import kotlinx.android.synthetic.main.activity_eula.* | |
import java.io.InputStream | |
class EulaActivity : AppCompatActivity() { | |
private lateinit var preferences: SharedPreferences | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
preferences = applicationContext | |
.getSharedPreferences("com.eristoddle.boilerplate", Context.MODE_PRIVATE) | |
setContentView(R.layout.activity_eula) | |
initializeUI() | |
} | |
private fun initializeUI() { | |
eula_cancel.setOnClickListener { cancelEULA() } | |
eula_confirm.setOnClickListener { | |
confirmEULA() | |
} | |
setEula() | |
} | |
private fun setEula() { | |
val eula = intent.extras!!.getInt("eula") | |
val inputStream: InputStream = resources.openRawResource(eula) | |
val bytes = ByteArray(inputStream.available()) | |
inputStream.read(bytes) | |
val htmlAsSpanned: Spanned = | |
HtmlCompat.fromHtml(String(bytes), HtmlCompat.FROM_HTML_MODE_LEGACY) | |
eula_content.text = htmlAsSpanned | |
} | |
private fun cancelEULA() { | |
Snackbar.make( | |
findViewById(android.R.id.content), | |
"You must accept the EULA to continue", | |
Snackbar.LENGTH_LONG | |
).show() | |
} | |
// NOTE: Here you would call your api to save the status | |
private fun confirmEULA() { | |
preferences.edit().putBoolean("eulaAccepted", true).apply() | |
val intent = Intent() | |
setResult(RESULT_OK, intent) | |
finish() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment