Commit 816fab51 by Kunj Gupta

Fixed - Pre fill user detail in variable from screen.

parent df26a011
...@@ -20,6 +20,14 @@ public class UserApiValues { ...@@ -20,6 +20,14 @@ public class UserApiValues {
@Expose @Expose
private String sysId; private String sysId;
@SerializedName("name")
@Expose
private String fullName;
@SerializedName("user_name")
@Expose
private String userId;
public String getFirstName() { public String getFirstName() {
return firstName; return firstName;
} }
...@@ -43,4 +51,20 @@ public class UserApiValues { ...@@ -43,4 +51,20 @@ public class UserApiValues {
public void setSysId(String sysId) { public void setSysId(String sysId) {
this.sysId = sysId; this.sysId = sysId;
} }
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
} }
...@@ -9,6 +9,7 @@ import android.content.ContentUris; ...@@ -9,6 +9,7 @@ import android.content.ContentUris;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Typeface; import android.graphics.Typeface;
...@@ -76,6 +77,7 @@ import com.vsoft.uoflservicenow.utils.CatalogueLog; ...@@ -76,6 +77,7 @@ import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils; import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.PartialCondition; import com.vsoft.uoflservicenow.utils.PartialCondition;
import com.vsoft.uoflservicenow.utils.PrefManager;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.uoflservicenow.utils.Util;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -118,7 +120,6 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -118,7 +120,6 @@ public class CatalogueVariableScreen extends AppCompatActivity {
private File mAttachmentFile; private File mAttachmentFile;
private Uri mAttachmentUri; private Uri mAttachmentUri;
private HashMap<CatalogueVariable, VariableViewContainer> mVariableViewMap; private HashMap<CatalogueVariable, VariableViewContainer> mVariableViewMap;
private HashMap<String, ArrayList<CatalogueVariable>> mContainerViewMap;
private static final int WRITE_EXTERNAL_STORAGE = 1; private static final int WRITE_EXTERNAL_STORAGE = 1;
private static final int FILE_SELECT_CODE = 0; private static final int FILE_SELECT_CODE = 0;
...@@ -364,7 +365,11 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -364,7 +365,11 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if(!mCatalogueVariableList.isEmpty()) { if(!mCatalogueVariableList.isEmpty()) {
VariableViewContainer container; VariableViewContainer container;
SharedPreferences sharedPreferences = null;
for (int i = 0; i < mCatalogueVariableList.size(); i++) { for (int i = 0; i < mCatalogueVariableList.size(); i++) {
if(sharedPreferences == null) {
sharedPreferences = getSharedPreferences(PrefManager.PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE);
}
CatalogueVariable catalogueVariable = mCatalogueVariableList.get(i); CatalogueVariable catalogueVariable = mCatalogueVariableList.get(i);
/*If API return active false for a variable, there is no need show that variable*/ /*If API return active false for a variable, there is no need show that variable*/
if(catalogueVariable.isActive()) { if(catalogueVariable.isActive()) {
...@@ -402,6 +407,14 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -402,6 +407,14 @@ public class CatalogueVariableScreen extends AppCompatActivity {
View controlView = container.getInputView(); View controlView = container.getInputView();
if (controlView != null) { if (controlView != null) {
/*For set default text in full_name and user_id textView.*/
if(catalogueVariable.getName().equals(getString(R.string.catalogue_user_full_name))) {
String userFullName = sharedPreferences.getString(PrefManager.PREFERENCE_USER_FULL_NAME, "");
((EditText)controlView).setText(userFullName);
} else if(catalogueVariable.getName().equals(getString(R.string.catalogue_user_id))) {
String userId = sharedPreferences.getString(PrefManager.PREFERENCE_USER_ID, "");
((EditText)controlView).setText(userId);
}
if (viewType == ViewType.DATE) { if (viewType == ViewType.DATE) {
controlView.setOnClickListener(dateListener); controlView.setOnClickListener(dateListener);
} else if (viewType == ViewType.DATE_AND_TIME) { } else if (viewType == ViewType.DATE_AND_TIME) {
......
...@@ -181,8 +181,10 @@ public class LoginScreen extends Activity { ...@@ -181,8 +181,10 @@ public class LoginScreen extends Activity {
if (mUserDetails != null) { if (mUserDetails != null) {
String firstName = mUserDetails.get(0).getFirstName(); String firstName = mUserDetails.get(0).getFirstName();
String lastName = mUserDetails.get(0).getLastName(); String lastName = mUserDetails.get(0).getLastName();
String sysid = mUserDetails.get(0).getSysId(); String sysId = mUserDetails.get(0).getSysId();
PrefManager.saveUserDetailsInPreferences(LoginScreen.this, firstName, lastName, sysid); String userFullName = mUserDetails.get(0).getFullName();
String userId = mUserDetails.get(0).getUserId();
PrefManager.saveUserDetailsInPreferences(LoginScreen.this, userFullName, userId, firstName, lastName, sysId);
startActivity(new Intent(LoginScreen.this, HomeScreen.class)); startActivity(new Intent(LoginScreen.this, HomeScreen.class));
finish(); finish();
} else { } else {
......
...@@ -10,21 +10,22 @@ import android.preference.PreferenceManager; ...@@ -10,21 +10,22 @@ import android.preference.PreferenceManager;
public class PrefManager { public class PrefManager {
private static volatile PrefManager pSelf = null; private static volatile PrefManager pSelf = null;
String TAG = PrefManager.class.getSimpleName();
private SharedPreferences sharedPref = null; private SharedPreferences sharedPref = null;
private SharedPreferences.Editor editor = null; private SharedPreferences.Editor editor = null;
//Login Preferences //Login Preferences
public static final String PREFERENCES_USER_VALUES_KEY = "UserPrefs"; public static final String PREFERENCES_USER_VALUES_KEY = "UserPrefs";
public static final String PREFERENCES_FIRST_NAME = "firstName"; private static final String PREFERENCES_FIRST_NAME = "firstName";
public static final String PREFERENCE_LAST_NAME = "lastName"; private static final String PREFERENCE_LAST_NAME = "lastName";
public static final String PREFERENCE_SYS_ID = "sysId"; public static final String PREFERENCE_SYS_ID = "sysId";
public static final String PREFERENCE_USER_FULL_NAME = "full_name";
public static final String PREFERENCE_USER_ID = "user_id";
public static PrefManager getInstance(){ public static PrefManager getInstance() {
if(pSelf == null){ if(pSelf == null) {
synchronized(PrefManager.class){ synchronized(PrefManager.class) {
if(pSelf == null){ if(pSelf == null) {
pSelf = new PrefManager(); pSelf = new PrefManager();
} }
} }
...@@ -36,65 +37,66 @@ public class PrefManager { ...@@ -36,65 +37,66 @@ public class PrefManager {
/** /**
* save username and password in shared preferences * save username and password in shared preferences
* @param context * @param context
* @param firstname * @param firstName
* @param lastname * @param lastName
* @param sysid * @param sysId
*/ */
public static void saveUserDetailsInPreferences(Context context,String firstname,String lastname,String sysid) public static void saveUserDetailsInPreferences(Context context, String userFullName, String userId, String firstName, String lastName, String sysId) {
{
SharedPreferences sharedPreferences = context.getSharedPreferences(PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE); SharedPreferences sharedPreferences = context.getSharedPreferences(PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
/** /**
* some times we are getting a username with white space * some times we are getting a username with white space
* so we just removed here * so we just removed here
*/ */
editor.putString(PREFERENCES_FIRST_NAME, firstname); editor.putString(PREFERENCES_FIRST_NAME, firstName);
editor.putString(PREFERENCE_LAST_NAME, lastname); editor.putString(PREFERENCE_LAST_NAME, lastName);
editor.putString(PREFERENCE_SYS_ID, sysid); editor.putString(PREFERENCE_SYS_ID, sysId);
editor.putString(PREFERENCE_USER_FULL_NAME, userFullName);
editor.putString(PREFERENCE_USER_ID, userId);
editor.apply(); editor.apply();
} }
public void init(Context context){ public void init(Context context) {
sharedPref = PreferenceManager.getDefaultSharedPreferences(context); sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
editor = sharedPref.edit(); editor = sharedPref.edit();
} }
//! Generic function to get boolean value for specified key. //! Generic function to get boolean value for specified key.
public boolean getPrefValueBoolean(String mKey,boolean defValue){ public boolean getPrefValueBoolean(String mKey,boolean defValue) {
return sharedPref.getBoolean(mKey,defValue); return sharedPref.getBoolean(mKey,defValue);
} }
//! Generic function to get int value for specified key. //! Generic function to get int value for specified key.
public int getPrefValueInt(String mKey, int defValue){ public int getPrefValueInt(String mKey, int defValue) {
return sharedPref.getInt(mKey, defValue); return sharedPref.getInt(mKey, defValue);
} }
//! Generic function to string value for specified key. //! Generic function to string value for specified key.
public String getPrefValueString(String mKey,String defValue){ public String getPrefValueString(String mKey,String defValue) {
return sharedPref.getString(mKey, defValue); return sharedPref.getString(mKey, defValue);
} }
public Long getPrefValueLong(String mKey,Long defValue){ public Long getPrefValueLong(String mKey,Long defValue) {
return sharedPref.getLong(mKey,defValue); return sharedPref.getLong(mKey,defValue);
} }
public void putPrefValueBoolean(String mKey,boolean mValue){ public void putPrefValueBoolean(String mKey,boolean mValue) {
editor.putBoolean(mKey,mValue); editor.putBoolean(mKey,mValue);
editor.commit(); editor.commit();
} }
public void putPrefValueInt(String mKey,int mValue){ public void putPrefValueInt(String mKey,int mValue) {
editor.putInt(mKey, mValue); editor.putInt(mKey, mValue);
editor.commit(); editor.commit();
} }
public void putPrefValueString(String mKey,String mValue){ public void putPrefValueString(String mKey,String mValue) {
editor.putString(mKey, mValue); editor.putString(mKey, mValue);
editor.commit(); editor.commit();
} }
public void putLong(String mKey,long mValue){ public void putLong(String mKey,long mValue) {
editor.putLong(mKey,mValue); editor.putLong(mKey,mValue);
editor.commit(); editor.commit();
} }
......
...@@ -93,4 +93,12 @@ ...@@ -93,4 +93,12 @@
<string name="connection_alert_dialog_message">Please check your device settings to ensure you have a working internet connection.</string> <string name="connection_alert_dialog_message">Please check your device settings to ensure you have a working internet connection.</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<!--Catalogue Variable form screen - key for pre fill value-->
<string name="catalogue_user_full_name">full_name</string>
<string name="catalogue_user_id">user_id</string>
<!--Preference keys for pre fill value-->
<string name="preference_full_name">full_name</string>
<string name="preference_user_id">user_id</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment