Skip to content
Snippets Groups Projects
Commit c6405c8e authored by Francesco's avatar Francesco
Browse files

updated CompareString to 1.4.1

parent 94fd438e
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ android {
dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.github.Andre1299:CompareString:1.4'
compile 'com.github.Andre1299:CompareString:1.4.1'
compile 'commons-io:commons-io:2.4'
}
......
......@@ -23,6 +23,11 @@ public class search implements CommandAbstraction {
private final int FILE = 12;
private final int YOUTUBE = 13;
private final String YOUTUBE_PREFIX = "https://www.youtube.com/results?search_query=";
private final String GOOGLE_PREFIX = "http://www.google.com/#q=";
private final String PLAYSTORE_PREFIX = "market://search?q=";
private final String PLAYSTORE_BROWSER_PREFIX = "https://play.google.com/store/search?q=";
private final String PLAYSTORE_PARAM = "-p";
private final String FILE_PARAM = "-f";
private final String GOOGLE_PARAM = "-g";
......@@ -64,35 +69,35 @@ public class search implements CommandAbstraction {
private String google(List<String> args, Context c, Resources res) {
String toSearch = Tuils.toPlanString(args, "+");
Uri uri = Uri.parse("http://www.google.com/#q=" + toSearch);
Uri uri = Uri.parse(GOOGLE_PREFIX + toSearch);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
c.startActivity(intent);
return res.getString(R.string.output_searchinggoogle) + " " + flat(args);
return res.getString(R.string.output_searchinggoogle) + Tuils.SPACE + flat(args);
}
private String playstore(List<String> args, Context c, Resources res) {
String toSearch = Tuils.toPlanString(args, "%20");
try {
c.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=" + toSearch)));
c.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(PLAYSTORE_PREFIX + toSearch)));
} catch (android.content.ActivityNotFoundException anfe) {
c.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/search?q=" + toSearch)));
c.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(PLAYSTORE_BROWSER_PREFIX + toSearch)));
}
return res.getString(R.string.output_searchingplaystore) + " " + flat(args);
}
private String file(List<String> args, File cd, Resources res) {
String header = res.getString(R.string.output_search_file) + " " + cd.getAbsolutePath();
String header = res.getString(R.string.output_search_file) + Tuils.SPACE + cd.getAbsolutePath();
String name = Tuils.toPlanString(args);
String found = Tuils.toPlanString(rightPaths(cd, name, FileManager.USE_SCROLL_COMPARE), "\n");
if (found.length() > 1)
return header.concat("\n" + found);
return header.concat(Tuils.NEWLINE + found);
else
return header.concat("\n" + res.getString(R.string.output_nothing_found));
return header.concat(Tuils.NEWLINE + res.getString(R.string.output_nothing_found));
}
private List<String> rightPaths(File dir, String name, boolean scrollCompare) {
......@@ -116,24 +121,24 @@ public class search implements CommandAbstraction {
private boolean fileMatch(File f, String name, boolean scrollCompare) {
if (scrollCompare)
return Compare.scrollCompareTwoStrings(f.getName(), name) >= MIN_FILE_RATE;
return Compare.scrollComparison(f.getName(), name) >= MIN_FILE_RATE;
else
return Compare.linearCompareTwoStrings(f.getName(), name) >= MIN_FILE_RATE;
return Compare.linearComparison(f.getName(), name) >= MIN_FILE_RATE;
}
private String youTube(List<String> args, Context c, Resources res) {
String toSearch = Tuils.toPlanString(args, "+");
Uri uri = Uri.parse("https://www.youtube.com/results?search_query=" + toSearch);
Uri uri = Uri.parse(YOUTUBE_PREFIX + toSearch);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
c.startActivity(intent);
return res.getString(R.string.output_search_youtube) + " " + flat(args);
return res.getString(R.string.output_search_youtube) + Tuils.SPACE + flat(args);
}
private String flat(List<String> args) {
String flat = "";
for (String s : args)
flat = flat.concat(s + " ");
flat = flat.concat(s + Tuils.SPACE);
return flat;
}
......
......@@ -114,7 +114,7 @@ public class AppsManager {
// find a package using its public label
// notice that it can be an app or an hidden app (depends on appList parameter)
public String findPackage(Set<AppInfo> appList, String name) {
String label = Compare.getOneSimilarString(labelSet(appList), name, MIN_RATE, USE_SCROLL_COMPARE);
String label = Compare.similarString(labelSet(appList), name, MIN_RATE, USE_SCROLL_COMPARE);
if (label == null)
return null;
......
......@@ -56,7 +56,7 @@ public class ContactManager {
Map<String, String> contacts = getContacts();
Set<String> names = contacts.keySet();
String mostSuitable = Compare.getOneSimilarString(names, name, minRate, USE_SCROLL_COMPARE);
String mostSuitable = Compare.similarString(names, name, minRate, USE_SCROLL_COMPARE);
return mostSuitable == null ? null : contacts.get(mostSuitable);
}
}
......@@ -54,7 +54,7 @@ public class MusicManager implements OnCompletionListener {
// return a song by incomplete name
public String getSong(String s, int minRate) {
return Compare.getOneSimilarString(getNames(), s, minRate, USE_SCROLL_COMPARE);
return Compare.similarString(getNames(), s, minRate, USE_SCROLL_COMPARE);
}
// return the path by complete name
......
......@@ -11,7 +11,6 @@ import ohi.andre.consolelauncher.commands.Command;
import ohi.andre.consolelauncher.commands.CommandAbstraction;
import ohi.andre.consolelauncher.commands.CommandTuils;
import ohi.andre.consolelauncher.commands.ExecInfo;
import ohi.andre.consolelauncher.tuils.Tuils;
/**
* Created by francescoandreuzzi on 25/12/15.
......@@ -36,8 +35,8 @@ public class SuggestionsManager {
List<Compare.CompareInfo> suggestionList = new ArrayList<>();
before = Tuils.trimSpaces(before);
lastWord = Tuils.trimSpaces(lastWord);
before = before.trim();
lastWord = lastWord.trim();
// lastword = 0
if (lastWord.length() == 0) {
......@@ -168,7 +167,7 @@ public class SuggestionsManager {
FileManager.DirInfo dirInfo = FileManager.cd(info.currentDirectory, prev);
if (dirInfo.file.isDirectory()) {
prev = prev.substring(prev.indexOf(File.separator) + 1);
Compare.getCompareInfo(suggestions, dirInfo.file.list(), prev, MIN_FILE_RATE, FileManager.USE_SCROLL_COMPARE);
Compare.compareInfo(suggestions, dirInfo.file.list(), prev, MIN_FILE_RATE, FileManager.USE_SCROLL_COMPARE);
}
}
}
......@@ -179,7 +178,7 @@ public class SuggestionsManager {
for (String s : info.contacts.names())
suggestions.add(new Compare.CompareInfo(s, -1));
} else
Compare.getCompareInfo(suggestions, info.contacts.names(), prev, MIN_CONTACTS_RATE, ContactManager.USE_SCROLL_COMPARE);
Compare.compareInfo(suggestions, info.contacts.names(), prev, MIN_CONTACTS_RATE, ContactManager.USE_SCROLL_COMPARE);
}
private static void suggestSong(ExecInfo info, List<Compare.CompareInfo> suggestions, String prev) {
......@@ -187,7 +186,7 @@ public class SuggestionsManager {
for (String s : info.player.getNames())
suggestions.add(new Compare.CompareInfo(s, -1));
} else
Compare.getCompareInfo(suggestions, info.player.getNames(), prev, MIN_SONGS_RATE, MusicManager.USE_SCROLL_COMPARE);
Compare.compareInfo(suggestions, info.player.getNames(), prev, MIN_SONGS_RATE, MusicManager.USE_SCROLL_COMPARE);
}
// help...
......@@ -197,7 +196,7 @@ public class SuggestionsManager {
return;
}
Compare.getCompareInfo(suggestions, info.commandGroup.getCommands(), prev, MIN_COMMAND_RATE, false);
Compare.compareInfo(suggestions, info.commandGroup.getCommands(), prev, MIN_COMMAND_RATE, false);
}
// use when suggesting random commands
......@@ -219,7 +218,7 @@ public class SuggestionsManager {
for (String s : info.appsManager.getAppsLabels())
suggestions.add(new Compare.CompareInfo(s, -1));
} else
Compare.getCompareInfo(suggestions, info.appsManager.getAppsLabels(), prev, MIN_APPS_RATE, AppsManager.USE_SCROLL_COMPARE);
Compare.compareInfo(suggestions, info.appsManager.getAppsLabels(), prev, MIN_APPS_RATE, AppsManager.USE_SCROLL_COMPARE);
}
private static void suggestFilesInDir(List<Compare.CompareInfo> suggestions, File dir, String prev) {
......@@ -231,7 +230,7 @@ public class SuggestionsManager {
return;
}
Compare.getCompareInfo(suggestions, dir.list(), prev, MIN_FILE_RATE, FileManager.USE_SCROLL_COMPARE);
Compare.compareInfo(suggestions, dir.list(), prev, MIN_FILE_RATE, FileManager.USE_SCROLL_COMPARE);
}
private static void suggestFilesInDir(List<Compare.CompareInfo> suggestions, File dir) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment