How to change toast message's default icon in jetpack compose? - kotlin

I have a toast message in my code and it shows when user enter empty dictionary name but there is a problem for me toast shows message with a default android icon and I don't want this. How can I change this icon or remove in jetpack compose kotlin ?
here is screen shot.
Hear is my code
fun updateDictionary(context: Context, dictionaryName: String): Boolean {
if (dictionaryName.isEmpty()) {
Toast.makeText(context, "Please Enter The Dictionary Name !", Toast.LENGTH_LONG).show()
return false
}
val dictionary = OwnDicEntity(dictionaryName, dicCreationTime ?: "", dicId)
updateDicUseCase.updateDic(dictionary)
return true
}
if I want to update dictionary , I go to the update screen and this function is triggered and I have to write update dictionary name if I enter empty dictionary name. it shows toast message as I wrote above.
I'm returning a boolean value, true and false, so that it doesn't update when I enter a empty value.

Starting with Android 12 you don't get any control over how Toasts look - you get two lines of text and your application icon, so the user knows where the Toast came from. (Android 11 still allows for a custom view, but only for apps in the foreground.)
If you want to change the icon, you need to add a new one for your app - the one you're seeing is the default ic_launcher drawable for a new project. Some info about that here.
If you want to remove the icon, you can't! Since you seem to be displaying this as a popup in your own app, you might want to consider a Snackbar instead, or setting the error hint on a text field, or maybe create an area of your UI dedicated to displaying any errors (e.g. if there are multiple components you need to validate, and you want the error state in one place).

Related

When updating/deleting entry in RoomDatabase and then creating new entry App crashes

I work on an app where I have a recyclerview and a fab on the first fragment (listFragment) you see when you open the app. you click the fab, camera opens, you make a picture -> click ok and get to another fragment, there you fill out some stuff and then press save. you get back to the recyclerview fragment and now you can see the saved entry (room database). when you click the listItem you created before you get to an update fragment where you can either update stuff or delete it. now before it all worked fine.
But now with help of a yt video I tried to also insert a bitmap into the database. That works (#TypeConverter) and now I also have the right bitmap displayed in the listItem and the updateFragment.
The problem:
When I click on a listItem and in the updateFragment I click the update button or delete icon that works fine and I get back to the listFragment. But when I then click on the fab in order to create a new entry the camera opens and then the app crashes (and the camera stays open).
Even when the delete and update code is commented out and the only thing that happens when you click these buttons is the navigation between fragments it still crashes but if I remove all the bitmap database code it is fine again. I can delete and/or update multiple entries no problem but when I click the fab and camera starts the app crashes. I also use safeargs for transportation of data to updateFragment when I click the listItem. The app also crashes when I delete/update something and then leave the app by pressing the homebutton on the phone. I navigate out of the app and then get the "app crashed" message.
LOGCAT:
java.lang.RuntimeException: android.os.TransactionTooLargeException:
data parcel size 4675628 bytes
I also found out that if I delete/update multiple entries in a row and then click the fab and the camera opens the amount of bytes multiply. For the following number to be reached I deleted 5 listItems in a row:
TransactionTooLargeException: data parcel size 23309336 bytes
I just wonder what type of data that is and why does it stack up for every navigation between my updateFragment and listFragment(as even when the code for deleting and updating is removed that still happens)? And why does it then become a problem when I start the camera or close the app per homebutton? Maybe contrary to my original believe the bitmap being display in the listItems and the updateFragment are somehow the problem. I display high quality bitmaps by using a fileprovider because in the addFragment and the updateFragment the imageViews are rather big and i use the same bitmap for the small imageViews on the listItems.
If anyone has any idea why that might happen I would be super gratefull!
Author here:
Found an answer to my problem even though I still don't completely get it.
Instead of using a #TypeConverter to turn a bitmap into a byteArray on storing it in the database and on retrieving turning it form byteArray back to bitmap i now store a uri as a string. I found that code which turns a bitmap into a uri and stores the bitmap on the device and it works like a charm:
private fun saveImageToInternalStorage(bitmap: Bitmap): Uri {
val wrapper = ContextWrapper(applicationContext)
var file = wrapper.getDir(IMAGE_DIRECTORY, Context.MODE_PRIVATE)
file = File(file, "${UUID.randomUUID()}.jpg")
try{
val stream : OutputStream = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream)
stream.flush()
stream.close()
}catch (e: IOException){
e.printStackTrace()
}
return Uri.parse(file.absolutePath)
}
companion object{
private const val IMAGE_DIRECTORY = "...Images"
}

how to set onClickListener on words of string in a textField in compose UI

Actually I'm developing an social-media app where I want that my user can mention more than one user in between of their compliment string just like in Instagram comment section...
on which if someOne tap of their username... it'll lead them to the particular user's profile
desired result example
I'm well aware of the use of buildAnnotationString{} where we can play with textStyle but is there anyway to set onClickListener
you have to create ClickableText not simple Text.
ClickableText(text = AnnotatedString("ClickableText"),
onClick = {
// perform here your action
},
)

Notification action buttons action without showing the app

I have a local notification with action buttons 'Start' and 'Remind later'. When I click on either of two, the app opens. I want to keep it for the Start button, but for Remind later button I want to silently run some code (reschedule notification on a later time) without opening an app.
Is this possible to do?
function onOpened(notification) {
if (notification.action == 'Start') {
cancelNotification(notification.id)
NavigationService.navigate(notification.title)
} else {
cancelNotification(notification.id)
// reschedule
let dateTime = new Date(notification.fireDate)
dateTime.setMinutes(dateTime.getMinutes() + 30)
scheduleNotification(notification.id, notification.title, notification.message, dateTime)
}
}
This code works, but as I said, it bring the app to the foreground, and I'd like to avoid it.
You need to include your full code if you looking for help, but from your tags, I assume you are using React Native Push Notifications. If that's the case you might want to look at this Action click brings the app from background to foreground issue. Basically, you need to go through some native codes and change a few lines.

In pentaho , Map component popup do not display the value after a refresh

I used map markers with parameter, First the marker and popup works fine.
And when I change the parameter, markers refreshed ok but, popup with data shows nothing.
I tried to solve, but nothing works. Kindly asking help
Marker Click function test JS:
function f(){
alert(this.dashboard.getParameterValue("status") +" you have clicked on");
//Dashboards.fireChange('status', e.vars.category.value);
}
Then you have to change the param values, check the alert box.
In the marker click function you have to write the alert function first.

ActivityIndicator without dialog box on android?

Im new to titanium and i'm trying to create an a indeterminate preloader (or activity indicator as it is called in titanum). The problem is that on android, the activty indicator is automatically placed in a dialog box, preventing users from interacting with the app until the dialog is dismissed.
Is there any way to just add a simple indetermindate preloader without using a dialog box in android?
Thanks.
According to Appcelerator Docs
Activity indicators must be used differently on Android and iOS:
On Android, the activity indicator is a modal dialog that blocks the UI. Calling show displays the indicator, and calling hide removes it.
One option that you can use is setting cancelable property to true which let the user to cancel the activity indicator dialog by pressing the BACK button.
Appcelerator docs says :
An activity indicator can be used to show the progress of an operation
in the UI to let the user know that some action is taking place. An
activity indicator consists of a spinning animation and an optional
text message, and is used to indicate an ongoing activity of
indeterminate length. To show progress, use Titanium.UI.ProgressBar
instead.
Titanium.App.addEventListener('show_indicator', function(e) {
showIndicator(e.title_msg, e.sub_msg);
});
function showIndicator(title_msg, sub_msg) {
var actIndG = Titanium.UI.createActivityIndicator({
style : Titanium.UI.iPhone.ActivityIndicatorStyle.BIG,
top :10
left : 130,
height : 60,
width : 60,
height : screenheigth,
width : screenwidth
});
indView.add(actIndG);
indWin.open();
}
Up vote or Mark best if it helps you.