Skip to content

Commit d67d65b

Browse files
committed
Add Write/Translate toggle button to toolbar
1 parent e847d09 commit d67d65b

7 files changed

Lines changed: 69 additions & 0 deletions

File tree

app/src/main/assets/hide-elements.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'div[aria-labelledby="app-stores-banner-description"]',
1313
'aside',
1414
'nav:has([data-testid="storefront-tabs-mobile-icon-text"])',
15+
'nav:has([aria-labelledby="product-navigation-mobile-bar-translator-link"])',
1516
].join(',');
1617

1718
const style = document.createElement('style');

app/src/main/java/com/example/deeplviewer/activity/MainActivity.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class MainActivity : AppCompatActivity() {
3535

3636
initializeWebView()
3737
createWebView(intent, savedInstanceState)
38+
setupWriteButton()
3839
setupSettingsButton()
3940
}
4041

@@ -133,6 +134,28 @@ class MainActivity : AppCompatActivity() {
133134
}
134135
}
135136

137+
private fun setupWriteButton() {
138+
val button = findViewById<ImageButton>(R.id.writeButton)
139+
updateWriteButtonIcon(button)
140+
button.setOnClickListener {
141+
val urlParam = getSharedPreferences("config", Context.MODE_PRIVATE)
142+
.getString("urlParam", "#en/en/") ?: "#en/en/"
143+
val isCurrentlyWrite = startUrl.contains("/write")
144+
val newPageType = if (isCurrentlyWrite) "translator" else "write"
145+
val newUrl = "https://www.deepl.com/$newPageType$urlParam"
146+
startUrl = newUrl
147+
webView.loadUrl(newUrl)
148+
updateWriteButtonIcon(button)
149+
}
150+
}
151+
152+
private fun updateWriteButtonIcon(button: ImageButton) {
153+
val isWrite = startUrl.contains("/write")
154+
button.setImageResource(
155+
if (isWrite) R.drawable.ic_deepl_translate else R.drawable.ic_deepl_write
156+
)
157+
}
158+
136159
/**
137160
* Sets up the settings button to open the SettingsActivity
138161
*/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="@color/settingIcon"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
8+
<path
9+
android:fillColor="#00000000"
10+
android:pathData="M5 8L11 14M4 14L10 8L12 5M2 5H14M7 2H8M22 22L17 12L12 22M14 18H20"
11+
android:strokeWidth="1.5"
12+
android:strokeColor="@android:color/white"
13+
android:strokeLineCap="round"
14+
android:strokeLineJoin="round" />
15+
16+
</vector>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="@color/settingIcon"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
8+
<path
9+
android:fillColor="#00000000"
10+
android:pathData="M5 6V10M19 14V18M10 2V4M7 8H3M21 16H17M11 3H9M13 19.5V21.5M14 20.5H12M14.9999 5.00038L18.9999 9.00038M21.1739 6.81238C21.7026 6.2838 21.9997 5.56685 21.9998 4.81923C21.9999 4.07162 21.703 3.35459 21.1744 2.82588C20.6459 2.29717 19.9289 2.00009 19.1813 2C18.4337 1.99991 17.7166 2.2968 17.1879 2.82538L3.84193 16.1744C3.60975 16.4059 3.43805 16.6909 3.34193 17.0044L2.02093 21.3564C1.99509 21.4429 1.99314 21.5347 2.01529 21.6222C2.03743 21.7097 2.08285 21.7896 2.14673 21.8534C2.21061 21.9172 2.29055 21.9624 2.37809 21.9845C2.46563 22.0065 2.55749 22.0044 2.64393 21.9784L6.99693 20.6584C7.3101 20.5631 7.59511 20.3925 7.82693 20.1614L21.1739 6.81238Z"
11+
android:strokeWidth="1.5"
12+
android:strokeColor="@android:color/white"
13+
android:strokeLineCap="round"
14+
android:strokeLineJoin="round" />
15+
16+
</vector>

app/src/main/res/layout/activity_main.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838
android:layout_height="match_parent"
3939
android:layout_weight="1" />
4040

41+
<ImageButton
42+
android:id="@+id/writeButton"
43+
android:layout_width="28dp"
44+
android:layout_height="28dp"
45+
android:layout_gravity="center_vertical"
46+
android:layout_marginStart="16dp"
47+
android:background="@color/transparent"
48+
android:contentDescription="@string/title_deepl_write"
49+
android:scaleType="fitCenter"
50+
app:srcCompat="@drawable/ic_deepl_write" />
51+
4152
<ImageButton
4253
android:id="@+id/settingButton"
4354
android:layout_width="28dp"

app/src/main/res/values-ja/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<string name="copy_clipboard">テキストをコピーしました</string>
55
<string name="network_err">DeepLサーバーへの接続に失敗しました</string>
66
<string name="title_activity_settings">設定</string>
7+
<string name="title_deepl_write">DeepL Write</string>
78
<string name="themeSettings">テーマの設定</string>
89
<string name="theme">テーマ</string>
910
<string name="theme_light">ライト</string>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<string name="copy_clipboard">Text has been Copied</string>
66
<string name="network_err">Oops, failed to connect to DeepL server</string>
77
<string name="title_activity_settings">Settings</string>
8+
<string name="title_deepl_write">DeepL Write</string>
89
<string name="themeSettings">Theme settings</string>
910
<string name="theme">Theme</string>
1011
<string name="theme_light">Light</string>

0 commit comments

Comments
 (0)