Skip to content

Commit

Permalink
Feat[mod_fragment]: remove explicit static variable in each mod insta…
Browse files Browse the repository at this point in the history
…ll fragment
  • Loading branch information
artdeell committed Feb 10, 2025
1 parent d8f429e commit 01de8c8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
import java.io.IOException;

public class BTAInstallFragment extends ModVersionListFragment<BTAUtils.BTAVersionList> {
private static ModloaderListenerProxy sTaskProxy;
public static final String TAG = "BTAInstallFragment";

public BTAInstallFragment() {
super(TAG);
}

@Override
public int getTitleText() {
return R.string.select_bta_version;
Expand All @@ -25,21 +30,11 @@ public int getNoDataMsg() {
return R.string.modloader_dl_failed_to_load_list;
}

@Override
public ModloaderListenerProxy getTaskProxy() {
return sTaskProxy;
}

@Override
public BTAUtils.BTAVersionList loadVersionList() throws IOException {
return BTAUtils.downloadVersionList();
}

@Override
public void setTaskProxy(ModloaderListenerProxy proxy) {
sTaskProxy = proxy;
}

@Override
public ExpandableListAdapter createAdapter(BTAUtils.BTAVersionList versionList, LayoutInflater layoutInflater) {
return new BTAVersionListAdapter(versionList, layoutInflater);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@
public class FabricInstallFragment extends FabriclikeInstallFragment {

public static final String TAG = "FabricInstallFragment";
private static ModloaderListenerProxy sTaskProxy;

public FabricInstallFragment() {
super(FabriclikeUtils.FABRIC_UTILS);
}

@Override
protected ModloaderListenerProxy getListenerProxy() {
return sTaskProxy;
}

@Override
protected void setListenerProxy(ModloaderListenerProxy listenerProxy) {
sTaskProxy = listenerProxy;
super(FabriclikeUtils.FABRIC_UTILS, TAG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.kdt.pojavlaunch.PojavApplication;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.extra.ExtraCore;
import net.kdt.pojavlaunch.modloaders.FabriclikeDownloadTask;
import net.kdt.pojavlaunch.modloaders.FabriclikeUtils;
import net.kdt.pojavlaunch.modloaders.FabricVersion;
Expand All @@ -36,6 +37,7 @@

public abstract class FabriclikeInstallFragment extends Fragment implements ModloaderDownloadListener, CompoundButton.OnCheckedChangeListener {
private final FabriclikeUtils mFabriclikeUtils;
private final String mExtraTag;
private Spinner mGameVersionSpinner;
private FabricVersion[] mGameVersionArray;
private Future<?> mGameVersionFuture;
Expand All @@ -48,9 +50,10 @@ public abstract class FabriclikeInstallFragment extends Fragment implements Modl
private Button mStartButton;
private View mRetryView;
private CheckBox mOnlyStableCheckbox;
protected FabriclikeInstallFragment(FabriclikeUtils mFabriclikeUtils) {
protected FabriclikeInstallFragment(FabriclikeUtils mFabriclikeUtils, String mFragmentTag) {
super(R.layout.fragment_fabric_install);
this.mFabriclikeUtils = mFabriclikeUtils;
this.mExtraTag = mFragmentTag + "_proxy";
}

@Override
Expand Down Expand Up @@ -290,6 +293,10 @@ private void updateGameSpinner() {
mGameVersionSpinner.setAdapter(createAdapter(mGameVersionArray, mOnlyStableCheckbox.isChecked()));
}

protected abstract ModloaderListenerProxy getListenerProxy();
protected abstract void setListenerProxy(ModloaderListenerProxy listenerProxy);
private ModloaderListenerProxy getListenerProxy() {
return (ModloaderListenerProxy) ExtraCore.getValue(mExtraTag);
}
private void setListenerProxy(ModloaderListenerProxy listenerProxy) {
ExtraCore.setValue(mExtraTag, listenerProxy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

public class ForgeInstallFragment extends ModVersionListFragment<List<String>> {
public static final String TAG = "ForgeInstallFragment";
private static ModloaderListenerProxy sTaskProxy;
public ForgeInstallFragment() {
super(TAG);
}

@Override
public void onAttach(@NonNull Context context) {
Expand All @@ -38,15 +40,6 @@ public int getNoDataMsg() {
return R.string.forge_dl_no_installer;
}

@Override
public ModloaderListenerProxy getTaskProxy() {
return sTaskProxy;
}
@Override
public void setTaskProxy(ModloaderListenerProxy proxy) {
sTaskProxy = proxy;
}

@Override
public List<String> loadVersionList() throws IOException {
return ForgeUtils.downloadForgeVersions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.extra.ExtraCore;
import net.kdt.pojavlaunch.mirrors.DownloadMirror;
import net.kdt.pojavlaunch.modloaders.ModloaderDownloadListener;
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
Expand All @@ -25,14 +26,15 @@
import java.io.IOException;

public abstract class ModVersionListFragment<T> extends Fragment implements Runnable, View.OnClickListener, ExpandableListView.OnChildClickListener, ModloaderDownloadListener {
public static final String TAG = "ForgeInstallFragment";
private final String mExtraTag;
private ExpandableListView mExpandableListView;
private ProgressBar mProgressBar;
private LayoutInflater mInflater;
private View mRetryView;

public ModVersionListFragment() {
public ModVersionListFragment(String mFragmentTag) {
super(R.layout.fragment_mod_version_list);
this.mExtraTag = mFragmentTag + "_proxy";
}

@Override
Expand Down Expand Up @@ -148,11 +150,19 @@ public void onDownloadError(Exception e) {
});
}

private void setTaskProxy(ModloaderListenerProxy proxy) {
ExtraCore.setValue(mExtraTag, proxy);
}

private ModloaderListenerProxy getTaskProxy() {
return (ModloaderListenerProxy) ExtraCore.getValue(mExtraTag);
}

public abstract int getTitleText();
public abstract int getNoDataMsg();
public abstract ModloaderListenerProxy getTaskProxy();

public abstract T loadVersionList() throws IOException;
public abstract void setTaskProxy(ModloaderListenerProxy proxy);

public abstract ExpandableListAdapter createAdapter(T versionList, LayoutInflater layoutInflater);
public abstract Runnable createDownloadTask(Object selectedVersion, ModloaderListenerProxy listenerProxy);
public abstract void onDownloadFinished(Context context, File downloadedFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import net.kdt.pojavlaunch.JavaGUILauncherActivity;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
import net.kdt.pojavlaunch.modloaders.OptiFineDownloadTask;
import net.kdt.pojavlaunch.modloaders.OptiFineUtils;
Expand All @@ -18,7 +17,9 @@

public class OptiFineInstallFragment extends ModVersionListFragment<OptiFineUtils.OptiFineVersions> {
public static final String TAG = "OptiFineInstallFragment";
private static ModloaderListenerProxy sTaskProxy;
public OptiFineInstallFragment() {
super(TAG);
}
@Override
public int getTitleText() {
return R.string.of_dl_select_version;
Expand All @@ -28,22 +29,11 @@ public int getTitleText() {
public int getNoDataMsg() {
return R.string.of_dl_failed_to_scrape;
}

@Override
public ModloaderListenerProxy getTaskProxy() {
return sTaskProxy;
}

@Override
public OptiFineUtils.OptiFineVersions loadVersionList() throws IOException {
return OptiFineUtils.downloadOptiFineVersions();
}

@Override
public void setTaskProxy(ModloaderListenerProxy proxy) {
sTaskProxy = proxy;
}

@Override
public ExpandableListAdapter createAdapter(OptiFineUtils.OptiFineVersions versionList, LayoutInflater layoutInflater) {
return new OptiFineVersionListAdapter(versionList, layoutInflater);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ public class QuiltInstallFragment extends FabriclikeInstallFragment {
private static ModloaderListenerProxy sTaskProxy;

public QuiltInstallFragment() {
super(FabriclikeUtils.QUILT_UTILS);
}

@Override
protected ModloaderListenerProxy getListenerProxy() {
return sTaskProxy;
}

@Override
protected void setListenerProxy(ModloaderListenerProxy listenerProxy) {
sTaskProxy = listenerProxy;
super(FabriclikeUtils.QUILT_UTILS, TAG);
}
}

0 comments on commit 01de8c8

Please sign in to comment.