Skip to content

Instantly share code, notes, and snippets.

View cengiztoru's full-sized avatar
💻

Cengiz TORU cengiztoru

💻
View GitHub Profile
@cengiztoru
cengiztoru / GetVisibleItemsInUi.kt
Created May 14, 2024 11:40
Get Visible Items in UI RecyclerView, ListAdapter
fun <Model, VH : RecyclerView.ViewHolder> ListAdapter<Model, VH>.getVisibleItemsInUi(
layoutManager: RecyclerView.LayoutManager
): List<Model>? {
if (layoutManager is LinearLayoutManager) {
val firstViewPosition = layoutManager.findFirstVisibleItemPosition()
val lastViewPosition = layoutManager.findLastVisibleItemPosition()
return currentList.slice(firstViewPosition..lastViewPosition)
}
return null
}
@cengiztoru
cengiztoru / EmptyInterceptor.kt
Created May 9, 2024 14:05
Empty Okhttp3 Interceptor
class EmptyInterceptor @Inject constructor() : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request: Request = chain.request()
val builder = request.newBuilder()
return chain.proceed(builder.build())
}
}
@cengiztoru
cengiztoru / TrimAudio.py
Created September 17, 2023 18:59
Python trim audio and save it
import os
import subprocess
import time
from pydub import AudioSegment
DIRECTORY_PATH = "D:/asr-ı saadet radyo tiyatrosu"
ONE_SECOND = 1000
AUDIO_PREFIX_TO_TRIM = 40 * ONE_SECOND
if (isCurrentLanguageRTL) {
etEmail.doOnTextChanged { text, start, before, count ->
etEmail.setSelection(0)
}
}
if(isCurrentLanguageRTL) {
textView.gravity = Gravity.END
}
override fun onRtlPropertiesChanged(layoutDirection: kotlin.Int) {
super.onRtlPropertiesChanged(layoutDirection)
//do magic
}
val layoutDirection = context.resources.configuration.layoutDirection
val viewLayoutDirection = view.layoutDirection
if (layoutDirection == View.LAYOUT_DIRECTION_RTL){
//do stuff
}
willLoadHtmlData = if(isCurrentLanguageRTL) <html dir=\"rtl\"><body> $mainHtmlData </body></html> else $mainHtmlData
@cengiztoru
cengiztoru / ExampleFragment.kt
Created July 8, 2021 17:05
TabLayout with ViewPager2
TabLayoutMediator(mTabLayout, mViewPager) { tab, position ->
tab.text = it[position].title
}.attach()
@cengiztoru
cengiztoru / HomeFragment.kt
Created July 1, 2020 22:31
Navigation Architectural Components - Getting Passed Data
lateinit var user: User
val args: HomeFragmentArgs by navArgs()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
user = args.user
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,