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 |
package io.legado.app.ui.search |
||||||
|
|
||||||
import android.os.Bundle |
import android.os.Bundle |
||||||
import androidx.appcompat.app.AppCompatActivity |
import androidx.lifecycle.ViewModelProvider |
||||||
import io.legado.app.R |
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) |
Loading…
Reference in new issue