mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 12:22:08 +01:00
Merge pull request #36 from di72nn/feature_followed_tags
Add "Followed tags" listing
This commit is contained in:
commit
93ee2b896a
6 changed files with 77 additions and 7 deletions
|
@ -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();
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,17 @@ 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) {" +
|
||||
" try {" +
|
||||
" 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;" +
|
||||
" } catch(e) {}" +
|
||||
" }" +
|
||||
" var userProfile = JSON.stringify(gon.user);" +
|
||||
" AndroidBridge.setUserProfile(userProfile.toString());" +
|
||||
" } " +
|
||||
|
@ -108,6 +122,34 @@ public class Helpers {
|
|||
|
||||
// End
|
||||
sb.append("</body></html>");
|
||||
wv.loadData(sb.toString(), "text/html", "UTF-16");
|
||||
wv.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
||||
}
|
||||
|
||||
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();
|
||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||
sb.append(String.format(Locale.getDefault(),
|
||||
"<a href='https://%s/followed_tags' style='color: #000000; text-decoration: none;'>%s</a>",
|
||||
appSettings.getPodDomain(), app.getString(R.string.all_tags)));
|
||||
sb.append("<hr style='height:5px;' />");
|
||||
for (String tag: profile.getFollowedTags()) {
|
||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||
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.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -173,4 +173,6 @@
|
|||
<string name="app_hashtag" translatable="false">#DiasporaForAndroid</string>
|
||||
|
||||
<string name="toast_set_proxy_failed">Warning: Could not set network proxy…</string>
|
||||
|
||||
<string name="all_tags">All tags</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue