Skip to content

Commit

Permalink
Changed the way outline is initialized.
Browse files Browse the repository at this point in the history
Helps sharing data betweem outline and widget.
  • Loading branch information
hdweiss committed Dec 15, 2011
1 parent 9dce26d commit dbccaf7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
14 changes: 6 additions & 8 deletions src/com/matburt/mobileorg/Gui/OutlineActivity.java
Expand Up @@ -54,24 +54,25 @@ public class OutlineActivity extends ListActivity
*/
private int lastSelection = 0;

private boolean initSuccess = true;

private final Handler syncHandler = new Handler();
private IOException syncError;
private ProgressDialog syncDialog;
private OutlineListAdapter outlineAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

this.appInst = (MobileOrgApplication) this.getApplication();

this.outlineAdapter = new OutlineListAdapter(this, appInst.nodestackTop());
this.setListAdapter(outlineAdapter);

Intent intent = getIntent();
this.depth = intent.getIntExtra("depth", 1);

if(this.depth == 1) {
this.initSuccess = appInst.init();
if(this.initSuccess == false)
if(this.appInst.getOrgFiles().isEmpty())
this.showWizard();
}

Expand All @@ -95,7 +96,7 @@ public void onResume() {
* data has been updated.
*/
private void refreshDisplay() {
this.setListAdapter(new OutlineListAdapter(this, appInst.nodestackTop()));
outlineAdapter.notifyDataSetChanged();
getListView().setSelection(lastSelection);
}

Expand Down Expand Up @@ -345,9 +346,6 @@ private void postSynchronize() {
if (this.syncError != null) {
ErrorReporter.displayError(this, this.syncError.getMessage());
} else {
if(this.initSuccess == false) {
this.initSuccess = appInst.init();
}
this.onResume();
}
}
Expand Down
29 changes: 20 additions & 9 deletions src/com/matburt/mobileorg/Parsing/MobileOrgApplication.java
Expand Up @@ -28,19 +28,17 @@ public void onCreate() {
this.rootNode = new Node("");
clearNodestack();
this.parser = new OrgFileParser(getBaseContext(), this);
init();
}


public boolean init() {

private void init() {
if (this.appdb.getOrgFiles().isEmpty())
return false;
return;

this.rootNode = this.parser.prepareRootNode();
clearNodestack();

this.edits = this.parser.parseEdits();

return true;
}

public void pushNodestack(Node node) {
Expand Down Expand Up @@ -68,16 +66,26 @@ public int nodestackSize() {
}


public void makeSureNodeIsParsed(Node node) {
public boolean makeSureNodeIsParsed(Node node) {
if (node == null)
return false;

if (node.parsed == false) {
if (node.encrypted == false) {
this.parser.parseFile(node.name, rootNode);
} else {
// decryptNode(node);
return;
return true;
}
}
}
return false;
}

public Node getFileNode(String filename) {
Node node = this.rootNode.findChildNode(filename);
makeSureNodeIsParsed(node);
return node;
}

/**
* This function is called by the synchronizer or capture for each file that
Expand Down Expand Up @@ -134,6 +142,9 @@ public HashMap<String, String> getOrgFiles() {
return appdb.getOrgFiles();
}

public ArrayList<EditNode> getNodeEdits() {
return this.edits;
}

public ArrayList<String> getPriorities() {
return appdb.getPriorities();
Expand Down
6 changes: 3 additions & 3 deletions src/com/matburt/mobileorg/Services/MobileOrgSyncService.java
Expand Up @@ -46,7 +46,7 @@ public void onStart(Intent intent, int startid) {
startTimer();
}

public void startTimer() {
private void startTimer() {
if(!this.timerScheduled) {
boolean doAutoSync = this.appSettings.getBoolean("doAutoSync", false);
if(doAutoSync) { //This may can be removed since we are checking this at a higher level
Expand Down Expand Up @@ -83,7 +83,7 @@ public void run() {
}
}

public void stopTimer() {
private void stopTimer() {
if(this.timer != null) {
this.timer.cancel();
this.timer = new Timer();
Expand All @@ -106,7 +106,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
}

public void runSynchronizer() {
private void runSynchronizer() {
MobileOrgApplication appInst = (MobileOrgApplication) this.getApplication();
final SyncManager syncman = new SyncManager(this, appInst);

Expand Down
16 changes: 3 additions & 13 deletions src/com/matburt/mobileorg/Services/MobileOrgWidget.java
Expand Up @@ -9,17 +9,14 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.widget.RemoteViews;

import com.matburt.mobileorg.R;
import com.matburt.mobileorg.Gui.NodeEditActivity;
import com.matburt.mobileorg.Parsing.EditNode;
import com.matburt.mobileorg.Parsing.MobileOrgApplication;
import com.matburt.mobileorg.Parsing.Node;
import com.matburt.mobileorg.Parsing.OrgFileParser;

public class MobileOrgWidget extends AppWidgetProvider {
public static String WIDGET_CAPTURE = "WIDGET_CAPTURE";
Expand Down Expand Up @@ -48,7 +45,7 @@ public void onDestroy() {
super.onDestroy();
}

public RemoteViews genUpdateDisplay(Context context) {
private RemoteViews genUpdateDisplay(Context context) {
RemoteViews updateViews = null;
updateViews = new RemoteViews(context.getPackageName(),
R.layout.widget);
Expand All @@ -66,10 +63,8 @@ public RemoteViews genUpdateDisplay(Context context) {
private String getAgenda() {
MobileOrgApplication appInst = (MobileOrgApplication)this.getApplication();

OrgFileParser ofp = new OrgFileParser(getBaseContext(), appInst);
Node agendaNode = ofp.parseFile("agendas.org", null);
ArrayList<EditNode> parseEdits = ofp.parseEdits();

Node agendaNode = appInst.getFileNode("agendas.org");
ArrayList<EditNode> parseEdits = appInst.getNodeEdits();

StringBuilder widgetBuffer = new StringBuilder();
if (agendaNode != null) {
Expand All @@ -91,11 +86,6 @@ private String getAgenda() {
return widgetBuffer.toString();
}

public String getStorageLocation(Context context) {
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
return appPrefs.getString("storageMode", "");
}

@Override
public IBinder onBind(Intent intent) {
// We don't need to bind to this service
Expand Down

0 comments on commit dbccaf7

Please sign in to comment.