diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-02-04 19:21:39 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-02-04 19:21:39 +0300 |
commit | 848fd4d174e000ab3e2398661cdfac2426f5341c (patch) | |
tree | 4cb2aecff9609c193a451f3d383afa032b2ccf1e | |
parent | 9539ed322c125694c813080242944012aad27b7a (diff) |
cleanup
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java | 260 |
1 files changed, 0 insertions, 260 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java index 6434cd33f..517316cc1 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java @@ -1,22 +1,14 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters; -import android.annotation.SuppressLint; import android.app.Activity; -import android.content.ContentResolver; -import android.content.ContentUris; import android.content.Context; import android.content.SharedPreferences; -import android.database.Cursor; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.Uri; -import android.os.Build; -import android.os.Environment; import android.preference.PreferenceManager; -import android.provider.DocumentsContract; -import android.provider.MediaStore; import android.webkit.MimeTypeMap; import androidx.annotation.NonNull; @@ -301,258 +293,6 @@ public class ServerAdapter { return type; } - public void getAttachmentsForCard(Long remoteBoardId, long remoteStackId, long remoteCardId, String contentType, Uri attachmentUri, IResponseCallback<List<Attachment>> responseCallback) { - ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().getAttachments(remoteBoardId, remoteStackId, remoteCardId), responseCallback); - } - - - /* Get uri related content real local file path. */ - private String getUriRealPath(Context ctx, Uri uri) - { - String ret = ""; - - if( isAboveKitKat() ) - { - // Android OS above sdk version 19. - ret = getUriRealPathAboveKitkat(ctx, uri); - }else - { - // Android OS below sdk version 19 - ret = getImageRealPath(ctx.getContentResolver(), uri, null); - } - - return ret; - } - - @SuppressLint("NewApi") - private String getUriRealPathAboveKitkat(Context ctx, Uri uri) - { - String ret = ""; - - if(ctx != null && uri != null) { - - if(isContentUri(uri)) - { - if(isGooglePhotoDoc(uri.getAuthority())) - { - ret = uri.getLastPathSegment(); - }else { - ret = getImageRealPath(ctx.getContentResolver(), uri, null); - } - }else if(isFileUri(uri)) { - ret = uri.getPath(); - }else if(isDocumentUri(ctx, uri)){ - - // Get uri related document id. - String documentId = DocumentsContract.getDocumentId(uri); - - // Get uri authority. - String uriAuthority = uri.getAuthority(); - - if(isMediaDoc(uriAuthority)) - { - String idArr[] = documentId.split(":"); - if(idArr.length == 2) - { - // First item is document type. - String docType = idArr[0]; - - // Second item is document real id. - String realDocId = idArr[1]; - - // Get content uri by document type. - Uri mediaContentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; - if("image".equals(docType)) - { - mediaContentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; - }else if("video".equals(docType)) - { - mediaContentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; - }else if("audio".equals(docType)) - { - mediaContentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; - } - - // Get where clause with real document id. - String whereClause = MediaStore.Images.Media._ID + " = " + realDocId; - - ret = getImageRealPath(ctx.getContentResolver(), mediaContentUri, whereClause); - } - - }else if(isDownloadDoc(uriAuthority)) - { - // Build download uri. - Uri downloadUri = Uri.parse("content://downloads/public_downloads"); - - // Append download document id at uri end. - Uri downloadUriAppendId = ContentUris.withAppendedId(downloadUri, Long.valueOf(documentId)); - - ret = getImageRealPath(ctx.getContentResolver(), downloadUriAppendId, null); - - }else if(isExternalStoreDoc(uriAuthority)) - { - String idArr[] = documentId.split(":"); - if(idArr.length == 2) - { - String type = idArr[0]; - String realDocId = idArr[1]; - - if("primary".equalsIgnoreCase(type)) - { - ret = Environment.getExternalStorageDirectory() + "/" + realDocId; - } - } - } - } - } - - return ret; - } - - /* Check whether current android os version is bigger than kitkat or not. */ - private boolean isAboveKitKat() - { - boolean ret = false; - ret = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; - return ret; - } - - /* Check whether this uri represent a document or not. */ - @SuppressLint("NewApi") - private boolean isDocumentUri(Context ctx, Uri uri) - { - boolean ret = false; - if(ctx != null && uri != null) { - ret = DocumentsContract.isDocumentUri(ctx, uri); - } - return ret; - } - - /* Check whether this uri is a content uri or not. - * content uri like content://media/external/images/media/1302716 - * */ - private boolean isContentUri(Uri uri) - { - boolean ret = false; - if(uri != null) { - String uriSchema = uri.getScheme(); - if("content".equalsIgnoreCase(uriSchema)) - { - ret = true; - } - } - return ret; - } - - /* Check whether this uri is a file uri or not. - * file uri like file:///storage/41B7-12F1/DCIM/Camera/IMG_20180211_095139.jpg - * */ - private boolean isFileUri(Uri uri) - { - boolean ret = false; - if(uri != null) { - String uriSchema = uri.getScheme(); - if("file".equalsIgnoreCase(uriSchema)) - { - ret = true; - } - } - return ret; - } - - - /* Check whether this document is provided by ExternalStorageProvider. */ - private boolean isExternalStoreDoc(String uriAuthority) - { - boolean ret = false; - - if("com.android.externalstorage.documents".equals(uriAuthority)) - { - ret = true; - } - - return ret; - } - - /* Check whether this document is provided by DownloadsProvider. */ - private boolean isDownloadDoc(String uriAuthority) - { - boolean ret = false; - - if("com.android.providers.downloads.documents".equals(uriAuthority)) - { - ret = true; - } - - return ret; - } - - /* Check whether this document is provided by MediaProvider. */ - private boolean isMediaDoc(String uriAuthority) - { - boolean ret = false; - - if("com.android.providers.media.documents".equals(uriAuthority)) - { - ret = true; - } - - return ret; - } - - /* Check whether this document is provided by google photos. */ - private boolean isGooglePhotoDoc(String uriAuthority) - { - boolean ret = false; - - if("com.google.android.apps.photos.content".equals(uriAuthority)) - { - ret = true; - } - - return ret; - } - - /* Return uri represented document file real local path.*/ - private String getImageRealPath(ContentResolver contentResolver, Uri uri, String whereClause) - { - String ret = ""; - - // Query the uri with condition. - Cursor cursor = contentResolver.query(uri, null, whereClause, null, null); - - if(cursor!=null) - { - boolean moveToFirst = cursor.moveToFirst(); - if(moveToFirst) - { - - // Get columns name by uri type. - String columnName = MediaStore.Images.Media.DATA; - - if( uri==MediaStore.Images.Media.EXTERNAL_CONTENT_URI ) - { - columnName = MediaStore.Images.Media.DATA; - }else if( uri==MediaStore.Audio.Media.EXTERNAL_CONTENT_URI ) - { - columnName = MediaStore.Audio.Media.DATA; - }else if( uri==MediaStore.Video.Media.EXTERNAL_CONTENT_URI ) - { - columnName = MediaStore.Video.Media.DATA; - } - - // Get column index. - int imageColumnIndex = cursor.getColumnIndex(columnName); - - // Get column value which is the uri related file local path. - ret = cursor.getString(imageColumnIndex); - } - } - - return ret; - } - public void updateAttachment(Long remoteBoardId, long remoteStackId, long remoteCardId, long remoteAttachmentId, String contentType, Uri attachmentUri, IResponseCallback<Attachment> responseCallback) { ensureInternetConnection(); File attachment = new File(attachmentUri.getPath()); |