Skip to content

Commit

Permalink
[release] v1.2.0
Browse files Browse the repository at this point in the history
- New UI design.
  • Loading branch information
Konyaco committed Aug 11, 2021
1 parent fd8e859 commit 6e565eb
Show file tree
Hide file tree
Showing 64 changed files with 3,195 additions and 377 deletions.
4 changes: 2 additions & 2 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId = "me.konyaco.collinsdictionary"
minSdk = 21
targetSdk = 31
versionCode = 1
versionName = "1.1.0"
versionCode = 2
versionName = "1.2.0"
}

buildTypes {
Expand Down
2 changes: 2 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
android:theme="@style/Theme.CollinsDictionary">
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:windowSoftInputMode="adjustPan"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package me.konyaco.collinsdictionary

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.remember
import androidx.appcompat.app.AppCompatActivity
import me.konyaco.collinsdictionary.ui.App
import me.konyaco.collinsdictionary.ui.AppViewModel
import me.konyaco.collinsdictionary.ui.MyTheme

class MainActivity : AppCompatActivity() {
private val component by lazy { AppComponent() }
private val component by lazy { AppViewModel() }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
12 changes: 8 additions & 4 deletions android/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.CollinsDictionary" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:colorPrimary">@color/purple_500</item>
<item name="android:colorPrimaryDark">@color/purple_700</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:colorPrimary">#E57373</item>
<item name="android:colorPrimaryDark">#E57373</item>
<item name="android:background">#212121</item>
<item name="android:statusBarColor">#212121</item>
<item name="android:navigationBarColor">#212121</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
</resources>
10 changes: 0 additions & 10 deletions android/src/main/res/values/colors.xml

This file was deleted.

14 changes: 8 additions & 6 deletions android/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.CollinsDictionary" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:colorPrimary">@color/purple_500</item>
<item name="android:colorPrimaryDark">@color/purple_700</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<!-- <item name="android:windowIsTranslucent">true</item>-->
<item name="android:colorPrimary">#D32F2F</item>
<item name="android:colorPrimaryDark">#D32F2F</item>
<item name="android:background">#FAFAFA</item>
<item name="android:statusBarColor">#FAFAFA</item>
<item name="android:navigationBarColor">#FAFAFA</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
</resources>
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ allprojects {
}

group = "me.konyaco.collinsdictionary"
version = "1.1.0"
version = "1.2.0"
13 changes: 10 additions & 3 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ kotlin {
api(compose.foundation)
api(compose.animation)
api(compose.material)
api(compose.preview)
api(compose.uiTooling)
api(compose.materialIconsExtended)
}
}
Expand All @@ -27,6 +29,7 @@ kotlin {
}
val jvmMain by getting {
dependencies {
api(compose.desktop.currentOs)
implementation("org.jsoup:jsoup:1.11.3")
}
}
Expand All @@ -38,11 +41,15 @@ kotlin {
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

android {
compileSdkVersion(31)
compileSdk = 31
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(21)
targetSdkVersion(31)
minSdk = 21
targetSdk = 31
}
}
3 changes: 1 addition & 2 deletions common/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.konyaco.collinsdictionary.common" />
<manifest package="me.konyaco.collinsdictionary.common" />
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@ package me.konyaco.collinsdictionary.service
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import java.net.URL
import javax.net.ssl.HttpsURLConnection

actual class CollinsOnlineDictionary : CollinsDictionary {
override fun getDefinition(word: String): Word? {
return CollinsDictionaryHTMLParser.parse(getHtml(word))
}

private fun getHtml(word: String): String {
return URL("https://www.collinsdictionary.com/dictionary/english/$word").readText()
val url = URL("https://www.collinsdictionary.com/dictionary/english/$word")

val conn = (url.openConnection() as HttpsURLConnection).apply {
instanceFollowRedirects = false
connect()
}
return conn.inputStream.bufferedReader().readText()
}
}

private object CollinsDictionaryHTMLParser {
fun parse(html: String): Word? {
val jsoup = Jsoup.parse(html)
val mainContentElement = jsoup.getElementById("main_content") ?: return null // Word not found
val mainContentElement =
jsoup.getElementById("main_content") ?: return null // Word not found

return Word(parseCobuildDictionary(mainContentElement))
}

fun parseCobuildDictionary(mainContentElement: Element): CobuildDictionary {
val cobuildElement = mainContentElement.getElementsByClass("dictionary Cob_Adv_Brit dictentry").firstOrNull()
val cobuildElement =
mainContentElement.getElementsByClass("dictionary Cob_Adv_Brit dictentry").firstOrNull()

return if (cobuildElement != null) {
CobuildDictionary(listOf(parseSection(cobuildElement)))
Expand Down Expand Up @@ -99,9 +108,11 @@ private class DefinitionParser {
?: error("Cannot find word definitions")

definitionElement.getElementsByClass("hom").forEachIndexed { index, element ->
val grammarGroup: String = element.getElementsByClass("gramGrp pos").firstOrNull()?.text()
?: element.getElementsByClass("gramGrp").firstOrNull()?.getElementsByClass("pos")?.text()
?: return@forEachIndexed // Maybe it's not a definition, just skip
val grammarGroup: String =
element.getElementsByClass("gramGrp pos").firstOrNull()?.text()
?: element.getElementsByClass("gramGrp").firstOrNull()
?.getElementsByClass("pos")?.text()
?: return@forEachIndexed // Maybe it's not a definition, just skip
// ?: error("Cannot find grammar group in entry $index")

val senseElement = element.getElementsByClass("sense").first()
Expand All @@ -110,7 +121,12 @@ private class DefinitionParser {

val examples = senseElement.getElementsByClass("cit type-example").map {
val sentence = it.getElementsByClass("quote").first().text()
ExampleSentence(sentence, null, null, emptyList()) // TODO: 2021/7/28 Grammar pattern and sound url.
ExampleSentence(
sentence,
null,
null,
emptyList()
) // TODO: 2021/7/28 Grammar pattern and sound url.
}

definitionEntries.add(
Expand All @@ -128,4 +144,4 @@ private class DefinitionParser {

return definitionEntries
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package me.konyaco.collinsdictionary
package me.konyaco.collinsdictionary.ui

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.konyaco.collinsdictionary.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Typography
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontFamily
import me.konyaco.collinsdictionary.common.R

@Composable
actual fun MyTheme(content: @Composable () -> Unit) {
MaterialTheme(
colors = if (isSystemInDarkTheme()) darkColors else lightColors,
typography = Typography(defaultFontFamily = RobotoFontFamily),
content = content
)
}

actual object MyRes {
actual val Sound: Painter
@Composable
get() = painterResource(R.drawable.ic_sound)

actual val WordNotFoundLRes: Painter
@Composable
get() = painterResource(R.drawable.wordnotfound_l)

actual val WordNotFoundSRes: Painter
@Composable
get() = painterResource(R.drawable.wordnotfound_s)

actual val WordNotFoundLRes_Dark: Painter
@Composable
get() = painterResource(R.drawable.wordnotfound_l_dark)

actual val WordNotFoundSRes_Dark: Painter
@Composable
get() = painterResource(R.drawable.wordnotfound_s_dark)
}

actual val RobotoFontFamily: FontFamily = FontFamily.Default
actual val SourceSerifProFontFamily: FontFamily = FontFamily.Serif
9 changes: 9 additions & 0 deletions common/src/androidMain/res/drawable/ic_sound.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="18dp"
android:height="18dp"
android:viewportWidth="18"
android:viewportHeight="18">
<path
android:pathData="M0,6V12H4L9,17V1L4,6H0ZM13.5,9C13.5,7.23 12.48,5.71 11,4.97V13.02C12.48,12.29 13.5,10.77 13.5,9ZM11,0.23V2.29C13.89,3.15 16,5.83 16,9C16,12.17 13.89,14.85 11,15.71V17.77C15.01,16.86 18,13.28 18,9C18,4.72 15.01,1.14 11,0.23Z"
android:fillColor="#D32F2F"/>
</vector>
Loading

0 comments on commit 6e565eb

Please sign in to comment.