Skip to content

Commit

Permalink
SettingsFragmentStub
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenMushroomNew committed Jan 1, 2022
1 parent 2c4f66b commit 6feded1
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ abstract class AbsSettingsFragment : PreferenceFragmentCompat() {
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
if (binderViewModel.pingBinder()) {
setObjectField(
onCreatePreferenceManager(savedInstanceState),
PreferenceFragmentCompat::class.java
)
}
setObjectField(
onCreatePreferenceManager(savedInstanceState), PreferenceFragmentCompat::class.java
)
}

override fun onCreateRecyclerView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.preference.PreferenceViewHolder
import androidx.preference.SwitchPreferenceCompat
import com.google.android.material.transition.platform.Hold
import me.gm.cleaner.plugin.R
import me.gm.cleaner.plugin.databinding.ModuleFragmentBinding
import me.gm.cleaner.plugin.ktx.mediumAnimTime

class SettingsFragment : AbsSettingsFragment() {
Expand All @@ -52,14 +51,10 @@ class SettingsFragment : AbsSettingsFragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
) = if (!binderViewModel.pingBinder()) {
ModuleFragmentBinding.inflate(layoutInflater).root
} else {
super.onCreateView(inflater, container, savedInstanceState).also {
setFragmentResultListener(TemplatesFragment::class.java.name) { _, bundle ->
enterKey = bundle.getString(TemplatesFragment.KEY)
postponeEnterTransition()
}
) = super.onCreateView(inflater, container, savedInstanceState).also {
parentFragment?.setFragmentResultListener(TemplatesFragment::class.java.name) { _, bundle ->
enterKey = bundle.getString(TemplatesFragment.KEY)
parentFragment?.postponeEnterTransition()
}
}

Expand All @@ -73,15 +68,15 @@ class SettingsFragment : AbsSettingsFragment() {
return@setOnClickListener
}
enterKey = preference.key
exitTransition = Hold().apply {
parentFragment?.exitTransition = Hold().apply {
duration = requireContext().mediumAnimTime
}

val direction = SettingsFragmentDirections.actionSettingsToTemplates()
val direction = SettingsFragmentStubDirections.actionSettingsToTemplates()
val extras = FragmentNavigatorExtras(it to it.transitionName)
navController.navigate(direction, extras)
}
startPostponedEnterTransition()
parentFragment?.startPostponedEnterTransition()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2021 Green Mushroom
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package me.gm.cleaner.plugin.module.settings

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.commit
import me.gm.cleaner.plugin.R
import me.gm.cleaner.plugin.databinding.SettingsFragmentStubBinding
import me.gm.cleaner.plugin.module.ModuleFragment

class SettingsFragmentStub : ModuleFragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
) = if (!binderViewModel.pingBinder()) {
super.onCreateView(inflater, container, savedInstanceState)
} else {
SettingsFragmentStubBinding.inflate(layoutInflater).root.also {
savedInstanceState ?: childFragmentManager.commit {
replace(R.id.settings, SettingsFragment())
}
}
}
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/settings_fragment_stub.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ Copyright 2021 Green Mushroom
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent" />
2 changes: 1 addition & 1 deletion app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

<fragment
android:id="@+id/settings_fragment"
android:name="me.gm.cleaner.plugin.module.settings.SettingsFragment"
android:name="me.gm.cleaner.plugin.module.settings.SettingsFragmentStub"
android:label="@string/settings">
<action
android:id="@+id/action_settings_to_templates"
Expand Down

0 comments on commit 6feded1

Please sign in to comment.