/
VaultModule.java
59 lines (47 loc) · 1.58 KB
/
VaultModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*******************************************************************************
* Copyright (c) 2017 Skymatic UG (haftungsbeschränkt).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the accompanying LICENSE file.
*******************************************************************************/
package org.cryptomator.ui.model;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;
import javax.inject.Scope;
import org.cryptomator.common.settings.NioAdapterImpl;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.common.settings.VaultSettings;
import dagger.Module;
import dagger.Provides;
@Module
public class VaultModule {
private final VaultSettings vaultSettings;
public VaultModule(VaultSettings vaultSettings) {
this.vaultSettings = Objects.requireNonNull(vaultSettings);
}
@Provides
@PerVault
public VaultSettings provideVaultSettings() {
return vaultSettings;
}
@Scope
@Documented
@Retention(RetentionPolicy.RUNTIME)
@interface PerVault {
}
@Provides
@PerVault
public Volume provideNioAdpater(Settings settings, WebDavVolume webDavVolume, FuseVolume fuseVolume) {
NioAdapterImpl impl = NioAdapterImpl.valueOf(settings.usedNioAdapterImpl().get());
switch (impl) {
case WEBDAV:
return webDavVolume;
case FUSE:
return fuseVolume;
default:
//this should not happen!
throw new IllegalStateException("Unsupported NioAdapter: " + settings.usedNioAdapterImpl().get());
}
}
}