Tidy code
This commit is contained in:
parent
5d29048e91
commit
49b50ef4ca
6 changed files with 18 additions and 25 deletions
|
|
@ -11,4 +11,4 @@ fun String.showToast(
|
|||
|
||||
fun Int.showToast(context: Context = ToDoApplication.context, duration: Int = Toast.LENGTH_SHORT) {
|
||||
Toast.makeText(context, this, duration).show()
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,6 @@ package cn.super12138.todo.views.main
|
|||
// 2023.11.18立项
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import cn.super12138.todo.R
|
||||
import cn.super12138.todo.ToDoApplication
|
||||
|
|
@ -21,7 +19,19 @@ class MainActivity : BaseActivity() {
|
|||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.toolbar)
|
||||
binding.toolbar.setOnMenuItemClickListener { menuItem ->
|
||||
when (menuItem.itemId) {
|
||||
R.id.item_settings -> {
|
||||
val intent = Intent(ToDoApplication.context, SettingsActivity::class.java)
|
||||
startActivity(intent)
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
// setSupportActionBar(binding.toolbar)
|
||||
/*val pref = getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isFirstUse = pref.getBoolean("first_use", false)
|
||||
|
||||
|
|
@ -46,19 +56,4 @@ class MainActivity : BaseActivity() {
|
|||
"2" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.main, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.item_settings -> {
|
||||
val intent = Intent(ToDoApplication.context, SettingsActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -107,7 +107,6 @@ class ToDoFragment : Fragment() {
|
|||
put("context", todoContext)
|
||||
}
|
||||
Repository.insertData(todoData)
|
||||
// dbHelper.writableDatabase.insert("ToDo", null, todoData)
|
||||
|
||||
binding.todoList.adapter?.notifyItemInserted(todoList.size + 1)
|
||||
|
||||
|
|
@ -126,7 +125,6 @@ class ToDoFragment : Fragment() {
|
|||
.setPositiveButton(R.string.ok) { dialog, which ->
|
||||
todoList.clear()
|
||||
Repository.deleteData(true, null)
|
||||
// dbHelper.writableDatabase.delete("ToDo", null, null)
|
||||
binding.todoList.adapter?.notifyItemRangeRemoved(0, todoList.size + 1)
|
||||
|
||||
progressViewModel.updateProgress()
|
||||
|
|
@ -163,6 +161,7 @@ class ToDoFragment : Fragment() {
|
|||
binding.addItem.show()
|
||||
}
|
||||
})
|
||||
|
||||
todoViewModel.refreshData.observe(viewLifecycleOwner, Observer {
|
||||
binding.todoList.adapter?.notifyItemInserted(todoList.size + 1)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:menu="@menu/main"
|
||||
app:title="@string/app_name" />
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
|
@ -35,13 +36,11 @@
|
|||
android:layout_weight="3"
|
||||
android:minHeight="160dp" />
|
||||
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/todo_frag"
|
||||
android:name="cn.super12138.todo.views.todo.ToDoFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="2" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
@ -56,6 +56,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:contentDescription="@string/app_name"
|
||||
app:srcCompat="@drawable/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:menu="@menu/main"
|
||||
app:title="@string/app_name" />
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
|
@ -35,13 +36,11 @@
|
|||
android:layout_weight="2"
|
||||
android:minHeight="160dp" />
|
||||
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/todo_frag"
|
||||
android:name="cn.super12138.todo.views.todo.ToDoFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="3" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
Loading…
Reference in a new issue