diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java index c47f6b5ca..c719bc275 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java @@ -996,6 +996,7 @@ public boolean onNavigationItemSelected(MenuItem item) { snackbarNoInternet.show(); } } + break; case R.id.nav_activities: { if (WebHelper.isOnline(MainActivity.this)) { diff --git a/app/src/main/java/com/github/dfa/diaspora_android/receiver/UpdateTitleReceiver.java b/app/src/main/java/com/github/dfa/diaspora_android/receiver/UpdateTitleReceiver.java index c04f0ffec..38e1a3a0f 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/receiver/UpdateTitleReceiver.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/receiver/UpdateTitleReceiver.java @@ -74,8 +74,14 @@ public void onReceive(Context context, Intent intent) { setTitle(R.string.nav_mentions); } else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_PUBLIC)) { setTitle(R.string.public_); + } else if (urls.getManageContactsUrl().equals(url)) { + setTitle(R.string.contacts); + } else if (urls.getManageTagsUrl().equals(url)) { + setTitle(R.string.pref_title__manage_tags); } else if (urls.isAspectUrl(url)) { setTitle(urls.getAspectNameFromUrl(url, app)); + } else if (urls.getReportsUrl().equals(url)) { + setTitle(R.string.nav_reports); } } else { AppLog.spam(this, "onReceive()- Invalid url: " + url); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/service/SaveImageTask.java b/app/src/main/java/com/github/dfa/diaspora_android/service/SaveImageTask.java new file mode 100644 index 000000000..49cf6ab01 --- /dev/null +++ b/app/src/main/java/com/github/dfa/diaspora_android/service/SaveImageTask.java @@ -0,0 +1,74 @@ +package com.github.dfa.diaspora_android.service; + +import android.app.DownloadManager; +import android.content.Context; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Environment; +import android.os.Looper; +import android.os.StrictMode; +import android.widget.Toast; + +import com.github.dfa.diaspora_android.R; +import com.github.dfa.diaspora_android.util.AppLog; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +/** + * Created by vanitas on 06.11.16. + */ + +public class SaveImageTask extends AsyncTask { + + protected Context context; + + public void setContext(Context context) { + this.context = context; + } + + protected String doInBackground(String... urls) { + String url = urls[0]; + if (url != null) { + Uri source = Uri.parse(url); + DownloadManager.Request request = new DownloadManager.Request(source); + URL sourceUrl; + InputStream is; + byte[] a = new byte[8]; + String extension = ".png"; + try { + sourceUrl = new URL(source.toString()); + is = sourceUrl.openStream(); + is.read(a); + is.close(); + AppLog.d(this, "Array: " + new String(a)); + //JPG + if (new String(a).startsWith(new String(new byte[]{-1, -40}))) { + AppLog.d(this, "is jpg"); + extension = ".jpg"; + } else + //GIF + if (new String(a).startsWith("GIF")) { + AppLog.d(this, "is gif"); + extension = ".gif"; + } else { + AppLog.d(this, "is SPARTAAAA! (GIF)"); + } + } catch (IOException ignored) { + } + File destinationFile = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + + System.currentTimeMillis() + extension); + request.setDestinationUri(Uri.fromFile(destinationFile)); + ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request); + return destinationFile.getAbsolutePath(); + } + return null; + } + + @Override + protected void onPostExecute(String s) { + Toast.makeText(context, context.getString(R.string.share__toast_saved_image_to_location)+" "+s, Toast.LENGTH_LONG).show(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/dfa/diaspora_android/web/ContextMenuWebView.java b/app/src/main/java/com/github/dfa/diaspora_android/web/ContextMenuWebView.java index f9fc22fb3..351c12eab 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/web/ContextMenuWebView.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/web/ContextMenuWebView.java @@ -30,18 +30,27 @@ import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.net.Uri; +import android.os.AsyncTask; import android.os.Environment; +import android.os.StrictMode; import android.support.v4.content.LocalBroadcastManager; import android.util.AttributeSet; import android.view.ContextMenu; import android.view.MenuItem; import android.widget.Toast; +import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.activity.MainActivity; import com.github.dfa.diaspora_android.service.ImageDownloadTask; +import com.github.dfa.diaspora_android.service.SaveImageTask; +import com.github.dfa.diaspora_android.util.AppLog; import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; /** * Subclass of WebView which adds a context menu for long clicks on images or links to share, save @@ -107,17 +116,9 @@ public void onClick(DialogInterface dialog, int which) { } } if (writeToStoragePermitted) { - if (url != null) { - Uri source = Uri.parse(url); - DownloadManager.Request request = new DownloadManager.Request(source); - File destinationFile = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" - + 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) + " " + - destinationFile.getAbsolutePath(), Toast.LENGTH_LONG).show(); - } + SaveImageTask saveTask = new SaveImageTask(); + saveTask.setContext(context); + saveTask.execute(url); } } break;