Skip to content

Commit

Permalink
Add advanced preference for refreshing push directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 committed Feb 23, 2014
1 parent e188f62 commit ca2eeca
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public List<PreKeyEntity> getPreKeys(PushAddress destination) throws IOException
return response.getKeys();
} catch (JsonParseException e) {
throw new IOException(e);
} catch (NotFoundException nfe) {
throw new UnregisteredUserException(destination.getNumber(), nfe);
}
}

Expand All @@ -163,6 +165,8 @@ public PreKeyEntity getPreKey(PushAddress destination) throws IOException {
return response.getKeys().get(0);
} catch (JsonParseException e) {
throw new IOException(e);
} catch (NotFoundException nfe) {
throw new UnregisteredUserException(destination.getNumber(), nfe);
}
}

Expand Down
6 changes: 5 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<string name="ApplicationPreferencesActivity_unregistering">Unregistering...</string>
<string name="ApplicationPreferencesActivity_unregistering_for_data_based_communication">Unregistering for data based communication</string>
<string name="ApplicationPreferencesActivity_error_connecting_to_server">Error connecting to server!</string>
<string name="ApplicationPreferencesActivity_you_are_not_registered_with_the_push_service">You are not registered with the push service...</string>
<string name="ApplicationPreferencesActivity_updating_directory">Updating directory</string>
<string name="ApplicationPreferencesActivity_updating_push_directory">Updating push directory...</string>

<!-- AttachmentTypeSelectorAdapter -->

Expand Down Expand Up @@ -689,7 +692,8 @@
</string>
<string name="preferences__allow_sms_fallback">Allow SMS Fallback</string>
<string name="preferences__send_and_receive_sms_messages_when_push_is_not_available">Send and receive SMS messages when push is not available</string>

<string name="preferences__refresh_push_directory">Refresh Push Directory</string>

<!-- **************************************** -->
<!-- menus -->
<!-- **************************************** -->
Expand Down
4 changes: 4 additions & 0 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,9 @@

<Preference android:key="pref_mms_preferences"
android:title="@string/preferences__advanced_mms_access_point_names"/>

<Preference android:key="pref_update_directory"
android:title="@string/preferences__refresh_push_directory"/>

</PreferenceCategory>
</PreferenceScreen>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.thoughtcrime.securesms.push.PushServiceSocketFactory;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.ActionBarUtil;
import org.thoughtcrime.securesms.util.DirectoryHelper;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.MemoryCleaner;
Expand Down Expand Up @@ -82,7 +83,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
private static final String PUSH_MESSAGING_PREF = "pref_toggle_push_messaging";
private static final String MMS_PREF = "pref_mms_preferences";
private static final String KITKAT_DEFAULT_PREF = "pref_set_default";

private static final String UPDATE_DIRECTORY_PREF = "pref_update_directory";

private final DynamicTheme dynamicTheme = new DynamicTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
Expand Down Expand Up @@ -119,6 +120,8 @@ protected void onCreate(Bundle icicle) {
.setOnPreferenceChangeListener(new ListSummaryListener());
this.findPreference(TextSecurePreferences.RINGTONE_PREF)
.setOnPreferenceChangeListener(new RingtoneSummaryListener());
this.findPreference(UPDATE_DIRECTORY_PREF)
.setOnPreferenceClickListener(new DirectoryUpdateListener());

initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_COLOR_PREF));
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_BLINK_PREF));
Expand Down Expand Up @@ -529,6 +532,46 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
}

private class DirectoryUpdateListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
final Context context = ApplicationPreferencesActivity.this;

if (!TextSecurePreferences.isPushRegistered(context)) {
Toast.makeText(context,
getString(R.string.ApplicationPreferencesActivity_you_are_not_registered_with_the_push_service),
Toast.LENGTH_LONG).show();
return true;
}

new AsyncTask<Void, Void, Void>() {
private ProgressDialog progress;

@Override
protected void onPreExecute() {
progress = ProgressDialog.show(context,
getString(R.string.ApplicationPreferencesActivity_updating_directory),
getString(R.string.ApplicationPreferencesActivity_updating_push_directory),
true);
}

@Override
protected Void doInBackground(Void... params) {
DirectoryHelper.refreshDirectory(context);
return null;
}

@Override
protected void onPostExecute(Void result) {
if (progress != null)
progress.dismiss();
}
}.execute();

return true;
}
}

/* http://code.google.com/p/android/issues/detail?id=4611#c35 */
@SuppressWarnings("deprecation")
@Override
Expand Down

1 comment on commit ca2eeca

@WhisperBTC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! BitHub has sent payment of $13.65USD for this commit.

Please sign in to comment.