Skip to content

Commit

Permalink
Merge pull request #106 from ebraminio/master
Browse files Browse the repository at this point in the history
Cleanup around up navigation setup code
  • Loading branch information
bubelov authored Nov 26, 2021
2 parents b3e4554 + a8ce977 commit 615ee8b
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 39 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/auth/DirectAuthFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class DirectAuthFragment : AppFragment() {
super.onViewCreated(view, savedInstanceState)

toolbar.apply {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener { findNavController().popBackStack() }
setupUpNavigation()
setTitle(R.string.nextcloud_login)
}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/auth/MinifluxAuthFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class MinifluxAuthFragment : AppFragment() {
super.onViewCreated(view, savedInstanceState)

toolbar.apply {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener { findNavController().popBackStack() }
setupUpNavigation()
setTitle(R.string.miniflux_login)
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/common/AppFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package common

import android.os.Bundle
import android.view.View
import androidx.appcompat.graphics.drawable.DrawerArrowDrawable
import androidx.core.view.isVisible
import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.google.android.material.appbar.MaterialToolbar
import timber.log.Timber

abstract class AppFragment(
Expand Down Expand Up @@ -51,4 +54,12 @@ abstract class AppFragment(
super.onResume()
Timber.d("Resuming fragment (class = ${javaClass.simpleName})")
}

protected fun MaterialToolbar.setupUpNavigation(hideKeyboard: Boolean = false) {
navigationIcon = DrawerArrowDrawable(context).also { it.progress = 1f }
setNavigationOnClickListener {
if (hideKeyboard) requireContext().hideKeyboard(searchPanelText)
findNavController().popBackStack()
}
}
}
6 changes: 1 addition & 5 deletions app/src/main/java/entries/EntriesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,7 @@ class EntriesFragment : AppFragment(), Scrollable {
}

is EntriesFilter.BelongToFeed -> {
toolbar.setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)

toolbar.setNavigationOnClickListener {
findNavController().popBackStack()
}
setupUpNavigation()

lifecycleScope.launchWhenResumed {
title = model.getFeed(filter.feedId)?.title
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/entry/EntryFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class EntryFragment : AppFragment() {
super.onViewCreated(view, savedInstanceState)

toolbar.apply {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener { findNavController().popBackStack() }
setupUpNavigation()
inflateMenu(R.menu.menu_entry)
}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/feedsettings/FeedSettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class FeedSettingsFragment : AppFragment() {
}

toolbar.apply {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener { findNavController().popBackStack() }
setupUpNavigation()
title = feed.title
}

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/log/ExceptionFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import co.appreactor.news.R
import co.appreactor.news.databinding.FragmentExceptionBinding
import common.AppFragment
Expand Down Expand Up @@ -39,8 +38,7 @@ class ExceptionFragment : AppFragment() {
val log = model.selectById(args.logId) ?: return@launchWhenResumed

toolbar.apply {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener { findNavController().popBackStack() }
setupUpNavigation()
title = getString(R.string.stack_trace)
inflateMenu(R.menu.menu_exception)

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/log/LogFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class LogFragment : AppFragment() {
super.onViewCreated(view, savedInstanceState)

toolbar.apply {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener { findNavController().popBackStack() }
setupUpNavigation()
setTitle(R.string.event_log)
inflateMenu(R.menu.menu_log_entries)

Expand Down
9 changes: 1 addition & 8 deletions app/src/main/java/search/SearchFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,7 @@ class SearchFragment : AppFragment() {

searchPanel.isVisible = true

toolbar.apply {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)

setNavigationOnClickListener {
requireContext().hideKeyboard(searchPanelText)
findNavController().popBackStack()
}
}
toolbar.setupUpNavigation(hideKeyboard = true)

lifecycleScope.launch {
model.searchString.collect {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/settings/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class SettingsFragment : AppFragment() {
super.onViewCreated(view, savedInstanceState)

toolbar.apply {
setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
setNavigationOnClickListener { findNavController().popBackStack() }
setupUpNavigation()
setTitle(R.string.settings)
}

Expand Down
11 changes: 0 additions & 11 deletions app/src/main/res/drawable/ic_baseline_arrow_back_24.xml

This file was deleted.

0 comments on commit 615ee8b

Please sign in to comment.