This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class Status { | |
SUCCESS, | |
ERROR, | |
LOADING | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".ui.main.view.MainActivity"> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/superhero_recycler" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:card_view="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content"> | |
<androidx.cardview.widget.CardView | |
android:id="@+id/card_view" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainAdapter(private val result: ArrayList<Hero>, | |
private val clickListener: (Long) -> Unit): | |
RecyclerView.Adapter<MainAdapter.DataViewHolder>() { | |
class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
fun bind(hero: Hero, clickListener: (Long) -> Unit ) { | |
itemView.apply { | |
superheroName.text = hero.name | |
Glide.with(superheroImage.context) | |
.load(hero.image.lg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
private lateinit var viewModel: MainViewModel | |
private lateinit var adapter: MainAdapter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainViewModel(private val mainRepository: MainRepository) : ViewModel() { | |
fun getSuperHeroes() = liveData(Dispatchers.IO) { | |
emit(Resource.loading(data = null)) | |
try { | |
emit(Resource.success(data = mainRepository.getSuperHeroes())) | |
} catch (exception: Exception) { | |
emit(Resource.error(data = null, message = exception.message ?: "Error Occurred!")) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewModelFactory(private val apiHelper: ApiHelper) : ViewModelProvider.Factory { | |
override fun <T : ViewModel?> create(modelClass: Class<T>): T { | |
if (modelClass.isAssignableFrom(MainViewModel::class.java)) { | |
return MainViewModel(MainRepository(apiHelper)) as T | |
} | |
throw IllegalArgumentException("Unknown class name") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Preference DataStore | |
implementation "androidx.datastore:datastore-preferences:1.0.0-alpha04" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<com.google.android.material.chip.ChipGroup | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_marginBottom="15dp" | |
app:singleLine="true" | |
android:id="@+id/chip_group" | |
app:singleSelection="true"> | |
<!-- app:checkedChip="@id/yes"--> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style name="checkable_chip" parent="Widget.MaterialComponents.Chip.Choice"> | |
<item name="android:checkable">true</item> | |
<item name="android:textColor">@color/chip_colors_text</item> | |
<item name="chipBackgroundColor">@color/chip_colors</item> | |
<item name="checkedIcon">@null</item> | |
<item name="chipIconVisible">false</item> | |
<item name="chipStrokeColor">@color/purple</item> | |
<item name="chipStrokeWidth">1dp</item> | |
<item name="ensureMinTouchTargetSize">true</item> | |
<item name="checkedIconVisible">false</item> |