Skip to content

Commit 5005be0

Browse files
shit 2
1 parent 070ec70 commit 5005be0

File tree

19 files changed

+154
-409
lines changed

19 files changed

+154
-409
lines changed

androidApp/src/main/java/com/mrboomdev/awery/app/App.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ class App : Application() {
476476
}
477477

478478
@JvmStatic
479-
fun snackbar(activity: Activity, title: Any?, button: Any?, buttonCallback: Runnable?, duration: Int) {
479+
@JvmOverloads
480+
fun snackbar(activity: Activity, title: Any?, button: Any?, buttonCallback: Runnable?, duration: Int = Snackbar.LENGTH_LONG) {
480481
runOnUiThread {
481482
val titleText = title?.toString() ?: "null"
482483
val buttonText = button?.toString() ?: "null"

androidApp/src/main/java/com/mrboomdev/awery/app/AweryLifecycle.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ open class AweryLifecycle private constructor() : ActivityLifecycleCallbacks {
3232
}
3333

3434
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
35+
PlatformResources.load(activity)
3536
if(infos.contains(activity)) return
3637

3738
infos[activity] = ActivityInfo(activity).apply {

androidApp/src/main/java/com/mrboomdev/awery/app/CrashHandler.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ object CrashHandler {
283283
return this
284284
}
285285

286+
fun setPrefix(prefix: String?): Builder {
287+
report.prefix = prefix
288+
return this
289+
}
290+
286291
fun setTitle(title: String?): Builder {
287292
report.title = title
288293
return this

androidApp/src/main/java/com/mrboomdev/awery/data/settings/SettingsItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public String getDescription(Context context) {
283283
+ description.substring(endIndex + 1);
284284
}
285285

286-
var got = i18n(R.string.class, description);
286+
var got = i18n(description);
287287
return got != null ? got : description;
288288
}
289289

androidApp/src/main/java/com/mrboomdev/awery/extensions/ExtensionSettings.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
import com.mrboomdev.awery.ui.mobile.screens.settings.SettingsDataHandler;
5050
import com.mrboomdev.awery.util.async.AsyncFuture;
5151
import com.mrboomdev.awery.util.async.AsyncUtils;
52-
import com.mrboomdev.awery.util.exceptions.ExceptionDescriptor;
52+
import com.mrboomdev.awery.util.exceptions.OkiThrowableMessage;
53+
import com.mrboomdev.awery.util.exceptions.OkiThrowableMessageKt;
5354
import com.mrboomdev.awery.util.io.HttpClient;
5455
import com.mrboomdev.awery.util.io.HttpRequest;
5556
import com.mrboomdev.awery.util.ui.dialog.DialogBuilder;
@@ -224,7 +225,7 @@ public void onSuccess(@NonNull List<Extension> result) {
224225
@Override
225226
public void onFailure(@NonNull Throwable t) {
226227
Log.e(TAG, "Failed to get a repository!", t);
227-
runOnUiThread(() -> inputField.setError(ExceptionDescriptor.getTitle(t, context)));
228+
runOnUiThread(() -> inputField.setError(OkiThrowableMessageKt.explain(t).getTitle()));
228229
loadingWindow.dismiss();
229230
}
230231
});
@@ -456,13 +457,13 @@ public void onFailure(@NonNull Throwable t) {
456457

457458
switch(getUpdateStatus()) {
458459
case DOWNGRADE -> dialog.setMessage("It looks like you're trying to install an older version of an extension. Try uninstalling an old version and retry again."
459-
+ "\n\nException:\n" + ExceptionDescriptor.getMessage(t, context)).show();
460+
+ "\n\nException:\n" + OkiThrowableMessageKt.explain(t).getMessage()).show();
460461

461462
case UPDATE -> dialog.setMessage("It look's like you're trying to update an extension from a different repository. Try uninstalling an old version and retry again."
462-
+ "\n\nException:\n" + ExceptionDescriptor.getMessage(t, context)).show();
463+
+ "\n\nException:\n" + OkiThrowableMessageKt.explain(t).getMessage()).show();
463464

464465
default -> dialog.setMessage("Something just went wrong. We don't know what, and we don't know why."
465-
+ "\n\nException:\n" + ExceptionDescriptor.getMessage(t, context)).show();
466+
+ "\n\nException:\n" + OkiThrowableMessageKt.explain(t).getMessage()).show();
466467
}
467468
}
468469
});
@@ -472,7 +473,7 @@ public void onFailure(@NonNull Throwable t) {
472473
public void onFailure(@NonNull Throwable t) {
473474
Log.e(TAG, "Failed to download an extension!", t);
474475
window.dismiss();
475-
toast(ExceptionDescriptor.getTitle(t, context));
476+
toast(OkiThrowableMessageKt.explain(t).getTitle());
476477
}
477478
});
478479

androidApp/src/main/java/com/mrboomdev/awery/extensions/support/yomi/aniyomi/AniyomiProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public AsyncFuture<List<CatalogVideoFile>> getVideoFiles(@NonNull SettingsList f
244244
source, AniyomiEpisode.fromEpisode(episode)).await();
245245

246246
if(videos == null || videos.isEmpty()) {
247-
throw new ZeroResultsException("Aniyomi: No videos found", R.string.nothing_found);
247+
throw new ZeroResultsException("Aniyomi: No videos found", i18n(String0_commonMainKt.getNothing_found(Res.string.INSTANCE)));
248248
}
249249

250250
return stream(videos).map(item -> new CatalogVideoFile(
@@ -278,13 +278,13 @@ public Set<String> getFeatures() {
278278
}
279279

280280
@Contract("null -> fail")
281-
private void checkSearchResults(AnimesPage page) {
281+
private void checkSearchResults(AnimesPage page) throws ZeroResultsException {
282282
if(page == null) {
283283
throw new NullPointerException("page is null!");
284284
}
285285

286286
if(page.getAnimes().isEmpty()) {
287-
throw new ZeroResultsException("No media was found", R.string.no_media_found);
287+
throw new ZeroResultsException("No media was found", i18n(String0_commonMainKt.getNo_media_found(Res.string.INSTANCE)));
288288
}
289289
}
290290

@@ -294,7 +294,7 @@ public AsyncFuture<CatalogMedia> getMedia(String id) {
294294
setUrl(id);
295295
}}).then(anime -> {
296296
if(anime == null) {
297-
throw new ZeroResultsException("Anime not found", R.string.no_media_found);
297+
throw new ZeroResultsException("Anime not found", i18n(String0_commonMainKt.getNo_media_found(Res.string.INSTANCE)));
298298
}
299299

300300
// Manually set values if they wasn't been by an extension

androidApp/src/main/java/com/mrboomdev/awery/ui/mobile/screens/catalog/feeds/FeedsFragment.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.mrboomdev.awery.app.App.resolveAttrColor;
44
import static com.mrboomdev.awery.app.AweryLifecycle.runOnUiThread;
5+
import static com.mrboomdev.awery.platform.PlatformResourcesKt.i18n;
56
import static com.mrboomdev.awery.util.async.AsyncUtils.thread;
67
import static com.mrboomdev.awery.util.ui.ViewUtil.useLayoutParams;
78
import static java.util.Objects.requireNonNull;
@@ -30,15 +31,17 @@
3031
import com.mrboomdev.awery.data.settings.SettingsItemType;
3132
import com.mrboomdev.awery.data.settings.SettingsList;
3233
import com.mrboomdev.awery.databinding.ScreenFeedBinding;
34+
import com.mrboomdev.awery.ext.util.exceptions.ZeroResultsException;
3335
import com.mrboomdev.awery.extensions.ExtensionProvider;
3436
import com.mrboomdev.awery.extensions.data.CatalogFeed;
3537
import com.mrboomdev.awery.ext.data.CatalogMedia;
3638
import com.mrboomdev.awery.extensions.data.CatalogSearchResults;
39+
import com.mrboomdev.awery.generated.Res;
40+
import com.mrboomdev.awery.generated.String0_commonMainKt;
3741
import com.mrboomdev.awery.ui.mobile.screens.catalog.MediaCategoriesAdapter;
3842
import com.mrboomdev.awery.util.MediaUtils;
3943
import com.mrboomdev.awery.util.async.AsyncFuture;
4044
import com.mrboomdev.awery.util.exceptions.ExtensionNotInstalledException;
41-
import com.mrboomdev.awery.util.exceptions.ZeroResultsException;
4245
import com.mrboomdev.awery.ui.mobile.components.EmptyStateView;
4346
import com.mrboomdev.awery.util.ui.adapter.SingleViewAdapter;
4447

@@ -135,14 +138,14 @@ private void loadFeed(@NonNull CatalogFeed feed, long currentLoadId) {
135138
loadFeed(feed, new AsyncFuture.Callback<>() {
136139
@SuppressLint("NotifyDataSetChanged")
137140
@Override
138-
public void onSuccess(@NonNull CatalogSearchResults<? extends CatalogMedia> searchResults) {
141+
public void onSuccess(@NonNull CatalogSearchResults<? extends CatalogMedia> searchResults) throws ZeroResultsException {
139142
if(currentLoadId != loadId) return;
140143

141144
var filtered = MediaUtils.filterMediaSync(searchResults);
142145
var filteredResults = CatalogSearchResults.of(filtered, searchResults.hasNextPage());
143146

144147
if(filteredResults.isEmpty()) {
145-
throw new ZeroResultsException("All results were filtered out.", R.string.no_media_found);
148+
throw new ZeroResultsException("All results were filtered out.", i18n(String0_commonMainKt.getNo_media_found(Res.string.INSTANCE)));
146149
}
147150

148151
runOnUiThread(() -> {
@@ -181,14 +184,14 @@ public void onFailure(@NonNull Throwable e) {
181184
loadFeed(feed, new AsyncFuture.Callback<>() {
182185
@SuppressLint("NotifyDataSetChanged")
183186
@Override
184-
public void onSuccess(@NonNull CatalogSearchResults<? extends CatalogMedia> searchResults) {
187+
public void onSuccess(@NonNull CatalogSearchResults<? extends CatalogMedia> searchResults) throws ZeroResultsException {
185188
if(currentLoadId != loadId) return;
186189

187190
var filtered = MediaUtils.filterMediaSync(searchResults);
188191
var filteredResults = CatalogSearchResults.of(filtered, searchResults.hasNextPage());
189192

190193
if(filteredResults.isEmpty()) {
191-
throw new ZeroResultsException("All results were filtered out.", R.string.no_media_found);
194+
throw new ZeroResultsException("All results were filtered out.", i18n(String0_commonMainKt.getNo_media_found(Res.string.INSTANCE)));
192195
}
193196

194197
runOnUiThread(() -> {
@@ -296,7 +299,7 @@ private void tryToLoadNextFeed(@Nullable CatalogFeed loadedFeed, long currentLoa
296299
} else {
297300
emptyStateAdapter.getBinding(binding -> runOnUiThread(() -> {
298301
if(tab == null || tab.showEnd) {
299-
binding.setInfo(R.string.you_reached_end, R.string.you_reached_end_description);
302+
binding.setInfo(i18n(String0_commonMainKt.getYou_reached_end(Res.string.INSTANCE)), i18n(String0_commonMainKt.getYou_reached_end_description(Res.string.INSTANCE)));
300303
emptyStateAdapter.setEnabled(true);
301304
} else {
302305
binding.hideAll();

androidApp/src/main/java/com/mrboomdev/awery/ui/mobile/screens/media/MediaCommentsFragment.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static com.mrboomdev.awery.app.App.resolveAttrColor;
88
import static com.mrboomdev.awery.app.App.toast;
99
import static com.mrboomdev.awery.app.AweryLifecycle.runOnUiThread;
10+
import static com.mrboomdev.awery.platform.PlatformResourcesKt.i18n;
1011
import static com.mrboomdev.awery.util.NiceUtils.parseDate;
1112
import static com.mrboomdev.awery.util.NiceUtils.requireArgument;
1213
import static com.mrboomdev.awery.util.NiceUtils.requireNonNull;
@@ -55,10 +56,12 @@
5556
import com.mrboomdev.awery.extensions.data.CatalogVideo;
5657
import com.mrboomdev.awery.extensions.request.PostMediaCommentRequest;
5758
import com.mrboomdev.awery.extensions.request.ReadMediaCommentsRequest;
59+
import com.mrboomdev.awery.generated.Res;
60+
import com.mrboomdev.awery.generated.String0_commonMainKt;
5861
import com.mrboomdev.awery.util.NiceUtils;
62+
import com.mrboomdev.awery.util.exceptions.OkiThrowableMessageKt;
5963
import com.mrboomdev.awery.utils.UniqueIdGenerator;
6064
import com.mrboomdev.awery.util.async.AsyncFuture;
61-
import com.mrboomdev.awery.util.exceptions.ExceptionDescriptor;
6265
import com.mrboomdev.awery.util.ui.adapter.DropdownAdapter;
6366
import com.mrboomdev.awery.util.ui.adapter.DropdownBindingAdapter;
6467
import com.mrboomdev.awery.util.ui.adapter.SingleViewAdapter;
@@ -230,8 +233,8 @@ private void loadData(CatalogComment parent, CatalogComment reloadThis, int page
230233

231234
if(sources == null || sources.isEmpty()) {
232235
loadingAdapter.getBinding(binding -> {
233-
binding.title.setText(R.string.nothing_found);
234-
binding.message.setText(R.string.no_comment_extensions);
236+
binding.title.setText(i18n(String0_commonMainKt.getNothing_found(Res.string.INSTANCE)));
237+
binding.message.setText(i18n(String0_commonMainKt.getNo_comment_extensions(Res.string.INSTANCE)));
235238

236239
binding.info.setVisibility(View.VISIBLE);
237240
binding.progressBar.setVisibility(View.GONE);
@@ -315,9 +318,9 @@ public void onFailure(Throwable e) {
315318
return;
316319
}
317320

318-
var descriptor = new ExceptionDescriptor(e);
319-
binding.title.setText(descriptor.getTitle(getContext()));
320-
binding.message.setText(descriptor.getMessage(getContext()));
321+
var descriptor = OkiThrowableMessageKt.explain(e);
322+
binding.title.setText(descriptor.getTitle());
323+
binding.message.setText(descriptor.getMessage());
321324

322325
binding.info.setVisibility(View.VISIBLE);
323326
binding.progressBar.setVisibility(View.GONE);
@@ -341,8 +344,8 @@ private void reachedEnd() {
341344
loadingAdapter.getBinding(binding -> {
342345
binding.info.setVisibility(View.VISIBLE);
343346
binding.progressBar.setVisibility(View.GONE);
344-
binding.title.setText(R.string.you_reached_end);
345-
binding.message.setText(R.string.you_reached_end_description);
347+
binding.title.setText(i18n(String0_commonMainKt.getYou_reached_end(Res.string.INSTANCE)));
348+
binding.message.setText(i18n(String0_commonMainKt.getYou_reached_end_description(Res.string.INSTANCE)));
346349
loadingAdapter.setEnabled(true);
347350
});
348351
}
@@ -547,7 +550,7 @@ public void onFailure(Throwable t) {
547550
CrashHandler.showErrorDialog(requireContext(), new CrashHandler.CrashReport.Builder()
548551
.setTitle("Failed to edit an comment")
549552
.setThrowable(t)
550-
.setPrefix(R.string.please_report_bug_extension)
553+
.setPrefix(i18n(String0_commonMainKt.getPlease_report_bug_extension(Res.string.INSTANCE)))
551554
.build());
552555

553556
sendBinding.loadingIndicator.setVisibility(View.GONE);
@@ -752,10 +755,10 @@ public CommentViewHolder(@NonNull WidgetCommentBinding binding) {
752755
new DialogBuilder(requireContext())
753756
.setTitle("Delete the comment?")
754757
.setMessage("You'll be unable to undo this action later.")
755-
.setPositiveButton(R.string.confirm, dialog -> {
758+
.setPositiveButton(i18n(String0_commonMainKt.getConfirm(Res.string.INSTANCE)), dialog -> {
756759
selectedProvider.deleteComment(comment).addCallback(new AsyncFuture.Callback<>() {
757760
@Override
758-
public void onSuccess(Boolean success) {
761+
public void onSuccess(@NonNull Boolean success) {
759762
var context = getContext();
760763
if(context == null) return;
761764

@@ -768,21 +771,21 @@ public void onSuccess(Boolean success) {
768771
}
769772

770773
@Override
771-
public void onFailure(Throwable t) {
774+
public void onFailure(@NonNull Throwable t) {
772775
var context = getContext();
773776
if(context == null) return;
774777

775778
CrashHandler.showErrorDialog(new CrashHandler.CrashReport.Builder()
776779
.setTitle("Failed to delete an comment")
777-
.setPrefix(R.string.please_report_bug_extension)
780+
.setPrefix(i18n(String0_commonMainKt.getPlease_report_bug_extension(Res.string.INSTANCE)))
778781
.setThrowable(t)
779782
.build());
780783
}
781784
});
782785

783786
dialog.dismiss();
784787
})
785-
.setNegativeButton(R.string.cancel, DialogBuilder::dismiss)
788+
.setNegativeButton(i18n(String0_commonMainKt.getCancel(Res.string.INSTANCE)), DialogBuilder::dismiss)
786789
.show();
787790
});
788791

@@ -844,7 +847,7 @@ public void onFailure(Throwable t) {
844847

845848
CrashHandler.showErrorDialog(new CrashHandler.CrashReport.Builder()
846849
.setTitle("Failed to vote")
847-
.setPrefix(R.string.please_report_bug_extension)
850+
.setPrefix(i18n(String0_commonMainKt.getPlease_report_bug_extension(Res.string.INSTANCE)))
848851
.setThrowable(t)
849852
.build());
850853
}

androidApp/src/main/java/com/mrboomdev/awery/ui/mobile/screens/media/MediaPlayEpisodesAdapter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static com.mrboomdev.awery.app.App.share;
55
import static com.mrboomdev.awery.app.AweryLifecycle.getActivity;
66
import static com.mrboomdev.awery.app.AweryLifecycle.runOnUiThread;
7+
import static com.mrboomdev.awery.platform.PlatformResourcesKt.i18n;
78
import static com.mrboomdev.awery.util.NiceUtils.stream;
89
import static com.mrboomdev.awery.util.async.AsyncUtils.thread;
910
import static com.mrboomdev.awery.util.ui.ViewUtil.dpPx;
@@ -27,6 +28,8 @@
2728
import com.mrboomdev.awery.ext.data.CatalogMedia;
2829
import com.mrboomdev.awery.extensions.data.CatalogMediaProgress;
2930
import com.mrboomdev.awery.extensions.data.CatalogVideo;
31+
import com.mrboomdev.awery.generated.Res;
32+
import com.mrboomdev.awery.generated.String0_commonMainKt;
3033
import com.mrboomdev.awery.utils.UniqueIdGenerator;
3134

3235
import java.util.ArrayList;
@@ -154,12 +157,12 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
154157
0, com.google.android.material.R.style.Widget_Material3_PopupMenu), v);
155158

156159
menu.getMenu().add(0, 0, 0, progress != 0
157-
? R.string.mark_not_watched : R.string.mark_watched);
160+
? i18n(String0_commonMainKt.getMark_not_watched(Res.string.INSTANCE)) : i18n(String0_commonMainKt.getMark_watched(Res.string.INSTANCE)));
158161

159-
menu.getMenu().add(0, 1, 0, R.string.comments);
162+
menu.getMenu().add(0, 1, 0, i18n(String0_commonMainKt.getComments(Res.string.INSTANCE)));
160163
// menu.getMenu().add(0, 2, 0, "Download");
161-
menu.getMenu().add(0, 3, 0, R.string.share);
162-
menu.getMenu().add(0, 4, 0, R.string.open_link_externally);
164+
menu.getMenu().add(0, 3, 0, i18n(String0_commonMainKt.getShare(Res.string.INSTANCE)));
165+
menu.getMenu().add(0, 4, 0, i18n(String0_commonMainKt.getOpen_link_externally(Res.string.INSTANCE)));
163166
// menu.getMenu().add(0, 5, 0, "Hide");
164167

165168
menu.setOnMenuItemClickListener(item -> switch(item.getItemId()) {

androidApp/src/main/java/com/mrboomdev/awery/ui/mobile/screens/media/MediaPlayFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import com.mrboomdev.awery.util.ui.adapter.SingleViewAdapter
6464
import com.mrboomdev.awery.util.ui.adapter.SingleViewAdapter.BindingSingleViewAdapter
6565
import com.mrboomdev.awery.utils.buildIntent
6666
import com.mrboomdev.awery.utils.startActivityForResult
67-
import com.mrboomdev.safeargsnext.SafeArgsIntent
6867
import com.mrboomdev.safeargsnext.owner.SafeArgsFragment
6968
import com.mrboomdev.safeargsnext.util.rememberSafeArgs
7069
import com.squareup.moshi.adapter
@@ -612,7 +611,7 @@ class MediaPlayFragment: Fragment(), SafeArgsFragment<MediaPlayFragment.Args>, O
612611

613612
placeholderAdapter!!.getBinding { binding ->
614613
runOnUiThread {
615-
if(error.t is BotSecurityBypassException && source != null && (media?.url != null || source.previewUrl != null)) {
614+
if(error.unwrapped is BotSecurityBypassException && source != null && (media?.url != null || source.previewUrl != null)) {
616615
binding.setInfo(
617616
title = error.title,
618617
message = error.message,

0 commit comments

Comments
 (0)