Skip to content

Commit

Permalink
Fix indication of checking state in navigation drawer, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
geckour committed Dec 27, 2017
1 parent b249462 commit 7221f05
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class MainActivity : RxAppCompatActivity(), NavigationView.OnNavigationItemSelec

binding.appBarMain?.fabLeft?.hide()

binding.navView.setNavigationItemSelectedListener(this)
binding.navView.apply {
setNavigationItemSelectedListener(this@MainActivity)
setCheckedItem(R.id.nav_problem)
}

if (savedInstanceState == null) {
val fragment = ProblemsFragment.newInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import retrofit2.converter.gson.GsonConverterFactory
class ApiClient {

companion object {
private val baseUrl = "172.16.21.15:8080"
private val baseUrl = "172.16.21.15:8080/pm"
}

private val service = Retrofit.Builder().client(OkHttpProvider.client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class DraftProblemsFragment: RxFragment() {
}

binding.textIndicateEmpty.setText(R.string.problem_fragment_message_empty_draft)

(activity as MainActivity).binding.navView.menu.findItem(R.id.nav_draft).isChecked = true
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ class EditorFragment: RxFragment(), MyAlertDialogFragment.IListener, Pikkel by P
}
} else false
}

(activity as MainActivity).binding.navView.menu.findItem(R.id.nav_editor).isChecked = true
}

override fun onAttach(context: Context?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class ProblemsFragment: RxFragment() {
}

binding.textIndicateEmpty.setText(R.string.problem_fragment_message_empty)

(activity as MainActivity).binding.navView.menu.findItem(R.id.nav_problem).isChecked = true
}

override fun onResume() {
Expand Down
51 changes: 29 additions & 22 deletions app/src/main/res/menu/activity_main_drawer.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="@string/nav_main">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_problem"
android:icon="@drawable/ic_menu_camera"
android:title="@string/nav_problem" />

<group android:checkableBehavior="single">
<item
android:id="@+id/nav_problem"
android:icon="@drawable/ic_menu_camera"
android:title="@string/nav_problem" />
<item
android:id="@+id/nav_draft"
android:icon="@drawable/ic_menu_gallery"
android:title="@string/nav_draft" />
<item
android:id="@+id/nav_editor"
android:icon="@drawable/ic_menu_slideshow"
android:title="@string/nav_editor" />
<item
android:id="@+id/nav_setting"
android:icon="@drawable/ic_menu_manage"
android:title="@string/nav_setting" />
<item
android:id="@+id/nav_draft"
android:icon="@drawable/ic_menu_gallery"
android:title="@string/nav_draft" />

<item android:title="@string/nav_other">
<menu>
<item
android:id="@+id/nav_editor"
android:icon="@drawable/ic_menu_slideshow"
android:title="@string/nav_editor" />
</group>
</menu>
</item>

<item android:title="@string/nav_other">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_search"
android:icon="@drawable/ic_search_black_24px"
android:title="@string/nav_search" />
</menu>
</item>
</group>

<item
android:id="@+id/nav_setting"
android:icon="@drawable/ic_menu_manage"
android:title="@string/nav_setting" />
</group>
</menu>
</item>
</menu>
8 changes: 1 addition & 7 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>
xmlns:app="http://schemas.android.com/apk/res-auto" />
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<string name="action_save">保存</string>
<string name="action_undo">取り消し</string>

<string name="nav_main">編集</string>
<string name="nav_problem">作成済みの問題</string>
<string name="nav_draft">下書き</string>
<string name="nav_editor">新規作成</string>
Expand Down

0 comments on commit 7221f05

Please sign in to comment.