Prevent DialogFragment.show crash
This commit is contained in:
@@ -8,6 +8,7 @@ import android.os.Parcelable
|
|||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatDialogFragment
|
import androidx.appcompat.app.AppCompatDialogFragment
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import be.mygod.vpnhotspot.util.showAllowingStateLoss
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +43,7 @@ abstract class AlertDialogFragment<Arg : Parcelable, Ret : Parcelable> :
|
|||||||
|
|
||||||
fun show(target: Fragment, requestCode: Int = 0, tag: String = javaClass.simpleName) {
|
fun show(target: Fragment, requestCode: Int = 0, tag: String = javaClass.simpleName) {
|
||||||
setTargetFragment(target, requestCode)
|
setTargetFragment(target, requestCode)
|
||||||
show(target.parentFragmentManager, tag)
|
showAllowingStateLoss(target.parentFragmentManager, tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import be.mygod.vpnhotspot.preference.SharedPreferenceDataStore
|
|||||||
import be.mygod.vpnhotspot.preference.SummaryFallbackProvider
|
import be.mygod.vpnhotspot.preference.SummaryFallbackProvider
|
||||||
import be.mygod.vpnhotspot.util.RootSession
|
import be.mygod.vpnhotspot.util.RootSession
|
||||||
import be.mygod.vpnhotspot.util.launchUrl
|
import be.mygod.vpnhotspot.util.launchUrl
|
||||||
|
import be.mygod.vpnhotspot.util.showAllowingStateLoss
|
||||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -167,7 +168,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
findPreference<Preference>("misc.donate")!!.setOnPreferenceClickListener {
|
findPreference<Preference>("misc.donate")!!.setOnPreferenceClickListener {
|
||||||
EBegFragment().show(parentFragmentManager, "EBegFragment")
|
EBegFragment().showAllowingStateLoss(parentFragmentManager, "EBegFragment")
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +181,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
app.connectivity.getLinkProperties(it)?.interfaceName
|
app.connectivity.getLinkProperties(it)?.interfaceName
|
||||||
}.toTypedArray())
|
}.toTypedArray())
|
||||||
setTargetFragment(this@SettingsPreferenceFragment, 0)
|
setTargetFragment(this@SettingsPreferenceFragment, 0)
|
||||||
}.show(parentFragmentManager, preference.key)
|
}.showAllowingStateLoss(parentFragmentManager, preference.key)
|
||||||
else -> super.onDisplayPreferenceDialog(preference)
|
else -> super.onDisplayPreferenceDialog(preference)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import be.mygod.vpnhotspot.R
|
|||||||
import be.mygod.vpnhotspot.RepeaterService
|
import be.mygod.vpnhotspot.RepeaterService
|
||||||
import be.mygod.vpnhotspot.databinding.DialogWifiApBinding
|
import be.mygod.vpnhotspot.databinding.DialogWifiApBinding
|
||||||
import be.mygod.vpnhotspot.util.QRCodeDialog
|
import be.mygod.vpnhotspot.util.QRCodeDialog
|
||||||
|
import be.mygod.vpnhotspot.util.showAllowingStateLoss
|
||||||
import be.mygod.vpnhotspot.util.toByteArray
|
import be.mygod.vpnhotspot.util.toByteArray
|
||||||
import be.mygod.vpnhotspot.util.toParcelable
|
import be.mygod.vpnhotspot.util.toParcelable
|
||||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||||
@@ -199,7 +200,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
|||||||
SmartSnackbar.make(e).show()
|
SmartSnackbar.make(e).show()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
QRCodeDialog().withArg(qrString).show(parentFragmentManager, "QRCodeDialog")
|
QRCodeDialog().withArg(qrString).showAllowingStateLoss(parentFragmentManager, "QRCodeDialog")
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> false
|
else -> false
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import androidx.annotation.DrawableRes
|
|||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.databinding.BindingAdapter
|
import androidx.databinding.BindingAdapter
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.room.macToString
|
import be.mygod.vpnhotspot.room.macToString
|
||||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||||
@@ -60,6 +62,10 @@ fun <T : Parcelable> ByteArray.toParcelable() = useParcel { p ->
|
|||||||
p.readParcelable<T>(javaClass.classLoader)
|
p.readParcelable<T>(javaClass.classLoader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun DialogFragment.showAllowingStateLoss(manager: FragmentManager, tag: String? = null) {
|
||||||
|
if (!manager.isStateSaved) show(manager, tag)
|
||||||
|
}
|
||||||
|
|
||||||
fun broadcastReceiver(receiver: (Context, Intent) -> Unit) = object : BroadcastReceiver() {
|
fun broadcastReceiver(receiver: (Context, Intent) -> Unit) = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) = receiver(context, intent)
|
override fun onReceive(context: Context, intent: Intent) = receiver(context, intent)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user