diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 47a023576..d04315dd6 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -5,27 +5,24 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.ActionBarDrawerToggle -import androidx.appcompat.app.AppCompatActivity import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.ViewModelProviders import com.google.android.material.navigation.NavigationView import io.legado.app.R +import io.legado.app.base.BaseActivity import io.legado.app.ui.search.SearchActivity -import io.legado.app.utils.longSnackbar import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.app_bar_main.* -import org.jetbrains.anko.startActivity -class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener { +class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedListener { + override val viewModel: MainViewModel + get() = ViewModelProvider.AndroidViewModelFactory.getInstance(application).create(MainViewModel::class.java) + override val layoutID: Int + get() = R.layout.activity_main - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + override fun onViewModelCreated(viewModel: MainViewModel, savedInstanceState: Bundle?) { setSupportActionBar(toolbar) - fab.setOnClickListener { startActivity(Intent(this, SearchActivity::class.java)) } val toggle = ActionBarDrawerToggle( @@ -37,7 +34,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte toggle.syncState() nav_view.setNavigationItemSelectedListener(this) - val mainViewModel = ViewModelProviders.of(this).get(MainViewModel::class.java) } override fun onBackPressed() { @@ -55,14 +51,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte return true } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - return when (item.itemId) { - R.id.action_settings -> true - else -> super.onOptionsItemSelected(item) - } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + return super.onCompatOptionsItemSelected(item) } override fun onNavigationItemSelected(item: MenuItem): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/main/MainDataBinding.kt b/app/src/main/java/io/legado/app/ui/main/MainDataBinding.kt new file mode 100644 index 000000000..7c950c419 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/MainDataBinding.kt @@ -0,0 +1,63 @@ +package io.legado.app.ui.main + +import android.view.View +import androidx.databinding.ViewDataBinding + +class MainDataBinding(bindingComponent: Any?, root: View?, localFieldCount: Int) : + ViewDataBinding(bindingComponent, root, localFieldCount) { + /** + * Set a value value in the Binding class. + * + * + * Typically, the developer will be able to call the subclass's set method directly. For + * example, if there is a variable `x` in the Binding, a `setX` method + * will be generated. However, there are times when the specific subclass of ViewDataBinding + * is unknown, so the generated method cannot be discovered without reflection. The + * setVariable call allows the values of variables to be set without reflection. + * + * @param variableId the BR id of the variable to be set. For example, if the variable is + * `x`, then variableId will be `BR.x`. + * @param value The new value of the variable to be set. + * @return `true` if the variable is declared or used in the binding or + * `false` otherwise. + */ + override fun setVariable(variableId: Int, value: Any?): Boolean { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + /** + * @hide + */ + override fun executeBindings() { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + /** + * Called when an observed object changes. Sets the appropriate dirty flag if applicable. + * @param localFieldId The index into mLocalFieldObservers that this Object resides in. + * @param object The object that has changed. + * @param fieldId The BR ID of the field being changed or _all if + * no specific field is being notified. + * @return true if this change should cause a change to the UI. + * @hide + */ + override fun onFieldChange(localFieldId: Int, `object`: Any?, fieldId: Int): Boolean { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + /** + * Invalidates all binding expressions and requests a new rebind to refresh UI. + */ + override fun invalidateAll() { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + /** + * Returns whether the UI needs to be refresh to represent the current data. + * + * @return true if any field has changed and the binding should be evaluated. + */ + override fun hasPendingBindings(): Boolean { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/MainModel.kt b/app/src/main/java/io/legado/app/ui/main/MainModel.kt deleted file mode 100644 index 86da567f6..000000000 --- a/app/src/main/java/io/legado/app/ui/main/MainModel.kt +++ /dev/null @@ -1,5 +0,0 @@ -package io.legado.app.ui.main - -class MainModel { - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt index f583abc6f..2d4f64ba2 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt @@ -4,7 +4,6 @@ import android.os.Bundle import androidx.lifecycle.ViewModelProvider import io.legado.app.R import io.legado.app.base.BaseActivity -import io.legado.app.search.SearchDataBinding class SearchActivity : BaseActivity() { @@ -15,7 +14,6 @@ class SearchActivity : BaseActivity() { get() = R.layout.activity_search override fun onViewModelCreated(viewModel: SearchViewModel, savedInstanceState: Bundle?) { - dataBinding.searchViewModel = viewModel } diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index 486b05137..a7dfaad9b 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -1,7 +1,7 @@ - +