This commit is contained in:
Sagi Dayan 2016-07-09 19:14:07 +03:00
parent 9651eba02c
commit 01aaf28247
8 changed files with 175 additions and 50 deletions

View file

@ -0,0 +1,99 @@
package com.android_app.matan.ara.sagi.thesocialnotework;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.android.volley.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
/**
* A simple {@link Fragment} subclass.
*/
public class ExploreFragment extends Fragment {
private static final String TAG = "[TSN/Explore]";
protected User user;
protected MainActivity parent;
private ListAdapter noteListAdapter;
private List<Note> notes;
protected ListView list_notes;
public ExploreFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_explore, container, false);
parent = (MainActivity)getActivity();
user = parent.getUser();
notes = new ArrayList<>();
//Get Views
list_notes = (ListView)view.findViewById(R.id.list_notes);
noteListAdapter = new ListAdapter(parent, notes);
try {
getAllNotes();
} catch (JSONException e) {
e.printStackTrace();
}
return view;
}
public void getAllNotes() throws JSONException {
Log.d(TAG, "url: " + Utils.BASE_URL + "/note/getPublic");
String url = Utils.BASE_URL + "/note/getPublic";
JSONObject payload = new JSONObject();
payload.put("id", user.getId());
VolleyUtilSingleton.getInstance(getActivity()).post(url, payload ,getNotesSuccessListener,Utils.genericErrorListener);
}
Response.Listener<JSONObject> getNotesSuccessListener = new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "getNotesSuccessListener: " + response.toString());
Utils.dismissLoadingDialog();
try {
//need to get all notes and add to listOfNotes
JSONArray noteObjectsArray = response.getJSONArray("notes");
parent.getUser().setNumber_of_notes(noteObjectsArray.length());
Date time = new Date();
for (int i = 0; i < noteObjectsArray.length(); i++) {
JSONObject noteObject = noteObjectsArray.getJSONObject(i);
time.setTime(noteObject.getLong("created_at"));
notes.add(Utils.getNoteFromJsonObj(noteObject, time));
}
list_notes.setAdapter(noteListAdapter);
} catch (Exception e) {
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
}
}
};
}

View file

@ -9,6 +9,7 @@ import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
//import com.android.volley.toolbox.NetworkImageView;
@ -62,7 +63,7 @@ public class ListAdapter extends BaseAdapter {
TextView date = (TextView) v.findViewById(R.id.nvm_date_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);
ImageView permission = (ImageView) v.findViewById(R.id.nvm_permission_image_view);
// NetworkImageView thumbNail = (NetworkImageView) v.findViewById(R.id.infoImageImageView);
// String url = mVideos.get(position).getImgURL();
// thumbNail.setImageUrl(url, VolleyUtilSingleTone.getInstance(mContext).getImageLoader());
@ -73,7 +74,11 @@ public class ListAdapter extends BaseAdapter {
location.setText(curNote.getAddress());
if(likes !=null )likes.setText(""+curNote.getLikes());
// permission.setText(curNote.isPublic() ? "Public":"Private");
permission.setBackground(curNote.isPublic() ? v.getResources().getDrawable(R.drawable.public_icon): v.getResources().getDrawable(R.drawable.private_icon));
if(((MainActivity)mContext).getUser().getId().equals(curNote.ownerId)){// MY Note
permission.setBackground(curNote.isPublic() ? v.getResources().getDrawable(R.drawable.public_icon): v.getResources().getDrawable(R.drawable.private_icon));
}else{
Utils.URLtoImageView(permission, curNote.getAvatar());
}
Animation animation = AnimationUtils.loadAnimation(mContext, (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
v.startAnimation(animation);

View file

@ -52,6 +52,7 @@ public class MainActivity extends AppCompatActivity
private GmapFragment gmapFragment;
private PersonalFragment personalFragment;
private SettingsFragment settingsFragment;
private ExploreFragment exploreFragment;
private Toolbar toolbar;
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
private ImageView menu_avatar;
@ -71,6 +72,7 @@ public class MainActivity extends AppCompatActivity
gmapFragment = new GmapFragment();
personalFragment = new PersonalFragment();
settingsFragment = new SettingsFragment();
exploreFragment = new ExploreFragment();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
@ -153,6 +155,9 @@ public class MainActivity extends AppCompatActivity
if (id == R.id.nav_explore) {
toolbar.setTitle("Explore");
setSupportActionBar(toolbar);
Log.d(TAG, "Before going to Explore");
ft.replace(R.id.fragment_container, exploreFragment);
ft.commit();
} else if (id == R.id.nav_map) {
Log.d(TAG, "Before going to map");

View file

@ -114,7 +114,7 @@ public class PersonalFragment extends Fragment {
gpsUtils = activity.getGPSUtils();
gpsUtils.getLocation();
listOfNotes = new ArrayList<>();
noteListAdapter = new ListAdapter(getContext(), listOfNotes);
noteListAdapter = new ListAdapter(activity, listOfNotes);
noteList.setAdapter(noteListAdapter);
noteList.setOnItemClickListener(new ItemClickedListener());
Utils.showLoadingDialog(getActivity(), "Fetching..", "getting your notes");

View file

@ -0,0 +1,16 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.android_app.matan.ara.sagi.thesocialnotework.ExploreFragment"
android:orientation="vertical"
android:paddingTop="15dp">
<!-- TODO: Update blank fragment layout -->
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list_notes"
android:choiceMode="none" />
</LinearLayout>

View file

@ -81,8 +81,7 @@
android:id="@+id/ps_list_listview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:layout_marginTop="10dp" />
android:layout_weight="0.8" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"

View file

@ -4,19 +4,19 @@
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:layout_width="70dp"
android:layout_height="70dp"
android:id="@+id/nvm_permission_textview"
android:background="@drawable/private_icon"
android:gravity="center_vertical|center_horizontal" />
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:id="@+id/nvm_permission_image_view"
android:layout_gravity="left" />
<LinearLayout
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:layout_marginLeft="15dp">
android:layout_marginLeft="15dp"
android:layout_gravity="center">
<TextView
android:layout_width="fill_parent"
@ -70,7 +70,7 @@
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<ImageView
android:layout_width="13dp"
@ -92,10 +92,11 @@
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3">
android:layout_weight="0.3"
android:gravity="end"
android:layout_gravity="right">
<LinearLayout
android:orientation="horizontal"

View file

@ -1,43 +1,43 @@
<resources>
<string name="app_name">TSN</string>
<string name="app_name">TSN</string>
<!-- Strings related to login -->
<string name="prompt_email">Email</string>
<string name="prompt_username">Username</string>
<string name="prompt_password">Password</string>
<string name="action_login">Login</string>
<string name="action_register">Register</string>
<string name="register">Register</string>
<string name="create_new_account">No account yet? Create one for FREE</string>
<string name="action_sign_in_short">Sign in</string>
<string name="error_invalid_email">This email address is invalid</string>
<string name="error_invalid_password">This password is too short</string>
<string name="error_incorrect_password">This password is incorrect</string>
<string name="error_field_required">This field is required</string>
<!-- Strings related to login -->
<string name="prompt_email">Email</string>
<string name="prompt_username">Username</string>
<string name="prompt_password">Password</string>
<string name="action_login">Login</string>
<string name="action_register">Register</string>
<string name="register">Register</string>
<string name="create_new_account">No account yet? Create one for FREE</string>
<string name="action_sign_in_short">Sign in</string>
<string name="error_invalid_email">This email address is invalid</string>
<string name="error_invalid_password">This password is too short</string>
<string name="error_incorrect_password">This password is incorrect</string>
<string name="error_field_required">This field is required</string>
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions."
</string>
<string name="title_activity_personal_space">PersonalSpaceActivity</string>
<string name="nvf_private_label">Private</string>
<string name="nvf_public_label">Public</string>
<string name="logo">Logo</string>
<string name="nvf_title">Title</string>
<string name="nvf_content">Content</string>
<string name="throw_me">Discard</string>
<string name="note_me">Save</string>
<string name="username">Username</string>
<string name="password">Password</string>
<string name="title_activity_main">MainActivity</string>
<string name="title_activity_personal_space">PersonalSpaceActivity</string>
<string name="nvf_private_label">Private</string>
<string name="nvf_public_label">Public</string>
<string name="logo">Logo</string>
<string name="nvf_title">Title</string>
<string name="nvf_content">Content</string>
<string name="throw_me">Discard</string>
<string name="note_me">Save</string>
<string name="username">Username</string>
<string name="password">Password</string>
<string name="title_activity_main">MainActivity</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_settings">Settings</string>
<string name="action_settings">Settings</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="login_err_message_invalid">Password should be at least 4 chars long</string>
<string name="title_activity_maps">Map</string>
<string name="avatar">Avatar</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="login_err_message_invalid">Password should be at least 4 chars long</string>
<string name="title_activity_maps">Map</string>
<string name="avatar">Avatar</string>
</resources>