Skip to content

Commit

Permalink
Merge pull request #2 from Philipp0002/usage-without-account
Browse files Browse the repository at this point in the history
Fix login for users without account (just device)
  • Loading branch information
Philipp0002 authored Jul 29, 2024
2 parents e2f310d + b7b1e55 commit a003c5b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
18 changes: 16 additions & 2 deletions app/src/main/java/de/raffaelhahn/xadgps_client/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ private void performLogin() {
@Override
public void received(JSONObject data) throws Exception {
if("0".equals(data.getString("state"))){
JSONObject userInfo = data.getJSONObject("userInfo");
saveUserData(userInfo.getString("userName"), userInfo.getString("loginName"), userInfo.getString("userID"));
if("0".equals(data.getString("loginType"))) {
JSONObject userInfo = data.getJSONObject("userInfo");
saveUserData(userInfo.getString("userName"), userInfo.getString("loginName"), userInfo.getString("userID"));
} else {
JSONObject deviceInfo = data.getJSONObject("deviceInfo");
saveDeviceData(deviceInfo.getString("deviceID"), deviceInfo.getString("deviceName"));
}
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
} else {
Expand Down Expand Up @@ -80,9 +85,18 @@ public void finished() {
public void saveUserData(String username, String loginName, String userId) {
SharedPreferences preferences = getSharedPreferences(Constants.SP_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("operating_mode", "USER");
editor.putString("username", username);
editor.putString("loginName", loginName);
editor.putString("userId", userId);
editor.apply();
}

public void saveDeviceData(String deviceId, String deviceName) {
SharedPreferences preferences = getSharedPreferences(Constants.SP_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("operating_mode", "DEVICE");
editor.putString("deviceId", deviceId);
editor.apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
Configuration.getInstance().setUserAgentValue(getPackageName());

SharedPreferences sharedPreferences = getSharedPreferences(Constants.SP_NAME, MODE_PRIVATE);
if(!sharedPreferences.contains("userId")){
if(!sharedPreferences.contains("operating_mode")){
startActivity(new Intent(this, LoginActivity.class));
finish();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ public Result doWork() {
SharedPreferences preferences = getApplicationContext().getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE);

GetDeviceListAsync getDeviceListAsync = new GetDeviceListAsync();
getDeviceListAsync.paramUserId = preferences.getString("userId", "");
getDeviceListAsync.paramTypeId = "0";
if(preferences.getString("operating_mode", "").equals("USER")) {
getDeviceListAsync.paramUserId = preferences.getString("userId", "");
getDeviceListAsync.paramTypeId = "0";
} else {
getDeviceListAsync.paramUserId = preferences.getString("deviceId", "");
getDeviceListAsync.paramTypeId = "1";
}

getDeviceListAsync.paramMapType = "Google";
getDeviceListAsync.paramLanguage = Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry();
getDeviceListAsync.runFetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ public void stopRequestDeviceListUpdate() {

public void updateDeviceList() {
GetDeviceListAsync getDeviceListAsync = new GetDeviceListAsync();
getDeviceListAsync.paramUserId = context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE).getString("userId", "");
getDeviceListAsync.paramTypeId = "0";
if(context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE).getString("operating_mode", "").equals("USER")) {
getDeviceListAsync.paramUserId = context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE).getString("userId", "");
getDeviceListAsync.paramTypeId = "0";
} else {
getDeviceListAsync.paramUserId = context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE).getString("deviceId", "");
getDeviceListAsync.paramTypeId = "1";
}
getDeviceListAsync.paramMapType = "Google";
getDeviceListAsync.paramLanguage = Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry();
getDeviceListAsync.callback = new AsyncCallback<JSONObject>() {
Expand Down

0 comments on commit a003c5b

Please sign in to comment.