diff --git a/app/src/main/java/dev/lowrespalmtree/comet/MainActivity.kt b/app/src/main/java/dev/lowrespalmtree/comet/MainActivity.kt index 87a07e1..a082189 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/MainActivity.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/MainActivity.kt @@ -4,20 +4,37 @@ 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 dev.lowrespalmtree.comet.databinding.ActivityMainBinding import kotlinx.coroutines.ExperimentalCoroutinesApi @ExperimentalCoroutinesApi class MainActivity : AppCompatActivity() { + private lateinit var binding: ActivityMainBinding + private var navHost: NavHostFragment? = null + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + Database.init(applicationContext) // TODO move to App Startup? - supportFragmentManager.findFragmentById(R.id.nav_host_fragment)?.also { navHost -> - findViewById(R.id.drawer_navigation)?.apply { - setupWithNavController((navHost as NavHostFragment).navController) - } - } + navHost = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment? + navHost?.also { binding.drawerNavigation.setupWithNavController(it.navController) } + } + + fun goHome() { + navHost?.navController?.navigate(R.id.action_global_pageViewFragment) + binding.drawerLayout.closeDrawers() + } + + fun openHistory() { + binding.drawerLayout.closeDrawers() + // TODO + } + + fun openSettings() { + navHost?.navController?.navigate(R.id.action_global_settingsFragment) + binding.drawerLayout.closeDrawers() } } \ 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 fd7076a..b906174 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/PageViewFragment.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/PageViewFragment.kt @@ -77,7 +77,7 @@ class PageViewFragment : Fragment(), ContentAdapter.ContentAdapterListener { private fun onBackPressed() { if (visitedUrls.size >= 2) { visitedUrls.removeLastOrNull() // Always remove current page first. - openUrl(visitedUrls.removeLastOrNull()!!) + visitedUrls.removeLastOrNull()?.also { openUrl(it) } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e8bbd25..855f214 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,6 @@ + + android:title="@string/settings" + android:onClick="openSettings" /> \ No newline at end of file diff --git a/app/src/main/res/navigation/main.xml b/app/src/main/res/navigation/main.xml index db1d14f..6b8c937 100644 --- a/app/src/main/res/navigation/main.xml +++ b/app/src/main/res/navigation/main.xml @@ -8,8 +8,22 @@ android:id="@+id/pageViewFragment" android:name="dev.lowrespalmtree.comet.PageViewFragment" android:label="PageViewFragment" /> + + \ 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 df98894..737a7fb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -27,6 +27,7 @@ Automatically download attachments for incoming emails Only download attachments when manually requested + Home \ No newline at end of file