Add about screen to the context menu of the main screen

This commit is contained in:
Jonas Lochmann 2020-10-26 01:00:00 +01:00
parent 4248139747
commit d6dda12bb6
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
6 changed files with 237 additions and 3 deletions

View file

@ -0,0 +1,65 @@
/*
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package io.timelimit.android.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.Navigation
import io.timelimit.android.R
import io.timelimit.android.livedata.liveDataFromValue
import io.timelimit.android.ui.main.ActivityViewModelHolder
import io.timelimit.android.ui.main.AuthenticationFab
import kotlinx.android.synthetic.main.fragment_main.*
abstract class SingleFragmentWrapper: Fragment() {
private val activity: ActivityViewModelHolder by lazy { getActivity() as ActivityViewModelHolder }
private lateinit var navController: NavController
protected val navigation get() = navController
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
navController = Navigation.findNavController(container!!)
return inflater.inflate(R.layout.single_fragment_wrapper, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
AuthenticationFab.manageAuthenticationFab(
fab = fab,
fragment = this,
shouldHighlight = activity.getActivityViewModel().shouldHighlightAuthenticationButton,
authenticatedUser = activity.getActivityViewModel().authenticatedUser,
doesSupportAuth = liveDataFromValue(showAuthButton)
)
fab.setOnClickListener { activity.showAuthenticationScreen() }
if (savedInstanceState == null) {
childFragmentManager.beginTransaction()
.replace(R.id.container, createChildFragment())
.commit()
}
}
abstract fun createChildFragment(): Fragment
abstract val showAuthButton: Boolean
}

View file

@ -0,0 +1,49 @@
/*
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package io.timelimit.android.ui.fragment
import androidx.fragment.app.Fragment
import io.timelimit.android.R
import io.timelimit.android.extensions.safeNavigate
import io.timelimit.android.ui.overview.about.AboutFragment
import io.timelimit.android.ui.overview.about.AboutFragmentParentHandlers
class AboutFragmentWrapped: SingleFragmentWrapper(), AboutFragmentParentHandlers {
override val showAuthButton: Boolean = false
override fun createChildFragment(): Fragment = AboutFragment()
override fun onShowDiagnoseScreen() {
navigation.safeNavigate(
AboutFragmentWrappedDirections.actionAboutFragmentWrappedToDiagnoseMainFragment(),
R.id.aboutFragmentWrapped
)
}
override fun onShowPurchaseScreen() {
navigation.safeNavigate(
AboutFragmentWrappedDirections.actionAboutFragmentWrappedToPurchaseFragment(),
R.id.aboutFragmentWrapped
)
}
override fun onShowStayAwesomeScreen() {
navigation.safeNavigate(
AboutFragmentWrappedDirections.actionAboutFragmentWrappedToStayAwesomeFragment(),
R.id.aboutFragmentWrapped
)
}
}

View file

@ -16,9 +16,7 @@
package io.timelimit.android.ui.overview.main
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.*
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.LiveData
@ -60,6 +58,12 @@ class MainFragment : Fragment(), OverviewFragmentParentHandlers, AboutFragmentPa
private var wereViewsCreated = false
private var didRedirectToUserScreen = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
navigation = Navigation.findNavController(container!!)
@ -231,4 +235,22 @@ class MainFragment : Fragment(), OverviewFragmentParentHandlers, AboutFragmentPa
}
override fun getCustomTitle(): LiveData<String?> = liveDataFromValue("${getString(R.string.main_tab_overview)} (${getString(R.string.app_name)})")
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.fragment_main_menu, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
R.id.menu_main_about -> {
navigation.safeNavigate(
MainFragmentDirections.actionOverviewFragmentToAboutFragmentWrapped(),
R.id.overviewFragment
)
true
}
else -> super.onOptionsItemSelected(item)
}
}

View file

@ -0,0 +1,44 @@
<!--
TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="io.timelimit.android.ui.fragment.SingleFragmentWrapper">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
app:fabSize="normal"
android:src="@drawable/ic_lock_open_white_24dp"
android:layout_margin="16dp"
android:layout_gravity="end|bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:icon="@drawable/ic_info_outline_black_24dp"
android:title="@string/main_tab_about"
android:id="@+id/menu_main_about" />
</menu>

View file

@ -90,6 +90,13 @@
<action
android:id="@+id/action_overviewFragment_to_parentModeFragment"
app:destination="@id/parentModeFragment" />
<action
android:id="@+id/action_overviewFragment_to_aboutFragmentWrapped"
app:destination="@id/aboutFragmentWrapped"
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/manageChildFragment"
@ -434,4 +441,30 @@
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/aboutFragmentWrapped"
android:name="io.timelimit.android.ui.fragment.AboutFragmentWrapped"
android:label="AboutFragmentWrapped" >
<action
android:id="@+id/action_aboutFragmentWrapped_to_diagnoseMainFragment"
app:destination="@id/diagnoseMainFragment"
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/action_aboutFragmentWrapped_to_stayAwesomeFragment"
app:destination="@id/stayAwesomeFragment"
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/action_aboutFragmentWrapped_to_purchaseFragment"
app:destination="@id/purchaseFragment"
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>
</navigation>