Timeline things working right now Woohoo!

This commit is contained in:
Marijn Jansen
2017-06-26 15:20:18 +02:00
parent a9ad130866
commit 247a443aba
11 changed files with 279 additions and 186 deletions

View File

@@ -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 {

View File

@@ -17,7 +17,11 @@ 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, ProfileFragment.OnFragmentInteractionListener, TimelineFragment.OnFragmentInteractionListener, ProfilePictureUploader.ProfilePictureUpdatedListener {
public class MainActivity extends AppCompatActivity implements
CameraFragment.OnFragmentInteractionListener,
ProfileFragment.OnFragmentInteractionListener,
ProfilePictureUploader.ProfilePictureUpdatedListener,
DownloadClass.PostDownloadListener {
final static private String TAG = "MainScreen";
FirebaseAuth mAuth;
@@ -100,10 +104,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 +122,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();
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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() {

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -18,4 +18,5 @@
<string name="profile_picture_description">profiel foto</string>
<string name="change_psw_button">Wachtwoord wijzigen</string>
<string name="please_wait">Wacht a.u.b.</string>
<string name="niet_slecht">\"Niet slecht.\"s</string>
</resources>

View File

@@ -24,4 +24,5 @@
<string name="profile_picture_description">profile picture</string>
<string name="change_psw_button">Change Password</string>
<string name="please_wait">Please Wait</string>
<string name="niet_slecht">\"Niet slecht.\"s</string>
</resources>