Skip to content

Instantly share code, notes, and snippets.

View devrath's full-sized avatar
💭
I'm grateful when for one drop in glass. Since I knw exactly what to do with it

Devrath devrath

💭
I'm grateful when for one drop in glass. Since I knw exactly what to do with it
View GitHub Profile
Start
PKG-ONE: 😎😎😎
PKG-TWO: 😎😎😎
PKG-Three: 😎😎😎
End
Process finished with exit code 0
// ----> MainClass
import pkgone.MyViewClass
fun main() {
println("Start")
pkgone.MyViewClass().display()
pkgtwo.MyViewClass().display()
pkgthree.MyViewClass().display()
println("End")
}
@devrath
devrath / AssistedInjection.kt
Created August 27, 2021 06:26
AssistedInjection.kt
class DownloadAssetsAnalytics @AssistedInject constructor(
@Assisted("downloadTaskParams") val downloadTaskParams: DownloadTaskParams,
@Assisted("errorOnDownload") val errorOnDownload: Boolean
){
// Where we have used the dependency
}
@AssistedFactory
interface DownloadAssetsAnalyticsFactory {
fun create(
class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::inflate) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.apply {
btnInternalStorageImgId.setOnClickListener {
openActivity(InternalStorageImagesActivity::class.java)
}
}
}
class InternalStorageGalleryFragment :
BaseFragment<FragmentInternalStorageGalleryBinding>(FragmentInternalStorageGalleryBinding::inflate) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.test.text = "Hello view binding"
}
}
abstract class BaseActivity<VIEW_BINDING: ViewBinding>(
private val inflate: InflateActivity<VIEW_BINDING>
) : AppCompatActivity() {
lateinit var binding : VIEW_BINDING
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = inflate.invoke(layoutInflater)
setContentView(binding.root)
abstract class BaseFragment<VIEW_BINDING: ViewBinding>(
private val inflate: InflateFragment<VIEW_BINDING>
) : Fragment() {
private var _binding: VIEW_BINDING? = null
val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = inflate.invoke(inflater, container, false)
return binding.root
@devrath
devrath / NonJvmOverloaded.kt
Created May 27, 2021 05:52
custom textview without jvm overloads
class CustomBoldTextView : AppCompatTextView {
var FONT_NAME = "Roboto-Bold.ttf"
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
context,
attrs,
defStyle
) {
init(attrs, context)
}
@devrath
devrath / JvmOverloaded.kt
Created May 27, 2021 05:50
Example of custom font set from assets with jvm overloads
class CustomBoldTextView @JvmOverloads constructor(context: Context,
attrs: AttributeSet? = null,
defStyle: Int = androidx.appcompat.R.attr.titleTextStyle) : AppCompatTextView(context, attrs, defStyle) {
private var FONT_NAME = "Roboto-Bold.ttf"
init { init(attrs) }
private fun init(attrs: AttributeSet?) {
if (attrs != null) {
val a = context.obtainStyledAttributes(attrs, R.styleable.CustomTextView)
@devrath
devrath / ButtonGistDemo.java
Created May 21, 2021 11:25
ButtonGistDemo
public class Main {
public static void main(String[] args) {
var button = new Button();
button.setText("Click button")
}
}