Skip to content

Commit 46eb536

Browse files
committed
Not showing DetailListPreferences if there is no list
1 parent 29f2a1d commit 46eb536

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class MySiteFragment extends Fragment
4848
private WPTextView mBlogSubtitleTextView;
4949
private LinearLayout mLookAndFeelHeader;
5050
private RelativeLayout mThemesContainer;
51+
private View mConfigurationHeader;
52+
private View mSettingsView;
5153
private View mFabView;
5254
private LinearLayout mNoSiteView;
5355
private ScrollView mScrollView;
@@ -116,6 +118,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
116118
mBlogSubtitleTextView = (WPTextView) rootView.findViewById(R.id.my_site_subtitle_label);
117119
mLookAndFeelHeader = (LinearLayout) rootView.findViewById(R.id.my_site_look_and_feel_header);
118120
mThemesContainer = (RelativeLayout) rootView.findViewById(R.id.row_themes);
121+
mConfigurationHeader = rootView.findViewById(R.id.row_configuration);
122+
mSettingsView = rootView.findViewById(R.id.row_settings);
119123
mScrollView = (ScrollView) rootView.findViewById(R.id.scroll_view);
120124
mNoSiteView = (LinearLayout) rootView.findViewById(R.id.no_site_view);
121125
mNoSiteDrakeImageView = (ImageView) rootView.findViewById(R.id.my_site_no_site_view_drake);
@@ -186,7 +190,7 @@ public void onClick(View v) {
186190
}
187191
});
188192

189-
rootView.findViewById(R.id.row_settings).setOnClickListener(new View.OnClickListener() {
193+
mSettingsView.setOnClickListener(new View.OnClickListener() {
190194
@Override
191195
public void onClick(View v) {
192196
ActivityLauncher.viewBlogSettingsForResult(getActivity(), mBlog);
@@ -304,6 +308,11 @@ private void refreshBlogDetails() {
304308
mLookAndFeelHeader.setVisibility(themesVisibility);
305309
mThemesContainer.setVisibility(themesVisibility);
306310

311+
// show settings for all self-hosted to expose Delete Site
312+
int settingsVisibility = mBlog.isAdmin() || !mBlog.isDotcomFlag() ? View.VISIBLE : View.GONE;
313+
mConfigurationHeader.setVisibility(settingsVisibility);
314+
mSettingsView.setVisibility(settingsVisibility);
315+
307316
mBlavatarImageView.setImageUrl(GravatarUtils.blavatarFromUrl(mBlog.getUrl(), mBlavatarSz), WPNetworkImageView.ImageType.BLAVATAR);
308317

309318
String blogName = StringUtils.unescapeHTML(mBlog.getBlogName());

WordPress/src/main/java/org/wordpress/android/ui/prefs/SelfHostedSiteSettings.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SelfHostedSiteSettings extends SiteSettingsInterface {
6060

6161
// Requires WordPress 4.5.x or higher
6262
private static final int REQUIRED_MAJOR_VERSION = 4;
63-
private static final int REQUIRED_MINOR_VERSION = 5;
63+
private static final int REQUIRED_MINOR_VERSION = 3;
6464

6565
private static final String OPTION_ALLOWED = "open";
6666
private static final String OPTION_DISALLOWED = "closed";
@@ -133,11 +133,18 @@ public void onFailure(long id, final Exception error) {
133133
*/
134134
@Override
135135
protected void fetchRemoteData() {
136-
Object[] params = {mBlog.getRemoteBlogId(), mBlog.getUsername(), mBlog.getPassword()};
137136

138-
// Need two interfaces or the first call gets aborted
139-
instantiateInterface().callAsync(mOptionsCallback, ApiHelper.Methods.GET_OPTIONS, params);
140-
instantiateInterface().callAsync(mCategoriesCallback, ApiHelper.Methods.GET_CATEGORIES, params);
137+
Thread thread = new Thread(new Runnable() {
138+
@Override
139+
public void run() {
140+
Object[] params = {mBlog.getRemoteBlogId(), mBlog.getUsername(), mBlog.getPassword()};
141+
142+
// Need two interfaces or the first call gets aborted
143+
instantiateInterface().callAsync(mOptionsCallback, ApiHelper.Methods.GET_OPTIONS, params);
144+
instantiateInterface().callAsync(mCategoriesCallback, ApiHelper.Methods.GET_CATEGORIES, params);
145+
}
146+
});
147+
thread.run();
141148
}
142149

143150
/**

WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public class SiteSettingsFragment extends PreferenceFragment
114114
*/
115115
private static final int REGION_SUBSTRING_INDEX = 3;
116116

117+
private static final long FETCH_DELAY = 1000;
118+
117119
// Reference to blog obtained from passed ID (ARG_LOCAL_BLOG_ID)
118120
private Blog mBlog;
119121

@@ -214,15 +216,17 @@ public void onPause() {
214216
public void onResume() {
215217
super.onResume();
216218

217-
new Handler().postDelayed(new Runnable() {
218-
@Override
219-
public void run() {
220-
// initialize settings with locally cached values, fetch remote on first pass
221-
mSiteSettings.init(mShouldFetch);
222-
// stop future calls from fetching remote settings
223-
mShouldFetch = false;
224-
}
225-
}, 1000);
219+
if (mShouldFetch) {
220+
new Handler().postDelayed(new Runnable() {
221+
@Override
222+
public void run() {
223+
// initialize settings with locally cached values, fetch remote on first pass
224+
mSiteSettings.init(mShouldFetch);
225+
// stop future calls from fetching remote settings
226+
}
227+
}, FETCH_DELAY);
228+
mShouldFetch = false;
229+
}
226230
}
227231

228232
@Override
@@ -328,6 +332,8 @@ public boolean onPreferenceClick(Preference preference) {
328332
} else if (preference == mPagingPref) {
329333
showPagingDialog();
330334
return true;
335+
} else if (preference == mCategoryPref || preference == mFormatPref) {
336+
return !shouldShowListPreference((DetailListPreference) preference);
331337
}
332338

333339
return false;
@@ -1096,6 +1102,10 @@ public void onClick(DialogInterface dialog, int whichButton) {
10961102
dialogBuilder.create().show();
10971103
}
10981104

1105+
private boolean shouldShowListPreference(DetailListPreference preference) {
1106+
return preference != null && preference.getEntries() != null && preference.getEntries().length > 0;
1107+
}
1108+
10991109
/**
11001110
* Generates display strings for given language codes. Used as entries in language preference.
11011111
*/

WordPress/src/main/java/org/xmlrpc/android/ApiHelper.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
import com.android.volley.DefaultRetryPolicy;
1111
import com.android.volley.NetworkResponse;
1212
import com.android.volley.RedirectError;
13-
import com.android.volley.Request;
14-
import com.android.volley.toolbox.JsonObjectRequest;
1513
import com.android.volley.toolbox.RequestFuture;
1614
import com.android.volley.toolbox.StringRequest;
1715
import com.google.gson.Gson;
1816

19-
import org.json.JSONObject;
2017
import org.wordpress.android.WordPress;
2118
import org.wordpress.android.analytics.AnalyticsTracker;
2219
import org.wordpress.android.datasets.CommentTable;
@@ -25,7 +22,6 @@
2522
import org.wordpress.android.models.Comment;
2623
import org.wordpress.android.models.CommentList;
2724
import org.wordpress.android.models.FeatureSet;
28-
import org.wordpress.android.networking.WPDelayedHurlStack;
2925
import org.wordpress.android.ui.media.MediaGridFragment.Filter;
3026
import org.wordpress.android.ui.stats.StatsUtils;
3127
import org.wordpress.android.ui.stats.StatsWidgetProvider;
@@ -34,20 +30,14 @@
3430
import org.wordpress.android.util.AppLog.T;
3531
import org.wordpress.android.util.DateTimeUtils;
3632
import org.wordpress.android.util.MapUtils;
37-
import org.wordpress.android.util.UrlUtils;
3833
import org.wordpress.android.util.helpers.MediaFile;
3934
import org.xmlpull.v1.XmlPullParser;
4035
import org.xmlpull.v1.XmlPullParserException;
4136

42-
import java.io.BufferedReader;
4337
import java.io.File;
4438
import java.io.FileNotFoundException;
4539
import java.io.IOException;
46-
import java.io.InputStream;
47-
import java.io.InputStreamReader;
4840
import java.io.StringReader;
49-
import java.net.URL;
50-
import java.security.GeneralSecurityException;
5141
import java.util.ArrayList;
5242
import java.util.HashMap;
5343
import java.util.HashSet;
@@ -59,7 +49,6 @@
5949
import java.util.regex.Matcher;
6050
import java.util.regex.Pattern;
6151

62-
import javax.net.ssl.HttpsURLConnection;
6352
import javax.net.ssl.SSLHandshakeException;
6453

6554
public class ApiHelper {

0 commit comments

Comments
 (0)