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 | |
Widget build(BuildContext context){ | |
return Scaffold( | |
appBar: AppBar( | |
backgroundColor: Colors.white30, | |
elevation: 0.0, | |
title: Text('Hero Page 2', | |
style: TextStyle( | |
color: Colors.black | |
),), |
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
class Repository() { | |
fun getMessage(): String{ | |
return "This is a Repository message!" | |
} | |
} |
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
//... Code removed for brevity | |
class MainViewModel(private val repository: Repository) : ViewModel() { | |
private var messageData: MutableLiveData<String>? = null | |
fun loadData(): LiveData<String>?{ | |
if(messageData == null){ | |
messageData = MutableLiveData() | |
} |
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
object DependeciesModule { | |
val appModule = module { | |
// Usinlge only one instance of the giving class will run at time | |
single { Repository() } | |
// Koin will take care of creating ViewModel's dependencies | |
viewModel { MainViewModel( get()) } | |
} | |
} |
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
class MainActivity : AppCompatActivity() { | |
// we get our viewModel from Koin | |
private val mainViewModel: MainViewModel by viewModel() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.main_activity) | |
mainViewModel.loadData()?.observe(this, Observer{ |
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
class MyApp: Application() { | |
override fun onCreate() { | |
super.onCreate() | |
// call this to setup Koin with your modules | |
startKoin(this, listOf(DependeciesModule.appModule) ) | |
} | |
} |
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
package com.pedromassango.programmers.extras; | |
import android.app.ActivityManager; | |
import android.content.Context; | |
import android.os.Process; | |
import android.support.v7.app.AlertDialog; | |
import android.util.Log; | |
import android.widget.Toast; | |
import java.util.ArrayList; |
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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.pedromassango.alarmmanagersample"> | |
<application | |
... > | |
<activity android:name=".MainActivity"> | |
... | |
</activity> | |
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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.drawerlayout.widget.DrawerLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<FrameLayout |
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
public void onCreate() { | |
super.onCreate(); | |
if (DEVELOPER_MODE) { | |
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() | |
.detectDiskReads() | |
.detectDiskWrites() | |
.detectNetwork() // ou .detectAll() | |
.penaltyLog() | |
.build()); |