Skip to content

Instantly share code, notes, and snippets.

View pramonow's full-sized avatar
:octocat:
Cat with octopus combo

Pramono Winata pramonow

:octocat:
Cat with octopus combo
  • Jakarta, Indonesia
View GitHub Profile
class DemoActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_demo)
//now we creating adapter and passing in a lambda method
var demoAdapter = DemoAdapter{ item -> doClick(item) }
}
//creating method to make it look simpler
//Adapter having lambda function inside the constructor
class DemoAdapter(val adapterOnClick : (Any) -> Unit): RecyclerView.Adapter<DemoAdapter.DemoVH>(){
var itemList:MutableList<Any> = ArrayList()
override fun onBindViewHolder(demoVH: DemoVH, i: Int) {
demoVH.setItem(itemList.get(i))
}
/*
other abstract method implementation
*/
class DemoActivity : AppCompatActivity(), AdapterOnClick {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_demo)
//create our adapter here and passing in our class
var demoAdapter = DemoAdapter(this)
//other layout manager binding
}
//Sample adapter with click interface
class DemoAdapter(val adapterOnClick: AdapterOnClick) : RecyclerView.Adapter<DemoAdapter.DemoVH> {
var itemList:MutableList<Any> = ArrayList()
override fun onBindViewHolder(demoVH: DemoVH, i: Int) {
demoVH.setItem(itemList.get(i))
}
/*
implement other abstract method ..
*/
interface AdapterOnClick {
fun onClick(item: Any)
}
@pramonow
pramonow / server.go
Last active February 22, 2022 07:32
package main
import (
"fmt"
"log"
"net"
"sync"
"time"
pb "github.com/pramonow/go-grpc-server-streaming-example/src/proto"
@pramonow
pramonow / client.go
Last active February 22, 2022 07:32
package main
import (
"context"
"io"
"log"
pb "github.com/pramonow/go-grpc-server-streaming-example/src/proto"
"google.golang.org/grpc"
syntax = "proto3";
package protobuf;
service StreamService {
rpc FetchResponse (Request) returns (stream Response) {}
}
message Request {
int32 id = 1;