added delete option to note display
This commit is contained in:
parent
e6af9bce68
commit
4dae63bb75
2 changed files with 100 additions and 60 deletions
|
@ -1,7 +1,9 @@
|
|||
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
@ -14,6 +16,7 @@ import android.widget.AdapterView;
|
|||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
@ -84,35 +87,35 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
|||
new HeavyWorker(this).execute();
|
||||
// getAllNotes();
|
||||
|
||||
//https://thesocialnotework-api.appspot.com/api/note/all?uid=<USER_ID>
|
||||
addBtn.setOnClickListener(addNewNoteDialog);
|
||||
|
||||
// click on listView item
|
||||
noteList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||
//create and configure dialog
|
||||
Note note = listOfNotes.get(position);
|
||||
final Dialog dialog = new Dialog(PersonalSpaceActivity.this);
|
||||
dialog.setContentView(R.layout.note_display_full);
|
||||
dialog.setTitle("You wrote...");
|
||||
final Note note = listOfNotes.get(position);
|
||||
final Dialog noteViewDialog = new Dialog(PersonalSpaceActivity.this);
|
||||
noteViewDialog.setContentView(R.layout.note_display_full);
|
||||
noteViewDialog.setTitle("You wrote...");
|
||||
|
||||
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
||||
lp.copyFrom(dialog.getWindow().getAttributes());
|
||||
lp.copyFrom(noteViewDialog.getWindow().getAttributes());
|
||||
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
dialog.show();
|
||||
noteViewDialog.show();
|
||||
// dialog.getWindow().setAttributes(lp);
|
||||
|
||||
|
||||
//get note_view_full layout elements
|
||||
final TextView title = (TextView) dialog.findViewById(R.id.ndf_title_textview);
|
||||
final TextView body = (TextView) dialog.findViewById(R.id.ndf_body_textview);
|
||||
final TextView time = (TextView) dialog.findViewById(R.id.ndf_time_textview);
|
||||
final TextView location = (TextView) dialog.findViewById(R.id.ndf_address_textview);
|
||||
final TextView likes = (TextView) dialog.findViewById(R.id.ndf_likes_textview);
|
||||
final TextView tags = (TextView) dialog.findViewById(R.id.ndf_tags_textview);
|
||||
final TextView permission = (TextView) dialog.findViewById(R.id.ndf_permission_textview);
|
||||
final TextView title = (TextView) noteViewDialog.findViewById(R.id.ndf_title_textview);
|
||||
final TextView body = (TextView) noteViewDialog.findViewById(R.id.ndf_body_textview);
|
||||
final TextView time = (TextView) noteViewDialog.findViewById(R.id.ndf_time_textview);
|
||||
final TextView location = (TextView) noteViewDialog.findViewById(R.id.ndf_address_textview);
|
||||
final TextView likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview);
|
||||
final TextView tags = (TextView) noteViewDialog.findViewById(R.id.ndf_tags_textview);
|
||||
final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview);
|
||||
final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton);
|
||||
|
||||
|
||||
title.setText(note.getTitle());
|
||||
|
@ -123,10 +126,51 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
|||
tags.setText(note.getTags().toString());
|
||||
permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private"));
|
||||
|
||||
}
|
||||
deleteBtn.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
//Put up the Yes/No message box
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(PersonalSpaceActivity.this);
|
||||
builder
|
||||
.setTitle("Delete Note")
|
||||
.setMessage("Are you sure you want to delete the note?")
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
//Yes button clicked, do something
|
||||
Toast.makeText(PersonalSpaceActivity.this, "Item Deleted!",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
//TODO send delete
|
||||
JSONObject delNote = new JSONObject();
|
||||
try {
|
||||
delNote.put("uid", userId);
|
||||
delNote.put("nid", note.getId());
|
||||
VolleyUtilSingleton.getInstance(PersonalSpaceActivity.this).post(BASE_URL + "/note/delete",delNote, deleteNoteSuccessListener, genericErrorListener);
|
||||
listOfNotes.remove(position);
|
||||
|
||||
} catch (JSONException e) {
|
||||
Toast.makeText(PersonalSpaceActivity.this, "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
noteList.setAdapter(noteListAdapter);
|
||||
// dialog.dismiss();
|
||||
noteViewDialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
//Yes button clicked, do something
|
||||
Toast.makeText(PersonalSpaceActivity.this, "Note still here!",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
// dialog.dismiss();
|
||||
noteViewDialog.dismiss();
|
||||
}
|
||||
}) //Do nothing on no
|
||||
.show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
@ -170,16 +214,14 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
|||
public void onClick(View v) {
|
||||
|
||||
//title too short
|
||||
if (newTitle.getText().length() == 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
@ -225,7 +267,6 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
|||
};
|
||||
|
||||
|
||||
|
||||
public void setLocationPermission(boolean locationPermission) {
|
||||
this.locationPermission = locationPermission;
|
||||
}
|
||||
|
@ -288,28 +329,23 @@ public class PersonalSpaceActivity extends AppCompatActivity {
|
|||
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"),
|
||||
// noteObject.getInt("likes"),
|
||||
// jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
||||
// );
|
||||
// listOfNotes.add(addNote);
|
||||
}
|
||||
noteList.setAdapter(noteListAdapter);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
//response listener for getting all user notes
|
||||
Response.Listener<JSONObject> deleteNoteSuccessListener = new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Log.d(TAG, "deleteNoteSuccessListener: " + response.toString());
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
//response ErrorListener for getting all user notes
|
||||
Response.ErrorListener getNotesErrorListener = new Response.ErrorListener() {
|
||||
|
@ -379,16 +415,13 @@ 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++)
|
||||
{
|
||||
for (int i = 0, count = jArray.length(); i < count; i++) {
|
||||
try {
|
||||
JSONObject jsonObject = jArray.getJSONObject(i);
|
||||
stringArray.add(jsonObject.toString());
|
||||
}
|
||||
catch (JSONException e) {
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,13 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="New Text" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ndf_delete_imagebutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:background="@android:drawable/ic_menu_delete" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
Loading…
Reference in a new issue