diff --git a/app/MyHyvesBookPlusStagram/app/build.gradle b/app/MyHyvesBookPlusStagram/app/build.gradle index dadf17f..907707c 100644 --- a/app/MyHyvesBookPlusStagram/app/build.gradle +++ b/app/MyHyvesBookPlusStagram/app/build.gradle @@ -26,11 +26,14 @@ dependencies { }) compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:design:25.3.1' - compile 'com.google.firebase:firebase-database:10.0.1' - compile 'com.google.firebase:firebase-auth:10.0.1' + compile 'com.google.firebase:firebase-database:11.0.1' + compile 'com.google.firebase:firebase-auth:11.0.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support:support-v4:25.3.1' - compile 'com.google.firebase:firebase-storage:10.0.1' + compile 'com.google.firebase:firebase-storage:11.0.1' + + // FirebaseUI Storage only + compile 'com.firebaseui:firebase-ui-storage:2.0.1' testCompile 'junit:junit:4.12' } diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/LoginActivity.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/LoginActivity.java index 695906b..992e3e3 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/LoginActivity.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/LoginActivity.java @@ -235,6 +235,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList }); } + //TODO Make modular for use with Profile fragment. /** * Saves the Username to Firebase * @param user The User object that needs to be updated 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 f1eecc8..ff753af 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 @@ -1,13 +1,33 @@ package nl.myhyvesbookplus.tagram; import android.content.Context; +import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.app.Fragment; +import android.support.annotation.NonNull; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.TextView; +import android.widget.ImageView; +import android.widget.Toast; +import com.bumptech.glide.Glide; +import com.firebase.ui.storage.images.FirebaseImageLoader; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +import org.w3c.dom.Text; + +import static android.content.ContentValues.TAG; /** * A simple {@link Fragment} subclass. @@ -17,7 +37,7 @@ import android.view.ViewGroup; * Use the {@link ProfileFragment#newInstance} factory method to * create an instance of this fragment. */ -public class ProfileFragment extends Fragment { +public class ProfileFragment extends Fragment implements View.OnClickListener { // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; @@ -27,11 +47,21 @@ public class ProfileFragment extends Fragment { private String mParam1; private String mParam2; - private OnFragmentInteractionListener mListener; + /// Views /// + + protected Button changePwdButton; + protected ImageButton profilePicButton; + protected StorageReference httpsReference; + protected TextView profileName; + protected ImageView profilePicture; + + private OnFragmentInteractionListener mListener; + protected FirebaseUser user; + + /// Required empty public constructor /// + + public ProfileFragment() {} - public ProfileFragment() { - // Required empty public constructor - } /** * Use this factory method to create a new instance of @@ -58,13 +88,48 @@ public class ProfileFragment extends Fragment { mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } + + user = FirebaseAuth.getInstance().getCurrentUser(); + if (user != null && user.getPhotoUrl() != null) { + httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString()); + } } + /** + * Assigns all views. + */ + 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); + bindOnClick(); + } + + protected void bindOnClick() { + profilePicButton.setOnClickListener(this); + changePwdButton.setOnClickListener(this); + } + + /// Setup /// + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_profile, container, false); + View view = inflater.inflate(R.layout.fragment_profile, container, false); + findViews(view); + + if (httpsReference != null) { + Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture); + } + + // TODO Remove check for getDisplayName if all users are required to enter a displayName anyways. + if (user != null && user.getDisplayName() != null) { + profileName.setText(user.getDisplayName()); + } + + return view; } // TODO: Rename method, update argument and hook method into UI event @@ -74,6 +139,56 @@ public class ProfileFragment extends Fragment { } } + /** + * Called when a view has been clicked. + * + * @param v The view that was clicked. + */ + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.profile_pic_button: + profilePicOnClick(); + break; + case R.id.change_psw_button: + changePwdOnClick(); + break; + } + } + + // 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"); + } + + // TODO Make this function into its own class for modularity. + /** + * Performs password reset action. + */ + public void changePwdOnClick() { + if (user != null && user.getEmail() != null) { + FirebaseAuth.getInstance().sendPasswordResetEmail(user.getEmail()) + .addOnCompleteListener(new OnCompleteListener() { + @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.", + Toast.LENGTH_SHORT).show(); + } + }); + } else { + // 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); @@ -85,6 +200,9 @@ public class ProfileFragment extends Fragment { } } + /** + * Obligatory onDetach function included in fragments. + */ @Override public void onDetach() { super.onDetach(); @@ -96,10 +214,8 @@ public class ProfileFragment extends Fragment { * 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 Communicating with Other Fragments for more information. + * 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 diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/drawable/avatar_standard.png b/app/MyHyvesBookPlusStagram/app/src/main/res/drawable/avatar_standard.png new file mode 100644 index 0000000..21ab818 Binary files /dev/null and b/app/MyHyvesBookPlusStagram/app/src/main/res/drawable/avatar_standard.png differ diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/layout/fragment_camera.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/layout/fragment_camera.xml index 49fd204..392188c 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/res/layout/fragment_camera.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/layout/fragment_camera.xml @@ -14,11 +14,6 @@ android:layout_height="wrap_content" android:text="@string/hello_camera" /> -