Skip to content

Commit

Permalink
fix: ic launcher for release
Browse files Browse the repository at this point in the history
  • Loading branch information
kamui-fin committed Oct 21, 2023
1 parent 4b900de commit 2aa44a4
Show file tree
Hide file tree
Showing 55 changed files with 269 additions and 162 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Rin

Rin is a minimal and lightning fast Japanese popup dictionary app for Android, inspired from Apple's highlight and lookup [feature](https://www.macrumors.com/how-to/look-up-word-definitions-ios-11/).
The installable APK can be found in the latest [releases](https://github.com/kamui-fin/rin/releases/latest).
Rin is a minimal and lightning fast Japanese popup dictionary app for Android, inspired from Apple's
highlight and lookup [feature](https://www.macrumors.com/how-to/look-up-word-definitions-ios-11/).
The installable APK can be found in the
latest [releases](https://github.com/kamui-fin/rin/releases/latest).

Features include:

Expand All @@ -10,8 +12,8 @@ Features include:
- Automatic word de-inflection
- Recursive lookups within definitions
- Importing Yomichan dictionaries
- Frequency and pitch accent dictionaries supported
- Set dictionary priorities for search result ordering
- Frequency and pitch accent dictionaries supported
- Set dictionary priorities for search result ordering
- Save words into a list
- View word tags

Expand Down
4 changes: 0 additions & 4 deletions app/src/debug/res/values/ic_launcher_background.xml

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/java/com/kamui/rin/CopyToClipboardReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent

class CopyToClipboardReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action == "COPY_TO_CLIPBOARD") {
Expand Down
45 changes: 42 additions & 3 deletions app/src/main/java/com/kamui/rin/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.kamui.rin

import android.app.AlertDialog
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.MenuItem
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.*
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import com.kamui.rin.databinding.ActivityMainBinding
import com.kamui.rin.ui.setupTheme
Expand All @@ -17,20 +21,42 @@ class MainActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding

private val requestPermissionLauncher =
registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (!isGranted) {
val builder = AlertDialog.Builder(applicationContext)
builder.setTitle("Rin Notifications")
builder.setMessage("Rin optionally uses notifications to display dictionary management progress")
builder.setPositiveButton("OK") { dialog, _ ->
dialog.dismiss()
}
val alertDialog: AlertDialog = builder.create()
alertDialog.show()
}
}


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)

val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
binding.bottomNavigation.setupWithNavController(navController)

setupTheme(Settings(PreferenceManager.getDefaultSharedPreferences(applicationContext)).darkTheme())

appBarConfiguration = AppBarConfiguration(navController.graph)
configureActionBar(navController)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getNotificationPermission()
}
}

private fun configureActionBar(navController: NavController) {
Expand All @@ -51,4 +77,17 @@ class MainActivity : AppCompatActivity() {
}
return true
}

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private fun getNotificationPermission() {
if (ContextCompat.checkSelfPermission(
this, android.Manifest.permission.POST_NOTIFICATIONS
) != PackageManager.PERMISSION_GRANTED
) {
shouldShowRequestPermissionRationale(android.Manifest.permission.POST_NOTIFICATIONS)
requestPermissionLauncher.launch(
android.Manifest.permission.POST_NOTIFICATIONS
)
}
}
}
5 changes: 4 additions & 1 deletion app/src/main/java/com/kamui/rin/adapter/DictEntryAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import com.kamui.rin.db.model.DictEntry
import com.kamui.rin.db.model.Dictionary
import com.kamui.rin.ui.fragment.LookupFragmentDirections

class DictEntryAdapter(private val context: Context, private val entries: List<Pair<DictEntry, Dictionary>>) :
class DictEntryAdapter(
private val context: Context,
private val entries: List<Pair<DictEntry, Dictionary>>
) :
RecyclerView.Adapter<DictEntryAdapter.ViewHolder>() {
private var lastPosition = -1

Expand Down
21 changes: 18 additions & 3 deletions app/src/main/java/com/kamui/rin/db/AppDatabase.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package com.kamui.rin.db

import android.content.Context
import androidx.room.*
import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.DeleteColumn
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.AutoMigrationSpec
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.kamui.rin.db.dao.*
import com.kamui.rin.db.model.*
import com.kamui.rin.db.dao.DictEntryDao
import com.kamui.rin.db.dao.DictionaryDao
import com.kamui.rin.db.dao.FrequencyDao
import com.kamui.rin.db.dao.PitchAccentDao
import com.kamui.rin.db.dao.SavedWordDao
import com.kamui.rin.db.dao.TagDao
import com.kamui.rin.db.model.DictEntry
import com.kamui.rin.db.model.DictEntryTagCrossRef
import com.kamui.rin.db.model.Dictionary
import com.kamui.rin.db.model.Frequency
import com.kamui.rin.db.model.PitchAccent
import com.kamui.rin.db.model.SavedWord
import com.kamui.rin.db.model.Tag

@DeleteColumn(tableName = "DictEntry", columnName = "pitchAccent")
@DeleteColumn(tableName = "DictEntry", columnName = "freq")
Expand Down
24 changes: 15 additions & 9 deletions app/src/main/java/com/kamui/rin/db/dao/DictEntryDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,32 @@ interface DictEntryDao {
): DictEntry

@Transaction
@Query("SELECT * FROM DictEntry " +
"JOIN Dictionary ON Dictionary.dictId = DictEntry.dictionaryId " +
"WHERE kanji = :query AND Dictionary.dictId NOT IN (:disabled)")
@Query(
"SELECT * FROM DictEntry " +
"JOIN Dictionary ON Dictionary.dictId = DictEntry.dictionaryId " +
"WHERE kanji = :query AND Dictionary.dictId NOT IN (:disabled)"
)
fun searchEntryByKanji(
query: String,
disabled: List<Long?>
): Map<DictEntry, Dictionary>

@Transaction
@Query("SELECT * FROM DictEntry " +
"JOIN Dictionary ON Dictionary.dictId = DictEntry.dictionaryId " +
"WHERE reading = :query AND Dictionary.dictId NOT IN (:disabled)")
@Query(
"SELECT * FROM DictEntry " +
"JOIN Dictionary ON Dictionary.dictId = DictEntry.dictionaryId " +
"WHERE reading = :query AND Dictionary.dictId NOT IN (:disabled)"
)
fun searchEntryByReading(
query: String,
disabled: List<Long>
): Map<DictEntry, Dictionary>

@Query("SELECT Tag.* from DictEntryTagCrossRef " +
"JOIN Tag ON Tag.tagId = DictEntryTagCrossRef.tagId " +
"WHERE DictEntryTagCrossRef.entryId = :entryId")
@Query(
"SELECT Tag.* from DictEntryTagCrossRef " +
"JOIN Tag ON Tag.tagId = DictEntryTagCrossRef.tagId " +
"WHERE DictEntryTagCrossRef.entryId = :entryId"
)
fun getTagsForEntry(entryId: Long): List<Tag>

@Insert
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/kamui/rin/db/dao/FrequencyDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package com.kamui.rin.db.dao
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Transaction
import com.kamui.rin.db.model.Frequency
import com.kamui.rin.db.model.Tag

@Dao
interface FrequencyDao {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/kamui/rin/db/model/DictEntry.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.kamui.rin.db.model

import androidx.room.*
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey

@Entity(
foreignKeys = [
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/kamui/rin/db/model/SavedWord.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kamui.rin.db.model

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/kamui/rin/dict/Japanese.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.kamui.rin.dict

fun toHiragana(c: Char): Char {
if (isFullWidthKatakana(c)) {
return (c.toInt() - 0x60).toChar()
return (c.code - 0x60).toChar()
} else if (isHalfWidthKatakana(c)) {
return (c.toInt() - 0xcf25).toChar()
return (c.code - 0xcf25).toChar()
}
return c
}
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/kamui/rin/dict/Lookup.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.kamui.rin.dict

import android.content.Context
import com.kamui.rin.Settings
import com.kamui.rin.db.AppDatabase
import com.kamui.rin.db.dao.DictEntryDao
import com.kamui.rin.db.model.DictEntry
import com.kamui.rin.Settings
import com.kamui.rin.db.model.Dictionary
import java.util.*
import kotlin.collections.ArrayList

class Lookup(
context: Context,
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/kamui/rin/dict/YomichanDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package com.kamui.rin.dict

import com.kamui.rin.db.model.Frequency
import com.kamui.rin.db.model.Tag
import kotlinx.serialization.json.*
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.intOrNull
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.long

val format = Json { ignoreUnknownKeys = true }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat.getSystemService
import androidx.work.CoroutineWorker
import androidx.work.ForegroundInfo
import androidx.work.WorkerParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.kamui.rin.dict.worker

import android.content.Context
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import com.kamui.rin.db.AppDatabase
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class DeleteDictionaryWorker(context: Context, parameters: WorkerParameters) : BaseDictionaryWorker(context, parameters) {
class DeleteDictionaryWorker(context: Context, parameters: WorkerParameters) :
BaseDictionaryWorker(context, parameters) {
override suspend fun doWork(): Result {
return withContext(Dispatchers.IO) {
return@withContext try {
Expand All @@ -28,5 +28,6 @@ class DeleteDictionaryWorker(context: Context, parameters: WorkerParameters) : B
AppDatabase.buildDatabase(applicationContext).dictionaryDao().deleteDictionary(dictId)
}

override fun getNotificationId(): Int { return 0; }
override fun getNotificationId(): Int {
return 0; }
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.kamui.rin.dict.worker

import android.content.Context
import android.net.Uri
import android.util.Log
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import com.kamui.rin.db.AppDatabase
import com.kamui.rin.db.model.DictEntry
import com.kamui.rin.db.model.Dictionary
import com.kamui.rin.dict.YomichanMeta
import com.kamui.rin.dict.decodeDictionaryEntries
import com.kamui.rin.dict.decodeTags
import com.kamui.rin.dict.format
import kotlinx.serialization.decodeFromString
import java.io.FileNotFoundException
import android.content.Context
import android.util.Log
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import com.kamui.rin.db.AppDatabase
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString
import java.io.FileNotFoundException

class ImportDictionaryWorker(context: Context, parameters: WorkerParameters) :
BaseDictionaryWorker(context, parameters) {
Expand Down Expand Up @@ -92,5 +92,6 @@ class ImportDictionaryWorker(context: Context, parameters: WorkerParameters) :
}
}

override fun getNotificationId(): Int { return 1; }
override fun getNotificationId(): Int {
return 1; }
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
package com.kamui.rin.dict.worker

import android.net.Uri
import com.kamui.rin.db.model.DictEntry
import com.kamui.rin.db.model.Dictionary
import com.kamui.rin.dict.YomichanMeta
import com.kamui.rin.dict.decodeDictionaryEntries
import com.kamui.rin.dict.decodeTags
import com.kamui.rin.dict.format
import kotlinx.serialization.decodeFromString
import java.io.FileNotFoundException
import android.content.Context
import android.util.Log
import android.net.Uri
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import com.kamui.rin.db.AppDatabase
import com.kamui.rin.dict.decodeFrequencyEntries
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.FileNotFoundException

class ImportFrequencyWorker(context: Context, parameters: WorkerParameters) :
BaseDictionaryWorker(context, parameters) {
Expand Down Expand Up @@ -58,5 +49,6 @@ class ImportFrequencyWorker(context: Context, parameters: WorkerParameters) :
}
}

override fun getNotificationId(): Int { return 2; }
override fun getNotificationId(): Int {
return 2; }
}
Loading

0 comments on commit 2aa44a4

Please sign in to comment.