Some fixes
This commit is contained in:
parent
dff76aada1
commit
9a06f5660b
|
@ -6,7 +6,7 @@ The other app is **[TubeLab](#TubeLab)** a Peertube Android app working for all
|
||||||
|
|
||||||
## <a name="TubeLab">TubeLab</a>
|
## <a name="TubeLab">TubeLab</a>
|
||||||
|
|
||||||
Tubelab is an Android app for Peertube (GNU GPLv3).
|
Tubelab is an Android app for Peertube (GNU GPLv3). <img src='https://img.shields.io/f-droid/v/app.fedilab.tubelab?include_prereleases' />
|
||||||
|
|
||||||
[<img alt='Get it on Google Play' src='./images/get-it-on-play.png' height="80"/>](https://play.google.com/store/apps/details?id=app.fedilab.tubelab)
|
[<img alt='Get it on Google Play' src='./images/get-it-on-play.png' height="80"/>](https://play.google.com/store/apps/details?id=app.fedilab.tubelab)
|
||||||
[<img alt='Get it on F-Droid' src='./images/get-it-on-fdroid.png' height="80"/>](https://f-droid.org/packages/app.fedilab.tubelab/)
|
[<img alt='Get it on F-Droid' src='./images/get-it-on-fdroid.png' height="80"/>](https://f-droid.org/packages/app.fedilab.tubelab/)
|
||||||
|
|
|
@ -16,7 +16,6 @@ package app.fedilab.fedilabtube;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
@ -37,20 +36,14 @@ import androidx.core.content.ContextCompat;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||||
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
|
|
||||||
import net.gotev.uploadservice.MultipartUploadRequest;
|
|
||||||
import net.gotev.uploadservice.ServerResponse;
|
|
||||||
import net.gotev.uploadservice.UploadInfo;
|
|
||||||
import net.gotev.uploadservice.UploadNotificationConfig;
|
|
||||||
import net.gotev.uploadservice.UploadStatusDelegate;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import app.fedilab.fedilabtube.client.APIResponse;
|
import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||||
|
@ -87,6 +80,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
||||||
private Video video;
|
private Video video;
|
||||||
private String channelToSendId;
|
private String channelToSendId;
|
||||||
private ActivityPeertubeEditBinding binding;
|
private ActivityPeertubeEditBinding binding;
|
||||||
|
private Uri inputData;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -458,14 +452,13 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
||||||
videoParams.setCategory(finalCategoryToSend.getId());
|
videoParams.setCategory(finalCategoryToSend.getId());
|
||||||
videoParams.setLicence(String.valueOf(finalLicenseToSend.getId()));
|
videoParams.setLicence(String.valueOf(finalLicenseToSend.getId()));
|
||||||
videoParams.setLanguage(finalLanguageToSend.getId());
|
videoParams.setLanguage(finalLanguageToSend.getId());
|
||||||
|
|
||||||
videoParams.setChannelId(channelToSendId);
|
videoParams.setChannelId(channelToSendId);
|
||||||
videoParams.setPrivacy(finalPrivacyToSend.getId());
|
videoParams.setPrivacy(finalPrivacyToSend.getId());
|
||||||
List<String> tags = binding.pVideoTags.getTags();
|
List<String> tags = binding.pVideoTags.getTags();
|
||||||
videoParams.setTags(tags);
|
videoParams.setTags(tags);
|
||||||
binding.setUploadSubmit.setEnabled(false);
|
binding.setUploadSubmit.setEnabled(false);
|
||||||
MyVideoVM myVideoVM = new ViewModelProvider(PeertubeEditUploadActivity.this).get(MyVideoVM.class);
|
MyVideoVM myVideoVM = new ViewModelProvider(PeertubeEditUploadActivity.this).get(MyVideoVM.class);
|
||||||
myVideoVM.updateVideo(videoId, videoParams, null, null).observe(PeertubeEditUploadActivity.this, this::manageUpdate);
|
myVideoVM.updateVideo(videoId, videoParams, inputData, inputData).observe(PeertubeEditUploadActivity.this, this::manageUpdate);
|
||||||
});
|
});
|
||||||
|
|
||||||
binding.setUploadPrivacy.setSelection(privacyPosition, false);
|
binding.setUploadPrivacy.setSelection(privacyPosition, false);
|
||||||
|
@ -570,54 +563,13 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
||||||
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
|
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
|
inputData = data.getData();
|
||||||
uploadConfig.getCompleted().autoClear = true;
|
|
||||||
try {
|
|
||||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
|
||||||
Uri uri = data.getData();
|
|
||||||
try {
|
|
||||||
String uploadId = UUID.randomUUID().toString();
|
|
||||||
new MultipartUploadRequest(PeertubeEditUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeEditUploadActivity.this) + "/api/v1/" + String.format("/videos/%s", video.getId()))
|
|
||||||
.addFileToUpload(uri.toString().replace("file://", ""), "thumbnailfile")
|
|
||||||
.setMethod("PUT")
|
|
||||||
.addHeader("Authorization", "Bearer " + token)
|
|
||||||
.setNotificationConfig(uploadConfig)
|
|
||||||
.setMaxRetries(2)
|
|
||||||
.setDelegate(new UploadStatusDelegate() {
|
|
||||||
@Override
|
|
||||||
public void onProgress(Context context, UploadInfo uploadInfo) {
|
|
||||||
// your code here
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
|
|
||||||
Exception exception) {
|
|
||||||
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
|
|
||||||
Glide.with(PeertubeEditUploadActivity.this)
|
Glide.with(PeertubeEditUploadActivity.this)
|
||||||
.load(uri)
|
.load(data.getData())
|
||||||
|
.thumbnail(0.1f)
|
||||||
|
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
|
||||||
.into(binding.pVideoPreview);
|
.into(binding.pVideoPreview);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancelled(Context context, UploadInfo uploadInfo) {
|
|
||||||
// your code here
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.startUpload();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,10 +19,15 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
|
import androidx.documentfile.provider.DocumentFile;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -559,22 +564,7 @@ public class RetrofitPeertubeAPI {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
if (userSettings.getAvatarfile() != null) {
|
if (userSettings.getAvatarfile() != null) {
|
||||||
InputStream inputStream = _context.getContentResolver().openInputStream(userSettings.getAvatarfile());
|
MultipartBody.Part bodyThumbnail = createFile("avatarfile", userSettings.getAvatarfile(), userSettings.getFileName());
|
||||||
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
|
|
||||||
int bufferSize = 1024;
|
|
||||||
byte[] buffer = new byte[bufferSize];
|
|
||||||
|
|
||||||
int len;
|
|
||||||
while ((len = inputStream.read(buffer)) != -1) {
|
|
||||||
byteBuffer.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
byte[] imageBytes = byteBuffer.toByteArray();
|
|
||||||
String mime = MimeTypeMap.getFileExtensionFromUrl(userSettings.getAvatarfile().toString());
|
|
||||||
if (mime == null || mime.trim().length() == 0) {
|
|
||||||
mime = "png";
|
|
||||||
}
|
|
||||||
RequestBody requestFile = RequestBody.create(MediaType.parse("image/" + mime), imageBytes);
|
|
||||||
MultipartBody.Part bodyThumbnail = MultipartBody.Part.createFormData("avatarfile", userSettings.getFileName(), requestFile);
|
|
||||||
Call<UserMe.AvatarResponse> updateProfilePicture = peertubeService.updateProfilePicture(getToken(), bodyThumbnail);
|
Call<UserMe.AvatarResponse> updateProfilePicture = peertubeService.updateProfilePicture(getToken(), bodyThumbnail);
|
||||||
Response<UserMe.AvatarResponse> responseAvatar = updateProfilePicture.execute();
|
Response<UserMe.AvatarResponse> responseAvatar = updateProfilePicture.execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
|
@ -594,6 +584,29 @@ public class RetrofitPeertubeAPI {
|
||||||
return avatarResponse;
|
return avatarResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MultipartBody.Part createFile(@NotNull String paramName, @NotNull Uri uri, String filename) throws IOException {
|
||||||
|
|
||||||
|
InputStream inputStream = _context.getContentResolver().openInputStream(uri);
|
||||||
|
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
|
||||||
|
int bufferSize = 1024;
|
||||||
|
byte[] buffer = new byte[bufferSize];
|
||||||
|
|
||||||
|
int len;
|
||||||
|
while ((len = inputStream.read(buffer)) != -1) {
|
||||||
|
byteBuffer.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
byte[] imageBytes = byteBuffer.toByteArray();
|
||||||
|
String mime = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
|
||||||
|
if (mime == null || mime.trim().length() == 0) {
|
||||||
|
mime = "png";
|
||||||
|
}
|
||||||
|
if (filename == null) {
|
||||||
|
filename = "my_image." + mime;
|
||||||
|
}
|
||||||
|
RequestBody requestFile = RequestBody.create(MediaType.parse("image/" + mime), imageBytes);
|
||||||
|
return MultipartBody.Part.createFormData(paramName, filename, requestFile);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if users via their uris are following the authenticated user
|
* Check if users via their uris are following the authenticated user
|
||||||
*
|
*
|
||||||
|
@ -949,17 +962,30 @@ public class RetrofitPeertubeAPI {
|
||||||
* @param previewfile File preview
|
* @param previewfile File preview
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
public APIResponse updateVideo(String videoId, VideoParams videoParams, File thumbnail, File previewfile) {
|
public APIResponse updateVideo(String videoId, VideoParams videoParams, Uri thumbnail, Uri previewfile) {
|
||||||
PeertubeService peertubeService = init();
|
PeertubeService peertubeService = init();
|
||||||
|
|
||||||
MultipartBody.Part bodyThumbnail = null;
|
MultipartBody.Part bodyThumbnail = null;
|
||||||
MultipartBody.Part bodyPreviewfile = null;
|
MultipartBody.Part bodyPreviewfile = null;
|
||||||
|
try {
|
||||||
if (thumbnail != null) {
|
if (thumbnail != null) {
|
||||||
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), thumbnail);
|
DocumentFile documentFile = DocumentFile.fromSingleUri(_context, thumbnail);
|
||||||
bodyThumbnail = MultipartBody.Part.createFormData("image", thumbnail.getName(), requestFile);
|
String thumbnailName = null;
|
||||||
|
if (documentFile != null) {
|
||||||
|
thumbnailName = documentFile.getName();
|
||||||
|
}
|
||||||
|
bodyThumbnail = createFile("avatarfile", thumbnail, thumbnailName);
|
||||||
}
|
}
|
||||||
if (previewfile != null) {
|
if (previewfile != null) {
|
||||||
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), previewfile);
|
DocumentFile documentFile = DocumentFile.fromSingleUri(_context, thumbnail);
|
||||||
bodyPreviewfile = MultipartBody.Part.createFormData("image", previewfile.getName(), requestFile);
|
String previewfileName = null;
|
||||||
|
if (documentFile != null) {
|
||||||
|
previewfileName = documentFile.getName();
|
||||||
|
}
|
||||||
|
bodyPreviewfile = createFile("image", previewfile, previewfileName);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
RequestBody channelId = RequestBody.create(MediaType.parse("text/plain"), videoParams.getChannelId());
|
RequestBody channelId = RequestBody.create(MediaType.parse("text/plain"), videoParams.getChannelId());
|
||||||
RequestBody description = RequestBody.create(MediaType.parse("text/plain"), videoParams.getDescription());
|
RequestBody description = RequestBody.create(MediaType.parse("text/plain"), videoParams.getDescription());
|
||||||
|
|
|
@ -16,6 +16,7 @@ package app.fedilab.fedilabtube.viewmodel;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
|
@ -24,8 +25,6 @@ import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import app.fedilab.fedilabtube.client.APIResponse;
|
import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||||
import app.fedilab.fedilabtube.client.entities.VideoParams;
|
import app.fedilab.fedilabtube.client.entities.VideoParams;
|
||||||
|
@ -39,13 +38,13 @@ public class MyVideoVM extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LiveData<APIResponse> updateVideo(String videoId, VideoParams videoParams, File thumbnail, File previewfile) {
|
public LiveData<APIResponse> updateVideo(String videoId, VideoParams videoParams, Uri thumbnail, Uri previewfile) {
|
||||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||||
update(videoId, videoParams, thumbnail, previewfile);
|
update(videoId, videoParams, thumbnail, previewfile);
|
||||||
return apiResponseMutableLiveData;
|
return apiResponseMutableLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(String videoId, VideoParams videoParams, File thumbnail, File previewfile) {
|
private void update(String videoId, VideoParams videoParams, Uri thumbnail, Uri previewfile) {
|
||||||
Context _mContext = getApplication().getApplicationContext();
|
Context _mContext = getApplication().getApplicationContext();
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue