Skip to content

Commit

Permalink
added gridlayoutmanager for wide screens
Browse files Browse the repository at this point in the history
bump version to 1.1.0
  • Loading branch information
llopisdon committed Aug 21, 2021
1 parent ae55fff commit e6f1d43
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0.1"
versionName "1.1.0"

def apodApiKey = project.findProperty("apodktm_nasa_apod_api_key") ?: 'DEMO_KEY'
println("APOD KEY: $apodApiKey")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.machineinteractive.apodktm

import android.content.res.Configuration
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
Expand All @@ -14,10 +15,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.*
import coil.imageLoader
import coil.load
import coil.request.ImageRequest
Expand Down Expand Up @@ -64,8 +62,18 @@ class ApodsListFragment : Fragment(), ApodAdapter.Listener {

adapter = ApodAdapter(this)

val isWideScreen = resources.getBoolean(R.bool.wide_screen)
val isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
val useGridLayout = isLandscape || isWideScreen

binding.run {
recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.layoutManager = if (useGridLayout) {
val spanCount = if (isLandscape && !isWideScreen) 2 else 3
GridLayoutManager(requireContext(), spanCount)
} else {
LinearLayoutManager(requireContext())
}

recyclerView.adapter = adapter
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#25FF0B</color>
<bool name="wide_screen">true</bool>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/bool.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="wide_screen">false</bool>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<color name="ic_launcher_background">#25FF0B</color>

<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
Expand Down

0 comments on commit e6f1d43

Please sign in to comment.