Skip to content
This repository was archived by the owner on Feb 17, 2020. It is now read-only.

Commit f4cf5cc

Browse files
committed
Merge branch 'develop' into conf/droidcon-turin-2018
2 parents eded253 + 47a356d commit f4cf5cc

15 files changed

Lines changed: 61 additions & 28 deletions

File tree

app/src/main/java/net/squanchy/imageloader/GlideImageLoader.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ private class GlideImageRequest(private val request: RequestBuilder<Drawable>) :
3232
request.apply(RequestOptions.errorOf(errorImageResId))
3333
}
3434

35+
override fun placeholder(@DrawableRes placeholderImageResId: Int) = apply {
36+
request.apply(RequestOptions.placeholderOf(placeholderImageResId))
37+
}
38+
3539
override fun into(target: ImageView) {
3640
request.into(target)
3741
}

app/src/main/java/net/squanchy/imageloader/ImageLoader.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ interface ImageRequest {
1515

1616
fun error(@DrawableRes errorImageResId: Int): ImageRequest
1717

18+
fun placeholder(@DrawableRes placeholderImageResId: Int): ImageRequest
19+
1820
fun into(target: ImageView)
1921
}

app/src/main/java/net/squanchy/schedule/view/EventItemView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ abstract class EventItemView : CardLayout {
1212

1313
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
1414

15-
abstract fun updateWith(event: Event, showRoom: Boolean = false)
15+
abstract fun updateWith(event: Event, showRoom: Boolean = false, showDay: Boolean = false)
1616
}

app/src/main/java/net/squanchy/schedule/view/OtherEventItemView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class OtherEventItemView @JvmOverloads constructor(
1414
defStyleAttr: Int = R.attr.cardViewDefaultStyle
1515
) : EventItemView(context, attrs, defStyleAttr) {
1616

17-
override fun updateWith(event: Event, showRoom: Boolean) {
17+
override fun updateWith(event: Event, showRoom: Boolean, showDay: Boolean) {
1818
event.type.ensureSupported()
1919

2020
timestamp.text = startTimeAsFormattedString(event)

app/src/main/java/net/squanchy/schedule/view/TalkEventItemView.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ class TalkEventItemView @JvmOverloads constructor(
1717
defStyleAttr: Int = R.attr.cardViewDefaultStyle
1818
) : EventItemView(context, attrs, defStyleAttr) {
1919

20-
override fun updateWith(event: Event, showRoom: Boolean) {
20+
private val timeFormatter = DateTimeFormat.shortTime()
21+
private val dateFormatter = DateTimeFormat.forPattern("EEE d")
22+
23+
override fun updateWith(event: Event, showRoom: Boolean, showDay: Boolean) {
2124
ensureSupportedType(event.type)
2225

23-
timestamp.text = startTimeAsFormattedString(event)
26+
timestamp.text = startTimeAsFormattedString(event, showDay)
2427
title.text = event.title
2528
room.apply {
2629
text = event.place.orNull().toPlaceLabel()
@@ -47,10 +50,14 @@ class TalkEventItemView @JvmOverloads constructor(
4750
}
4851
}
4952

50-
private fun startTimeAsFormattedString(event: Event): String {
51-
val formatter = DateTimeFormat.shortTime()
52-
.withZone(event.timeZone)
53+
private fun startTimeAsFormattedString(event: Event, showDay: Boolean): String {
54+
val timeZone = event.timeZone
55+
val startDateTime = event.startTime.toDateTime(timeZone)
56+
57+
// Note: the space at the end of the template string is not a typo, it separates the date from the time
58+
val formattedDate = if (showDay) "${dateFormatter.withZone(timeZone).print(startDateTime)} " else ""
59+
val formattedTime = timeFormatter.withZone(timeZone).print(startDateTime)
5360

54-
return formatter.print(event.startTime.toDateTime())
61+
return "$formattedDate$formattedTime"
5562
}
5663
}

app/src/main/java/net/squanchy/search/SearchActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class SearchActivity : AppCompatActivity(), SearchRecyclerView.OnSearchResultCli
5050

5151
override fun onCreate(savedInstanceState: Bundle?) {
5252
super.onCreate(savedInstanceState)
53+
5354
setContentView(R.layout.activity_search)
5455
enableLightNavigationBar(this)
5556
setupToolbar()
@@ -245,7 +246,7 @@ class SearchActivity : AppCompatActivity(), SearchRecyclerView.OnSearchResultCli
245246
companion object {
246247

247248
private const val SPEECH_REQUEST_CODE = 100
248-
private const val QUERY_DEBOUNCE_TIMEOUT = 250L
249+
private const val QUERY_DEBOUNCE_TIMEOUT = 350L
249250
private const val MIN_QUERY_LENGTH = 2
250251
private const val QUERY_KEY = "SearchActivity.query_key"
251252
}

app/src/main/java/net/squanchy/search/SearchItemView.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class SearchItemView @JvmOverloads constructor(
3838

3939
val avatarImageURL = speaker.photoUrl
4040
if (avatarImageURL.isDefined()) {
41-
imageLoader.load(avatarImageURL.getOrThrow()).into(speakerPhoto)
41+
imageLoader.load(avatarImageURL.getOrThrow())
42+
.placeholder(R.drawable.ic_avatar_placeholder)
43+
.error(R.drawable.ic_no_avatar)
44+
.into(speakerPhoto)
4245
} else {
4346
speakerPhoto.setImageResource(R.drawable.ic_no_avatar)
4447
}

app/src/main/java/net/squanchy/search/view/SearchAdapter.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import net.squanchy.R
1212
import net.squanchy.imageloader.ImageLoader
1313
import net.squanchy.imageloader.imageLoaderComponent
1414
import net.squanchy.schedule.view.EventItemView
15-
import net.squanchy.search.SearchResult
1615
import net.squanchy.search.SearchListElement
1716
import net.squanchy.search.SearchListElement.EventElement
1817
import net.squanchy.search.SearchListElement.SpeakerElement
@@ -28,8 +27,6 @@ internal class SearchAdapter(activity: AppCompatActivity) : ListAdapter<SearchLi
2827

2928
private lateinit var listener: SearchRecyclerView.OnSearchResultClickListener
3029

31-
private var searchResult = SearchResult.Success(emptyList())
32-
3330
init {
3431
this.activity = activity
3532

@@ -95,11 +92,18 @@ internal class SearchAdapter(activity: AppCompatActivity) : ListAdapter<SearchLi
9592

9693
private fun isEmpty() = itemCount == 0
9794

98-
fun updateWith(searchResult: SearchResult.Success, listener: SearchRecyclerView.OnSearchResultClickListener) {
95+
fun updateWith(items: List<SearchListElement>, listener: SearchRecyclerView.OnSearchResultClickListener) {
9996
this.listener = listener
100-
this.searchResult = searchResult
97+
super.submitList(items)
98+
}
10199

102-
submitList(searchResult.elements)
100+
@Deprecated(
101+
message = "Use updateWith() instead",
102+
replaceWith = ReplaceWith("updateWith(items, onSearchResultClickListener)"),
103+
level = DeprecationLevel.ERROR
104+
)
105+
override fun submitList(items: MutableList<SearchListElement>?) {
106+
throw UnsupportedOperationException("Use updateWith() instead")
103107
}
104108

105109
companion object {

app/src/main/java/net/squanchy/search/view/SearchItemViewHolder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sealed class SearchItemViewHolder(view: View) : RecyclerView.ViewHolder(view) {
3434
class SearchEventViewHolder(itemView: EventItemView) : SearchItemViewHolder(itemView) {
3535

3636
fun updateWith(event: Event, listener: (Event) -> Unit) {
37-
(itemView as EventItemView).updateWith(event)
37+
(itemView as EventItemView).updateWith(event, showRoom = true, showDay = true)
3838
itemView.setOnClickListener { listener(event) }
3939
}
4040
}

app/src/main/java/net/squanchy/search/view/SearchRecyclerView.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ class SearchRecyclerView @JvmOverloads constructor(
2121
defStyle: Int = 0
2222
) : RecyclerView(context, attrs, defStyle) {
2323

24+
private val columnsCount = context.resources.getInteger(R.integer.search_columns_count)
25+
2426
private lateinit var adapter: SearchAdapter
2527

2628
override fun onFinishInflate() {
2729
super.onFinishInflate()
2830

29-
val gridLayoutManager = GridLayoutManager(context, COLUMNS_COUNT)
31+
val gridLayoutManager = GridLayoutManager(context, columnsCount)
3032
layoutManager = gridLayoutManager
3133

3234
val horizontalSpacing = resources.getDimensionPixelSize(R.dimen.card_horizontal_margin)
@@ -40,9 +42,9 @@ class SearchRecyclerView @JvmOverloads constructor(
4042
fun updateWith(searchResult: SearchResult.Success, listener: OnSearchResultClickListener) {
4143
setAdapterIfNone(adapter)
4244

43-
adapter.updateWith(searchResult, listener)
45+
adapter.updateWith(searchResult.elements, listener)
4446

45-
val spanSizeLookup = adapter.createSpanSizeLookup(COLUMNS_COUNT)
47+
val spanSizeLookup = adapter.createSpanSizeLookup(columnsCount)
4648
(layoutManager as GridLayoutManager).spanSizeLookup = spanSizeLookup
4749
}
4850

@@ -72,9 +74,4 @@ class SearchRecyclerView @JvmOverloads constructor(
7274
outRect.set(horizontalSpacing, topSpacing, horizontalSpacing, bottomSpacing)
7375
}
7476
}
75-
76-
companion object {
77-
78-
private const val COLUMNS_COUNT = 4
79-
}
8077
}

0 commit comments

Comments
 (0)