Skip to content

Instantly share code, notes, and snippets.

@sjthn
sjthn / RecyclerViewAdapter.kt
Last active May 7, 2018 12:52
Kotlin template for RecyclerView Adapter in Android Studio
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
#end
#parse("File Header.java")
class ${NAME}(private var items: MutableList<${ITEM_TYPE}>): RecyclerView.Adapter<${VIEWHOLDER}>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ${VIEWHOLDER} {
if (type.equals("image/png")){
Uri fileStream = intentReader.getStream();
Bitmap bitmap = null;
try {
InputStream inputStream = getContentResolver()
.openInputStream(fileStream);
bitmap = BitmapFactory.decodeStream(inputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String type = intentReader.getType();
if (type.equals("text/plain")){
CharSequence text = intentReader.getText();
textView.setText(text);
}
ShareCompat.IntentReader intentReader = ShareCompat.IntentReader.from(this);
if (intentReader.isShareIntent()) {
// ...
}
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/plain" />
<data android:mimeType="text/html" />
<data android:mimeType="image/png" />
</intent-filter>
Intent intent = ShareCompat.IntentBuilder.from(this)
.setType("image/png")
.setStream(imageUri)
.setChooserTitle("Choose image client")
.getIntent();
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
ShareCompat.IntentBuilder intentBuilder = ShareCompat.IntentBuilder.from(this);
Intent intent = intentBuilder
.setType("text/html")
.setText(text)
.setChooserTitle("Choose email client")
.createChooserIntent();
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}