Commit bd9092f7 authored by Christophe Henry's avatar Christophe Henry

Merge branch 'fix-home-back-buttons' into 'develop'

Fix #82: Home and back buttons sometimes not displayed

Closes #82

See merge request !71
parents c8a00983 8316f233
Pipeline #3480 failed with stage
in 0 seconds
......@@ -3,19 +3,19 @@ package fr.chenry.android.freshrss.activities
import android.os.Bundle
import android.view.MenuItem
import android.widget.TextView
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.Observer
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import fr.chenry.android.freshrss.*
import androidx.navigation.ui.*
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.navigationdrawer.AddSubscriptionDialog
import fr.chenry.android.freshrss.components.subscriptions.MainSubscriptionFragmentDirections
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.utils.BurgerMenuDrawerListener
import fr.chenry.android.freshrss.utils.e
import fr.chenry.android.freshrss.utils.whenNotNull
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity: AppCompatActivity() {
......@@ -23,29 +23,25 @@ class MainActivity: AppCompatActivity() {
Navigation.findNavController(this, R.id.main_activity_host_fragment)
}
private val drawerLayout by lazy {
val drawerLayout: DrawerLayout by lazy {
findViewById<DrawerLayout>(R.id.activity_main_navigation_drawer)
}
private val drawerToggle by lazy {
ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
private val appBarConfiguration by lazy {
AppBarConfiguration(navigation.graph, drawerLayout)
}
private val appBarConfiguration by lazy {AppBarConfiguration(navigation.graph)}
private val backstackCount get() = main_activity_host_fragment?.childFragmentManager?.backStackEntryCount ?: 0
private val backstackCount
inline get() = main_activity_host_fragment?.childFragmentManager?.backStackEntryCount ?: 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
restoreState()
setContentView(R.layout.activity_main)
FreshRSSApplication.app.refresherService.value?.apply {refresh()}
NavigationUI.setupActionBarWithNavController(this, navigation, appBarConfiguration)
setupActionBarWithNavController(navigation, appBarConfiguration)
FreshRSSApplication.app.refresherService.value.whenNotNull {it.refresh()}
drawerLayout.addDrawerListener(drawerToggle)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeButtonEnabled(true)
drawerToggle.syncState()
drawerLayout.addDrawerListener(BurgerMenuDrawerListener(this))
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
......@@ -61,7 +57,7 @@ class MainActivity: AppCompatActivity() {
fun onAddSubscriptionClick(@Suppress("UNUSED_PARAMETER") menuItem: MenuItem): Boolean {
drawerLayout.closeDrawers()
AddSubscriptionDialog{
AddSubscriptionDialog {
Store.postAddSubscription(it).fail(this::e)
}.show(main_activity_host_fragment!!.childFragmentManager, AddSubscriptionDialog::class.java.canonicalName)
return true
......@@ -69,7 +65,7 @@ class MainActivity: AppCompatActivity() {
fun onSettingsItemClick(@Suppress("UNUSED_PARAMETER") menuItem: MenuItem): Boolean {
drawerLayout.closeDrawers()
navigation.navigate(MainNavDirections.actionGlobalSettingsFragment())
navigation.navigate(MainSubscriptionFragmentDirections.mainSubscriptionsToSettings())
return true
}
......@@ -102,17 +98,8 @@ class MainActivity: AppCompatActivity() {
super.onRestoreInstanceState(savedInstanceState)
}
override fun onSupportNavigateUp(): Boolean {
val result = navigation.navigateUp() || super.onSupportNavigateUp()
if(backstackCount == 1) {
drawerToggle.syncState()
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeButtonEnabled(true)
}
return result
}
override fun onSupportNavigateUp(): Boolean =
navigation.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
private fun restoreState() {
Store.subscriptionsSection.value = FreshRSSApplication.preferences.subscriptionSection
......
......@@ -5,6 +5,7 @@ import android.view.*
import androidx.fragment.app.Fragment
import androidx.lifecycle.*
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.*
import androidx.recyclerview.widget.RecyclerView.ViewHolder
......@@ -57,9 +58,8 @@ class SubscriptionArticlesFragment: Fragment(), Observer<List<SubscriptionArticl
fun onItemClick(position: Int): Boolean =
adapter.getItem(position)?.article?.id?.let {articleId ->
val direction = SubscriptionArticlesFragmentDirections
.actionSubscriptionArticlesFragmentToSubscriptionArticlesDetailFragment(articleId)
view?.findNavController()?.navigate(direction)
val direction = SubscriptionArticlesFragmentDirections.articlesToArticleDetail(articleId)
findNavController().navigate(direction)
true
} ?: false
......
......@@ -110,9 +110,7 @@ class MainSubscriptionFragment: Fragment(), BottomNavigationView.OnNavigationIte
override fun getCount() = SubscriptionSection.values().size
private fun instantiateFragment(subscriptionSection: SubscriptionSection): Fragment {
val arguments = MainNavDirections
.actionGlobalSubscriptionsFragment(VoidCategory, subscriptionSection)
.arguments
val arguments = MainNavDirections.toSubscriptions(VoidCategory, subscriptionSection).arguments
return childFragmentManager
.fragmentFactory
......
......@@ -11,7 +11,8 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import eu.davidea.fastscroller.FastScroller
import fr.chenry.android.freshrss.*
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.subscriptions.SubscriptionSection.*
import fr.chenry.android.freshrss.components.subscriptions.adapters.SubscriptionsFlexibleAdapter
import fr.chenry.android.freshrss.store.Store
......@@ -23,16 +24,16 @@ import fr.chenry.android.freshrss.utils.whenNotNull
import kotlinx.android.synthetic.main.fragment_subscriptions.*
import nl.komponents.kovenant.Promise
class SubscriptionsFragment : Fragment(), Observer<Subscriptions> {
class SubscriptionsFragment: Fragment(), Observer<Subscriptions> {
private val args: SubscriptionsFragmentArgs by navArgs()
private val section by lazy { args.section }
private val category by lazy { args.category }
private val section by lazy {args.section}
private val category by lazy {args.category}
val model by lazy {
if (category != VoidCategory)
if(category != VoidCategory)
ViewModelProvider(this, SubscriptionsFragmentCategoryVMF(category, section))
.get(AllSubscriptionsVM::class.java)
else when (section) {
else when(section) {
ALL -> ViewModelProvider(this).get(AllSubscriptionsVM::class.java)
UNREAD -> ViewModelProvider(this).get(UnreadSubscriptionsVM::class.java)
FAVORITES -> ViewModelProvider(this).get(FavoritesSubscriptionsVM::class.java)
......@@ -44,39 +45,42 @@ class SubscriptionsFragment : Fragment(), Observer<Subscriptions> {
initRecyclerView(view)
Store.refreshingPromise.observe(viewLifecycleOwner, Observer { toggleProgressCircle(model.subscriptions.value ?: listOf()) })
Store.refreshingPromise.observe(
viewLifecycleOwner,
Observer {toggleProgressCircle(model.subscriptions.value ?: listOf())})
model.subscriptions.observe(viewLifecycleOwner, this)
val contentDescription = if (category != VoidCategory) {
when (section) {
val contentDescription = if(category != VoidCategory) {
when(section) {
ALL -> R.string.empty_subscriptions_section_all_category
UNREAD -> R.string.empty_subscriptions_section_unread_category
FAVORITES -> R.string.empty_subscriptions_section_favorites_category
}
} else {
when (section) {
when(section) {
ALL -> R.string.empty_subscriptions_section_all
UNREAD -> R.string.empty_subscriptions_section_unread
FAVORITES -> R.string.empty_subscriptions_section_favorites
}
}.let { FreshRSSApplication.getStringR(it, category.label) }
}.let {FreshRSSApplication.getStringR(it, category.label)}
view.findViewById<EmotionnalImageSubtext>(R.id.fragment_subscriptions_empty_list).text = contentDescription
val imageResource = when (section) {
val imageResource = when(section) {
ALL -> R.drawable.ic_undraw_empty
UNREAD -> R.drawable.ic_undraw_joyride
FAVORITES -> R.drawable.ic_undraw_loving_it
}
view.findViewById<EmotionnalImageSubtext>(R.id.fragment_subscriptions_empty_list).setImageResource(imageResource)
view.findViewById<EmotionnalImageSubtext>(R.id.fragment_subscriptions_empty_list)
.setImageResource(imageResource)
view.findViewById<SwipeRefreshLayout>(R.id.subcription_pull_to_refresh)?.let {
Store.refreshingPromise.observe(viewLifecycleOwner, Observer<Promise<Unit, Exception>?> { v ->
Store.refreshingPromise.observe(viewLifecycleOwner, Observer<Promise<Unit, Exception>?> {v ->
it.isRefreshing = v != null
})
it.setOnRefreshListener {
FreshRSSApplication.app.refresherService.value.whenNotNull {rs -> rs.refresh() }
FreshRSSApplication.app.refresherService.value.whenNotNull {rs -> rs.refresh()}
}
}
......@@ -85,15 +89,20 @@ class SubscriptionsFragment : Fragment(), Observer<Subscriptions> {
override fun onChanged(subscriptions: Subscriptions?) = toggleProgressCircle((subscriptions ?: listOf()))
fun onClick(subscription: Subscription) = when (section) {
FAVORITES -> MainNavDirections.actionGlobalSubscriptionArticlesFragment(subscription.id, READ)
ALL -> MainNavDirections.actionGlobalSubscriptionArticlesFragment(subscription.id, READ)
UNREAD -> MainNavDirections.actionGlobalSubscriptionArticlesFragment(subscription.id, ReadStatus.UNREAD)
}.let { findNavController().navigate(it) }
fun onClick(subscription: Subscription) = when(section) {
FAVORITES -> subscription.id to READ
ALL -> subscription.id to READ
UNREAD -> subscription.id to ReadStatus.UNREAD
}.let {
val direction = if(category == VoidCategory)
MainSubscriptionFragmentDirections.mainSubscriptionsToArticles(it.first, it.second) else
SubscriptionsFragmentDirections.articlesCategoryToArticles(it.first, it.second)
findNavController().navigate(direction)
}
fun onClick(subscriptionCategory: SubscriptionCategory) =
MainNavDirections.actionGlobalSubscriptionsFragment(subscriptionCategory, section)
.let { findNavController().navigate(it) }
MainSubscriptionFragmentDirections.mainSubscriptionsToArticlesCategory(subscriptionCategory, section)
.let {findNavController().navigate(it)}
private fun initRecyclerView(view: View) {
val adapter = SubscriptionsFlexibleAdapter(this)
......
package fr.chenry.android.freshrss.utils
import android.view.View
import androidx.appcompat.graphics.drawable.DrawerArrowDrawable
import androidx.drawerlayout.widget.DrawerLayout
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.activities.MainActivity
import kotlin.math.max
import kotlin.math.min
class BurgerMenuDrawerListener(private val activity: MainActivity): DrawerLayout.DrawerListener {
private val drawerArrowDrawable = DrawerArrowDrawable(activity.supportActionBar!!.themedContext)
override fun onDrawerStateChanged(newState: Int) =
activity.supportActionBar?.setHomeAsUpIndicator(drawerArrowDrawable).unit()
override fun onDrawerSlide(drawerView: View, slideOffset: Float) = setPosition(slideOffset)
override fun onDrawerClosed(drawerView: View) {
activity.supportActionBar?.setHomeActionContentDescription(R.string.navigation_drawer_open)
setPosition(0f)
}
override fun onDrawerOpened(drawerView: View) {
activity.supportActionBar?.setHomeActionContentDescription(R.string.navigation_drawer_close)
setPosition(1f)
}
private fun setPosition(rawPosition: Float) {
val position = min(1f, max(0f, rawPosition))
drawerArrowDrawable.progress = position
when(rawPosition) {
1f -> drawerArrowDrawable.setVerticalMirror(true)
0f -> drawerArrowDrawable.setVerticalMirror(false)
}
}
}
......@@ -72,7 +72,7 @@ fun Request.authentify(account: Account) =
fun Request.authorize(account: Account) = this.header("T" to account.writeToken)
fun Any.unit(): Unit = Unit
fun Any?.unit(): Unit = Unit
fun Any.v(message: String) = Log.v(this::class.qualifiedName, message).unit()
fun Any.v(message: Throwable) = Log.v(this::class.qualifiedName, "VERBOSE", message).unit()
fun Any.d(message: String) = Log.d(this::class.qualifiedName, message).unit()
......
......@@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/fragment_subscription"
android:visibility="gone" />
android:visibility="visible" />
<fr.chenry.android.freshrss.utils.Loader
android:id="@+id/fragment_subscriptions_waiting"
......@@ -33,7 +33,7 @@
android:id="@+id/fragment_subscriptions_empty_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:visibility="gone"
app:src="@drawable/ic_undraw_blogging"
app:text="@string/empty_subscriptions_section_unread" />
</FrameLayout>
......
......@@ -9,7 +9,29 @@
android:id="@+id/mainSubscriptionFragment"
android:name="fr.chenry.android.freshrss.components.subscriptions.MainSubscriptionFragment"
android:label="@string/app_name"
tools:layout="@layout/fragment_main_subscription" />
tools:layout="@layout/fragment_main_subscription" >
<action
android:id="@+id/main_subscriptions_to_articles"
app:destination="@id/subscriptionArticlesFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action
android:id="@+id/main_subscriptions_to_articles_category"
app:destination="@id/subscriptionsFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action
android:id="@+id/main_subscriptions_to_settings"
app:destination="@id/settingsFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/subscriptionArticlesFragment"
android:name="fr.chenry.android.freshrss.components.subscriptionarticles.SubscriptionArticlesFragment"
......@@ -22,10 +44,10 @@
android:name="readStatus"
app:argType="fr.chenry.android.freshrss.store.database.models.ReadStatus" />
<action
android:id="@+id/action_subscriptionArticlesFragment_to_subscriptionArticlesDetailFragment"
android:id="@+id/articles_to_article_detail"
app:destination="@+id/subscriptionArticlesDetailFragment"
app:enterAnim="@anim/nav_default_pop_enter_anim"
app:exitAnim="@anim/nav_default_pop_exit_anim"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
......@@ -38,13 +60,6 @@
android:name="articleId"
app:argType="string" />
</fragment>
<action
android:id="@+id/action_global_subscriptionArticlesFragment"
app:destination="@id/subscriptionArticlesFragment"
app:enterAnim="@anim/nav_default_pop_enter_anim"
app:exitAnim="@anim/nav_default_pop_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<fragment
android:id="@+id/subscriptionsFragment"
android:name="fr.chenry.android.freshrss.components.subscriptions.SubscriptionsFragment"
......@@ -56,23 +71,23 @@
<argument
android:name="section"
app:argType="fr.chenry.android.freshrss.components.subscriptions.SubscriptionSection" />
<action
android:id="@+id/articles_category_to_articles"
app:destination="@id/subscriptionArticlesFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<action
android:id="@+id/action_global_subscriptionsFragment"
app:destination="@id/subscriptionsFragment"
app:enterAnim="@anim/nav_default_pop_enter_anim"
app:exitAnim="@anim/nav_default_pop_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<fragment
android:id="@+id/settingsFragment"
android:name="fr.chenry.android.freshrss.components.navigationdrawer.SettingsFragment"
android:label="@string/title_settings" />
<action
android:id="@+id/action_global_settingsFragment"
app:destination="@id/settingsFragment"
app:enterAnim="@anim/nav_default_pop_enter_anim"
app:exitAnim="@anim/nav_default_pop_exit_anim"
android:id="@+id/to_subscriptions"
app:destination="@id/subscriptionsFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</navigation>
\ No newline at end of file
......@@ -78,7 +78,7 @@
<string name="empty_subscriptions_section_all_category">You have no subscription in %s category.\nWhy don\'t you add one?</string>
<string name="empty_subscriptions_section_unread">Yaye! You have read everything here.\nWhy don\'t go in a library to read a book?</string>
<string name="empty_subscriptions_section_unread_category">Yaye! You have read everything in %s category.\nWhy don\'t go in a library to read a book?</string>
<string name="empty_subscription_list">There is no articles on %s feed yet.\nNew articles will probably be published soon.</string>
<string name="empty_subscription_list">There is no articles on %s feed yet.\\nNew articles will probably be published soon.</string>
<string name="empty_subscription_unread_list">You have read every article on %s feed!</string>
<string name="human_time_grouping_today">Today</string>
<string name="human_time_grouping_yesterday">Yesterday</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment