mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-08 08:26:09 +00:00
OCHttpClient::getPhoneList now used GoLang aar
* add handleEarlyHTTPStatus to properly handle http return codes in java part * cleanup dead code
This commit is contained in:
parent
1f26787983
commit
db2cc05a3a
Binary file not shown.
@ -12,15 +12,13 @@ import android.view.View;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import fr.unix_experience.owncloud_sms.R;
|
import fr.unix_experience.owncloud_sms.R;
|
||||||
import fr.unix_experience.owncloud_sms.adapters.ContactListAdapter;
|
import fr.unix_experience.owncloud_sms.adapters.ContactListAdapter;
|
||||||
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
|
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
|
||||||
|
import ncsmsgo.SmsPhoneListResponse;
|
||||||
|
|
||||||
public interface ASyncContactLoad {
|
public interface ASyncContactLoad {
|
||||||
class ContactLoadTask extends AsyncTask<Void, Void, Boolean> {
|
class ContactLoadTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
@ -68,10 +66,15 @@ public interface ASyncContactLoad {
|
|||||||
|
|
||||||
ArrayList<String> serverPhoneList = new ArrayList<>();
|
ArrayList<String> serverPhoneList = new ArrayList<>();
|
||||||
|
|
||||||
JSONArray phoneNumbers = _client.getServerPhoneNumbers();
|
SmsPhoneListResponse splr = _client.getServerPhoneNumbers();
|
||||||
for (int i = 0; i < phoneNumbers.length(); i++) {
|
if (splr == null) {
|
||||||
String phone = phoneNumbers.getString(i);
|
_objects.add(_context.getString(R.string.err_fetch_phonelist));
|
||||||
serverPhoneList.add(phone);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String phoneNumber;
|
||||||
|
while (!(phoneNumber = splr.getNextEntry()).equals("")) {
|
||||||
|
serverPhoneList.add(phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read all contacts
|
// Read all contacts
|
||||||
@ -81,9 +84,6 @@ public interface ASyncContactLoad {
|
|||||||
|
|
||||||
// Sort phone numbers
|
// Sort phone numbers
|
||||||
Collections.sort(_objects);
|
Collections.sort(_objects);
|
||||||
} catch (JSONException e) {
|
|
||||||
_objects.add(_context.getString(R.string.err_fetch_phonelist));
|
|
||||||
return false;
|
|
||||||
} catch (OCSyncException e) {
|
} catch (OCSyncException e) {
|
||||||
_objects.add(_context.getString(e.getErrorId()));
|
_objects.add(_context.getString(e.getErrorId()));
|
||||||
return false;
|
return false;
|
||||||
|
@ -47,6 +47,7 @@ import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
|
|||||||
import fr.unix_experience.owncloud_sms.providers.AndroidVersionProvider;
|
import fr.unix_experience.owncloud_sms.providers.AndroidVersionProvider;
|
||||||
import ncsmsgo.SmsBuffer;
|
import ncsmsgo.SmsBuffer;
|
||||||
import ncsmsgo.SmsHTTPClient;
|
import ncsmsgo.SmsHTTPClient;
|
||||||
|
import ncsmsgo.SmsPhoneListResponse;
|
||||||
import ncsmsgo.SmsPushResponse;
|
import ncsmsgo.SmsPushResponse;
|
||||||
|
|
||||||
public class OCHttpClient {
|
public class OCHttpClient {
|
||||||
@ -108,17 +109,13 @@ public class OCHttpClient {
|
|||||||
return new Pair<>(0, null);
|
return new Pair<>(0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<Integer, JSONObject> post(String oc_call, String data) throws OCSyncException {
|
private void handleEarlyHTTPStatus(int httpStatus) throws OCSyncException {
|
||||||
Log.i(OCHttpClient.TAG, "Perform POST " + _url + oc_call);
|
switch (httpStatus) {
|
||||||
try {
|
case 403: {
|
||||||
return execute("POST",
|
// Authentication failed
|
||||||
new URL(_url.toString() + oc_call), data, false);
|
throw new OCSyncException(R.string.err_sync_auth_failed, OCSyncErrorType.AUTH);
|
||||||
} catch (MalformedURLException e) {
|
}
|
||||||
Log.e(OCHttpClient.TAG, "Malformed URL provided, aborting. URL was: "
|
|
||||||
+ _url.toExternalForm() + oc_call);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Pair<>(0, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<Integer, JSONObject> getAllSmsIds() throws OCSyncException {
|
Pair<Integer, JSONObject> getAllSmsIds() throws OCSyncException {
|
||||||
@ -130,6 +127,8 @@ public class OCHttpClient {
|
|||||||
Integer serverAPIVersion = (int) _smsHttpClient.doVersionCall();
|
Integer serverAPIVersion = (int) _smsHttpClient.doVersionCall();
|
||||||
int httpStatus = (int) _smsHttpClient.getLastHTTPStatus();
|
int httpStatus = (int) _smsHttpClient.getLastHTTPStatus();
|
||||||
|
|
||||||
|
handleEarlyHTTPStatus(httpStatus);
|
||||||
|
|
||||||
// If last status is not 200, send the wrong status now
|
// If last status is not 200, send the wrong status now
|
||||||
if (httpStatus != 200) {
|
if (httpStatus != 200) {
|
||||||
return new Pair<>(httpStatus, 0);
|
return new Pair<>(httpStatus, 0);
|
||||||
@ -153,11 +152,16 @@ public class OCHttpClient {
|
|||||||
|
|
||||||
Pair<Integer, SmsPushResponse> pushSms(SmsBuffer smsBuf) throws OCSyncException {
|
Pair<Integer, SmsPushResponse> pushSms(SmsBuffer smsBuf) throws OCSyncException {
|
||||||
SmsPushResponse spr = _smsHttpClient.doPushCall(smsBuf);
|
SmsPushResponse spr = _smsHttpClient.doPushCall(smsBuf);
|
||||||
return new Pair<>((int) _smsHttpClient.getLastHTTPStatus(), spr);
|
int httpStatus = (int) _smsHttpClient.getLastHTTPStatus();
|
||||||
|
handleEarlyHTTPStatus(httpStatus);
|
||||||
|
return new Pair<>(httpStatus, spr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<Integer, JSONObject> getPhoneList() throws OCSyncException {
|
Pair<Integer, SmsPhoneListResponse> getPhoneList() throws OCSyncException {
|
||||||
return get(_smsHttpClient.getPhoneListCall(), true);
|
SmsPhoneListResponse splr = _smsHttpClient.doGetPhoneList();
|
||||||
|
int httpStatus = (int) _smsHttpClient.getLastHTTPStatus();
|
||||||
|
handleEarlyHTTPStatus(httpStatus);
|
||||||
|
return new Pair<>(httpStatus, splr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<Integer, JSONObject> getMessages(Long start, Integer limit) throws OCSyncException {
|
Pair<Integer, JSONObject> getMessages(Long start, Integer limit) throws OCSyncException {
|
||||||
|
@ -23,8 +23,6 @@ import android.content.Context;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@ -35,6 +33,7 @@ import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType;
|
|||||||
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
|
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
|
||||||
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
|
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
|
||||||
import ncsmsgo.SmsBuffer;
|
import ncsmsgo.SmsBuffer;
|
||||||
|
import ncsmsgo.SmsPhoneListResponse;
|
||||||
import ncsmsgo.SmsPushResponse;
|
import ncsmsgo.SmsPushResponse;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@ -74,18 +73,13 @@ public class OCSMSOwnCloudClient {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray getServerPhoneNumbers() throws OCSyncException {
|
SmsPhoneListResponse getServerPhoneNumbers() throws OCSyncException {
|
||||||
Pair<Integer, JSONObject> response = _http.getPhoneList();
|
Pair<Integer, SmsPhoneListResponse> response = _http.getPhoneList();
|
||||||
if (response.second == null) {
|
if (response.second == null || response.first != 200) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return response.second;
|
||||||
return response.second.getJSONArray("phoneList");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Log.e(OCSMSOwnCloudClient.TAG, "No phonelist received from server, empty it", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doPushRequest(SmsBuffer smsBuffer) throws OCSyncException {
|
public void doPushRequest(SmsBuffer smsBuffer) throws OCSyncException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user