Skip to content

Commit

Permalink
Merge pull request #2 from khmerlang/add_sug_color_type
Browse files Browse the repository at this point in the history
Add type check for spell check
  • Loading branch information
RathanakSreang authored Apr 5, 2024
2 parents 81afa5a + 2dd34f7 commit 4345755
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
minSdkVersion 21
targetSdk = 33
versionCode 5
versionName '4.1'
versionName '5.1'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rathanak.khmerroman.keyboard.smartbar

import android.annotation.SuppressLint
import android.content.Context
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
Expand All @@ -17,9 +18,17 @@ import androidx.recyclerview.widget.RecyclerView
import com.google.android.flexbox.FlexboxLayout
import com.rathanak.khmerroman.R
import com.rathanak.khmerroman.keyboard.R2KhmerService
import com.rathanak.khmerroman.keyboard.common.Styles
import com.rathanak.khmerroman.request.SpellCheckResultDTO

class SpellSuggestionAdapter(private val smartSpell: SpellSuggestionManager, private val context: Context, var suggestionsList: java.util.ArrayList<SpellCheckResultDTO>) : BaseAdapter() {
private val primaryTypes = listOf("primary", "suggestion", "improvement", "reforming", "refactoring")
private val secondaryTypes = listOf("secondary")
private val successTypes = listOf("success")
private val errorTypes = listOf("error", "typo", "danger")
private val infoTypes = listOf("info")
private val warningTypes = listOf("warning", "recommend", "grammar")

override fun getCount(): Int {
return suggestionsList.size
}
Expand All @@ -32,13 +41,35 @@ class SpellSuggestionAdapter(private val smartSpell: SpellSuggestionManager, pri
return position.toLong()
}

@SuppressLint("NewApi")
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
var convertView = convertView
convertView = LayoutInflater.from(context).inflate(R.layout.spell_suggestion_item, parent, false)
val serialNum = convertView.findViewById(R.id.typoText) as TextView
val typoWord = suggestionsList[position].word
val type = suggestionsList[position].type
serialNum.text = typoWord

if (errorTypes.contains(type)) {
serialNum.foreground = context.resources.getDrawable(R.drawable.strikethrough_shape_error)
serialNum.setTextColor(context.resources.getColor(R.color.error))
} else if(primaryTypes.contains(type)) {
serialNum.foreground = context.resources.getDrawable(R.drawable.strikethrough_shape_primary)
serialNum.setTextColor(context.resources.getColor(R.color.primary))
} else if (secondaryTypes.contains(type)) {
serialNum.foreground = context.resources.getDrawable(R.drawable.strikethrough_shape_secondary)
serialNum.setTextColor(context.resources.getColor(R.color.secondary))
} else if (successTypes.contains(type)) {
serialNum.foreground = context.resources.getDrawable(R.drawable.strikethrough_shape_success)
serialNum.setTextColor(context.resources.getColor(R.color.success))
} else if (infoTypes.contains(type)) {
serialNum.foreground = context.resources.getDrawable(R.drawable.strikethrough_shape_info)
serialNum.setTextColor(context.resources.getColor(R.color.info))
} else if (warningTypes.contains(type)) {
serialNum.foreground = context.resources.getDrawable(R.drawable.strikethrough_shape_warning)
serialNum.setTextColor(context.resources.getColor(R.color.warning))
}

val btnSpellItemClose = convertView.findViewById(R.id.btnSpellItemClose) as ImageButton
btnSpellItemClose.setOnClickListener {
suggestionsList.removeAt(position); // remove the item from the data list
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/strikethrough_shape_error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="3dp"
android:color="@color/error" />
</shape>
</item>
</selector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/strikethrough_shape_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="3dp"
android:color="@color/info" />
</shape>
</item>
</selector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/strikethrough_shape_primary.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="3dp"
android:color="@color/primary" />
</shape>
</item>
</selector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/strikethrough_shape_secondary.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="3dp"
android:color="@color/secondary" />
</shape>
</item>
</selector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/strikethrough_shape_success.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="3dp"
android:color="@color/success" />
</shape>
</item>
</selector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/strikethrough_shape_warning.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="3dp"
android:color="@color/warning" />
</shape>
</item>
</selector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill"
android:text="sreangrathanak@yahoo.com"
android:text="admin@khmerlang.com"
android:drawablePadding="5dp"
android:textSize="12sp"
android:drawableLeft="@drawable/ic_baseline_email_24"
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,20 @@
<color name="coloDisable">#cccccc</color>
<color name="colorDisableAccent">#cccccc</color>

<color name="primary">#7e2cda</color>
<color name="suggestion">#7e2cda</color>
<color name="improvement">#7e2cda</color>
<color name="reforming">#7e2cda</color>
<color name="refactoring">#7e2cda</color>
<color name="secondary">#6c757d</color>
<color name="success">#198754</color>
<color name="error">#dc3545</color>
<color name="typo">#dc3545</color>
<color name="danger">#dc3545</color>
<color name="warning">#ff8f00</color>
<color name="recommend">#ff8f00</color>
<color name="grammar">#ff8f00</color>
<color name="info">#0dcaf0</color>

<!--Default colors-->
<!--Keyboard-->
Expand Down

0 comments on commit 4345755

Please sign in to comment.