Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add share button to the Session Detail Screen #578

Closed
wants to merge 13 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.droidkaigi.confsched2018.presentation.detail

import android.arch.lifecycle.ViewModelProvider
import android.arch.lifecycle.ViewModelProviders
import android.content.Intent
import android.graphics.drawable.Animatable
import android.os.Bundle
import android.support.v4.app.Fragment
Expand Down Expand Up @@ -84,6 +85,15 @@ class SessionDetailFragment : Fragment(), Injectable {
sessionDetailViewModel.onFavoriteClick(session)
sessionAlarm.toggleRegister(session)
}
binding.shareButton.setOnClickListener {
val shareIntent = Intent(Intent.ACTION_SEND).apply {
type = resources.getString(R.string.session_share_intent_type)
val text = generateSharedText(session)
putExtra(Intent.EXTRA_TEXT, text)
}
startActivity(Intent.createChooser(shareIntent,
resources.getString(R.string.session_share_via)))
}
binding.sessionTopic.text = session.topic.getNameByLang(lang())
val levelDrawable = binding.context.drawable(when (session.level) {
is Level.Beginner -> R.drawable.ic_beginner_lightgreen_20dp
Expand All @@ -98,6 +108,40 @@ class SessionDetailFragment : Fragment(), Injectable {
}
}

/**
* Generate a shared text
*
* e.g.
* ConstraintLayout, now and future (Nicolas Roard, John Hoford, thagikura) #droidkaigi_room6
* https://droidkaigi.jp/2018/timetable/?session=16988
*
* @param session The [Session.SpeechSession] object
* @return A shared text
*/
private fun generateSharedText(session: Session.SpeechSession): String {
val speakers = session.speakers.joinToString(", ") { it.name }
val hashTag = generateHashTagByRoom(session.room.name)
val title = resources.getString(R.string.session_share_title,
session.title,
speakers,
hashTag)
val url = resources.getString(R.string.session_share_url, session.id)
return "$title\n$url"
}

/**
* Generate a hash tag by room name.
*
* e.g. #droidkaigi_hall, #droidkaigi_room1, ...
*
* @param roomName The Room name
* @return A hash tag
*/
private fun generateHashTagByRoom(roomName: String): String {
val lowerCasedName = roomName.replace(" ", "").toLowerCase()
return resources.getString(R.string.session_share_hash_tag, lowerCasedName)
}

private fun updateDrawable() {
val img = if (binding.fab.isActivated) R.drawable.ic_anim_favorite_unchecking else R.drawable.ic_anim_favorite_checking
binding.fab.setImageResource(img)
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_share_white_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/layout/fragment_session_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@
app:speakers="@{session.speakers}"
app:textColor="@color/app_bar_text_color"
/>
<ImageView
android:id="@+id/share_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/session_content_description_share"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/session_title"
app:srcCompat="@drawable/ic_share_white_24dp"
/>

</android.support.constraint.ConstraintLayout>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<string name="session_load_retry">リトライ</string>
<string name="session_finished">終了済みのセッション</string>
<string name="session_go_to_feedback">アンケートへ</string>
<string name="session_share_via">シェア</string>

<!-- Session detail -->
<string name="detail_sessions_next">Next</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
<string name="session_finished">Finished Session</string>
<string name="session_go_to_feedback">Go To Feedback</string>
<string name="session_current_badge" translatable="false">NOW!</string>
<string name="session_share_url" translatable="false">https://droidkaigi.jp/2018/timetable?session=%s</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for translatable="false" 👍

<string name="session_share_title" translatable="false">%1$s (%2$s) %3$s</string>
<string name="session_share_hash_tag" translatable="false">#droidkaigi_%s</string>
<string name="session_share_intent_type" translatable="false">text/plain</string>
<string name="session_share_via">Share via</string>
<string name="session_content_description_share">Share button</string>

<!-- Session detail -->
<string name="detail_sessions_next">Next</string>
Expand Down