Skip to content

Commit 36161c3

Browse files
committed
refactor
1 parent 7138eb5 commit 36161c3

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.hoc081098.firestore_coroutinesflow
2+
3+
import android.content.Context
4+
import android.content.res.Configuration.ORIENTATION_PORTRAIT
5+
6+
val Context.isOrientationPortrait get() = this.resources.configuration.orientation == ORIENTATION_PORTRAIT

app/src/main/java/com/hoc081098/firestore_coroutinesflow/ui/main/MainFragment.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import androidx.fragment.app.Fragment
88
import androidx.lifecycle.observe
99
import androidx.navigation.fragment.findNavController
1010
import androidx.recyclerview.widget.GridLayoutManager
11-
import com.hoc081098.firestore_coroutinesflow.GlideApp
12-
import com.hoc081098.firestore_coroutinesflow.Lce
13-
import com.hoc081098.firestore_coroutinesflow.R
11+
import com.hoc081098.firestore_coroutinesflow.*
1412
import com.hoc081098.firestore_coroutinesflow.databinding.MainFragmentBinding
15-
import com.hoc081098.firestore_coroutinesflow.viewBinding
1613
import kotlinx.coroutines.ExperimentalCoroutinesApi
1714
import org.koin.androidx.viewmodel.ext.android.viewModel
1815

@@ -32,10 +29,14 @@ class MainFragment : Fragment(R.layout.main_fragment) {
3229

3330
binding.recyclerView.run {
3431
setHasFixedSize(true)
35-
layoutManager = GridLayoutManager(context, 2)
32+
layoutManager = GridLayoutManager(context, if (context.isOrientationPortrait) 2 else 3)
3633
adapter = categoryAdapter
3734
}
3835

36+
bindVM(categoryAdapter)
37+
}
38+
39+
private fun bindVM(categoryAdapter: CategoryAdapter) {
3940
vm.categoriesData.observe(owner = viewLifecycleOwner) { state ->
4041
when (state) {
4142
Lce.Loading -> {
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/main"
56
android:layout_width="match_parent"
6-
android:layout_height="match_parent">
7+
android:layout_height="match_parent"
8+
tools:context=".ui.main.MainFragment">
79

8-
<TextView
9-
android:id="@+id/textView2"
10+
<androidx.recyclerview.widget.RecyclerView
11+
android:id="@+id/recyclerView"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
tools:listitem="@layout/category_item" />
15+
16+
<ProgressBar
17+
android:id="@+id/progressBar"
18+
style="?android:attr/progressBarStyle"
1019
android:layout_width="wrap_content"
1120
android:layout_height="wrap_content"
12-
android:text="TextView"
13-
tools:layout_editor_absoluteX="137dp"
14-
tools:layout_editor_absoluteY="194dp" />
15-
</androidx.constraintlayout.widget.ConstraintLayout>
21+
app:layout_constraintBottom_toBottomOf="parent"
22+
app:layout_constraintEnd_toEndOf="parent"
23+
app:layout_constraintHorizontal_bias="0.5"
24+
app:layout_constraintStart_toStartOf="parent"
25+
app:layout_constraintTop_toTopOf="parent" />
26+
27+
<androidx.appcompat.widget.AppCompatTextView
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:text="Empty list"
31+
android:id="@+id/emptyError"
32+
android:textAlignment="center"
33+
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
34+
app:layout_constraintBottom_toBottomOf="parent"
35+
app:layout_constraintEnd_toEndOf="parent"
36+
app:layout_constraintHorizontal_bias="0.5"
37+
app:layout_constraintStart_toStartOf="parent"
38+
app:layout_constraintTop_toTopOf="parent">
39+
40+
</androidx.appcompat.widget.AppCompatTextView>
41+
42+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)