Potentially fixed Felix' bug in the camera. Also made some changes for better readability of my own code.

This commit is contained in:
Niels Zwemmer
2017-06-28 19:46:38 +02:00
parent 2315d58598
commit 1fdd21440b
4 changed files with 35 additions and 33 deletions

View File

@@ -149,6 +149,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
view.findViewById(R.id.comment_box).bringToFront(); view.findViewById(R.id.comment_box).bringToFront();
view.findViewById(R.id.filter_buttons).setVisibility(View.GONE); view.findViewById(R.id.filter_buttons).setVisibility(View.GONE);
((FloatingActionButton)view.findViewById(R.id.upload_button)).hide(); ((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(); view.findViewById(R.id.switch_camera_button).bringToFront();
mCameraLayout.removeView(view.findViewById(R.id.pic_preview)); 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(); view.findViewById(R.id.switch_camera_button).bringToFront();
mCameraLayout.removeView(view.findViewById(R.id.pic_preview)); 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; return view;
} }
public void hideKeyboard(View view) { /**
InputMethodManager inputMethodManager =(InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); * Hides keyboard after submit, upload or cancel button gets pressed.
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); */
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 // TODO: Rename method, update argument and hook method into UI event

View File

@@ -45,9 +45,12 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
protected TextView profileName; protected TextView profileName;
protected ImageView profilePicture; protected ImageView profilePicture;
protected FirebaseUser user; protected FirebaseUser user;
protected File photoFile = null; protected File photoFile;
private ListView listView; private ListView listView;
private DownloadClass downloadClass; private DownloadClass downloadClass;
private View headerInflater;
private View timeLineInflater;
ProgressDialog progressDialog; ProgressDialog progressDialog;
/// Required empty public constructor /// /// Required empty public constructor ///
@@ -58,19 +61,25 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
user = FirebaseAuth.getInstance().getCurrentUser(); user = FirebaseAuth.getInstance().getCurrentUser();
photoFile = null;
} }
/** /**
* Assigns all views and buttons. * Assigns all views and buttons for the header.
*/ */
protected void findViews(View view) { protected void findHeaderViews() {
profilePicButton = (ImageButton) view.findViewById(R.id.profile_pic_button); profilePicButton = (ImageButton) headerInflater.findViewById(R.id.profile_pic_button);
profilePicture = (ImageView) view.findViewById(R.id.imageView_profile_picture); profilePicture = (ImageView) headerInflater.findViewById(R.id.imageView_profile_picture);
profileName = (TextView) view.findViewById(R.id.profile_name); profileName = (TextView) headerInflater.findViewById(R.id.profile_name);
changePwdButton = (Button) view.findViewById(R.id.change_psw_button); changePwdButton = (Button) headerInflater.findViewById(R.id.change_psw_button);
bindOnClick(); bindOnClick();
} }
protected void findTimelineViews() {
listView = (ListView) timeLineInflater.findViewById(R.id.list);
listView.addHeaderView(headerInflater);
}
/** /**
* Bind the buttons to their listeners. * Bind the buttons to their listeners.
*/ */
@@ -84,11 +93,11 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View viewTimeline = inflater.inflate(R.layout.fragment_profile_timeline, container, false);
listView = (ListView) viewTimeline.findViewById(R.id.list); timeLineInflater = inflater.inflate(R.layout.fragment_profile_timeline, container, false);
View viewHeader = inflater.inflate(R.layout.fragment_profile_header, listView, false); headerInflater = inflater.inflate(R.layout.fragment_profile_header, listView, false);
findViews(viewHeader); findHeaderViews();
listView.addHeaderView(viewHeader); findTimelineViews();
profilePicture.invalidate(); profilePicture.invalidate();
@@ -106,11 +115,9 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture); Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture);
} }
downloadClass = new DownloadClass(getActivity());
downloadClass = new DownloadClass(getActivity(), "profile");
downloadClass.getPostsFromServer(); downloadClass.getPostsFromServer();
return viewTimeline; return timeLineInflater;
} }
/** /**

View File

@@ -32,13 +32,13 @@ public class TimelineFragment extends Fragment {
final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) view.findViewById(R.id.swipe); final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) view.findViewById(R.id.swipe);
swipeView.setEnabled(false); swipeView.setEnabled(false);
downloadClass = new DownloadClass(getActivity(), "timeline"); downloadClass = new DownloadClass(getActivity());
downloadClass.getPostsFromServer(); downloadClass.getPostsFromServer();
swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
downloadClass = new DownloadClass(getActivity(), "timeline"); downloadClass = new DownloadClass(getActivity());
downloadClass.getPostsFromServer(); downloadClass.getPostsFromServer();
swipeView.setRefreshing(true); swipeView.setRefreshing(true);
( new Handler()).postDelayed(new Runnable() { ( new Handler()).postDelayed(new Runnable() {

View File

@@ -24,9 +24,8 @@ public class DownloadClass {
private DatabaseReference mDataRef; private DatabaseReference mDataRef;
private ArrayList<UriPost> mList; private ArrayList<UriPost> mList;
private PostDownloadListener mListener; private PostDownloadListener mListener;
private String fragmentName;
public DownloadClass(Context context, String fragmentName) { public DownloadClass(Context context) {
if (context instanceof DownloadClass.PostDownloadListener) { if (context instanceof DownloadClass.PostDownloadListener) {
mListener = (PostDownloadListener) context; mListener = (PostDownloadListener) context;
} else { } else {
@@ -35,7 +34,6 @@ public class DownloadClass {
} }
mDataRef = FirebaseDatabase.getInstance().getReference(); mDataRef = FirebaseDatabase.getInstance().getReference();
mList = new ArrayList<>(); mList = new ArrayList<>();
this.fragmentName = fragmentName;
} }
public void getPostsFromServer() { public void getPostsFromServer() {