Skip to content

Commit

Permalink
Implemented ViewOnlineActivity, some progress on #9
Browse files Browse the repository at this point in the history
PR #12
  • Loading branch information
iyxan23 authored Jan 27, 2021
2 parents 909a6a9 + e9f2809 commit ae949c2
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;

import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.appbar.CollapsingToolbarLayout;
Expand All @@ -13,10 +14,14 @@
import androidx.appcompat.widget.Toolbar;

import android.view.View;
import android.widget.TextView;

import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QuerySnapshot;
import com.iyxan23.sketch.collab.R;
import com.iyxan23.sketch.collab.databinding.ActivityViewOnlineProjectBinding;

Expand All @@ -38,6 +43,8 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

CollapsingToolbarLayout toolbar_layout = findViewById(R.id.toolbar_layout);

FloatingActionButton fab = binding.fab;
fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show());
Expand All @@ -47,11 +54,62 @@ protected void onCreate(Bundle savedInstanceState) {
// Fetch the project from the database
FirebaseFirestore firestore = FirebaseFirestore.getInstance();
DocumentReference project = firestore.collection("projects").document(project_key);
CollectionReference project_commits = firestore.collection("projects").document(project_key).collection("commits");
CollectionReference userdata = firestore.collection("userdata");

final DocumentSnapshot[] tmp = new DocumentSnapshot[3];

project
.get()
.continueWithTask(task -> {
tmp[0] = task.getResult();
return userdata.document(tmp[0].getString("author")).get();
})
.continueWithTask(task -> {
tmp[1] = task.getResult();

// Get the latest commit
return project_commits.orderBy("timestamp", Query.Direction.DESCENDING).limit(1).get();
})
/* Currently not implemented, because the first commit should be initial
.continueWithTask(task -> {
tmp[2] = task.getResult().getDocuments().get(0);
// Get the first commit
return project_commits.orderBy("timestamp", Query.Direction.ASCENDING).limit(1).get();
})
*/
.addOnCompleteListener(task -> {

DocumentSnapshot project_data = tmp[0];
DocumentSnapshot uploader_userdata = tmp[1];
DocumentSnapshot latest_commit = task.getResult().getDocuments().get(0);

TextView commit_end = findViewById(R.id.commit_end);
TextView commit_end_id = findViewById(R.id.commit_end_id);
TextView commit_start = findViewById(R.id.commit_start);
TextView commit_start_id = findViewById(R.id.commit_start_id);
TextView app_title = findViewById(R.id.app_title_project);
TextView description_textview = findViewById(R.id.description_project);

String name = project_data.getString("name");
String description = project_data.getString("description");
String author_name = uploader_userdata.getString("name");
String latest_commit_id = latest_commit.getId();
String latest_commit_message = latest_commit.getString("name");
String first_commit_id = "initial";
String first_commit_message = "Initial Commit";

// Set these to the views
app_title.setText(author_name + "/" + name);
toolbar_layout.setTitle(name);
commit_end.setText(latest_commit_message);
commit_end_id.setText(latest_commit_id);
commit_start.setText(first_commit_message);
commit_start_id.setText(first_commit_id);
description_textview.setText(description);

// Hide the progressbar
findViewById(R.id.progress_project).setVisibility(View.GONE);
});
}

Expand Down
16 changes: 15 additions & 1 deletion app/src/main/res/layout/activity_view_online_project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:title="Project Name"
app:title="Loading project"
app:expandedTitleMarginBottom="42dp"
app:expandedTitleMarginStart="16dp"
app:contentScrim="@color/colorBackground"
Expand Down Expand Up @@ -64,6 +64,19 @@
app:layout_constraintStart_toEndOf="@+id/imageView10"
app:layout_constraintTop_toTopOf="@+id/imageView10" />

<TextView
android:id="@+id/app_title_project"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginTop="16dp"
android:text="Loading Name"
android:textSize="18sp"
android:fontFamily="@font/sourcecodepro_semibold"
android:textColor="#FFFFFF"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.appcompat.widget.Toolbar
Expand All @@ -84,6 +97,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="@color/colorPrimary"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@drawable/ic_edit"
Expand Down
66 changes: 42 additions & 24 deletions app/src/main/res/layout/content_scrolling.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider4"
app:srcCompat="@drawable/ic_commit_start" />
Expand All @@ -68,30 +68,33 @@
app:srcCompat="@drawable/ic_commit_end" />

<TextView
android:id="@+id/textView19"
android:id="@+id/commit_end"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:layout_marginEnd="24dp"
android:ellipsize="end"
android:fontFamily="@font/sourcecodepro_regular"
android:singleLine="true"
android:text="Commit End"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="@+id/imageView12"
app:layout_constraintEnd_toStartOf="@+id/textView22"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView12"
app:layout_constraintTop_toTopOf="@+id/imageView12" />

<TextView
android:id="@+id/textView20"
android:id="@+id/commit_start"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:fontFamily="@font/sourcecodepro_regular"
android:singleLine="true"
android:text="Commit Start"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="@+id/imageView14"
app:layout_constraintEnd_toStartOf="@+id/textView23"
app:layout_constraintEnd_toEndOf="@+id/commit_end"
app:layout_constraintStart_toEndOf="@+id/imageView14"
app:layout_constraintTop_toTopOf="@+id/imageView14" />

Expand All @@ -103,33 +106,32 @@
android:text="..."
android:textColor="#878787"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@+id/textView20"
app:layout_constraintStart_toStartOf="@+id/textView19"
app:layout_constraintTop_toBottomOf="@+id/textView19" />
app:layout_constraintBottom_toTopOf="@+id/commit_start"
app:layout_constraintStart_toStartOf="@+id/commit_end"
app:layout_constraintTop_toBottomOf="@+id/commit_end" />

<TextView
android:id="@+id/textView22"
android:id="@+id/commit_end_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:fontFamily="@font/sourcecodepro_regular"
android:text="IQUyMIuqvyFuef"
android:textColor="#A9A9A9"
android:textSize="12sp"
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView19" />
app:layout_constraintTop_toBottomOf="@+id/commit_end" />

<TextView
android:id="@+id/textView23"
android:id="@+id/commit_start_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:fontFamily="@font/sourcecodepro_regular"
android:text="IQUyMIuqvyFuef"
android:textColor="#A9A9A9"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="@+id/textView22"
app:layout_constraintTop_toBottomOf="@+id/textView22" />
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="@+id/commit_end_id"
app:layout_constraintTop_toBottomOf="@+id/commit_start" />

<View
android:id="@+id/divider5"
Expand All @@ -149,9 +151,11 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="8dp"
Expand Down Expand Up @@ -180,9 +184,11 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="8dp"
Expand Down Expand Up @@ -212,7 +218,7 @@
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="?android:attr/listDivider"
android:backgroundTint="#ACACAC"
Expand All @@ -226,24 +232,36 @@
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:text="README"
android:text="Description"
android:textSize="16sp"
android:fontFamily="@font/sourcecodepro_regular"
android:textColor="#FFFFFF"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider6" />

<TextView
android:id="@+id/textView27"
android:id="@+id/description_project"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="README Text"
android:text="Loading description"
android:textColor="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView25" />

<ProgressBar
android:id="@+id/progress_project"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:indeterminate="true"
android:translationY="-6dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

0 comments on commit ae949c2

Please sign in to comment.