fix: Article Translate

This commit is contained in:
xtaodada 2024-08-15 11:03:23 +08:00
parent 97a78d6efc
commit 5b3d720003
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
4 changed files with 34 additions and 15 deletions

View File

@ -373,14 +373,6 @@ public class ArticleViewer implements NotificationCenter.NotificationCenterDeleg
private boolean drawBlockSelection;
private LinkPath urlPath = new LinkPath();
private static final int search_item = 1;
private static final int trans_item = 2;
private static final int share_item = 3;
private static final int open_item = 4;
private static final int settings_item = 5;
public ActionBarMenuSubItem transMenu;
private int anchorsOffsetMeasuredWidth;
TextSelectionHelper.ArticleTextSelectionHelper textSelectionHelper;
@ -4490,6 +4482,16 @@ public class ArticleViewer implements NotificationCenter.NotificationCenterDeleg
pages[0].getWebView().reload();
}
}
if (id == WebActionBar.trans_item) {
if (!pages[0].adapter.trans) {
updateTranslateButton(true);
ArticleTransKt.doTransLATE(this);
} else {
updateTranslateButton(false);
updatePaintSize();
}
}
});
actionBar.forwardButton.setOnClickListener(v -> {
@ -4751,6 +4753,14 @@ public class ArticleViewer implements NotificationCenter.NotificationCenterDeleg
}*/
}
public void updateTranslateButton(Boolean trans) {
if (actionBar == null || pages.length < 1) {
return;
}
actionBar.trans = trans;
pages[0].adapter.trans = trans;
}
private void updateSearchButtons() {
if (searchResults == null && !pages[0].isWeb()) {
return;
@ -6882,7 +6892,9 @@ public class ArticleViewer implements NotificationCenter.NotificationCenterDeleg
private void cleanup() {
trans = false;
transMenu.setTextAndIcon(LocaleController.getString("Translate", R.string.Translate), R.drawable.ic_translate);
if (actionBar != null) {
actionBar.trans = false;
}
currentPage = null;
blocks.clear();
photoBlocks.clear();

View File

@ -98,6 +98,8 @@ public class ItemOptions {
private int foregroundIndex;
private ActionBarPopupWindow.ActionBarPopupWindowLayout lastLayout;
public ActionBarMenuSubItem subItem;
public boolean swipeback;
private ItemOptions(BaseFragment fragment, View scrimView, boolean swipeback) {
@ -229,7 +231,7 @@ public class ItemOptions {
return this;
}
ActionBarMenuSubItem subItem = new ActionBarMenuSubItem(context, false, false, resourcesProvider);
subItem = new ActionBarMenuSubItem(context, false, false, resourcesProvider);
subItem.setPadding(dp(18), 0, dp(18), 0);
if (iconResId != 0 || iconDrawable != null) {
subItem.setTextAndIcon(text, iconResId, iconDrawable);

View File

@ -121,6 +121,9 @@ public class WebActionBar extends FrameLayout {
public static final int history_item = 8;
public static final int forward_item = 9;
public static final int trans_item = 100;
public boolean trans = false;
public WebActionBar(Context context, Theme.ResourcesProvider resourcesProvider) {
super(context);
this.resourcesProvider = resourcesProvider;
@ -197,6 +200,11 @@ public class WebActionBar extends FrameLayout {
}
if (menuType == ArticleViewer.PageLayout.TYPE_ARTICLE) {
o.add(R.drawable.msg_openin, getString(R.string.OpenInExternalApp), click.run(open_item));
if (trans) {
o.add(R.drawable.photo_undo, getString("UndoTranslate", R.string.UndoTranslate), click.run(trans_item));
} else {
o.add(R.drawable.ic_translate, getString(R.string.Translate), click.run(trans_item));
}
o.add(R.drawable.msg_search, getString(R.string.Search), click.run(search_item));
o.add(R.drawable.msg_share, getString(R.string.ShareFile), click.run(share_item));
o.add(R.drawable.msg_settings_old, getString(R.string.Settings), click.run(settings_item));

View File

@ -60,8 +60,7 @@ fun ArticleViewer.doTransLATE() {
status.setOnCancelListener {
pages[0].adapter.trans = false
transMenu.setTextAndIcon(LocaleController.getString("Translate", R.string.Translate), R.drawable.ic_translate)
updateTranslateButton(false)
cancel.set(true)
transPool.close()
@ -135,9 +134,7 @@ fun ArticleViewer.doTransLATE() {
cancel.set(true)
status.dismiss()
updatePaintSize()
pages[0].adapter.trans = false
transMenu.setTextAndIcon(LocaleController.getString("Translate", R.string.Translate), R.drawable.ic_translate)
updateTranslateButton(false)
AlertUtil.showTransFailedDialog(parentActivity, it is UnsupportedOperationException, it.message
?: it.javaClass.simpleName, Runnable {
doTransLATE()