Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add haptic feedback when swiping between verses #34

Merged
merged 3 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
.externalNativeBuild
.cxx
local.properties

hs_err_pid*.log
replay_pid*.log
26 changes: 26 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 26 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
alias(libs.plugins.com.android.application)
alias(libs.plugins.org.jetbrains.kotlin.android)
}

android {
namespace 'com.wirelessalien.android.bhagavadgita'
compileSdk 33
compileSdk 35

defaultConfig {
applicationId "com.wirelessalien.android.bhagavadgita"
minSdk 23
targetSdk 33
targetSdk 35
versionCode 8
versionName "3.3"

Expand All @@ -23,8 +23,9 @@ android {
versionNameSuffix 'Debug'
}
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug //don't forget to comment this line out when generating signed app apk/bundle
}
}
compileOptions {
Expand All @@ -37,25 +38,30 @@ android {
viewBinding {
enabled = true
}
buildFeatures{
buildConfig = true
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.cardview:cardview:1.0.0"
implementation 'com.google.code.gson:gson:2.10.1'
implementation "androidx.recyclerview:recyclerview:1.3.1"
implementation "androidx.viewpager2:viewpager2:1.1.0-beta02"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.0"
implementation libs.androidx.core.ktx
implementation libs.androidx.appcompat
implementation libs.material
implementation libs.androidx.constraintlayout
implementation libs.androidx.cardview
implementation libs.gson
implementation libs.androidx.recyclerview
implementation libs.androidx.viewpager2
implementation libs.kotlinx.coroutines.android
implementation libs.androidx.lifecycle.runtime.ktx
implementation libs.androidx.lifecycle.viewmodel.ktx
implementation libs.androidx.lifecycle.livedata.ktx

implementation libs.kotlin.reflect


testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
testImplementation libs.junit
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core
}
41 changes: 40 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,43 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

# Keep all classes in Gson
-keep class com.google.gson.** { *; }

# Keep Gson internal serialization classes
-keep class sun.misc.** { *; }
-keep class com.google.gson.stream.** { *; }

# GSON
-keepattributes Signature
-keep class com.google.gson.reflect.TypeToken { *; }
-keep class * extends com.google.gson.reflect.TypeToken

# Coroutines
-keepattributes Signature
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

# Preserve models
#-keep class com.wirelessalien.android.bhagavadgita.data.**
#-keepclassmembers class com.wirelessalien.android.bhagavadgita.data.** {
# !transient <fields>;
#}
-keep class com.wirelessalien.android.bhagavadgita.data.** {
!transient <fields>;
}

# Preserve Serializable Classes
-keepclassmembers,allowobfuscation,allowshrinking class * {
@com.google.gson.annotations.SerializedName <fields>;
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object readResolve();
java.lang.Object writeReplace();
}

Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@

package com.wirelessalien.android.bhagavadgita

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package com.wirelessalien.android.bhagavadgita.activity
import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.wirelessalien.android.bhagavadgita.R
import com.wirelessalien.android.bhagavadgita.databinding.ActivityAboutGitaBinding
import com.wirelessalien.android.bhagavadgita.utils.Themes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ import android.text.Spannable
import android.text.SpannableString
import android.text.style.BackgroundColorSpan
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.wirelessalien.android.bhagavadgita.adapter.AllVerseAdapter
import com.wirelessalien.android.bhagavadgita.data.Commentary
import com.wirelessalien.android.bhagavadgita.data.Translation
import com.wirelessalien.android.bhagavadgita.data.Verse
import com.wirelessalien.android.bhagavadgita.databinding.AllVerseActivityBinding
import com.wirelessalien.android.bhagavadgita.utils.NullableTypAdapterFactory
import com.wirelessalien.android.bhagavadgita.utils.Themes
import kotlinx.coroutines.*
import java.io.IOException
import kotlin.reflect.typeOf

class AllVerseActivity : AppCompatActivity() {

Expand Down Expand Up @@ -80,7 +84,8 @@ class AllVerseActivity : AppCompatActivity() {
// Set the chapter details in the UI
binding.verseRecyclerView.layoutManager = LinearLayoutManager(this@AllVerseActivity)
binding.verseRecyclerView.adapter = AllVerseAdapter(verseList, currentTextSize)
binding.progressBar.visibility = View.GONE // Hide the ProgressBar once the verses are loaded
binding.progressBar.visibility =
View.GONE // Hide the ProgressBar once the verses are loaded
}
}
}
Expand Down Expand Up @@ -131,7 +136,7 @@ class AllVerseActivity : AppCompatActivity() {

val matchedContexts = mutableListOf<String>()

// Add matched contexts for verse titles
// Add matched contexts for verse titles
verseSearchResult.forEach { verse ->
if (verse.title.contains(newText!!, ignoreCase = true)) {
matchedContexts.add("Match found in verse title: ${verse.title}")
Expand Down Expand Up @@ -188,15 +193,17 @@ class AllVerseActivity : AppCompatActivity() {

val matchedText = if (!newText.isNullOrBlank()) newText else null

val filteredList = if (verseSearchResult.isNotEmpty() || translationSearchResult.isNotEmpty() || commentarySearchResult.isNotEmpty()) {
// Combine the results and get unique verse_ids
val verseIds = (verseSearchResult.map { it.verse_id } + translationSearchResult.map { it.verse_id } + commentarySearchResult.map { it.verse_id }).toSet()
val filteredList =
if (verseSearchResult.isNotEmpty() || translationSearchResult.isNotEmpty() || commentarySearchResult.isNotEmpty()) {
// Combine the results and get unique verse_ids
val verseIds =
(verseSearchResult.map { it.verse_id } + translationSearchResult.map { it.verse_id } + commentarySearchResult.map { it.verse_id }).toSet()

// Filter the original verseList based on the verse_ids
verseList.filter { it.verse_id in verseIds }
} else {
emptyList()
}
// Filter the original verseList based on the verse_ids
verseList.filter { it.verse_id in verseIds }
} else {
emptyList()
}

val highlightedMatchedContexts = matchedContexts.map { context ->
val spannableString = SpannableString(context)
Expand All @@ -214,12 +221,22 @@ class AllVerseActivity : AppCompatActivity() {

// Update UI on the main thread
withContext(Dispatchers.Main) {
updateAdapterTextSize(currentTextSize, filteredList, matchedText, highlightedMatchedContexts)
updateAdapterTextSize(
currentTextSize,
filteredList,
matchedText,
highlightedMatchedContexts
)
}
}
}

private fun updateAdapterTextSize(newSize: Int, filteredList: List<Verse>, matchedText: String?, matchedContexts: List<SpannableString>) {
private fun updateAdapterTextSize(
newSize: Int,
filteredList: List<Verse>,
matchedText: String?,
matchedContexts: List<SpannableString>
) {
val recyclerViewC = binding.verseRecyclerView
val adapterC = recyclerViewC.adapter as? AllVerseAdapter
adapterC?.updateTextSize(newSize, filteredList, matchedText, matchedContexts)
Expand All @@ -241,10 +258,11 @@ class AllVerseActivity : AppCompatActivity() {
val commentaries = Gson().fromJson<List<Commentary>>(jsonString, commentaryListType)

// Convert the list of commentaries into a map for easy access
return commentaries.associateBy { it.id}
return commentaries.associateBy { it.id }
}

private fun loadJsonFromAsset(fileName: String): String? {

return try {
applicationContext.assets.open(fileName).bufferedReader().use {
it.readText()
Expand All @@ -258,7 +276,6 @@ class AllVerseActivity : AppCompatActivity() {
private fun loadAllVerses(): List<Verse> {
val jsonString = loadJsonFromAsset("verse.json")
val verseListType = object : TypeToken<List<Verse>>() {}.type

return Gson().fromJson(jsonString, verseListType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.IOException
import java.util.Locale

class ChapterDetailsActivity : AppCompatActivity() {

Expand Down Expand Up @@ -136,7 +137,7 @@ class ChapterDetailsActivity : AppCompatActivity() {
val progress = (readVerses.toDouble() / versesCount.toDouble()) * 100

binding.progressBarReadCount.progress = progress.toInt()
binding.progressTextView.text = String.format("%.2f%%", progress)
binding.progressTextView.text = String.format(Locale.getDefault(),"%.2f%%", progress)
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@

package com.wirelessalien.android.bhagavadgita.activity

import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.wirelessalien.android.bhagavadgita.R
import com.wirelessalien.android.bhagavadgita.databinding.ActivityHanumanChalisaBinding
import com.wirelessalien.android.bhagavadgita.fragment.HanumanChalisaE
import com.wirelessalien.android.bhagavadgita.fragment.HanumanChalisaH
Expand Down
Loading