Commit 48154719 authored by Stefan Zabka's avatar Stefan Zabka
Browse files

changed all transactions to navigations

parent 080bb0d2
Pipeline #2642 failed with stage
in 4 minutes and 12 seconds
......@@ -31,6 +31,8 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
......@@ -95,15 +97,6 @@ class MainActivity : AppCompatActivity() {
}
fun permissionGranted() {
val fragment = when {
intent.action == "application/x.card10.app" -> InstallerFragment()
else -> MainFragment()
}
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commit()
val workManager = WorkManager.getInstance(this)
if (!bluetoothAdapter.bondedDevices.isEmpty()
) {
......@@ -116,4 +109,10 @@ class MainActivity : AppCompatActivity() {
workManager.cancelUniqueWork(WORK_NAME)
}
}
override fun onBackPressed() {
if (!findNavController(R.id.nav_host_fragment).popBackStack()) {
super.onBackPressed()
}
}
}
......@@ -64,7 +64,7 @@ class AppDetailFragment : Fragment() {
val ctx = activity ?: throw java.lang.IllegalStateException()
val loadingDialog = LoadingDialog()
loadingDialog.show(fragmentManager, "loading")
loadingDialog.show(requireFragmentManager(), "loading")
val errorDialog =
AlertDialog.Builder(ctx).setMessage(R.string.hatchery_error_generic)
......
......@@ -30,6 +30,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import de.ccc.events.badge.card10.R
......@@ -56,7 +57,7 @@ class AppListFragment : Fragment() {
recyclerView.adapter = listAdapter
val loadingDialog = LoadingDialog()
loadingDialog.show(fragmentManager, "loading")
loadingDialog.show(requireFragmentManager(), "loading")
DownloadTask(activity as Context, listAdapter, loadingDialog).execute()
}
......@@ -66,11 +67,7 @@ class AppListFragment : Fragment() {
val fragment = AppDetailFragment()
fragment.arguments = bundle
val fragmentManager = activity?.supportFragmentManager ?: throw IllegalStateException()
fragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit()
findNavController()
}
private class DownloadTask(
......
/*
* Copyright by the original author or authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.ccc.events.badge.card10.main
import android.bluetooth.BluetoothAdapter
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import androidx.navigation.NavDirections
import androidx.navigation.fragment.findNavController
import de.ccc.events.badge.card10.CARD10_BLUETOOTH_MAC_PREFIX
import de.ccc.events.badge.card10.R
import de.ccc.events.badge.card10.filetransfer.FileTransferFragment
import de.ccc.events.badge.card10.hatchery.AppListFragment
import de.ccc.events.badge.card10.sparkle.BeautifulFragment
import kotlinx.android.synthetic.main.disconnected_fragment.*
import kotlinx.android.synthetic.main.main_fragment.*
import kotlinx.android.synthetic.main.main_fragment.label_status
/**
* Here we give the user the option to start his device and connect it
*/
class DisconnectedFragment : Fragment() {
private val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
inflater.inflate(R.layout.disconnected_fragment, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
button_pair.setOnClickListener { MainFragmentDirections.Scanner() }
val bondedCard10s =
bluetoothAdapter.bondedDevices.filter { it.address.startsWith(CARD10_BLUETOOTH_MAC_PREFIX, true) }
if (bondedCard10s.isNotEmpty()) {
findNavController().navigate(DisconnectedFragmentDirections.Connected())
}
}
}
......@@ -23,63 +23,56 @@
package de.ccc.events.badge.card10.main
import android.bluetooth.BluetoothAdapter
import android.icu.util.UniversalTimeScale
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import androidx.navigation.NavDirections
import androidx.navigation.fragment.findNavController
import de.ccc.events.badge.card10.CARD10_BLUETOOTH_MAC_PREFIX
import de.ccc.events.badge.card10.R
import de.ccc.events.badge.card10.common.ConnectionService
import de.ccc.events.badge.card10.filetransfer.FileTransferFragment
import de.ccc.events.badge.card10.hatchery.AppListFragment
import de.ccc.events.badge.card10.mood.MoodFragment
import de.ccc.events.badge.card10.scanner.ScannerFragment
import de.ccc.events.badge.card10.sparkle.BeautifulFragment
import kotlinx.android.synthetic.main.main_fragment.*
/**
* The initial fragment, the user can access all implemented functions
*/
class MainFragment : Fragment() {
private val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
inflater.inflate(R.layout.main_fragment, container, false)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) : View?{
/** TODO: find out and document what this does*/
if(requireActivity().intent.action == "application/x.card10.app"){
findNavController().navigate(MainFragmentDirections.Installer())
return null
}
return inflater.inflate(R.layout.main_fragment, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
button_pair.setOnClickListener { startFragment(ScannerFragment()) }
button_mood.setOnClickListener { startFragment(MoodFragment()) }
button_beautiful.setOnClickListener { startFragment(BeautifulFragment()) }
button_hatchery.setOnClickListener { startFragment(AppListFragment()) }
button_send.setOnClickListener { startFragment(FileTransferFragment()) }
/**TODO: discuss whether databinding layout is acceptable so we can move this into the xml
*/
button_mood.setOnClickListener { startFragment(MainFragmentDirections.Mood()) }
button_beautiful.setOnClickListener { startFragment(MainFragmentDirections.Beautiful()) }
button_hatchery.setOnClickListener { startFragment(MainFragmentDirections.AppList()) }
val bondedCard10s =
bluetoothAdapter.bondedDevices.filter { it.address.startsWith(CARD10_BLUETOOTH_MAC_PREFIX, true) }
if (bondedCard10s.isNotEmpty()) {
val device = bondedCard10s[0]
label_status.text = getString(R.string.main_label_paired, device.name, device.address)
showConnectedView(view)
} else {
label_status.text = getString(R.string.main_label_not_connected)
showDisconnectedView(view)
startFragment(MainFragmentDirections.Disconnected())
}
}
private fun startFragment(fragment: Fragment) {
fragmentManager!!.beginTransaction()
.replace(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit()
}
private fun showConnectedView(view: View) {
view.findViewById<ConstraintLayout>(R.id.container_connected).visibility = View.VISIBLE
view.findViewById<ConstraintLayout>(R.id.container_disconnected).visibility = View.GONE
}
private fun showDisconnectedView(view: View) {
view.findViewById<ConstraintLayout>(R.id.container_connected).visibility = View.GONE
view.findViewById<ConstraintLayout>(R.id.container_disconnected).visibility = View.VISIBLE
private fun startFragment(direction: NavDirections) {
findNavController().navigate(direction)
}
}
......@@ -38,6 +38,7 @@ import de.ccc.events.badge.card10.ROCKETS_CHARACTERISTIC_UUID
import kotlinx.android.synthetic.main.mood_fragment.*
import java.util.concurrent.CountDownLatch
@ExperimentalUnsignedTypes
class MoodFragment : Fragment() {
private val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph"/>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/card10_logo_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/label_status"
android:layout_marginTop="@dimen/logo_margin_bottom"
android:gravity="center"
android:text="@string/main_label_not_connected"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image_logo"/>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/label_status"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/container_disconnected">
<Button android:id="@+id/button_pair"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_button_pair"
android:layout_marginTop="8dp"
style="@style/MainButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -23,23 +23,6 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image_logo"/>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/label_status"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/container_disconnected">
<Button android:id="@+id/button_pair"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_button_pair"
android:layout_marginTop="@dimen/main_label_margin"
style="@style/MainButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/label_status"
......
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph" app:startDestination="@id/mainFragment">
<fragment android:id="@+id/mainFragment" android:name="de.ccc.events.badge.card10.main.MainFragment"
android:label="MainFragment" tools:layout="@layout/main_fragment">
<action android:id="@+id/Scanner" app:destination="@id/scannerFragment"
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/Mood" app:destination="@id/moodFragment"/>
<action android:id="@+id/Beautiful" app:destination="@id/beautifulFragment"/>
<action android:id="@+id/AppList" app:destination="@id/appListFragment"/>
<action android:id="@+id/Transfer"
app:destination="@id/fileTransferFragment"/>
<action android:id="@+id/Disconnected"
app:destination="@id/disconnectedFragment"/>
<action android:id="@+id/Installer" app:destination="@id/installerFragment"/>
</fragment>
<fragment android:id="@+id/installerFragment" android:name="de.ccc.events.badge.card10.installer.InstallerFragment"
android:label="InstallerFragment" tools:layout="@layout/installer_fragment"/>
<fragment android:id="@+id/scannerFragment" android:name="de.ccc.events.badge.card10.scanner.ScannerFragment"
android:label="ScannerFragment" tools:layout="@layout/scanner_fragment"/>
<fragment android:id="@+id/moodFragment" android:name="de.ccc.events.badge.card10.mood.MoodFragment"
android:label="Mood" tools:layout="@layout/mood_fragment"/>
<fragment android:id="@+id/beautifulFragment" android:name="de.ccc.events.badge.card10.sparkle.BeautifulFragment"
android:label="BeautifulFragment" tools:layout="@layout/beautiful_fragment"/>
<fragment android:id="@+id/appListFragment" android:name="de.ccc.events.badge.card10.hatchery.AppListFragment"
android:label="AppListFragment" tools:layout="@layout/app_list_fragment">
<action android:id="@+id/action_appListFragment_to_appDetailFragment" app:destination="@id/appDetailFragment"/>
</fragment>
<fragment android:id="@+id/fileTransferFragment"
android:name="de.ccc.events.badge.card10.filetransfer.FileTransferFragment"
android:label="FileTransferFragment" tools:layout="@layout/file_transfer_fragment"/>
<fragment android:id="@+id/appDetailFragment" android:name="de.ccc.events.badge.card10.hatchery.AppDetailFragment"
android:label="AppDetailFragment" tools:layout="@layout/app_detail_fragment"/>
<fragment android:id="@+id/disconnectedFragment" android:name="de.ccc.events.badge.card10.main.DisconnectedFragment"
android:label="DisconnectedFragment">
<action android:id="@+id/Connected" app:destination="@id/mainFragment"
/>
</fragment>
</navigation>
\ No newline at end of file
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