Skip to content

Commit

Permalink
Merge pull request #130 from PDesire/master
Browse files Browse the repository at this point in the history
Add some null safety & Add MediaScan on file deletion
  • Loading branch information
friedger authored Apr 1, 2019
2 parents 5627010 + 809b963 commit d432d84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;

import androidx.annotation.NonNull;

/**
* Used by the standard search Service, in order to provide results asynchronously to the SearchableActivity.
*
Expand Down Expand Up @@ -43,7 +45,7 @@ public boolean onCreate() {
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
public Cursor query(@NonNull Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();
sqlBuilder.setTables(TABLE_NAME);
Expand All @@ -58,7 +60,7 @@ public Cursor query(Uri uri, String[] projection, String selection,
}

@Override
public Uri insert(Uri uri, ContentValues values) {
public Uri insert(@NonNull Uri uri, ContentValues values) {
long rowID = db.insert(TABLE_NAME, "", values);
if (rowID > 0) {
Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
Expand All @@ -69,21 +71,21 @@ public Uri insert(Uri uri, ContentValues values) {
}

@Override
public int update(Uri uri, ContentValues values, String selection,
public int update(@NonNull Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
// We only write, read and delete the db. Not implemented for now.
return 0;
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
int count = db.delete(TABLE_NAME, selection, selectionArgs);
getContext().getContentResolver().notifyChange(uri, null);
return count;
}

@Override
public String getType(Uri uri) {
public String getType(@NonNull Uri uri) {
return SEARCH_MIMETYPE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import java.util.ArrayList;

import androidx.annotation.NonNull;

/**
* Not that good, but it's a working implementation at least. We REALLY need asynchronous suggestion refreshing.
*
Expand All @@ -32,7 +34,7 @@ public class SearchSuggestionsProvider extends ContentProvider {
/**
* Always clears all suggestions. Parameters other than uri are ignored.
*/
public int delete(Uri uri, String selection, String[] selectionArgs) {
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
int count = mSuggestions.size();
mSuggestions.clear();
getContext().getContentResolver().notifyChange(uri, null);
Expand All @@ -41,12 +43,13 @@ public int delete(Uri uri, String selection, String[] selectionArgs) {
}

@Override
public String getType(Uri uri) {
public String getType(@NonNull Uri uri) {
return SEARCH_SUGGEST_MIMETYPE;
}

@Override
public Uri insert(Uri uri, ContentValues values) {
@NonNull
public Uri insert(@NonNull Uri uri, ContentValues values) {
long id = mSuggestions.size() + 1;
values.put(BaseColumns._ID, id);
mSuggestions.add(values);
Expand All @@ -69,7 +72,7 @@ public boolean onCreate() {
/**
* NOT a cheap call. Actual search happens here.
*/
public Cursor query(Uri uri, String[] projection, String selection,
public Cursor query(@NonNull Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
searcher.setQuery(uri.getLastPathSegment().toLowerCase());

Expand Down Expand Up @@ -97,7 +100,7 @@ public Cursor query(Uri uri, String[] projection, String selection,
/**
* We don't care about updating. Unimplemented.
*/
public int update(Uri uri, ContentValues values, String selection,
public int update(@NonNull Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.media.MediaScannerConnection;
import android.net.Uri;

import org.openintents.filemanager.files.FileHolder;
Expand Down Expand Up @@ -45,7 +46,9 @@ public static void informFilesAdded(Context c, List<FileHolder> files) {
}

public static void informFileDeleted(Context c, File f) {
// TODO implement
String[] file = new String[]{f.getPath()};

MediaScannerConnection.scanFile(c, file, null, null);
}

public static void informFilesDeleted(Context c, File[] files) {
Expand Down

0 comments on commit d432d84

Please sign in to comment.