Skip to content

Commit 2a3d9d6

Browse files
authored
Merge pull request #2 from Njumbi/dev
Dev
2 parents 1257eed + bf3d1be commit 2a3d9d6

File tree

6 files changed

+94
-23
lines changed

6 files changed

+94
-23
lines changed

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
# Using DiffUtils In A Recyclerview
3+
This is an application that is part of a technical article. You can read the article from here
4+
# Table Of Contents
5+
6+
* [About the App](#AboutTheApp)
7+
8+
* [General Preview](#general-preview)
9+
10+
* [Architecture](#architecture)
11+
12+
* [Permissions](#permissions)
13+
14+
* [Run Project](#run-locally)
15+
16+
* [Installation](#installation)
17+
18+
* [Dependencies](#dependencies)
19+
20+
* [Authors](#todo)
21+
22+
* [License](#license)
23+
24+
## About the App
25+
The app displays a list of Disney character names and images using DiffUtils:
26+
27+
## General Preview
28+
29+
<a href="url">< height="550" ></a>
30+
31+
## Permissions
32+
33+
You need to allow the internet permissions before running the app:
34+
35+
## Installations
36+
37+
Clone the project
38+
39+
```bash
40+
41+
```
42+
## Run Project
43+
44+
Go to android studio compile and install dependencies
45+
46+
Run the app on your emulator or device
47+
48+
49+
50+
## Dependencies
51+
52+
- Retrofit/Gson
53+
54+
- Glide
55+
56+
- HILT
57+
58+
- Coroutines
59+
60+
- view binding
61+
62+
- Live Data
63+
64+
## Contributing
65+
66+
Contributions are always welcome!
67+
68+
See [contributing guidelines](https://github.com/github/docs/blob/main/CONTRIBUTING.md) for ways to get started.
69+
70+
Please adhere to this project's `code of conduct`.
71+
72+
1. Fork it
73+
2. Create your feature branch (git checkout -b my-new-feature)
74+
3. Commit your changes (git commit -m 'Add some feature')
75+
4. Push your branch (git push origin my-new-feature)
76+
5. Create a new Pull Request
77+
78+
## License
79+
80+
[MIT](https://choosealicense.com/licenses/mit/)

app/src/main/java/com/example/diff_utils_recyclerview_example/ui/MainActivity.kt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package com.example.diff_utils_recyclerview_example.ui
22

3-
import androidx.appcompat.app.AppCompatActivity
43
import android.os.Bundle
5-
import android.view.LayoutInflater
6-
import android.widget.Toast
7-
import android.widget.Toast.makeText
84
import androidx.activity.viewModels
9-
import androidx.lifecycle.ViewModel
10-
import androidx.lifecycle.lifecycleScope
5+
import androidx.appcompat.app.AppCompatActivity
116
import androidx.recyclerview.widget.LinearLayoutManager
127
import androidx.recyclerview.widget.RecyclerView
13-
import com.example.diff_utils_recyclerview_example.R
148
import com.example.diff_utils_recyclerview_example.databinding.ActivityMainBinding
159
import com.example.diff_utils_recyclerview_example.ui.adapters.CharactersAdapter
1610
import com.example.diff_utils_recyclerview_example.ui.viewmodel.fetchCharactersViewModel
@@ -20,8 +14,8 @@ import dagger.hilt.android.AndroidEntryPoint
2014
@AndroidEntryPoint
2115
class MainActivity : AppCompatActivity() {
2216
private lateinit var binding: ActivityMainBinding
23-
private lateinit var charactersAdapter:CharactersAdapter
24-
private val charactersViewModel: fetchCharactersViewModel by viewModels()
17+
private lateinit var charactersAdapter: CharactersAdapter
18+
private val charactersViewModel: fetchCharactersViewModel by viewModels()
2519

2620
override fun onCreate(savedInstanceState: Bundle?) {
2721
super.onCreate(savedInstanceState)
@@ -30,14 +24,14 @@ class MainActivity : AppCompatActivity() {
3024

3125
charactersAdapter = CharactersAdapter()
3226
var recyclerView = binding.rvCharacters
33-
recyclerView.layoutManager = LinearLayoutManager(this,RecyclerView.VERTICAL,false)
27+
recyclerView.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
3428
recyclerView.adapter = charactersAdapter
3529

36-
charactersViewModel.fetchCharacters.observe(this){
37-
charactersAdapter.saveData(it.data)
30+
charactersViewModel.fetchCharacters.observe(this) {
31+
charactersAdapter.saveData(it.data)
3832
}
39-
charactersViewModel.errorResponse.observe(this){errorMessage ->
40-
Snackbar.make(binding.root,errorMessage.toString(),Snackbar.LENGTH_SHORT).show()
33+
charactersViewModel.errorResponse.observe(this) { errorMessage ->
34+
Snackbar.make(binding.root, errorMessage.toString(), Snackbar.LENGTH_SHORT).show()
4135
}
4236
charactersViewModel.getCharacters()
4337
}
522 KB
Loading

app/src/main/res/values-night/themes.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
22
<!-- Base application theme. -->
3-
<style name="Theme.Diff_Utils_Recyclerview_Example" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
3+
<style name="Theme.Diff_Utils_Recyclerview_Example" parent="Theme.MaterialComponents.Light.NoActionBar">
44
<!-- Primary brand color. -->
5-
<item name="colorPrimary">@color/purple_200</item>
6-
<item name="colorPrimaryVariant">@color/purple_700</item>
5+
<item name="colorPrimary">@color/white</item>
6+
<item name="colorPrimaryVariant">@color/black</item>
77
<item name="colorOnPrimary">@color/black</item>
88
<!-- Secondary brand color. -->
99
<item name="colorSecondary">@color/teal_200</item>

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="purple_200">#FFBB86FC</color>
4-
<color name="purple_500">#FF6200EE</color>
5-
<color name="purple_700">#FF3700B3</color>
63
<color name="teal_200">#FF03DAC5</color>
74
<color name="teal_700">#FF018786</color>
85
<color name="black">#FF000000</color>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
22
<!-- Base application theme. -->
3-
<style name="Theme.Diff_Utils_Recyclerview_Example" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
3+
<style name="Theme.Diff_Utils_Recyclerview_Example" parent="Theme.MaterialComponents.Light.NoActionBar">
44
<!-- Primary brand color. -->
5-
<item name="colorPrimary">@color/purple_500</item>
6-
<item name="colorPrimaryVariant">@color/purple_700</item>
5+
<item name="colorPrimary">@color/white</item>
6+
<item name="colorPrimaryVariant">@color/black</item>
77
<item name="colorOnPrimary">@color/white</item>
88
<!-- Secondary brand color. -->
99
<item name="colorSecondary">@color/teal_200</item>

0 commit comments

Comments
 (0)