This commit is contained in:
Sagi Dayan 2016-07-10 17:50:26 +03:00
parent 2ca32ca356
commit aae20aa1cc
4 changed files with 716 additions and 750 deletions

View file

@ -1,22 +1,11 @@
package com.android_app.matan.ara.sagi.thesocialnotework; package com.android_app.matan.ara.sagi.thesocialnotework;
import android.*;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode; import android.os.StrictMode;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
@ -29,54 +18,42 @@ import android.view.MenuItem;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast; import android.widget.Toast;
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;
import org.json.JSONObject;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class MainActivity extends AppCompatActivity public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener { implements NavigationView.OnNavigationItemSelectedListener {
public static final String LOCAL_DATA_TSN = "TSN_DATA_STORE"; public static final String LOCAL_DATA_TSN = "TSN_DATA_STORE";
protected final String TAG = "[TSN / MainActivity]"; protected final String TAG = "[TSN / MainActivity]";
protected User user; protected User user;
private GPSUtils gpsUtils; private GPSUtils gpsUtils;
private boolean locationPermission;
private GmapFragment gmapFragment; private GmapFragment gmapFragment;
private PersonalFragment personalFragment; private PersonalFragment personalFragment;
private SettingsFragment settingsFragment; private SettingsFragment settingsFragment;
private ExploreFragment exploreFragment; private ExploreFragment exploreFragment;
private Toolbar toolbar; private Toolbar toolbar;
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
private ImageView menu_avatar; private ImageView menu_avatar;
private MainActivity self; private MainActivity self;
private NavigationView nav_view; private NavigationView nav_view;
private final int FINE_PERM = 0, CAMERA_PERM = 1; private final int FINE_PERM = 0;
/**
* On Activity Start
* @param savedInstanceState
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
this.self = this; this.self = this;
toolbar = (Toolbar) findViewById(R.id.toolbar); this.toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Personal Notes"); this.toolbar.setTitle("Personal Notes");
setSupportActionBar(toolbar); this.setSupportActionBar(toolbar);
gmapFragment = new GmapFragment(); this.gmapFragment = new GmapFragment();
personalFragment = new PersonalFragment(); this.personalFragment = new PersonalFragment();
settingsFragment = new SettingsFragment(); this.settingsFragment = new SettingsFragment();
exploreFragment = new ExploreFragment(); this.exploreFragment = new ExploreFragment();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); StrictMode.setThreadPolicy(policy);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
@ -99,7 +76,6 @@ public class MainActivity extends AppCompatActivity
//Change Layout //Change Layout
Log.d(TAG, "Changing Fragment to Personal Activity"); Log.d(TAG, "Changing Fragment to Personal Activity");
// PersonalFragment personalFragment = new PersonalFragment();
personalFragment.setArguments(b); personalFragment.setArguments(b);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_container, personalFragment); ft.replace(R.id.fragment_container, personalFragment);
@ -129,15 +105,18 @@ public class MainActivity extends AppCompatActivity
return true; return true;
} }
/**
* Handle action bar item clicks here. The action bar will
* automatically handle clicks on the Home/Up button, so long
* as you specify a parent activity in AndroidManifest.xml.
* @param item - Action bar item (Menu)
* @return
*/
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); int id = item.getItemId();
Log.d(TAG, "onOptionsItemSelected: id -> "+id); Log.d(TAG, "onOptionsItemSelected: id -> "+id);
//noinspection SimplifiableIfStatement // Settings
if (id == R.id.action_settings) { if (id == R.id.action_settings) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
toolbar.setTitle("Settings"); toolbar.setTitle("Settings");
@ -146,17 +125,19 @@ public class MainActivity extends AppCompatActivity
ft.commit(); ft.commit();
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
/**
* This function will be called when an item is selected from the nav bar.
* @param item
* @return
*/
@SuppressWarnings("StatementWithEmptyBody") @SuppressWarnings("StatementWithEmptyBody")
@Override @Override
public boolean onNavigationItemSelected(MenuItem item) { public boolean onNavigationItemSelected(MenuItem item) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
int id = item.getItemId(); int id = item.getItemId();
if (id == R.id.nav_explore) { if (id == R.id.nav_explore) {
toolbar.setTitle("Explore"); toolbar.setTitle("Explore");
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -193,16 +174,17 @@ public class MainActivity extends AppCompatActivity
finish(); finish();
} }
// Close the drawer
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START); drawer.closeDrawer(GravityCompat.START);
return true; return true;
} }
public GPSUtils getGPSUtils() { public GPSUtils getGPSUtils() {
return this.gpsUtils; return this.gpsUtils;
} }
public User getUser() { public User getUser() {
return user; return user;
} }
@ -211,6 +193,12 @@ public class MainActivity extends AppCompatActivity
return user.getId(); return user.getId();
} }
/**
* Permittion handlers
* @param requestCode
* @param permissions
* @param grantResults
*/
@Override @Override
public void onRequestPermissionsResult(int requestCode, public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) { String permissions[], int[] grantResults) {
@ -248,6 +236,9 @@ public class MainActivity extends AppCompatActivity
} }
/**
* Update the Navbar avatar
*/
public void updateNavAvatar() { public void updateNavAvatar() {
//Change The Avatar //Change The Avatar
Utils.URLtoImageView(menu_avatar, user.getAvatar()); Utils.URLtoImageView(menu_avatar, user.getAvatar());

View file

@ -1,10 +1,10 @@
package com.android_app.matan.ara.sagi.thesocialnotework; package com.android_app.matan.ara.sagi.thesocialnotework;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.MarkerOptions;
/** /**
* Created by JERLocal on 7/8/2016. * Created by JERLocal on 7/8/2016.
* This class will hold information about a Mark on the Map.
*/ */
public class MarkerNoteStruct { public class MarkerNoteStruct {
private Note note; private Note note;

View file

@ -10,211 +10,220 @@ import java.util.Date;
/** /**
* Created by JERLocal on 7/1/2016. * Created by JERLocal on 7/1/2016.
* A Note Class - Represents a note Object
*/ */
public class Note implements Parcelable { public class Note implements Parcelable {
protected int likes; protected int likes;
protected ArrayList<String> tags; protected ArrayList<String> tags;
protected float lat, lon; protected float lat, lon;
protected String id, address, title, body, timestamp, avatar, ownerId; protected String id, address, title, body, timestamp, avatar, ownerId;
protected boolean isPublic; protected boolean isPublic;
public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic, int likes, String avatar, String ownerId, ArrayList<String> tags) { public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic, int likes, String avatar, String ownerId, ArrayList<String> tags) {
this.id = id; this.id = id;
this.lat = lat; this.lat = lat;
this.lon = lon; this.lon = lon;
this.address = address; this.address = address;
this.title = title;
this.title = title; this.body = body;
this.body = body; this.timestamp = timestamp;
this.timestamp = timestamp; this.isPublic = isPublic;
this.isPublic = isPublic; this.likes = likes;
this.likes = likes; this.tags = tags;
this.tags = tags; this.avatar = avatar;
this.avatar = avatar; this.ownerId = ownerId;
this.ownerId = ownerId; }
}
protected Note(Parcel in) { protected Note(Parcel in) {
likes = in.readInt(); likes = in.readInt();
tags = in.createStringArrayList(); tags = in.createStringArrayList();
lat = in.readFloat(); lat = in.readFloat();
lon = in.readFloat(); lon = in.readFloat();
id = in.readString();
id = in.readString(); address = in.readString();
address = in.readString(); title = in.readString();
title = in.readString(); body = in.readString();
body = in.readString(); timestamp = in.readString();
timestamp = in.readString(); avatar = in.readString();
avatar = in.readString(); ownerId = in.readString();
ownerId = in.readString(); isPublic = in.readByte() != 0;
isPublic = in.readByte() != 0; }
}
public static final Creator<Note> CREATOR = new Creator<Note>() {
@Override
public Note createFromParcel(Parcel in) {
return new Note(in);
}
@Override
public Note[] newArray(int size) {
return new Note[size];
}
};
public static final Creator<Note> CREATOR = new Creator<Note>() {
@Override @Override
public String toString() { public Note createFromParcel(Parcel in) {
return "Note{" + return new Note(in);
"id=" + id +
", lat=" + lat +
", lon=" + lon +
", address='" + address + '\'' +
", title='" + title + '\'' +
", body='" + body + '\'' +
", timestamp=" + timestamp +
", isPublic=" + isPublic +
", avatar=" + avatar +
", ownerId=" + ownerId +
'}';
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public float getLat() {
return lat;
}
public void setLat(float lat) {
this.lat = lat;
}
public float getLon() {
return lon;
}
public void setLon(float lon) {
this.lon = lon;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public boolean isPublic() {
return isPublic;
}
public void setPublic(boolean aPublic) {
isPublic = aPublic;
}
public String getLocationAndTime() {
return getTimestamp() + " at " + getAddress();
}
public int getLikes() {
return likes;
}
public void setLikes(int likes) {
this.likes = likes;
}
public ArrayList<String> getTags() {
return tags;
}
public void setTags(ArrayList<String> tags) {
this.tags = tags;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getOwnerId() {
return ownerId;
}
public void setOwnerId(String ownerId) {
this.ownerId = ownerId;
}
@Override
public int describeContents() {
return 0;
} }
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public Note[] newArray(int size) {
dest.writeInt(likes); return new Note[size];
dest.writeList(tags);
dest.writeFloat(lat);
dest.writeFloat(lon);
dest.writeString(id);
dest.writeString(address);
dest.writeString(title);
dest.writeString(body);
dest.writeString(timestamp);
dest.writeString(avatar);
dest.writeString(ownerId);
dest.writeByte((byte) (isPublic ? 1 : 0));
} }
};
public String getTime() {
Date d = new Date(timestamp);
DateFormat format = new SimpleDateFormat("HH:mm");
return format.format(d);
}
public String getDate() { @Override
Date d = new Date(timestamp); public String toString() {
DateFormat format = new SimpleDateFormat("dd MMM yyy"); return "Note{" +
return format.format(d); "id=" + id +
} ", lat=" + lat +
", lon=" + lon +
", address='" + address + '\'' +
", title='" + title + '\'' +
", body='" + body + '\'' +
", timestamp=" + timestamp +
", isPublic=" + isPublic +
", avatar=" + avatar +
", ownerId=" + ownerId +
'}';
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public float getLat() {
return lat;
}
public void setLat(float lat) {
this.lat = lat;
}
public float getLon() {
return lon;
}
public void setLon(float lon) {
this.lon = lon;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public boolean isPublic() {
return isPublic;
}
public void setPublic(boolean aPublic) {
isPublic = aPublic;
}
public String getLocationAndTime() {
return getTimestamp() + " at " + getAddress();
}
public int getLikes() {
return likes;
}
public void setLikes(int likes) {
this.likes = likes;
}
public ArrayList<String> getTags() {
return tags;
}
public void setTags(ArrayList<String> tags) {
this.tags = tags;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getOwnerId() {
return ownerId;
}
public void setOwnerId(String ownerId) {
this.ownerId = ownerId;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(likes);
dest.writeList(tags);
dest.writeFloat(lat);
dest.writeFloat(lon);
dest.writeString(id);
dest.writeString(address);
dest.writeString(title);
dest.writeString(body);
dest.writeString(timestamp);
dest.writeString(avatar);
dest.writeString(ownerId);
dest.writeByte((byte) (isPublic ? 1 : 0));
}
/**
* Get a Simplified Readable Time (Creation of the note)
*
* @return String
*/
public String getTime() {
Date d = new Date(timestamp);
DateFormat format = new SimpleDateFormat("HH:mm");
return format.format(d);
}
/**
* Get a Simplified Readable Date (Creation of the note)
*
* @return String
*/
public String getDate() {
Date d = new Date(timestamp);
DateFormat format = new SimpleDateFormat("dd MMM yyy");
return format.format(d);
}
} }