From 01aaf28247fb0748374aea813bf00ee0b91bc2e1 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sat, 9 Jul 2016 19:14:07 +0300 Subject: [PATCH] Explore --- .../thesocialnotework/ExploreFragment.java | 99 +++++++++++++++++++ .../sagi/thesocialnotework/ListAdapter.java | 9 +- .../sagi/thesocialnotework/MainActivity.java | 5 + .../thesocialnotework/PersonalFragment.java | 2 +- app/src/main/res/layout/fragment_explore.xml | 16 +++ app/src/main/res/layout/fragment_personal.xml | 3 +- app/src/main/res/layout/note_view_mini.xml | 25 ++--- app/src/main/res/values/strings.xml | 66 ++++++------- 8 files changed, 175 insertions(+), 50 deletions(-) create mode 100644 app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java create mode 100644 app/src/main/res/layout/fragment_explore.xml diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java new file mode 100644 index 0000000..8be26f9 --- /dev/null +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java @@ -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 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 getNotesSuccessListener = new Response.Listener() { + @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()); + } + + } + }; + +} diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ListAdapter.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ListAdapter.java index baf9c12..43260f3 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ListAdapter.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ListAdapter.java @@ -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); diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java index 6b0988f..fee6bd3 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java @@ -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"); diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java index 6636b88..e5eb014 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java @@ -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"); diff --git a/app/src/main/res/layout/fragment_explore.xml b/app/src/main/res/layout/fragment_explore.xml new file mode 100644 index 0000000..b17eaa6 --- /dev/null +++ b/app/src/main/res/layout/fragment_explore.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/app/src/main/res/layout/fragment_personal.xml b/app/src/main/res/layout/fragment_personal.xml index 02141dd..8f0328e 100644 --- a/app/src/main/res/layout/fragment_personal.xml +++ b/app/src/main/res/layout/fragment_personal.xml @@ -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" /> - + - + android:layout_marginLeft="15dp" + android:layout_gravity="center"> + android:layout_height="wrap_content"> + android:layout_weight="0.3" + android:gravity="end" + android:layout_gravity="right"> - TSN + TSN - - Email - Username - Password - Login - Register - Register - No account yet? Create one for FREE - Sign in - This email address is invalid - This password is too short - This password is incorrect - This field is required + + Email + Username + Password + Login + Register + Register + No account yet? Create one for FREE + Sign in + This email address is invalid + This password is too short + This password is incorrect + This field is required "Contacts permissions are needed for providing email completions." - PersonalSpaceActivity - Private - Public - Logo - Title - Content - Discard - Save - Username - Password - MainActivity + PersonalSpaceActivity + Private + Public + Logo + Title + Content + Discard + Save + Username + Password + MainActivity - Open navigation drawer - Close navigation drawer + Open navigation drawer + Close navigation drawer - Settings + Settings - - Hello blank fragment - Password should be at least 4 chars long - Map - Avatar + + Hello blank fragment + Password should be at least 4 chars long + Map + Avatar