This commit is contained in:
Thomas 2020-09-11 11:50:26 +02:00
parent df0b18f535
commit 42b0574143
4 changed files with 98 additions and 101 deletions

View File

@ -15,7 +15,6 @@ package app.fedilab.fedilabtube;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -65,7 +64,6 @@ public class AllPlaylistsActivity extends AppCompatActivity {
PlaylistAdapter playlistAdapter;
private AsyncTask<Void, Void, Void> asyncTask;
private RelativeLayout mainLoader;
private RelativeLayout textviewNoAction;
private HashMap<Integer, String> privacyToSend;
@ -74,6 +72,7 @@ public class AllPlaylistsActivity extends AppCompatActivity {
private String idChannel;
private List<Playlist> playlists;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -111,7 +110,43 @@ public class AllPlaylistsActivity extends AppCompatActivity {
playlistAdapter = new PlaylistAdapter(AllPlaylistsActivity.this, playlists, textviewNoAction);
lv_playlist.setAdapter(playlistAdapter);
add_new.setOnClickListener(view -> {
add_new.setOnClickListener(view -> manageAlert(null));
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE);
if (apiResponse.getError() != null) {
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
if (actionType == PlaylistsVM.action.GET_PLAYLIST) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
playlists.addAll(apiResponse.getPlaylists());
playlistAdapter.notifyDataSetChanged();
textviewNoAction.setVisibility(View.GONE);
} else {
textviewNoAction.setVisibility(View.VISIBLE);
}
}
}
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);
@ -121,15 +156,18 @@ public class AllPlaylistsActivity extends AppCompatActivity {
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 (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());
@ -183,8 +221,6 @@ public class AllPlaylistsActivity extends AppCompatActivity {
});
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.action_playlist_create));
alertDialog.setOnDismissListener(dialogInterface -> {
@ -196,42 +232,6 @@ public class AllPlaylistsActivity extends AppCompatActivity {
if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
});
}
@Override
public void onDestroy() {
super.onDestroy();
if (asyncTask != null && !asyncTask.isCancelled()) {
asyncTask.cancel(true);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE);
if (apiResponse.getError() != null) {
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
if (actionType == PlaylistsVM.action.GET_PLAYLIST) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
playlists.addAll(apiResponse.getPlaylists());
playlistAdapter.notifyDataSetChanged();
textviewNoAction.setVisibility(View.GONE);
} else {
textviewNoAction.setVisibility(View.VISIBLE);
}
}
}

View File

@ -122,7 +122,6 @@ public class PlaylistAdapter extends BaseAdapter {
popup.getMenuInflater()
.inflate(R.menu.playlist_menu, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
//noinspection SwitchStatementWithTooFewBranches
switch (item.getItemId()) {
case R.id.action_delete:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
@ -142,9 +141,9 @@ public class PlaylistAdapter extends BaseAdapter {
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
.show();
break;
/*case R.id.action_edit:
case R.id.action_edit:
break;*/
break;
}
return true;
});

View File

@ -34,9 +34,9 @@
<ImageView
android:id="@+id/preview_playlist"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_height="100dp"
android:contentDescription="@string/preview"
android:scaleType="centerInside"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/preview_title"
app:layout_constraintStart_toStartOf="parent"
@ -46,6 +46,7 @@
android:id="@+id/preview_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/playlist_more"
@ -76,12 +77,11 @@
<ImageButton
android:id="@+id/playlist_more"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:contentDescription="@string/display_more"
android:src="@drawable/ic_baseline_more_vert_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -6,11 +6,9 @@
android:icon="@drawable/ic_baseline_delete_24"
android:title="@string/delete"
app:showAsAction="ifRoom" />
<!--
<item
android:id="@+id/action_edit"
android:icon="@drawable/ic_baseline_edit_24"
android:title="@string/edit"
app:showAsAction="ifRoom" />
-->
</menu>