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
// The authenticate function is called whenever ZAP requires to authenticate for a Context for which this script | |
// was selected as the Authentication Method. The function should send any messages that are required to do the authentication | |
// and should return a message with the authenticated response. | |
// | |
// NOTE: Any message sent in the function should be obtained using the 'helper.prepareMessage()' method. | |
// | |
// Parameters: | |
// helper - a helper class providing useful methods: prepareMessage(), sendAndReceive(msg) | |
// paramsValues - the values of the parameters configured in the Session Properties -> Authentication panel. | |
// The paramsValues is a map, having as keys the parameters names (as returned by the getRequiredParamsNames() |
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
class BooksViewModel(bookDao: BookDao) : ViewModel() { | |
// to make things simpler here, let's skip the repository layer | |
val books = bookDao.books() | |
} |
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
class BooksViewModel(bookDao: BookDao) : ViewModel() { | |
// the LiveData from Room won't be exposed to the view... | |
private val dbBooks = bookDao.books() | |
// ...because this is what we'll want to expose | |
val books = MediatorLiveData<List<Book>>() | |
private var currentOrder = ASCENDING |
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
@Singleton | |
@Component(modules = [YourModule::class, ThatOtherModule::class]) | |
interface ApplicationComponent { | |
@Component.Builder | |
interface Builder { | |
@BindsInstance fun applicationContext(applicationContext: Context): Builder | |
fun build(): ApplicationComponent | |
} | |
} |
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
interface DaggerComponentProvider { | |
val component: ApplicationComponent | |
} | |
val Activity.injector get() = (application as DaggerComponentProvider).component |
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
class ViewModelFactory<VM : ViewModel> @Inject constructor( | |
private val viewModel: Lazy<VM> | |
) : ViewModelProvider.Factory { | |
@Suppress("UNCHECKED_CAST") | |
override fun <T : ViewModel> create(modelClass: Class<T>) = viewModel.get() as T | |
} |
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
class BestPostActivity : AppCompatActivity() { | |
private val viewModel by lazy { | |
ViewModelProviders | |
.of(this, injector.bestPostViewModelFactory()) | |
.get(BestPostViewModel::class.java) | |
} | |
... | |
} |
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
@Reusable | |
class BestPostFinder @Inject constructor() { | |
... | |
} |
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
@Module | |
object PostModule { | |
@JvmStatic @Provides @Reusable | |
fun provideBestPostFinder() = BestPostFinder() | |
} |
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
@Singleton | |
@Component(modules = [ApplicationModule::class, YourModule::class, ThatOtherModule::class]) | |
interface ApplicationComponent | |
@Module | |
class ApplicationModule(private val applicationContext: Context) { | |
@Provides fun provideApplicationContext(): Context = applicationContext | |
} |
OlderNewer