1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-12-22 19:08:03 +01:00

Rework app to use new DiasporaPod class

This commit is contained in:
Gregor Santner 2016-10-07 02:43:12 +02:00
parent 654a00d647
commit c550c2474e
14 changed files with 156 additions and 70 deletions

View file

@ -28,6 +28,8 @@ import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.data.DiasporaPodList;
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod;
import com.github.dfa.diaspora_android.data.PodUserProfile;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AvatarImageLoader;

View file

@ -236,7 +236,9 @@ public class AboutActivity extends AppCompatActivity {
osVersion.setText(getString(R.string.fragment_debug__android_version, Build.VERSION.RELEASE));
deviceName.setText(getString(R.string.fragment_debug__device_name, Build.MANUFACTURER + " " + Build.MODEL));
podDomain.setText(getString(R.string.fragment_debug__pod_domain, settings.getPodDomain()));
if (settings.getPod() != null) {
podDomain.setText(getString(R.string.fragment_debug__pod_domain, settings.getPod().getName()));
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();

View file

@ -60,6 +60,7 @@ import android.widget.Toast;
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.DiasporaPodList;
import com.github.dfa.diaspora_android.data.PodUserProfile;
import com.github.dfa.diaspora_android.fragment.BrowserFragment;
import com.github.dfa.diaspora_android.fragment.CustomFragment;
@ -178,7 +179,7 @@ public class MainActivity extends AppCompatActivity
}
});
if(!appSettings.hasPodDomain()) {
if(!appSettings.hasPod()) {
AppLog.d(this, "We have no pod. Show PodSelectionFragment");
showFragment(getFragment(PodSelectionFragment.TAG));
} else {
@ -324,8 +325,8 @@ public class MainActivity extends AppCompatActivity
if (!appSettings.getName().equals("")) {
navheaderTitle.setText(appSettings.getName());
}
if (!appSettings.getPodDomain().equals("")) {
navheaderDescription.setText(appSettings.getPodDomain());
if (appSettings.getPod() != null) {
navheaderDescription.setText(appSettings.getPod().getName());
}
String avatarUrl = appSettings.getAvatarUrl();
if (!avatarUrl.equals("")) {
@ -356,6 +357,8 @@ public class MainActivity extends AppCompatActivity
navMenu.findItem(R.id.nav_mentions).setVisible(appSettings.isVisibleInNavMentions());
navMenu.findItem(R.id.nav_profile).setVisible(appSettings.isVisibleInNavProfile());
navMenu.findItem(R.id.nav_public).setVisible(appSettings.isVisibleInNavPublic_activities());
// Hide all pod related options if no pod is selected
navMenu.setGroupVisible(navMenu.findItem(R.id.nav_exit).getGroupId(), appSettings.getPod() != null);
}
@OnClick(R.id.main__topbar)
@ -397,6 +400,7 @@ public class MainActivity extends AppCompatActivity
}
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
appSettings.setPod(null);
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView());
showFragment(getFragment(PodSelectionFragment.TAG));
} else if (ACTION_CLEAR_CACHE.equals(action)) {

View file

@ -35,7 +35,10 @@ import android.view.MenuItem;
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.DiasporaPodList;
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
/**
* @author vanitas
@ -124,21 +127,22 @@ public class SettingsActivity extends AppCompatActivity {
@Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
Intent intent = new Intent(getActivity(), MainActivity.class);
String podDomain = ((App) getActivity().getApplication()).getSettings().getPodDomain();
App app = ((App) getActivity().getApplication());
DiasporaUrlHelper diasporaUrlHelper = new DiasporaUrlHelper(app.getSettings());
switch (preference.getTitleRes()) {
case R.string.pref_title__personal_settings: {
intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/user/edit");
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getPersonalSettingsUrl());
break;
}
case R.string.pref_title__manage_tags: {
intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/tag_followings/manage");
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageTagsUrl());
break;
}
case R.string.pref_title__manage_contacts: {
intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/contacts");
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageContactsUrl());
break;
}
case R.string.pref_title__change_account: {

View file

@ -23,6 +23,11 @@ import android.content.Context;
import android.content.SharedPreferences;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod;
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod.DiasporaPodUrl;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Settings
@ -32,6 +37,7 @@ public class AppSettings {
private final SharedPreferences prefApp;
private final SharedPreferences prefPod;
private final Context context;
private DiasporaPod currentPod0Cached;
public AppSettings(Context context) {
this.context = context.getApplicationContext();
@ -138,24 +144,44 @@ public class AppSettings {
setString(prefPod, R.string.pref_key__podprofile_name, name);
}
public String getPodDomain() {
return getString(prefPod, R.string.pref_key__poddomain, "");
// TODO: Remove legacy at some time ;)
public void upgradeLegacyPoddomain() {
String legacy = getString(prefPod, R.string.pref_key__poddomain_legacy, "");
if (!legacy.equals("")) {
DiasporaPod pod = new DiasporaPod();
pod.setName(legacy);
pod.getPodUrls().add(new DiasporaPodUrl().setHost(legacy));
setPod(pod);
}
}
public void setPodDomain(String podDomain) {
setString(prefPod, R.string.pref_key__poddomain, podDomain);
public DiasporaPod getPod() {
upgradeLegacyPoddomain();
if (currentPod0Cached == null) {
String pref = getString(prefPod, R.string.pref_key__current_pod_0, "");
try {
currentPod0Cached = new DiasporaPod().fromJson(new JSONObject(pref));
} catch (JSONException e) {
currentPod0Cached = null;
}
}
return currentPod0Cached;
}
public boolean hasPodDomain() {
return !getString(prefPod, R.string.pref_key__poddomain, "").equals("");
public void setPod(DiasporaPod pod) {
try {
setString(prefPod, R.string.pref_key__current_pod_0,
pod == null ? null : pod.toJson().toString());
currentPod0Cached = pod;
} catch (JSONException ignored) {
}
}
public String[] getPreviousPodlist() {
return getStringArray(prefApp, R.string.pref_key__previous_podlist);
}
public void setPreviousPodlist(String[] pods) {
setStringArray(prefApp, R.string.pref_key__previous_podlist, pods);
public boolean hasPod() {
upgradeLegacyPoddomain();
return !getString(prefPod, R.string.pref_key__current_pod_0, "").equals("");
}
public void setPodAspects(PodAspect[] aspects) {

View file

@ -1,5 +1,7 @@
package com.github.dfa.diaspora_android.data;
import android.support.annotation.NonNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
@ -287,6 +289,7 @@ public class DiasporaPodList implements Iterable<DiasporaPodList.DiasporaPod>, S
/*
* Getter & Setter
*/
@NonNull
public List<DiasporaPodUrl> getPodUrls() {
return podUrls;
}
@ -296,6 +299,7 @@ public class DiasporaPodList implements Iterable<DiasporaPodList.DiasporaPod>, S
return this;
}
@NonNull
public List<String> getMainLangs() {
return mainLangs;
}
@ -312,6 +316,16 @@ public class DiasporaPodList implements Iterable<DiasporaPodList.DiasporaPod>, S
return this;
}
/**
* Returns the first DiasporaPodUrl in the list
*/
public DiasporaPodUrl getPodUrl(){
if(podUrls.size() > 0){
return podUrls.get(0);
}
return null;
}
public DiasporaPod appendPodUrls(DiasporaPodUrl... values) {
for (DiasporaPodUrl value : values) {
this.podUrls.add(value);

View file

@ -70,8 +70,8 @@ public class PodAspect {
public String toHtmlLink(final App app) {
final AppSettings appSettings = app.getSettings();
return String.format(Locale.getDefault(),
"<a href='https://%s/aspects?a_ids[]=%d' style='color: #000000; text-decoration: none;'>%s</a>",
appSettings.getPodDomain(), id, name);
"<a href='%s/aspects?a_ids[]=%d' style='color: #000000; text-decoration: none;'>%s</a>",
appSettings.getPod().getPodUrl().getBaseUrl(), id, name);
}
@Override

View file

@ -208,7 +208,7 @@ public class PodSelectionFragment extends CustomFragment implements SearchView.O
System.out.println(accepted + ": " + pod.toString());
if (accepted) {
//TODO: Rework for new pod url system ;)
app.getSettings().setPodDomain(pod.getPodUrls().get(0).getHost());
app.getSettings().setPod(pod);
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

View file

@ -21,6 +21,8 @@ package com.github.dfa.diaspora_android.util;
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.DiasporaPodList;
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod;
import com.github.dfa.diaspora_android.data.PodAspect;
/**
@ -31,7 +33,6 @@ import com.github.dfa.diaspora_android.data.PodAspect;
public class DiasporaUrlHelper {
private final AppSettings settings;
public static final String HTTPS = "https://";
public static final String SUBURL_NOTIFICATIONS = "/notifications";
public static final String SUBURL_POSTS = "/posts/";
public static final String SUBURL_STREAM = "/stream";
@ -49,6 +50,9 @@ public class DiasporaUrlHelper {
public static final String SUBURL_FOLOWED_TAGS = "/followed_tags";
public static final String SUBURL_ASPECTS = "/aspects";
public static final String SUBURL_STATISTICS = "/statistics";
public static final String SUBURL_PERSONAL_SETTINGS = "/user/edit";
public static final String SUBURL_MANAGE_TAGS = "/tag_followings/manage";
public static final String SUBURL_MANAGE_CONTACTS = "/contacts";
public static final String URL_BLANK = "about:blank";
public DiasporaUrlHelper(AppSettings settings) {
@ -56,17 +60,22 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url of the pod set in AppSettings.
* Return a url of the pod set in AppSettings.
* Eg. https://pod.geraspora.de
*
* @return https://(pod-domain.tld)
*/
public String getPodUrl() {
return HTTPS + settings.getPodDomain();
DiasporaPod pod = settings.getPod();
if (pod != null){
return settings.getPod().getPodUrl().getBaseUrl();
}
return "http://127.0.0.1";
}
/**
* Return a https url that points to the stream of the configured diaspora account
* Return a url that points to the stream of the configured diaspora account
*
* @return https://(pod-domain.tld)/stream
*/
@ -75,7 +84,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that points to the notifications feed of the configured diaspora account
* Return a url that points to the notifications feed of the configured diaspora account
*
* @return https://(pod-domain.tld)/notifications
*/
@ -84,7 +93,7 @@ public class DiasporaUrlHelper {
}
/**
* Returns a https url that points to the post with the id postId
* Returns a url that points to the post with the id postId
*
* @return https://(pod-domain.tld)/posts/(postId)
*/
@ -93,7 +102,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that points to the conversations overview of the registered diaspora account
* Return a url that points to the conversations overview of the registered diaspora account
*
* @return https://(pod-domain.tld)/conversations
*/
@ -102,7 +111,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that points to the new-post form that lets the user create a new post
* Return a url that points to the new-post form that lets the user create a new post
*
* @return https://(pod-domain.tld)/status_messages/new
*/
@ -111,7 +120,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that shows the profile of the currently registered diaspora account
* Return a url that shows the profile of the currently registered diaspora account
*
* @return https://(pod-domain.tld)/people/(profileId)
*/
@ -120,7 +129,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that shows the profile of the user with user id profileId
* Return a url that shows the profile of the user with user id profileId
*
* @param profileId Id of the profile to be shown
* @return https://(pod-domain.tld)/people/(profileId)
@ -130,7 +139,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that points to the activities feed of the currently registered diaspora account
* Return a url that points to the activities feed of the currently registered diaspora account
*
* @return https://(pod-domain.tld)/activity
*/
@ -139,7 +148,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that points to the feed of posts that were liked by the currently registered diaspora account
* Return a url that points to the feed of posts that were liked by the currently registered diaspora account
*
* @return https://(pod-domain.tld)/liked
*/
@ -148,7 +157,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that points to the stream of posts that were commented by the currently registered diaspora account
* Return a url that points to the stream of posts that were commented by the currently registered diaspora account
*
* @return https://(pod-domain.tld)/commented
*/
@ -157,7 +166,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that points to the stream of posts in which the currently registered diaspora account has been mentioned in
* Return a url that points to the stream of posts in which the currently registered diaspora account has been mentioned in
*
* @return https://(pod-domain.tld)/mentions
*/
@ -166,7 +175,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that points to the stream of public posts
* Return a url that points to the stream of public posts
*
* @return https://(pod-domain.tld)/public
*/
@ -175,7 +184,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that toggles between mobile and desktop view when opened
* Return a url that toggles between mobile and desktop view when opened
*
* @return https://(pod-domain.tld)/mobile/toggle
*/
@ -184,7 +193,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that queries posts for the given hashtag query
* Return a url that queries posts for the given hashtag query
*
* @param query hashtag to be searched
* @return https://(pod-domain.tld)/tags/query
@ -194,7 +203,7 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that queries user accounts for query
* Return a url that queries user accounts for query
*
* @param query search term
* @return https://(pod-domain.tld)/people.mobile?q=(query)
@ -204,13 +213,37 @@ public class DiasporaUrlHelper {
}
/**
* Return a https url that points to the statistics page of the pod.
* Return a url that points to the statistics page of the pod.
* @return https://(pod-domain.tld)/statistics
*/
public String getStatisticsUrl() {
return getPodUrl() + SUBURL_STATISTICS;
}
/**
* Return a url that points to the personal settings page of the pod.
* @return https://(pod-domain.tld)/user/edit
*/
public String getPersonalSettingsUrl() {
return getPodUrl() + SUBURL_PERSONAL_SETTINGS;
}
/**
* Return a url that points to the manage tags page of the pod.
* @return https://(pod-domain.tld)/tag_followings/manage
*/
public String getManageTagsUrl() {
return getPodUrl() + SUBURL_MANAGE_TAGS;
}
/**
* Return a url that points to the manage tags page of the pod.
* @return https://(pod-domain.tld)/contacts
*/
public String getManageContactsUrl() {
return getPodUrl() + SUBURL_MANAGE_CONTACTS;
}
/**
* Returns the url of the blank WebView
*

View file

@ -29,6 +29,7 @@ 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.DiasporaPodList;
import com.github.dfa.diaspora_android.data.PodAspect;
import com.github.dfa.diaspora_android.data.PodUserProfile;
@ -139,16 +140,17 @@ public class WebHelper {
// Content
AppSettings appSettings = app.getSettings();
String pod0BaseUrl = appSettings.getPod().getPodUrl().getBaseUrl();
sb.append("<span style='margin-left: 30px; '></span>&raquo; &nbsp;");
sb.append(String.format(Locale.getDefault(),
"<a href='https://%s/followed_tags' style='color: #000000; text-decoration: none;'><b>%s</b></a>",
appSettings.getPodDomain(), app.getString(R.string.all_tags)));
"<a href='%s/followed_tags' style='color: #000000; text-decoration: none;'><b>%s</b></a>",
pod0BaseUrl, 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>&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));
"<a href='%s/tags/%s' style='color: #000000; text-decoration: none;'>#%s</a>",
pod0BaseUrl, tag, tag));
sb.append("<hr style='height:5px;' />");
}

View file

@ -19,7 +19,6 @@
package com.github.dfa.diaspora_android.webview;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.LocalBroadcastManager;
import android.webkit.CookieManager;
import android.webkit.WebView;
@ -39,7 +38,7 @@ public class CustomWebViewClient extends WebViewClient {
//Open non-diaspora links in customtab/external browser
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.contains(app.getSettings().getPodDomain())) {
if (!url.contains(app.getSettings().getPod().getPodUrl().getHost())) {
Intent i = new Intent(MainActivity.ACTION_OPEN_EXTERNAL_URL);
i.putExtra(MainActivity.EXTRA_URL, url);
LocalBroadcastManager.getInstance(app.getApplicationContext()).sendBroadcast(i);
@ -57,7 +56,7 @@ public class CustomWebViewClient extends WebViewClient {
if (cookies != null) {
cookieManager.setCookie(url, cookies);
cookieManager.setCookie("https://" + app.getSettings().getPodDomain(), cookies);
cookieManager.setCookie(app.getSettings().getPod().getPodUrl().getBaseUrl(), cookies);
//for (String c : cookies.split(";")) {
//AppLog.d(this, "Cookie: " + c.split("=")[0] + " Value:" + c.split("=")[1]);
//}

View file

@ -48,6 +48,24 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
tools:text="Geraspora"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin_half"
android:text="@string/pod_address"
android:textAppearance="@style/AppTheme.TextAppearance.Caption"/>
<EditText
android:id="@+id/podselection__dialog__edit_podaddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin_half"
android:ems="10"
android:hint="@string/pod_address"
android:inputType="textPersonName"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
tools:text="pod.geraspora.de"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -78,24 +96,6 @@
android:text="https"/>
</RadioGroup>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin_half"
android:text="@string/pod_address"
android:textAppearance="@style/AppTheme.TextAppearance.Caption"/>
<EditText
android:id="@+id/podselection__dialog__edit_podaddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin_half"
android:ems="10"
android:hint="@string/pod_address"
android:inputType="textPersonName"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
tools:text="pod.geraspora.de"/>
<LinearLayout
android:layout_width="match_parent"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="none">
<group android:checkableBehavior="none" android:id="@+id/nav_group__pod">
<item
android:id="@+id/nav_stream"
android:icon="@drawable/ic_stream"

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Key Names (Untranslatable) -->
<string name="pref_key__poddomain" translatable="false">podDomain</string>
<string name="pref_key__previous_podlist" translatable="false">previousPodlist</string>
<string name="pref_key__poddomain_legacy" translatable="false">podDomain</string>
<string name="pref_key__current_pod_0" translatable="false">pref_key__current_pod_0</string>
<string name="pref_key__font_size" translatable="false">pref_key_font_size</string>
<string name="pref_key__intellihide_toolbars" translatable="false">pref_key_intellihide_toolbars</string>
<string name="pref_catkey__pod_settings" translatable="false">pref_key_category_pod_settings</string>