1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-06-16 16:44:53 +02:00

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; 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: { case R.id.nav_followed_tags: {
if (Helpers.isOnline(MainActivity.this)) { 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); setTitle(R.string.jb_followed_tags);
} else { } else {
snackbarNoInternet.show(); snackbarNoInternet.show();

View file

@ -71,6 +71,7 @@ public class AppSettings {
public static final String PODUSERPROFILE_ID = "podUserProfile_guid"; public static final String PODUSERPROFILE_ID = "podUserProfile_guid";
public static final String PODDOMAIN = "podDomain"; public static final String PODDOMAIN = "podDomain";
public static final String PODUSERPROFILE_ASPECTS = "podUserProfile_aspects"; 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_ENABLED = "pref_key_proxy_enabled";
public static final String PROXY_WAS_ENABLED = "wasProxyEnabled"; public static final String PROXY_WAS_ENABLED = "wasProxyEnabled";
public static final String PROXY_HOST = "pref_key_proxy_host"; public static final String PROXY_HOST = "pref_key_proxy_host";
@ -156,6 +157,14 @@ public class AppSettings {
return aspects; 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") @SuppressLint("CommitPrefEdits")
public void setProxyEnabled(boolean enabled) { public void setProxyEnabled(boolean enabled) {
//commit instead of apply because the app is likely to be killed before apply is called. //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 guid;
private String name; private String name;
private PodAspect[] podAspects; private PodAspect[] podAspects;
private String[] followedTags;
private int notificationCount; private int notificationCount;
private int unreadMessagesCount; private int unreadMessagesCount;
@ -40,6 +41,7 @@ public class PodUserProfile {
guid = appSettings.getProfileId(); guid = appSettings.getProfileId();
name = appSettings.getName(); name = appSettings.getName();
podAspects = appSettings.getPodAspects(); podAspects = appSettings.getPodAspects();
followedTags = appSettings.getFollowedTags();
} }
public PodUserProfile(App app, Handler callbackHandler, WebUserProfileChangedListener listener) { public PodUserProfile(App app, Handler callbackHandler, WebUserProfileChangedListener listener) {
@ -94,6 +96,12 @@ public class PodUserProfile {
appSettings.setPodAspects(podAspects); appSettings.setPodAspects(podAspects);
} }
// Followed tags
if (json.has("android_app.followed_tags")
&& loadFollowedTags(json.getJSONArray("android_app.followed_tags"))) {
appSettings.setFollowedTags(followedTags);
}
isWebUserProfileLoaded = true; isWebUserProfileLoaded = true;
} catch (JSONException e) { } catch (JSONException e) {
Log.d(App.TAG, e.getMessage()); Log.d(App.TAG, e.getMessage());
@ -131,6 +139,10 @@ public class PodUserProfile {
return podAspects; return podAspects;
} }
public String[] getFollowedTags() {
return followedTags;
}
/* /*
* Private property setters * Private property setters
*/ */
@ -195,6 +207,14 @@ public class PodUserProfile {
return true; 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) { private boolean loadUnreadMessagesCount(final int unreadMessagesCount) {
if (this.unreadMessagesCount != unreadMessagesCount) { if (this.unreadMessagesCount != unreadMessagesCount) {
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.App;
import com.github.dfa.diaspora_android.R; 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.PodAspect;
import com.github.dfa.diaspora_android.data.PodUserProfile; import com.github.dfa.diaspora_android.data.PodUserProfile;
import java.util.Locale;
public class Helpers { public class Helpers {
public static boolean isOnline(Context context) { 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}] // 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() {" + wv.loadUrl("javascript: ( function() {" +
" if (typeof gon !== 'undefined' && typeof gon.user !== 'undefined') {" + " 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);" + " var userProfile = JSON.stringify(gon.user);" +
" AndroidBridge.setUserProfile(userProfile.toString());" + " AndroidBridge.setUserProfile(userProfile.toString());" +
" } " + " } " +
@ -110,4 +122,27 @@ public class Helpers {
sb.append("</body></html>"); sb.append("</body></html>");
wv.loadData(sb.toString(), "text/html", "UTF-16"); 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:icon="@drawable/ic_person_black_24dp"
android:title="@string/jb_profile" /> android:title="@string/jb_profile" />
<!-- TODO followed_tags currently not implemented as single viewable page
(0.5.7.1-paf04894e, 2016 March 20) -->
<item <item
android:id="@+id/nav_followed_tags" android:id="@+id/nav_followed_tags"
android:icon="@drawable/jb_tag2" android:icon="@drawable/jb_tag2"
android:title="@string/jb_followed_tags" android:title="@string/jb_followed_tags" />
android:visible="false" />
<item <item
android:id="@+id/nav_aspects" android:id="@+id/nav_aspects"
android:icon="@drawable/jb_aspects" android:icon="@drawable/jb_aspects"