This file contains hidden or 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
-- Example table | |
CREATE TABLE ring_buffer (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT); | |
-- Number 10 on where statement defines the ring buffer's size | |
CREATE TRIGGER delete_tail AFTER INSERT ON ring_buffer | |
BEGIN | |
DELETE FROM ring_buffer WHERE id%10=NEW.id%10 AND id!=NEW.id; | |
END; |
This file contains hidden or 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"?> | |
<!-- | |
Copyright 2017 Google Inc. | |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
in compliance with the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software distributed under the License |
This file contains hidden or 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 ShowAdapter(private val items: List<Show>) : RecyclerView.Adapter<ShowViewHolder>() { | |
init { | |
setHasStableIds(true) | |
} | |
override fun getItemCount() = items.size | |
override fun getItemId(position: Int) = items[position].hashCode().toLong() | |
override fun onCreateViewHolder(parent: ViewGroup, vt: Int) = ShowViewHolder(parent.inflate(R.layout.item_show)) | |
override fun onBindViewHolder(holder: ShowViewHolder, position: Int) = holder.bind(items[position]) | |
} |
This file contains hidden or 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
data class Show( | |
@StringRes val title: Int, | |
@StringRes val description: Int, | |
@DrawableRes val image: Int | |
) |
This file contains hidden or 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 ShowViewHolder(view: View) : ViewHolder(view) { | |
private val title = itemView.title | |
private val description = itemView.description | |
private val thumbnail = itemView.thumbnail | |
private val poster = itemView.poster | |
private val interpolator = FastOutLinearInInterpolator() | |
/** | |
* Offset the thumb and text with a factor [-1.0..1.0] of the total width |
This file contains hidden or 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"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
android:clipChildren="false" | |
> |
This file contains hidden or 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"?> | |
<FrameLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
... > | |
<ImageView | |
android:id="@+id/poster" | |
android:layout_width="match_parent" |
This file contains hidden or 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
recyclerView.apply { | |
// Create and attach the adapter | |
adapter = ShowAdapter(tvShows) | |
// Configure to be a horizontal list | |
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) | |
// Attach a snap helper, more on that below | |
PagerSnapHelper().attachToRecyclerView(this) | |
This file contains hidden or 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 RecyclerView.setupParallaxScrollListener() { | |
addOnScrollListener(object : OnScrollListener() { | |
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { | |
val layoutManager = layoutManager as? LinearLayoutManager ?: return | |
val scrollOffset = recyclerView.computeHorizontalScrollOffset() | |
val offsetFactor = (scrollOffset % measuredWidth) / measuredWidth.toFloat() | |
val firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition() | |
findViewHolderForAdapterPosition(firstVisibleItemPosition)?.let { |
This file contains hidden or 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
#!/bin/bash | |
EMULATOR=~/Library/Android/sdk/tools/emulator | |
if [ $# -ne 1 ]; then | |
echo "ERROR: Please specify the target AVD from the list below" 1>&2 | |
$EMULATOR -list-avds 1>&2 | |
exit 1 | |
fi | |
$EMULATOR -avd $1 -dns-server "8.8.8.8,8.8.4.4" |