Skip to content

Commit

Permalink
Release alpha 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
iyxan23 committed Feb 11, 2021
2 parents 4555505 + 81a2896 commit ad5e048
Show file tree
Hide file tree
Showing 30 changed files with 1,860 additions and 153 deletions.
8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionName "0.1-alpha"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -34,12 +34,16 @@ android {

dependencies {
implementation platform('com.google.firebase:firebase-bom:26.1.1')

// Firebase common libraries
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'

// other stuff
implementation 'org.jetbrains:annotations:16.0.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
Expand Down Expand Up @@ -60,9 +59,11 @@
<activity
android:name=".online.BrowseCodeActivity"
android:theme="@style/Theme.SketchCollab.NoActionBar" />
<activity
android:name=".pickers.UserPicker"
android:theme="@style/Theme.SketchCollab.NoActionBar" />

<service
android:name=".services.CloneService" />
<service android:name=".services.CloneService" />
</application>

</manifest>
194 changes: 194 additions & 0 deletions app/src/main/java/com/iyxan23/sketch/collab/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextWatcher;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
Expand All @@ -24,17 +32,24 @@
import com.google.firebase.firestore.QuerySnapshot;
import com.google.firebase.firestore.Source;
import com.iyxan23.sketch.collab.adapters.ChangesAdapter;
import com.iyxan23.sketch.collab.adapters.SearchAdapter;
import com.iyxan23.sketch.collab.models.SearchItem;
import com.iyxan23.sketch.collab.models.SketchwareProject;
import com.iyxan23.sketch.collab.models.SketchwareProjectChanges;
import com.iyxan23.sketch.collab.online.BrowseActivity;

import org.json.JSONException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";

// List of local projects
ArrayList<SketchwareProject> localProjects = new ArrayList<>();

Expand Down Expand Up @@ -238,16 +253,28 @@ private void initialize() {

assert snapshot != null; // snapshot shouldn't be null

Log.d("MainActivity", "documents: " + snapshot.getDocuments());
Log.d("MainActivity", "project_key: " + project_key);

// Check if the project doesn't exists in the database.
if (snapshot.getDocuments().size() == 0) continue;

DocumentSnapshot commit_info = snapshot.getDocuments().get(0);

if (!project_commit.equals(commit_info.getId())) {
// Hmm, looks like this man's project has an older commit, tell him to update his project
Log.d(TAG, "initialize: Old Commit");
} else {
Log.d(TAG, "initialize: Latest commit");
// This mans project has the same commit
// Check if this project also has the same shasum
String local_shasum = project.sha512sum();
String server_shasum = commit_info.getString("sha512sum");

Log.d(TAG, "initialize: Checking shasum");
Log.d(TAG, "shasum local: " + local_shasum);
Log.d(TAG, "shasum server: " + server_shasum);

// Check if they're the same
if (!local_shasum.equals(server_shasum)) {
// Alright looks like he's got some local updates with the same head commit
Expand Down Expand Up @@ -288,4 +315,171 @@ private void initialize() {
}
}).start();
}

// THE SEARCH / COMMANDS THING =================================================================

boolean isOpened = false;

SearchAdapter s_adapter;
ArrayList<SearchItem> s_items;
RecyclerView s_rv;
EditText s_edittext;

HashMap<String, Integer> index = new HashMap<>();

String[] commands = new String[] {
"upload", // goes to UploadActivity
"local", // goes to ViewLocalProjectActivity (soon)
"open", // goes to ViewOnlineProjectActivity
"browse", // goes to BrowseActivity
"show code", // goes to BrowseCodeActivity
"commits" // goes to CommitsActivity
};

/* Syntaxes:
*
* upload (project name)
* local
* open (project name)
* browse
* show code (project name)
* commits (project name)
*/

public void search_button_click(View view) {
s_edittext = findViewById(R.id.search_edittext);

View settings_button = findViewById(R.id.imageView);
View home_textview = findViewById(R.id.home_textview);
View search_autocomplete_layout = findViewById(R.id.inc_search);
View main_content = findViewById(R.id.scrollView2);

s_rv = findViewById(R.id.search_rv);

if (isOpened) {
// Do a search
} else {
// Open the thing
settings_button.setVisibility(View.GONE);
home_textview.setVisibility(View.GONE);
s_edittext.setVisibility(View.VISIBLE);
search_autocomplete_layout.setVisibility(View.VISIBLE);
main_content.setVisibility(View.GONE);

// Initialize some stuff
s_items = new ArrayList<>();
for (String item: commands) {
s_items.add(new SearchItem(item));
}

// Index localProjects to be a HashMap<String: Name, Integer: id>
// Oh yeah, we're including project name and app name
new Thread(() -> {
for (SketchwareProject project : localProjects) {
if (project.metadata == null)
continue;

index.put(project.metadata.project_name, project.metadata.id);
index.put(project.metadata.app_name, project.metadata.id);
}
}).start();

s_adapter = new SearchAdapter(s_items, this);

s_rv.setAdapter(s_adapter);
s_rv.setLayoutManager(new LinearLayoutManager(this));

s_edittext.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }

@Override
public void afterTextChanged(Editable s) { }

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
update_rv(s.toString());
}
});
}
}

private void update_rv(String input) {
s_items.clear();

Pattern pattern = Pattern.compile(input);

for (String command: commands) {
boolean matched = false;

Matcher m = pattern.matcher(command);

SpannableString command_s = new SpannableString(command);
while (m.find()) {
matched = true;
command_s.setSpan(
new StyleSpan(Typeface.BOLD),
m.start(),
m.end(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE
);
}

if (matched)
s_items.add(new SearchItem(command_s, "Command"));
}

s_adapter.updateView(s_items);

// Find in local project(s)
for (String name: index.keySet()) {
boolean matched = false;

Matcher m = pattern.matcher(name);

SpannableString name_s = new SpannableString(name);
while (m.find()) {
matched = true;
name_s.setSpan(
new StyleSpan(Typeface.BOLD),
m.start(),
m.end(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE
);
}

if (matched)
s_items.add(new SearchItem(name_s, "Open Local Project"));
}

s_adapter.updateView(s_items);

// TODO: ADD PUBLIC PROJECTS FUNCTIONALITY
}

@Override
public void onBackPressed() {
s_edittext = findViewById(R.id.search_edittext);

View settings_button = findViewById(R.id.imageView);
View home_textview = findViewById(R.id.home_textview);
View search_autocomplete_layout = findViewById(R.id.inc_search);
View main_content = findViewById(R.id.scrollView2);

if (isOpened) {
// Close the search thing
settings_button.setVisibility(View.VISIBLE);
home_textview.setVisibility(View.VISIBLE);
s_edittext.setVisibility(View.GONE);
search_autocomplete_layout.setVisibility(View.GONE);
main_content.setVisibility(View.VISIBLE);

// Clear some stuff to reduce the memory usage
s_items.clear();
index.clear();

} else {
super.onBackPressed();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.firebase.Timestamp;
import com.google.firebase.firestore.DocumentSnapshot;
import com.iyxan23.sketch.collab.R;
Expand Down Expand Up @@ -79,13 +80,61 @@ public void onBindViewHolder(@NonNull final ViewHolder holder, final int positio
// https://stackoverflow.com/questions/11275034/android-calculating-minutes-hours-days-from-point-in-time
CharSequence relativeTimeStr =
DateUtils.getRelativeTimeSpanString(
item.timestamp.getSeconds() * 1000,
item.timestamp.getNanoseconds() / 1000,
System.currentTimeMillis(),

DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE
);

holder.timestamp.setText(relativeTimeStr);

holder.body.setOnClickListener(v -> {
// Show a bottomsheet
View bottom_sheet_view = LayoutInflater
.from(v.getContext())
.inflate(R.layout.bottomsheet_commit, null);

BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(v.getContext());

TextView title = bottom_sheet_view.findViewById(R.id.commit_title);
TextView author = bottom_sheet_view.findViewById(R.id.commit_author);
TextView code = bottom_sheet_view.findViewById(R.id.patch_code);
TextView time = bottom_sheet_view.findViewById(R.id.commit_time);

title.setText(item.name);
author.setText(item.author_username + " (Commit ID: " + item.id + ")");

StringBuilder patch = new StringBuilder();

// Check if this commit doesn't have any commits
if (item.patch != null) {
for (String key : item.patch.keySet()) {
Log.d(TAG, "onBindViewHolder: key: " + key + " | patch: " + item.patch.get(key));

patch.append(key).append(":\n").append(item.patch.get(key));
}

} else {
patch.append("This commit doesn't have any patch");
}

Log.d(TAG, "onBindViewHolder: result: " + patch.toString());

code.setText(patch.toString());

CharSequence relativeTimeStr_ =
DateUtils.getRelativeTimeSpanString(
item.timestamp.getNanoseconds() / 1000,
System.currentTimeMillis(),

DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE
);

time.setText(relativeTimeStr_);

bottomSheetDialog.setContentView(bottom_sheet_view);
bottomSheetDialog.show();
});
}

@Override
Expand Down
Loading

0 comments on commit ad5e048

Please sign in to comment.