# Conflicts:
#	app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java
This commit is contained in:
Matan Bar Yosef 2016-07-09 18:26:49 +03:00
commit 43c34b9316
10 changed files with 773 additions and 480 deletions

View file

@ -6,7 +6,9 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission." />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

View file

@ -377,6 +377,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
}
VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/like", jsonObj, getNotesSuccessListener, Utils.genericErrorListener);
mainActivity.getUser().getLiked_notes().add(note.getId());
mainActivity.getUser().updateUser(mainActivity);
likes.setText("Likes: "+(note.getLikes()+1));
}
}

View file

@ -38,11 +38,9 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
private TextView mRegisterButton;
private Button mLoginButton;
private final String TAG = "[TSN/LoginActivity]";
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
private final String LOGIN_PATH = "/login";
private LoginActivity self; //this
protected LinearLayout layout;
private boolean permissionsReturend = false;
@Override
@ -126,8 +124,6 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
try {
if (!response.isNull("user")) {
Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console
SharedPreferences sharedPref = self.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
String id, password, email, avatar, username, likedNotes = "";
JSONArray likedNotes_JSON;
@ -143,8 +139,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
likedNotes += User.LIKED_NOTES_DELIMETER;
}
}
editor.putString("UserData", id + User.ATTARS_DELIMETER + username + User.ATTARS_DELIMETER + password + User.ATTARS_DELIMETER + email + User.ATTARS_DELIMETER + avatar + User.ATTARS_DELIMETER + likedNotes);
editor.commit();
Utils.updateUserSharedPref(id + User.ATTARS_DELIMETER + username + User.ATTARS_DELIMETER + password + User.ATTARS_DELIMETER + email + User.ATTARS_DELIMETER + avatar + User.ATTARS_DELIMETER + likedNotes);
Intent personalSpaceActivity = new Intent(LoginActivity.this, MainActivity.class);
Bundle loginUserBundle = new Bundle();
loginUserBundle.putString("UserData", id + User.ATTARS_DELIMETER + username + User.ATTARS_DELIMETER + password + User.ATTARS_DELIMETER + email + User.ATTARS_DELIMETER + avatar + User.ATTARS_DELIMETER + likedNotes);

View file

@ -48,6 +48,7 @@ public class MainActivity extends AppCompatActivity
protected final String TAG = "[TSN / MainActivity]";
protected User user;
private GPSUtils gpsUtils;
private boolean locationPermission;
private GmapFragment gmapFragment;
private PersonalFragment personalFragment;
private SettingsFragment settingsFragment;
@ -64,8 +65,6 @@ public class MainActivity extends AppCompatActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.self = this;
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Personal Notes");
setSupportActionBar(toolbar);
@ -75,6 +74,7 @@ public class MainActivity extends AppCompatActivity
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
@ -172,10 +172,11 @@ public class MainActivity extends AppCompatActivity
ft.commit();
} else if (id == R.id.nav_logout) {
SharedPreferences sharedPref = this.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.remove("UserData");
editor.commit();
try {
Utils.removeUserDataFromPrefs();
} catch (Exception e) {
e.printStackTrace();
}
Intent loginActivity = new Intent(MainActivity.this, LoginActivity.class);
startActivity(loginActivity);
finish();
@ -206,8 +207,8 @@ public class MainActivity extends AppCompatActivity
switch (requestCode) {
case FINE_PERM: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 1) {
if (!(grantResults[0] == PackageManager.PERMISSION_GRANTED)){
if (grantResults.length > 2) {
if (!(grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
Log.d(TAG, "onRequestPermissionsResult: Did Not get permission for location");
Toast.makeText(MainActivity.this, "No Location Permissions granted.\n\"An App is nothing without its permissions\"", Toast.LENGTH_LONG).show();
System.exit(0);
@ -221,12 +222,28 @@ public class MainActivity extends AppCompatActivity
} else {
Utils.setCameraPermission(true);
}
if (grantResults[2] != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "onRequestPermissionsResult:DIDNT get READ\\WRITE External storage permission");
Toast.makeText(MainActivity.this, "No READ\\WRITE External storage Permissions granted.\nyou will not be able to change avatar", Toast.LENGTH_LONG).show();
Utils.setCameraPermission(false);
} else {
Utils.setCameraPermission(true);
}
return;
}
}
}
}
public void updateNavAvatar() {
//Change The Avatar
Log.d(TAG, "updateNavAvatar: PINPINPINPIN");
Utils.URLtoImageView(menu_avatar, user.getAvatar());
Toast.makeText(this, "Profile Updated!", Toast.LENGTH_LONG).show();
}
}

View file

@ -96,10 +96,13 @@ public class PersonalFragment extends Fragment {
ActivityCompat.requestPermissions(activity, new String[]{
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.CAMERA
android.Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE
},
FINE_PERM
);
// ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, FINE_PERM);
// if (!Utils.arePermissionsGranted()) {
@ -316,6 +319,7 @@ public class PersonalFragment extends Fragment {
try {
//need to get all notes and add to listOfNotes
JSONArray noteObjectsArray = response.getJSONArray("notes");
activity.getUser().setNumber_of_notes(noteObjectsArray.length());
Date time = new Date();
for (int i = 0; i < noteObjectsArray.length(); i++) {
JSONObject noteObject = noteObjectsArray.getJSONObject(i);

View file

@ -1,57 +1,56 @@
package com.android_app.matan.ara.sagi.thesocialnotework;
import android.*;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class SettingsFragment extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private static final String TAG = "Settings" ;
private static final int REQUEST_IMAGE_CAPTURE = 1;
private Button cameraBtn;
import com.android.volley.Response;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.File;
public class SettingsFragment extends Fragment implements View.OnClickListener, TextWatcher {
private static final String TAG = "[TSN/Settings]" ;
private MainActivity parent;
private ImageButton cameraBtn;
private ImageView avatarImage;
// private OnFragmentInteractionListener mListener;
private EditText txt_username, txt_password, txt_email;
private Uri currentImgUri;
private TextView lbl_num_of_notes, lbl_num_of_liked;
private User user;
private Button btn_save;
public SettingsFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment SettingsFragment.
*/
// TODO: Rename and change types and number of parameters
public static SettingsFragment newInstance(String param1, String param2) {
SettingsFragment fragment = new SettingsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
@ -63,19 +62,40 @@ public class SettingsFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_settings, container, false);
this.parent = (MainActivity)getActivity();
Utils.showLoadingDialog(parent, "Just a sec...", "");
this.user = parent.getUser();
Log.d(TAG, "onCreateView: "+user.toString());
this.cameraBtn = (ImageButton) view.findViewById(R.id.btn_camera);
this.cameraBtn.setOnClickListener(this);
this.avatarImage = (ImageView) view.findViewById(R.id.settings_userAvater_iamgeView);
this.txt_email = (EditText)view.findViewById(R.id.txt_email);
this.txt_email.addTextChangedListener(this);
this.txt_password = (EditText)view.findViewById(R.id.txt_password);
this.txt_password.addTextChangedListener(this);
this.txt_username = (EditText)view.findViewById(R.id.txt_username);
this.lbl_num_of_notes = (TextView)view.findViewById(R.id.lbl_num_of_notes);
this.lbl_num_of_liked = (TextView)view.findViewById(R.id.lbl_num_of_liked);
this.btn_save = (Button)view.findViewById(R.id.btn_save);
this.btn_save.setOnClickListener(this);
cameraBtn = (Button) view.findViewById(R.id.camera_button);
cameraBtn.setOnClickListener(cameraBtnListener);
avatarImage = (ImageView) view.findViewById(R.id.settings_userAvater_iamgeView);
this.txt_username.setEnabled(false);
//Populate The data
Utils.URLtoImageView(avatarImage, user.getAvatar());
this.txt_username.setText(""+user.getUsername());
this.txt_password.setText(""+user.getPassword());
Log.d(TAG, "onCreateView: The FUCKING EMAIL IS --------------->>>" + user.getEmail());
this.txt_email.setText(""+user.getEmail());
this.lbl_num_of_notes.setText(""+user.getNumber_of_notes()); //TODO
this.lbl_num_of_liked.setText(""+user.getLiked_notes().size());
Utils.dismissLoadingDialog();
return view;
}
// // TODO: Rename method, update argument and hook method into UI event
// public void onButtonPressed(Uri uri) {
// if (mListener != null) {
// mListener.onFragmentInteraction(uri);
// }
// }
@Override
public void onAttach(Context context) {
@ -87,64 +107,117 @@ public class SettingsFragment extends Fragment {
super.onDetach();
}
// /**
// * This interface must be implemented by activities that contain this
// * fragment to allow an interaction in this fragment to be communicated
// * to the activity and potentially other fragments contained in that
// * activity.
// * <p>
// * See the Android Training lesson <a href=
// * "http://developer.android.com/training/basics/fragments/communicating.html"
// * >Communicating with Other Fragments</a> for more information.
// */
// public interface OnFragmentInteractionListener {
// // TODO: Update argument type and name
// void onFragmentInteraction(Uri uri);
// }
private View.OnClickListener cameraBtnListener = new View.OnClickListener()
{
public void onClick(View v)
{
if (ActivityCompat.checkSelfPermission((MainActivity) getActivity(),
Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "in camera Button");
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}
else{
Toast.makeText(getActivity(), "No Location Permissions granted.\n\"An App is nothing without its permissions\"", Toast.LENGTH_LONG).show();
}
}
};
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "on activity result");
Log.d(TAG, "requestCode: "+requestCode);
Log.d(TAG, "resultCode: "+resultCode);
Log.d(TAG, "Activity.RESULT_OK: "+Activity.RESULT_OK);
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {
Log.d(TAG, "inside if");
public void onClick(View view) {
switch(view.getId()){
case R.id.btn_camera:
//check for permission
// ActivityCompat.requestPermissions(parent, new String[]{Manifest.permission.CAMERA}, 1);
if ((ActivityCompat.checkSelfPermission(parent, android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)
&&(ActivityCompat.checkSelfPermission(parent, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
openCamera(view);
}else{
Toast.makeText(getActivity(), "No Camera or Storage Permissions granted.\n\"An App is nothing without its permissions\"", Toast.LENGTH_LONG).show();
Bundle extras = data.getExtras();
Bitmap imageBitmap= (Bitmap) extras.get("data");
Log.d(TAG, "bitmap: "+imageBitmap.toString());
}
// Bitmap imageBitmap = (Bitmap) extras.get("data");
avatarImage.setImageBitmap(imageBitmap);
break;
case R.id.btn_save:
user.updateUser(parent);
break;
}
}
/**
* creates a new camera intent
* @param v
*/
protected void openCamera(View v) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
createDir();
Long currentImageTimeStamp = System.currentTimeMillis();
String timeStamp = Long.toString(currentImageTimeStamp);
File photo = new File(Utils.PHOTOS_DIR_PATH, timeStamp + ".jpg");
currentImgUri = Uri.fromFile(photo);
intent.putExtra(MediaStore.EXTRA_OUTPUT, currentImgUri);
Log.d(TAG, "openCamera: Image URI is: " + currentImgUri);
startActivityForResult(intent, 1);
}
protected void createDir() {
File f = new File(Utils.PHOTOS_DIR_PATH);
f.mkdirs();
}
@Override
public void onActivityResult(int requestCode, int resaultCode, Intent intent) {
super.onActivityResult(requestCode, requestCode, intent);
if (resaultCode == Activity.RESULT_OK) {
if (currentImgUri != null) {
saveImage();
Log.d(TAG, "onActivityResult: Image Capured!! - Now Upload That Shit!!");
} else { //capturing failed
Toast.makeText(getActivity(), "Failed to Get Photo, Try Again", Toast.LENGTH_LONG).show();
Log.e(TAG, "onActivityResult: Image URI returned as NULL - Orientation Fail");
}
} else {
Log.i(TAG, "onActivityResult: User Canceled Image taking");
}
}
private void saveImage() {
Utils.showLoadingDialog(parent, "Saving Image...", "This Can Take a while");
File myFile = new File(currentImgUri.getPath());
JSONObject payload = new JSONObject();
try {
payload.put("image", ImageToBase64(myFile.getAbsolutePath()));
} catch (JSONException e) {
e.printStackTrace();
Utils.dismissLoadingDialog();
Toast.makeText(parent, "Failed to upload image.. Try Again", Toast.LENGTH_LONG).show();
}
VolleyUtilSingleton.getInstance(parent).post(Utils.BASE_URL + Utils.UPLOAD_IMAGE_PATH, payload, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "onResponse: "+response.toString());
try {
user.setAvatar(response.getString("image_url"));
//Populate The data
Utils.URLtoImageView(avatarImage, user.getAvatar());
user.updateUser(parent);
} catch (JSONException e) {
e.printStackTrace();
}
Utils.dismissLoadingDialog();
}
}, Utils.genericErrorListener);
}
private String ImageToBase64(String filePath){
Bitmap bm = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 50, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
Log.d(TAG, "ImageToBase64: "+b.length/1000);
return Base64.encodeToString(b, Base64.DEFAULT);
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
user.setEmail(txt_email.getText().toString());
user.setPassword(txt_password.getText().toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
}

View file

@ -1,16 +1,11 @@
package com.android_app.matan.ara.sagi.thesocialnotework;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.graphics.drawable.DrawableWrapper;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import java.util.Random;
@ -18,7 +13,6 @@ public class SplashActivity extends AppCompatActivity {
private ImageView background;
private int timerDelay = 3500;
private final String TAG = "Splash Screen Activity";
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -33,8 +27,8 @@ public class SplashActivity extends AppCompatActivity {
} else {
background.setImageDrawable( getResources().getDrawable(rand_splash()));
}
SharedPreferences sharedPref = this.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE);
final String userData = sharedPref.getString("UserData", null);
final String userData = Utils.getUserFromSharedPrefs(this);
Thread timerThread = new Thread(){
public void run(){

View file

@ -1,6 +1,15 @@
package com.android_app.matan.ara.sagi.thesocialnotework;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;
import com.android.volley.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Vector;
@ -21,9 +30,13 @@ public class User {
public static final String TAG = "[TSN/User]", ATTARS_DELIMETER="||" , LIKED_NOTES_DELIMETER="|";
protected String id, password, email, avatar, username;
protected Vector<String> liked_notes;
protected int number_of_notes;
protected User self;
public User(String serializedUserData){
self = this;
liked_notes = new Vector<>();
number_of_notes = 0;
String[] array = serializedUserData.split("\\|\\|");
for (int i = 0 ; i < array.length ; i ++){
switch (i){
@ -52,6 +65,14 @@ public class User {
}
}
public int getNumber_of_notes() {
return number_of_notes;
}
public void setNumber_of_notes(int number_of_notes) {
this.number_of_notes = number_of_notes;
}
public String getId() {
return id;
}
@ -119,7 +140,7 @@ public class User {
for (int i = 0; i < liked_notes.size(); i++) {
result += liked_notes.get(i);
if(i != liked_notes.size() - 1){
result+=";";
result+=User.LIKED_NOTES_DELIMETER;
}
}
return result;
@ -129,6 +150,46 @@ public class User {
return "Id: "+id+" UserName: " + username +" Password: " +password +" email: " + email+ " Avatar: " +avatar+" Liked Notes: "+liked_notes.toString();
}
public void updateUser(final MainActivity activity){
Log.d(TAG, "updateUser: ================================");
VolleyUtilSingleton.getInstance(activity).post(Utils.BASE_URL + "/user/upsert", this.toJSON(), new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
if(response.get("status").equals("OK")){
Log.d(TAG, "onResponse: In OKOKOKOK");
activity.updateNavAvatar();
Utils.updateUserSharedPref(self.Serialise());
activity.updateNavAvatar();
}
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}, Utils.genericErrorListener);
}
public JSONObject toJSON() {
JSONObject json = new JSONObject();
JSONArray liked = new JSONArray();
for (int i = 0; i < liked_notes.size(); i++) {
liked.put(liked_notes.get(i));
}
try {
json.put("id", this.id);
json.put("password", this.password);
json.put("username", this.username);
json.put("email", this.email);
json.put("avatar", this.avatar);
json.put("liked_notes_id", liked);
} catch (JSONException e) {
e.printStackTrace();
}
return json;
}
}

View file

@ -2,6 +2,7 @@ package com.android_app.matan.ara.sagi.thesocialnotework;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@ -11,6 +12,7 @@ import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;
import android.widget.ImageView;
@ -37,11 +39,14 @@ import java.util.HashMap;
public class Utils {
public static final String TAG = "Utils";
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api", UPLOAD_IMAGE_PATH="/file/upload";
public static ProgressDialog progress;
private static HashMap<String, Bitmap> bitmapHash = new HashMap<>();
public static final String PHOTOS_DIR_PATH = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/TheSocialNotework/";
private static boolean mLocationPermission = false;
private static boolean mCameraPermission = false;
private static SharedPreferences prefs;
public static Bitmap getBitmapFromURL(String url) {
@ -74,6 +79,7 @@ public class Utils {
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "genericErrorListener");
error.printStackTrace();
Utils.dismissLoadingDialog();
}
};
@ -142,7 +148,8 @@ public class Utils {
private static class setUserAvatar extends AsyncTask<Void, Void, Bitmap> {
private ImageView iv;
private String url;
public setUserAvatar(ImageView imageView, String url){
public setUserAvatar(ImageView imageView, String url) {
this.iv = imageView;
this.url = url;
}
@ -156,9 +163,8 @@ public class Utils {
}
@Override
protected void onPostExecute(Bitmap b){
protected void onPostExecute(Bitmap b) {
iv.setImageBitmap(b);
//getRoundedCornerBitmap(b, 20);
}
}
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
@ -204,6 +210,28 @@ public class Utils {
return mLocationPermission;
}
public static String getUserFromSharedPrefs(Context contexst){
if(prefs == null){
prefs = contexst.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE);
}
return prefs.getString("UserData", null);
};
public static void updateUserSharedPref(String data) throws Exception {
if(prefs == null) throw new Exception("Prefs are not available");
SharedPreferences.Editor editor = prefs.edit();
editor.putString("UserData", data);
editor.commit();
}
public static void removeUserDataFromPrefs() throws Exception{
if(prefs == null) throw new Exception("Prefs are not available");
SharedPreferences.Editor editor = prefs.edit();
editor.remove("UserData");
editor.commit();
}
}

View file

@ -1,20 +1,138 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.android_app.matan.ara.sagi.thesocialnotework.SettingsFragment">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:padding="10dp"
android:layout_marginTop="15dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.26">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.65">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txt_username"
android:hint="Username" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/txt_password"
android:hint="Password" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/txt_email"
android:hint="Email"
android:inputType="none|text" />
</LinearLayout>
<RelativeLayout
android:layout_width="90dp"
android:layout_height="90dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/settings_userAvater_iamgeView"
android:layout_gravity="top|center_horizontal"
android:src="@drawable/default_avatar" />
<ImageButton
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/btn_camera"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="@android:color/transparent"
android:src="@drawable/ic_menu_camera"
android:tint="#7b7b7b" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="0.14"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Nuber Of Notes: "
android:id="@+id/textView3"
android:textStyle="bold"
android:layout_weight="0.25" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="15"
android:id="@+id/lbl_num_of_notes"
android:layout_weight="0.25" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Notes I Liked:"
android:id="@+id/textView4"
android:textStyle="bold"
android:layout_weight="0.25" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="30"
android:id="@+id/lbl_num_of_liked"
android:layout_weight="0.25" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="126dp"
android:layout_gravity="right"
android:layout_weight="0.07">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change"
android:id="@+id/camera_button"
android:layout_gravity="center"/>
android:text="Save Changes"
android:id="@+id/btn_save"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="29dp" />
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/settings_userAvater_iamgeView"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>