Explore
This commit is contained in:
parent
9651eba02c
commit
01aaf28247
8 changed files with 175 additions and 50 deletions
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import android.view.ViewGroup;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
//import com.android.volley.toolbox.NetworkImageView;
|
//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 date = (TextView) v.findViewById(R.id.nvm_date_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 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);
|
// 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());
|
||||||
|
@ -73,7 +74,11 @@ public class ListAdapter extends BaseAdapter {
|
||||||
location.setText(curNote.getAddress());
|
location.setText(curNote.getAddress());
|
||||||
if(likes !=null )likes.setText(""+curNote.getLikes());
|
if(likes !=null )likes.setText(""+curNote.getLikes());
|
||||||
// permission.setText(curNote.isPublic() ? "Public":"Private");
|
// permission.setText(curNote.isPublic() ? "Public":"Private");
|
||||||
|
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));
|
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);
|
Animation animation = AnimationUtils.loadAnimation(mContext, (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
|
||||||
v.startAnimation(animation);
|
v.startAnimation(animation);
|
||||||
|
|
|
@ -52,6 +52,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
private GmapFragment gmapFragment;
|
private GmapFragment gmapFragment;
|
||||||
private PersonalFragment personalFragment;
|
private PersonalFragment personalFragment;
|
||||||
private SettingsFragment settingsFragment;
|
private SettingsFragment settingsFragment;
|
||||||
|
private ExploreFragment exploreFragment;
|
||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
||||||
private ImageView menu_avatar;
|
private ImageView menu_avatar;
|
||||||
|
@ -71,6 +72,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
gmapFragment = new GmapFragment();
|
gmapFragment = new GmapFragment();
|
||||||
personalFragment = new PersonalFragment();
|
personalFragment = new PersonalFragment();
|
||||||
settingsFragment = new SettingsFragment();
|
settingsFragment = new SettingsFragment();
|
||||||
|
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);
|
||||||
|
|
||||||
|
@ -153,6 +155,9 @@ public class MainActivity extends AppCompatActivity
|
||||||
if (id == R.id.nav_explore) {
|
if (id == R.id.nav_explore) {
|
||||||
toolbar.setTitle("Explore");
|
toolbar.setTitle("Explore");
|
||||||
setSupportActionBar(toolbar);
|
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) {
|
} else if (id == R.id.nav_map) {
|
||||||
|
|
||||||
Log.d(TAG, "Before going to map");
|
Log.d(TAG, "Before going to map");
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class PersonalFragment extends Fragment {
|
||||||
gpsUtils = activity.getGPSUtils();
|
gpsUtils = activity.getGPSUtils();
|
||||||
gpsUtils.getLocation();
|
gpsUtils.getLocation();
|
||||||
listOfNotes = new ArrayList<>();
|
listOfNotes = new ArrayList<>();
|
||||||
noteListAdapter = new ListAdapter(getContext(), listOfNotes);
|
noteListAdapter = new ListAdapter(activity, listOfNotes);
|
||||||
noteList.setAdapter(noteListAdapter);
|
noteList.setAdapter(noteListAdapter);
|
||||||
noteList.setOnItemClickListener(new ItemClickedListener());
|
noteList.setOnItemClickListener(new ItemClickedListener());
|
||||||
Utils.showLoadingDialog(getActivity(), "Fetching..", "getting your notes");
|
Utils.showLoadingDialog(getActivity(), "Fetching..", "getting your notes");
|
||||||
|
|
16
app/src/main/res/layout/fragment_explore.xml
Normal file
16
app/src/main/res/layout/fragment_explore.xml
Normal 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>
|
|
@ -81,8 +81,7 @@
|
||||||
android:id="@+id/ps_list_listview"
|
android:id="@+id/ps_list_listview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="0.8"
|
android:layout_weight="0.8" />
|
||||||
android:layout_marginTop="10dp" />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<android.support.design.widget.FloatingActionButton
|
<android.support.design.widget.FloatingActionButton
|
||||||
android:id="@+id/fab"
|
android:id="@+id/fab"
|
||||||
|
|
|
@ -4,19 +4,19 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="5dp">
|
android:padding="5dp">
|
||||||
|
|
||||||
<TextView
|
<ImageView
|
||||||
android:layout_width="70dp"
|
android:layout_width="70dp"
|
||||||
android:layout_height="70dp"
|
android:layout_height="70dp"
|
||||||
android:id="@+id/nvm_permission_textview"
|
android:id="@+id/nvm_permission_image_view"
|
||||||
android:background="@drawable/private_icon"
|
android:layout_gravity="left" />
|
||||||
android:gravity="center_vertical|center_horizontal" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.6"
|
android:layout_weight="0.6"
|
||||||
android:layout_marginLeft="15dp">
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_gravity="center">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="13dp"
|
android:layout_width="13dp"
|
||||||
|
@ -92,10 +92,11 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="0.3">
|
android:layout_weight="0.3"
|
||||||
|
android:gravity="end"
|
||||||
|
android:layout_gravity="right">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
|
Loading…
Reference in a new issue