Skip to content

Commit e6de6aa

Browse files
committed
Version 0.9:
* Fixed a Bunch of Bugs * Updated Gradle Dependencies (where possible) * Tweaked the GUI to not look as terrible... * Improved Searching and Match Algorithm * Result Sorting Based on Accuracy
1 parent 0d0b35e commit e6de6aa

21 files changed

+349
-378
lines changed

.idea/dictionaries/paul.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ android {
2323
}
2424
buildTypes.each {
2525
// INSERT THE GOOGLE CLOUD API KEY BELOW (Instead of "AIza..."):
26-
it.buildConfigField 'String', 'API_KEY', '"AIzaSyCbt2d9aEVwJylEQKw-Kuv7sbdt83oYVys"'
26+
it.buildConfigField 'String', 'API_KEY', '"AIzaSyD-VCuixZVo-YP0_m0T09VDxBjA0Ab-xnI"'
2727
}
2828
}
2929
compileOptions {
@@ -41,22 +41,22 @@ android {
4141

4242
dependencies {
4343

44-
implementation 'androidx.appcompat:appcompat:1.1.0'
45-
implementation 'com.google.android.material:material:1.1.0'
46-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
47-
implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'
48-
implementation 'com.android.support:support-annotations:27.0.2'
44+
implementation 'androidx.appcompat:appcompat:1.2.0'
45+
implementation 'com.google.android.material:material:1.3.0'
46+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
47+
implementation 'com.google.apis:google-api-services-vision:v1-rev9-1.21.0'
48+
implementation 'com.android.support:support-annotations:28.0.0'
4949

5050
implementation 'androidx.annotation:annotation:1.1.0'
51-
implementation "androidx.core:core-ktx:+"
52-
implementation 'com.android.support:design:27.0.2'
53-
compile 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
54-
compile 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
55-
implementation 'com.opencsv:opencsv:4.6'
51+
implementation 'androidx.core:core-ktx:1.3.2'
52+
//implementation 'com.android.support:design:28.0.0' //Turns out we don't use this!
53+
implementation 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
54+
implementation 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
55+
implementation 'com.opencsv:opencsv:5.3'
5656
implementation 'com.android.support:recyclerview-v7:28.0.0'
5757

5858

59-
testImplementation 'junit:junit:4.+'
60-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
61-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
59+
testImplementation 'junit:junit:4.13.2'
60+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
61+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
6262
}

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!--Sortify App, Created 13/03/2021 -->
3+
<!--Made by Paul & Abdul -->
4+
<!--for Google's 2021 Solution Challenge-->
5+
26
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
37
package="google.sc21.sortify">
48
<!-- This Ensures that Only Devices with a Camera can Download our App -->
@@ -15,7 +19,7 @@
1519
android:roundIcon="@mipmap/ic_launcher_round"
1620
android:supportsRtl="true"
1721
android:theme="@style/Theme.Sortify">
18-
<activity android:name=".ExploreActivity"></activity>
22+
<activity android:name=".ExploreActivity" />
1923
<activity android:name=".MainActivity">
2024
<intent-filter>
2125
<action android:name="android.intent.action.MAIN" />

app/src/main/assets/recyclable.csv

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

app/src/main/java/google/sc21/sortify/ExploreActivity.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package google.sc21.sortify;
22

33
import androidx.appcompat.app.AppCompatActivity;
4+
import androidx.recyclerview.widget.DividerItemDecoration;
45
import androidx.recyclerview.widget.LinearLayoutManager;
56
import androidx.recyclerview.widget.RecyclerView;
67

78
import android.content.Context;
89
import android.content.Intent;
910
import android.graphics.Bitmap;
1011
import android.os.Bundle;
11-
import android.util.Log;
1212
import android.view.View;
13-
import android.view.ViewGroup;
1413
import android.widget.ImageView;
1514
import android.widget.Toast;
1615

@@ -31,34 +30,8 @@ public class ExploreActivity extends AppCompatActivity implements MyRecyclerView
3130
private static RecyclerView exploreList;
3231
private static ImageView junkPhoto;
3332
private static Context context;
34-
private static List<Junk> referenceDataSet;
3533

3634

37-
@Override
38-
protected void onCreate(Bundle savedInstanceState) {
39-
super.onCreate(savedInstanceState);
40-
setContentView(R.layout.activity_explore);
41-
junkPhoto = findViewById(R.id.junkView);
42-
exploreList = findViewById(R.id.junkListView);
43-
ExploreActivity.context = getApplicationContext();
44-
45-
List<Junk> template = new ArrayList<>();
46-
List<String> empty = new LinkedList<String>();
47-
template.add(new Junk("Please Wait...",empty,"",""));
48-
49-
exploreList.setLayoutManager(new LinearLayoutManager(this));
50-
adapter = new MyRecyclerViewAdapter(this, template);
51-
adapter.setClickListener(this);
52-
exploreList.setAdapter(adapter);
53-
54-
Intent intent = getIntent();
55-
String mode = intent.getStringExtra("mode");
56-
if (mode.equals("discover")) {
57-
junkPhoto.setVisibility(View.GONE);
58-
loadData(importDataset());
59-
}
60-
}
61-
6235

6336
public static void loadData(List<Junk> data) {
6437
exploreList.setLayoutManager(new LinearLayoutManager(ExploreActivity.context));
@@ -98,4 +71,33 @@ private List<Junk> importDataset() {
9871
return referenceData;
9972
}
10073
//endregion
74+
75+
76+
77+
@Override
78+
protected void onCreate(Bundle savedInstanceState) {
79+
super.onCreate(savedInstanceState);
80+
setContentView(R.layout.activity_explore);
81+
junkPhoto = findViewById(R.id.junkView);
82+
exploreList = findViewById(R.id.junkListView);
83+
ExploreActivity.context = getApplicationContext();
84+
85+
List<Junk> template = new ArrayList<>();
86+
List<String> empty = new LinkedList<String>();
87+
template.add(new Junk("Please Wait...",empty,"",""));
88+
89+
exploreList.setLayoutManager(new LinearLayoutManager(this));
90+
adapter = new MyRecyclerViewAdapter(this, template);
91+
adapter.setClickListener(this);
92+
exploreList.setAdapter(adapter);
93+
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(exploreList.getContext(), LinearLayoutManager.VERTICAL);
94+
exploreList.addItemDecoration(dividerItemDecoration);
95+
96+
Intent intent = getIntent();
97+
String mode = intent.getStringExtra("mode");
98+
if (mode.equals("discover")) {
99+
junkPhoto.setVisibility(View.GONE);
100+
loadData(importDataset());
101+
}
102+
}
101103
}
Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package google.sc21.sortify;
22

3-
import java.io.Serializable;
43
import java.util.LinkedList;
54
import java.util.List;
65
import java.util.Scanner;
76

87
public class Junk {
98
private String name;
10-
private List<String> aliases = new LinkedList<String>();
9+
private List<String> aliases = new LinkedList<>();
1110
private String guidance;
1211
private String link;
12+
private float accuracy;
1313

1414
public Junk(String junkName, List<String> junkAliases, String junkGuidance, String junkURL) {
1515
name = junkName;
@@ -24,43 +24,83 @@ public static Junk newItemFromCSV(Scanner scanner) {
2424
item.name = scanner.next();
2525
item.link = scanner.next();
2626
String temp = scanner.next().toLowerCase();
27-
if (temp != null) {
28-
item.aliases.add(temp);
29-
if (item.aliases != null && item.aliases.get(0).contains("\"")) {
30-
item.aliases.set(0,item.aliases.get(0).substring(1));
27+
item.aliases.add(temp);
28+
if (item.aliases != null && item.aliases.get(0).contains("\"")) {
29+
item.aliases.set(0,item.aliases.get(0).substring(1));
30+
item.aliases.add(scanner.next().toLowerCase());
31+
while (!(item.aliases.get(item.aliases.size() - 1).contains("\""))) {
3132
item.aliases.add(scanner.next().toLowerCase());
32-
while (!(item.aliases.get(item.aliases.size() - 1).contains("\""))) {
33-
item.aliases.add(scanner.next().toLowerCase());
34-
}
35-
item.aliases.set((item.aliases.size() - 1),item.aliases.get(item.aliases.size() - 1).substring(0, item.aliases.get(item.aliases.size() - 1).length()-1));
3633
}
34+
item.aliases.set((item.aliases.size() - 1),item.aliases.get(item.aliases.size() - 1).substring(0, item.aliases.get(item.aliases.size() - 1).length()-1));
3735
}
3836
temp = scanner.next().toLowerCase();
39-
if (temp != null) {
40-
item.guidance = temp;
41-
if (item.guidance != null && item.guidance.contains("\"")) {
42-
item.guidance = item.guidance.substring(1);
43-
item.guidance = item.guidance + scanner.next();
44-
while (!(item.guidance.contains("\""))) {
45-
item.guidance = item.guidance + scanner.next();
46-
}
47-
item.guidance = item.guidance.substring(0, (item.guidance.length()-1));
37+
item.guidance = temp;
38+
if (item.guidance.contains("\"")) {
39+
item.guidance = item.guidance.substring(1);
40+
item.guidance = item.guidance + scanner.next();
41+
while (!(item.guidance.contains("\""))) {
42+
item.guidance += scanner.next();
4843
}
44+
item.guidance = item.guidance.substring(0, (item.guidance.length()-1));
4945
}
46+
item.accuracy = 0;
5047
return item;
5148
}
5249

53-
public boolean matches(String label) {
54-
if (name.toLowerCase().contains(label.toLowerCase()) || aliases.contains(label.toLowerCase())) {
55-
return true;
56-
} else {
57-
return false;
50+
// Returns how accurate the match is
51+
public float matches(String label) {
52+
String input = label.toLowerCase();
53+
float accuracy = 0;
54+
char[] inputArray = input.toCharArray();
55+
if (name.toLowerCase().contains(input)) {
56+
int matchingLetters = 0;
57+
char[] compareArray = name.toLowerCase().toCharArray();
58+
int startPosition = name.toLowerCase().indexOf(input);
59+
int compareLength = name.length();
60+
int inputPosition = 0;
61+
int comparePosition = startPosition;
62+
boolean stillMatches = true;
63+
while (stillMatches && comparePosition < compareLength && inputPosition < input.length()) {
64+
if (inputArray[inputPosition] == compareArray[comparePosition]) {
65+
matchingLetters++;
66+
} else {
67+
stillMatches = false;
68+
}
69+
comparePosition++;
70+
inputPosition++;
71+
}
72+
accuracy = (float)matchingLetters/(float)compareLength;
73+
} else if (aliases.contains(input)) {
74+
for (int alias=0; alias < aliases.size(); alias++) {
75+
int matchingLetters = 0;
76+
char[] compareArray = aliases.get(alias).toCharArray();
77+
int startPosition = aliases.get(alias).indexOf(input);
78+
int compareLength = aliases.get(alias).length();
79+
int inputPosition = 0;
80+
int comparePosition = startPosition;
81+
boolean stillMatches = true;
82+
while (stillMatches && comparePosition < compareLength && inputPosition < input.length()) {
83+
if (inputArray[inputPosition] == compareArray[comparePosition]) {
84+
matchingLetters++;
85+
} else {
86+
stillMatches = false;
87+
}
88+
inputPosition++;
89+
comparePosition++;
90+
}
91+
if (matchingLetters/aliases.get(alias).length() > accuracy) {
92+
accuracy = (float)matchingLetters/(float)compareLength;
93+
}
94+
}
5895
}
96+
return accuracy;
5997
}
6098

6199
public String returnName() {return name;}
62100
public List<String> returnAliases() {return aliases;}
63-
public String returnInfo() {return guidance;
64-
}
101+
public String returnInfo() {return guidance;}
102+
public void setAccuracy(float value) {accuracy = value;}
103+
public float returnAccurcay() {return accuracy;}
104+
65105

66106
}

0 commit comments

Comments
 (0)