Nav Avater - Changes

This commit is contained in:
Sagi Dayan 2016-07-08 01:09:29 +03:00
parent db3d15fa0a
commit f3e410a679
3 changed files with 34 additions and 6 deletions

View file

@ -13,6 +13,7 @@ import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
@ -26,6 +27,7 @@ import android.widget.ImageView;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.google.android.gms.maps.model.MarkerOptions;
import org.json.JSONArray;
import org.json.JSONException;
@ -48,12 +50,15 @@ public class MainActivity extends AppCompatActivity
private Toolbar toolbar;
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
private ImageView menu_avatar;
private MainActivity self;
private NavigationView nav_view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.self = this;
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Personal Notes");
setSupportActionBar(toolbar);
@ -65,6 +70,8 @@ public class MainActivity extends AppCompatActivity
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);
@ -78,8 +85,11 @@ public class MainActivity extends AppCompatActivity
//get Bundle data (UserString)
Bundle b = getIntent().getExtras();
this.user = new User(b.getString("UserData"));
menu_avatar = (ImageView)findViewById(R.id.user_avatar);
//TODO - Change the menu_avatar to user.getAvatar()
//Get The Nav_View Avatar View
nav_view = (NavigationView) findViewById(R.id.nav_view);
View header_v = nav_view.getHeaderView(0);
menu_avatar = (ImageView)header_v.findViewById(R.id.nav_user_avatar);
//Change Layout
@ -92,6 +102,9 @@ public class MainActivity extends AppCompatActivity
Log.d(TAG, "Changed");
gpsUtils = new GPSUtils(this);
gpsUtils.getLocation();
//Change The Avatar
new setUserAvatar().execute();
}
@Override
@ -156,7 +169,7 @@ public class MainActivity extends AppCompatActivity
SharedPreferences sharedPref = this.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.remove("UserId");
editor.remove("UserData");
editor.commit();
Intent loginActivity = new Intent(MainActivity.this, LoginActivity.class);
startActivity(loginActivity);
@ -188,4 +201,19 @@ public class MainActivity extends AppCompatActivity
public String getUserId(){return user.getId();}
private class setUserAvatar extends AsyncTask<Void, Void, Bitmap> {
@Override
protected Bitmap doInBackground(Void... v) {
Bitmap b = Utils.getBitmapFromURL(self.user.getAvatar());
return b;
}
@Override
protected void onPostExecute(Bitmap b){
self.menu_avatar.setImageBitmap(b);
}
}
}

View file

@ -111,7 +111,7 @@ public class User {
}
public String Serialise(){
return id + "||" + username + "||" + password + "||" + email + "||" + serialiseNoteList();
return id + ATTARS_DELIMETER + username + ATTARS_DELIMETER + password + ATTARS_DELIMETER + email + ATTARS_DELIMETER +avatar + ATTARS_DELIMETER + serialiseNoteList();
}
private String serialiseNoteList() {
@ -126,7 +126,7 @@ public class User {
}
public String toString(){
return "Id: "+id+" UserName: " + username +" Password: " +password +" email: " + email+ " Liked Notes: "+liked_notes.toString();
return "Id: "+id+" UserName: " + username +" Password: " +password +" email: " + email+ " Avatar: " +avatar+" Liked Notes: "+liked_notes.toString();
}

View file

@ -14,7 +14,7 @@
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:id="@+id/user_avatar"
android:id="@+id/nav_user_avatar"
android:src="@drawable/default_avatar"
android:scaleType="fitCenter"
android:layout_alignParentTop="true"