Skip to content

Instantly share code, notes, and snippets.

View pedromassango's full-sized avatar

Pedro Massango pedromassango

View GitHub Profile
@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
),),
class Repository() {
fun getMessage(): String{
return "This is a Repository message!"
}
}
//... 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()
}
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()) }
}
}
@pedromassango
pedromassango / MainActivity.kt
Created October 3, 2018 10:21
Usage of an class injected by Koin in an Activity
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{
@pedromassango
pedromassango / MyApp.kt
Created October 3, 2018 10:25
This is where we should initialize our Koin framework, by passing the modules that we want to use
class MyApp: Application() {
override fun onCreate() {
super.onCreate()
// call this to setup Koin with your modules
startKoin(this, listOf(DependeciesModule.appModule) )
}
}
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;
<?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>
<?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
@pedromassango
pedromassango / StrictModeSample.java
Created November 18, 2018 15:19
Como inicializar StrictMode no android
public void onCreate() {
super.onCreate();
if (DEVELOPER_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // ou .detectAll()
.penaltyLog()
.build());