mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
fix crashes
This commit is contained in:
parent
486a1d451b
commit
adda634198
6 changed files with 69 additions and 45 deletions
|
|
@ -145,17 +145,21 @@ class PushNotificationManager(
|
|||
additionalData
|
||||
)
|
||||
}
|
||||
|
||||
val notificationFactory = HabiticaLocalNotificationFactory()
|
||||
val localNotification = notificationFactory.build(
|
||||
remoteMessageIdentifier,
|
||||
context
|
||||
)
|
||||
localNotification.setExtras(remoteMessage.data)
|
||||
val notification = remoteMessage.notification
|
||||
if (notification != null) {
|
||||
val notificationManager = NotificationManagerCompat.from(context)
|
||||
notificationManager.notify(notification.channelId, notification)
|
||||
} else {
|
||||
val notificationFactory = HabiticaLocalNotificationFactory()
|
||||
val localNotification = notificationFactory.build(
|
||||
remoteMessageIdentifier,
|
||||
context
|
||||
localNotification.notifyLocally(
|
||||
notification.title ?: remoteMessage.data["title"],
|
||||
notification.body ?: remoteMessage.data["body"],
|
||||
remoteMessage.data
|
||||
)
|
||||
localNotification.setExtras(remoteMessage.data)
|
||||
} else {
|
||||
localNotification.notifyLocally(
|
||||
remoteMessage.data["title"],
|
||||
remoteMessage.data["body"],
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import com.habitrpg.common.habitica.helpers.LanguageHelper
|
|||
import com.habitrpg.common.habitica.helpers.launchCatching
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStream
|
||||
import java.util.Date
|
||||
|
|
@ -239,34 +240,39 @@ abstract class BaseActivity : AppCompatActivity() {
|
|||
if (message?.isNotBlank() == true) {
|
||||
sharingIntent.putExtra(Intent.EXTRA_TEXT, message)
|
||||
}
|
||||
if (image != null) {
|
||||
val fos: OutputStream
|
||||
val uri: Uri
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val resolver = contentResolver
|
||||
val contentValues = ContentValues()
|
||||
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "${Date()}.png")
|
||||
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/png")
|
||||
contentValues.put(
|
||||
MediaStore.MediaColumns.RELATIVE_PATH,
|
||||
Environment.DIRECTORY_PICTURES
|
||||
)
|
||||
uri =
|
||||
resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues) ?: return
|
||||
fos = resolver.openOutputStream(uri, "wt") ?: return
|
||||
} else {
|
||||
val imagesDir =
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
.toString()
|
||||
val file = File(imagesDir, "${Date()}.png")
|
||||
uri = file.absoluteFile.toUri()
|
||||
fos = FileOutputStream(file)
|
||||
try {
|
||||
if (image != null) {
|
||||
val fos: OutputStream
|
||||
val uri: Uri
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val resolver = contentResolver
|
||||
val contentValues = ContentValues()
|
||||
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "${Date()}.png")
|
||||
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/png")
|
||||
contentValues.put(
|
||||
MediaStore.MediaColumns.RELATIVE_PATH,
|
||||
Environment.DIRECTORY_PICTURES
|
||||
)
|
||||
uri =
|
||||
resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
|
||||
?: return
|
||||
fos = resolver.openOutputStream(uri, "wt") ?: return
|
||||
} else {
|
||||
val imagesDir =
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
.toString()
|
||||
val file = File(imagesDir, "${Date()}.png")
|
||||
uri = file.absoluteFile.toUri()
|
||||
fos = FileOutputStream(file)
|
||||
}
|
||||
image.compress(Bitmap.CompressFormat.PNG, 100, fos)
|
||||
fos.close()
|
||||
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri)
|
||||
}
|
||||
image.compress(Bitmap.CompressFormat.PNG, 100, fos)
|
||||
fos.close()
|
||||
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri)
|
||||
startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_using)))
|
||||
} catch (_: FileNotFoundException) {
|
||||
|
||||
}
|
||||
startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_using)))
|
||||
}
|
||||
|
||||
fun reload() {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,14 @@ class TimeTravelersShopFragment : ShopFragment() {
|
|||
val subscriptionBottomSheet = EventOutcomeSubscriptionBottomSheetFragment().apply {
|
||||
eventType = EventOutcomeSubscriptionBottomSheetFragment.EVENT_HOURGLASS_SHOP_OPENED
|
||||
}
|
||||
activity?.supportFragmentManager?.let { subscriptionBottomSheet.show(it, SubscriptionBottomSheetFragment.TAG) }
|
||||
if (isAdded) {
|
||||
activity?.supportFragmentManager?.let {
|
||||
subscriptionBottomSheet.show(
|
||||
it,
|
||||
SubscriptionBottomSheetFragment.TAG
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -511,8 +511,10 @@ class PartyDetailFragment : BaseFragment<FragmentPartyDetailBinding>() {
|
|||
isDestructive = true
|
||||
) { _, _ ->
|
||||
viewModel.leaveGroup(groupChallenges, false) {
|
||||
parentFragmentManager.popBackStack()
|
||||
MainNavigationController.navigate(R.id.noPartyFragment)
|
||||
if (isAdded) {
|
||||
parentFragmentManager.popBackStack()
|
||||
MainNavigationController.navigate(R.id.noPartyFragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
alert.setExtraCloseButtonVisibility(View.VISIBLE)
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
NAME=4.3.2
|
||||
CODE=6841
|
||||
NAME=4.3.3
|
||||
CODE=6861
|
||||
|
|
@ -8,6 +8,7 @@ import androidx.activity.ComponentActivity
|
|||
import androidx.core.view.children
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.google.android.gms.common.api.ApiException
|
||||
import com.google.android.gms.tasks.Tasks
|
||||
import com.google.android.gms.wearable.CapabilityClient
|
||||
import com.google.android.gms.wearable.MessageClient
|
||||
|
|
@ -119,13 +120,17 @@ abstract class BaseActivity<B : ViewBinding, VM : BaseViewModel> : ComponentActi
|
|||
val nodeID = info.nodes.firstOrNull()
|
||||
if (nodeID != null) {
|
||||
function?.invoke(true)
|
||||
Tasks.await(
|
||||
messageClient.sendMessage(
|
||||
nodeID.id,
|
||||
url,
|
||||
data
|
||||
try {
|
||||
Tasks.await(
|
||||
messageClient.sendMessage(
|
||||
nodeID.id,
|
||||
url,
|
||||
data
|
||||
)
|
||||
)
|
||||
)
|
||||
} catch (_: ApiException) {
|
||||
// It's not connected
|
||||
}
|
||||
} else {
|
||||
function?.invoke(false)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue