VM-v9
This commit is contained in:
parent
df0b18f535
commit
42b0574143
|
@ -15,7 +15,6 @@ package app.fedilab.fedilabtube;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
@ -65,7 +64,6 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
PlaylistAdapter playlistAdapter;
|
PlaylistAdapter playlistAdapter;
|
||||||
private AsyncTask<Void, Void, Void> asyncTask;
|
|
||||||
private RelativeLayout mainLoader;
|
private RelativeLayout mainLoader;
|
||||||
private RelativeLayout textviewNoAction;
|
private RelativeLayout textviewNoAction;
|
||||||
private HashMap<Integer, String> privacyToSend;
|
private HashMap<Integer, String> privacyToSend;
|
||||||
|
@ -74,6 +72,7 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
||||||
private String idChannel;
|
private String idChannel;
|
||||||
private List<Playlist> playlists;
|
private List<Playlist> playlists;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -111,100 +110,12 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
||||||
playlistAdapter = new PlaylistAdapter(AllPlaylistsActivity.this, playlists, textviewNoAction);
|
playlistAdapter = new PlaylistAdapter(AllPlaylistsActivity.this, playlists, textviewNoAction);
|
||||||
lv_playlist.setAdapter(playlistAdapter);
|
lv_playlist.setAdapter(playlistAdapter);
|
||||||
|
|
||||||
add_new.setOnClickListener(view -> {
|
add_new.setOnClickListener(view -> manageAlert(null));
|
||||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(AllPlaylistsActivity.this);
|
|
||||||
LayoutInflater inflater1 = getLayoutInflater();
|
|
||||||
View dialogView = inflater1.inflate(R.layout.add_playlist, new LinearLayout(AllPlaylistsActivity.this), false);
|
|
||||||
dialogBuilder.setView(dialogView);
|
|
||||||
EditText display_name = dialogView.findViewById(R.id.display_name);
|
|
||||||
EditText description = dialogView.findViewById(R.id.description);
|
|
||||||
set_upload_channel = dialogView.findViewById(R.id.set_upload_channel);
|
|
||||||
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
|
|
||||||
|
|
||||||
|
|
||||||
ChannelsVM viewModelC = new ViewModelProvider(AllPlaylistsActivity.this).get(ChannelsVM.class);
|
|
||||||
viewModelC.get().observe(AllPlaylistsActivity.this, this::manageVIewChannels);
|
|
||||||
|
|
||||||
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
|
||||||
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
|
||||||
|
|
||||||
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
|
||||||
|
|
||||||
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
|
|
||||||
PlaylistElement playlistElement = new PlaylistElement();
|
|
||||||
playlistElement.setDisplayName(display_name.getText().toString().trim());
|
|
||||||
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
|
|
||||||
playlistElement.setDescription(description.getText().toString().trim());
|
|
||||||
}
|
|
||||||
playlistElement.setVideoChannelId(idChannel);
|
|
||||||
String idPrivacy;
|
|
||||||
String label;
|
|
||||||
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
|
|
||||||
idPrivacy = String.valueOf(privacyM.getKey());
|
|
||||||
label = privacyM.getValue();
|
|
||||||
if ((label.equals("Public") && (playlistElement.getVideoChannelId() == null || playlistElement.getVideoChannelId().equals("")))) {
|
|
||||||
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
|
|
||||||
} else {
|
|
||||||
if (privacyToSend != null) {
|
|
||||||
playlistElement.setPrivacy(idPrivacy);
|
|
||||||
}
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
String playlistId = new PeertubeAPI(AllPlaylistsActivity.this).createPlaylist(playlistElement);
|
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
||||||
Runnable myRunnable = () -> {
|
|
||||||
Playlist playlist = new Playlist();
|
|
||||||
playlist.setId(playlistId);
|
|
||||||
playlist.setDescription(playlistElement.getDescription());
|
|
||||||
playlist.setDisplayName(playlistElement.getDisplayName());
|
|
||||||
playlist.setPrivacy(privacyToSend);
|
|
||||||
playlists.add(playlist);
|
|
||||||
playlistAdapter.notifyDataSetChanged();
|
|
||||||
};
|
|
||||||
mainHandler.post(myRunnable);
|
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
||||||
Runnable myRunnable = () -> {
|
|
||||||
if (e.getMessage() != null) {
|
|
||||||
Toasty.error(AllPlaylistsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
} else {
|
|
||||||
Toasty.error(AllPlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mainHandler.post(myRunnable);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
|
||||||
|
|
||||||
|
|
||||||
AlertDialog alertDialog = dialogBuilder.create();
|
|
||||||
alertDialog.setTitle(getString(R.string.action_playlist_create));
|
|
||||||
alertDialog.setOnDismissListener(dialogInterface -> {
|
|
||||||
//Hide keyboard
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
assert imm != null;
|
|
||||||
imm.hideSoftInputFromWindow(display_name.getWindowToken(), 0);
|
|
||||||
});
|
|
||||||
if (alertDialog.getWindow() != null)
|
|
||||||
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
|
||||||
alertDialog.show();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if (asyncTask != null && !asyncTask.isCancelled()) {
|
|
||||||
asyncTask.cancel(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -234,6 +145,95 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void manageAlert(Playlist playlistToEdit) {
|
||||||
|
|
||||||
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(AllPlaylistsActivity.this);
|
||||||
|
LayoutInflater inflater1 = getLayoutInflater();
|
||||||
|
View dialogView = inflater1.inflate(R.layout.add_playlist, new LinearLayout(AllPlaylistsActivity.this), false);
|
||||||
|
dialogBuilder.setView(dialogView);
|
||||||
|
EditText display_name = dialogView.findViewById(R.id.display_name);
|
||||||
|
EditText description = dialogView.findViewById(R.id.description);
|
||||||
|
set_upload_channel = dialogView.findViewById(R.id.set_upload_channel);
|
||||||
|
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
|
||||||
|
|
||||||
|
ChannelsVM viewModelC = new ViewModelProvider(AllPlaylistsActivity.this).get(ChannelsVM.class);
|
||||||
|
viewModelC.get().observe(AllPlaylistsActivity.this, this::manageVIewChannels);
|
||||||
|
|
||||||
|
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
||||||
|
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
||||||
|
|
||||||
|
if (playlistToEdit != null) {
|
||||||
|
display_name.setText(playlistToEdit.getDisplayName());
|
||||||
|
description.setText(playlistToEdit.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
||||||
|
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
|
||||||
|
PlaylistElement playlistElement = new PlaylistElement();
|
||||||
|
playlistElement.setDisplayName(display_name.getText().toString().trim());
|
||||||
|
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
|
||||||
|
playlistElement.setDescription(description.getText().toString().trim());
|
||||||
|
}
|
||||||
|
playlistElement.setVideoChannelId(idChannel);
|
||||||
|
String idPrivacy;
|
||||||
|
String label;
|
||||||
|
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
|
||||||
|
idPrivacy = String.valueOf(privacyM.getKey());
|
||||||
|
label = privacyM.getValue();
|
||||||
|
if ((label.equals("Public") && (playlistElement.getVideoChannelId() == null || playlistElement.getVideoChannelId().equals("")))) {
|
||||||
|
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
if (privacyToSend != null) {
|
||||||
|
playlistElement.setPrivacy(idPrivacy);
|
||||||
|
}
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
String playlistId = new PeertubeAPI(AllPlaylistsActivity.this).createPlaylist(playlistElement);
|
||||||
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
Runnable myRunnable = () -> {
|
||||||
|
Playlist playlist = new Playlist();
|
||||||
|
playlist.setId(playlistId);
|
||||||
|
playlist.setDescription(playlistElement.getDescription());
|
||||||
|
playlist.setDisplayName(playlistElement.getDisplayName());
|
||||||
|
playlist.setPrivacy(privacyToSend);
|
||||||
|
playlists.add(playlist);
|
||||||
|
playlistAdapter.notifyDataSetChanged();
|
||||||
|
};
|
||||||
|
mainHandler.post(myRunnable);
|
||||||
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
Runnable myRunnable = () -> {
|
||||||
|
if (e.getMessage() != null) {
|
||||||
|
Toasty.error(AllPlaylistsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
Toasty.error(AllPlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mainHandler.post(myRunnable);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||||
|
AlertDialog alertDialog = dialogBuilder.create();
|
||||||
|
alertDialog.setTitle(getString(R.string.action_playlist_create));
|
||||||
|
alertDialog.setOnDismissListener(dialogInterface -> {
|
||||||
|
//Hide keyboard
|
||||||
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
assert imm != null;
|
||||||
|
imm.hideSoftInputFromWindow(display_name.getWindowToken(), 0);
|
||||||
|
});
|
||||||
|
if (alertDialog.getWindow() != null)
|
||||||
|
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void manageVIewChannels(APIResponse apiResponse) {
|
public void manageVIewChannels(APIResponse apiResponse) {
|
||||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||||
|
|
|
@ -122,7 +122,6 @@ public class PlaylistAdapter extends BaseAdapter {
|
||||||
popup.getMenuInflater()
|
popup.getMenuInflater()
|
||||||
.inflate(R.menu.playlist_menu, popup.getMenu());
|
.inflate(R.menu.playlist_menu, popup.getMenu());
|
||||||
popup.setOnMenuItemClickListener(item -> {
|
popup.setOnMenuItemClickListener(item -> {
|
||||||
//noinspection SwitchStatementWithTooFewBranches
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_delete:
|
case R.id.action_delete:
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
@ -142,9 +141,9 @@ public class PlaylistAdapter extends BaseAdapter {
|
||||||
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
|
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
|
||||||
.show();
|
.show();
|
||||||
break;
|
break;
|
||||||
/*case R.id.action_edit:
|
case R.id.action_edit:
|
||||||
|
|
||||||
break;*/
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,9 +34,9 @@
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/preview_playlist"
|
android:id="@+id/preview_playlist"
|
||||||
android:layout_width="150dp"
|
android:layout_width="150dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="100dp"
|
||||||
android:contentDescription="@string/preview"
|
android:contentDescription="@string/preview"
|
||||||
android:scaleType="centerInside"
|
android:scaleType="centerCrop"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/preview_title"
|
app:layout_constraintEnd_toStartOf="@+id/preview_title"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
@ -46,6 +46,7 @@
|
||||||
android:id="@+id/preview_title"
|
android:id="@+id/preview_title"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/playlist_more"
|
app:layout_constraintEnd_toStartOf="@+id/playlist_more"
|
||||||
|
@ -76,12 +77,11 @@
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/playlist_more"
|
android:id="@+id/playlist_more"
|
||||||
style="@style/Widget.AppCompat.Button.Borderless"
|
style="@style/Widget.AppCompat.Button.Borderless"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="40dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="40dp"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:contentDescription="@string/display_more"
|
android:contentDescription="@string/display_more"
|
||||||
android:src="@drawable/ic_baseline_more_vert_24"
|
android:src="@drawable/ic_baseline_more_vert_24"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
|
@ -6,11 +6,9 @@
|
||||||
android:icon="@drawable/ic_baseline_delete_24"
|
android:icon="@drawable/ic_baseline_delete_24"
|
||||||
android:title="@string/delete"
|
android:title="@string/delete"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
<!--
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_edit"
|
android:id="@+id/action_edit"
|
||||||
android:icon="@drawable/ic_baseline_edit_24"
|
android:icon="@drawable/ic_baseline_edit_24"
|
||||||
android:title="@string/edit"
|
android:title="@string/edit"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
-->
|
|
||||||
</menu>
|
</menu>
|
||||||
|
|
Loading…
Reference in New Issue