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

Release refinement #107

Merged
merged 2 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2019 Hossain Khan
*
* 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 is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hossainkhan.android.demo.data


/**
* A class to represent external resource request with data or error on fail.
*/
class ResourceResult(
val resources: List<ResourceInfo> = emptyList(),
val error: Exception? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import com.hossainkhan.android.demo.R
import com.hossainkhan.android.demo.data.ResourceInfo
import com.hossainkhan.android.demo.databinding.ActivityLearningResourceBinding
Expand All @@ -34,6 +36,9 @@ import dagger.android.AndroidInjection
import timber.log.Timber
import javax.inject.Inject

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

@Inject
Expand Down Expand Up @@ -69,7 +74,13 @@ class LearningResourceActivity : AppCompatActivity() {
}

viewModel.data.observe(this, Observer { result ->
ideaListAdapter.submitList(result)
if (result?.error != null) {
Timber.w(result.error, "Unable to load resources.")
Snackbar.make(binding.root, R.string.message_resource_load_failed, Snackbar.LENGTH_INDEFINITE).show()
return@Observer
} else {
ideaListAdapter.submitList(result.resources)
}
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.Query
import com.google.firebase.firestore.QuerySnapshot
import com.hossainkhan.android.demo.data.ResourceInfo
import com.hossainkhan.android.demo.data.ResourceResult
import timber.log.Timber
import java.lang.Exception
import javax.inject.Inject
import kotlin.Exception

class LearningResourceViewModel @Inject constructor(
firestore: FirebaseFirestore
Expand All @@ -37,8 +38,8 @@ class LearningResourceViewModel @Inject constructor(

val isLoading = ObservableField(true)

private val _data = MutableLiveData<List<ResourceInfo>>()
val data: LiveData<List<ResourceInfo>> = _data
private val _data = MutableLiveData<ResourceResult>()
val data: LiveData<ResourceResult> = _data

private val resourceData = mutableListOf<ResourceInfo>()

Expand All @@ -49,6 +50,12 @@ class LearningResourceViewModel @Inject constructor(
.get()
.addOnSuccessListener(this::updateResources)
.addOnFailureListener(this::onLoadFailed)
.addOnCompleteListener {
if (it.result?.isEmpty == true) {
Timber.i("Completed with no data. This is likely due to no internet.")
onLoadFailed(Exception("No data"))
}
}
}

private fun updateResources(result: QuerySnapshot) {
Expand All @@ -58,11 +65,12 @@ class LearningResourceViewModel @Inject constructor(
resourceData.add(x)
}
isLoading.set(false)
_data.value = resourceData
_data.value = ResourceResult(resourceData)
}

private fun onLoadFailed(exception: Exception) {
Timber.w(exception, "Error getting documents.")
isLoading.set(false)
_data.value = ResourceResult(error = exception)
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/ic_github_logo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="438.549"
android:viewportWidth="438.549" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<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"/>
</vector>
8 changes: 7 additions & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
- https://developer.android.com/guide/topics/resources/providing-resources
- https://developer.android.com/training/multiscreen/screensizes
-->
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!--
Overrides snackbar text truncation.
https://stackoverflow.com/questions/32228300/how-to-prevent-my-snackbar-text-from-being-truncated-on-android/32228529
-->
<integer tools:override="true" name="design_snackbar_text_max_lines">4</integer>

<dimen name="box_size_small">40dp</dimen>
<dimen name="box_size_medium">80dp</dimen>
<dimen name="box_size_large">120dp</dimen>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
<string name="additional_resource_title">External Resources</string>
<string name="tech_talk_author_and_venue">by %1$s at %2$s</string>
<string name="tech_talk_publish_date">Published on %1$s</string>

<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>
</resources>