Hi, I have an activity which defines 5 fragments in a ViewPager and I can swipe between all 5 fragments.
I defined a public method which quoteDetailsFragment can call in order to update the view in quoteViewFragment.
In quoteViewFragment, it reloads all of the fields to reflect the changes in the quoteDetailsFragment which is where all the checkboxes and edittexts are located. That's where you modify inputs for the quote.
Okay, here's the problem. If I remove everything from loadQuoteValues() and have it only update one single text field with a static string of characters, it takes about 1 second, which is the same amount of time it takes to update the entire quote, so there's no way to make the update take less time. Therefore, if I need to spend this second to update, I need to decide when I'm going to process the update on the quoteViewFragment side.
I tried the update in an asynchronous task but that doesn't allow me to update the view elements from a thread outside the user interface.
I tried the update when the user swipes but that was causing the swipe to hang for a second and skip a bunch of frames while it processed.
I tried running it inside an onTextChangedListener on each editText but then the editText inputs would hang for a second after each character input while the process ran.
I tried running it on editText blur through a focusChangeListener which worked great except the user will sometimes edit an editText and then swipe to the quote while the editText still has focus. Then the quote isn't being update with this last editText change unless the user first clicks into a different editText and then swipes.
As you can see, the editText listener updates the quote model and when the quoteViewFragment updates, it gets all data from the same quote model and recreates itself based on these values.
How can I update the second fragment without having the swipe nor input hang while it processes? My main goal here is to give users a screen with all inputs which they can modify based on what the customer wants and then they can swipe to see the quote already built, based on their inputs. It is acceptable to have a spinning wheel after swipe while the quote loads but I can't figure out how to get a callback after the swipe is complete. It always runs as soon as I lift my finger.
Java:
private void setupViewPager(ViewPager viewPager)
{
adapter = new ViewPagerAdapter(getSupportFragmentManager());
quoteDetailsFragment =new QuoteDetailsFragment();
quoteViewFragment =new QuoteViewFragment();
quoteModifiersFragment =new QuoteModifiersFragment();
quoteViewFragment2 = new QuoteViewFragment2();
quoteContractFragment = new QuoteContractFragment();
adapter.addFragment(quoteDetailsFragment,"Details");
adapter.addFragment(quoteViewFragment,"CHAT");
adapter.addFragment(quoteModifiersFragment,"CONTACTS");
adapter.addFragment(quoteViewFragment2, "TAB44");
adapter.addFragment(quoteContractFragment, "TAB55");
viewPager.setAdapter(adapter);
}
I defined a public method which quoteDetailsFragment can call in order to update the view in quoteViewFragment.
Java:
public void updateQuoteView()
{
quoteViewFragment.loadQuoteValues();
}
In quoteViewFragment, it reloads all of the fields to reflect the changes in the quoteDetailsFragment which is where all the checkboxes and edittexts are located. That's where you modify inputs for the quote.
Java:
public void loadQuoteValues()
{
Double quotePriceValue = quote.calculateQuotePrice();
// remove all views before populating the view again
optionsTable.removeAllViews();
buildingDetails.setText(String.valueOf(quote.getBuildingWidth()) + "' X " + String.valueOf(quote.getBuildingLength() + "' X " + String.valueOf(quote.getBuildingHeight() + "' " + quote.getBuildingType())));
quotePrice.setText(String.valueOf(defaultFormat.format(quotePriceValue)));
quotePrice2.setText(String.valueOf(defaultFormat.format(quotePriceValue)));
..................
Okay, here's the problem. If I remove everything from loadQuoteValues() and have it only update one single text field with a static string of characters, it takes about 1 second, which is the same amount of time it takes to update the entire quote, so there's no way to make the update take less time. Therefore, if I need to spend this second to update, I need to decide when I'm going to process the update on the quoteViewFragment side.
I tried the update in an asynchronous task but that doesn't allow me to update the view elements from a thread outside the user interface.
I tried the update when the user swipes but that was causing the swipe to hang for a second and skip a bunch of frames while it processed.
I tried running it inside an onTextChangedListener on each editText but then the editText inputs would hang for a second after each character input while the process ran.
I tried running it on editText blur through a focusChangeListener which worked great except the user will sometimes edit an editText and then swipe to the quote while the editText still has focus. Then the quote isn't being update with this last editText change unless the user first clicks into a different editText and then swipes.
Java:
for (final EditText editText : editTexts) { //need to be final for custom behaviors
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus)
{
// for blank inputs, like deleting the width to enter a new value
String editValue = editText.getText().toString().equals("") ? "0" : editText.getText().toString();
if(editText == buildingWidth){
quote.setBuildingWidth(Integer.parseInt(editValue));
}
else if(editText == buildingLength){
quote.setBuildingLength(Integer.parseInt(editValue));
}
................................
As you can see, the editText listener updates the quote model and when the quoteViewFragment updates, it gets all data from the same quote model and recreates itself based on these values.
How can I update the second fragment without having the swipe nor input hang while it processes? My main goal here is to give users a screen with all inputs which they can modify based on what the customer wants and then they can swipe to see the quote already built, based on their inputs. It is acceptable to have a spinning wheel after swipe while the quote loads but I can't figure out how to get a callback after the swipe is complete. It always runs as soon as I lift my finger.