blob: eaf3fbfa34fd1f18e65d6239aeaf7b4a90d8aa99 (
plain)
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
60
61
62
63
64
65
|
package se.leap.bitmaskclient.providersetup.fragments;
import android.Manifest;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import java.util.ArrayList;
public class SetupFragmentFactory {
public static final int PROVIDER_SELECTION_FRAGMENT = 0;
public static final int CIRCUMVENTION_SETUP_FRAGMENT = 1;
public static final int CONFIGURE_PROVIDER_FRAGMENT = 2;
public static final int VPN_PERMISSON_EDUCATIONAL_FRAGMENT = 3;
public static final int VPN_PERMISSON_FRAGMENT = 4;
public static final int NOTIFICATION_PERMISSON_EDUCATIONAL_FRAGMENT = 5;
public static final int NOTIFICATION_PERMISSON_FRAGMENT = 6;
public static final int SUCCESS_FRAGMENT = 7;
private final Intent vpnPermissionRequest;
private final ArrayList<Integer> fragmentTypes;
public SetupFragmentFactory(@NonNull ArrayList<Integer> fragmentTypes, Intent vpnPermissionRequest) {
this.fragmentTypes = fragmentTypes;
this.vpnPermissionRequest = vpnPermissionRequest;
}
public Fragment createFragment(int position) {
if (position < 0 || position >= fragmentTypes.size()) {
throw new IllegalStateException("Illegal fragment position");
}
int type = fragmentTypes.get(position);
switch (type) {
case PROVIDER_SELECTION_FRAGMENT:
return ProviderSelectionFragment.newInstance(position);
case CIRCUMVENTION_SETUP_FRAGMENT:
return CircumventionSetupFragment.newInstance(position);
case CONFIGURE_PROVIDER_FRAGMENT:
return ConfigureProviderFragment.newInstance(position);
case NOTIFICATION_PERMISSON_EDUCATIONAL_FRAGMENT:
return NotificationSetupFragment.newInstance(position);
case NOTIFICATION_PERMISSON_FRAGMENT:
return EmptyPermissionSetupFragment.newInstance(position, Manifest.permission.POST_NOTIFICATIONS);
case VPN_PERMISSON_EDUCATIONAL_FRAGMENT:
return VpnPermissionSetupFragment.newInstance(position);
case VPN_PERMISSON_FRAGMENT:
return EmptyPermissionSetupFragment.newInstance(position, vpnPermissionRequest);
case SUCCESS_FRAGMENT:
return SetupSuccessFragment.newInstance(position);
default:
throw new IllegalArgumentException("Unexpected fragment type: " + type);
}
}
public int getItemCount() {
return fragmentTypes.size();
}
public int getPos(int fragmentType) {
return fragmentTypes.indexOf(fragmentType);
}
}
|