add basic navigation drawer
This commit is contained in:
parent
4aaa0fbcdb
commit
37832f1d8b
|
@ -39,14 +39,20 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
def nav_version = "2.3.5"
|
||||||
|
def room_version = "2.4.0"
|
||||||
implementation 'androidx.core:core-ktx:1.7.0'
|
implementation 'androidx.core:core-ktx:1.7.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.4.0'
|
implementation 'androidx.appcompat:appcompat:1.4.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
|
implementation 'androidx.fragment:fragment-ktx:1.4.0'
|
||||||
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation "androidx.room:room-runtime:2.4.0"
|
implementation "androidx.room:room-runtime:$room_version"
|
||||||
|
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
|
||||||
|
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
|
||||||
|
implementation 'androidx.preference:preference-ktx:1.1.1'
|
||||||
implementation 'com.google.android.material:material:1.4.0'
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
kapt "androidx.room:room-compiler:2.4.0"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
|
|
|
@ -2,31 +2,22 @@ package dev.lowrespalmtree.comet
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
|
import androidx.navigation.ui.setupWithNavController
|
||||||
|
import com.google.android.material.navigation.NavigationView
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
|
||||||
|
|
||||||
@ExperimentalCoroutinesApi
|
@ExperimentalCoroutinesApi
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
Database.init(applicationContext) // TODO move to App Startup?
|
Database.init(applicationContext) // TODO move to App Startup?
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
supportFragmentManager.findFragmentById(R.id.nav_host_fragment)?.also { navHost ->
|
||||||
supportFragmentManager
|
findViewById<NavigationView>(R.id.drawer_navigation)?.apply {
|
||||||
.beginTransaction()
|
setupWithNavController((navHost as NavHostFragment).navController)
|
||||||
.add(R.id.main_content, PageViewFragment().apply { arguments = intent.extras })
|
|
||||||
.commit()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
|
||||||
// TODO pass to PageViewFragment
|
|
||||||
super.onBackPressed()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val TAG = "MainActivity"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -128,7 +128,7 @@ class PageViewFragment : Fragment(), ContentAdapter.ContentAdapterListener {
|
||||||
binding.contentProgressBar.show()
|
binding.contentProgressBar.show()
|
||||||
}
|
}
|
||||||
PageViewModel.State.RECEIVING -> {
|
PageViewModel.State.RECEIVING -> {
|
||||||
binding.appBar.setExpanded(true, true)
|
binding.appBarLayout.setExpanded(true, true)
|
||||||
binding.contentSwipeLayout.isRefreshing = false
|
binding.contentSwipeLayout.isRefreshing = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package dev.lowrespalmtree.comet
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
|
|
||||||
|
class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
|
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||||
|
}
|
||||||
|
}
|
7
app/src/main/res/anim/slide_in_left.xml
Normal file
7
app/src/main/res/anim/slide_in_left.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<translate android:fromXDelta="-50%p" android:toXDelta="0"
|
||||||
|
android:duration="@android:integer/config_mediumAnimTime"/>
|
||||||
|
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
|
||||||
|
android:duration="@android:integer/config_mediumAnimTime" />
|
||||||
|
</set>
|
7
app/src/main/res/anim/slide_in_right.xml
Normal file
7
app/src/main/res/anim/slide_in_right.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<translate android:fromXDelta="50%p" android:toXDelta="0"
|
||||||
|
android:duration="@android:integer/config_mediumAnimTime"/>
|
||||||
|
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
|
||||||
|
android:duration="@android:integer/config_mediumAnimTime" />
|
||||||
|
</set>
|
7
app/src/main/res/anim/slide_out_left.xml
Normal file
7
app/src/main/res/anim/slide_out_left.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<translate android:fromXDelta="0" android:toXDelta="-50%p"
|
||||||
|
android:duration="@android:integer/config_mediumAnimTime"/>
|
||||||
|
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
|
||||||
|
android:duration="@android:integer/config_mediumAnimTime" />
|
||||||
|
</set>
|
7
app/src/main/res/anim/slide_out_right.xml
Normal file
7
app/src/main/res/anim/slide_out_right.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<translate android:fromXDelta="0" android:toXDelta="50%p"
|
||||||
|
android:duration="@android:integer/config_mediumAnimTime"/>
|
||||||
|
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
|
||||||
|
android:duration="@android:integer/config_mediumAnimTime" />
|
||||||
|
</set>
|
|
@ -1,7 +1,25 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout
|
<androidx.drawerlayout.widget.DrawerLayout
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/main_content"
|
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_width="match_parent" />
|
android:layout_width="match_parent"
|
||||||
|
android:fitsSystemWindows="true">
|
||||||
|
|
||||||
|
<androidx.fragment.app.FragmentContainerView
|
||||||
|
android:id="@+id/nav_host_fragment"
|
||||||
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:navGraph="@navigation/main"
|
||||||
|
app:defaultNavHost="true" />
|
||||||
|
|
||||||
|
<com.google.android.material.navigation.NavigationView
|
||||||
|
android:id="@+id/drawer_navigation"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="start"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
app:menu="@menu/drawer" />
|
||||||
|
|
||||||
|
</androidx.drawerlayout.widget.DrawerLayout>
|
|
@ -4,10 +4,11 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/root"
|
android:id="@+id/root"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
>
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/app_bar"
|
android:id="@+id/app_bar_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="56dp">
|
android:layout_height="56dp">
|
||||||
|
|
||||||
|
|
11
app/src/main/res/menu/drawer.xml
Normal file
11
app/src/main/res/menu/drawer.xml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/history"
|
||||||
|
android:icon="@android:drawable/ic_menu_recent_history"
|
||||||
|
android:title="@string/history" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/settingsFragment"
|
||||||
|
android:icon="@android:drawable/ic_menu_preferences"
|
||||||
|
android:title="@string/settings" />
|
||||||
|
</menu>
|
|
@ -1,10 +0,0 @@
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
tools:context="dev.lowrespalmtree.comet.ScrollingActivity">
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_settings"
|
|
||||||
android:orderInCategory="100"
|
|
||||||
android:title="@string/action_settings"
|
|
||||||
app:showAsAction="never" />
|
|
||||||
</menu>
|
|
17
app/src/main/res/navigation/main.xml
Normal file
17
app/src/main/res/navigation/main.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/main"
|
||||||
|
app:startDestination="@id/pageViewFragment">
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/pageViewFragment"
|
||||||
|
android:name="dev.lowrespalmtree.comet.PageViewFragment"
|
||||||
|
android:label="PageViewFragment" >
|
||||||
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/settingsFragment"
|
||||||
|
android:name="dev.lowrespalmtree.comet.SettingsFragment"
|
||||||
|
android:label="SettingsFragment">
|
||||||
|
</fragment>
|
||||||
|
</navigation>
|
12
app/src/main/res/values/arrays.xml
Normal file
12
app/src/main/res/values/arrays.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<resources>
|
||||||
|
<!-- Reply Preference -->
|
||||||
|
<string-array name="reply_entries">
|
||||||
|
<item>Reply</item>
|
||||||
|
<item>Reply to all</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="reply_values">
|
||||||
|
<item>reply</item>
|
||||||
|
<item>reply_all</item>
|
||||||
|
</string-array>
|
||||||
|
</resources>
|
|
@ -1,6 +1,21 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Comet</string>
|
<string name="app_name">Comet</string>
|
||||||
<string name="error_alert_title">Error</string>
|
<string name="error_alert_title">Error</string>
|
||||||
<string name="action_settings">Settings</string>
|
|
||||||
<string name="url">URL</string>
|
<string name="url">URL</string>
|
||||||
|
<string name="settings">Settings</string>
|
||||||
|
<string name="history">History</string>
|
||||||
|
<!-- Preference Titles -->
|
||||||
|
<string name="messages_header">Messages</string>
|
||||||
|
<string name="sync_header">Sync</string>
|
||||||
|
|
||||||
|
<!-- Messages Preferences -->
|
||||||
|
<string name="signature_title">Your signature</string>
|
||||||
|
<string name="reply_title">Default reply action</string>
|
||||||
|
|
||||||
|
<!-- Sync Preferences -->
|
||||||
|
<string name="sync_title">Sync email periodically</string>
|
||||||
|
<string name="attachment_title">Download incoming attachments</string>
|
||||||
|
<string name="attachment_summary_on">Automatically download attachments for incoming emails
|
||||||
|
</string>
|
||||||
|
<string name="attachment_summary_off">Only download attachments when manually requested</string>
|
||||||
</resources>
|
</resources>
|
35
app/src/main/res/xml/root_preferences.xml
Normal file
35
app/src/main/res/xml/root_preferences.xml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<PreferenceCategory app:title="@string/messages_header">
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
app:key="signature"
|
||||||
|
app:title="@string/signature_title"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
app:defaultValue="reply"
|
||||||
|
app:entries="@array/reply_entries"
|
||||||
|
app:entryValues="@array/reply_values"
|
||||||
|
app:key="reply"
|
||||||
|
app:title="@string/reply_title"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory app:title="@string/sync_header">
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
app:key="sync"
|
||||||
|
app:title="@string/sync_title" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
app:dependency="sync"
|
||||||
|
app:key="attachment"
|
||||||
|
app:summaryOff="@string/attachment_summary_off"
|
||||||
|
app:summaryOn="@string/attachment_summary_on"
|
||||||
|
app:title="@string/attachment_title" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
</androidx.preference.PreferenceScreen>
|
|
@ -1,4 +1,5 @@
|
||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
@ -6,10 +7,8 @@ buildscript {
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "com.android.tools.build:gradle:7.0.4"
|
classpath "com.android.tools.build:gradle:7.0.4"
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
|
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
|
||||||
|
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
|
||||||
// in the individual module build.gradle files
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue