Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug - view doesn't seem to redraw correctly when restored from saved state #172

Closed
chpasha opened this issue Jan 23, 2020 · 8 comments
Closed
Assignees
Labels
Bug bug!!

Comments

@chpasha
Copy link

chpasha commented Jan 23, 2020

There seems to be an issue with redrawing correctly (at least the speed value) if restored from saved state. I'm using TubeSpeedometer but since values are restored in base class (Gauge) maybe the problem is common to all types. The symptoms are - if I minimize the app, kill it and restore, the value of TubeSpeedometer stays at 100 (why 100? default value of maxSpeed?) - inspite of correct value 38100 being assigned. After debugging I noticed that the correct value is ignored while setting (and thus animation etc.) since the old value is already correct (because it is restored by component itself). A quick workaround was to set the value twice with view.speedTo(value++) and view.speedTo(value--) - with it the TubeSpeedometer redraws correctly since value is changed.
So there must be something wrong in the redraw logic when the view is restored from saved state

@anastr
Copy link
Owner

anastr commented Jan 24, 2020

May I have a little bit information about your view...
What's the max speed of your speedometer?
If you leave the min-max speed as default, this issue still come up?

@anastr anastr added the Bug bug!! label Jan 24, 2020
@anastr anastr self-assigned this Jan 24, 2020
@chpasha
Copy link
Author

chpasha commented Jan 24, 2020

I use it not as speedometer but as a circle gauge, so the values are way bigger than the usual defaults (that is why I suspect that the value of 100 comes from some defaults of the TubeSpeedometer or its parent). This is the code I use to bind the values to the widget via Android Binding

@BindingAdapter("mileage")
	public static void setValue(TubeSpeedometer view, Vehicle vehicle)
	{
		float mileage = vehicle != null ? defaultIfNull(vehicle.getCurrentMileage(), 0f) : 0f;
		float annualMileage = vehicle != null ? defaultIfNull(vehicle.getAnnualMileage(), 0f) : 0;
		float maxValue = Math.max(annualMileage, mileage);

		view.setMinSpeed(0f);
		view.setMaxSpeed(Math.max(maxValue, 1));
		//Workaround
		//view.speedTo(mileage++);
		//view.speedTo(mileage--);
                 view.speedTo(mileage);

		view.clearSections();
		if (annualMileage < mileage)
		{
			view.addSections(new Section(1f, Color.RED));

			view.setTickNumber(1);
			view.setTicks(new ArrayList<>(Collections.singletonList(annualMileage)));
		}
		else
		{
			view.setTickNumber(0);
			view.addSections(new Section(1f, view.getResources().getColor(R.color.colorForeground)));
		}
	}

the values for this vehicle are mileage 38100, annual mileage (max) - 40000. The component is alright (without workaround) all the time except for the case when I minimize the app, kill it and restore. But the workaround does the job.

P. S. of course I restore the values myself, so in this case we have a double job - vehicle has restored values and the Gauge has restored them as well, but the problem is that it doesn't reflect them after restore and setting them in BindingAdapter to the same values has no effect

@anastr
Copy link
Owner

anastr commented Jan 24, 2020

I found out that the min-max Values are the problem, what really happened is that speed value has been restored but min-max Values are not...
Thanks for reporting this issue, it will be fixed as soon as possible.

@chpasha
Copy link
Author

chpasha commented Jan 24, 2020

Great, thank you.

Are you sure, you have to restore anything? I think it is a responsibility of the app to restore and reset data. Even if you do - your widget is not alone in the view hierarchy, so other data still has to be saved and restored

@anastr
Copy link
Owner

anastr commented Jan 24, 2020

Literally, Android system will not restored anything you have changed at the run time, which means our responsibility to do so.

That's the logic of the app life cycle.

@chpasha
Copy link
Author

chpasha commented Jan 24, 2020

Yes, I know, what I mean is - I'm not sure that your widget has to store and restore data, I think that the application, that uses it, should do this.

@anastr
Copy link
Owner

anastr commented Jan 24, 2020

You are right, i should remove it in the next version.

@anastr
Copy link
Owner

anastr commented Feb 23, 2020

done c93b5e1, it's user responsibility for now.

@anastr anastr closed this as completed Feb 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug bug!!
Projects
None yet
Development

No branches or pull requests

2 participants