Skip to content

Commit 3132614

Browse files
committed
Update LocalModListAdapter.java
1 parent 20a2142 commit 3132614

File tree

1 file changed

+28
-46
lines changed

1 file changed

+28
-46
lines changed

FCL/src/main/java/com/tungsten/fcl/ui/manage/LocalModListAdapter.java

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,6 @@ public LocalModListAdapter(Context context, ModListPage modListPage) {
6868
selectedItemsProperty.clear();
6969
fromSelf = false;
7070
notifyDataSetChanged();
71-
Task.runAsync(() -> {
72-
listProperty().get().forEach(modInfoObject -> {
73-
for (RemoteMod.Type type : RemoteMod.Type.values()) {
74-
try {
75-
if (modInfoObject.getRemoteMod() == null) {
76-
Optional<RemoteMod.Version> remoteVersion = type.getRemoteModRepository().getRemoteVersionByLocalFile(modInfoObject.getModInfo(), modInfoObject.getModInfo().getFile());
77-
if (remoteVersion.isPresent()) {
78-
RemoteMod remoteMod = type.getRemoteModRepository().getModById(remoteVersion.get().getModid());
79-
modInfoObject.getModInfo().setRemoteVersion(remoteVersion.get());
80-
modInfoObject.setRemoteMod(remoteMod);
81-
Schedulers.androidUIThread().execute(LocalModListAdapter.this::notifyDataSetChanged);
82-
break;
83-
}
84-
}
85-
} catch (Throwable ignore) {
86-
}
87-
}
88-
});
89-
notifyDataSetChanged();
90-
}).start();
9171
});
9272
selectedItemsProperty.addListener((InvalidationListener) observable -> {
9373
if (!fromSelf) {
@@ -157,26 +137,9 @@ public View getView(int i, View view, ViewGroup viewGroup) {
157137
viewHolder.checkBox.checkProperty().unbindBidirectional(viewHolder.booleanProperty);
158138
}
159139
viewHolder.checkBox.checkProperty().bindBidirectional(viewHolder.booleanProperty = modInfoObject.getActive());
160-
if (StringUtils.isNotBlank(modInfoObject.getModInfo().getLogoPath())) {
161-
Task.supplyAsync(() -> {
162-
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(modInfoObject.getModInfo().getFile())) {
163-
Path iconPath = fs.getPath(modInfoObject.getModInfo().getLogoPath());
164-
if (Files.exists(iconPath)) {
165-
ByteArrayOutputStream stream = new ByteArrayOutputStream();
166-
Files.copy(iconPath, stream);
167-
return new ByteArrayInputStream(stream.toByteArray());
168-
}
169-
}
170-
return null;
171-
}).whenComplete(Schedulers.androidUIThread(), (stream, exception) -> {
172-
if (stream != null) {
173-
viewHolder.icon.setVisibility(View.VISIBLE);
174-
viewHolder.icon.setImageBitmap(BitmapFactory.decodeStream(stream));
175-
}
176-
}).start();
177-
} else {
178-
viewHolder.icon.setVisibility(View.GONE);
179-
}
140+
viewHolder.icon.setTag(i);
141+
viewHolder.icon.setImageBitmap(null);
142+
viewHolder.icon.setVisibility(View.GONE);
180143
viewHolder.name.setText(modInfoObject.getTitle());
181144
String tag = getTag(modInfoObject);
182145
viewHolder.tag.setText(tag);
@@ -194,12 +157,31 @@ public View getView(int i, View view, ViewGroup viewGroup) {
194157
ModInfoDialog dialog = new ModInfoDialog(getContext(), modInfoObject);
195158
dialog.show();
196159
});
197-
RemoteMod remoteMod = modInfoObject.getRemoteMod();
198-
if (remoteMod != null) {
199-
viewHolder.icon.setVisibility(View.VISIBLE);
200-
Glide.with(getContext()).load(remoteMod.getIconUrl()).into(viewHolder.icon);
201-
viewHolder.name.setText(remoteMod.getTitle());
202-
}
160+
Task.supplyAsync(() -> {
161+
for (RemoteMod.Type type : RemoteMod.Type.values()) {
162+
try {
163+
if (modInfoObject.getRemoteMod() == null) {
164+
Optional<RemoteMod.Version> remoteVersion = type.getRemoteModRepository().getRemoteVersionByLocalFile(modInfoObject.getModInfo(), modInfoObject.getModInfo().getFile());
165+
if (remoteVersion.isPresent()) {
166+
RemoteMod remoteMod = type.getRemoteModRepository().getModById(remoteVersion.get().getModid());
167+
modInfoObject.getModInfo().setRemoteVersion(remoteVersion.get());
168+
modInfoObject.setRemoteMod(remoteMod);
169+
} else {
170+
continue;
171+
}
172+
}
173+
return modInfoObject.getRemoteMod();
174+
} catch (Throwable ignore) {
175+
}
176+
}
177+
return null;
178+
}).whenComplete(Schedulers.androidUIThread(), (remoteMod, exception) -> {
179+
if ((int) viewHolder.icon.getTag() == i && remoteMod != null) {
180+
viewHolder.icon.setVisibility(View.VISIBLE);
181+
Glide.with(viewHolder.icon).load(remoteMod.getIconUrl()).into(viewHolder.icon);
182+
viewHolder.name.setText(remoteMod.getTitle());
183+
}
184+
}).start();
203185
return view;
204186
}
205187

0 commit comments

Comments
 (0)