added limitation in adding note

This commit is contained in:
Aran Zaiger 2016-07-03 14:32:08 +03:00
parent 8c711b6cf5
commit 52f7808a70
5 changed files with 184 additions and 61 deletions

View file

@ -5,7 +5,7 @@
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<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">
<set>
<option value="$PROJECT_DIR$" />

View file

@ -59,12 +59,18 @@ public class ListAdapter extends BaseAdapter {
TextView title = (TextView) v.findViewById(R.id.nvm_title_textview);
TextView datetime = (TextView) v.findViewById(R.id.nvm_time_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);
// String url = mVideos.get(position).getImgURL();
// thumbNail.setImageUrl(url, VolleyUtilSingleTone.getInstance(mContext).getImageLoader());
title.setText(mNotes.get(position).getTitle());
datetime.setText(Html.fromHtml(mNotes.get(position).getTimestamp()));
location.setText(mNotes.get(position).getAddress());
Note curNote = mNotes.get(position);
title.setText(curNote.getTitle());
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);
// v.startAnimation(animation);
lastPosition = position;

View file

@ -1,25 +1,32 @@
package com.android_app.matan.ara.sagi.thesocialnotework;
import java.util.ArrayList;
/**
* Created by JERLocal on 7/1/2016.
*/
public class Note {
// protected int id;
protected int likes;
protected ArrayList<String> tags;
protected float lat, lon;
protected String id, address, title, body;
protected String timestamp;
protected String id, address, title, body, timestamp;
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.lat = lat;
this.lon = lon;
this.address = address;
this.title = title;
this.body = body;
this.timestamp = timestamp;
this.isPublic = isPublic;
this.likes = likes;
this.tags = tags;
}
@Override
@ -103,6 +110,21 @@ public class Note {
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 void save(SQLiteOpenHelper dbHelper, Context context){
// SQLiteDatabase db = dbHelper.getWritableDatabase();

View file

@ -15,6 +15,7 @@ import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.Response;
@ -29,6 +30,7 @@ import org.json.JSONObject;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -72,8 +74,8 @@ public class PersonalSpaceActivity extends AppCompatActivity {
listOfNotes = new ArrayList<>();
//add demo notes to view
addDemoNotes(listOfNotes);
//TODO - remove -add demo notes to view
// addDemoNotes(listOfNotes);
noteListAdapter = new ListAdapter(this, listOfNotes);
noteList.setAdapter(noteListAdapter);
@ -123,6 +125,22 @@ public class PersonalSpaceActivity extends AppCompatActivity {
saveBtn.setOnClickListener(new View.OnClickListener() {
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
final JSONObject noteJson = new JSONObject();
try {
@ -165,17 +183,17 @@ public class PersonalSpaceActivity extends AppCompatActivity {
//TODO remove
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 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 n4 = new Note("4", 400, 400, "hell2", "My 4st Title", "ohh i'm so sexy4", ""+System.currentTimeMillis() / 1000, true);
listOfNotes.add(n1);
listOfNotes.add(n2);
listOfNotes.add(n3);
// listOfNotes.add(n4);
}
// //TODO remove
// 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 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 n4 = new Note("4", 400, 400, "hell2", "My 4st Title", "ohh i'm so sexy4", ""+System.currentTimeMillis() / 1000, true);
// listOfNotes.add(n1);
// listOfNotes.add(n2);
// listOfNotes.add(n3);
//// listOfNotes.add(n4);
// }
public void setLocationPermission(boolean locationPermission) {
@ -192,19 +210,22 @@ public class PersonalSpaceActivity extends AppCompatActivity {
Date time = new Date();
JSONObject noteObject = response.getJSONObject("note");
time.setTime(noteObject.getLong("created_at"));
addNoteFromJsonObj(noteObject, time);
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")
);
listOfNotes.add(addNote);
// 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);
noteList.setAdapter(noteListAdapter);
} catch (Exception e) {
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
@ -236,17 +257,20 @@ public class PersonalSpaceActivity extends AppCompatActivity {
JSONObject noteObject = noteObjectsArray.getJSONObject(i);
time.setTime(noteObject.getLong("created_at"));
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")
);
listOfNotes.add(addNote);
addNoteFromJsonObj(noteObject, time);
// 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);
}
noteList.setAdapter(noteListAdapter);
} 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);
}
}

View file

@ -1,27 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Note Title"
android:id="@+id/nvm_title_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"
/>
<TextView
android:layout_width="fill_parent"
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date and time"
android:id="@+id/nvm_time_textview" />
android:layout_weight="0.6">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="location"
android:id="@+id/nvm_location_textview" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Note Title"
android:id="@+id/nvm_title_textview" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date and time"
android:id="@+id/nvm_time_textview" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="location"
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>