Skip to content

Commit

Permalink
Polishing for beta release (#29)
Browse files Browse the repository at this point in the history
* removing default url from api & passing it in on create instead

* moving business logic from class to request json parameters where applicable

* updating tests to reflect API changes

* updating comment

* updating the build to spin and test against a local yfirlestur service

* adding an if check for logging to prepare for release

* adding missing name to build yaml

* Updating readme and images

* removing unused variables and tidying up

* renaming app from simacorrect to rettritun

* adding privacy notice dialog on app resume

* changing privacy notice text

* updating text values

* adding icon for app launcher
  • Loading branch information
Kristober committed Sep 7, 2022
1 parent f9da2eb commit a3887c5
Show file tree
Hide file tree
Showing 53 changed files with 170 additions and 313 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed .github/images/screenshot1.png
Binary file not shown.
Binary file removed .github/images/screenshot2.png
Binary file not shown.
36 changes: 28 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,28 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Checkout Yfirlestur Repo
uses: actions/checkout@v3
with:
repository: mideind/Yfirlestur
path: yfirlestur
ref: 8f66be976fb7f1486bd1824dde061d14d2f7ce5a
- name: Yfirlestur Dependency
run: |
if [ ! -f "./gunicorn_user.txt" ]; then
echo 'root' > yfirlestur/gunicorn_user.txt
echo 'root' >> yfirlestur/gunicorn_user.txt
fi
- uses: docker/build-push-action@v2
with:
context: ./yfirlestur/
tags: yfirlestur:latest
push: false
load: true
- name: Docker Run
run: |
docker run -dp 5002:5002 yfirlestur:latest
- name: Setup JDK
uses: actions/setup-java@v2
with:
Expand All @@ -21,14 +42,13 @@ jobs:
git submodule update --init
./gradlew assemble
./gradlew build -x test
- name: "Run tests"
run: |
./gradlew test
- name: Archive reports
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
path: |
app/build/reports/**/*
- name: Download reports
uses: actions/download-artifact@v3.0.0
uses: actions/upload-artifact@v2
with:
name: archive-reports
path: |
app/build/reports/**/*
app/build/reports/**/*
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
# Simacorrect
# Símacorrect - Réttritun fyrir Android

## Introduction

Simacorrect is a spell checker that provides spell and grammar correction for Icelandic on Android devices.
Réttritun is a spell checker that provides spell and grammar correction for Icelandic on Android devices.
Spell checking is made via API calls by utilizing the web service [Yfirlestur](https://github.com/mideind/), which wraps the spelling and grammar checking engine
[GreynirCorrect](https://github.com/mideind/GreynirCorrect)

Simacorrect is currently in closed beta but will be available on the Google Play Store in the near future.

Réttritun is available on the [Playstore]()

Note for Samsung users. The spell checker is not compatible with the default keyboard for Samsung devices [Samsung Keyboard](https://play.google.com/store/apps/details?id=com.samsung.emojikeyboard.themes&hl=is&gl=US). You can switch to using other keyboards that support 3rd party spell checkers, such as Google's keyboard [Gboard](https://play.google.com/store/apps/details?id=com.google.android.inputmethod.latin&hl=is&gl=US)

## Features
- #### Supports correction for grammatical errors for Android version 12.0 and higher (blue annotation)
- This covers grammar, compound, punctuation and phrasing errors as well as spelling suggestions.
- #### Correction for spelling errors (red annotation)
- This covers spelling, capitalization and abbreviation errors.

## Screenshots

[<img src=".github/images/screenshot1.png" align="left"
width="200"
hspace="10" vspace="10">](/readme/Wallabag%20Reading%20List.png)
## Screenshots

[<img src=".github/images/screenshot2.png" align="center"
width="200"
hspace="10" vspace="10">](/readme/Wallabag%20Reading%20List.png)
<p float="left">
<img src=".github/images/Google Pixel 4 XL Screenshot 0.png" width = 150/>
<img src=".github/images/Google Pixel 4 XL Screenshot 1.png" width = 150/>
<img src=".github/images/Google Pixel 4 XL Screenshot 2.png" width = 150/>
<img src=".github/images/Google Pixel 4 XL Screenshot 3.png" width = 150/>
<img src=".github/images/Google Pixel 4 XL Screenshot 4.png" width = 150/>
</p>


## Contributing
Expand Down
8 changes: 1 addition & 7 deletions api/src/main/java/org/grammatek/apis/CorrectApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ import org.grammatek.infrastructure.ResponseType
import org.grammatek.infrastructure.Success
import org.grammatek.infrastructure.toMultiValue

class CorrectApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
companion object {
@JvmStatic
val defaultBasePath: String by lazy {
System.getProperties().getProperty(ApiClient.baseUrlKey, "https://yfirlestur.is")
}
}
class CorrectApi(basePath: kotlin.String) : ApiClient(basePath) {

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ open class ApiClient(val baseUrl: String) {
var username: String? = null
var password: String? = null
var accessToken: String? = null
const val baseUrlKey = "org.grammatek.baseUrl"

@JvmStatic
val client: OkHttpClient by lazy {
Expand Down
Binary file added app/src/main/ic_launcher-playstore.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 2 additions & 10 deletions app/src/main/java/org/grammatek/simacorrect/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -17,7 +16,6 @@ import androidx.appcompat.app.AppCompatActivity

class AboutActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Log.d(TAG, "onCreate")
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
title = "About"
Expand Down Expand Up @@ -65,13 +63,11 @@ class AboutActivity : AppCompatActivity() {

private class SettingsArrayAdapter(
context: Context,
values: Array<String?>,
data: Array<String?>
private val values: Array<String?>,
private val data: Array<String?>
) :
ArrayAdapter<String?>(context, R.layout.activity_about, values) {
private val ctx: Context = context
private val values: Array<String?> = values
private val data: Array<String?> = data
override fun getViewTypeCount(): Int {
return 2
}
Expand All @@ -90,8 +86,4 @@ class AboutActivity : AppCompatActivity() {
return cView
}
}

companion object {
private val TAG = AboutActivity::class.java.simpleName
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/org/grammatek/simacorrect/App.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package org.grammatek.simacorrect

import android.app.Application
import android.util.Log
import android.content.Context
import org.grammatek.simacorrect.network.ConnectionManager

class App : Application() {
private lateinit var _connectionChecker: ConnectionManager

override fun onCreate() {
Log.v(TAG, "onCreate()")
super.onCreate()

appContext = applicationContext
_connectionChecker = ConnectionManager()
_connectionChecker.registerConnectionManager(this)
}

companion object {
private val TAG = App::class.java.simpleName

lateinit var appContext: Context
private set
}
}
7 changes: 0 additions & 7 deletions app/src/main/java/org/grammatek/simacorrect/EmailFeedback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

Expand All @@ -15,7 +14,6 @@ class EmailFeedback : AppCompatActivity() {
}

private fun sendEmail() {
Log.v(TAG, "Send email")
val recipientEmail = "info@grammatek.com"
val subject = getString(R.string.email_subject)
val msg = getString(R.string.email_message)
Expand All @@ -28,7 +26,6 @@ class EmailFeedback : AppCompatActivity() {
try {
startActivity(Intent.createChooser(emailIntent, sendMsg))
finish()
Log.i(TAG, "Finished sending email...")
} catch (ex: ActivityNotFoundException) {
Toast.makeText(
this@EmailFeedback,
Expand All @@ -37,8 +34,4 @@ class EmailFeedback : AppCompatActivity() {
).show()
}
}

companion object {
private val TAG = EmailFeedback::class.java.simpleName
}
}
36 changes: 36 additions & 0 deletions app/src/main/java/org/grammatek/simacorrect/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.grammatek.simacorrect

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.text.SpannableString
import android.text.util.Linkify
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit


class MainActivity : AppCompatActivity() {
private lateinit var etText: EditText
Expand Down Expand Up @@ -36,4 +42,34 @@ class MainActivity : AppCompatActivity() {
startActivity(intent)
}
}

override fun onResume() {
super.onResume()
val privacyAccepted = this.getPreferences(Context.MODE_PRIVATE).getBoolean("privacy_info_accepted", false)
if (!privacyAccepted) {
showPrivacyNoticeDialog()
}
}

/**
* Shows Réttritun privacy notice dialog
*/
private fun showPrivacyNoticeDialog() {
val privacyNotice = SpannableString(resources.getString(R.string.privacy_notice))
Linkify.addLinks(privacyNotice, Linkify.ALL)

val dialogBox: AlertDialog = AlertDialog.Builder(this)
.setTitle(R.string.privacy_title)
.setMessage(privacyNotice)
.setPositiveButton(R.string.ok) { _, _ ->
this.getPreferences(Context.MODE_PRIVATE).edit {
putBoolean("privacy_info_accepted", true)
apply()
}
}
.setCancelable(false)
.create()

dialogBox.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import android.util.Log
import org.grammatek.apis.CorrectApi
import org.grammatek.models.CorrectRequest
import org.grammatek.models.CorrectResponse
import org.grammatek.simacorrect.App
import org.grammatek.simacorrect.R
import java.io.IOException
import java.net.InetSocketAddress
import java.net.Socket
Expand All @@ -24,7 +26,7 @@ import java.util.concurrent.TimeUnit
class ConnectionManager {
private var _threadPoolExecutor: ScheduledThreadPoolExecutor? = null
private var _periodicFuture: ScheduledFuture<*>? = null
private val _apiServer: String = "yfirlestur.is"
private val _apiServer: String = App.appContext.resources.getString(R.string.grammatek_api_url)

/**
* Registers network callback to monitor network changes
Expand All @@ -43,11 +45,11 @@ class ConnectionManager {
override fun onAvailable(network: Network) {
val nc: NetworkCapabilities? = manager.getNetworkCapabilities(network)
if(nc != null && nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
Log.d(TAG, "Internet available")
if (LOG) Log.d(TAG, "Internet available")
g_isNetworkConnected = true
startApiServiceHealthCheck()
} else {
Log.d(TAG, "Internet unavailable")
if (LOG) Log.d(TAG, "Internet unavailable")
g_isNetworkConnected = false
stopApiServiceHealthCheck()
}
Expand Down Expand Up @@ -96,7 +98,7 @@ class ConnectionManager {
}
} catch (e: IOException) {
// Either we have a timeout, unreachable host or failed DNS lookup
Log.d(TAG, "IO Exception: ${e.message}")
if (LOG) Log.d(TAG, "IO Exception: ${e.message}")
return false
}
}
Expand All @@ -106,46 +108,49 @@ class ConnectionManager {
*/
private var periodicTask = Runnable {
try {
Log.d(TAG, "Is Reachable: $g_isServiceReachable, Is Connected: $g_isNetworkConnected")
if (LOG) Log.d(TAG, "Is Reachable: $g_isServiceReachable, Is Connected: $g_isNetworkConnected")

if (isHostAvailable(_apiServer, 443, 2000)) {
g_isServiceReachable = true
Log.d(TAG, "$_apiServer Service available!")
if (LOG) Log.d(TAG, "$_apiServer Service available!")
} else {
g_isServiceReachable = false
Log.d(TAG, "$_apiServer Service is NOT available !")
if (LOG) Log.d(TAG, "$_apiServer Service is NOT available !")
}
} catch (e: Exception) {
Log.w(TAG, "Exception: " + e.message)
if (LOG) Log.w(TAG, "Exception: " + e.message)
}
}

companion object {
private const val LOG = false
private val TAG = ConnectionManager::class.java.simpleName
private val API: CorrectApi = CorrectApi()
private val API: CorrectApi = CorrectApi(
"https://${App.appContext.resources.getString(R.string.grammatek_api_url)}"
)

var g_isNetworkConnected: Boolean = false
private set
var g_isServiceReachable: Boolean = false
private set

/**
* Returns the corrected spelling for [textToCorrect] if successful.
* Returns the corrected spelling for text in [request] if successful.
* Returns null if there is no correction to be made OR no connection.
*
* @param [textToCorrect] The text to be spell checked (corrected).
* @param [request] The request to be spell checked (corrected).
* @return YfirlesturResponse which contains the spell checking
* information of [textToCorrect].
* information of [request].
*/
fun correctSentence(request: CorrectRequest): CorrectResponse? {
if(!g_isServiceReachable || !g_isNetworkConnected) {
Log.d(TAG, "correctSentence: isServiceReachable: $g_isServiceReachable, isNetworkConnected: $g_isNetworkConnected")
if (LOG) Log.d(TAG, "correctSentence: isServiceReachable: $g_isServiceReachable, isNetworkConnected: $g_isNetworkConnected")
return null
}
try {
return API.correctApiPost(request)
} catch (e: Exception) {
Log.d(TAG, "Exception: $e")
if (LOG) Log.d(TAG, "Exception: $e")
}
return null
}
Expand Down

0 comments on commit a3887c5

Please sign in to comment.