Skip to content

Commit

Permalink
we now need to alter the base path that org files can be stored in, I…
Browse files Browse the repository at this point in the history
… don't like the way I have had to do this... instead of repeating this code we need some common way to get this information
  • Loading branch information
matburt committed Sep 13, 2010
1 parent 19021ea commit 55d8c06
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
43 changes: 39 additions & 4 deletions src/com/matburt/mobileorg/MobileOrgActivity.java
Expand Up @@ -28,6 +28,7 @@
import java.lang.Runnable;
import java.io.BufferedReader;
import java.io.StringReader;
import java.io.File;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
Expand Down Expand Up @@ -149,9 +150,22 @@ public void runParser() {
MobileOrgApplication appInst = (MobileOrgApplication)this.getApplication();
ArrayList<String> allOrgList = this.appdb.getOrgFiles();
String storageMode = this.getStorageLocation();
String userSynchro = this.appSettings.getString("syncSource","");
String orgBasePath = "";

if (userSynchro.equals("sdcard")) {
String indexFile = this.appSettings.getString("indexFilePath","");
File fIndexFile = new File(indexFile);
orgBasePath = fIndexFile.getParent() + "/";
}
else {
orgBasePath = "/sdcard/mobileorg/";
}

OrgFileParser ofp = new OrgFileParser(allOrgList,
storageMode,
this.appdb);
this.appdb,
orgBasePath);
try {
ofp.parse();
appInst.rootNode = ofp.rootNode;
Expand Down Expand Up @@ -210,7 +224,18 @@ public void onListItemClick(ListView l, View v, int position, long id) {
if(Encryption.isAvailable((Context)this))
{
//retrieve the encrypted file data
byte[] rawData = OrgFileParser.getRawFileData(thisNode.nodeName);
String userSynchro = this.appSettings.getString("syncSource","");
String orgBasePath = "";
if (userSynchro.equals("sdcard")) {
String indexFile = this.appSettings.getString("indexFilePath","");
File fIndexFile = new File(indexFile);
orgBasePath = fIndexFile.getParent() + "/";
}
else {
orgBasePath = "/sdcard/mobileorg/";
}

byte[] rawData = OrgFileParser.getRawFileData(orgBasePath, thisNode.nodeName);
//and send it to APG for decryption
Encryption.decrypt(this, rawData);
}
Expand Down Expand Up @@ -261,11 +286,21 @@ else if(requestCode == Encryption.DECRYPT_MESSAGE)
}

Node thisNode = appInst.getSelectedNode();

String userSynchro = this.appSettings.getString("syncSource","");
String orgBasePath = "";
if (userSynchro.equals("sdcard")) {
String indexFile = this.appSettings.getString("indexFilePath","");
File fIndexFile = new File(indexFile);
orgBasePath = fIndexFile.getParent() + "/";
}
else {
orgBasePath = "/sdcard/mobileorg/";
}
String decryptedData = data.getStringExtra(Encryption.EXTRA_DECRYPTED_MESSAGE);
OrgFileParser ofp = new OrgFileParser(appdb.getOrgFiles(),
getStorageLocation(),
appdb);
appdb,
orgBasePath);

ofp.parse(thisNode, new BufferedReader(new StringReader(decryptedData)));
expandSelection(appInst.nodeSelection);
Expand Down
16 changes: 15 additions & 1 deletion src/com/matburt/mobileorg/MobileOrgWidget.java
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.File;

public class MobileOrgWidget extends AppWidgetProvider {
private static final String LT = "MobileOrgWidget";
Expand Down Expand Up @@ -54,13 +55,26 @@ public void onDestroy() {
}

public RemoteViews genUpdateDisplay(Context context) {
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Resources res = context.getResources();
RemoteViews updateViews = null;
updateViews = new RemoteViews(context.getPackageName(),
R.layout.widget_mobileorg);
ArrayList<String> allOrgList = this.appdb.getOrgFiles();
String storageMode = this.getStorageLocation(context);
OrgFileParser ofp = new OrgFileParser(allOrgList, storageMode, this.appdb);
String userSynchro = appPrefs.getString("syncSource","");
String orgBasePath = "";
if (userSynchro.equals("sdcard")) {
String indexFile = appPrefs.getString("indexFilePath","");
File fIndexFile = new File(indexFile);
orgBasePath = fIndexFile.getParent() + "/";
}
else {
orgBasePath = "/sdcard/mobileorg/";
}

OrgFileParser ofp = new OrgFileParser(allOrgList, storageMode,
this.appdb, orgBasePath);
ofp.parse();
Node agendaNode = ofp.rootNode.findChildNode("agendas.org");
Node todoNode = agendaNode.findChildNode("ToDo: ALL");
Expand Down
12 changes: 7 additions & 5 deletions src/com/matburt/mobileorg/OrgFileParser.java
Expand Up @@ -35,13 +35,15 @@ class TitleComponents {
Node rootNode = new Node("MobileOrg", Node.HEADING);
MobileOrgDatabase appdb;
public static final String LT = "MobileOrg";
public static final String ORG_DIR = "/sdcard/mobileorg/";
public String orgDir = "/sdcard/mobileorg/";
OrgFileParser(ArrayList<String> orgpaths,
String storageMode,
MobileOrgDatabase appdb) {
MobileOrgDatabase appdb,
String orgBasePath) {
this.appdb = appdb;
this.storageMode = storageMode;
this.orgPaths = orgpaths;
this.orgDir = orgBasePath;
this.todoKeywords.add("TODO");
this.todoKeywords.add("DONE");

Expand Down Expand Up @@ -232,7 +234,7 @@ public BufferedReader getHandle(String filename) {
this.fstream = new FileInputStream("/data/data/com.matburt.mobileorg/files/" + normalized);
}
else if (this.storageMode.equals("sdcard")) {
this.fstream = new FileInputStream(ORG_DIR + filename);
this.fstream = new FileInputStream(this.orgDir + filename);
}
else {
Log.e(LT, "[Parse] Unknown storage mechanism: " + this.storageMode);
Expand All @@ -247,10 +249,10 @@ else if (this.storageMode.equals("sdcard")) {
return breader;
}

public static byte[] getRawFileData(String filename)
public static byte[] getRawFileData(String baseDir, String filename)
{
try {
File file = new File(ORG_DIR + filename);
File file = new File(baseDir + filename);
FileInputStream is = new FileInputStream(file);
byte[] buffer = new byte[(int)file.length()];
int offset = 0;
Expand Down

0 comments on commit 55d8c06

Please sign in to comment.