-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor classes to a more package-by-feature approach * Fix a potential NPE * Auto-fit grid. Fixes #45. Fixes #46. * Fixes a visual issue
- Loading branch information
Showing
11 changed files
with
61 additions
and
38 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
app/src/main/kotlin/app/gaming/AutoFitStaggeredGridRecyclerView.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package app.gaming | ||
|
||
import android.content.Context | ||
import android.support.annotation.Px | ||
import android.support.v7.widget.RecyclerView | ||
import android.support.v7.widget.StaggeredGridLayoutManager | ||
import android.util.AttributeSet | ||
import org.jorge.ms.app.R | ||
import util.android.ext.getDimension | ||
|
||
/** | ||
* A recycler view that automatically attaches to itself a GridLayoutManager and performs auto-fit | ||
* with its elements. | ||
* @param context The context | ||
* @param attrs The attributes | ||
* @see <a href="http://blog.sqisland.com/2014/12/recyclerview-autofit-grid.html"> | ||
* Square Island: RecyclerView: Autofit grid</a> | ||
*/ | ||
internal class AutoFitStaggeredGridRecyclerView(context: Context, attrs: AttributeSet?) | ||
: RecyclerView(context, attrs) { | ||
private @Px val columnWidth: Int | ||
|
||
init { | ||
@Px val defaultColumnWidth = context.getDimension(R.dimen.default_column_width).toInt() | ||
if (attrs != null) { | ||
val attrsArray = intArrayOf(android.R.attr.columnWidth) | ||
val typedArray = context.obtainStyledAttributes(attrs, attrsArray) | ||
columnWidth = typedArray.getDimensionPixelSize(0, defaultColumnWidth) | ||
typedArray.recycle() | ||
} else { | ||
columnWidth = defaultColumnWidth | ||
} | ||
layoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL) | ||
} | ||
|
||
override fun onMeasure(widthSpec: Int, heightSpec: Int) { | ||
super.onMeasure(widthSpec, heightSpec) | ||
if (columnWidth > 0) { | ||
val spanCount = Math.max(1, measuredWidth / columnWidth) | ||
(layoutManager as StaggeredGridLayoutManager).spanCount = spanCount | ||
} | ||
} | ||
} |
This file contains 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
2 changes: 1 addition & 1 deletion
2
.../kotlin/app/widget/LoadableContentView.kt → .../kotlin/app/gaming/LoadableContentView.kt
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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