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

fix(android): fix onprogress payload value for data other than HashMap #11168

Merged
merged 26 commits into from
Oct 21, 2019
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b3345a5
fix(android): fix onprogress payload value for data other than HashMap
ypbnv Aug 22, 2019
ce0fedb
Merge branch 'master' into TIMOB-27293
garymathews Sep 9, 2019
965146b
Merge branch 'master' into TIMOB-27293
sgtcoolguy Sep 9, 2019
7ab7007
Merge branch 'master' into TIMOB-27293
ypbnv Sep 10, 2019
21b6176
test: missing unit test
ypbnv Sep 11, 2019
830583a
Merge branch 'master' into TIMOB-27293
ypbnv Sep 11, 2019
129704d
Merge branch 'master' into TIMOB-27293
Sep 13, 2019
8684cdd
fix(android): add guard for zero length request
ypbnv Sep 16, 2019
f699ef2
Merge branch 'master' into TIMOB-27293
Sep 16, 2019
c285aec
Merge branch 'master' into TIMOB-27293
sgtcoolguy Sep 17, 2019
0b31821
Merge branch 'master' into TIMOB-27293
ypbnv Oct 9, 2019
6b0cd0a
test(ios): trying to fix the unit test fir iOS
ypbnv Oct 10, 2019
37543e4
Merge branch 'master' into TIMOB-27293
ypbnv Oct 10, 2019
ebb279c
test(ios): try using ImageView for cross-platform test
ypbnv Oct 10, 2019
048bec5
Merge branch 'master' into TIMOB-27293
ypbnv Oct 16, 2019
969d7d7
test(ios): try to fix progress event unit test for iOS
ypbnv Oct 16, 2019
d64c528
test(ios): put the send data in a dictionary
ypbnv Oct 17, 2019
c4e2e06
test(ios): try to pass the iOS test for progress event
ypbnv Oct 17, 2019
61713c3
test(ios): try to pass the iOS unit test
ypbnv Oct 17, 2019
b910850
Merge branch 'master' into TIMOB-27293
ypbnv Oct 17, 2019
63e741a
test(ios): try to pass a unit test in iOS
ypbnv Oct 17, 2019
0ae860e
Merge branch 'TIMOB-27293' of https://github.com/ypbnv/titanium_mobil…
ypbnv Oct 17, 2019
ec47cbf
test(android): try to pass the unit test
ypbnv Oct 17, 2019
c907837
Merge branch 'master' into TIMOB-27293
ypbnv Oct 21, 2019
9da2c04
fix(android): fix progress callback for request without multipart
ypbnv Oct 21, 2019
b5ef204
test: forgot to push the changed test
ypbnv Oct 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,6 @@ public void send(Object userData) throws UnsupportedEncodingException
aborted = false;

// TODO consider using task manager
int totalLength = 0;
needMultipart = false;

if (userData != null) {
Expand Down Expand Up @@ -1136,12 +1135,11 @@ public void send(Object userData) throws UnsupportedEncodingException
}

if (value instanceof TiBaseFile || value instanceof TiBlob || value instanceof HashMap) {
totalLength += addTitaniumFileAsPostData(key, value);
addTitaniumFileAsPostData(key, value);

} else {
String str = TiConvert.toString(value);
addPostData(key, str);
totalLength += str.length();
}

} else if (isGet) {
Expand Down Expand Up @@ -1172,8 +1170,7 @@ public void send(Object userData) throws UnsupportedEncodingException
Log.d(TAG, "Instantiating http request with method='" + method + "' and this url:", Log.DEBUG_MODE);
Log.d(TAG, this.url, Log.DEBUG_MODE);

clientThread =
new Thread(new ClientRunnable(totalLength), "TiHttpClient-" + httpClientThreadCounter.incrementAndGet());
clientThread = new Thread(new ClientRunnable(), "TiHttpClient-" + httpClientThreadCounter.incrementAndGet());
clientThread.setPriority(Thread.MIN_PRIORITY);
clientThread.start();

Expand All @@ -1182,16 +1179,14 @@ public void send(Object userData) throws UnsupportedEncodingException

private class ClientRunnable implements Runnable
{
private final int totalLength;
private int contentLength;
private PrintWriter printWriter;
private OutputStream outputStream;
private String boundary;
private static final String LINE_FEED = "\r\n";

public ClientRunnable(int totalLength)
public ClientRunnable()
{
this.totalLength = totalLength;
this.contentLength = 0;
}

Expand Down Expand Up @@ -1276,7 +1271,7 @@ public void run()
public void progress(int progress)
{
KrollDict data = new KrollDict();
double currentProgress = ((double) progress / totalLength);
double currentProgress = ((double) progress / contentLength);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ypbnv, we should check if content length is zero. I can see this potentially happening with an HTTP "PUT" without a body.

public void progress(int progress)
{
	if (contentLength <= 0) {
		return;
	}

	// The rest of the code goes here...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (currentProgress > 1)
currentProgress = 1;
data.put("progress", currentProgress);
Expand Down