This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ercnksgl.testapp.util | |
import android.view.MotionEvent | |
import androidx.recyclerview.widget.RecyclerView | |
import kotlin.math.abs | |
class DisallowParentSwipeOnItemTouchListener : RecyclerView.OnItemTouchListener { | |
var startPoint = 0f | |
override fun onInterceptTouchEvent( | |
rv: RecyclerView, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recyclerView" | |
android:layout_width="0dp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.recyclerview.widget.RecyclerView | |
import com.ercnksgl.diffutlisapp.R | |
import com.google.android.material.button.MaterialButton | |
class MainActivity : AppCompatActivity() { | |
private val itemAdapter = ItemAdapter() | |
private val list = arrayListOf<Item>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import android.widget.TextView | |
import androidx.recyclerview.widget.DiffUtil | |
import androidx.recyclerview.widget.RecyclerView | |
class ItemAdapter : RecyclerView.Adapter<ItemAdapter.ViewHolder>() { | |
private var list = emptyList<Item>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.recyclerview.widget.DiffUtil | |
class CustomDiffUtils<T>( | |
private val oldList: List<T>, | |
private val newList: List<T> | |
) : DiffUtil.Callback() { | |
override fun getOldListSize() = oldList.size | |
override fun getNewListSize() = newList.size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.annotation.StringRes | |
import com.ercnksgl.sealedtest.R | |
sealed class ApiError { | |
data class ServerError( | |
val errorBody: String? = null | |
) : ApiError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.ercnksgl.sealedtest.data.network.Result | |
import com.ercnksgl.sealedtest.data.network.response.ApiError | |
import com.ercnksgl.sealedtest.data.network.response.ApiError.UnexpectedError | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.withContext | |
import retrofit2.Response | |
class NetworkUtils { | |
suspend fun <T : Any> request(onRequest: suspend () -> Response<T>): Result<T> = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.ercnksgl.sealedtest.data.network.response.ApiError | |
sealed class Result<out T : Any> { | |
data class Success<out T : Any>(val data: T) : Result<T>() | |
data class Error(val error: ApiError) : Result<Nothing>() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.annotation.ColorRes | |
import androidx.annotation.DrawableRes | |
import androidx.annotation.StringRes | |
import com.ercnksgl.enumtestapp.R | |
enum class MessageType( | |
@StringRes val titleResId: Int, | |
@DrawableRes val iconResId: Int, | |
@ColorRes val cardColorResId: Int, | |
@ColorRes val titleColorResId: Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getRelativeTimeDifference(resources: Resources, time: LocalDateTime): String { | |
val now = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() | |
val timeDifference = now - time.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() | |
return when { | |
timeDifference < DateUtils.MINUTE_IN_MILLIS -> resources.getString(R.string.just_now) | |
timeDifference < DateUtils.HOUR_IN_MILLIS -> { | |
val minute = (timeDifference / DateUtils.MINUTE_IN_MILLIS).toInt() | |
resources.getString(R.string.minutes_ago, minute) | |
} | |
timeDifference < DateUtils.DAY_IN_MILLIS -> { |
NewerOlder