parent
4479b936ba
commit
9eedabc48d
@ -0,0 +1,43 @@ |
||||
package io.legado.app.base |
||||
|
||||
import android.view.Menu |
||||
import android.view.MenuInflater |
||||
import android.view.MenuItem |
||||
import androidx.appcompat.view.SupportMenuInflater |
||||
import androidx.appcompat.widget.Toolbar |
||||
import androidx.fragment.app.Fragment |
||||
import io.legado.app.utils.setIconColor |
||||
|
||||
abstract class BaseFragment(contentLayoutId: Int = 0) : Fragment(contentLayoutId) { |
||||
|
||||
var supportToolbar: Toolbar? = null |
||||
private set |
||||
|
||||
val menuInflater: MenuInflater |
||||
get() = SupportMenuInflater(requireContext()) |
||||
|
||||
|
||||
fun setSupportToolbar(toolbar: Toolbar) { |
||||
supportToolbar = toolbar |
||||
supportToolbar?.let { |
||||
it.menu.apply { |
||||
setIconColor(requireContext()) |
||||
onCompatCreateOptionsMenu(this) |
||||
} |
||||
|
||||
it.setOnMenuItemClickListener { item -> |
||||
onCompatOptionsItemSelected(item) |
||||
true |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
open fun onCompatCreateOptionsMenu(menu: Menu) { |
||||
} |
||||
|
||||
open fun onCompatOptionsItemSelected(item: MenuItem) { |
||||
} |
||||
|
||||
//TODO |
||||
} |
@ -1,28 +1,20 @@ |
||||
package io.legado.app.ui.main.bookshelf |
||||
|
||||
import android.os.Bundle |
||||
import android.util.Log |
||||
import android.view.MenuItem |
||||
import android.view.Menu |
||||
import android.view.View |
||||
import androidx.appcompat.widget.Toolbar |
||||
import androidx.fragment.app.Fragment |
||||
import io.legado.app.App |
||||
import io.legado.app.R |
||||
import io.legado.app.utils.setIconColor |
||||
import io.legado.app.base.BaseFragment |
||||
import kotlinx.android.synthetic.main.view_titlebar.* |
||||
|
||||
class BookshelfFragment : Fragment(R.layout.fragment_bookshelf), Toolbar.OnMenuItemClickListener { |
||||
class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
Log.e("TAG", "BookshelfFragment") |
||||
toolbar.inflateMenu(R.menu.bookshelf) |
||||
toolbar.menu.setIconColor(App.INSTANCE) |
||||
toolbar.setOnMenuItemClickListener(this) |
||||
setSupportToolbar(toolbar) |
||||
} |
||||
|
||||
override fun onMenuItemClick(item: MenuItem?): Boolean { |
||||
return false |
||||
override fun onCompatCreateOptionsMenu(menu: Menu) { |
||||
menuInflater.inflate(R.menu.bookshelf, menu) |
||||
} |
||||
|
||||
|
||||
|
@ -1,28 +1,25 @@ |
||||
package io.legado.app.ui.main.booksource |
||||
|
||||
import android.os.Bundle |
||||
import android.util.Log |
||||
import android.view.Menu |
||||
import android.view.MenuItem |
||||
import android.view.View |
||||
import androidx.appcompat.widget.Toolbar |
||||
import androidx.fragment.app.Fragment |
||||
import io.legado.app.App |
||||
import io.legado.app.R |
||||
import io.legado.app.utils.setIconColor |
||||
import io.legado.app.base.BaseFragment |
||||
import kotlinx.android.synthetic.main.view_titlebar.* |
||||
|
||||
class BookSourceFragment : Fragment(R.layout.fragment_book_source), Toolbar.OnMenuItemClickListener { |
||||
class BookSourceFragment : BaseFragment(R.layout.fragment_book_source) { |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
Log.e("TAG", "BookSourceFragment") |
||||
toolbar.inflateMenu(R.menu.book_source) |
||||
toolbar.menu.setIconColor(App.INSTANCE) |
||||
toolbar.setOnMenuItemClickListener(this) |
||||
setSupportToolbar(toolbar) |
||||
} |
||||
|
||||
override fun onMenuItemClick(item: MenuItem?): Boolean { |
||||
return false |
||||
override fun onCompatCreateOptionsMenu(menu: Menu) { |
||||
menuInflater.inflate(R.menu.book_source, menu) |
||||
} |
||||
|
||||
override fun onCompatOptionsItemSelected(item: MenuItem) { |
||||
|
||||
} |
||||
|
||||
} |
@ -1,28 +1,21 @@ |
||||
package io.legado.app.ui.main.findbook |
||||
|
||||
import android.os.Bundle |
||||
import android.util.Log |
||||
import android.view.Menu |
||||
import android.view.MenuItem |
||||
import android.view.View |
||||
import androidx.appcompat.widget.Toolbar |
||||
import androidx.fragment.app.Fragment |
||||
import io.legado.app.App |
||||
import io.legado.app.R |
||||
import io.legado.app.utils.setIconColor |
||||
import io.legado.app.base.BaseFragment |
||||
import kotlinx.android.synthetic.main.view_titlebar.* |
||||
|
||||
class FindBookFragment : Fragment(R.layout.fragment_find_book), Toolbar.OnMenuItemClickListener { |
||||
class FindBookFragment : BaseFragment(R.layout.fragment_find_book) { |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
Log.e("TAG", "FindBookFragment") |
||||
toolbar.inflateMenu(R.menu.find_book) |
||||
toolbar.menu.setIconColor(App.INSTANCE) |
||||
toolbar.setOnMenuItemClickListener(this) |
||||
setSupportToolbar(toolbar) |
||||
} |
||||
|
||||
override fun onMenuItemClick(item: MenuItem?): Boolean { |
||||
return false |
||||
override fun onCompatCreateOptionsMenu(menu: Menu) { |
||||
menuInflater.inflate(R.menu.find_book, menu) |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue