@5.01.15 Dennis Thießen: SettingsActivity modifiziert und durch PreferenceFragment ersetzt
This commit is contained in:
@@ -72,12 +72,12 @@
|
||||
android:name="com.facebook.FacebookActivity"
|
||||
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"></activity>
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/title_activity_entrance"
|
||||
android:parentActivityName=".LoginActivity"
|
||||
android:screenOrientation="portrait"></activity>
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".MapsActivity"
|
||||
android:label="@string/title_activity_maps"
|
||||
@@ -104,22 +104,22 @@
|
||||
android:name=".ProfileActivity"
|
||||
android:label="@string/title_activity_user_config"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:screenOrientation="portrait"></activity>
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:label="@string/title_activity_settings"
|
||||
android:screenOrientation="portrait"></activity>
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".SubscriptionsActivity"
|
||||
android:label="@string/title_activity_subscriptions"
|
||||
android:screenOrientation="portrait"></activity>
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".ViewReportActivity"
|
||||
android:label="@string/title_activity_view_report"
|
||||
android:screenOrientation="portrait"></activity>
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".ReportWFActivity"
|
||||
android:label="@string/title_activity_report_wf"></activity>
|
||||
android:label="@string/title_activity_report_wf" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -1,168 +1,24 @@
|
||||
package org.deke.risk.riskahead;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.StringRequest;
|
||||
|
||||
import org.deke.risk.riskahead.helper.AppConfig;
|
||||
import org.deke.risk.riskahead.helper.AppController;
|
||||
import org.deke.risk.riskahead.fragment.SettingsFragment;
|
||||
import org.deke.risk.riskahead.helper.BaseActivity;
|
||||
import org.deke.risk.riskahead.helper.SessionManager;
|
||||
import org.deke.risk.riskahead.helper.TextValidator;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SettingsActivity extends BaseActivity {
|
||||
|
||||
private final static String mActivityTitle = "Account Settings";
|
||||
private final static String TAG = SettingsActivity.class.getSimpleName();
|
||||
|
||||
private TextView txtUsername;
|
||||
private TextView txtSurname;
|
||||
private TextView txtName;
|
||||
private TextView txtEmail;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
userHasToBeLoggedIn();
|
||||
|
||||
txtUsername = (TextView) findViewById(R.id.txt_settings_username);
|
||||
txtName = (TextView) findViewById(R.id.txt_settings_name);
|
||||
txtSurname = (TextView) findViewById(R.id.txt_settings_surname);
|
||||
txtEmail = (TextView) findViewById(R.id.txt_settings_email);
|
||||
|
||||
findViewById(R.id.btn_settings_req_password).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new AlertDialog.Builder(SettingsActivity.this)
|
||||
.setTitle("Send password reset E-Mail")
|
||||
.setMessage("Do you really want to reset your password? An E-Mail will be send to your address. Please follow the instructions to reset your password.")
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String tag_string_req = "requestpwreset";
|
||||
StringRequest strReq = getStringRequestResetPW(txtEmail.getText().toString());
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
|
||||
showMessage("E-Mail was sent to your address");
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// do nothing
|
||||
}
|
||||
})
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.btn_settings_change).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (txtUsername.getError() != null || txtEmail.getError() != null) {
|
||||
showMessage("Entered fields not valid\n" +
|
||||
"Please check errors first.");
|
||||
} else {
|
||||
showAlert();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
txtUsername.setText(user.get("username"));
|
||||
txtName.setText(user.get("name"));
|
||||
txtSurname.setText(user.get("surname"));
|
||||
txtEmail.setText(user.get("email"));
|
||||
|
||||
txtUsername.addTextChangedListener(new TextValidator(txtUsername, getApplicationContext()) {
|
||||
@Override
|
||||
public void validate(TextView textView, String text) {
|
||||
if (text.length() < 5) {
|
||||
textView.setError("Your username must be at least\n" +
|
||||
"5 characters in length.");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
txtEmail.addTextChangedListener(new TextValidator(txtEmail, getApplicationContext()) {
|
||||
@Override
|
||||
public void validate(TextView textView, String text) {
|
||||
if (!Patterns.EMAIL_ADDRESS.matcher(text).matches()) {
|
||||
textView.setError("Please enter a valid email address\n" +
|
||||
"e.g.: text@abc.de");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(user.get("providerType") != null && user.get("providerType").equals("local")){
|
||||
findViewById(R.id.btn_settings_req_password).setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
findViewById(R.id.btn_settings_req_password).setVisibility(View.INVISIBLE);
|
||||
}
|
||||
getFragmentManager().beginTransaction().replace(R.id.fragment_content, new SettingsFragment()).commit();
|
||||
}
|
||||
|
||||
private void showAlert() {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(SettingsActivity.this);
|
||||
|
||||
if(user.get("providerType") != null && user.get("providerType").equals("local")) {
|
||||
final EditText input = new EditText(this);
|
||||
input.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
||||
|
||||
alert.setView(input);
|
||||
|
||||
alert.setTitle("Change settings")
|
||||
.setMessage("Enter your password to confirm changes: ")
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String value = input.getText().toString();
|
||||
|
||||
String tag_string_req = "updateuser";
|
||||
StringRequest strReq = getStringChangeUserSettings(value);
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// do nothing
|
||||
}
|
||||
})
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
}else{
|
||||
alert.setTitle("Change settings")
|
||||
.setMessage("Do you really want to confirm changes?")
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
String tag_string_req = "updateuser";
|
||||
StringRequest strReq = getStringChangeUserSettings("");
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// do nothing
|
||||
}
|
||||
})
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -179,105 +35,7 @@ public class SettingsActivity extends BaseActivity {
|
||||
@Override
|
||||
protected String getActivityName() { return mActivityTitle; }
|
||||
|
||||
private StringRequest getStringChangeUserSettings(final String value) {
|
||||
showDialog();
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
Log.d(TAG, "Change user settings: " + response);
|
||||
hideDialog();
|
||||
|
||||
try {
|
||||
JSONObject jObj = new JSONObject(response);
|
||||
boolean error = jObj.getBoolean("error");
|
||||
if (!error) {
|
||||
showMessage(jObj.getString("msg"));
|
||||
JSONObject tmpuser = jObj.getJSONObject("user");
|
||||
session.addUser(tmpuser.getString("id"), tmpuser.getString("username"), tmpuser.getString("name"), tmpuser.getString("surname"), tmpuser.getString("email"), tmpuser.getString("status"), user.get("providerType"), tmpuser.getString("created_at"), tmpuser.getString("updated_at"), tmpuser.getString("lastlogin_at"), tmpuser.getString("accesskey"));
|
||||
finish();
|
||||
startActivity(getIntent());
|
||||
} else {
|
||||
String errorMsg = jObj.getString("error_msg");
|
||||
Log.e(TAG, "Error getting user settings (Server returned error): " + errorMsg);
|
||||
showMessage(errorMsg);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e(TAG, "Error getting user settings: " + error.getMessage());
|
||||
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||
hideDialog();
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getParams() {
|
||||
// Posting params to register url
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "updateuser");
|
||||
params.put("uid", user.get(SessionManager.KEY_UID));
|
||||
params.put("token", user.get(SessionManager.TOKEN));
|
||||
params.put("username", txtUsername.getText().toString());
|
||||
params.put("name", txtName.getText().toString());
|
||||
params.put("surname", txtSurname.getText().toString());
|
||||
params.put("email", txtEmail.getText().toString());
|
||||
params.put("providerType", user.get("providerType"));
|
||||
params.put("password", value);
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private StringRequest getStringRequestResetPW(final String email) {
|
||||
showDialog();
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
Log.d(TAG, "Resend E-Mail Response: " + response);
|
||||
hideDialog();
|
||||
|
||||
try {
|
||||
JSONObject jObj = new JSONObject(response);
|
||||
boolean error = jObj.getBoolean("error");
|
||||
if (!error) {
|
||||
//do nothing
|
||||
} else {
|
||||
String errorMsg = jObj.getString("error_msg");
|
||||
Log.e(TAG, "Error request email reset (Server returned error): " + errorMsg);
|
||||
showMessage(errorMsg);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e(TAG, "Error request email reset: " + error.getMessage());
|
||||
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||
hideDialog();
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getParams() {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "requestpwreset");
|
||||
params.put("email", email);
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
package org.deke.risk.riskahead.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.SwitchPreference;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.StringRequest;
|
||||
|
||||
import org.deke.risk.riskahead.R;
|
||||
import org.deke.risk.riskahead.SettingsActivity;
|
||||
import org.deke.risk.riskahead.helper.AppConfig;
|
||||
import org.deke.risk.riskahead.helper.AppController;
|
||||
import org.deke.risk.riskahead.helper.SessionManager;
|
||||
import org.deke.risk.riskahead.helper.TextValidator;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Dennis Thießen
|
||||
*/
|
||||
public class SettingsFragment extends PreferenceFragment {
|
||||
|
||||
private final static String TAG = SettingsFragment.class.getSimpleName();
|
||||
|
||||
private EditTextPreference prefUsername;
|
||||
private EditTextPreference prefSurname;
|
||||
private EditTextPreference prefName;
|
||||
private EditTextPreference prefEmail;
|
||||
|
||||
private SwitchPreference prefNotifications;
|
||||
private ListPreference prefRadius;
|
||||
private ListPreference prefFrequency;
|
||||
|
||||
private Preference btnRequestPW;
|
||||
|
||||
HashMap<String,String> user;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.settings);
|
||||
|
||||
prefUsername = (EditTextPreference) getPreferenceManager().findPreference("usernamePref");
|
||||
prefSurname = (EditTextPreference) getPreferenceManager().findPreference("surnamePref");
|
||||
prefName = (EditTextPreference) getPreferenceManager().findPreference("namePref");
|
||||
prefEmail = (EditTextPreference) getPreferenceManager().findPreference("emailPref");
|
||||
|
||||
btnRequestPW = (Preference) getPreferenceManager().findPreference("resetPassword");
|
||||
|
||||
prefRadius = (ListPreference) getPreferenceManager().findPreference("notifyRadius");
|
||||
prefNotifications = (SwitchPreference) getPreferenceManager().findPreference("notifyEnable");
|
||||
prefFrequency = (ListPreference) getPreferenceManager().findPreference("notifyFrequency");
|
||||
|
||||
prefUsername.getEditText().addTextChangedListener(new TextValidator(prefUsername.getEditText(), getActivity().getApplicationContext()) {
|
||||
@Override
|
||||
public void validate(TextView textView, String text) {
|
||||
if (text.length() < 5) {
|
||||
textView.setError("Your username must be at least\n" +
|
||||
"5 characters in length.");
|
||||
}
|
||||
}
|
||||
});
|
||||
prefEmail.getEditText().addTextChangedListener(new TextValidator(prefEmail.getEditText(), getActivity().getApplicationContext()) {
|
||||
@Override
|
||||
public void validate(TextView textView, String text) {
|
||||
if (!Patterns.EMAIL_ADDRESS.matcher(text).matches()) {
|
||||
textView.setError("Please enter a valid email address\n" +
|
||||
"e.g.: text@abc.de");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Preference.OnPreferenceChangeListener changeListener = new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
requestUpdateUserSettings(preference,newValue.toString());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
prefUsername.setOnPreferenceChangeListener(changeListener);
|
||||
prefSurname.setOnPreferenceChangeListener(changeListener);
|
||||
prefName.setOnPreferenceChangeListener(changeListener);
|
||||
prefEmail.setOnPreferenceChangeListener(changeListener);
|
||||
|
||||
btnRequestPW.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle("Send password reset E-Mail")
|
||||
.setMessage("Do you really want to reset your password? An E-Mail will be send to your address. Please follow the instructions to reset your password.")
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
requestPasswordReset();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// do nothing
|
||||
}
|
||||
})
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
updatePrefs();
|
||||
|
||||
if(!user.get(SessionManager.PROVIDER_TYPE).equals("local")){
|
||||
btnRequestPW.setEnabled(false);
|
||||
}else{
|
||||
btnRequestPW.setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void updatePrefs() {
|
||||
user = ((SettingsActivity) getActivity()).getUser();
|
||||
|
||||
prefUsername.setText(user.get(SessionManager.KEY_USERNAME));
|
||||
prefSurname.setText(user.get(SessionManager.KEY_SURNAME));
|
||||
prefName.setText(user.get(SessionManager.KEY_NAME));
|
||||
prefEmail.setText(user.get(SessionManager.KEY_EMAIL));
|
||||
|
||||
prefUsername.setSummary(user.get(SessionManager.KEY_USERNAME));
|
||||
prefSurname.setSummary(user.get(SessionManager.KEY_SURNAME));
|
||||
prefName.setSummary(user.get(SessionManager.KEY_NAME));
|
||||
prefEmail.setSummary(user.get(SessionManager.KEY_EMAIL));
|
||||
}
|
||||
|
||||
private void requestPasswordReset() {
|
||||
String tag_string_req = "requestpwreset";
|
||||
StringRequest strReq = getStringRequestResetPW(user.get(SessionManager.KEY_EMAIL));
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
|
||||
((SettingsActivity) getActivity()).showMessage("E-Mail was sent to your address");
|
||||
}
|
||||
|
||||
private StringRequest getStringRequestResetPW(final String email) {
|
||||
((SettingsActivity) getActivity()).showDialog();
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
Log.d(TAG, "Resend E-Mail Response: " + response);
|
||||
((SettingsActivity) getActivity()).hideDialog();
|
||||
|
||||
try {
|
||||
JSONObject jObj = new JSONObject(response);
|
||||
boolean error = jObj.getBoolean("error");
|
||||
if (!error) {
|
||||
//do nothing
|
||||
} else {
|
||||
String errorMsg = jObj.getString("error_msg");
|
||||
Log.e(TAG, "Error request email reset (Server returned error): " + errorMsg);
|
||||
((SettingsActivity) getActivity()).showMessage(errorMsg);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e(TAG, "Error request email reset: " + error.getMessage());
|
||||
((SettingsActivity) getActivity()).showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||
((SettingsActivity) getActivity()).hideDialog();
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getParams() {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "requestpwreset");
|
||||
params.put("email", email);
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void requestUpdateUserSettings(Preference pref, String newValue) {
|
||||
String username = prefUsername.getText(),name = prefName.getText(),surname = prefSurname.getText(),email = prefEmail.getText();
|
||||
|
||||
if(pref.getKey().equals("usernamePref")){
|
||||
username = newValue;
|
||||
}else if(pref.getKey().equals("namePref")){
|
||||
name = newValue;
|
||||
}else if(pref.getKey().equals("surnamePref")){
|
||||
surname = newValue;
|
||||
}else if(pref.getKey().equals("emailPref")){
|
||||
email = newValue;
|
||||
}
|
||||
|
||||
String tag_string_req = "updateuser";
|
||||
StringRequest strReq = getStringChangeUserSettings(username,name,surname,email);
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
|
||||
}
|
||||
|
||||
private StringRequest getStringChangeUserSettings(final String username, final String name, final String surname, final String email) {
|
||||
((SettingsActivity) getActivity()).showDialog();
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
Log.d(TAG, "Change user settings: " + response);
|
||||
((SettingsActivity) getActivity()).hideDialog();
|
||||
|
||||
try {
|
||||
JSONObject jObj = new JSONObject(response);
|
||||
boolean error = jObj.getBoolean("error");
|
||||
if (!error) {
|
||||
((SettingsActivity) getActivity()).showMessage(jObj.getString("msg"));
|
||||
JSONObject tmpuser = jObj.getJSONObject("user");
|
||||
((SettingsActivity) getActivity()).session.addUser(tmpuser.getString("id"), tmpuser.getString("username"), tmpuser.getString("name"), tmpuser.getString("surname"), tmpuser.getString("email"), tmpuser.getString("status"), user.get("providerType"), tmpuser.getString("created_at"), tmpuser.getString("updated_at"), tmpuser.getString("lastlogin_at"), tmpuser.getString("accesskey"));
|
||||
|
||||
} else {
|
||||
String errorMsg = jObj.getString("error_msg");
|
||||
Log.e(TAG, "Error getting user settings (Server returned error): " + errorMsg);
|
||||
((SettingsActivity) getActivity()).showMessage(errorMsg);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
updatePrefs();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e(TAG, "Error getting user settings: " + error.getMessage());
|
||||
((SettingsActivity) getActivity()).showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||
((SettingsActivity) getActivity()).hideDialog();
|
||||
updatePrefs();
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getParams() {
|
||||
// Posting params to register url
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "updateuser");
|
||||
params.put("uid", user.get(SessionManager.KEY_UID));
|
||||
params.put("token", user.get(SessionManager.TOKEN));
|
||||
params.put("username", username);
|
||||
params.put("name", name);
|
||||
params.put("surname", surname);
|
||||
params.put("email", email);
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.ads.AdListener;
|
||||
@@ -91,6 +90,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public HashMap<String, String> getUser(){
|
||||
user = session.getUserDetails();
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public abstract class TextValidator implements TextWatcher {
|
||||
|
||||
public TextValidator(TextView textView, Context context) {
|
||||
this.textView = textView;
|
||||
if(this.textView.getText().length() == 0) this.textView.setError(context.getResources().getString(R.string.error_enter_value));
|
||||
//if(this.textView.getText().length() == 0) this.textView.setError(context.getResources().getString(R.string.error_enter_value));
|
||||
}
|
||||
|
||||
public abstract void validate(TextView textView, String text);
|
||||
|
||||
@@ -16,130 +16,13 @@
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutMain"
|
||||
android:layout_below="@+id/toolbar"
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_below="@id/toolbar">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/layoutContent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_marginBottom="20dp">
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/til_settings_username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/txt_settings_username"
|
||||
android:hint="Username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/til_settings_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/til_settings_username">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/txt_settings_name"
|
||||
android:hint="@string/lbl_settings_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/til_settings_surname"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/til_settings_name">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/txt_settings_surname"
|
||||
android:hint="@string/lbl_settings_surname"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/til_settings_name"
|
||||
android:layout_toRightOf="@+id/til_settings_name"
|
||||
android:layout_toEndOf="@+id/til_settings_name" />
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/til_settings_email"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/til_settings_surname">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/txt_settings_email"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/lbl_settings_email"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/til_settings_password"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/til_settings_email">
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<com.beardedhen.androidbootstrap.BootstrapButton
|
||||
android:id="@+id/btn_settings_req_password"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
bootstrap:bootstrapText="@string/btn_settings_req_password"
|
||||
bootstrap:bootstrapBrand="primary"
|
||||
bootstrap:roundedCorners="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutFooter"
|
||||
android:gravity="center"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#7fbfbfbf"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_settings_change"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/white"
|
||||
android:background="@color/bg_common_trans"
|
||||
android:layout_marginRight="1dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:text="@string/btn_settings_change" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -313,6 +313,96 @@
|
||||
<item>Tiere</item>
|
||||
<item>Sonstiges…</item>
|
||||
</string-array>
|
||||
<string name="title_activity_settings_activityv2">Settings</string>
|
||||
|
||||
<!-- Strings related to Settings -->
|
||||
|
||||
<!-- Example General settings -->
|
||||
<string name="pref_header_general">General</string>
|
||||
|
||||
<string name="pref_title_social_recommendations">Enable social recommendations</string>
|
||||
<string name="pref_description_social_recommendations">Recommendations for people to contact
|
||||
based on your message history
|
||||
</string>
|
||||
|
||||
<string name="pref_title_display_name">Display name</string>
|
||||
<string name="pref_default_display_name">John Smith</string>
|
||||
|
||||
<string name="pref_title_add_friends_to_messages">Add friends to messages</string>
|
||||
<string-array name="pref_example_list_titles">
|
||||
<item>Always</item>
|
||||
<item>When possible</item>
|
||||
<item>Never</item>
|
||||
</string-array>
|
||||
<string-array name="pref_example_list_values">
|
||||
<item>1</item>
|
||||
<item>0</item>
|
||||
<item>-1</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Example settings for Data & Sync -->
|
||||
<string name="pref_header_data_sync">Data & sync</string>
|
||||
|
||||
<string name="pref_title_sync_frequency">Sync frequency</string>
|
||||
<string-array name="pref_sync_frequency_titles">
|
||||
<item>15 minutes</item>
|
||||
<item>30 minutes</item>
|
||||
<item>1 hour</item>
|
||||
<item>3 hours</item>
|
||||
<item>6 hours</item>
|
||||
<item>Never</item>
|
||||
</string-array>
|
||||
<string-array name="pref_sync_frequency_values">
|
||||
<item>15</item>
|
||||
<item>30</item>
|
||||
<item>60</item>
|
||||
<item>180</item>
|
||||
<item>360</item>
|
||||
<item>-1</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_title_system_sync_settings">System sync settings</string>
|
||||
|
||||
<!-- Example settings for Notifications -->
|
||||
<string name="pref_header_notifications">Notifications</string>
|
||||
|
||||
<string name="pref_title_new_message_notifications">New message notifications</string>
|
||||
|
||||
<string name="pref_title_ringtone">Ringtone</string>
|
||||
<string name="pref_ringtone_silent">Silent</string>
|
||||
|
||||
<string name="pref_title_vibrate">Vibrate</string>
|
||||
<string name="title_activity_settings_activity_v2">Settings</string>
|
||||
|
||||
<string-array name="notification_radius">
|
||||
<item>1 KM</item>
|
||||
<item>5 KM</item>
|
||||
<item>10 KM</item>
|
||||
<item>15 KM</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="notification_radius_entry">
|
||||
<item>1</item>
|
||||
<item>5</item>
|
||||
<item>10</item>
|
||||
<item>15</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="notification_freq">
|
||||
<item>Every 5 Minutes</item>
|
||||
<item>Every 10 Minutes</item>
|
||||
<item>Every 15 Minutes</item>
|
||||
<item>Every 30 Minutes</item>
|
||||
<item>Every hour</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="notification_freq_entry">
|
||||
<item>5</item>
|
||||
<item>10</item>
|
||||
<item>15</item>
|
||||
<item>30</item>
|
||||
<item>60</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
</resources>
|
||||
|
||||
67
app/src/main/res/xml/settings.xml
Normal file
67
app/src/main/res/xml/settings.xml
Normal file
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="Account Settings">
|
||||
|
||||
<EditTextPreference
|
||||
android:key="usernamePref"
|
||||
android:title="Username"
|
||||
android:summary="Please enter your username"
|
||||
android:dialogTitle="Enter your username" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="namePref"
|
||||
android:title="Name"
|
||||
android:summary="Please enter your name"
|
||||
android:dialogTitle="Enter your name" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="surnamePref"
|
||||
android:title="Surname"
|
||||
android:summary="Please enter your surname"
|
||||
android:dialogTitle="Enter your surname" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="emailPref"
|
||||
android:inputType="textEmailAddress"
|
||||
android:title="E-Mail"
|
||||
android:summary="Please enter your email"
|
||||
android:dialogTitle="Enter your email" />
|
||||
|
||||
<Preference
|
||||
android:key="resetPassword"
|
||||
android:title="Reset Password"
|
||||
android:summary="Request a new password" />
|
||||
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="Notifications">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="notfiyEnable"
|
||||
android:title="Show Notifications"
|
||||
android:summary="Enable notifications in your area" />
|
||||
|
||||
<ListPreference
|
||||
android:key="notifyRadius"
|
||||
android:title="Radius"
|
||||
android:entries="@array/notification_radius"
|
||||
android:entryValues="@array/notification_radius_entry"
|
||||
android:summary="Choose the radius from your last known location in which notifications will be displayed"
|
||||
android:dialogTitle="Notification Radius" />
|
||||
|
||||
<ListPreference
|
||||
android:key="notifyFrequency"
|
||||
android:title="Poll Frequency"
|
||||
android:entries="@array/notification_freq"
|
||||
android:entryValues="@array/notification_freq_entry"
|
||||
android:summary="Decide how often notification updates should be received from server"
|
||||
android:dialogTitle="Poll Frequency" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
Reference in New Issue
Block a user