diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java index 3bdc1b5..818fa47 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java @@ -149,6 +149,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL view.findViewById(R.id.comment_box).bringToFront(); view.findViewById(R.id.filter_buttons).setVisibility(View.GONE); ((FloatingActionButton)view.findViewById(R.id.upload_button)).hide(); + hideKeyboard(); } }); @@ -179,6 +180,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL view.findViewById(R.id.switch_camera_button).bringToFront(); mCameraLayout.removeView(view.findViewById(R.id.pic_preview)); + hideKeyboard(); } }); @@ -203,6 +205,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL view.findViewById(R.id.switch_camera_button).bringToFront(); mCameraLayout.removeView(view.findViewById(R.id.pic_preview)); + hideKeyboard(); } }); @@ -242,21 +245,15 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL } }); - (view.findViewById(R.id.comment_text)).setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View v, boolean hasFocus) { - if (!hasFocus) { - hideKeyboard(v); - } - } - }); - return view; } - public void hideKeyboard(View view) { - InputMethodManager inputMethodManager =(InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); - inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); + /** + * Hides keyboard after submit, upload or cancel button gets pressed. + */ + public void hideKeyboard() { + ((InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE)) + .toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); } // TODO: Rename method, update argument and hook method into UI event diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java index 0316efa..b6cfce8 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java @@ -45,9 +45,12 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { protected TextView profileName; protected ImageView profilePicture; protected FirebaseUser user; - protected File photoFile = null; + protected File photoFile; private ListView listView; private DownloadClass downloadClass; + private View headerInflater; + private View timeLineInflater; + ProgressDialog progressDialog; /// Required empty public constructor /// @@ -58,19 +61,25 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); user = FirebaseAuth.getInstance().getCurrentUser(); + photoFile = null; } /** - * Assigns all views and buttons. + * Assigns all views and buttons for the header. */ - protected void findViews(View view) { - profilePicButton = (ImageButton) view.findViewById(R.id.profile_pic_button); - profilePicture = (ImageView) view.findViewById(R.id.imageView_profile_picture); - profileName = (TextView) view.findViewById(R.id.profile_name); - changePwdButton = (Button) view.findViewById(R.id.change_psw_button); + protected void findHeaderViews() { + profilePicButton = (ImageButton) headerInflater.findViewById(R.id.profile_pic_button); + profilePicture = (ImageView) headerInflater.findViewById(R.id.imageView_profile_picture); + profileName = (TextView) headerInflater.findViewById(R.id.profile_name); + changePwdButton = (Button) headerInflater.findViewById(R.id.change_psw_button); bindOnClick(); } + protected void findTimelineViews() { + listView = (ListView) timeLineInflater.findViewById(R.id.list); + listView.addHeaderView(headerInflater); + } + /** * Bind the buttons to their listeners. */ @@ -84,11 +93,11 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View viewTimeline = inflater.inflate(R.layout.fragment_profile_timeline, container, false); - listView = (ListView) viewTimeline.findViewById(R.id.list); - View viewHeader = inflater.inflate(R.layout.fragment_profile_header, listView, false); - findViews(viewHeader); - listView.addHeaderView(viewHeader); + + timeLineInflater = inflater.inflate(R.layout.fragment_profile_timeline, container, false); + headerInflater = inflater.inflate(R.layout.fragment_profile_header, listView, false); + findHeaderViews(); + findTimelineViews(); profilePicture.invalidate(); @@ -106,11 +115,9 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture); } - - - downloadClass = new DownloadClass(getActivity(), "profile"); + downloadClass = new DownloadClass(getActivity()); downloadClass.getPostsFromServer(); - return viewTimeline; + return timeLineInflater; } /** diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/TimelineFragment.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/TimelineFragment.java index db99e77..7d41818 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/TimelineFragment.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/TimelineFragment.java @@ -32,13 +32,13 @@ public class TimelineFragment extends Fragment { final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) view.findViewById(R.id.swipe); swipeView.setEnabled(false); - downloadClass = new DownloadClass(getActivity(), "timeline"); + downloadClass = new DownloadClass(getActivity()); downloadClass.getPostsFromServer(); swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { - downloadClass = new DownloadClass(getActivity(), "timeline"); + downloadClass = new DownloadClass(getActivity()); downloadClass.getPostsFromServer(); swipeView.setRefreshing(true); ( new Handler()).postDelayed(new Runnable() { diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/DownloadClass.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/DownloadClass.java index cd5e0e0..819b772 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/DownloadClass.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/DownloadClass.java @@ -24,9 +24,8 @@ public class DownloadClass { private DatabaseReference mDataRef; private ArrayList mList; private PostDownloadListener mListener; - private String fragmentName; - public DownloadClass(Context context, String fragmentName) { + public DownloadClass(Context context) { if (context instanceof DownloadClass.PostDownloadListener) { mListener = (PostDownloadListener) context; } else { @@ -35,7 +34,6 @@ public class DownloadClass { } mDataRef = FirebaseDatabase.getInstance().getReference(); mList = new ArrayList<>(); - this.fragmentName = fragmentName; } public void getPostsFromServer() {