Skip to content

Commit

Permalink
[#183]Improve initial org download speed. Delet old unused parsers.
Browse files Browse the repository at this point in the history
  • Loading branch information
stellanl committed Jan 3, 2016
1 parent 38d337c commit cb2eebe
Show file tree
Hide file tree
Showing 18 changed files with 426 additions and 817 deletions.
5 changes: 5 additions & 0 deletions android/AkvoRSR/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
android:enabled="true"
android:exported="false" >
</service>
<service
android:name="org.akvo.rsr.up.service.GetOrgDataService"
android:enabled="true"
android:exported="false" >
</service>

</application>

Expand Down
6 changes: 3 additions & 3 deletions android/AkvoRSR/res/layout/activity_org_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/label_progress_projects" />
android:text="@string/label_progress_orgs" />

<ProgressBar
android:id="@+id/progressBar1"
Expand All @@ -38,7 +38,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/label_progress_updates" />
android:text="@string/label_progress_countries" />

<ProgressBar
android:id="@+id/progressBar2"
Expand Down Expand Up @@ -123,7 +123,7 @@
<!-- list of projects. if it is empty, the TextView will be shown instead -->

<ListView
android:id="@+id/list_projects"
android:id="@+id/list_orgs"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
Expand Down
55 changes: 55 additions & 0 deletions android/AkvoRSR/res/layout/org_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!-- One project list item -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
>

<ImageView
android:id="@+id/list_item_thumbnail"
android:layout_width="100dip"
android:layout_height="80dip"
android:layout_margin="10dp"
android:contentDescription="@string/app_name"
/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<TextView
android:id="@+id/list_item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dip"
android:textSize="16sp"
android:textColor="@color/orange"
android:typeface="sans" />

<TextView
android:id="@+id/list_item_long_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:paddingRight="5dp"
android:textSize="12sp"
android:typeface="sans"
/>

<TextView
android:id="@+id/list_item_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:paddingRight="5dp"
android:textSize="12sp"
android:typeface="sans"
/>
<!-- URL? -->

</LinearLayout>
</LinearLayout>
47 changes: 25 additions & 22 deletions android/AkvoRSR/res/values/ids.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item
type="id"
name="project_id_tag" />
<item
type="id"
name="update_id_tag" />
<item
type="id"
name="thumbnail_url_tag" />
<item
type="id"
name="thumbnail_fn_tag" />
<item
type="id"
name="thumbnail_expandable_tag" />
<item
type="id"
name="object_type_tag" />
</resources>

<?xml version="1.0" encoding="utf-8"?>
<resources>
<item
type="id"
name="project_id_tag" />
<item
type="id"
name="update_id_tag" />
<item
type="id"
name="thumbnail_url_tag" />
<item
type="id"
name="thumbnail_fn_tag" />
<item
type="id"
name="thumbnail_expandable_tag" />
<item
type="id"
name="object_type_tag" />
<item
type="id"
name="org_id_tag" />
</resources>

19 changes: 10 additions & 9 deletions android/AkvoRSR/src/org/akvo/rsr/up/OrgListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.akvo.rsr.up.util.ConstantUtil;
import org.akvo.rsr.up.util.DialogUtil;
import org.akvo.rsr.up.util.SettingsUtil;
import org.akvo.rsr.up.viewadapter.OrgListCursorAdapter;
import org.akvo.rsr.up.viewadapter.ProjectListCursorAdapter;

import android.os.Bundle;
Expand Down Expand Up @@ -52,7 +53,7 @@
public class OrgListActivity extends ActionBarActivity {


private static final String TAG = "ProjectListActivity";
private static final String TAG = "OrgListActivity";

private RsrDbAdapter ad;
private Cursor dataCursor;
Expand All @@ -75,13 +76,13 @@ protected void onCreate(Bundle savedInstanceState) {
mEmployed = !SettingsUtil.getAuthUser(this).getOrgIds().isEmpty();

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_project_list);
setContentView(R.layout.activity_org_list);

projCountLabel = (TextView) findViewById(R.id.projcountlabel);
inProgress = (LinearLayout) findViewById(R.id.projlistprogress);
projCountLabel = (TextView) findViewById(R.id.orgcountlabel);
inProgress = (LinearLayout) findViewById(R.id.orglistprogress);
inProgress1 = (ProgressBar) findViewById(R.id.progressBar1);

mList = (ListView) findViewById(R.id.list_projects);
mList = (ListView) findViewById(R.id.list_orgs);
mEmptyText = (TextView) findViewById(R.id.list_empty_text);
mFirstTimeText = (TextView) findViewById(R.id.first_time_text);
mUnemployedText = (TextView) findViewById(R.id.unemployed_text);
Expand Down Expand Up @@ -111,7 +112,7 @@ public void onClick(View view) {
//show X instead of magnifying glass
searchButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_close_normal,0,0,0);
searchField.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
searchField.requestFocus();
// searchField.requestFocus();
// showSoftKeyBoard(searchField);
}
}
Expand All @@ -134,8 +135,8 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
ad.open();

//register a listener for completion broadcasts
IntentFilter f = new IntentFilter(ConstantUtil.PROJECTS_FETCHED_ACTION);
f.addAction(ConstantUtil.PROJECTS_PROGRESS_ACTION);
IntentFilter f = new IntentFilter(ConstantUtil.ORGS_FETCHED_ACTION);
f.addAction(ConstantUtil.ORGS_PROGRESS_ACTION);
broadRec = new ResponseReceiver();
LocalBroadcastManager.getInstance(this).registerReceiver(broadRec, f);

Expand Down Expand Up @@ -255,7 +256,7 @@ private void getData() {
mUnemployedText.setVisibility(View.GONE);
}
//Populate list view
ProjectListCursorAdapter projects = new ProjectListCursorAdapter(this, dataCursor);
OrgListCursorAdapter projects = new OrgListCursorAdapter(this, dataCursor);
mList.setAdapter(projects);
}

Expand Down
62 changes: 40 additions & 22 deletions android/AkvoRSR/src/org/akvo/rsr/up/dao/RsrDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class RsrDbAdapter {
public static final String OLD_TYPE_COL = "old_type";
public static final String PRIMARY_COUNTRY_ID_COL = "primary_country_id";
public static final String MODIFIED_COL = "modified_date";
public static final String LOGO_URL_COL = "logo_url";
public static final String LOGO_FN_COL = "logo_fn";

public static final String RESULT_COL = "result";
public static final String RESULT_ID_COL = "result_id";
Expand All @@ -116,8 +118,8 @@ public class RsrDbAdapter {
private DatabaseHelper databaseHelper;
private SQLiteDatabase database;

private static final String PROJECT_JOIN = "project LEFT OUTER JOIN country ON (project.country_id = country._id)";
private static final String UPDATE_JOIN = "_update LEFT OUTER JOIN country ON (_update.country_id = country._id)";
private static final String PROJECT_COUNTRY_JOIN = "project LEFT OUTER JOIN country ON (project.country_id = country._id)";
private static final String UPDATE_COUNTRY_JOIN = "_update LEFT OUTER JOIN country ON (_update.country_id = country._id)";
private static final String ORG_COUNTRY_JOIN = "_organisation LEFT OUTER JOIN country ON (_organisation.primary_country_id = country._id)";

// Table names
Expand Down Expand Up @@ -165,7 +167,9 @@ public class RsrDbAdapter {
+ MODIFIED_COL + " integer, "
+ OLD_TYPE_COL + " string, "
+ NEW_TYPE_COL + " string, "
+ PRIMARY_COUNTRY_ID_COL + " string, "
+ LOGO_URL_COL + " string, "
+ LOGO_FN_COL + " string, "
+ PRIMARY_COUNTRY_ID_COL + " string "
+ ")";

private static final String RESULT_TABLE_CREATE =
Expand Down Expand Up @@ -198,7 +202,7 @@ public class RsrDbAdapter {
// private static final int DATABASE_VERSION = 14; //update now has photo metadata and video
// private static final int DATABASE_VERSION = 15; //update now has location
// private static final int DATABASE_VERSION = 16; //project gets a last_fetch datetime to optimize fetches
private static final int DATABASE_VERSION = 17; //results framework (added result, indicator and period tables)
private static final int DATABASE_VERSION = 17; //results framework (added result, indicator and period tables). New Org columns.

private final Context context;

Expand Down Expand Up @@ -276,6 +280,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("alter table " + ORG_TABLE + " add column " + PRIMARY_COUNTRY_ID_COL + " string");
db.execSQL("alter table " + ORG_TABLE + " add column " + OLD_TYPE_COL + " string");
db.execSQL("alter table " + ORG_TABLE + " add column " + NEW_TYPE_COL + " string");
db.execSQL("alter table " + ORG_TABLE + " add column " + LOGO_URL_COL + " string");
db.execSQL("alter table " + ORG_TABLE + " add column " + LOGO_FN_COL + " string");
db.execSQL("alter table " + ORG_TABLE + " add column " + MODIFIED_COL + " integer");
}
}
Expand Down Expand Up @@ -633,7 +639,7 @@ public Cursor listVisibleProjects() {
* Gets all projects, all columns and country data
*/
public Cursor listAllProjectsWithCountry() {
Cursor cursor = database.query(PROJECT_JOIN,
Cursor cursor = database.query(PROJECT_COUNTRY_JOIN,
null,
null,
null,
Expand All @@ -648,7 +654,7 @@ public Cursor listAllProjectsWithCountry() {
* Gets visible projects, all columns and country data
*/
public Cursor listVisibleProjectsWithCountry() {
Cursor cursor = database.query(PROJECT_JOIN,
Cursor cursor = database.query(PROJECT_COUNTRY_JOIN,
new String[] { "project._id", "project.title", "project.hidden", "project.thumbnail_url", "project.thumbnail_fn", "country.name", "country.continent" },
HIDDEN_COL + " = ?",
new String[] { "0" },
Expand All @@ -673,7 +679,7 @@ public Cursor listVisibleProjectsWithCountryMatching(String search) {
search = search.replaceAll(",", " ");
*/
//Match caseless, assume country or continent is present in entirety
Cursor cursor = database.query(PROJECT_JOIN,
Cursor cursor = database.query(PROJECT_COUNTRY_JOIN,
new String[] { "project._id", "project.title", "project.hidden", "project.thumbnail_url", "project.thumbnail_fn", "country.name", "country.continent" },
HIDDEN_COL + " = ? AND ( title LIKE ? OR name LIKE ? OR continent LIKE ? OR project._id = ?)",
new String[] { "0", "%" + search + "%", search, search, search },
Expand Down Expand Up @@ -825,13 +831,16 @@ public List<String> getMissingUsersList() {
* Gets all orgs, all columns
*/
public Cursor listAllOrgs() {
Cursor cursor = database.query(ORG_TABLE,
null,
null,
null,
null,
null,
null);
Cursor cursor = database.query(ORG_COUNTRY_JOIN,
new String[] {
"_organisation._id", "_organisation.name", "_organisation.long_name", "_organisation.logo_url", "_organisation.logo_fn",
"country.name AS country_name", "country.continent"
},
null,
null,
null,
null,
"_organisation.name");
return cursor;
}

Expand All @@ -842,12 +851,15 @@ public Cursor listAllOrgs() {
public Cursor listAllOrgsMatching(String search) {
//Match caseless, assume id, country or continent is present in entirety (or else "1" would match more than 10% of records)
Cursor cursor = database.query(ORG_COUNTRY_JOIN,
new String[] { "_organisation._id", "_organisation.name", "_organisation.long_name", "country.name", "country.continent" },
"( name LIKE ? OR long_name LIKE ? OR country.name LIKE ? OR continent LIKE ? OR organisation._id = ?)",
new String[] { "%" + search + "%", "%" + search + "%", search, search, search },
null,
null,
null);
new String[] {
"_organisation._id", "_organisation.name", "_organisation.long_name", "_organisation.logo_url", "_organisation.logo_fn",
"country.name AS country_name", "country.continent"
},
"( _organisation.name LIKE ? OR _organisation.long_name LIKE ? OR country_name LIKE ? OR continent LIKE ? OR _organisation._id = ?)",
new String[] { "%" + search + "%", "%" + search + "%", search, search, search },
null,
null,
"_organisation.name");
return cursor;
}

Expand Down Expand Up @@ -887,7 +899,7 @@ public List<String> getMissingOrgsList() {
*/
public Project findProject(String _id) {
Project project = null;
Cursor cursor = database.query(PROJECT_JOIN,
Cursor cursor = database.query(PROJECT_COUNTRY_JOIN,
null,
"project._id = ?",
new String[] { _id }, null, null, null);
Expand Down Expand Up @@ -922,7 +934,7 @@ public Project findProject(String _id) {
*/
public Update findUpdate(String _id) {
Update update = null;
Cursor cursor = database.query(UPDATE_JOIN,
Cursor cursor = database.query(UPDATE_COUNTRY_JOIN,
null, //all columns
"_update._id = ?",
new String[] { _id }, null, null, null);
Expand Down Expand Up @@ -1096,6 +1108,9 @@ public Organisation findOrganisation(String _id) {
org.setLongName(cursor.getString(cursor.getColumnIndexOrThrow(LONG_NAME_COL)));
org.setEmail(cursor.getString(cursor.getColumnIndexOrThrow(EMAIL_COL)));
org.setUrl(cursor.getString(cursor.getColumnIndexOrThrow(URL_COL)));
org.setLogo(cursor.getString(cursor.getColumnIndexOrThrow(LOGO_URL_COL)));
//org.setLogoFilename(cursor.getString(cursor.getColumnIndexOrThrow(LOGO_FN_COL)));
org.setPrimaryCountryId(cursor.getString(cursor.getColumnIndexOrThrow(PRIMARY_COUNTRY_ID_COL)));
}
cursor.close();
}
Expand All @@ -1117,6 +1132,9 @@ public void saveOrganisation(Organisation org) {
updatedValues.put(LONG_NAME_COL, org.getLongName());
updatedValues.put(EMAIL_COL, org.getEmail());
updatedValues.put(URL_COL, org.getUrl());
updatedValues.put(PRIMARY_COUNTRY_ID_COL, org.getPrimaryCountryId());
updatedValues.put(LOGO_URL_COL, org.getLogo());
//not logo filename, to preserve cache connection

Cursor cursor = database.query(ORG_TABLE,
new String[] { PK_ID_COL },
Expand Down
9 changes: 9 additions & 0 deletions android/AkvoRSR/src/org/akvo/rsr/up/domain/Organisation.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Organisation {
private String mNewType;//IATI type integer code?
private String mPrimaryCountryId;
private Date mLastModifiedAt;
private String mLogo;
// private Set<String>mCountryIds;

public String getId() {
Expand Down Expand Up @@ -135,4 +136,12 @@ public void setPrimaryCountryId(String id) {
mPrimaryCountryId=id;
}

public String getLogo() {
return mLogo;
}

public void setLogo(String logo) {
mLogo = logo;
}

}
Loading

0 comments on commit cb2eebe

Please sign in to comment.