From f3e410a679fefca1e7b48c34a7dbfbdd364de402 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Fri, 8 Jul 2016 01:09:29 +0300 Subject: [PATCH] Nav Avater - Changes --- .../sagi/thesocialnotework/MainActivity.java | 34 +++++++++++++++++-- .../ara/sagi/thesocialnotework/User.java | 4 +-- app/src/main/res/layout/nav_header_main.xml | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java index 47e79dc..a1d12e2 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java @@ -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 { + + @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); + } + + } + } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/User.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/User.java index 25c95dd..d7ebd89 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/User.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/User.java @@ -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(); } diff --git a/app/src/main/res/layout/nav_header_main.xml b/app/src/main/res/layout/nav_header_main.xml index 02d57f6..bc1df14 100644 --- a/app/src/main/res/layout/nav_header_main.xml +++ b/app/src/main/res/layout/nav_header_main.xml @@ -14,7 +14,7 @@