Skip to content

Commit

Permalink
add search feature to reader viewmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
kazemcodes committed Apr 7, 2022
1 parent d5d03fb commit 87a095f
Show file tree
Hide file tree
Showing 22 changed files with 604 additions and 186 deletions.
13 changes: 12 additions & 1 deletion .idea/deploymentTargetDropDown.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.core.app.NotificationManagerCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -32,5 +33,10 @@ class MainActivity : ComponentActivity() {

}

override fun onDestroy() {
NotificationManagerCompat.from(this).cancelAll()
super.onDestroy()
}

}

10 changes: 10 additions & 0 deletions core-ui/src/main/java/org/ireader/core_ui/theme/AppPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ class AppPreferences @Inject constructor(
const val AUTO_SCROLL_MODE_OFFSET = "auto_scroll_mode_offset"
const val SCROLL_INDICATOR_PADDING = "scroll_indicator_padding"
const val SCROLL_INDICATOR_WIDTH = "scroll_indicator_width"
const val SELECTABLE_TEXT = "selectable_text"


const val TEXT_READER_SPEECH_RATE = "text_reader_speech_rate"
const val TEXT_READER_SPEECH_PITCH = "text_reader_speech_pitch"
const val TEXT_READER_SPEECH_LANGUAGE = "text_reader_speech_language"
const val TEXT_READER_SPEECH_VOICE = "text_reader_speech_voice"
const val TEXT_READER_AUTO_NEXT = "text_reader_auto_next"

/** Services **/
const val Last_UPDATE_CHECK = "last_update_check"
Expand Down Expand Up @@ -108,6 +110,10 @@ class AppPreferences @Inject constructor(
return preferenceStore.getBoolean(SCROLL_MODE, true)
}

fun selectableText(): Preference<Boolean> {
return preferenceStore.getBoolean(SELECTABLE_TEXT, true)
}

fun autoScrollInterval(): Preference<Long> {
return preferenceStore.getLong(AUTO_SCROLL_MODE_INTERVAL, 5000L)
}
Expand Down Expand Up @@ -136,6 +142,10 @@ class AppPreferences @Inject constructor(
return preferenceStore.getFloat(TEXT_READER_SPEECH_RATE, .8f)
}

fun readerAutoNext(): Preference<Boolean> {
return preferenceStore.getBoolean(TEXT_READER_AUTO_NEXT, false)
}

fun speechPitch(): Preference<Float> {
return preferenceStore.getFloat(TEXT_READER_SPEECH_PITCH, .8f)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.media.MediaMetadata
import android.media.session.PlaybackState
import android.os.Build
import android.support.v4.media.MediaMetadataCompat
import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.net.toUri
Expand Down Expand Up @@ -176,19 +176,19 @@ class DefaultNotificationHelper @Inject constructor(
setMetadata(MediaMetadataCompat.Builder().apply {
putText(MediaMetadata.METADATA_KEY_TITLE, chapter.title)
}.build())
val actions =
PlaybackState.ACTION_PLAY_PAUSE or PlaybackState.ACTION_STOP or PlaybackState.ACTION_SKIP_TO_NEXT or PlaybackState.ACTION_SKIP_TO_PREVIOUS
setPlaybackState(PlaybackStateCompat.Builder().apply {
setActions(PlaybackStateCompat.ACTION_PLAY or PlaybackStateCompat.ACTION_STOP or PlaybackStateCompat.ACTION_SKIP_TO_NEXT or PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)

}.build())
}
return NotificationCompat.Builder(applicationContext,
Notifications.CHANNEL_TEXT_READER_PROGRESS).apply {
setContentTitle(chapter.title)
setContentText("${progress}/${chapter.content.size}")
setSmallIcon(org.ireader.core.R.drawable.ic_infinity)
setOnlyAlertOnce(true)
// setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
setLargeIcon(applicationContext, book.cover)
//setShowWhen(false)
priority = NotificationCompat.PRIORITY_LOW

addAction(R.drawable.ic_baseline_skip_previous,
Expand All @@ -213,7 +213,6 @@ class DefaultNotificationHelper @Inject constructor(
.setShowActionsInCompactView(1, 2, 3)
)
setSubText(book.title)
color = applicationContext.resources.getColor(R.color.blue_200)

//setColorized(true)
//setAutoCancel(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.core.app.NotificationCompat
import androidx.core.graphics.drawable.toBitmap
import coil.ImageLoader
import coil.request.ImageRequest
import coil.transform.CircleCropTransformation

data class Channel(
val name: String,
Expand Down Expand Up @@ -41,10 +40,9 @@ fun createChannel(context: Context, channel: Channel) {
if (data != null) {
val request = ImageRequest.Builder(context)
.data(data)
.transformations(CircleCropTransformation())
.allowHardware(true)
.target { setLargeIcon(it.toBitmap()) }
.size(200)
.size(512)
.build()
ImageLoader(context).execute(request)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,12 @@ class TextReaderPrefUseCase @Inject constructor(
return appPreferences.speechVoice().get()
}

fun saveAutoNext(value: Boolean) {
appPreferences.readerAutoNext().set(value)
}

fun readAutoNext(): Boolean {
return appPreferences.readerAutoNext().get()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@ import javax.inject.Inject
class SelectedFontStateUseCase @Inject constructor(
private val appPreferences: AppPreferences,
) {
fun save(fontIndex: Int) {
fun saveFont(fontIndex: Int) {
appPreferences.font().set(fontIndex)
}

/**
* fontIndex is the index of font which is in fonts list inside the Type package
*/
fun read(): FontType {
fun readFont(): FontType {
val fontType = appPreferences.font().get()
return fonts[fontType]
}

fun saveSelectableText(value: Boolean) {
appPreferences.selectableText().set(value)
}

fun readSelectableText(): Boolean {
return appPreferences.selectableText().get()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -63,13 +62,13 @@ fun ReadingScreen(
val context = LocalContext.current


DisposableEffect(key1 = true) {
onDispose {
vm.uiFunc.apply {
vm.restoreSetting(context, scrollState)
}
}
}
// DisposableEffect(key1 = true) {
// onDispose {
// vm.uiFunc.apply {
// vm.restoreSetting(context, scrollState)
// }
// }
// }
LaunchedEffect(key1 = scaffoldState.drawerState.targetValue) {
if (chapter != null && scaffoldState.drawerState.targetValue == DrawerValue.Open && vm.stateChapters.isNotEmpty()) {
vm.uiFunc.apply {
Expand Down Expand Up @@ -195,6 +194,15 @@ fun ReadingScreen(
vm.showSnackBar(UiText.ExceptionString(e))
}
}
},
vm = vm,
state = vm,
scrollState = scrollState,
onBookMark = {
vm.uiFunc.apply {
vm.bookmarkChapter()

}
}
)
},
Expand Down
Loading

0 comments on commit 87a095f

Please sign in to comment.