Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit aef22b4

Browse files
authored
Merge pull request #107 from amardeshbd/release-refinement
Release refinement
2 parents 906d80d + 06ad3b5 commit aef22b4

File tree

6 files changed

+62
-7
lines changed

6 files changed

+62
-7
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2019 Hossain Khan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hossainkhan.android.demo.data
18+
19+
20+
/**
21+
* A class to represent external resource request with data or error on fail.
22+
*/
23+
class ResourceResult(
24+
val resources: List<ResourceInfo> = emptyList(),
25+
val error: Exception? = null
26+
)

app/src/main/java/com/hossainkhan/android/demo/ui/resource/LearningResourceActivity.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import android.content.Intent
2121
import android.net.Uri
2222
import android.os.Bundle
2323
import androidx.appcompat.app.AppCompatActivity
24+
import androidx.constraintlayout.widget.ConstraintLayout
2425
import androidx.databinding.DataBindingUtil
2526
import androidx.lifecycle.Observer
2627
import androidx.lifecycle.ViewModelProvider
2728
import androidx.recyclerview.widget.LinearLayoutManager
2829
import androidx.recyclerview.widget.RecyclerView
30+
import com.google.android.material.snackbar.Snackbar
2931
import com.hossainkhan.android.demo.R
3032
import com.hossainkhan.android.demo.data.ResourceInfo
3133
import com.hossainkhan.android.demo.databinding.ActivityLearningResourceBinding
@@ -34,6 +36,9 @@ import dagger.android.AndroidInjection
3436
import timber.log.Timber
3537
import javax.inject.Inject
3638

39+
/**
40+
* This activity lists external resources on [ConstraintLayout], such as tech talks on youtube.
41+
*/
3742
class LearningResourceActivity : AppCompatActivity() {
3843

3944
@Inject
@@ -69,7 +74,13 @@ class LearningResourceActivity : AppCompatActivity() {
6974
}
7075

7176
viewModel.data.observe(this, Observer { result ->
72-
ideaListAdapter.submitList(result)
77+
if (result?.error != null) {
78+
Timber.w(result.error, "Unable to load resources.")
79+
Snackbar.make(binding.root, R.string.message_resource_load_failed, Snackbar.LENGTH_INDEFINITE).show()
80+
return@Observer
81+
} else {
82+
ideaListAdapter.submitList(result.resources)
83+
}
7384
})
7485
}
7586

app/src/main/java/com/hossainkhan/android/demo/ui/resource/LearningResourceViewModel.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import com.google.firebase.firestore.FirebaseFirestore
2424
import com.google.firebase.firestore.Query
2525
import com.google.firebase.firestore.QuerySnapshot
2626
import com.hossainkhan.android.demo.data.ResourceInfo
27+
import com.hossainkhan.android.demo.data.ResourceResult
2728
import timber.log.Timber
28-
import java.lang.Exception
2929
import javax.inject.Inject
30+
import kotlin.Exception
3031

3132
class LearningResourceViewModel @Inject constructor(
3233
firestore: FirebaseFirestore
@@ -37,8 +38,8 @@ class LearningResourceViewModel @Inject constructor(
3738

3839
val isLoading = ObservableField(true)
3940

40-
private val _data = MutableLiveData<List<ResourceInfo>>()
41-
val data: LiveData<List<ResourceInfo>> = _data
41+
private val _data = MutableLiveData<ResourceResult>()
42+
val data: LiveData<ResourceResult> = _data
4243

4344
private val resourceData = mutableListOf<ResourceInfo>()
4445

@@ -49,6 +50,12 @@ class LearningResourceViewModel @Inject constructor(
4950
.get()
5051
.addOnSuccessListener(this::updateResources)
5152
.addOnFailureListener(this::onLoadFailed)
53+
.addOnCompleteListener {
54+
if (it.result?.isEmpty == true) {
55+
Timber.i("Completed with no data. This is likely due to no internet.")
56+
onLoadFailed(Exception("No data"))
57+
}
58+
}
5259
}
5360

5461
private fun updateResources(result: QuerySnapshot) {
@@ -58,11 +65,12 @@ class LearningResourceViewModel @Inject constructor(
5865
resourceData.add(x)
5966
}
6067
isLoading.set(false)
61-
_data.value = resourceData
68+
_data.value = ResourceResult(resourceData)
6269
}
6370

6471
private fun onLoadFailed(exception: Exception) {
6572
Timber.w(exception, "Error getting documents.")
6673
isLoading.set(false)
74+
_data.value = ResourceResult(error = exception)
6775
}
6876
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<vector android:height="24dp" android:viewportHeight="438.549"
2+
android:viewportWidth="438.549" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<path android:fillColor="#FF000000" android:pathData="M409.1,114.6c-19.6,-33.6 -46.2,-60.2 -79.8,-79.8C295.7,15.2 259.1,5.4 219.3,5.4c-39.8,0 -76.5,9.8 -110.1,29.4c-33.6,19.6 -60.2,46.2 -79.8,79.8C9.8,148.2 0,184.9 0,224.6c0,47.8 13.9,90.7 41.8,128.9c27.9,38.2 63.9,64.6 108.1,79.2c5.1,1 8.9,0.3 11.4,-2c2.5,-2.3 3.7,-5.1 3.7,-8.6c0,-0.6 -0,-5.7 -0.1,-15.4c-0.1,-9.7 -0.1,-18.2 -0.1,-25.4l-6.6,1.1c-4.2,0.8 -9.5,1.1 -15.8,1c-6.4,-0.1 -13,-0.8 -19.8,-2c-6.9,-1.2 -13.2,-4.1 -19.1,-8.6c-5.9,-4.5 -10.1,-10.3 -12.6,-17.6l-2.9,-6.6c-1.9,-4.4 -4.9,-9.2 -9,-14.6c-4.1,-5.3 -8.2,-8.9 -12.4,-10.8l-2,-1.4c-1.3,-1 -2.6,-2.1 -3.7,-3.4c-1.1,-1.3 -2,-2.7 -2.6,-4c-0.6,-1.3 -0.1,-2.4 1.4,-3.3c1.5,-0.9 4.3,-1.3 8.3,-1.3l5.7,0.9c3.8,0.8 8.5,3 14.1,6.9c5.6,3.8 10.2,8.8 13.8,14.8c4.4,7.8 9.7,13.8 15.8,17.8c6.2,4.1 12.4,6.1 18.7,6.1c6.3,0 11.7,-0.5 16.3,-1.4c4.6,-1 8.8,-2.4 12.8,-4.3c1.7,-12.8 6.4,-22.6 14,-29.4c-10.8,-1.1 -20.6,-2.9 -29.3,-5.1c-8.7,-2.3 -17.6,-6 -26.8,-11.1c-9.2,-5.1 -16.9,-11.5 -23,-19.1c-6.1,-7.6 -11.1,-17.6 -15,-30c-3.9,-12.4 -5.9,-26.6 -5.9,-42.8c0,-23 7.5,-42.6 22.6,-58.8c-7,-17.3 -6.4,-36.7 2,-58.2c5.5,-1.7 13.7,-0.4 24.6,3.9c10.9,4.3 18.8,8 23.8,11c5,3 9.1,5.6 12.1,7.7c17.7,-4.9 36,-7.4 54.8,-7.4s37.1,2.5 54.8,7.4l10.8,-6.8c7.4,-4.6 16.2,-8.8 26.3,-12.6c10.1,-3.8 17.8,-4.9 23.1,-3.1c8.6,21.5 9.3,40.9 2.3,58.2c15,16.2 22.6,35.8 22.6,58.8c0,16.2 -2,30.5 -5.9,43c-3.9,12.5 -8.9,22.5 -15.1,30c-6.2,7.5 -13.9,13.9 -23.1,19c-9.2,5.1 -18.2,8.9 -26.8,11.1c-8.7,2.3 -18.4,4 -29.3,5.1c9.9,8.6 14.8,22.1 14.8,40.5v60.2c0,3.4 1.2,6.3 3.6,8.6c2.4,2.3 6.1,3 11.3,2c44.2,-14.7 80.2,-41.1 108.1,-79.2c27.9,-38.2 41.8,-81.1 41.8,-128.9C438.5,184.9 428.7,148.2 409.1,114.6z"/>
4+
</vector>

app/src/main/res/values/dimens.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
- https://developer.android.com/guide/topics/resources/providing-resources
2525
- https://developer.android.com/training/multiscreen/screensizes
2626
-->
27-
<resources>
27+
<resources xmlns:tools="http://schemas.android.com/tools">
28+
<!--
29+
Overrides snackbar text truncation.
30+
https://stackoverflow.com/questions/32228300/how-to-prevent-my-snackbar-text-from-being-truncated-on-android/32228529
31+
-->
32+
<integer tools:override="true" name="design_snackbar_text_max_lines">4</integer>
33+
2834
<dimen name="box_size_small">40dp</dimen>
2935
<dimen name="box_size_medium">80dp</dimen>
3036
<dimen name="box_size_large">120dp</dimen>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
<string name="additional_resource_title">External Resources</string>
2727
<string name="tech_talk_author_and_venue">by %1$s at %2$s</string>
2828
<string name="tech_talk_publish_date">Published on %1$s</string>
29-
29+
<string name="message_resource_load_failed">Unable to load external resources. This is likely due to no internet connectivity. Please try re-loading this screen with network connection.</string>
3030
</resources>

0 commit comments

Comments
 (0)