diff --git a/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml b/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml index dff6028..63bdf6e 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml @@ -3,6 +3,9 @@ package="nl.myhyvesbookplus.tagram"> + + + + + + + + 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 14c8297..6228aac 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 @@ -16,7 +16,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; -import nl.myhyvesbookplus.tagram.controller.UploadClass; +import nl.myhyvesbookplus.tagram.controller.PostUploader; /** * A simple {@link Fragment} subclass. @@ -26,7 +26,7 @@ import nl.myhyvesbookplus.tagram.controller.UploadClass; * Use the {@link CameraFragment#newInstance} factory method to * create an instance of this fragment. */ -public class CameraFragment extends Fragment { +public class CameraFragment extends Fragment implements PostUploader.PostUploadListener{ // TODO: Rename parameter arguments, choose names that match private static final String TAG = "CameraFragment"; // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER @@ -144,8 +144,6 @@ public class CameraFragment extends Fragment { (view.findViewById(R.id.upload_button)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - UploadClass upload = new UploadClass(); - upload.uploadPicture(mPhoto); mPhoto.recycle(); mPhoto = null; @@ -291,6 +289,11 @@ public class CameraFragment extends Fragment { super.onResume(); } + @Override + public void PostUploadComplete(Boolean success) { + + } + /** * This interface must be implemented by activities that contain this * fragment to allow an interaction in this fragment to be communicated @@ -305,4 +308,5 @@ public class CameraFragment extends Fragment { // TODO: Update argument type and name void onFragmentInteraction(Uri uri); } + } diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java index bae9414..ab1768c 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java @@ -19,7 +19,6 @@ import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader; public class MainActivity extends AppCompatActivity implements CameraFragment.OnFragmentInteractionListener, - ProfileFragment.OnFragmentInteractionListener, ProfilePictureUploader.ProfilePictureUpdatedListener, DownloadClass.PostDownloadListener { final static private String TAG = "MainScreen"; 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 191a3ef..eb40f3d 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 @@ -2,13 +2,13 @@ package nl.myhyvesbookplus.tagram; import android.app.Fragment; import android.app.ProgressDialog; -import android.content.Context; import android.content.Intent; -import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; +import android.os.Environment; import android.provider.MediaStore; import android.support.annotation.NonNull; +import android.support.v4.content.FileProvider; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,7 +17,6 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; - import com.bumptech.glide.Glide; import com.firebase.ui.storage.images.FirebaseImageLoader; import com.google.android.gms.tasks.OnCompleteListener; @@ -27,76 +26,39 @@ import com.google.firebase.auth.FirebaseUser; import com.google.firebase.storage.FirebaseStorage; import com.google.firebase.storage.StorageReference; +import java.io.File; +import java.io.IOException; + import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader; import static android.app.Activity.RESULT_OK; -/** - * A simple {@link Fragment} subclass. - * Activities that contain this fragment must implement the - * {@link ProfileFragment.OnFragmentInteractionListener} interface - * to handle interaction events. - * Use the {@link ProfileFragment#newInstance} factory method to - * create an instance of this fragment. - */ public class ProfileFragment extends Fragment implements View.OnClickListener { - static final int REQUEST_IMAGE_CAPTURE = 1; - final static private String TAG = "ProfileFragment"; - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - private static Uri downloadUrl; + static final int REQUEST_TAKE_PHOTO = 1; + + /// Views, buttons and other protected declarations /// protected Button changePwdButton; protected ImageButton profilePicButton; - - /// Views /// protected StorageReference httpsReference; protected TextView profileName; protected ImageView profilePicture; protected FirebaseUser user; + protected File photoFile = null; + ProgressDialog progressDialog; - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; - private OnFragmentInteractionListener mListener; /// Required empty public constructor /// public ProfileFragment() {} - - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment ProfileFragment. - */ - // TODO: Rename and change types and number of parameters - public static ProfileFragment newInstance(String param1, String param2) { - ProfileFragment fragment = new ProfileFragment(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } - user = FirebaseAuth.getInstance().getCurrentUser(); } /** - * Assigns all views. + * Assigns all views and buttons. */ protected void findViews(View view) { profilePicButton = (ImageButton) view.findViewById(R.id.profile_pic_button); @@ -106,22 +68,30 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { bindOnClick(); } + /** + * Bind the buttons to their listeners. + */ protected void bindOnClick() { profilePicButton.setOnClickListener(this); changePwdButton.setOnClickListener(this); } - /// Setup /// + /// Page setup /// @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_profile, container, false); findViews(view); - if (user != null && user.getPhotoUrl() != null) { - httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString()); + if (user != null) { + if(user.getPhotoUrl() != null) { + httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString()); + } + + if (user.getDisplayName() != null) { + profileName.setText(user.getDisplayName()); + } } if (httpsReference != null) { @@ -130,20 +100,9 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { profilePicture.invalidate(); - if (user != null && user.getDisplayName() != null) { - profileName.setText(user.getDisplayName()); - } - return view; } - // TODO: Rename method, update argument and hook method into UI event - public void onButtonPressed(Uri uri) { - if (mListener != null) { - mListener.onFragmentInteraction(uri); - } - } - /** * Called when a view has been clicked. * @@ -161,43 +120,57 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { } } - // TODO Make the function actually do something. - /** - * Performs profile picture change action. - */ - public void profilePicOnClick() { -// Log.d(TAG, "profilePicOnClick: JE KAN NOG GEEN FOTO UPLOADEN"); - dispatchTakePictureIntent(); - } - /** * Starts new intent for access to the built-in camera of device. */ - private void dispatchTakePictureIntent() { + private void profilePicOnClick() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + /* Ensure that there's a camera activity to handle the intent */ if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { - startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); + /* Create the File where the photo should go */ + try { + photoFile = createImageFile(); + } catch (IOException ex) { + Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_LONG); + } + if (photoFile != null) { + Uri photoURI = FileProvider.getUriForFile(getActivity(), + "nl.myhyvesbookplus.tagram.fileprovider", + photoFile); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); + startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); + } } } /** * Grabs the image just taken by the built-in camera and pushes this image to the user account. - * @param requestCode - * @param resultCode - * @param data + * @param requestCode The code which corresponds to REQUEST_TAKE_PHOTO. Used as indicator. + * @param resultCode Code should be RESULT_OK to allow camera to proceed. + * @param data The image data from the camera. */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { - Bundle extras = data.getExtras(); - Bitmap imageBitmap = (Bitmap) extras.get("data"); - progressDialog = ProgressDialog.show(getActivity(), getString(R.string.please_wait), "bezig met uploaden", false, false); + if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) { + progressDialog = ProgressDialog.show(getActivity(), getString(R.string.please_wait), getString(R.string.upload_profile_pic), false, false); ProfilePictureUploader profilePictureUploader = new ProfilePictureUploader(getActivity()); - profilePictureUploader.uploadProfilePicture(imageBitmap); + profilePictureUploader.uploadProfilePicture(photoFile.getAbsoluteFile()); } } + private File createImageFile() throws IOException { + // Create an image file name + String imageFileName = "JPEG_" + user.getUid(); + File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); + return File.createTempFile( + imageFileName, /* prefix */ + ".jpg", /* suffix */ + storageDir /* directory */ + ); + } + + // TODO Make this function into its own class for modularity. /** @@ -210,8 +183,8 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { @Override public void onComplete(@NonNull Task task) { Toast.makeText(getActivity(), task.isSuccessful() - ? "An e-mail was sent, please follow its instructions." - : "An error occurred, please check internet connection.", + ? "An e-mail was sent, please follow its instructions." + : "An error occurred, please check internet connection.", Toast.LENGTH_SHORT).show(); } }); @@ -219,43 +192,4 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { // TODO Add code here for when there is no currently active user. } } - - /** - * Obligatory onAttach function included in fragments. - * @param context provided context for the function to operate on. - */ - @Override - public void onAttach(Context context) { - super.onAttach(context); - if (context instanceof OnFragmentInteractionListener) { - mListener = (OnFragmentInteractionListener) context; - } else { - throw new RuntimeException(context.toString() - + " must implement OnFragmentInteractionListener"); - } - } - - /** - * Obligatory onDetach function included in fragments. - */ - @Override - public void onDetach() { - super.onDetach(); - mListener = null; - } - - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated - * to the activity and potentially other fragments contained in that - * activity. - * See the Android Training lesson http://developer.android.com/training/basics/fragments/communicating.html - * for more information. - */ - public interface OnFragmentInteractionListener { - // TODO: Update argument type and name - void onFragmentInteraction(Uri uri); - } - - } diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/TimeLineAdapter.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/TimeLineAdapter.java index 5cf22f4..c5fde32 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/TimeLineAdapter.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/TimeLineAdapter.java @@ -5,7 +5,9 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.BaseAdapter; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; @@ -22,7 +24,7 @@ import nl.myhyvesbookplus.tagram.model.UriPost; * Created by marijnjansen on 26/06/2017. */ -public class TimeLineAdapter extends BaseAdapter { +public class TimeLineAdapter extends BaseAdapter implements AdapterView.OnItemClickListener { private static final String TAG = "TimeLineAdapter"; private LayoutInflater mInflater; private Context mContext; @@ -55,12 +57,20 @@ public class TimeLineAdapter extends BaseAdapter { View rowView = mInflater.inflate(R.layout.list_item_timeline, parent, false); TextView comment = (TextView) rowView.findViewById(R.id.comment_timeline); - TextView nietslechts = (TextView) rowView.findViewById(R.id.niet_slecht_count); + TextView nietSlechts = (TextView) rowView.findViewById(R.id.niet_slecht_count); ImageView photo = (ImageView) rowView.findViewById(R.id.timeline_image); + ImageButton nietSlechtButton = (ImageButton) rowView.findViewById(R.id.niet_slecht_button); + + nietSlechtButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + } + }); UriPost post = (UriPost) getItem(position); - nietslechts.setText(Integer.toString(post.getNietSlechts())); + nietSlechts.setText(Integer.toString(post.getNietSlechts())); comment.setText(post.getComment()); StorageReference ref = FirebaseStorage.getInstance().getReferenceFromUrl(post.getUri()); @@ -72,4 +82,23 @@ public class TimeLineAdapter extends BaseAdapter { return rowView; } + + + /** + * Callback method to be invoked when an item in this AdapterView has + * been clicked. + *

+ * Implementers can call getItemAtPosition(position) if they need + * to access the data associated with the selected item. + * + * @param parent The AdapterView where the click happened. + * @param view The view within the AdapterView that was clicked (this + * will be a view provided by the adapter) + * @param position The position of the view in the adapter. + * @param id The row id of the item that was clicked. + */ + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Log.d(TAG, "onItemClick: rowNumber! "+ position); + } } 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 44f568d..b2ca6d4 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 @@ -10,13 +10,7 @@ import android.widget.ListView; import nl.myhyvesbookplus.tagram.controller.DownloadClass; -/** - * A simple {@link Fragment} subclass. - * Use the {@link TimelineFragment#newInstance} factory method to - * create an instance of this fragment. - */ public class TimelineFragment extends Fragment { - final private static String TAG = "TimelineFragment"; private ListView listView; private DownloadClass downloadClass; @@ -25,29 +19,15 @@ public class TimelineFragment extends Fragment { // Required empty public constructor } - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * @return A new instance of fragment TimelineFragment. - */ - // TODO: Rename and change types and number of parameters - public static TimelineFragment newInstance() { - TimelineFragment fragment = new TimelineFragment(); - Bundle args = new Bundle(); - fragment.setArguments(args); - return fragment; - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_timeline, container, false); - listView = (ListView) view.findViewById(R.id.listview); + downloadClass = new DownloadClass(getActivity()); downloadClass.getPostsFromServer(); - // Inflate the layout for this fragment return view; } diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/ProfilePictureUploader.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/ProfilePictureUploader.java index 1137d5d..3264976 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/ProfilePictureUploader.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/ProfilePictureUploader.java @@ -5,6 +5,7 @@ import android.graphics.Bitmap; import android.net.Uri; import android.support.annotation.NonNull; import android.util.Log; +import android.widget.Toast; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnFailureListener; @@ -12,9 +13,12 @@ import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.Task; import com.google.firebase.auth.UserProfileChangeRequest; import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageMetadata; import com.google.firebase.storage.StorageReference; import com.google.firebase.storage.UploadTask; +import java.io.File; + import static java.lang.System.currentTimeMillis; /** @@ -39,10 +43,13 @@ public class ProfilePictureUploader extends UploadClass { } } - public void uploadProfilePicture(Bitmap picture) { - byte[] uploadPhoto = bitmapToBytes(picture); + public void uploadProfilePicture(File picture) { oldPicture = mUser.getPhotoUrl(); - UploadTask photoUpload = mStorageRef.child("profile").child(getUserUid() + "_" + currentTimeMillis()).putBytes(uploadPhoto); + StorageMetadata metadata = new StorageMetadata.Builder() + .setContentType("image/jpg") + .build(); + + UploadTask photoUpload = mStorageRef.child("profile").child(getUserUid() + "_" + currentTimeMillis()).putFile(Uri.fromFile(picture), metadata); photoUpload.addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { @@ -80,9 +87,9 @@ public class ProfilePictureUploader extends UploadClass { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { - Log.d(TAG, "onComplete: Delete successfull"); + Log.v(TAG, "onComplete: Delete successful"); } else { - Log.d(TAG, "onComplete: " + task.getException().getLocalizedMessage()); + Log.v(TAG, "onComplete: " + task.getException().getLocalizedMessage()); } } }); diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/layout/list_item_timeline.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/layout/list_item_timeline.xml index 5a0d59e..9e1bba4 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/res/layout/list_item_timeline.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/layout/list_item_timeline.xml @@ -2,6 +2,7 @@ diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml index 03b3f3f..79c3196 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml @@ -17,6 +17,19 @@ Wijzig Profiel Foto profiel foto Wachtwoord wijzigen + Momentje + Hallo leeg fragment + Hallo Camera fragment + Voer alstublieft email en wachtwoord in + Er is een fout opgetreden. Controleer internetverbinding. + Er is een e-mail verzonden. Volg a.u.b. de instructies. + Wachtwoorden komen niet overeen + Vul alstublieft alle velden in + Opslaan + Uploaden + Foto opslaan mislukt. Zorg a.u.b. dat er genoeg ruimte op uw telefoon beschikbaar is. + Het updaten van de profielfoto is mislukt. Controleer uw internetverbinding. + Profielfoto aan het uploaden... Wacht a.u.b. \"Niet slecht.\"s \ No newline at end of file diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml index 8a5ea78..3ba5068 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml @@ -3,7 +3,6 @@ Timeline Camera Profile - Username Password Confirm Password @@ -15,11 +14,10 @@ Please fill in email and password Passwords do not match Please fill in all the fields - Hello blank fragment Hello Camera MyHyvesBookPlusTagram logo - LogOut + Logout Change Profile Picture profile picture Change Password @@ -28,4 +26,9 @@ Upload Save + An e-mail was sent. Please follow its instructions. + An error occurred. Please check internet connection. + Saving image to storage failed. Please make sure there is space available on the device. + Updating the profile picture failed. Please check network connection. + Uploading profile picture... diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/xml/file_paths.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/xml/file_paths.xml new file mode 100644 index 0000000..c87d3ee --- /dev/null +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file