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

Aspect name as title (fixes#44 , fixes #47)

This commit is contained in:
Gregor Santner 2016-08-13 15:31:27 +02:00
parent 05819d6cf2
commit 4f148191f7
5 changed files with 105 additions and 54 deletions

View file

@ -11,6 +11,7 @@
- Click on profile picture now opens users profile
- Disabled backup functionality to prevent attackers to steal login cookies
- Allow slider customization
- Show aspect name after selection
# v0.1.4 (2016-07-31)
- by @vanitasvitae, @gsantner, @di72nn

View file

@ -220,7 +220,7 @@ public class MainActivity extends AppCompatActivity
@Override
public void onClick(View view) {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getNotificationsUrl());
webView.loadUrlNew(urls.getNotificationsUrl());
} else {
Snackbar.make(contentLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
@ -238,7 +238,7 @@ public class MainActivity extends AppCompatActivity
if (savedInstanceState == null) {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadData("", "text/html", null);
webView.loadUrl(url);
webView.loadUrlNew(url);
} else {
snackbarNoInternet.show();
}
@ -383,7 +383,7 @@ public class MainActivity extends AppCompatActivity
public void onClick(View view) {
navDrawer.closeDrawer(GravityCompat.START);
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getProfileUrl());
webView.loadUrlNew(urls.getProfileUrl());
} else {
snackbarNoInternet.show();
}
@ -488,7 +488,7 @@ public class MainActivity extends AppCompatActivity
if (loadUrl != null) {
webView.stopLoading();
navDrawer.closeDrawers();
webView.loadUrl(loadUrl);
webView.loadUrlNew(loadUrl);
}
}
@ -579,6 +579,8 @@ public class MainActivity extends AppCompatActivity
setTitle(R.string.nav_mentions);
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_PUBLIC)) {
setTitle(R.string.public_);
} else if (urls.isAspectUrl(url)){
setTitle(urls.getAspectNameFromUrl(url, app));
}
}
}
@ -621,7 +623,7 @@ public class MainActivity extends AppCompatActivity
switch (item.getItemId()) {
case R.id.action_notifications: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getNotificationsUrl());
webView.loadUrlNew(urls.getNotificationsUrl());
return true;
} else {
snackbarNoInternet.show();
@ -631,7 +633,7 @@ public class MainActivity extends AppCompatActivity
case R.id.action_conversations: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getConversationsUrl());
webView.loadUrlNew(urls.getConversationsUrl());
return true;
} else {
snackbarNoInternet.show();
@ -656,13 +658,13 @@ public class MainActivity extends AppCompatActivity
}
case R.id.action_toggle_desktop_page: {
webView.loadUrl(urls.getToggleMobileUrl());
webView.loadUrlNew(urls.getToggleMobileUrl());
return true;
}
case R.id.action_compose: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getNewPostUrl());
webView.loadUrlNew(urls.getNewPostUrl());
} else {
snackbarNoInternet.show();
}
@ -719,9 +721,9 @@ public class MainActivity extends AppCompatActivity
Snackbar.make(contentLayout, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show();
} else { // User have added a search tag
if (wasClickedOnSearchForPeople) {
webView.loadUrl(urls.getSearchPeopleUrl(cleanTag));
webView.loadUrlNew(urls.getSearchPeopleUrl(cleanTag));
} else {
webView.loadUrl(urls.getSearchTagsUrl(cleanTag));
webView.loadUrlNew(urls.getSearchTagsUrl(cleanTag));
}
}
@ -866,9 +868,8 @@ public class MainActivity extends AppCompatActivity
textToBeShared = sharedText;
}
webView.stopLoading();
webView.loadUrl(urls.getBlankUrl());
webView.loadUrl(urls.getNewPostUrl());
webView.loadUrlNew(urls.getBlankUrl());
webView.loadUrlNew(urls.getNewPostUrl());
}
/**
@ -877,7 +878,7 @@ public class MainActivity extends AppCompatActivity
* @param intent
*/
void handleSendSubject(Intent intent) {
webView.loadUrl(urls.getNewPostUrl());
webView.loadUrlNew(urls.getNewPostUrl());
String content = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_TEXT));
String subject = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_SUBJECT));
@ -890,9 +891,8 @@ public class MainActivity extends AppCompatActivity
final String sharedContent = WebHelper.escapeHtmlText(content);
textToBeShared = "**" + sharedSubject + "** " + sharedContent;
webView.stopLoading();
webView.loadUrl(urls.getBlankUrl());
webView.loadUrl(urls.getNewPostUrl());
webView.loadUrlNew(urls.getBlankUrl());
webView.loadUrlNew(urls.getNewPostUrl());
}
//TODO: Implement?
@ -954,7 +954,7 @@ public class MainActivity extends AppCompatActivity
switch (item.getItemId()) {
case R.id.nav_stream: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getStreamUrl());
webView.loadUrlNew(urls.getStreamUrl());
} else {
snackbarNoInternet.show();
}
@ -963,7 +963,7 @@ public class MainActivity extends AppCompatActivity
case R.id.nav_profile: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getProfileUrl());
webView.loadUrlNew(urls.getProfileUrl());
} else {
snackbarNoInternet.show();
}
@ -982,6 +982,7 @@ public class MainActivity extends AppCompatActivity
case R.id.nav_aspects: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrlNew(DiasporaUrlHelper.URL_BLANK);
WebHelper.showAspectList(webView, app);
setTitle(R.string.aspects);
} else {
@ -992,7 +993,7 @@ public class MainActivity extends AppCompatActivity
case R.id.nav_activities: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getActivityUrl());
webView.loadUrlNew(urls.getActivityUrl());
} else {
snackbarNoInternet.show();
}
@ -1001,7 +1002,7 @@ public class MainActivity extends AppCompatActivity
case R.id.nav_liked: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getLikedPostsUrl());
webView.loadUrlNew(urls.getLikedPostsUrl());
} else {
snackbarNoInternet.show();
}
@ -1010,7 +1011,7 @@ public class MainActivity extends AppCompatActivity
case R.id.nav_commented: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getCommentedUrl());
webView.loadUrlNew(urls.getCommentedUrl());
} else {
snackbarNoInternet.show();
}
@ -1019,7 +1020,7 @@ public class MainActivity extends AppCompatActivity
case R.id.nav_mentions: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getMentionsUrl());
webView.loadUrlNew(urls.getMentionsUrl());
} else {
snackbarNoInternet.show();
}
@ -1028,7 +1029,7 @@ public class MainActivity extends AppCompatActivity
case R.id.nav_public: {
if (WebHelper.isOnline(MainActivity.this)) {
webView.loadUrl(urls.getPublicUrl());
webView.loadUrlNew(urls.getPublicUrl());
} else {
snackbarNoInternet.show();
}

View file

@ -260,7 +260,7 @@ public class AppSettings {
}
public boolean isVisibleInNavHelp_license() {
return getBoolean(prefApp, R.string.pref_key__visibility_nav__help_license, false);
return getBoolean(prefApp, R.string.pref_key__visibility_nav__help_license, true);
}
public boolean isVisibleInNavPublic_activities() {
@ -268,27 +268,27 @@ public class AppSettings {
}
public boolean isVisibleInNavMentions() {
return getBoolean(prefApp, R.string.pref_key__visibility_nav__mentions, false);
return getBoolean(prefApp, R.string.pref_key__visibility_nav__mentions, true);
}
public boolean isVisibleInNavCommented() {
return getBoolean(prefApp, R.string.pref_key__visibility_nav__commented, false);
return getBoolean(prefApp, R.string.pref_key__visibility_nav__commented, true);
}
public boolean isVisibleInNavLiked() {
return getBoolean(prefApp, R.string.pref_key__visibility_nav__liked, false);
return getBoolean(prefApp, R.string.pref_key__visibility_nav__liked, true);
}
public boolean isVisibleInNavActivities() {
return getBoolean(prefApp, R.string.pref_key__visibility_nav__activities, false);
return getBoolean(prefApp, R.string.pref_key__visibility_nav__activities, true);
}
public boolean isVisibleInNavAspects() {
return getBoolean(prefApp, R.string.pref_key__visibility_nav__aspects, false);
return getBoolean(prefApp, R.string.pref_key__visibility_nav__aspects, true);
}
public boolean isVisibleInNavFollowed_tags() {
return getBoolean(prefApp, R.string.pref_key__visibility_nav__followed_tags, false);
return getBoolean(prefApp, R.string.pref_key__visibility_nav__followed_tags, true);
}
public boolean isVisibleInNavProfile() {

View file

@ -58,6 +58,7 @@ public class ContextMenuWebView extends NestedWebView {
private Context context;
private Activity parentActivity;
private String lasLoadUrl = "";
public ContextMenuWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
@ -110,7 +111,7 @@ public class ContextMenuWebView extends NestedWebView {
Uri source = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(source);
File destinationFile = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/"
+ System.currentTimeMillis()+".png");
+ System.currentTimeMillis() + ".png");
request.setDestinationUri(Uri.fromFile(destinationFile));
((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
Toast.makeText(context, context.getText(R.string.share__toast_saved_image_to_location) + " " +
@ -121,12 +122,12 @@ public class ContextMenuWebView extends NestedWebView {
break;
case ID_SHARE_IMAGE:
if(url != null) {
final Uri local = Uri.parse(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/"+System.currentTimeMillis()+".png");
if (url != null) {
final Uri local = Uri.parse(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
new ImageDownloadTask(null, local.getPath()) {
@Override
protected void onPostExecute(Bitmap result) {
Uri myUri= Uri.fromFile(new File(local.getPath()));
Uri myUri = Uri.fromFile(new File(local.getPath()));
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
@ -189,12 +190,22 @@ public class ContextMenuWebView extends NestedWebView {
}
}
public void loadUrlNew(String url){
stopLoading();
loadUrl(url);
}
@Override
public void loadUrl(String url) {
super.loadUrl(url);
Intent updateActivityTitleIntent = new Intent(MainActivity.ACTION_UPDATE_TITLE_FROM_URL);
updateActivityTitleIntent.putExtra(MainActivity.EXTRA_URL, getUrl());
LocalBroadcastManager.getInstance(context).sendBroadcast(updateActivityTitleIntent);
// Don't spam intents ;)
if (!lasLoadUrl.equals(url)) {
Intent updateActivityTitleIntent = new Intent(MainActivity.ACTION_UPDATE_TITLE_FROM_URL);
updateActivityTitleIntent.putExtra(MainActivity.EXTRA_URL, getUrl());
LocalBroadcastManager.getInstance(context).sendBroadcast(updateActivityTitleIntent);
}
lasLoadUrl = url;
}
public void setParentActivity(Activity activity) {

View file

@ -18,7 +18,10 @@
*/
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.PodAspect;
/**
* Helper class that provides easy access to specific urls related to diaspora
@ -54,140 +57,175 @@ public class DiasporaUrlHelper {
/**
* Return a https url of the pod set in AppSettings.
* Eg. https://pod.geraspora.de
*
* @return https://(pod-domain.tld)
*/
public String getPodUrl() {
return HTTPS+settings.getPodDomain();
return HTTPS + settings.getPodDomain();
}
/**
* Return a https url that points to the stream of the configured diaspora account
*
* @return https://(pod-domain.tld)/stream
*/
public String getStreamUrl() {
return getPodUrl()+SUBURL_STREAM;
return getPodUrl() + SUBURL_STREAM;
}
/**
* Return a https url that points to the notifications feed of the configured diaspora account
*
* @return https://(pod-domain.tld)/notifications
*/
public String getNotificationsUrl() {
return getPodUrl()+SUBURL_NOTIFICATIONS;
return getPodUrl() + SUBURL_NOTIFICATIONS;
}
/**
* Returns a https url that points to the post with the id postId
*
* @return https://(pod-domain.tld)/posts/(postId)
*/
public String getPostsUrl(long postId) {
return getPodUrl()+SUBURL_POSTS+postId;
return getPodUrl() + SUBURL_POSTS + postId;
}
/**
* Return a https url that points to the conversations overview of the registered diaspora account
*
* @return https://(pod-domain.tld)/conversations
*/
public String getConversationsUrl() {
return getPodUrl()+SUBURL_CONVERSATIONS;
return getPodUrl() + SUBURL_CONVERSATIONS;
}
/**
* Return a https url that points to the new-post form that lets the user create a new post
*
* @return https://(pod-domain.tld)/status_messages/new
*/
public String getNewPostUrl() {
return getPodUrl()+SUBURL_NEW_POST;
return getPodUrl() + SUBURL_NEW_POST;
}
/**
* Return a https url that shows the profile of the currently registered diaspora account
*
* @return https://(pod-domain.tld)/people/(profileId)
*/
public String getProfileUrl() {
return getPodUrl()+SUBURL_PEOPLE+settings.getProfileId();
return getPodUrl() + SUBURL_PEOPLE + settings.getProfileId();
}
/**
* Return a https 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)
*/
public String getProfileUrl(long profileId) {
return getPodUrl()+SUBURL_PEOPLE+profileId;
return getPodUrl() + SUBURL_PEOPLE + profileId;
}
/**
* Return a https url that points to the activities feed of the currently registered diaspora account
*
* @return https://(pod-domain.tld)/activity
*/
public String getActivityUrl() {
return getPodUrl()+SUBURL_ACTIVITY;
return getPodUrl() + SUBURL_ACTIVITY;
}
/**
* Return a https url that points to the feed of posts that were liked by the currently registered diaspora account
*
* @return https://(pod-domain.tld)/liked
*/
public String getLikedPostsUrl() {
return getPodUrl()+SUBURL_LIKED;
return getPodUrl() + SUBURL_LIKED;
}
/**
* Return a https url that points to the stream of posts that were commented by the currently registered diaspora account
*
* @return https://(pod-domain.tld)/commented
*/
public String getCommentedUrl() {
return getPodUrl()+SUBURL_COMMENTED;
return getPodUrl() + SUBURL_COMMENTED;
}
/**
* Return a https 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
*/
public String getMentionsUrl() {
return getPodUrl()+SUBURL_MENTIONS;
return getPodUrl() + SUBURL_MENTIONS;
}
/**
* Return a https url that points to the stream of public posts
*
* @return https://(pod-domain.tld)/public
*/
public String getPublicUrl() {
return getPodUrl()+SUBURL_PUBLIC;
return getPodUrl() + SUBURL_PUBLIC;
}
/**
* Return a https url that toggles between mobile and desktop view when opened
*
* @return https://(pod-domain.tld)/mobile/toggle
*/
public String getToggleMobileUrl() {
return getPodUrl()+SUBURL_TOGGLE_MOBILE;
return getPodUrl() + SUBURL_TOGGLE_MOBILE;
}
/**
* Return a https url that queries posts for the given hashtag query
*
* @param query hashtag to be searched
* @return https://(pod-domain.tld)/tags/query
*/
public String getSearchTagsUrl(String query) {
return getPodUrl()+SUBURL_SEARCH_TAGS+query;
return getPodUrl() + SUBURL_SEARCH_TAGS + query;
}
/**
* Return a https url that queries user accounts for query
*
* @param query search term
* @return https://(pod-domain.tld)/people.mobile?q=(query)
*/
public String getSearchPeopleUrl(String query) {
return getPodUrl()+SUBURL_SEARCH_PEOPLE+query;
return getPodUrl() + SUBURL_SEARCH_PEOPLE + query;
}
/**
* Returns the url of the blank WebView
*
* @return about:blank
*/
public String getBlankUrl() {
return URL_BLANK;
}
public boolean isAspectUrl(String url) {
return url.startsWith(getPodUrl() + "/aspects?a_ids[]=");
}
public String getAspectNameFromUrl(String url, App app) {
url = url.replace(getPodUrl() + "/aspects?a_ids[]=", "").split(",")[0];
try {
int id = Integer.parseInt(url);
for (PodAspect aspect : app.getPodUserProfile().getAspects()) {
if (aspect.id == id) {
return aspect.name;
}
}
} catch (Exception ignored) {
}
return app.getString(R.string.aspects);
}
}