Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.text.TextUtils;
import android.util.Pair;
import android.util.SparseBooleanArray;
Expand Down Expand Up @@ -385,6 +386,7 @@ public boolean onPreferenceClick(Preference preference) {
} else if (preference == mCategoryPref || preference == mFormatPref) {
return !shouldShowListPreference((DetailListPreference) preference);
} else if (preference == mExportSitePref) {
showExportContentDialog();
} else if (preference == mDeleteSitePref) {
requestPurchasesForDeletionCheck();
} else {
Expand Down Expand Up @@ -702,6 +704,22 @@ public String format(int value) {
});
}

private void showExportContentDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.export_your_content);
String email = AccountHelper.getDefaultAccount().getEmail();
builder.setMessage(getString(R.string.export_your_content_message, email));
builder.setPositiveButton(R.string.site_settings_export_content_title, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
exportSite();
}
});
builder.setNegativeButton(R.string.cancel, null);

builder.show();
}

private void requestPurchasesForDeletionCheck() {
final Blog currentBlog = WordPress.getCurrentBlog();
final ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "", getString(R.string.checking_purchases), true, false);
Expand Down Expand Up @@ -1187,6 +1205,29 @@ public void onClick(DialogInterface dialog, int which) {
builder.show();
}

private void exportSite() {
final Blog currentBlog = WordPress.getCurrentBlog();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I recommend adding if (!NetworkUtils.checkConnection(getActivity())) return; before making the network call. Even though site settings won't appear if there's no connection, there's no guarantee that won't change, and it's possible the connection could exist when settings appears but is lost by the time the user chooses to export.

if (currentBlog.isDotcomFlag()) {
final ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "", getActivity().getString(R.string.exporting_content_progress), true, true);
WordPress.getRestClientUtils().exportContentAll(currentBlog.getDotComBlogId(), new RestRequest.Listener() {
@Override
public void onResponse(JSONObject response) {
if (isAdded()) {
progressDialog.dismiss();
Snackbar.make(getView(), R.string.export_email_sent, Snackbar.LENGTH_LONG).show();
}
}
}, new RestRequest.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (isAdded()) {
progressDialog.dismiss();
}
}
});
}
}

private void deleteSite() {
final Blog currentBlog = WordPress.getCurrentBlog();
if (currentBlog.isDotcomFlag()) {
Expand Down
5 changes: 4 additions & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,6 @@
<string name="confirm_delete_site">Confirm Delete Site</string>
<string name="confirm_delete_site_prompt">Please type in %1$s in the field below to confirm. Your site will then be gone forever.</string>
<string name="site_settings_export_content_title">Export content</string>
<string name="export_content_message">Currently exporting is only available through the web interface. Please go to WordPress.com on your browser to export content.</string>
<string name="error_deleting_site">Error deleting site</string>
<string name="error_deleting_site_summary">There was an error in deleting your site. Please contact support for more assistance</string>
<string name="primary_domain">Primary Domain</string>
Expand All @@ -1381,6 +1380,10 @@
<string name="pending_email_change_snackbar">Click the verification link in the email sent to %1$s to confirm your new address</string>
<string name="primary_site">Primary site</string>
<string name="web_address">Web Address</string>
<string name="exporting_content_progress">Exporting content…</string>
<string name="export_email_sent">Export email sent!</string>
<string name="export_your_content">Export your content</string>
<string name="export_your_content_message">Your posts, pages, and settings will be emailed to you at %s.</string>

<!-- Plans -->
<string name="plan">Plan</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ public void getSitePurchases(String siteId, Listener listener, ErrorListener err
get(path, listener, errorListener);
}

public void exportContentAll(String siteId, Listener listener, ErrorListener errorListener) {
String path = String.format("sites/%s/exports/start", siteId);
post(path, listener, errorListener);
}

/**
* Make GET request
*/
Expand Down