From 37832f1d8bda8d98842725faabac323589091388 Mon Sep 17 00:00:00 2001 From: dece Date: Mon, 10 Jan 2022 12:53:11 +0100 Subject: [PATCH] add basic navigation drawer --- app/build.gradle | 12 +++++-- .../dev/lowrespalmtree/comet/MainActivity.kt | 23 ++++-------- .../lowrespalmtree/comet/PageViewFragment.kt | 2 +- .../lowrespalmtree/comet/SettingsFragment.kt | 11 ++++++ app/src/main/res/anim/slide_in_left.xml | 7 ++++ app/src/main/res/anim/slide_in_right.xml | 7 ++++ app/src/main/res/anim/slide_out_left.xml | 7 ++++ app/src/main/res/anim/slide_out_right.xml | 7 ++++ app/src/main/res/layout/activity_main.xml | 24 +++++++++++-- .../main/res/layout/fragment_page_view.xml | 5 +-- app/src/main/res/menu/drawer.xml | 11 ++++++ app/src/main/res/menu/menu_scrolling.xml | 10 ------ app/src/main/res/navigation/main.xml | 17 +++++++++ app/src/main/res/values/arrays.xml | 12 +++++++ app/src/main/res/values/strings.xml | 17 ++++++++- app/src/main/res/xml/root_preferences.xml | 35 +++++++++++++++++++ build.gradle | 7 ++-- 17 files changed, 174 insertions(+), 40 deletions(-) create mode 100644 app/src/main/java/dev/lowrespalmtree/comet/SettingsFragment.kt create mode 100644 app/src/main/res/anim/slide_in_left.xml create mode 100644 app/src/main/res/anim/slide_in_right.xml create mode 100644 app/src/main/res/anim/slide_out_left.xml create mode 100644 app/src/main/res/anim/slide_out_right.xml create mode 100644 app/src/main/res/menu/drawer.xml delete mode 100644 app/src/main/res/menu/menu_scrolling.xml create mode 100644 app/src/main/res/navigation/main.xml create mode 100644 app/src/main/res/values/arrays.xml create mode 100644 app/src/main/res/xml/root_preferences.xml diff --git a/app/build.gradle b/app/build.gradle index 1a2e415..5692731 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,14 +39,20 @@ android { } dependencies { + def nav_version = "2.3.5" + def room_version = "2.4.0" implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.4.0' 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.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' - kapt "androidx.room:room-compiler:2.4.0" + kapt "androidx.room:room-compiler:$room_version" testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/dev/lowrespalmtree/comet/MainActivity.kt b/app/src/main/java/dev/lowrespalmtree/comet/MainActivity.kt index f9e8bb7..87a07e1 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/MainActivity.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/MainActivity.kt @@ -2,31 +2,22 @@ package dev.lowrespalmtree.comet import android.os.Bundle 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 - @ExperimentalCoroutinesApi class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - Database.init(applicationContext) // TODO move to App Startup? - if (savedInstanceState == null) { - supportFragmentManager - .beginTransaction() - .add(R.id.main_content, PageViewFragment().apply { arguments = intent.extras }) - .commit() + supportFragmentManager.findFragmentById(R.id.nav_host_fragment)?.also { navHost -> + findViewById(R.id.drawer_navigation)?.apply { + setupWithNavController((navHost as NavHostFragment).navController) + } } } - - override fun onBackPressed() { - // TODO pass to PageViewFragment - super.onBackPressed() - } - - companion object { - const val TAG = "MainActivity" - } } \ No newline at end of file diff --git a/app/src/main/java/dev/lowrespalmtree/comet/PageViewFragment.kt b/app/src/main/java/dev/lowrespalmtree/comet/PageViewFragment.kt index a93dcfb..b8bd5d5 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/PageViewFragment.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/PageViewFragment.kt @@ -128,7 +128,7 @@ class PageViewFragment : Fragment(), ContentAdapter.ContentAdapterListener { binding.contentProgressBar.show() } PageViewModel.State.RECEIVING -> { - binding.appBar.setExpanded(true, true) + binding.appBarLayout.setExpanded(true, true) binding.contentSwipeLayout.isRefreshing = false } } diff --git a/app/src/main/java/dev/lowrespalmtree/comet/SettingsFragment.kt b/app/src/main/java/dev/lowrespalmtree/comet/SettingsFragment.kt new file mode 100644 index 0000000..789c228 --- /dev/null +++ b/app/src/main/java/dev/lowrespalmtree/comet/SettingsFragment.kt @@ -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) + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/slide_in_left.xml b/app/src/main/res/anim/slide_in_left.xml new file mode 100644 index 0000000..96995fa --- /dev/null +++ b/app/src/main/res/anim/slide_in_left.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/slide_in_right.xml b/app/src/main/res/anim/slide_in_right.xml new file mode 100644 index 0000000..6fb52a3 --- /dev/null +++ b/app/src/main/res/anim/slide_in_right.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/slide_out_left.xml b/app/src/main/res/anim/slide_out_left.xml new file mode 100644 index 0000000..020a1be --- /dev/null +++ b/app/src/main/res/anim/slide_out_left.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/slide_out_right.xml b/app/src/main/res/anim/slide_out_right.xml new file mode 100644 index 0000000..c4de800 --- /dev/null +++ b/app/src/main/res/anim/slide_out_right.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2bfd55e..e8bbd25 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,7 +1,25 @@ - \ No newline at end of file + android:layout_width="match_parent" + android:fitsSystemWindows="true"> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_page_view.xml b/app/src/main/res/layout/fragment_page_view.xml index d36c1a3..e51cbe0 100644 --- a/app/src/main/res/layout/fragment_page_view.xml +++ b/app/src/main/res/layout/fragment_page_view.xml @@ -4,10 +4,11 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + > diff --git a/app/src/main/res/menu/drawer.xml b/app/src/main/res/menu/drawer.xml new file mode 100644 index 0000000..56688f7 --- /dev/null +++ b/app/src/main/res/menu/drawer.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_scrolling.xml b/app/src/main/res/menu/menu_scrolling.xml deleted file mode 100644 index 45cc3e1..0000000 --- a/app/src/main/res/menu/menu_scrolling.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - \ No newline at end of file diff --git a/app/src/main/res/navigation/main.xml b/app/src/main/res/navigation/main.xml new file mode 100644 index 0000000..4644685 --- /dev/null +++ b/app/src/main/res/navigation/main.xml @@ -0,0 +1,17 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..6cf9ed4 --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,12 @@ + + + + Reply + Reply to all + + + + reply + reply_all + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dbfaf56..5624b64 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,21 @@ Comet Error - Settings URL + Settings + History + + Messages + Sync + + + Your signature + Default reply action + + + Sync email periodically + Download incoming attachments + Automatically download attachments for incoming emails + + Only download attachments when manually requested \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml new file mode 100644 index 0000000..61dfdf3 --- /dev/null +++ b/app/src/main/res/xml/root_preferences.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7f88f48..5f34279 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. + buildscript { repositories { google() @@ -6,10 +7,8 @@ buildscript { } dependencies { classpath "com.android.tools.build:gradle:7.0.4" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10' + classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5" } }