2
2
3
3
import android .content .Context ;
4
4
import android .content .Intent ;
5
+ import android .content .SharedPreferences ;
5
6
import android .graphics .Bitmap ;
6
7
import android .os .Bundle ;
7
8
import android .support .annotation .NonNull ;
37
38
38
39
public class ModFragment extends BaseFragment implements ModsAdapter .OnDataChangeListener {
39
40
private static final int MOD_FILE_PICKER_RESULT = 1 ;
41
+ private static final String NEED_PATCH_PREFERENCES_KEY = "NEED_PATCH_PREFERENCES_KEY" ;
40
42
private View view ;
41
43
private RecyclerView recyclerView ;
42
44
private ModsAdapter adapter ;
43
- public boolean needPatch ;
45
+ private boolean needPatch ;
44
46
private Context context ;
45
47
private File storeFile ;
48
+ private SharedPreferences settingsPreferences ;
46
49
47
50
@ Override
48
51
public BaseFragment setBase (Context base ) {
@@ -52,11 +55,22 @@ public BaseFragment setBase(Context base) {
52
55
Toast .makeText (base , R .string .store_mkdir_failed , Toast .LENGTH_LONG ).show ();
53
56
}
54
57
}
58
+ this .settingsPreferences = base .getSharedPreferences (SettingFragment .SETTINGS_PREFERENCE_NAME , Context .MODE_PRIVATE );
59
+ needPatch = settingsPreferences .getBoolean (NEED_PATCH_PREFERENCES_KEY , false );
55
60
adapter = new ModsAdapter (storeFile , base );
56
61
adapter .setListener (this );
57
62
return super .setBase (base );
58
63
}
59
64
65
+ public boolean isNeedPatch () {
66
+ return needPatch ;
67
+ }
68
+
69
+ public void setNeedPatch (boolean needPatch ) {
70
+ this .needPatch = needPatch ;
71
+ settingsPreferences .edit ().putBoolean (NEED_PATCH_PREFERENCES_KEY , needPatch ).apply ();
72
+ }
73
+
60
74
public int getItemCount (){
61
75
return adapter .getItemCount ();
62
76
}
@@ -69,11 +83,9 @@ public int getEnableItemCount(){
69
83
@ Override
70
84
public View onCreateView (LayoutInflater inflater , @ Nullable ViewGroup container , Bundle savedInstanceState ) {
71
85
this .context = inflater .getContext ();
72
- if (view == null ){
73
- view = inflater .inflate (R .layout .mod_fragment , container , false );
74
- recyclerView = view .findViewById (R .id .mod_list );
75
- adapter .setRecyclerView (recyclerView );
76
- }
86
+ view = inflater .inflate (R .layout .mod_fragment , container , false );
87
+ recyclerView = view .findViewById (R .id .mod_list );
88
+ adapter .setRecyclerView (recyclerView );
77
89
adapter .updateSetting ();
78
90
return view ;
79
91
}
0 commit comments