parent
2734464f5b
commit
7449a34bf8
@ -0,0 +1,2 @@ |
||||
package io.legado.app.data.entities |
||||
|
@ -0,0 +1,67 @@ |
||||
package io.legado.app.help |
||||
|
||||
import androidx.annotation.IntDef |
||||
import androidx.recyclerview.widget.GridLayoutManager |
||||
import androidx.recyclerview.widget.LinearLayoutManager |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager |
||||
|
||||
class LayoutManager private constructor() { |
||||
|
||||
interface LayoutManagerFactory { |
||||
fun create(recyclerView: RecyclerView): RecyclerView.LayoutManager |
||||
} |
||||
|
||||
@IntDef(LinearLayoutManager.HORIZONTAL, LinearLayoutManager.VERTICAL) |
||||
@Retention(AnnotationRetention.SOURCE) |
||||
annotation class Orientation |
||||
|
||||
companion object { |
||||
|
||||
|
||||
fun linear(): LayoutManagerFactory { |
||||
return object : LayoutManagerFactory { |
||||
override fun create(recyclerView: RecyclerView): RecyclerView.LayoutManager { |
||||
return LinearLayoutManager(recyclerView.context) |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
fun linear(@Orientation orientation: Int, reverseLayout: Boolean): LayoutManagerFactory { |
||||
return object : LayoutManagerFactory { |
||||
override fun create(recyclerView: RecyclerView): RecyclerView.LayoutManager { |
||||
return LinearLayoutManager(recyclerView.context, orientation, reverseLayout) |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
fun grid(spanCount: Int): LayoutManagerFactory { |
||||
return object : LayoutManagerFactory { |
||||
override fun create(recyclerView: RecyclerView): RecyclerView.LayoutManager { |
||||
return GridLayoutManager(recyclerView.context, spanCount) |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
fun grid(spanCount: Int, @Orientation orientation: Int, reverseLayout: Boolean): LayoutManagerFactory { |
||||
return object : LayoutManagerFactory { |
||||
override fun create(recyclerView: RecyclerView): RecyclerView.LayoutManager { |
||||
return GridLayoutManager(recyclerView.context, spanCount, orientation, reverseLayout) |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
fun staggeredGrid(spanCount: Int, @Orientation orientation: Int): LayoutManagerFactory { |
||||
return object : LayoutManagerFactory { |
||||
override fun create(recyclerView: RecyclerView): RecyclerView.LayoutManager { |
||||
return StaggeredGridLayoutManager(spanCount, orientation) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,13 +1,23 @@ |
||||
package io.legado.app.ui.search |
||||
|
||||
import android.os.Bundle |
||||
import androidx.appcompat.app.AppCompatActivity |
||||
import androidx.lifecycle.ViewModelProvider |
||||
import io.legado.app.R |
||||
import io.legado.app.base.BaseActivity |
||||
import io.legado.app.search.SearchDataBinding |
||||
|
||||
class SearchActivity : BaseActivity<SearchDataBinding, SearchViewModel>() { |
||||
|
||||
override val viewModel: SearchViewModel |
||||
get() = ViewModelProvider.AndroidViewModelFactory.getInstance(application).create(SearchViewModel::class.java) |
||||
|
||||
override val layoutID: Int |
||||
get() = R.layout.activity_search |
||||
|
||||
override fun onViewModelCreated(viewModel: SearchViewModel, savedInstanceState: Bundle?) { |
||||
dataBinding.searchViewModel = viewModel |
||||
|
||||
class SearchActivity : AppCompatActivity() { |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
setContentView(R.layout.activity_search) |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,6 @@ |
||||
package io.legado.app.ui.search |
||||
|
||||
import android.app.Application |
||||
import androidx.lifecycle.AndroidViewModel |
||||
|
||||
class SearchViewModel(application: Application) : AndroidViewModel(application) |
@ -1,9 +1,40 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context="io.legado.app.ui.search.SearchActivity"> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
<layout xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||
|
||||
<data class=".search.SearchDataBinding"> |
||||
<variable name="SearchViewModel" type="io.legado.app.ui.search.SearchViewModel"/> |
||||
</data> |
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context="io.legado.app.ui.search.SearchActivity"> |
||||
|
||||
<io.legado.app.ui.widget.TitleBar |
||||
android:id="@+id/titleBar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
/> |
||||
|
||||
<io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@id/titleBar"> |
||||
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/searchList" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"/> |
||||
|
||||
|
||||
</io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
|
||||
</layout> |
||||
|
||||
|
Loading…
Reference in new issue