Skip to content

Instantly share code, notes, and snippets.

View thenixan's full-sized avatar
🦫
Badger!

Ilya Nixan thenixan

🦫
Badger!
View GitHub Profile
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.SplashScreen" parent="AppTheme">
<item name="android:windowBackground">@drawable/splash</item>
private const val ACTIVITY_AUTH = 1000
abstract class SplashedActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
if (!isAuthenticated()) {
startActivityForResult(Intent(this, AuthActivity::class.java), ACTIVITY_AUTH)
}
setTheme(R.style.AppTheme_Base)
super.onCreate(savedInstanceState)
class AuthActivity : AppCompatActivity() {
private val authCardView by lazy { findViewById<CardView>(R.id.authCardView) }
private val okButton by lazy { findViewById<Button>(R.id.okButton) }
private val cancelButton by lazy { findViewById<Button>(R.id.cancelButton) }
private val loginEditText by lazy { findViewById<EditText>(R.id.loginEditText) }
private val passwordEditText by lazy { findViewById<EditText>(R.id.passwordEditText) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.nixan.splashscreenexample">
...
<activity android:name=".ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
class ShareActivity : SplashedActivity() {
private val helloText by lazy { findViewById<TextView>(R.id.helloText) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
getUser()?.let {
helloText.text = "${it.login}\n${intent.getStringExtra(Intent.EXTRA_TEXT)}"
}
buildscript {
ext.kotlin_version = '1.2.10'
ext.rxjava2_version = '2.1.9'
ext.retrofit_version = '2.3.0'
...
}
...
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
data class DataHolder(
@SerializedName("data") val data: Array<DataItem>
)
data class DataItem(
@SerializedName("about") val about: String,
@SerializedName("email") val email: String,
@SerializedName("first_name") val firstName: String,
@SerializedName("gender") val gender: String,
@SerializedName("hash") val hash: String,
fun benchmark(f: () -> Unit) {
System.gc()
val startTime = System.currentTimeMillis()
val startMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()
f.invoke()
System.gc()
val finishTime = System.currentTimeMillis()
val finishMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()
interface Api {
@GET("thenixan-blogposts/json-streaming-data/master/one-large-file.json")
fun loadDataInUsualWay(): Single<DataHolder>
}
val service = Retrofit.Builder()
.baseUrl("https://raw.githubusercontent.com/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
data class NewDataHolder(
@SerializedName("data")
val data: Observable<DataItem>
)