- One advantage of static factory methods is that, unlike constructors, they have names
- A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they’re invoked
- A third advantage of static factory methods is that, unlike constructors, they can return an object of any subtype of their return type
- The main disadvantage of providing only static factory methods is that classes without public or protected constructors cannot be subclassed
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
class MobileListAdapterStrategy<T : Any, VH : RecyclerView.ViewHolder>( | |
override val adapter: RecyclerView.Adapter<VH>, | |
private val diffCallback: DiffUtil.ItemCallback<T> | |
) : ListAdapterStrategy<T, VH> { | |
private val listAdapter = object : ListAdapter<T, VH>(diffCallback) { | |
fun getItemWithPosition(position: Int) = getItem(position) | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH { | |
return this.onCreateViewHolder(parent, viewType) | |
} |
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 io.reactivex.subjects.PublishSubject | |
import kotlinx.coroutines.CoroutineDispatcher | |
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.flowOn | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.newSingleThreadContext | |
import kotlinx.coroutines.suspendCancellableCoroutine |
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.app.Dialog | |
import android.os.Bundle | |
import android.view.View | |
import android.view.ViewGroup | |
import android.widget.DatePicker | |
import androidx.appcompat.app.AlertDialog | |
import androidx.core.os.bundleOf | |
import androidx.fragment.app.DialogFragment | |
import androidx.fragment.app.activityViewModels | |
import dagger.hilt.android.AndroidEntryPoint |
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"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="rectangle"> | |
<corners | |
android:topLeftRadius="24dp" | |
android:topRightRadius="24dp" /> | |
<stroke | |
android:width="1dp" | |
android:color="@color/divider_dark"/> | |
</shape> |
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 Fragment.showBottomSheetDialog( | |
@LayoutRes layout: Int, | |
@IdRes textViewToSet: Int? = null, | |
textToSet: String? = null, | |
fullScreen: Boolean = true, | |
expand: Boolean = true | |
) { | |
val dialog = BottomSheetDialog(context!!) | |
dialog.setOnShowListener { | |
val bottomSheet: FrameLayout = dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet) ?: return@setOnShowListener |
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.google.android.exoplayer2.* | |
import com.google.android.exoplayer2.audio.AudioAttributes | |
import com.google.android.exoplayer2.audio.AudioListener | |
import com.google.android.exoplayer2.ext.cast.CastPlayer | |
import com.google.android.exoplayer2.ext.cast.SessionAvailabilityListener | |
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource | |
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory | |
import com.google.android.exoplayer2.source.ProgressiveMediaSource | |
import com.google.android.exoplayer2.upstream.FileDataSource | |
import okhttp3.OkHttpClient |
Android Developer Toolbox - Notes
- Create different build variants which contain different code of your app
- Internal - for the company. Embed a lot of tools to locate issues easily.
- Production - only for customers
- Immutable state - it should not be changeable instead is replaced. Everything that changes in your app including the date and the UI state is stored in a single object tree.
- State is read only - to make a change you need to dispatch an action. An action is a plain javascript object. State = data, change = action
- Pure 2. Depend only on their input params 3. Some value for some input elements
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
//This method is supposed to tell the sockets server | |
//to post an refresh event with data to a selected client id | |
export function* postRefreshEvent(clientId, data) { | |
var connection = require('socket.io-emitter')({ host: '127.0.0.1', port: 8081 }); | |
connection.emit('refresh', clientId, data); | |
return {statusCode: OK} | |
} | |
// Websockets |
NewerOlder