Skip to content

Commit 92bde83

Browse files
committed
Feat[mod_fragment]: remove explicit static variable in each mod install fragment
1 parent 1e060d1 commit 92bde83

7 files changed

+38
-64
lines changed

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/BTAInstallFragment.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
import java.io.IOException;
1515

1616
public class BTAInstallFragment extends ModVersionListFragment<BTAUtils.BTAVersionList> {
17-
private static ModloaderListenerProxy sTaskProxy;
17+
public static final String TAG = "BTAInstallFragment";
18+
19+
public BTAInstallFragment() {
20+
super(TAG);
21+
}
22+
1823
@Override
1924
public int getTitleText() {
2025
return R.string.select_bta_version;
@@ -25,21 +30,11 @@ public int getNoDataMsg() {
2530
return R.string.modloader_dl_failed_to_load_list;
2631
}
2732

28-
@Override
29-
public ModloaderListenerProxy getTaskProxy() {
30-
return sTaskProxy;
31-
}
32-
3333
@Override
3434
public BTAUtils.BTAVersionList loadVersionList() throws IOException {
3535
return BTAUtils.downloadVersionList();
3636
}
3737

38-
@Override
39-
public void setTaskProxy(ModloaderListenerProxy proxy) {
40-
sTaskProxy = proxy;
41-
}
42-
4338
@Override
4439
public ExpandableListAdapter createAdapter(BTAUtils.BTAVersionList versionList, LayoutInflater layoutInflater) {
4540
return new BTAVersionListAdapter(versionList, layoutInflater);

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/FabricInstallFragment.java

+1-12
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,8 @@
66
public class FabricInstallFragment extends FabriclikeInstallFragment {
77

88
public static final String TAG = "FabricInstallFragment";
9-
private static ModloaderListenerProxy sTaskProxy;
109

1110
public FabricInstallFragment() {
12-
super(FabriclikeUtils.FABRIC_UTILS);
13-
}
14-
15-
@Override
16-
protected ModloaderListenerProxy getListenerProxy() {
17-
return sTaskProxy;
18-
}
19-
20-
@Override
21-
protected void setListenerProxy(ModloaderListenerProxy listenerProxy) {
22-
sTaskProxy = listenerProxy;
11+
super(FabriclikeUtils.FABRIC_UTILS, TAG);
2312
}
2413
}

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/FabriclikeInstallFragment.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import net.kdt.pojavlaunch.PojavApplication;
2222
import net.kdt.pojavlaunch.R;
2323
import net.kdt.pojavlaunch.Tools;
24+
import net.kdt.pojavlaunch.extra.ExtraCore;
2425
import net.kdt.pojavlaunch.modloaders.FabriclikeDownloadTask;
2526
import net.kdt.pojavlaunch.modloaders.FabriclikeUtils;
2627
import net.kdt.pojavlaunch.modloaders.FabricVersion;
@@ -36,6 +37,7 @@
3637

3738
public abstract class FabriclikeInstallFragment extends Fragment implements ModloaderDownloadListener, CompoundButton.OnCheckedChangeListener {
3839
private final FabriclikeUtils mFabriclikeUtils;
40+
private final String mExtraTag;
3941
private Spinner mGameVersionSpinner;
4042
private FabricVersion[] mGameVersionArray;
4143
private Future<?> mGameVersionFuture;
@@ -48,9 +50,10 @@ public abstract class FabriclikeInstallFragment extends Fragment implements Modl
4850
private Button mStartButton;
4951
private View mRetryView;
5052
private CheckBox mOnlyStableCheckbox;
51-
protected FabriclikeInstallFragment(FabriclikeUtils mFabriclikeUtils) {
53+
protected FabriclikeInstallFragment(FabriclikeUtils mFabriclikeUtils, String mFragmentTag) {
5254
super(R.layout.fragment_fabric_install);
5355
this.mFabriclikeUtils = mFabriclikeUtils;
56+
this.mExtraTag = mFragmentTag + "_proxy";
5457
}
5558

5659
@Override
@@ -290,6 +293,10 @@ private void updateGameSpinner() {
290293
mGameVersionSpinner.setAdapter(createAdapter(mGameVersionArray, mOnlyStableCheckbox.isChecked()));
291294
}
292295

293-
protected abstract ModloaderListenerProxy getListenerProxy();
294-
protected abstract void setListenerProxy(ModloaderListenerProxy listenerProxy);
296+
private ModloaderListenerProxy getListenerProxy() {
297+
return (ModloaderListenerProxy) ExtraCore.getValue(mExtraTag);
298+
}
299+
private void setListenerProxy(ModloaderListenerProxy listenerProxy) {
300+
ExtraCore.setValue(mExtraTag, listenerProxy);
301+
}
295302
}

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ForgeInstallFragment.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
public class ForgeInstallFragment extends ModVersionListFragment<List<String>> {
2323
public static final String TAG = "ForgeInstallFragment";
24-
private static ModloaderListenerProxy sTaskProxy;
24+
public ForgeInstallFragment() {
25+
super(TAG);
26+
}
2527

2628
@Override
2729
public void onAttach(@NonNull Context context) {
@@ -38,15 +40,6 @@ public int getNoDataMsg() {
3840
return R.string.forge_dl_no_installer;
3941
}
4042

41-
@Override
42-
public ModloaderListenerProxy getTaskProxy() {
43-
return sTaskProxy;
44-
}
45-
@Override
46-
public void setTaskProxy(ModloaderListenerProxy proxy) {
47-
sTaskProxy = proxy;
48-
}
49-
5043
@Override
5144
public List<String> loadVersionList() throws IOException {
5245
return ForgeUtils.downloadForgeVersions();

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ModVersionListFragment.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import net.kdt.pojavlaunch.R;
1818
import net.kdt.pojavlaunch.Tools;
19+
import net.kdt.pojavlaunch.extra.ExtraCore;
1920
import net.kdt.pojavlaunch.mirrors.DownloadMirror;
2021
import net.kdt.pojavlaunch.modloaders.ModloaderDownloadListener;
2122
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
@@ -25,14 +26,15 @@
2526
import java.io.IOException;
2627

2728
public abstract class ModVersionListFragment<T> extends Fragment implements Runnable, View.OnClickListener, ExpandableListView.OnChildClickListener, ModloaderDownloadListener {
28-
public static final String TAG = "ForgeInstallFragment";
29+
private final String mExtraTag;
2930
private ExpandableListView mExpandableListView;
3031
private ProgressBar mProgressBar;
3132
private LayoutInflater mInflater;
3233
private View mRetryView;
3334

34-
public ModVersionListFragment() {
35+
public ModVersionListFragment(String mFragmentTag) {
3536
super(R.layout.fragment_mod_version_list);
37+
this.mExtraTag = mFragmentTag + "_proxy";
3638
}
3739

3840
@Override
@@ -148,11 +150,19 @@ public void onDownloadError(Exception e) {
148150
});
149151
}
150152

153+
private void setTaskProxy(ModloaderListenerProxy proxy) {
154+
ExtraCore.setValue(mExtraTag, proxy);
155+
}
156+
157+
private ModloaderListenerProxy getTaskProxy() {
158+
return (ModloaderListenerProxy) ExtraCore.getValue(mExtraTag);
159+
}
160+
151161
public abstract int getTitleText();
152162
public abstract int getNoDataMsg();
153-
public abstract ModloaderListenerProxy getTaskProxy();
163+
154164
public abstract T loadVersionList() throws IOException;
155-
public abstract void setTaskProxy(ModloaderListenerProxy proxy);
165+
156166
public abstract ExpandableListAdapter createAdapter(T versionList, LayoutInflater layoutInflater);
157167
public abstract Runnable createDownloadTask(Object selectedVersion, ModloaderListenerProxy listenerProxy);
158168
public abstract void onDownloadFinished(Context context, File downloadedFile);

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/OptiFineInstallFragment.java

+3-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import net.kdt.pojavlaunch.JavaGUILauncherActivity;
99
import net.kdt.pojavlaunch.R;
10-
import net.kdt.pojavlaunch.Tools;
1110
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
1211
import net.kdt.pojavlaunch.modloaders.OptiFineDownloadTask;
1312
import net.kdt.pojavlaunch.modloaders.OptiFineUtils;
@@ -18,7 +17,9 @@
1817

1918
public class OptiFineInstallFragment extends ModVersionListFragment<OptiFineUtils.OptiFineVersions> {
2019
public static final String TAG = "OptiFineInstallFragment";
21-
private static ModloaderListenerProxy sTaskProxy;
20+
public OptiFineInstallFragment() {
21+
super(TAG);
22+
}
2223
@Override
2324
public int getTitleText() {
2425
return R.string.of_dl_select_version;
@@ -28,22 +29,11 @@ public int getTitleText() {
2829
public int getNoDataMsg() {
2930
return R.string.of_dl_failed_to_scrape;
3031
}
31-
32-
@Override
33-
public ModloaderListenerProxy getTaskProxy() {
34-
return sTaskProxy;
35-
}
36-
3732
@Override
3833
public OptiFineUtils.OptiFineVersions loadVersionList() throws IOException {
3934
return OptiFineUtils.downloadOptiFineVersions();
4035
}
4136

42-
@Override
43-
public void setTaskProxy(ModloaderListenerProxy proxy) {
44-
sTaskProxy = proxy;
45-
}
46-
4737
@Override
4838
public ExpandableListAdapter createAdapter(OptiFineUtils.OptiFineVersions versionList, LayoutInflater layoutInflater) {
4939
return new OptiFineVersionListAdapter(versionList, layoutInflater);

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/QuiltInstallFragment.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@ public class QuiltInstallFragment extends FabriclikeInstallFragment {
99
private static ModloaderListenerProxy sTaskProxy;
1010

1111
public QuiltInstallFragment() {
12-
super(FabriclikeUtils.QUILT_UTILS);
13-
}
14-
15-
@Override
16-
protected ModloaderListenerProxy getListenerProxy() {
17-
return sTaskProxy;
18-
}
19-
20-
@Override
21-
protected void setListenerProxy(ModloaderListenerProxy listenerProxy) {
22-
sTaskProxy = listenerProxy;
12+
super(FabriclikeUtils.QUILT_UTILS, TAG);
2313
}
2414
}

0 commit comments

Comments
 (0)