pull/32/head
parent
f9ebd4ac8d
commit
746dd05a9f
@ -1,2 +1,57 @@ |
||||
package io.legado.app.ui.sourcedebug |
||||
|
||||
import android.os.Bundle |
||||
import android.view.View |
||||
import androidx.appcompat.widget.SearchView |
||||
import androidx.lifecycle.AndroidViewModel |
||||
import androidx.recyclerview.widget.LinearLayoutManager |
||||
import io.legado.app.R |
||||
import io.legado.app.base.BaseActivity |
||||
import io.legado.app.utils.getViewModel |
||||
import kotlinx.android.synthetic.main.activity_source_debug.* |
||||
import kotlinx.android.synthetic.main.view_title_bar.* |
||||
|
||||
class SourceDebugActivity : BaseActivity<AndroidViewModel>() { |
||||
override val viewModel: AndroidViewModel |
||||
get() = getViewModel(AndroidViewModel::class.java) |
||||
override val layoutID: Int |
||||
get() = R.layout.activity_source_debug |
||||
|
||||
private lateinit var adapter: SourceDebugAdapter |
||||
|
||||
override fun onViewModelCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) { |
||||
initRecyclerView() |
||||
initSearchView() |
||||
} |
||||
|
||||
private fun initRecyclerView() { |
||||
adapter = SourceDebugAdapter() |
||||
recycler_view.layoutManager = LinearLayoutManager(this) |
||||
recycler_view.adapter = adapter |
||||
} |
||||
|
||||
private fun initSearchView() { |
||||
search_view.visibility = View.VISIBLE |
||||
search_view.onActionViewExpanded() |
||||
search_view.isSubmitButtonEnabled = true |
||||
search_view.queryHint = getString(R.string.search_book_key) |
||||
search_view.clearFocus() |
||||
search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener { |
||||
override fun onQueryTextSubmit(query: String?): Boolean { |
||||
startSearch(query ?: "我的") |
||||
return true |
||||
} |
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean { |
||||
return false |
||||
} |
||||
}) |
||||
} |
||||
|
||||
private fun startSearch(key: String) { |
||||
adapter.logList.clear() |
||||
adapter.notifyDataSetChanged() |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,32 @@ |
||||
package io.legado.app.ui.sourcedebug |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import io.legado.app.R |
||||
import kotlinx.android.synthetic.main.item_source_debug.view.* |
||||
|
||||
class SourceDebugAdapter : RecyclerView.Adapter<SourceDebugAdapter.MyViewHolder>() { |
||||
|
||||
val logList = arrayListOf<String>() |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { |
||||
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_source_debug, parent, false)) |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
||||
holder.bind(logList[position]) |
||||
} |
||||
|
||||
override fun getItemCount(): Int { |
||||
return logList.size |
||||
} |
||||
|
||||
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
||||
|
||||
fun bind(log: String) = with(itemView) { |
||||
text_view.text = log |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:id="@+id/ll_content" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
|
||||
<io.legado.app.ui.widget.TitleBar |
||||
android:id="@+id/title_bar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
app:fitStatusBar="false" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:title="书源编辑" /> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recycler_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" /> |
||||
|
||||
</LinearLayout> |
@ -0,0 +1,5 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:id="@+id/text_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" /> |
Loading…
Reference in new issue