Skip to content

Instantly share code, notes, and snippets.

View AkshatAgrawal05's full-sized avatar

Akshat Agrawal AkshatAgrawal05

View GitHub Profile
@AkshatAgrawal05
AkshatAgrawal05 / FabTabBackgroundView.java
Last active August 25, 2017 09:58
Code Snippet to create Google Space like navigation tab in Android
public final class FabTabBackgroundView extends View {
Paint paint;
Path path;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public FabTabBackgroundView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
@AkshatAgrawal05
AkshatAgrawal05 / ReadingJsonFromAssets.kt
Last active August 25, 2017 09:52
First Kotlin Project
fun getJsonFromAssets(): String? {
var json: String? = null
var inputStream: InputStream
inputStream = this.assets.open("reddit.json")
val size = inputStream.available()
val buffer = ByteArray(size)
inputStream.read(buffer)
inputStream.close()
json = String(buffer)
return json
@AkshatAgrawal05
AkshatAgrawal05 / JsonReaderTask.kt
Created August 25, 2017 10:03
Async Task to read json file
private inner class JsonExecuter : AsyncTask<Void, Void, String>() {
override fun doInBackground(vararg p0: Void?): String {
return getJsonFromAssets()!!
}
override fun onPostExecute(result: String?) {
super.onPostExecute(result)
val moshi = Moshi.Builder().build()
val jsonAdapter = moshi.adapter(Reddit::class.java)
@AkshatAgrawal05
AkshatAgrawal05 / Adapter.kt
Created August 25, 2017 10:21
Recycler View Adapter in Kotlin
class RedditAdapter(mainActivity: Context, mList: MutableList<Child>) : Adapter<RedditAdapter.ViewHolder>() {
var mContext = mainActivity
var mList = mList
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.reddit_item_view, parent, false))
}
override fun getItemCount(): Int {