From 222ffd8c530439d2b6a221d53dfa463a1cb86f09 Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Tue, 11 Aug 2020 23:11:48 +0200 Subject: [PATCH] Implemented MountPointChooserModule --- .../mountpoint/MountPointChooserModule.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooserModule.java b/main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooserModule.java index bade9e1bb..6f1fd0806 100644 --- a/main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooserModule.java +++ b/main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooserModule.java @@ -1,8 +1,70 @@ package org.cryptomator.common.mountpoint; +import com.google.common.collect.ImmutableSet; import dagger.Module; +import dagger.Provides; +import dagger.multibindings.IntoMap; +import org.cryptomator.common.Environment; +import org.cryptomator.common.mountpoint.MountPointChooser.Phase; +import org.cryptomator.common.vaults.PerVault; +import org.cryptomator.common.vaults.Vault; +import org.cryptomator.common.vaults.WindowsDriveLetters; +import javax.inject.Named; +import java.util.Comparator; +import java.util.Map; +import java.util.Set; + +/** + * Dagger-Module for {@link MountPointChooser MountPointChoosers.}
+ * See there for additional information. + * + * @see MountPointChooser + */ @Module public abstract class MountPointChooserModule { + @Provides + @IntoMap + @MountPointChooser.PhaseKey(Phase.CUSTOM_MOUNTPOINT) + @PerVault + public static MountPointChooser provideCustomMountPointChooser(Vault vault) { + return new CustomMountPointChooser(vault); + } + + @Provides + @IntoMap + @MountPointChooser.PhaseKey(Phase.CUSTOM_DRIVELETTER) + @PerVault + public static MountPointChooser provideCustomDriveLetterChooser(Vault vault) { + return new CustomDriveLetterChooser(vault); + } + + @Provides + @IntoMap + @MountPointChooser.PhaseKey(Phase.AVAILABLE_DRIVELETTER) + @PerVault + public static MountPointChooser provideAvailableDriveLetterChooser(WindowsDriveLetters windowsDriveLetters) { + return new AvailableDriveLetterChooser(windowsDriveLetters); + } + + @Provides + @IntoMap + @MountPointChooser.PhaseKey(Phase.TEMPORARY_MOUNTPOINT) + @PerVault + public static MountPointChooser provideTemporaryMountPointChooser(Vault vault, Environment environment) { + return new TemporaryMountPointChooser(vault, environment); + } + + @Provides + @PerVault + @Named("orderedValidMountPointChoosers") + public static Set provideOrderedValidMountPointChoosers(Map chooserMap) { + //Sorted Set + return chooserMap.entrySet().stream() + .sorted(Comparator.comparingInt(value -> value.getKey().getTiming())) + .map(Map.Entry::getValue) + .filter(MountPointChooser::isApplicable) + .collect(ImmutableSet.toImmutableSet()); + } }