-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update location search from tree dialog
- Loading branch information
Showing
22 changed files
with
191 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
opensrp-eusm/src/main/java/org/smartregister/eusm/config/EusmContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.smartregister.eusm.config; | ||
|
||
import org.smartregister.Context; | ||
import org.smartregister.eusm.repository.AppLocationRepository; | ||
import org.smartregister.repository.LocationRepository; | ||
|
||
public class EusmContext extends Context { | ||
|
||
private AppLocationRepository appLocationRepository; | ||
|
||
private static Context context = new EusmContext(); | ||
|
||
public static Context getInstance() { | ||
if (context == null) { | ||
context = new EusmContext(); | ||
} | ||
return context; | ||
} | ||
|
||
@Override | ||
public LocationRepository getLocationRepository() { | ||
if (appLocationRepository == null) { | ||
appLocationRepository = new AppLocationRepository(); | ||
} | ||
return appLocationRepository; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
opensrp-eusm/src/main/java/org/smartregister/eusm/repository/AppLocationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.smartregister.eusm.repository; | ||
|
||
import android.content.ContentValues; | ||
|
||
import net.sqlcipher.Cursor; | ||
import net.sqlcipher.database.SQLiteDatabase; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.smartregister.domain.Location; | ||
import org.smartregister.repository.BaseRepository; | ||
import org.smartregister.repository.LocationRepository; | ||
|
||
import timber.log.Timber; | ||
|
||
public class AppLocationRepository extends LocationRepository { | ||
|
||
protected static final String GEOGRAPHICAL_LEVEL = "geographical_level"; | ||
|
||
private static final String CREATE_LOCATION_TABLE = | ||
"CREATE TABLE " + LOCATION_TABLE + " (" + | ||
ID + " VARCHAR NOT NULL PRIMARY KEY," + | ||
UUID + " VARCHAR , " + | ||
PARENT_ID + " VARCHAR , " + | ||
NAME + " VARCHAR , " + | ||
GEOGRAPHICAL_LEVEL + " VARCHAR , " + | ||
SYNC_STATUS + " VARCHAR DEFAULT " + BaseRepository.TYPE_Synced + ", " + | ||
GEOJSON + " VARCHAR NOT NULL ) "; | ||
|
||
private static final String CREATE_LOCATION_NAME_INDEX = "CREATE INDEX " | ||
+ LOCATION_TABLE + "_" + NAME + "_ind ON " + LOCATION_TABLE + "(" + NAME + ")"; | ||
|
||
public static void createTable(SQLiteDatabase database) { | ||
database.execSQL(CREATE_LOCATION_TABLE); | ||
database.execSQL(CREATE_LOCATION_NAME_INDEX); | ||
} | ||
|
||
public void addOrUpdate(Location location) { | ||
if (StringUtils.isBlank(location.getId())) | ||
throw new IllegalArgumentException("id not provided"); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(ID, location.getId()); | ||
contentValues.put(UUID, location.getProperties().getUid()); | ||
contentValues.put(PARENT_ID, location.getProperties().getParentId()); | ||
contentValues.put(NAME, location.getProperties().getName()); | ||
contentValues.put(GEOGRAPHICAL_LEVEL, location.getProperties().getGeographicLevel()); | ||
contentValues.put(GEOJSON, gson.toJson(location)); | ||
contentValues.put(SYNC_STATUS, location.getSyncStatus()); | ||
getWritableDatabase().replace(getLocationTableName(), null, contentValues); | ||
} | ||
|
||
public Location getLocationByNameAndGeoLevel(String name, String level) { | ||
try (Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM " + getLocationTableName() + | ||
" WHERE " + NAME + " =? AND " + GEOGRAPHICAL_LEVEL + "=?", new String[]{name, level})) { | ||
if (cursor.moveToFirst()) { | ||
return readCursor(cursor); | ||
} | ||
} catch (Exception e) { | ||
Timber.e(e); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.