Updated on 2026-08-14
This commit is contained in:
commit
2c5210d4da
3 changed files with 19 additions and 20 deletions
|
|
@ -6,6 +6,7 @@ import android.content.pm.ActivityInfo
|
|||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.navigation.findNavController
|
||||
|
|
@ -15,7 +16,6 @@ import com.tangem.di.ToastHelper
|
|||
import com.tangem.tangem_sdk.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.tangem_sdk.android.reader.NfcManager
|
||||
import com.tangem.ui.dialog.RootFoundDialog
|
||||
import com.tangem.util.navigateSafely
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import com.tangem.wallet.R
|
||||
import javax.inject.Inject
|
||||
|
|
@ -39,12 +39,22 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
if (intent != null && (NfcAdapter.ACTION_TECH_DISCOVERED == intent.action || NfcAdapter.ACTION_NDEF_DISCOVERED == intent.action)) {
|
||||
val tag = intent.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG)
|
||||
if (tag != null) {
|
||||
findNavController(R.id.nav_host_fragment).navigateSafely(R.id.main)
|
||||
navigateSafelyToMainFragment()
|
||||
onTagDiscovered(tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun navigateSafelyToMainFragment() {
|
||||
try {
|
||||
findNavController(R.id.nav_host_fragment).navigate(R.id.main)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Log.w(this::class.java.simpleName, e.message)
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.w(this::class.java.simpleName, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import androidx.navigation.fragment.NavHostFragment.findNavController
|
|||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.navigation.NavigationResult
|
||||
import com.tangem.ui.navigation.NavigationResultListener
|
||||
import com.tangem.util.navigateSafely
|
||||
|
||||
abstract class BaseFragment : Fragment() {
|
||||
|
||||
|
|
@ -75,7 +74,13 @@ abstract class BaseFragment : Fragment() {
|
|||
}
|
||||
|
||||
protected fun navigateToDestination(@IdRes destination: Int, data: Bundle? = null) {
|
||||
findNavController(this).navigateSafely(destination, data)
|
||||
try {
|
||||
findNavController(this).navigate(destination, data)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Log.w(this::class.java.simpleName, e.message)
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.w(this::class.java.simpleName, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun navigateBackWithResult(resultCode: Int, data: Bundle? = null,
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
package com.tangem.util
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.navigation.NavController
|
||||
|
||||
fun NavController.navigateSafely(@IdRes destination: Int, data: Bundle? = null) {
|
||||
try {
|
||||
this.navigate(destination, data)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Log.w(this::class.java.simpleName, e.message)
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.w(this::class.java.simpleName, e.message)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue