Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View fevziomurtekin's full-sized avatar
:octocat:

Fevzi Ömür Tekin fevziomurtekin

:octocat:
View GitHub Profile
@fevziomurtekin
fevziomurtekin / FragmentModule.kt
Created May 19, 2019 22:56
FragmentModule.kt
@Module
abstract class FragmentModule {
@ContributesAndroidInjector
abstract fun contributeNewsFragment(): NewsFragment
@ContributesAndroidInjector
abstract fun contributeNewDetailsFragment(): NewDetailsFragment
}
@fevziomurtekin
fevziomurtekin / ViewModelModule.kt
Created May 19, 2019 22:54
ViewModelModule.kt
@Module
abstract class ViewModelModule {
@Binds
abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory
@Binds
@IntoMap
@ViewModelKey(MainViewModel::class)
abstract fun bindMainViewModel(mainViewModel: MainViewModel): ViewModel
@fevziomurtekin
fevziomurtekin / BaseApplication.kt
Created May 19, 2019 22:48
BaseApplication.kt
package com.fevziomurtekin.hackernewsapp
import android.app.Application
import com.fevziomurtekin.di.onlineNewsApp
import org.koin.android.ext.android.startKoin
class BaseApplication : Application(){
override fun onCreate() {
super.onCreate()
package com.fevziomurtekin.di
import com.fevziomurtekin.hackernewsapp.data.network.RetroInterface
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.dsl.module.applicationContext
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when(requestCode){
SPEECH_INPUT->{
if(resultCode== Activity.RESULT_OK
&& data !=null){
val result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
edittext.text=Editable.Factory.getInstance().newEditable(result[0])
sendMessage(send)
}
private fun appendText(message: String, type: Int) {
val layout: FrameLayout
when (type) {
USER -> layout = appendUserText()
BOT -> layout = appendBotText()
else -> layout = appendBotText()
}
layout.isFocusableInTouchMode = true
linear_chat.addView(layout)
val tv = layout.findViewById<TextView>(R.id.chatMsg)
fun onResult(response: DetectIntentResponse?) {
try {
if (response != null) {
var botReply:String=""
if(response.queryResult.fulfillmentText==" ")
botReply= response.queryResult.fulfillmentMessagesList[0].text.textList[0].toString()
else
botReply= response.queryResult.fulfillmentText
appendText(botReply, BOT)
private fun initAsisstantVoice() {
asistan_voice= TextToSpeech(applicationContext,object : TextToSpeech.OnInitListener {
override fun onInit(status: Int) {
if (status!=TextToSpeech.ERROR){
asistan_voice?.language=Locale("tr")
}
}
})
private fun sendMicrophoneMessage(view:View){
val intent: Intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
intent.putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
)
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault())
intent.putExtra(
RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt)
class RequestTask : AsyncTask<Void, Void, DetectIntentResponse> {
var activity: Activity? = null
private var session: SessionName? = null
private var sessionsClient: SessionsClient? = null
private var queryInput: QueryInput? = null
constructor(activity: Activity,session:SessionName,sessionsClient: SessionsClient,queryInput: QueryInput){
this.activity=activity