Skip to content

Commit

Permalink
Add latest_commit_timestamp
Browse files Browse the repository at this point in the history
Merge dev to main (#22)
  • Loading branch information
iyxan23 authored Feb 3, 2021
2 parents 64b59aa + dfedb84 commit 4555505
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public void onBindViewHolder(@NonNull final ViewHolder holder, final int positio
Log.d(TAG, "onBindViewHolder: called.");
SketchwareProjectChanges item = datas.get(position);

// TODO: EXTEND THIS
holder.project_name.setText(item.before.metadata.project_name);
holder.project_details.setText(item.before.metadata.project_package + " (" + item.before.metadata.id + ")");

Expand All @@ -76,36 +75,20 @@ public void onBindViewHolder(@NonNull final ViewHolder holder, final int positio
int addition = 0;
int deletion = 0;

// Yeah i gotta make this dry, i'll do it later
// TODO: MAKE THIS DRY
if ((files_changed & SketchwareProjectChanges.LOGIC) == SketchwareProjectChanges.LOGIC) {
int[] res = Util.getAdditionAndDeletion(item.getPatch(SketchwareProjectChanges.LOGIC));
addition += res[0];
deletion += res[1];
}

if ((files_changed & SketchwareProjectChanges.VIEW) == SketchwareProjectChanges.VIEW) {
int[] res = Util.getAdditionAndDeletion(item.getPatch(SketchwareProjectChanges.VIEW));
addition += res[0];
deletion += res[1];
}

if ((files_changed & SketchwareProjectChanges.FILE) == SketchwareProjectChanges.FILE) {
int[] res = Util.getAdditionAndDeletion(item.getPatch(SketchwareProjectChanges.FILE));
addition += res[0];
deletion += res[1];
}

if ((files_changed & SketchwareProjectChanges.LIBRARY) == SketchwareProjectChanges.LIBRARY) {
int[] res = Util.getAdditionAndDeletion(item.getPatch(SketchwareProjectChanges.LIBRARY));
addition += res[0];
deletion += res[1];
}

if ((files_changed & SketchwareProjectChanges.RESOURCES) == SketchwareProjectChanges.RESOURCES) {
int[] res = Util.getAdditionAndDeletion(item.getPatch(SketchwareProjectChanges.RESOURCES));
addition += res[0];
deletion += res[1];
int[] data_keys = new int[] {
SketchwareProjectChanges.LOGIC ,
SketchwareProjectChanges.VIEW ,
SketchwareProjectChanges.FILE ,
SketchwareProjectChanges.LIBRARY ,
SketchwareProjectChanges.RESOURCES ,
};

for (int data_key: data_keys) {
if ((files_changed & data_key) == data_key) {
int[] res = Util.getAdditionAndDeletion(item.getPatch(data_key));
addition += res[0];
deletion += res[1];
}
}

holder.summary.setText("+" + addition + " -" + deletion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}

// Get the latest commit timestamp
CollectionReference commits = firestore.collection("projects").document(project.getId()).collection("commits");
Timestamp latest_commit_timestamp;

try {
QuerySnapshot latest_commit = Tasks.await(
commits
.orderBy("timestamp", Query.Direction.DESCENDING)
.limit(1)
.get()
);

latest_commit_timestamp = latest_commit.getDocuments().get(0).getTimestamp("timestamp");

} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
Toast.makeText(BrowseActivity.this, "Error while fetching latest commit: " + e.getMessage(), Toast.LENGTH_LONG).show();
return;
// Add backwards compatibility for the old ealry-alpha version
if (!project.contains("latest_commit_timestamp")) {
latest_commit_timestamp = Timestamp.now();
} else {
latest_commit_timestamp = project.getTimestamp("latest_commit_timestamp");
}

items.add(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package com.iyxan23.sketch.collab.online;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.Task;
import com.google.android.material.textfield.TextInputEditText;
import com.google.firebase.Timestamp;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.iyxan23.sketch.collab.R;
import com.iyxan23.sketch.collab.Util;
import com.iyxan23.sketch.collab.models.SketchwareProjectChanges;

import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -33,6 +38,7 @@ public class PushCommitActivity extends AppCompatActivity {

FirebaseFirestore firestore = FirebaseFirestore.getInstance();
CollectionReference commits;
DocumentReference project;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -46,6 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
String project_key = getIntent().getStringExtra("project_key");

commits = firestore.collection("projects/" + project_key + "/commits");
project = firestore.document("projects/" + project_key);

patch_text = findViewById(R.id.patch_push);

Expand All @@ -66,6 +73,8 @@ protected void onCreate(Bundle savedInstanceState) {
put("author", user_uid);
}};

Task<Void> update_last_commit_timestamp = project.update("latest_commit_timestamp", Timestamp.now());

try {
data.put("sha512sum", commit_change.after.sha512sum());
} catch (JSONException e) {
Expand All @@ -81,7 +90,8 @@ protected void onCreate(Bundle savedInstanceState) {
progressDialog.setIndeterminate(true);
progressDialog.show();

commits .add(data)
update_last_commit_timestamp
.continueWithTask(task -> commits.add(data))
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
// Update the project's local commit id
Expand Down Expand Up @@ -118,26 +128,27 @@ protected void onCreate(Bundle savedInstanceState) {
// Get the changed files
int files_changed = commit_change.getFilesChanged();

// Yeah i gotta make this dry, i'll do it later
// TODO: MAKE THIS DRY
if ((files_changed & SketchwareProjectChanges.LOGIC) == SketchwareProjectChanges.LOGIC) {
patch.put("logic", commit_change.getPatch(SketchwareProjectChanges.LOGIC));
}

if ((files_changed & SketchwareProjectChanges.VIEW) == SketchwareProjectChanges.VIEW) {
patch.put("view", commit_change.getPatch(SketchwareProjectChanges.VIEW));
}

if ((files_changed & SketchwareProjectChanges.FILE) == SketchwareProjectChanges.FILE) {
patch.put("file", commit_change.getPatch(SketchwareProjectChanges.FILE));
}

if ((files_changed & SketchwareProjectChanges.LIBRARY) == SketchwareProjectChanges.LIBRARY) {
patch.put("library", commit_change.getPatch(SketchwareProjectChanges.LIBRARY));
}

if ((files_changed & SketchwareProjectChanges.RESOURCES) == SketchwareProjectChanges.RESOURCES) {
patch.put("resources", commit_change.getPatch(SketchwareProjectChanges.RESOURCES));
// Pack every patches into one map
int[] data_keys = new int[] {
SketchwareProjectChanges.LOGIC ,
SketchwareProjectChanges.VIEW ,
SketchwareProjectChanges.FILE ,
SketchwareProjectChanges.LIBRARY ,
SketchwareProjectChanges.RESOURCES ,
};

String[] data_keys_str = new String[] {
"logic" ,
"view" ,
"file" ,
"library" ,
"resources" ,
};

for (int index = 0; index < data_keys.length; index++) {
if ((files_changed & data_keys[index]) == data_keys[index]) {
patch.put(data_keys_str[index], commit_change.getPatch(data_keys[index]));
}
}

// Alright, patch is ready!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
put("author", auth.getUid());
put("version", 1);
put("open", isOpenSource.isChecked());
put("latest_commit_timestamp", Timestamp.now());
}};

try {
Expand Down

0 comments on commit 4555505

Please sign in to comment.