mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-23 13:01:50 +01:00
Make sure icons have a 1:1 ratio (#80)
* Make sure icons have a 1:1 ratio * Use recyclerview padding to increase grid edge margins * Fix race condition in searching roms * Use notify insert for adapter
This commit is contained in:
parent
392a1ac437
commit
f72b81fcea
@ -66,10 +66,9 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
|
||||
romFile.use {
|
||||
val entry = romFile.getAppEntry(file.uri)
|
||||
|
||||
val finalFoundCurrent = foundCurrent
|
||||
runOnUiThread {
|
||||
if (!foundCurrent) {
|
||||
adapter.addHeader(romFormat.name)
|
||||
}
|
||||
if (!finalFoundCurrent) adapter.addHeader(romFormat.name)
|
||||
|
||||
adapter.addItem(AppItem(entry))
|
||||
}
|
||||
@ -335,5 +334,11 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
|
||||
if (layoutType != adapter.layoutType) {
|
||||
setupAppList()
|
||||
}
|
||||
|
||||
val gridCardMagin = resources.getDimensionPixelSize(R.dimen.app_card_margin_half)
|
||||
when (layoutType) {
|
||||
LayoutType.List -> app_list.setPadding(0, 0, 0, 0)
|
||||
LayoutType.Grid, LayoutType.GridCompact -> app_list.setPadding(gridCardMagin, 0, gridCardMagin, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
@ -123,18 +122,6 @@ internal class AppAdapter(val layoutType : LayoutType, private val gridSpan : In
|
||||
setOnClickListener { onClick.invoke(item) }
|
||||
setOnLongClickListener { true.also { onLongClick.invoke(item) } }
|
||||
}
|
||||
|
||||
// Increase margin of edges to avoid huge gap in between items
|
||||
if (layoutType == LayoutType.Grid || layoutType == LayoutType.GridCompact) {
|
||||
holder.itemView.layoutParams = LinearLayout.LayoutParams(holder.itemView.layoutParams.width, holder.itemView.layoutParams.height).apply {
|
||||
if (position % gridSpan == 0) {
|
||||
marginStart = holder.itemView.resources.getDimensionPixelSize(R.dimen.app_card_margin) * 2
|
||||
} else if (position % gridSpan == gridSpan - 1) {
|
||||
marginEnd = holder.itemView.resources.getDimensionPixelSize(R.dimen.app_card_margin) * 2
|
||||
}
|
||||
}
|
||||
holder.itemView.requestLayout()
|
||||
}
|
||||
} else if (item is BaseHeader) {
|
||||
val holder = viewHolder as HeaderViewHolder
|
||||
|
||||
|
@ -64,7 +64,7 @@ abstract class HeaderAdapter<ItemType : BaseItem?, HeaderType : BaseHeader?, Vie
|
||||
filter.filter(searchTerm)
|
||||
} else {
|
||||
visibleArray.add(elementArray.size - 1)
|
||||
notifyDataSetChanged()
|
||||
notifyItemInserted(visibleArray.size)
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,9 +73,10 @@ abstract class HeaderAdapter<ItemType : BaseItem?, HeaderType : BaseHeader?, Vie
|
||||
*/
|
||||
fun addHeader(header : HeaderType) {
|
||||
elementArray.add(header)
|
||||
if (searchTerm.isEmpty())
|
||||
if (searchTerm.isEmpty()) {
|
||||
visibleArray.add(elementArray.size - 1)
|
||||
notifyDataSetChanged()
|
||||
notifyItemInserted(visibleArray.size)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +138,7 @@ abstract class HeaderAdapter<ItemType : BaseItem?, HeaderType : BaseHeader?, Vie
|
||||
/**
|
||||
* This returns an instance of the filter object which is used to search for items in the view
|
||||
*/
|
||||
override fun getFilter() : Filter = object : Filter() {
|
||||
override fun getFilter() = object : Filter() {
|
||||
/**
|
||||
* We use Jaro-Winkler distance for string similarity (https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance)
|
||||
*/
|
||||
|
@ -92,6 +92,7 @@ internal class LogAdapter internal constructor(val context : Context, val compac
|
||||
ItemViewHolder(view, view.findViewById(R.id.text_title), view.findViewById(R.id.text_subtitle))
|
||||
}
|
||||
}
|
||||
|
||||
ElementType.Header -> {
|
||||
HeaderViewHolder(view, view.findViewById(R.id.text_title))
|
||||
}
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/app_item_grid"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="@dimen/app_card_margin_half"
|
||||
android:clickable="true"
|
||||
@ -19,7 +19,7 @@
|
||||
app:cardUseCompatPadding="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="155dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical">
|
||||
@ -27,7 +27,8 @@
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="155dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@string/icon"
|
||||
tools:src="@drawable/default_icon" />
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/app_item_grid"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="@dimen/app_card_margin_half"
|
||||
@ -19,15 +19,14 @@
|
||||
app:cardUseCompatPadding="true">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="155dp"
|
||||
android:layout_height="155dp">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentTop="false"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@string/icon"
|
||||
android:foreground="@drawable/background_gradient"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
@ -38,7 +37,7 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:alpha="242.25"
|
||||
android:ellipsize="marquee"
|
||||
@ -51,14 +50,13 @@
|
||||
android:textStyle="bold"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintBottom_toTopOf="@id/text_subtitle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@id/icon"
|
||||
app:layout_constraintStart_toStartOf="@id/icon"
|
||||
tools:text="Title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:alpha="242.25"
|
||||
@ -70,11 +68,9 @@
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="@android:color/white"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@id/icon"
|
||||
app:layout_constraintEnd_toEndOf="@id/icon"
|
||||
app:layout_constraintStart_toStartOf="@id/icon"
|
||||
tools:text="Subtitle" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/log_list"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fastScrollEnabled="true"
|
||||
android:transcriptMode="normal"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
@ -14,6 +14,7 @@
|
||||
android:id="@+id/app_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
<emu.skyline.views.CustomLinearLayout
|
||||
|
@ -1,18 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:textColor="?colorSecondary"
|
||||
android:textSize="15sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user