Add "Followed tags" listing

This commit is contained in:
Dmitriy Bogdanov 2016-07-18 16:02:18 +04:00
parent 3ed4c77e4d
commit 0072f22845
No known key found for this signature in database
GPG Key ID: F396CC2653B8F64D
5 changed files with 67 additions and 6 deletions

View File

@ -858,10 +858,10 @@ public class MainActivity extends AppCompatActivity
}
break;
// TODO followed_tags currently not implemented as single viewable page (0.5.7.1-paf04894e, 2016 March 20)
case R.id.nav_followed_tags: {
if (Helpers.isOnline(MainActivity.this)) {
webView.loadUrl("https://" + podDomain + "/followed_tags");
// webView.loadUrl("https://" + podDomain + "/followed_tags");
Helpers.showFollowedTagsList(webView, app);
setTitle(R.string.jb_followed_tags);
} else {
snackbarNoInternet.show();

View File

@ -71,6 +71,7 @@ public class AppSettings {
public static final String PODUSERPROFILE_ID = "podUserProfile_guid";
public static final String PODDOMAIN = "podDomain";
public static final String PODUSERPROFILE_ASPECTS = "podUserProfile_aspects";
public static final String PODUSERPROFILE_FOLLOWED_TAGS = "podUserProfile_followedTags";
public static final String PROXY_ENABLED = "pref_key_proxy_enabled";
public static final String PROXY_WAS_ENABLED = "wasProxyEnabled";
public static final String PROXY_HOST = "pref_key_proxy_host";
@ -156,6 +157,14 @@ public class AppSettings {
return aspects;
}
public String[] getFollowedTags() {
return getStringArray(prefPod, PREF.PODUSERPROFILE_FOLLOWED_TAGS);
}
public void setFollowedTags(String[] tags) {
setStringArray(prefPod, PREF.PODUSERPROFILE_FOLLOWED_TAGS, tags);
}
@SuppressLint("CommitPrefEdits")
public void setProxyEnabled(boolean enabled) {
//commit instead of apply because the app is likely to be killed before apply is called.

View File

@ -28,6 +28,7 @@ public class PodUserProfile {
private String guid;
private String name;
private PodAspect[] podAspects;
private String[] followedTags;
private int notificationCount;
private int unreadMessagesCount;
@ -40,6 +41,7 @@ public class PodUserProfile {
guid = appSettings.getProfileId();
name = appSettings.getName();
podAspects = appSettings.getPodAspects();
followedTags = appSettings.getFollowedTags();
}
public PodUserProfile(App app, Handler callbackHandler, WebUserProfileChangedListener listener) {
@ -94,6 +96,12 @@ public class PodUserProfile {
appSettings.setPodAspects(podAspects);
}
// Followed tags
if (json.has("android_app.followed_tags")
&& loadFollowedTags(json.getJSONArray("android_app.followed_tags"))) {
appSettings.setFollowedTags(followedTags);
}
isWebUserProfileLoaded = true;
} catch (JSONException e) {
Log.d(App.TAG, e.getMessage());
@ -131,6 +139,10 @@ public class PodUserProfile {
return podAspects;
}
public String[] getFollowedTags() {
return followedTags;
}
/*
* Private property setters
*/
@ -195,6 +207,14 @@ public class PodUserProfile {
return true;
}
private boolean loadFollowedTags(final JSONArray jsonTags) throws JSONException {
followedTags = new String[jsonTags.length()];
for (int i = 0; i < jsonTags.length(); i++) {
followedTags[i] = jsonTags.getString(i);
}
return true;
}
private boolean loadUnreadMessagesCount(final int unreadMessagesCount) {
if (this.unreadMessagesCount != unreadMessagesCount) {
this.unreadMessagesCount = unreadMessagesCount;

View File

@ -30,9 +30,12 @@ import android.webkit.WebView;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.data.PodAspect;
import com.github.dfa.diaspora_android.data.PodUserProfile;
import java.util.Locale;
public class Helpers {
public static boolean isOnline(Context context) {
@ -86,6 +89,15 @@ public class Helpers {
// aspects":[{"id":124934,"name":"Friends","selected":true},{"id":124937,"name":"Liked me","selected":false},{"id":124938,"name":"Follow","selected":false},{"id":128327,"name":"Nur ich","selected":false}]
wv.loadUrl("javascript: ( function() {" +
" if (typeof gon !== 'undefined' && typeof gon.user !== 'undefined') {" +
" var followed_tags = document.getElementById(\"followed_tags\");" +
" if(followed_tags != null) {" +
" var links = followed_tags.nextElementSibling.children[0].children;" +
" var tags = [];" +
" for(var i = 0; i < links.length - 1; i++) {" + // the last element is "Manage followed tags" link
" tags.push(links[i].innerText.substring(1));" +
" }" +
" gon.user[\"android_app.followed_tags\"] = tags;" +
" }" +
" var userProfile = JSON.stringify(gon.user);" +
" AndroidBridge.setUserProfile(userProfile.toString());" +
" } " +
@ -110,4 +122,27 @@ public class Helpers {
sb.append("</body></html>");
wv.loadData(sb.toString(), "text/html", "UTF-16");
}
public static void showFollowedTagsList(final WebView wv, final App app) {
wv.stopLoading();
PodUserProfile profile = app.getPodUserProfile();
StringBuilder sb = new StringBuilder();
sb.append("<html><body style='margin-top: 25px; margin-left:auto;margin-right:auto; font-size: 400%;'>");
// Content
AppSettings appSettings = app.getSettings();
for (String tag: profile.getFollowedTags()) {
sb.append("<span style='margin-left: 30px; '></span>&raquo; &nbsp;");
sb.append(String.format(Locale.getDefault(),
"<a href='https://%s/tags/%s' style='color: #000000; text-decoration: none;'>#%s</a>",
appSettings.getPodDomain(), tag, tag));
sb.append("<hr style='height:5px;' />");
}
// End
sb.append("</body></html>");
wv.loadData(sb.toString(), "text/html", "UTF-16");
}
}

View File

@ -12,13 +12,10 @@
android:icon="@drawable/ic_person_black_24dp"
android:title="@string/jb_profile" />
<!-- TODO followed_tags currently not implemented as single viewable page
(0.5.7.1-paf04894e, 2016 March 20) -->
<item
android:id="@+id/nav_followed_tags"
android:icon="@drawable/jb_tag2"
android:title="@string/jb_followed_tags"
android:visible="false" />
android:title="@string/jb_followed_tags" />
<item
android:id="@+id/nav_aspects"
android:icon="@drawable/jb_aspects"