I am passing an id value through MessagingCenter. The value is passing from Android Mainactivity and subscribed on the PCL ChatPageviewModel. Please see below code:
// Sending group Id through the MessagingCenter on android Mainactivity
MessagingCenter.Send<object, string>(this, "webcontentId", webcontentId);
//Subscribing the group id on PCL ChatPageViewmodel
MessagingCenter.Subscribe<object, string>(this, "webcontentId", (object obj, string notifWebcontentId) =>
{
//Checking the id values and refreshing the message feed if ids are equal
});
My problem is MessagingCenter.Subscribe code executing multiple times and sometimes it returns old passed id value. I think need to add MessagingCenter.Unsubscribe codes for solving this issue. I added like below code on OnDisappearing method.
MessagingCenter.Unsubscribe<object, string>(this, "webcontentId");
But after adding this also getting old group id values in MessagingCenter.Subscribe. Is there any mistake on my MessagingCenter.Unsubscribe code? And on where need to add MessagingCenter.Unsubscribe codes?
Related
I want to initialize a value of an edit method inside the init method of form, i wrote this:
[Form]
public class foo extends FormRun
{
str paymTermId;
public void init()
{
CustTable custTable = CustTable::find("DE-001");
paymTermId = custTable.paymTermId;
super();
}
edit str edtpaymTermId(boolean set, str _paymTermId)
{
if (set)
{
paymTermId= _paymTermId;
}
return paymTermId ;
}
}
But when i open the form the control remains empty.
any suggestions?
I tried to reproduce the issue, but was not successful. For me, when opening the form, the control shows a value.
A possible reason why it is not working for you could be that you open the form in the wrong company. In your code, you retrieve the value to display in the control from the payment term of customer DE-001. This customer exists in company USMF in the Contoso demo data and has payment term Net10. If the form is opened in this company, the value is shown in the control. If you are in another company (e.g. DAT), no value is shown.
I see 2 things that are wrong:
You are setting the value BEFORE super(). It should be after.
You SHOULDN'T initialize the value via field, you should do it calling edit method. Edit methods have a boolean SET parameter which can simulate a call for setting a value.
We have below requirement.
Field 1 : comboBoxField and it is mandatory.
Field 2: comboBoxField
Case 1. If editor choose field 1 value is "value1", then field 2 is mandatory
Case 2: if editor choose Field 1 value is "value2", then filed 2 is optional.
How to do this validation either in form/field validation before commit action.
Or how do we validate in commit action.
Any lead will help me a lot. I am stuck in this issue for longtime.
I tried with cross-field, dynamic filed , switchable and composite field as suggested in documentation, but I got null pointer exceptions. If you know the solution please share code snippet also.
I also suffered with this type of validation. The problem is in the isolation of the fields. I couldn't find a way to validate one field depending on another field value.
Anyway I found a workaround solution. I aggregate two dependent fields with complex field and create a validator for it.
Here's my code for the Magnolia 5.7 and vaadin validator (it's deprecated 7th version, nevertheless the logic will be the same with the 8th version).
public class CompanyRequiredFieldsValidator implements Validator {
private final ConfiguredFieldValidatorDefinition definition;
public CompanyRequiredFieldsValidator(ConfiguredFieldValidatorDefinition definition) {
this.definition = definition;
}
#Override
public void validate(Object value) throws InvalidValueException {
Optional<String> companyName = getString(value, "companyName");
if (companyName.isPresent()) {
getString(value, "companyAddress")
.orElseThrow(() -> new InvalidValueException(definition.getErrorMessage()));
}
}
private Optional<String> getString(Object value, String property) {
return Optional.of(value)
.filter(Item.class::isInstance).map(Item.class::cast)
.map(_v -> _v.getItemProperty(property))
.map(Property::getValue)
.filter(String.class::isInstance).map(String.class::cast)
.filter(StringUtils::isNotEmpty);
}
}
For complex fields validated value has com.vaadin.v7.data.Item type, so it's possible to get all properties from it.
The only problem, that the error message does not highlight the inner field, only whole complex field.
I am trying to create a list view using Recycler View and display a list. Lets say what I am trying to display is like a typical chat screen - image, message, sender_name etc.
So all this data is stored in Firebase Realtime Database. I am also using ViewModel and would like to use DiffUtil for efficiency - since messages can be deleted, edited, starred, new ones added etc.. Due to DiffUtil, I am using a ListAdapter.
The issue I am facing is that the ListAdapter needs a List and I use a ChildEventListener.
How do I now observe changes from Firebase using LiveData and then update my list so that I can pass back into my DiffUtil? So if I add a new message, I'd like that to be added to my RecyclerView and I'd like to do that using DiffUtil since the list can also be updated.
What I found through research was that I might need to use Room for this purpose and observe the query for changes - so observe something like a getAllMessages() method which would return the complete list and then I can use that to pass into my DiffUtil. That sounds like an overkill to me - the implementation of Room.
Any pointers or suggestions on how I can achieve my need?
Here is the structure of my db:
if you dare to start programming an app, you won't be able to get along with Room soon. if you take this step, SQL knowledge is necessary as well...so don't be shy and just dare to do it
GGK
So I figured this out by doing the following in my ViewModel.
private val _message = MutableLiveData<List<TextListModel>>()
val message: LiveData<List<TextListModel>>
get() = _message
//...
private val eventListener =
object : ValueEventListener {
override fun onCancelled(databaseError: DatabaseError) {
Timber.e("Error!! ${databaseError.toException()}")
}
override fun onDataChange(dataSnapshot: DataSnapshot) {
val listOfMessages : MutableList<TextListModel> = mutableListOf()
for(msg in dataSnapshot.children) {
val item = msg.getValue(TextListModel::class.java)
listOfMessages.add(item!!)
}
_message.value = listOfMessages
}
}
In my fragment I observe message and perform adapter.submitList(newList) when there is an update.
This downloading of data using ValueEventListener is concerning though since it pulls the data from under the node. I am checking on how to use ChildEventListener for my purposes.
EDIT
Seems like Value events don't download the full tree over! Value events work with the data in the local state and only downloads the delta.
Some more information in this Youtube Video from 2016!
I am just picking up Realm and was trying out the QuickJournal example present on GitHub in Xamarin Forms
After the entries are load up in the list view from the constructor as below
public JournalEntriesViewModel()
{
_realm = Realm.GetInstance();
Entries = _realm.All<JournalEntry>();
.. .
}
I added a search bar and was trying to filter and update the Entries collection
public string Filter
{
get
{
retur _filter;
}
set
{
_filter = value;
Filter();
}
}
private void Filter()
{
Entries = _realm.All<JournalEntry>().Where(i => i.Title.StartsWith(_filter));
}
The Filter property is bound to the SearchBar Text in Xaml and the Entries list changes but the UI never updates. My impression was that since Realm uses Fody the notification is propagated to the UI to update.
I have also tried the below change using ToList to fire off the query & map it to realm core as mentioned in the documentation but to no avail. Converting Entries to RealmCollection doesn't work either
Entries = _realm.All<JournalEntry>().ToList().Where(i => i.Title.StartsWith(_filter));
Can someone kindly explain what I am missing here
Many Thanks
I managed to workaround this by firing a PropertyChanged event for the Entries property to update the UI after assigning the value.
This is my first post, sorry my English
Hello every one. I am a new programmer in PHP and i would like to use Zend Mobile Framework to implement my push notificator server.
I'm searching how to implement the tomcat project used in
http://developer.android.com/guide/google/gcm/demo.html
but written in PHP.
In the code most below I written the used sources.
When I call the submit button, always have response with InvalidRegistration error.
Can anyone see where the error?
Thank You very much
http://pastebin.com/MauzLX71
According with Android GCM's architectural overview you have an invalidRegistration error when:
Invalid Registration ID Check the formatting of the registration ID
that you pass to the server. Make sure it matches the registration ID
the phone receives in the com.google.android.c2dm.intent.REGISTRATION
intent and that you're not truncating it or adding additional
characters. Happens when error code is InvalidRegistration.
Check the official GCM documentaion here, please.
One of the things that you are likely having happen here is the following:
Your code is actually processing and attempting to send a message prior to your call of sendPush which may be causing part of the issue.
I've modified the code and had put the registration id in there: http://pastebin.com/NhrD5N6i
Did you sign up for an API key and replace that portion in the code?
In the demo client application; it shows how to actually leverage the registration; see my comment on the following GitHub issue: https://github.com/mwillbanks/Zend_Mobile/issues/16
Your server needs to have the registration id from the device; this is likely what you do not have.
One way of getting the registration ID is on the onRegistered call inside the client app, do a Log.i("MY_APP_TAG", regId); then look at the logcat output.
Android Example
public class GCMIntentService extends GCMBaseIntentService {
public GCMIntentService() {
super(Constants.SENDER_ID);
}
#Override
protected void onRegistered(Context context, String regId) {
Log.i("MY_APP_TAG", "Registered: " + regId);
}
#Override
protected void onUnregistered(Context context, String regId) {
// write a call here to send the regId to your server and unregister it
}
#Override
protected void onMessage(Context context, Intent intent) {
Log.i("MY_APP_TAG", "Received message!");
// grabbing data looks like the following; the assumption
// is title is part of the data string.
String title = intent.getExtras().getString("title");
}
}
*Zend_Mobile_Push_Gcm Example*
See the updated link (http://pastebin.com/NhrD5N6i) I provided of your pasted code; you will want to use the registration ID above in the textbox.