Skip to content

Commit

Permalink
Indentation and linting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Neamar committed Aug 2, 2016
1 parent 6379ef2 commit a8176d4
Show file tree
Hide file tree
Showing 54 changed files with 319 additions and 333 deletions.
16 changes: 8 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@
</intent-filter>
</receiver>

<service android:name=".dataprovider.AliasProvider"/>
<service android:name=".dataprovider.AppProvider"/>
<service android:name=".dataprovider.ContactsProvider"/>
<service android:name=".dataprovider.PhoneProvider"/>
<service android:name=".dataprovider.SearchProvider"/>
<service android:name=".dataprovider.SettingsProvider"/>
<service android:name=".dataprovider.ShortcutsProvider"/>
<service android:name=".dataprovider.TogglesProvider"/>
<service android:name=".dataprovider.AliasProvider" />
<service android:name=".dataprovider.AppProvider" />
<service android:name=".dataprovider.ContactsProvider" />
<service android:name=".dataprovider.PhoneProvider" />
<service android:name=".dataprovider.SearchProvider" />
<service android:name=".dataprovider.SettingsProvider" />
<service android:name=".dataprovider.ShortcutsProvider" />
<service android:name=".dataprovider.TogglesProvider" />
</application>

</manifest>
87 changes: 40 additions & 47 deletions app/src/main/java/fr/neamar/kiss/DataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.widget.Toast;

import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -49,12 +48,6 @@ public class DataHandler extends BroadcastReceiver
private Map<String, ProviderEntry> providers = new HashMap<>();
private boolean providersReady = false;

protected class ProviderEntry {
public IProvider provider = null;
public ServiceConnection connection = null;
}


/**
* Initialize all providers
*/
Expand All @@ -75,19 +68,19 @@ public DataHandler(Context context) {
prefs.registerOnSharedPreferenceChangeListener(this);

// Connect to initial providers
for(String providerName : PROVIDER_NAMES) {
if(prefs.getBoolean("enable-" + providerName, true)) {
for (String providerName : PROVIDER_NAMES) {
if (prefs.getBoolean("enable-" + providerName, true)) {
this.connectToProvider(providerName);
}
}
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.startsWith("enable-")) {
if (key.startsWith("enable-")) {
String providerName = key.substring(7);
if(PROVIDER_NAMES.contains(providerName)) {
if(sharedPreferences.getBoolean(key, true)) {
if (PROVIDER_NAMES.contains(providerName)) {
if (sharedPreferences.getBoolean(key, true)) {
this.connectToProvider(providerName);
} else {
this.disconnectFromProvider(providerName);
Expand Down Expand Up @@ -126,13 +119,13 @@ protected Intent providerName2Intent(String name) {
*/
protected void connectToProvider(final String name) {
// Do not continue if this provider has already been connected to
if(this.providers.containsKey(name)) {
if (this.providers.containsKey(name)) {
return;
}

// Find provider class for the given service name
Intent intent = this.providerName2Intent(name);
if(intent == null) {
if (intent == null) {
return;
}

Expand Down Expand Up @@ -176,7 +169,7 @@ public void onServiceDisconnected(ComponentName arg0) {
protected void disconnectFromProvider(String name) {
// Skip already disconnected services
ProviderEntry entry = this.providers.get(name);
if(entry == null) {
if (entry == null) {
return;
}

Expand All @@ -190,19 +183,18 @@ protected void disconnectFromProvider(String name) {
this.providers.remove(name);
}


/**
* Called when some event occurred that makes us believe that all data providers
* might be ready now
*/
private void handleProviderLoaded() {
if(this.providersReady) {
if (this.providersReady) {
return;
}

// Make sure that all providers are fully connected
for (ProviderEntry entry : this.providers.values()) {
if(entry.provider == null || !entry.provider.isLoaded()) {
if (entry.provider == null || !entry.provider.isLoaded()) {
return;
}
}
Expand All @@ -219,25 +211,22 @@ private void handleProviderLoaded() {
this.providersReady = true;
}


@Override
public void onReceive(Context context, Intent intent) {
this.handleProviderLoaded();
}


/**
* Reload all currently used data providers
*/
public void reloadAll() {
for(ProviderEntry entry : this.providers.values()) {
if(entry.provider != null && entry.provider.isLoaded()) {
for (ProviderEntry entry : this.providers.values()) {
if (entry.provider != null && entry.provider.isLoaded()) {
entry.provider.reload();
}
}
}


/**
* Get records for this query.
*
Expand All @@ -262,10 +251,10 @@ public ArrayList<Pojo> getResults(Context context, String query) {
ArrayList<Pojo> allPojos = new ArrayList<>();

for (ProviderEntry entry : this.providers.values()) {
if(entry.provider != null) {
if (entry.provider != null) {
// Retrieve results for query:
List<Pojo> pojos = entry.provider.getResults(query);

// Add results to list
for (Pojo pojo : pojos) {
// Give a boost if item was previously selected for this query
Expand All @@ -289,9 +278,9 @@ public ArrayList<Pojo> getResults(Context context, String query) {
* May return an empty set if the providers are not done building records,
* in this case it is probably a good idea to call this function 500ms after
*
* @param context android context
* @param itemCount max number of items to retrieve, total number may be less (search or calls are not returned for instance)
* @param smartHistory Recency vs Frecency
* @param context android context
* @param itemCount max number of items to retrieve, total number may be less (search or calls are not returned for instance)
* @param smartHistory Recency vs Frecency
* @param itemsToExclude Items to exclude from history
* @return pojos in recent history
*/
Expand All @@ -308,14 +297,14 @@ public ArrayList<Pojo> getHistory(Context context, int itemCount, boolean smartH
if (pojo != null) {
//Look if the pojo should get excluded
boolean exclude = false;
for(int j = 0; j < itemsToExclude.size(); j++){
if(itemsToExclude.get(j).id == pojo.id) {
for (int j = 0; j < itemsToExclude.size(); j++) {
if (itemsToExclude.get(j).id == pojo.id) {
exclude = true;
break;
}
}

if(!exclude){
if (!exclude) {
history.add(pojo);
}
}
Expand All @@ -327,46 +316,45 @@ public ArrayList<Pojo> getHistory(Context context, int itemCount, boolean smartH
public int getHistoryLength() {
return DBHelper.getHistoryLength(this.context);
}

public void addShortcut(ShortcutsPojo shortcut) {
ShortcutRecord record = new ShortcutRecord();
record.name = shortcut.name;
record.iconResource = shortcut.resourceName;
record.packageName = shortcut.packageName;
record.intentUri = shortcut.intentUri;
if (shortcut.icon != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
shortcut.icon.compress(CompressFormat.PNG,100,baos);
record.icon_blob = baos.toByteArray();
}

if (shortcut.icon != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
shortcut.icon.compress(CompressFormat.PNG, 100, baos);
record.icon_blob = baos.toByteArray();
}

DBHelper.insertShortcut(this.context, record);

if(this.getShortcutsProvider() != null) {
if (this.getShortcutsProvider() != null) {
this.getShortcutsProvider().reload();
}

Toast.makeText(context, R.string.shortcut_added, Toast.LENGTH_SHORT).show();
}

public void removeShortcut(ShortcutsPojo shortcut) {
DBHelper.removeShortcut(this.context, shortcut.name);

if(this.getShortcutsProvider() != null) {
if (this.getShortcutsProvider() != null) {
this.getShortcutsProvider().reload();
}
}

public void removeShortcuts(String packageName) {
DBHelper.removeShortcuts(this.context, packageName);

if(this.getShortcutsProvider() != null) {
if (this.getShortcutsProvider() != null) {
this.getShortcutsProvider().reload();
}
}


public void removeFromExcluded(String packageName) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context);
String excluded = prefs.getString("excluded-apps-list", context.getPackageName() + ";");
Expand All @@ -386,7 +374,7 @@ public ContactsProvider getContactsProvider() {
ProviderEntry entry = this.providers.get("contacts");
return (entry != null) ? ((ContactsProvider) entry.provider) : null;
}

public ShortcutsProvider getShortcutsProvider() {
ProviderEntry entry = this.providers.get("shortcuts");
return (entry != null) ? ((ShortcutsProvider) entry.provider) : null;
Expand Down Expand Up @@ -484,10 +472,15 @@ public void removeFromFavorites(Pojo pojo, Context context) {
}

PreferenceManager.getDefaultSharedPreferences(context).edit()
.putString("favorite-apps-list", favApps.replace(pojo.id+";", "")).commit();
.putString("favorite-apps-list", favApps.replace(pojo.id + ";", "")).commit();

((MainActivity) context).retrieveFavorites();

((MainActivity)context).retrieveFavorites();
}

protected class ProviderEntry {
public IProvider provider = null;
public ServiceConnection connection = null;
}

}
6 changes: 2 additions & 4 deletions app/src/main/java/fr/neamar/kiss/IconsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
Expand All @@ -38,6 +38,7 @@

public class IconsHandler {

private static final String TAG = "IconsHandler";
// map with available icons packs
private HashMap<String, String> iconsPacks = new HashMap<>();
// map with available drawable for an icons pack
Expand All @@ -54,12 +55,9 @@ public class IconsHandler {
private Bitmap frontImage = null;
// scale factor of an icons pack
private float factor = 1.0f;

private PackageManager pm;
private Context ctx;

private static final String TAG = "IconsHandler";

public IconsHandler(Context ctx) {
super();
this.ctx = ctx;
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/fr/neamar/kiss/KissApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public static void initDataHandler(Context ctx) {
dataHandler = new DataHandler(ctx);
}
}

public static IconsHandler getIconsHandler(Context ctx) {
if (iconsPackHandler == null) {
iconsPackHandler = new IconsHandler(ctx);
}
}

return iconsPackHandler;
}

public static void resetIconsHandler(Context ctx) {
iconsPackHandler = new IconsHandler(ctx);
}
Expand Down
Loading

0 comments on commit a8176d4

Please sign in to comment.