Merge branch 'master' into 'niels-profile'
# Conflicts: # app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java # app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml # app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml
This commit is contained in:
@@ -118,7 +118,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
|
||||
String passwordConfirmString = passwordConfirmField.getText().toString();
|
||||
|
||||
if (!emailString.isEmpty() && !usernameString.isEmpty()
|
||||
&& passwordString.isEmpty() && passwordConfirmString.isEmpty()) {
|
||||
&& !passwordString.isEmpty() && !passwordConfirmString.isEmpty()) {
|
||||
if (passwordField.getText().toString().equals(passwordConfirmField.getText().toString())) {
|
||||
registerUser(emailField.getText().toString(), passwordField.getText().toString());
|
||||
} else {
|
||||
|
||||
@@ -17,7 +17,10 @@ import com.google.firebase.auth.FirebaseAuth;
|
||||
import nl.myhyvesbookplus.tagram.controller.DownloadClass;
|
||||
import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements CameraFragment.OnFragmentInteractionListener, TimelineFragment.OnFragmentInteractionListener, ProfilePictureUploader.ProfilePictureUpdatedListener {
|
||||
public class MainActivity extends AppCompatActivity implements
|
||||
CameraFragment.OnFragmentInteractionListener,
|
||||
ProfilePictureUploader.ProfilePictureUpdatedListener,
|
||||
DownloadClass.PostDownloadListener {
|
||||
final static private String TAG = "MainScreen";
|
||||
|
||||
FirebaseAuth mAuth;
|
||||
@@ -100,10 +103,10 @@ public class MainActivity extends AppCompatActivity implements CameraFragment.On
|
||||
this.finish();
|
||||
}
|
||||
|
||||
public void testCreatePost(View view) {
|
||||
DownloadClass downloadClass = new DownloadClass();
|
||||
downloadClass.getPosts();
|
||||
}
|
||||
// public void testCreatePost(View view) {
|
||||
// DownloadClass downloadClass = new DownloadClass();
|
||||
// downloadClass.getPosts();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void ProfilePictureUpdated(Boolean success) {
|
||||
@@ -118,4 +121,12 @@ public class MainActivity extends AppCompatActivity implements CameraFragment.On
|
||||
Log.d(TAG, "ProfilePictureUpdated: Done reloading fragment");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void PostDownloaded() {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
fragmentManager.findFragmentById(R.id.content);
|
||||
TimelineFragment frag = (TimelineFragment) fragmentManager.findFragmentById(R.id.content);
|
||||
frag.startList();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package nl.myhyvesbookplus.tagram;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.firebase.ui.storage.images.FirebaseImageLoader;
|
||||
import com.google.firebase.storage.FirebaseStorage;
|
||||
import com.google.firebase.storage.StorageReference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import nl.myhyvesbookplus.tagram.model.UriPost;
|
||||
|
||||
/**
|
||||
* Created by marijnjansen on 26/06/2017.
|
||||
*/
|
||||
|
||||
public class TimeLineAdapter extends BaseAdapter {
|
||||
private static final String TAG = "TimeLineAdapter";
|
||||
private LayoutInflater mInflater;
|
||||
private Context mContext;
|
||||
private ArrayList<UriPost> mData;
|
||||
|
||||
TimeLineAdapter(Context context, ArrayList<UriPost> data) {
|
||||
mContext = context;
|
||||
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mData = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
Log.d(TAG, "getCount: " + mData.size());
|
||||
return mData.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mData.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
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);
|
||||
ImageView photo = (ImageView) rowView.findViewById(R.id.timeline_image);
|
||||
|
||||
UriPost post = (UriPost) getItem(position);
|
||||
|
||||
nietslechts.setText(Integer.toString(post.getNietSlechts()));
|
||||
comment.setText(post.getComment());
|
||||
|
||||
StorageReference ref = FirebaseStorage.getInstance().getReferenceFromUrl(post.getUri());
|
||||
Glide.with(mContext)
|
||||
.using(new FirebaseImageLoader())
|
||||
.load(ref)
|
||||
.into(photo);
|
||||
|
||||
|
||||
return rowView;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,25 @@
|
||||
package nl.myhyvesbookplus.tagram;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
|
||||
import nl.myhyvesbookplus.tagram.controller.DownloadClass;
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Activities that contain this fragment must implement the
|
||||
* {@link TimelineFragment.OnFragmentInteractionListener} interface
|
||||
* to handle interaction events.
|
||||
* Use the {@link TimelineFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class TimelineFragment extends Fragment {
|
||||
// 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";
|
||||
final private static String TAG = "TimelineFragment";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
private OnFragmentInteractionListener mListener;
|
||||
private ListView listView;
|
||||
private DownloadClass downloadClass;
|
||||
|
||||
public TimelineFragment() {
|
||||
// Required empty public constructor
|
||||
@@ -36,73 +28,31 @@ public class TimelineFragment extends Fragment {
|
||||
/**
|
||||
* 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 TimelineFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static TimelineFragment newInstance(String param1, String param2) {
|
||||
public static TimelineFragment newInstance() {
|
||||
TimelineFragment fragment = new TimelineFragment();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@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 inflater.inflate(R.layout.fragment_timeline, container, false);
|
||||
return view;
|
||||
}
|
||||
|
||||
// TODO: Rename method, update argument and hook method into UI event
|
||||
public void onButtonPressed(Uri uri) {
|
||||
if (mListener != null) {
|
||||
mListener.onFragmentInteraction(uri);
|
||||
}
|
||||
}
|
||||
|
||||
@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");
|
||||
}
|
||||
}
|
||||
|
||||
@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.
|
||||
* <p>
|
||||
* See the Android Training lesson <a href=
|
||||
* "http://developer.android.com/training/basics/fragments/communicating.html"
|
||||
* >Communicating with Other Fragments</a> for more information.
|
||||
*/
|
||||
public interface OnFragmentInteractionListener {
|
||||
// TODO: Update argument type and name
|
||||
void onFragmentInteraction(Uri uri);
|
||||
public void startList() {
|
||||
TimeLineAdapter adapter = new TimeLineAdapter(getActivity(), downloadClass.getmList());
|
||||
listView.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package nl.myhyvesbookplus.tagram.controller;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.firebase.database.DataSnapshot;
|
||||
@@ -9,6 +10,7 @@ import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.database.ValueEventListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import nl.myhyvesbookplus.tagram.model.UriPost;
|
||||
|
||||
@@ -18,30 +20,31 @@ import nl.myhyvesbookplus.tagram.model.UriPost;
|
||||
|
||||
public class DownloadClass {
|
||||
private static final String TAG = "DownloadClass";
|
||||
// private StorageReference mStorageRef;
|
||||
private DatabaseReference mDataRef;
|
||||
private ArrayList<UriPost> mList;
|
||||
private PostDownloadListener mListener;
|
||||
|
||||
public DownloadClass() {
|
||||
// mStorageRef = FirebaseStorage.getInstance().getReference();
|
||||
public DownloadClass(Context context) {
|
||||
if (context instanceof DownloadClass.PostDownloadListener) {
|
||||
mListener = (PostDownloadListener) context;
|
||||
} else {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement PostDownloadListener");
|
||||
}
|
||||
mDataRef = FirebaseDatabase.getInstance().getReference();
|
||||
mList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public UriPost[] getPosts() {
|
||||
UriPost[] posts = new UriPost[10];
|
||||
getPostsFromServer().toArray(posts);
|
||||
|
||||
return posts;
|
||||
}
|
||||
|
||||
private ArrayList<UriPost> getPostsFromServer() {
|
||||
public void getPostsFromServer() {
|
||||
Log.d(TAG, "getPostsFromServer: Begin of function");
|
||||
final ArrayList<UriPost> list = new ArrayList<>();
|
||||
mDataRef.child("posts").addListenerForSingleValueEvent(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
for (DataSnapshot data : dataSnapshot.getChildren()) {
|
||||
list.add(data.getValue(UriPost.class));
|
||||
mList.add(data.getValue(UriPost.class));
|
||||
}
|
||||
Collections.reverse(mList);
|
||||
mListener.PostDownloaded();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,6 +52,13 @@ public class DownloadClass {
|
||||
Log.d(TAG, "onCancelled: " + databaseError.getDetails() + databaseError.getMessage());
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<UriPost> getmList() {
|
||||
return mList;
|
||||
}
|
||||
|
||||
public interface PostDownloadListener {
|
||||
void PostDownloaded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class PostUploader extends UploadClass {
|
||||
}
|
||||
|
||||
public void uploadPicture(final BitmapPost post) {
|
||||
final String name = getUserUid() + currentTimeMillis();
|
||||
final String name = currentTimeMillis() + "_" + getUserUid();
|
||||
|
||||
UploadTask uploadTask = mStorageRef.child("posts").child(name + ".jpg").putBytes(bitmapToBytes(post.getBitmap()));
|
||||
uploadTask.addOnFailureListener(new OnFailureListener() {
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"--><!--xmlns:app="http://schemas.android.com/apk/res-auto"--><!--xmlns:tools="http://schemas.android.com/tools"--><!--android:layout_width="match_parent"--><!--android:layout_height="match_parent"--><!--tools:context="nl.myhyvesbookplus.tagram.LoginActivity">-->
|
||||
|
||||
<!--</android.support.constraint.ConstraintLayout>-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".LoginActivity">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -21,6 +29,7 @@
|
||||
android:paddingEnd="@dimen/activity_horizontal_margin"
|
||||
android:paddingStart="@dimen/activity_horizontal_margin"
|
||||
android:src="@drawable/logo_new" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -107,5 +116,6 @@
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="@string/back_to_login"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</FrameLayout>
|
||||
@@ -1,18 +1,15 @@
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="nl.myhyvesbookplus.tagram.TimelineFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
<ListView
|
||||
android:id="@+id/listview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Test bitmap upload"
|
||||
android:onClick="testCreatePost"/>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</FrameLayout>
|
||||
</ListView>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/timeline_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/comment_timeline"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hallo Ik ben een comment!" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp">
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/niet_slecht" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/niet_slecht_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="10" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -30,4 +30,6 @@
|
||||
<string name="image_save_error">Foto opslaan mislukt. Zorg a.u.b. dat er genoeg ruimte op uw telefoon beschikbaar is.</string>
|
||||
<string name="update_profile_pic_error">Het updaten van de profielfoto is mislukt. Controleer uw internetverbinding.</string>
|
||||
<string name="upload_profile_pic">Profielfoto aan het uploaden...</string>
|
||||
<string name="please_wait">Wacht a.u.b.</string>
|
||||
<string name="niet_slecht">\"Niet slecht.\"s</string>
|
||||
</resources>
|
||||
@@ -3,7 +3,6 @@
|
||||
<string name="title_home">Timeline</string>
|
||||
<string name="title_dashboard">Camera</string>
|
||||
<string name="title_notifications">Profile</string>
|
||||
|
||||
<string name="username">Username</string>
|
||||
<string name="password">Password</string>
|
||||
<string name="confirm_password">Confirm Password</string>
|
||||
@@ -15,7 +14,6 @@
|
||||
<string name="login_error">Please fill in email and password</string>
|
||||
<string name="password_match_error">Passwords do not match</string>
|
||||
<string name="register_error">Please fill in all the fields</string>
|
||||
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
<string name="hello_camera">Hello Camera</string>
|
||||
<string name="logo_text">MyHyvesBookPlusTagram logo</string>
|
||||
@@ -26,7 +24,7 @@
|
||||
<string name="please_wait">Please Wait</string>
|
||||
<string name="mail_successful">An e-mail was sent. Please follow its instructions.</string>
|
||||
<string name="mail_failed">An error occurred. Please check internet connection.</string>
|
||||
|
||||
<string name="niet_slecht">\"Niet slecht.\"s</string>
|
||||
<string name="upload">Upload</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="image_save_error">Saving image to storage failed. Please make sure there is space available on the device.</string>
|
||||
|
||||
Reference in New Issue
Block a user