added limitation in adding note
This commit is contained in:
parent
8c711b6cf5
commit
52f7808a70
5 changed files with 184 additions and 61 deletions
|
@ -5,7 +5,7 @@
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="distributionType" value="LOCAL" />
|
<option name="distributionType" value="LOCAL" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.10" />
|
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.10" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
|
|
@ -59,12 +59,18 @@ public class ListAdapter extends BaseAdapter {
|
||||||
TextView title = (TextView) v.findViewById(R.id.nvm_title_textview);
|
TextView title = (TextView) v.findViewById(R.id.nvm_title_textview);
|
||||||
TextView datetime = (TextView) v.findViewById(R.id.nvm_time_textview);
|
TextView datetime = (TextView) v.findViewById(R.id.nvm_time_textview);
|
||||||
TextView location = (TextView) v.findViewById(R.id.nvm_location_textview);
|
TextView location = (TextView) v.findViewById(R.id.nvm_location_textview);
|
||||||
|
TextView likes = (TextView) v.findViewById(R.id.nvm_likes_textview);
|
||||||
|
TextView permission = (TextView) v.findViewById(R.id.nvm_permission_textview);
|
||||||
// NetworkImageView thumbNail = (NetworkImageView) v.findViewById(R.id.infoImageImageView);
|
// NetworkImageView thumbNail = (NetworkImageView) v.findViewById(R.id.infoImageImageView);
|
||||||
// String url = mVideos.get(position).getImgURL();
|
// String url = mVideos.get(position).getImgURL();
|
||||||
// thumbNail.setImageUrl(url, VolleyUtilSingleTone.getInstance(mContext).getImageLoader());
|
// thumbNail.setImageUrl(url, VolleyUtilSingleTone.getInstance(mContext).getImageLoader());
|
||||||
title.setText(mNotes.get(position).getTitle());
|
Note curNote = mNotes.get(position);
|
||||||
datetime.setText(Html.fromHtml(mNotes.get(position).getTimestamp()));
|
title.setText(curNote.getTitle());
|
||||||
location.setText(mNotes.get(position).getAddress());
|
datetime.setText(Html.fromHtml(curNote.getTimestamp()));
|
||||||
|
location.setText(curNote.getAddress());
|
||||||
|
likes.setText(""+curNote.getLikes());
|
||||||
|
permission.setText(curNote.isPublic() ? "Public":"Private");
|
||||||
|
|
||||||
// Animation animation = AnimationUtils.loadAnimation(mContext, (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
|
// Animation animation = AnimationUtils.loadAnimation(mContext, (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
|
||||||
// v.startAnimation(animation);
|
// v.startAnimation(animation);
|
||||||
lastPosition = position;
|
lastPosition = position;
|
||||||
|
|
|
@ -1,25 +1,32 @@
|
||||||
package com.android_app.matan.ara.sagi.thesocialnotework;
|
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JERLocal on 7/1/2016.
|
* Created by JERLocal on 7/1/2016.
|
||||||
*/
|
*/
|
||||||
public class Note {
|
public class Note {
|
||||||
|
|
||||||
// protected int id;
|
protected int likes;
|
||||||
|
protected ArrayList<String> tags;
|
||||||
protected float lat, lon;
|
protected float lat, lon;
|
||||||
protected String id, address, title, body;
|
protected String id, address, title, body, timestamp;
|
||||||
protected String timestamp;
|
|
||||||
protected boolean isPublic;
|
protected boolean isPublic;
|
||||||
|
|
||||||
public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic) {
|
|
||||||
|
|
||||||
|
public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic, int likes, 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.tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,6 +110,21 @@ public class Note {
|
||||||
public String getLocationAndTime() {
|
public String getLocationAndTime() {
|
||||||
return getTimestamp()+" at "+ getAddress();
|
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 void save(SQLiteOpenHelper dbHelper, Context context){
|
// public void save(SQLiteOpenHelper dbHelper, Context context){
|
||||||
// SQLiteDatabase db = dbHelper.getWritableDatabase();
|
// SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||||
|
|
|
@ -15,6 +15,7 @@ import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
import com.android.volley.Response;
|
||||||
|
@ -29,6 +30,7 @@ import org.json.JSONObject;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -72,8 +74,8 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
listOfNotes = new ArrayList<>();
|
listOfNotes = new ArrayList<>();
|
||||||
//add demo notes to view
|
//TODO - remove -add demo notes to view
|
||||||
addDemoNotes(listOfNotes);
|
// addDemoNotes(listOfNotes);
|
||||||
noteListAdapter = new ListAdapter(this, listOfNotes);
|
noteListAdapter = new ListAdapter(this, listOfNotes);
|
||||||
|
|
||||||
noteList.setAdapter(noteListAdapter);
|
noteList.setAdapter(noteListAdapter);
|
||||||
|
@ -123,6 +125,22 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
||||||
|
|
||||||
saveBtn.setOnClickListener(new View.OnClickListener() {
|
saveBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
//title too short
|
||||||
|
if (newTitle.getText().length() == 0)
|
||||||
|
{
|
||||||
|
Toast toast = Toast.makeText(PersonalSpaceActivity.this, "Title too short.", Toast.LENGTH_LONG);
|
||||||
|
toast.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//title too long
|
||||||
|
if (newTitle.getText().length() > 20)
|
||||||
|
{
|
||||||
|
Toast toast = Toast.makeText(PersonalSpaceActivity.this, "Title too long.\n Use up to 20 notes.", Toast.LENGTH_LONG);
|
||||||
|
toast.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
//volley post
|
//volley post
|
||||||
final JSONObject noteJson = new JSONObject();
|
final JSONObject noteJson = new JSONObject();
|
||||||
try {
|
try {
|
||||||
|
@ -165,17 +183,17 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//TODO remove
|
// //TODO remove
|
||||||
public void addDemoNotes(List<Note> listOfNotes) {
|
// public void addDemoNotes(List<Note> listOfNotes) {
|
||||||
Note n1 = new Note("1", 100, 100, "location1", "My 1st Title", "ohh i'm so sexy1", ""+System.currentTimeMillis() / 1000, true);
|
// Note n1 = new Note("1", 100, 100, "location1", "My 1st Title", "ohh i'm so sexy1", ""+System.currentTimeMillis() / 1000, true);
|
||||||
Note n2 = new Note("2", 200, 200, "location2", "My 2st Title", "ohh i'm so sexy2", ""+System.currentTimeMillis() / 1000, true);
|
// Note n2 = new Note("2", 200, 200, "location2", "My 2st Title", "ohh i'm so sexy2", ""+System.currentTimeMillis() / 1000, true);
|
||||||
Note n3 = new Note("3", 300, 300, "hell", "My 3st Title", "ohh i'm so sexy3", ""+System.currentTimeMillis() / 1000, true);
|
// Note n3 = new Note("3", 300, 300, "hell", "My 3st Title", "ohh i'm so sexy3", ""+System.currentTimeMillis() / 1000, true);
|
||||||
// Note n4 = new Note("4", 400, 400, "hell2", "My 4st Title", "ohh i'm so sexy4", ""+System.currentTimeMillis() / 1000, true);
|
//// Note n4 = new Note("4", 400, 400, "hell2", "My 4st Title", "ohh i'm so sexy4", ""+System.currentTimeMillis() / 1000, true);
|
||||||
listOfNotes.add(n1);
|
// listOfNotes.add(n1);
|
||||||
listOfNotes.add(n2);
|
// listOfNotes.add(n2);
|
||||||
listOfNotes.add(n3);
|
// listOfNotes.add(n3);
|
||||||
// listOfNotes.add(n4);
|
//// listOfNotes.add(n4);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public void setLocationPermission(boolean locationPermission) {
|
public void setLocationPermission(boolean locationPermission) {
|
||||||
|
@ -192,19 +210,22 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
||||||
Date time = new Date();
|
Date time = new Date();
|
||||||
JSONObject noteObject = response.getJSONObject("note");
|
JSONObject noteObject = response.getJSONObject("note");
|
||||||
time.setTime(noteObject.getLong("created_at"));
|
time.setTime(noteObject.getLong("created_at"));
|
||||||
|
addNoteFromJsonObj(noteObject, time);
|
||||||
|
|
||||||
Note addNote = new Note(
|
// Note addNote = new Note(
|
||||||
noteObject.getString("id"),
|
// noteObject.getString("id"),
|
||||||
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
// Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
||||||
Float.parseFloat(noteObject.getJSONObject("location").getString("lng")),
|
// Float.parseFloat(noteObject.getJSONObject("location").getString("lng")),
|
||||||
noteObject.getJSONObject("location").getString("address"),
|
// noteObject.getJSONObject("location").getString("address"),
|
||||||
noteObject.getString("title"),
|
// noteObject.getString("title"),
|
||||||
noteObject.getString("body"),
|
// noteObject.getString("body"),
|
||||||
time.toString(),
|
// time.toString(),
|
||||||
noteObject.getBoolean("is_public")
|
// noteObject.getBoolean("is_public"),
|
||||||
);
|
// noteObject.getInt("likes"),
|
||||||
|
// jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
||||||
listOfNotes.add(addNote);
|
// );
|
||||||
|
//
|
||||||
|
// listOfNotes.add(addNote);
|
||||||
noteList.setAdapter(noteListAdapter);
|
noteList.setAdapter(noteListAdapter);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
|
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
|
||||||
|
@ -236,17 +257,20 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
||||||
JSONObject noteObject = noteObjectsArray.getJSONObject(i);
|
JSONObject noteObject = noteObjectsArray.getJSONObject(i);
|
||||||
time.setTime(noteObject.getLong("created_at"));
|
time.setTime(noteObject.getLong("created_at"));
|
||||||
|
|
||||||
Note addNote = new Note(
|
addNoteFromJsonObj(noteObject, time);
|
||||||
noteObject.getString("id"),
|
// Note addNote = new Note(
|
||||||
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
// noteObject.getString("id"),
|
||||||
Float.parseFloat(noteObject.getJSONObject("location").getString("lng")),
|
// Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
||||||
noteObject.getJSONObject("location").getString("address"),
|
// Float.parseFloat(noteObject.getJSONObject("location").getString("lng")),
|
||||||
noteObject.getString("title"),
|
// noteObject.getJSONObject("location").getString("address"),
|
||||||
noteObject.getString("body"),
|
// noteObject.getString("title"),
|
||||||
time.toString(),
|
// noteObject.getString("body"),
|
||||||
noteObject.getBoolean("is_public")
|
// time.toString(),
|
||||||
);
|
// noteObject.getBoolean("is_public"),
|
||||||
listOfNotes.add(addNote);
|
// noteObject.getInt("likes"),
|
||||||
|
// jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
||||||
|
// );
|
||||||
|
// listOfNotes.add(addNote);
|
||||||
}
|
}
|
||||||
noteList.setAdapter(noteListAdapter);
|
noteList.setAdapter(noteListAdapter);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -326,4 +350,35 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private ArrayList<String> jsonArrayToStringArray(JSONArray jArray){
|
||||||
|
ArrayList<String> stringArray = new ArrayList<String>();
|
||||||
|
for(int i = 0, count = jArray.length(); i< count; i++)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
JSONObject jsonObject = jArray.getJSONObject(i);
|
||||||
|
stringArray.add(jsonObject.toString());
|
||||||
|
}
|
||||||
|
catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stringArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException {
|
||||||
|
Note addNote = new Note(
|
||||||
|
noteObject.getString("id"),
|
||||||
|
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
||||||
|
Float.parseFloat(noteObject.getJSONObject("location").getString("lng")),
|
||||||
|
noteObject.getJSONObject("location").getString("address"),
|
||||||
|
noteObject.getString("title"),
|
||||||
|
noteObject.getString("body"),
|
||||||
|
time.toString(),
|
||||||
|
noteObject.getBoolean("is_public"),
|
||||||
|
noteObject.getInt("likes"),
|
||||||
|
jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
||||||
|
);
|
||||||
|
listOfNotes.add(addNote);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,22 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical" android:layout_width="match_parent"
|
android:orientation="horizontal" android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="70dp"
|
||||||
|
android:id="@+id/nvm_permission_textview"
|
||||||
|
android:background="@android:drawable/ic_lock_lock"
|
||||||
|
android:layout_weight="0.2"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0.6">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -23,5 +37,31 @@
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:text="location"
|
android:text="location"
|
||||||
android:id="@+id/nvm_location_textview" />
|
android:id="@+id/nvm_location_textview" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="0.2">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Tags #1"
|
||||||
|
android:id="@+id/nvm_tags1_textview" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Tags #2"
|
||||||
|
android:id="@+id/nvm_tags2_textview" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Likes"
|
||||||
|
android:id="@+id/nvm_likes_textview" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Reference in a new issue