merge resolved
This commit is contained in:
commit
c6988415ae
5 changed files with 116 additions and 2 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<application
|
||||
|
|
|
@ -23,8 +23,10 @@ import android.graphics.drawable.Drawable;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
|
@ -501,4 +503,15 @@ public class MainActivity extends BaseActivity {
|
|||
viewPager.setCurrentItem(pageHistory.peek());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
List<Fragment> fragments = getSupportFragmentManager().getFragments();
|
||||
if (fragments != null) {
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,9 +15,21 @@
|
|||
|
||||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
@ -27,6 +39,8 @@ import android.view.WindowManager;
|
|||
import com.squareup.picasso.Callback;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import uk.co.senab.photoview.PhotoView;
|
||||
|
@ -35,6 +49,9 @@ import uk.co.senab.photoview.PhotoViewAttacher;
|
|||
public class ViewMediaFragment extends DialogFragment {
|
||||
|
||||
private PhotoViewAttacher attacher;
|
||||
private DownloadManager downloadManager;
|
||||
|
||||
private static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
|
||||
|
||||
@BindView(R.id.view_media_image) PhotoView photoView;
|
||||
|
||||
|
@ -99,6 +116,25 @@ public class ViewMediaFragment extends DialogFragment {
|
|||
}
|
||||
});
|
||||
|
||||
attacher.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
|
||||
AlertDialog downloadDialog = new AlertDialog.Builder(getContext()).create();
|
||||
|
||||
downloadDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.dialog_download_image),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
|
||||
downloadImage();
|
||||
}
|
||||
});
|
||||
downloadDialog.show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
Picasso.with(getContext())
|
||||
.load(url)
|
||||
.into(photoView, new Callback() {
|
||||
|
@ -121,4 +157,63 @@ public class ViewMediaFragment extends DialogFragment {
|
|||
attacher.cleanup();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
private void downloadImage(){
|
||||
|
||||
//Permission stuff
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN &&
|
||||
ContextCompat.checkSelfPermission(this.getContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
android.support.v4.app.ActivityCompat.requestPermissions(getActivity(),
|
||||
new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
|
||||
PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
|
||||
} else {
|
||||
|
||||
|
||||
//download stuff
|
||||
String url = getArguments().getString("url");
|
||||
Uri uri = Uri.parse(url);
|
||||
|
||||
String filename = new File(url).getName();
|
||||
|
||||
downloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
|
||||
DownloadManager.Request request = new DownloadManager.Request(uri);
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, getString(R.string.app_name) + "/" + filename);
|
||||
|
||||
downloadManager.enqueue(request);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
|
||||
@NonNull int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
downloadImage();
|
||||
} else {
|
||||
doErrorDialog(R.string.error_media_download_permission, R.string.action_retry,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
downloadImage();
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId,
|
||||
View.OnClickListener listener) {
|
||||
Snackbar bar = Snackbar.make(getView(), getString(descriptionId),
|
||||
Snackbar.LENGTH_SHORT);
|
||||
bar.setAction(actionId, listener);
|
||||
bar.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<string name="error_generic">Ein Fehler ist aufgetreten.</string>
|
||||
<string name="error_no_web_browser_found">Kein Webbrowser gefunden.</string>
|
||||
<string name="error_retrieving_oauth_token">Es konnte kein Login-Token abgerufen werden.</string>
|
||||
<string name="error_media_download_permission">Eine Berechtigung wird zum Speichern des Mediums benötigt.</string>
|
||||
|
||||
<string name="title_home">Start</string>
|
||||
<string name="title_notifications">Benachrichtigungen</string>
|
||||
|
@ -107,6 +108,7 @@
|
|||
</string>
|
||||
<string name="dialog_title_finishing_media_upload">Stelle Medienupload fertig</string>
|
||||
<string name="dialog_message_uploading_media">Lade hoch…</string>
|
||||
<string name="dialog_download_image">Herunterladen</string>
|
||||
|
||||
<string name="visibility_public">Öffentlich sichtbar</string>
|
||||
<string name="visibility_unlisted">Öffentlich sichtbar, aber nicht in der öffentlichen Timeline</string>
|
||||
|
@ -126,6 +128,7 @@
|
|||
<string name="pref_title_notification_filters">Benachrichtigen wenn</string>
|
||||
<string name="pref_title_notification_filter_follows">Mir jemand folgt</string>
|
||||
<string name="pref_title_notification_filter_mentions">Ich erwähnt werde</string>
|
||||
|
||||
<string name="pref_title_notification_filter_reblogs">Jemand meine Posts teilt</string>
|
||||
<string name="pref_title_browser_settings">Browser</string>
|
||||
<string name="pref_title_custom_tabs">Öffne Links in der App</string>
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
<string name="error_media_upload_type">That type of file cannot be uploaded.</string>
|
||||
<string name="error_media_upload_opening">That file could not be opened.</string>
|
||||
<string name="error_media_upload_permission">Permission to read media is required.</string>
|
||||
<string name="error_media_download_permission">Permission to store media is required.</string>
|
||||
|
||||
<string name="error_media_upload_image_or_video">Images and videos cannot both be attached to the same status.</string>
|
||||
<string name="error_media_upload_sending">The upload failed.</string>
|
||||
<string name="error_report_too_few_statuses">At least one status must be reported.</string>
|
||||
|
@ -120,6 +122,7 @@
|
|||
</string>
|
||||
<string name="dialog_title_finishing_media_upload">Finishing Media Upload</string>
|
||||
<string name="dialog_message_uploading_media">Uploading…</string>
|
||||
<string name="dialog_download_image">Download</string>
|
||||
|
||||
<string name="visibility_public">Everyone can view</string>
|
||||
<string name="visibility_unlisted">Everyone can view, but not on public timelines</string>
|
||||
|
@ -152,5 +155,4 @@
|
|||
<string name="description_account_locked">Locked Account</string>
|
||||
<string name="status_share_content">Share content of toot</string>
|
||||
<string name="status_share_link">Share link to toot</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue