Skip to content
Browse files

Hide sync button/option menu item when working offline

  • Loading branch information...
1 parent 8174333 commit a4e6d4f633776069f05fc081ba263d106ac86d31 @ginatrapani ginatrapani committed Feb 21, 2011
View
2 res/values/strings.xml
@@ -103,7 +103,7 @@ You should have received a copy of the GNU General Public License along with Tod
<string name="line_breaks_pref_summary">Use Windows-friendly line breaks in the text file.</string>
<string name="work_offline_pref_key">workofflinepref</string>
<string name="work_offline_pref_title">Work offline</string>
- <string name="work_offline_pref_summary">Never sync to Dropbox.</string>
+ <string name="work_offline_pref_summary">Don\'t sync to Dropbox.</string>
<!-- login -->
<string name="dropbox_authentication">Log in to Dropbox</string>
<string name="username_label">Email Address:</string>
View
79 src/com/todotxt/todotxttouch/AddTask.java
@@ -64,7 +64,7 @@
private Task m_backup;
private TodoApplication m_app;
- private TaskBag taskBag;
+ private TaskBag taskBag;
private TextView titleBarLabel;
@@ -81,7 +81,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.add_task);
m_app = (TodoApplication) getApplication();
- taskBag = m_app.getTaskBag();
+ taskBag = m_app.getTaskBag();
final Intent intent = getIntent();
final String action = intent.getAction();
@@ -99,7 +99,6 @@ public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, share_text);
}
-
// title bar label
titleBarLabel = (TextView) findViewById(R.id.title_bar_label);
@@ -123,32 +122,37 @@ public void onCreate(Bundle savedInstanceState) {
titleBarLabel.setText(R.string.addtask);
}
- textInputField.setSelection(textInputField.getText().toString().length());
+ textInputField.setSelection(textInputField.getText().toString()
+ .length());
// priorities
priorities = (Spinner) findViewById(R.id.priorities);
final ArrayList<String> prioArr = new ArrayList<String>();
prioArr.add("Priority");
- prioArr.addAll(Priority.rangeInCode(Priority.A, Priority.E));
+ prioArr.addAll(Priority.rangeInCode(Priority.A, Priority.E));
priorities.setAdapter(Util.newSpinnerAdapter(this, prioArr));
if (m_backup != null) {
- int index = prioArr.indexOf(m_backup.getPriority().getCode());
+ int index = prioArr.indexOf(m_backup.getPriority().getCode());
priorities.setSelection(index < 0 ? 0 : index);
}
priorities.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long id) {
- int cursorPosition = textInputField.getSelectionStart();
- String currentText = textInputField.getText().toString();
- Priority priority = Priority.NONE;
- if (position > 0) {
+ int cursorPosition = textInputField.getSelectionStart();
+ String currentText = textInputField.getText().toString();
+ Priority priority = Priority.NONE;
+ if (position > 0) {
String item = prioArr.get(position);
- priority = Priority.toPriority(item);
+ priority = Priority.toPriority(item);
}
- String text = PriorityTextSplitter.getInstance().split(currentText).text;
- textInputField.setText(Strings.insertPadded(text, 0, priority.inFileFormat()));
- textInputField.setSelection(CursorPositionCalculator.calculate(cursorPosition, currentText, textInputField.getText().toString()));
+ String text = PriorityTextSplitter.getInstance().split(
+ currentText).text;
+ textInputField.setText(Strings.insertPadded(text, 0,
+ priority.inFileFormat()));
+ textInputField.setSelection(CursorPositionCalculator.calculate(
+ cursorPosition, currentText, textInputField.getText()
+ .toString()));
}
@Override
@@ -166,13 +170,16 @@ public void onNothingSelected(AdapterView<?> arg0) {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long id) {
if (position > 0) {
- int cursorPosition = textInputField.getSelectionStart();
- String currentText = textInputField.getText().toString();
- String item = "+"+projectsArr.get(position);
- textInputField.setText(Strings.insertPadded(currentText, cursorPosition, item));
- textInputField.setSelection(CursorPositionCalculator.calculate(cursorPosition, currentText, textInputField.getText().toString()));
+ int cursorPosition = textInputField.getSelectionStart();
+ String currentText = textInputField.getText().toString();
+ String item = "+" + projectsArr.get(position);
+ textInputField.setText(Strings.insertPadded(currentText,
+ cursorPosition, item));
+ textInputField.setSelection(CursorPositionCalculator
+ .calculate(cursorPosition, currentText,
+ textInputField.getText().toString()));
}
- projects.setSelection(0);
+ projects.setSelection(0);
}
@Override
@@ -190,13 +197,16 @@ public void onNothingSelected(AdapterView<?> arg0) {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long id) {
if (position > 0) {
- int cursorPosition = textInputField.getSelectionStart();
- String currentText = textInputField.getText().toString();
- String item = "@"+contextsArr.get(position);
- textInputField.setText(Strings.insertPadded(currentText, cursorPosition, item));
- textInputField.setSelection(CursorPositionCalculator.calculate(cursorPosition, currentText, textInputField.getText().toString()));
+ int cursorPosition = textInputField.getSelectionStart();
+ String currentText = textInputField.getText().toString();
+ String item = "@" + contextsArr.get(position);
+ textInputField.setText(Strings.insertPadded(currentText,
+ cursorPosition, item));
+ textInputField.setSelection(CursorPositionCalculator
+ .calculate(cursorPosition, currentText,
+ textInputField.getText().toString()));
}
- contexts.setSelection(0);
+ contexts.setSelection(0);
}
@Override
@@ -236,17 +246,17 @@ protected Boolean doInBackground(Object... params) {
try {
Task task = (Task) params[0];
String input = (String) params[1];
- if (task != null) {
- task.update(input);
- taskBag.update(task);
- } else {
- taskBag.addAsTask(input);
- }
- return true;
+ if (task != null) {
+ task.update(input);
+ taskBag.update(task);
+ } else {
+ taskBag.addAsTask(input);
+ }
+ return true;
} catch (Exception e) {
Log.e(TAG,
"input: " + input + " - " + e.getMessage());
- return false;
+ return false;
}
}
@@ -261,6 +271,7 @@ protected void onPostExecute(Boolean result) {
: getString(R.string.add_task_failed);
Util.showToastLong(AddTask.this, res);
}
+ m_ProgressDialog.dismiss();
}
}.execute(m_backup, input);
}
View
27 src/com/todotxt/todotxttouch/Preferences.java
@@ -30,15 +30,20 @@
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
+import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
+import android.util.Log;
public class Preferences extends PreferenceActivity {
+ final static String TAG = Preferences.class.getSimpleName();
+
private Preference aboutDialog;
private Preference logoutDialog;
private static final int ABOUT_DIALOG = 1;
@@ -64,7 +69,26 @@ protected void onCreate(Bundle savedInstanceState) {
}
aboutDialog = findPreference("app_version");
logoutDialog = findPreference("logout_dropbox");
+ setOnlineOfflinePrefs();
+ }
+ private void setOnlineOfflinePrefs() {
+ SharedPreferences appPreferences = PreferenceManager
+ .getDefaultSharedPreferences(this);
+ if (appPreferences.getBoolean("workofflinepref", false)) {
+ findPreference("todotxtpath").setEnabled(false);
+ findPreference("logout_dropbox").setEnabled(false);
+ Log.v(TAG, "Work offline is checked, disabling online settings");
+ } else {
+ findPreference("todotxtpath").setEnabled(true);
+ findPreference("logout_dropbox").setEnabled(true);
+ Log.v(TAG, "Work offline is not checked, enabling online settings");
+ }
+ }
+
+ protected void onResume() {
+ super.onResume();
+ setOnlineOfflinePrefs();
}
@Override
@@ -75,9 +99,8 @@ public boolean onPreferenceTreeClick(PreferenceScreen screen,
} else if (preference == logoutDialog) {
showDialog(LOGOUT_DIALOG);
}
-
+ setOnlineOfflinePrefs();
return true;
-
}
@Override
View
23 src/com/todotxt/todotxttouch/TodoTxtTouch.java
@@ -122,15 +122,8 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
currentActivityPointer = this;
- // final boolean customTitleSupported =
- // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
-
setContentView(R.layout.main);
- /*
- * if (customTitleSupported) {
- * getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
- * R.layout.title_bar); }
- */
+
m_app = (TodoApplication) getApplication();
m_app.m_prefs.registerOnSharedPreferenceChangeListener(this);
this.taskBag = m_app.getTaskBag();
@@ -180,6 +173,12 @@ public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Searched for " + m_search);
setFilteredTasks(false);
}
+
+ if (this.m_app.m_prefs.getBoolean("workofflinepref", false)) {
+ findViewById(R.id.btn_title_refresh).setVisibility(View.GONE);
+ } else {
+ findViewById(R.id.btn_title_refresh).setVisibility(View.VISIBLE);
+ }
}
private void initializeTasks() {
@@ -218,9 +217,15 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
Log.i(TAG, "New access token secret. Syncing!");
populateFromExternal();
} else if ("workofflinepref".equals(key)) {
- Log.i(TAG, "Switched online/offline mode. Push local changes if necessary.");
+ Log.i(TAG,
+ "Switched online/offline mode. Push local changes if necessary.");
taskBag.pushToRemote();
}
+ if (sharedPreferences.getBoolean("workofflinepref", false)) {
+ findViewById(R.id.btn_title_refresh).setVisibility(View.GONE);
+ } else {
+ findViewById(R.id.btn_title_refresh).setVisibility(View.VISIBLE);
+ }
}
@Override

0 comments on commit a4e6d4f

Please sign in to comment.
Something went wrong with that request. Please try again.