|
|
@ -2,21 +2,28 @@ package io.legado.app.ui.rss.read |
|
|
|
|
|
|
|
|
|
|
|
import android.app.Application |
|
|
|
import android.app.Application |
|
|
|
import android.content.Intent |
|
|
|
import android.content.Intent |
|
|
|
|
|
|
|
import android.speech.tts.TextToSpeech |
|
|
|
|
|
|
|
import android.speech.tts.UtteranceProgressListener |
|
|
|
import androidx.lifecycle.MutableLiveData |
|
|
|
import androidx.lifecycle.MutableLiveData |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.data.entities.RssArticle |
|
|
|
import io.legado.app.data.entities.RssArticle |
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.model.Rss |
|
|
|
import io.legado.app.model.Rss |
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
class ReadRssViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class ReadRssViewModel(application: Application) : BaseViewModel(application), |
|
|
|
|
|
|
|
TextToSpeech.OnInitListener { |
|
|
|
var callBack: CallBack? = null |
|
|
|
var callBack: CallBack? = null |
|
|
|
var rssSource: RssSource? = null |
|
|
|
var rssSource: RssSource? = null |
|
|
|
var rssArticle: RssArticle? = null |
|
|
|
var rssArticle: RssArticle? = null |
|
|
|
val contentLiveData = MutableLiveData<String>() |
|
|
|
val contentLiveData = MutableLiveData<String>() |
|
|
|
val urlLiveData = MutableLiveData<AnalyzeUrl>() |
|
|
|
val urlLiveData = MutableLiveData<AnalyzeUrl>() |
|
|
|
var star = false |
|
|
|
var star = false |
|
|
|
|
|
|
|
var textToSpeech: TextToSpeech = TextToSpeech(context, this) |
|
|
|
|
|
|
|
|
|
|
|
fun initData(intent: Intent) { |
|
|
|
fun initData(intent: Intent) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
@ -91,6 +98,50 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onInit(status: Int) { |
|
|
|
|
|
|
|
launch { |
|
|
|
|
|
|
|
if (status == TextToSpeech.SUCCESS) { |
|
|
|
|
|
|
|
textToSpeech.language = Locale.CHINA |
|
|
|
|
|
|
|
textToSpeech.setOnUtteranceProgressListener(TTSUtteranceListener()) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
toast(R.string.tts_init_failed) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun readAloud(text: String) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCleared() { |
|
|
|
|
|
|
|
super.onCleared() |
|
|
|
|
|
|
|
textToSpeech.stop() |
|
|
|
|
|
|
|
textToSpeech.shutdown() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 朗读监听 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private inner class TTSUtteranceListener : UtteranceProgressListener() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onStart(s: String) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDone(s: String) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) { |
|
|
|
|
|
|
|
super.onRangeStart(utteranceId, start, end, frame) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onError(s: String) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
fun upStarMenu() |
|
|
|
fun upStarMenu() |
|
|
|
} |
|
|
|
} |
|
|
|