Skip to content

Commit

Permalink
Tidy code
Browse files Browse the repository at this point in the history
  • Loading branch information
Super12138 committed Jan 6, 2024
1 parent 5d29048 commit 49b50ef
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/cn/super12138/todo/utils/Toast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
31 changes: 13 additions & 18 deletions app/src/main/kotlin/cn/super12138/todo/views/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()
Expand Down Expand Up @@ -163,6 +161,7 @@ class ToDoFragment : Fragment() {
binding.addItem.show()
}
})

todoViewModel.refreshData.observe(viewLifecycleOwner, Observer {
binding.todoList.adapter?.notifyItemInserted(todoList.size + 1)
})
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>

0 comments on commit 49b50ef

Please sign in to comment.