Skip to content

Commit

Permalink
Add support to store history and favourite words. (#63)
Browse files Browse the repository at this point in the history
* Add support to store history and favourite words.

* Add support for deleting from history and favourite page.

* Remove copy in favour of favourite since Android only allows 3 actions. Update db download URL.
  • Loading branch information
tirkarthi committed Feb 17, 2024
1 parent 1d08591 commit d8ac11d
Show file tree
Hide file tree
Showing 17 changed files with 580 additions and 73 deletions.
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
applicationId "com.xtreak.notificationdictionary"
minSdk 24
targetSdk 33
versionCode 22
versionName "0.0.22"
versionCode 23
versionName "0.0.23"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -48,6 +48,9 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}

dependencies {
Expand All @@ -68,7 +71,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

def room_version = "2.3.0"
def room_version = "2.5.0"
apply plugin: 'kotlin-kapt'

implementation "androidx.room:room-runtime:$room_version"
Expand Down
32 changes: 24 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xtreak.notificationdictionary" >
package="com.xtreak.notificationdictionary">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Expand All @@ -11,7 +11,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NotificationDictionary" >
android:theme="@style/Theme.NotificationDictionary">

<meta-data
android:name="io.sentry.dsn"
Expand All @@ -22,42 +22,58 @@
android:exported="true"
android:label="@string/about"
android:parentActivityName=".MainActivity" />
<activity
android:name=".HistoryActivity"
android:exported="true"
android:label="@string/history"
android:parentActivityName=".MainActivity" />

<activity
android:name=".FavouriteActivity"
android:exported="true"
android:label="@string/favourite"
android:parentActivityName=".MainActivity"/>

<activity
android:name=".ProcessTextActivity"
android:exported="true"
android:label="@string/process_text_label"
android:parentActivityName=".MainActivity" >
android:parentActivityName=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>
</activity>

<activity
android:name=".ProcessViewActivity"
android:exported="true"
android:label="@string/process_text_label"
android:parentActivityName=".MainActivity" >
android:parentActivityName=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:exported="true" >
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand All @@ -66,4 +82,4 @@
android:theme="@style/Theme.MaterialComponents.NoActionBar" />
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2024, Karthikeyan Singaravelan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.xtreak.notificationdictionary

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.xtreak.notificationdictionary.adapters.HistoryAdapter
import java.util.concurrent.Executors

class FavouriteActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_favourite)

val executor = Executors.newSingleThreadExecutor()
val handler = Handler(Looper.getMainLooper())

val linearLayoutManager = LinearLayoutManager(this)
linearLayoutManager.orientation = LinearLayoutManager.VERTICAL

executor.execute {
val database = AppDatabase.getDatabase(this)
val historyDao = database.historyDao()
var entries = historyDao.getAllFavouriteEntriesWithMeaning()

handler.post {
val mRecyclerView = findViewById<RecyclerView>(R.id.favouriteRecyclerView)
val mListadapter = HistoryAdapter(entries as MutableList<HistoryDao.WordWithMeaning>, this, true)
mRecyclerView.adapter = mListadapter
mRecyclerView.layoutManager = linearLayoutManager
mListadapter.notifyItemRangeChanged(1, 100)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2024, Karthikeyan Singaravelan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.xtreak.notificationdictionary

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.xtreak.notificationdictionary.adapters.HistoryAdapter
import java.util.concurrent.Executors

class HistoryActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_history)

val executor = Executors.newSingleThreadExecutor()
val handler = Handler(Looper.getMainLooper())

val linearLayoutManager = LinearLayoutManager(this)
linearLayoutManager.orientation = LinearLayoutManager.VERTICAL

executor.execute {
val database = AppDatabase.getDatabase(this)
val historyDao = database.historyDao()
var entries = historyDao.getAllEntriesWithMeaning()

handler.post {
val mRecyclerView = findViewById<RecyclerView>(R.id.historyRecyclerView)
val mListadapter = HistoryAdapter(entries as MutableList<HistoryDao.WordWithMeaning>, this, false)
mRecyclerView.adapter = mListadapter
mRecyclerView.layoutManager = linearLayoutManager
mListadapter.notifyItemRangeChanged(1, 100)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.content.DialogInterface
import android.content.Intent
import android.content.res.Configuration
import android.os.*
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -144,26 +145,26 @@ class MainActivity : AppCompatActivity() {
Word(
1,
"",
"Read meanings aloud as you read",
"Store history and favourite words",
1,
1,
"""Enable Read switch at the right top to read aloud meaning of the word when the notification is created. There is also read button per notification to read meaning for each word."""
"""History of searches is stored. Words can also be starred from notification to be stored as favourite. History and Favourite are accessible from the menu at right top. In case of issues due to update please uninstall and try reinstalling the app since it needs database changes."""
),
Word(
1,
"",
"Copy and share",
"Read meanings aloud as you read",
1,
1,
"""Click on meaning to copy. Long press to share meaning with others. Notifications also have button for these actions."""
"""Enable Read switch at the right top to read aloud meaning of the word when the notification is created. There is also read button per notification to read meaning for each word."""
),
Word(
1,
"",
"Multilingual support",
"Copy and share",
1,
1,
"""Languages supported include French, German and Polish."""
"""Click on meaning to copy. Long press to share meaning with others. Notifications also have button for these actions."""
),
Word(
1,
Expand Down Expand Up @@ -409,6 +410,14 @@ class MainActivity : AppCompatActivity() {
.withLicenseShown(true)
.start(this)
}
R.id.history -> {
val history_activity = Intent(applicationContext, HistoryActivity::class.java)
startActivityForResult(history_activity, 0)
}
R.id.favourite -> {
val favourite_activity = Intent(applicationContext, FavouriteActivity::class.java)
startActivityForResult(favourite_activity, 0)
}
}
return true
}
Expand All @@ -429,7 +438,7 @@ class MainActivity : AppCompatActivity() {
// But we don't want the user to cancel this. It's one time and takes a couple of seconds

// TODO: Make this configurable based on environment?
val url = "https://xtreak.sfo3.cdn.digitaloceanspaces.com/dictionaries/$database_name.zip"
val url = "https://xtreak.sfo3.cdn.digitaloceanspaces.com/dictionaries/v2/$database_name.zip"
// val url = "http://192.168.0.105:8000/$database_name.zip" // for local mobile testing
// val url = "http://10.0.2.2:8000/$database_name.zip" // for local emulator testing

Expand Down Expand Up @@ -570,12 +579,17 @@ class MainActivity : AppCompatActivity() {
executor.execute {
val database = AppDatabase.getDatabase(this)
val dao = database.dictionaryDao()
val historyDao = database.historyDao()
var meanings: List<Word>

try {
meanings = dao.getAllMeaningsByWord(word)
if (meanings.isNotEmpty()) {
addHistoryEntry(historyDao, word)
}
} catch (e: Exception) {
Sentry.captureException(e)
Log.d("ndict:", e.toString())
meanings = listOf(
Word(
1, "", "Error", 1, 1,
Expand Down Expand Up @@ -606,6 +620,4 @@ class MainActivity : AppCompatActivity() {
}
}
}


}
Loading

0 comments on commit d8ac11d

Please sign in to comment.