-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFragmentSwitcher.java
More file actions
130 lines (116 loc) · 4.13 KB
/
FragmentSwitcher.java
File metadata and controls
130 lines (116 loc) · 4.13 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
public class FragmentSwitcher
{
private Context context;
private FragmentManager fragmentManager;
private FragmentTransaction fragmentTransaction;
private Fragment fragment;
private Bundle bundle;
private String description;
private boolean isSetToBackStack=false;
private int resIDFrameContainer;
public FragmentSwitcher(){
//require blank constructor
}
public FragmentSwitcher(int resIDFrameContainer, @NonNull Context context, @NonNull FragmentManager fragmentManager)
{
this.resIDFrameContainer = resIDFrameContainer;
this.fragmentManager = fragmentManager;
this.context = context;
}
public FragmentSwitcher(int resIDFrameContainer, @NonNull Context context, @NonNull FragmentManager fragmentManager, @NonNull Fragment fragment)
{
this.resIDFrameContainer = resIDFrameContainer;
this.fragmentManager = fragmentManager;
this.context = context;
this.fragment = fragment;
}
public FragmentSwitcher(int resIDFrameContainer, @NonNull Context context, @NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, @Nullable Bundle bundle)
{
this.resIDFrameContainer = resIDFrameContainer;
this.fragmentManager = fragmentManager;
this.context = context;
this.fragment = fragment;
this.bundle = bundle;
}
public FragmentSwitcher(int resIDFrameContainer, @NonNull Context context, @NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, @Nullable Bundle bundle, @Nullable String description)
{
this.resIDFrameContainer = resIDFrameContainer;
this.fragmentManager = fragmentManager;
this.context = context;
this.fragment = fragment;
this.bundle = bundle;
this.description = description;
}
public FragmentSwitcher withContext(@NonNull Context context)
{
this.context=context;
return this;
}
public FragmentSwitcher withContainer(int resIDFrameContainer)
{
this.resIDFrameContainer=resIDFrameContainer;
return this;
}
public FragmentSwitcher withFragmentManager(@NonNull FragmentManager fragmentManager)
{
this.fragmentManager=fragmentManager;
return this;
}
public FragmentSwitcher withFragment(@NonNull Fragment fragment)
{
this.fragment = fragment;
return this;
}
public FragmentSwitcher withExtraBundle(@Nullable Bundle bundle, @Nullable String description)
{
this.bundle = bundle;
this.description = description;
return this;
}
public FragmentSwitcher setToBackStack(boolean isSetToBackStack)
{
this.isSetToBackStack = isSetToBackStack;
return this;
}
public void commitAdd()
{
if(bundle!=null)
{
fragment.setArguments(bundle);
}
//fragment.setDescription(description); no more implemented
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(resIDFrameContainer, fragment, fragment.getClass().getSimpleName());
if (isSetToBackStack)
{
fragmentTransaction.addToBackStack(fragment.getTag());
}
fragmentTransaction.commit();
}
public void commitReplace()
{
if(bundle!=null)
{
fragment.setArguments(bundle);
}
//fragment.setDescription(description); no more implemented
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(resIDFrameContainer, fragment, fragment.getClass().getSimpleName());
if (isSetToBackStack)
{
fragmentTransaction.addToBackStack(fragment.getTag());
}
fragmentTransaction.commit();
}
public static FragmentSwitcher getInstance()
{
return new FragmentSwitcher();
}
}