Improve Peertube upload
This commit is contained in:
parent
8b5bdb8831
commit
5eae023315
|
@ -49,6 +49,7 @@ import net.gotev.uploadservice.ServerResponse;
|
||||||
import net.gotev.uploadservice.UploadInfo;
|
import net.gotev.uploadservice.UploadInfo;
|
||||||
import net.gotev.uploadservice.UploadNotificationAction;
|
import net.gotev.uploadservice.UploadNotificationAction;
|
||||||
import net.gotev.uploadservice.UploadNotificationConfig;
|
import net.gotev.uploadservice.UploadNotificationConfig;
|
||||||
|
import net.gotev.uploadservice.UploadServiceSingleBroadcastReceiver;
|
||||||
import net.gotev.uploadservice.UploadStatusDelegate;
|
import net.gotev.uploadservice.UploadStatusDelegate;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -60,6 +61,7 @@ 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.android.client.APIResponse;
|
import app.fedilab.android.client.APIResponse;
|
||||||
import app.fedilab.android.client.Entities.Account;
|
import app.fedilab.android.client.Entities.Account;
|
||||||
|
@ -71,7 +73,7 @@ import app.fedilab.android.interfaces.OnRetrievePeertubeInterface;
|
||||||
|
|
||||||
import static app.fedilab.android.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
import static app.fedilab.android.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||||
|
|
||||||
public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePeertubeInterface {
|
public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePeertubeInterface, UploadStatusDelegate {
|
||||||
|
|
||||||
|
|
||||||
private final int PICK_IVDEO = 52378;
|
private final int PICK_IVDEO = 52378;
|
||||||
|
@ -84,7 +86,7 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
|
||||||
private String filename;
|
private String filename;
|
||||||
private HashMap<Integer, String> privacyToSend;
|
private HashMap<Integer, String> privacyToSend;
|
||||||
private HashMap<String, String> channelToSend;
|
private HashMap<String, String> channelToSend;
|
||||||
private String videoID;
|
private UploadServiceSingleBroadcastReceiver uploadReceiver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -142,6 +144,8 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
|
||||||
new RetrievePeertubeChannelsAsyncTask(PeertubeUploadActivity.this, PeertubeUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
new RetrievePeertubeChannelsAsyncTask(PeertubeUploadActivity.this, PeertubeUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
channels = new HashMap<>();
|
channels = new HashMap<>();
|
||||||
|
|
||||||
|
uploadReceiver = new UploadServiceSingleBroadcastReceiver(this);
|
||||||
|
uploadReceiver.register(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,6 +187,12 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
uploadReceiver.unregister(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||||
|
|
||||||
|
@ -345,52 +355,21 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
|
||||||
uploadConfig.getCancelled().message = getString(R.string.toast_cancelled);
|
uploadConfig.getCancelled().message = getString(R.string.toast_cancelled);
|
||||||
uploadConfig.getCompleted().actions.add(new UploadNotificationAction(R.drawable.ic_check, getString(R.string.video_uploaded_action), clickIntent));
|
uploadConfig.getCompleted().actions.add(new UploadNotificationAction(R.drawable.ic_check, getString(R.string.video_uploaded_action), clickIntent));
|
||||||
|
|
||||||
|
String uploadId = UUID.randomUUID().toString();
|
||||||
String uploadId =
|
uploadReceiver.setUploadID(uploadId);
|
||||||
new MultipartUploadRequest(PeertubeUploadActivity.this, "https://" + Helper.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
|
new MultipartUploadRequest(PeertubeUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
|
||||||
.addFileToUpload(uri.toString().replace("file://",""), "videofile")
|
.addFileToUpload(uri.toString().replace("file://",""), "videofile")
|
||||||
.addHeader("Authorization", "Bearer " + token)
|
.addHeader("Authorization", "Bearer " + token)
|
||||||
.setNotificationConfig(uploadConfig)
|
.setNotificationConfig(uploadConfig)
|
||||||
.addParameter("name", filename)
|
.addParameter("name", filename)
|
||||||
.addParameter("channelId", idChannel)
|
.addParameter("channelId", idChannel)
|
||||||
.addParameter("privacy", String.valueOf(idPrivacy))
|
.addParameter("privacy", String.valueOf(idPrivacy))
|
||||||
.addParameter("nsfw", "false")
|
.addParameter("nsfw", "false")
|
||||||
.addParameter("commentsEnabled", "true")
|
.addParameter("commentsEnabled", "true")
|
||||||
.addParameter("waitTranscoding", "true")
|
.addParameter("waitTranscoding", "true")
|
||||||
.setMaxRetries(2)
|
.setMaxRetries(2)
|
||||||
.setDelegate(new UploadStatusDelegate() {
|
.startUpload();
|
||||||
@Override
|
finish();
|
||||||
public void onProgress(Context context, UploadInfo uploadInfo) {
|
|
||||||
// your code here
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
|
|
||||||
Exception exception) {
|
|
||||||
// your code here
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
|
|
||||||
try {
|
|
||||||
JSONObject response = new JSONObject(serverResponse.getBodyAsString());
|
|
||||||
videoID = response.getJSONObject("video").get("id").toString();
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
editor.putString(Helper.VIDEO_ID, videoID);
|
|
||||||
editor.commit();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancelled(Context context, UploadInfo uploadInfo) {
|
|
||||||
// your code here
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.startUpload();
|
|
||||||
finish();
|
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -398,4 +377,37 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgress(Context context, UploadInfo uploadInfo) {
|
||||||
|
// your code here
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
|
||||||
|
Exception exception) {
|
||||||
|
// your code here
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
|
||||||
|
try {
|
||||||
|
JSONObject response = new JSONObject(serverResponse.getBodyAsString());
|
||||||
|
String videoID = response.getJSONObject("video").get("id").toString();
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putString(Helper.VIDEO_ID, videoID);
|
||||||
|
editor.commit();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled(Context context, UploadInfo uploadInfo) {
|
||||||
|
// your code here
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue