Fix upload

This commit is contained in:
Thomas 2020-11-21 09:37:18 +01:00
parent 3ea012f62e
commit d685031ee8
2 changed files with 20 additions and 29 deletions

View File

@ -118,8 +118,8 @@ dependencies {
implementation "com.github.bumptech.glide:glide:4.11.0" implementation "com.github.bumptech.glide:glide:4.11.0"
annotationProcessor "com.github.bumptech.glide:compiler:4.11.0" annotationProcessor "com.github.bumptech.glide:compiler:4.11.0"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "net.gotev:uploadservice:4.5.0" implementation "net.gotev:uploadservice:4.4.2"
implementation "net.gotev:uploadservice-okhttp:4.5.0" implementation "net.gotev:uploadservice-okhttp:4.4.2"
implementation "com.google.code.gson:gson:2.8.6" implementation "com.google.code.gson:gson:2.8.6"
implementation 'androidx.media:media:1.2.0' implementation 'androidx.media:media:1.2.0'
implementation 'com.github.ybq:Android-SpinKit:1.4.0' implementation 'com.github.ybq:Android-SpinKit:1.4.0'

View File

@ -29,10 +29,6 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -58,6 +54,7 @@ import java.util.Map;
import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.data.ChannelData; import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.databinding.ActivityPeertubeUploadBinding;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.viewmodel.ChannelsVM; import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
@ -71,16 +68,12 @@ public class PeertubeUploadActivity extends AppCompatActivity {
public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724; public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724;
private final int PICK_IVDEO = 52378; private final int PICK_IVDEO = 52378;
private Button set_upload_file, set_upload_submit;
private Spinner set_upload_privacy, set_upload_channel;
private TextView set_upload_file_name;
private EditText video_title;
private HashMap<String, String> channels; private HashMap<String, String> channels;
private Uri uri; private Uri uri;
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 ActivityPeertubeUploadBinding binding;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -89,14 +82,10 @@ public class PeertubeUploadActivity extends AppCompatActivity {
if (getSupportActionBar() != null) if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_peertube_upload); binding = ActivityPeertubeUploadBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
set_upload_file = findViewById(R.id.set_upload_file);
set_upload_file_name = findViewById(R.id.set_upload_file_name);
set_upload_channel = findViewById(R.id.set_upload_channel);
set_upload_privacy = findViewById(R.id.set_upload_privacy);
set_upload_submit = findViewById(R.id.set_upload_submit);
video_title = findViewById(R.id.video_title);
ChannelsVM viewModelC = new ViewModelProvider(PeertubeUploadActivity.this).get(ChannelsVM.class); ChannelsVM viewModelC = new ViewModelProvider(PeertubeUploadActivity.this).get(ChannelsVM.class);
viewModelC.get(MY_CHANNELS, null).observe(PeertubeUploadActivity.this, this::manageVIewChannels); viewModelC.get(MY_CHANNELS, null).observe(PeertubeUploadActivity.this, this::manageVIewChannels);
@ -112,7 +101,7 @@ public class PeertubeUploadActivity extends AppCompatActivity {
Toasty.error(PeertubeUploadActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); Toasty.error(PeertubeUploadActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
return; return;
} }
set_upload_submit.setEnabled(true); binding.setUploadSubmit.setEnabled(true);
uri = data.getData(); uri = data.getData();
filename = null; filename = null;
DocumentFile documentFile = DocumentFile.fromSingleUri(this, uri); DocumentFile documentFile = DocumentFile.fromSingleUri(this, uri);
@ -122,8 +111,8 @@ public class PeertubeUploadActivity extends AppCompatActivity {
if (filename == null) { if (filename == null) {
filename = new Date().toString(); filename = new Date().toString();
} }
set_upload_file_name.setVisibility(View.VISIBLE); binding.setUploadFileName.setVisibility(View.VISIBLE);
set_upload_file_name.setText(filename); binding.setUploadFileName.setText(filename);
} }
} }
@ -167,7 +156,7 @@ public class PeertubeUploadActivity extends AppCompatActivity {
channelToSend.put(channelName[0], channelId[0]); channelToSend.put(channelName[0], channelId[0]);
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(PeertubeUploadActivity.this, ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(PeertubeUploadActivity.this,
android.R.layout.simple_spinner_dropdown_item, channelName); android.R.layout.simple_spinner_dropdown_item, channelName);
set_upload_channel.setAdapter(adapterChannel); binding.setUploadChannel.setAdapter(adapterChannel);
if (peertubeInformation == null) { if (peertubeInformation == null) {
return; return;
@ -197,10 +186,10 @@ public class PeertubeUploadActivity extends AppCompatActivity {
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(PeertubeUploadActivity.this, ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(PeertubeUploadActivity.this,
android.R.layout.simple_spinner_dropdown_item, privaciesA); android.R.layout.simple_spinner_dropdown_item, privaciesA);
set_upload_privacy.setAdapter(adapterPrivacies); binding.setUploadPrivacy.setAdapter(adapterPrivacies);
//Manage privacies //Manage privacies
set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { binding.setUploadPrivacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies()); LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies());
@ -223,9 +212,9 @@ public class PeertubeUploadActivity extends AppCompatActivity {
} }
}); });
set_upload_file.setEnabled(true); binding.setUploadFile.setEnabled(true);
set_upload_file.setOnClickListener(v -> { binding.setUploadFile.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(PeertubeUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != if (ContextCompat.checkSelfPermission(PeertubeUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) { PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PeertubeUploadActivity.this, ActivityCompat.requestPermissions(PeertubeUploadActivity.this,
@ -243,7 +232,7 @@ public class PeertubeUploadActivity extends AppCompatActivity {
}); });
//Manage languages //Manage languages
set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { binding.setUploadChannel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels); LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels);
@ -267,7 +256,7 @@ public class PeertubeUploadActivity extends AppCompatActivity {
} }
}); });
set_upload_submit.setOnClickListener(v -> { binding.setUploadSubmit.setOnClickListener(v -> {
if (uri != null) { if (uri != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next(); Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
String idChannel = channelM.getValue(); String idChannel = channelM.getValue();
@ -277,17 +266,19 @@ public class PeertubeUploadActivity extends AppCompatActivity {
try { try {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
new MultipartUploadRequest(PeertubeUploadActivity.this, "https://" + Helper.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload") new MultipartUploadRequest(PeertubeUploadActivity.this, "https://" + Helper.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
.setMethod("POST") .setMethod("POST")
.setBearerAuth(token) .setBearerAuth(token)
.addHeader("User-Agent", getString(R.string.app_name) + "/" + BuildConfig.VERSION_NAME) .addHeader("User-Agent", getString(R.string.app_name) + "/" + BuildConfig.VERSION_NAME)
.addParameter("privacy", String.valueOf(idPrivacy)) .addParameter("privacy", String.valueOf(idPrivacy))
.addParameter("nsfw", "false") .addParameter("nsfw", "false")
.addParameter("name", filename)
.addParameter("commentsEnabled", "true") .addParameter("commentsEnabled", "true")
.addParameter("downloadEnabled", "true") .addParameter("downloadEnabled", "true")
.addParameter("waitTranscoding", "true") .addParameter("waitTranscoding", "true")
.addParameter("channelId", idChannel) .addParameter("channelId", idChannel)
.addFileToUpload(uri.toString(), "videofile", filename) .addFileToUpload(uri.toString(), "videofile")
.setNotificationConfig((context, uploadId) -> getNotificationConfig(uploadId)) .setNotificationConfig((context, uploadId) -> getNotificationConfig(uploadId))
.setMaxRetries(2) .setMaxRetries(2)
.startUpload(); .startUpload();