More update on view

This commit is contained in:
Thomas 2023-01-25 15:59:17 +01:00
parent 6ef2683e5e
commit 8b26deb064
6 changed files with 165 additions and 253 deletions

View File

@ -14,13 +14,10 @@ package app.fedilab.android.peertube.fragment;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@ -29,12 +26,12 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.databinding.FragmentRecyclerviewPeertubeBinding;
import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
import app.fedilab.android.peertube.client.data.AccountData;
@ -47,23 +44,18 @@ import es.dmoral.toasty.Toasty;
public class DisplayAccountsFragment extends Fragment implements AccountsListAdapter.AllAccountsRemoved {
private boolean flag_loading;
private Context context;
private AccountsListAdapter accountsListAdapter;
private String max_id;
private List<AccountData.PeertubeAccount> accounts;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private RecyclerView lv_accounts;
private View rootView;
private RetrofitPeertubeAPI.DataType accountFetch;
private FragmentRecyclerviewPeertubeBinding binding;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_recyclerview_peertube, container, false);
binding = FragmentRecyclerviewPeertubeBinding.inflate(getLayoutInflater());
context = getContext();
Bundle bundle = this.getArguments();
accounts = new ArrayList<>();
if (bundle != null) {
@ -75,27 +67,18 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
firstLoad = true;
flag_loading = true;
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
lv_accounts = rootView.findViewById(R.id.lv_elements);
lv_accounts.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
mainLoader = rootView.findViewById(R.id.loader);
nextElementLoader = rootView.findViewById(R.id.loading_next);
textviewNoAction = rootView.findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
binding.lvElements.addItemDecoration(new DividerItemDecoration(requireActivity(), DividerItemDecoration.VERTICAL));
binding.loader.setVisibility(View.VISIBLE);
binding.loadingNext.setVisibility(View.GONE);
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
accountsListAdapter.allAccountsRemoved = this;
lv_accounts.setAdapter(accountsListAdapter);
TextView no_action_text = rootView.findViewById(R.id.no_action_text);
binding.lvElements.setAdapter(accountsListAdapter);
if (accountFetch == RetrofitPeertubeAPI.DataType.MUTED) {
no_action_text.setText(context.getString(R.string.no_muted));
binding.noActionText.setText(getString(R.string.no_muted));
}
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(context);
lv_accounts.setLayoutManager(mLayoutManager);
lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
final LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
binding.lvElements.setLayoutManager(mLayoutManager);
binding.lvElements.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
@ -106,18 +89,18 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
flag_loading = true;
AccountsVM viewModel = new ViewModelProvider(DisplayAccountsFragment.this).get(AccountsVM.class);
viewModel.getAccounts(accountFetch, max_id).observe(DisplayAccountsFragment.this.requireActivity(), apiResponse -> manageViewAccounts(apiResponse));
nextElementLoader.setVisibility(View.VISIBLE);
binding.loadingNext.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
binding.loadingNext.setVisibility(View.GONE);
}
}
}
});
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.MUTED, max_id).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
return rootView;
return binding.getRoot();
}
@Override
@ -134,7 +117,7 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
@Override
public void onDestroyView() {
super.onDestroyView();
rootView = null;
binding = null;
}
@Override
@ -143,28 +126,21 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
this.context = context;
}
@Override
public void onDestroy() {
super.onDestroy();
}
public void scrollToTop() {
if (lv_accounts != null)
lv_accounts.setAdapter(accountsListAdapter);
binding.lvElements.setAdapter(accountsListAdapter);
}
private void manageViewAccounts(APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
binding.loader.setVisibility(View.GONE);
binding.loadingNext.setVisibility(View.GONE);
if (apiResponse.getError() != null) {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
Toasty.error(requireActivity(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
binding.swipeContainer.setRefreshing(false);
flag_loading = false;
return;
}
@ -181,9 +157,9 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
max_id = "0";
}
if (firstLoad && (accounts == null || accounts.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
binding.noAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
binding.noAction.setVisibility(View.GONE);
max_id = String.valueOf(Integer.parseInt(max_id) + 20);
if (accounts != null && accounts.size() > 0) {
int previousPosition = this.accounts.size();
@ -192,11 +168,11 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
if (previousPosition == 0) {
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
accountsListAdapter.allAccountsRemoved = this;
lv_accounts.setAdapter(accountsListAdapter);
binding.lvElements.setAdapter(accountsListAdapter);
} else
accountsListAdapter.notifyItemRangeChanged(currentPosition, accounts.size());
}
swipeRefreshLayout.setRefreshing(false);
binding.swipeContainer.setRefreshing(false);
firstLoad = false;
}
@ -205,14 +181,14 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
accounts = new ArrayList<>();
firstLoad = true;
flag_loading = true;
swipeRefreshLayout.setRefreshing(true);
binding.swipeContainer.setRefreshing(true);
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.MUTED, null).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
}
@Override
public void onAllAccountsRemoved() {
textviewNoAction.setVisibility(View.VISIBLE);
binding.noAction.setVisibility(View.VISIBLE);
}

View File

@ -75,7 +75,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
private ChannelListAdapter channelListAdapter;
private List<ChannelData.Channel> channels;
private String name;
private View rootView;
private FloatingActionButton action_button;
private FragmentRecyclerviewPeertubeBinding binding;
private AddChannelPeertubeBinding bindingDialog;
@ -88,8 +87,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
binding = FragmentRecyclerviewPeertubeBinding.inflate(LayoutInflater.from(context));
rootView = binding.getRoot();
context = getContext();
Bundle bundle = this.getArguments();
channels = new ArrayList<>();
max_id = "0";
@ -119,7 +116,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);
loadChannels(max_id);
return rootView;
return binding.getRoot();
}
private void loadChannels(String max_id) {
@ -168,7 +165,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
@Override
public void onDestroyView() {
super.onDestroyView();
rootView = null;
binding = null;
}
@Override

View File

@ -25,8 +25,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@ -35,7 +33,6 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.jetbrains.annotations.NotNull;
@ -45,6 +42,7 @@ import java.util.List;
import java.util.Map;
import app.fedilab.android.R;
import app.fedilab.android.databinding.FragmentOverviewPeertubeBinding;
import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.data.VideoData;
import app.fedilab.android.peertube.client.entities.OverviewVideo;
@ -63,20 +61,16 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
private LinearLayoutManager mLayoutManager;
private GridLayoutManager gLayoutManager;
private boolean flag_loading;
private Context context;
private PeertubeAdapter peertubeAdapater;
private int page;
private List<VideoData.Video> peertubes;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private TextView textviewNoActionText;
private View rootView;
private RecyclerView lv_status;
private TimelineVM viewModelFeeds;
private Map<String, Boolean> relationship;
private Map<String, List<PlaylistExist>> playlists;
private FragmentOverviewPeertubeBinding binding;
public DisplayOverviewFragment() {
}
@ -84,23 +78,17 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_overview_peertube, container, false);
binding = FragmentOverviewPeertubeBinding.inflate(getLayoutInflater());
peertubes = new ArrayList<>();
context = getContext();
lv_status = rootView.findViewById(R.id.lv_status);
page = 1;
flag_loading = true;
firstLoad = true;
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
mainLoader = rootView.findViewById(R.id.loader);
nextElementLoader = rootView.findViewById(R.id.loading_next_status);
textviewNoAction = rootView.findViewById(R.id.no_action);
textviewNoActionText = rootView.findViewById(R.id.no_action_text);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
binding.loader.setVisibility(View.VISIBLE);
binding.loadingNextStatus.setVisibility(View.GONE);
peertubeAdapater = new PeertubeAdapter(this.peertubes);
@ -110,19 +98,19 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
lv_status.setAdapter(peertubeAdapater);
if (!Helper.isTablet(context)) {
mLayoutManager = new LinearLayoutManager(context);
if (!Helper.isTablet(requireActivity())) {
mLayoutManager = new LinearLayoutManager(requireActivity());
lv_status.setLayoutManager(mLayoutManager);
} else {
gLayoutManager = new GridLayoutManager(context, 2);
int spanCount = (int) Helper.convertDpToPixel(2, context);
int spacing = (int) Helper.convertDpToPixel(5, context);
gLayoutManager = new GridLayoutManager(requireActivity(), 2);
int spanCount = (int) Helper.convertDpToPixel(2, requireActivity());
int spacing = (int) Helper.convertDpToPixel(5, requireActivity());
lv_status.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
lv_status.setLayoutManager(gLayoutManager);
}
viewModelFeeds = new ViewModelProvider(DisplayOverviewFragment.this).get(TimelineVM.class);
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);
loadTimeline(page);
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
@ -131,14 +119,14 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
loadTimeline(page);
nextElementLoader.setVisibility(View.VISIBLE);
binding.loadingNextStatus.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
binding.loadingNextStatus.setVisibility(View.GONE);
}
}
} else if (gLayoutManager != null) {
@ -146,14 +134,14 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
if (dy > 0) {
int visibleItemCount = gLayoutManager.getChildCount();
int totalItemCount = gLayoutManager.getItemCount();
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
loadTimeline(page);
nextElementLoader.setVisibility(View.VISIBLE);
binding.loadingNextStatus.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
binding.loadingNextStatus.setVisibility(View.GONE);
}
}
}
@ -167,11 +155,9 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
@Override
public void onPause() {
super.onPause();
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setEnabled(false);
swipeRefreshLayout.setRefreshing(false);
swipeRefreshLayout.clearAnimation();
}
binding.swipeContainer.setEnabled(false);
binding.swipeContainer.setRefreshing(false);
binding.swipeContainer.clearAnimation();
if (getActivity() != null) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && getView() != null) {
@ -187,12 +173,6 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
}
@Override
public void onAttach(@NotNull Context context) {
super.onAttach(context);
this.context = context;
}
@Override
public void onStop() {
@ -207,16 +187,16 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
private void manageVIewVideos(APIResponse apiResponse) {
//hide loaders
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
binding.loader.setVisibility(View.GONE);
binding.loadingNextStatus.setVisibility(View.GONE);
//handle other API error
if (this.peertubes == null || apiResponse == null || apiResponse.getOverviewVideo() == null || (apiResponse.getError() != null)) {
if (apiResponse == null || apiResponse.getError() == null)
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
else {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
Toasty.error(requireActivity(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
}
swipeRefreshLayout.setRefreshing(false);
binding.swipeContainer.setRefreshing(false);
flag_loading = false;
return;
}
@ -313,11 +293,11 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
} else
peertubeAdapater.notifyItemRangeInserted(previousPosition, totalAdded);
//remove handlers
swipeRefreshLayout.setRefreshing(false);
textviewNoAction.setVisibility(View.GONE);
binding.swipeContainer.setRefreshing(false);
binding.noAction.setVisibility(View.GONE);
if (firstLoad && (this.peertubes == null || this.peertubes.size() == 0)) {
textviewNoActionText.setText(R.string.no_video_to_display);
textviewNoAction.setVisibility(View.VISIBLE);
binding.noActionText.setText(R.string.no_video_to_display);
binding.noAction.setVisibility(View.VISIBLE);
}
flag_loading = false;
firstLoad = false;
@ -339,7 +319,7 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
@Override
public void onResume() {
super.onResume();
swipeRefreshLayout.setEnabled(true);
binding.swipeContainer.setEnabled(true);
}

View File

@ -18,7 +18,6 @@ import static app.fedilab.android.mastodon.helper.Helper.dialogStyle;
import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.DataType.MY_CHANNELS;
import static app.fedilab.android.peertube.helper.Helper.peertubeInformation;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@ -32,22 +31,14 @@ import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
@ -57,6 +48,8 @@ import java.util.List;
import java.util.Map;
import app.fedilab.android.R;
import app.fedilab.android.databinding.AddPlaylistPeertubeBinding;
import app.fedilab.android.databinding.FragmentPlaylistsPeertubeBinding;
import app.fedilab.android.peertube.activities.PlaylistsActivity;
import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
@ -73,41 +66,30 @@ import es.dmoral.toasty.Toasty;
public class DisplayPlaylistsFragment extends Fragment {
private Context context;
private List<Playlist> playlists;
private RelativeLayout mainLoader;
private FloatingActionButton add_new;
private PlaylistAdapter playlistAdapter;
private RelativeLayout textviewNoAction;
private HashMap<Integer, String> privacyToSend;
private HashMap<String, String> channelToSend;
private Spinner set_upload_channel;
private Spinner set_upload_privacy;
private HashMap<String, String> channels;
private FragmentPlaylistsPeertubeBinding binding;
private AddPlaylistPeertubeBinding bindingAlert;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//View for fragment is the same that fragment accounts
View rootView = inflater.inflate(R.layout.fragment_playlists_peertube, container, false);
binding = FragmentPlaylistsPeertubeBinding.inflate(getLayoutInflater());
context = getContext();
playlists = new ArrayList<>();
RecyclerView lv_playlist = rootView.findViewById(R.id.lv_playlist);
textviewNoAction = rootView.findViewById(R.id.no_action);
mainLoader = rootView.findViewById(R.id.loader);
RelativeLayout nextElementLoader = rootView.findViewById(R.id.loading_next_items);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
binding.loader.setVisibility(View.VISIBLE);
binding.loadingNextItems.setVisibility(View.GONE);
playlists = new ArrayList<>();
playlistAdapter = new PlaylistAdapter(playlists, false);
lv_playlist.setAdapter(playlistAdapter);
binding.lvPlaylist.setAdapter(playlistAdapter);
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
viewModel.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(DisplayPlaylistsFragment.this.requireActivity(), apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLISTS, apiResponse));
add_new = rootView.findViewById(R.id.add_new);
LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
@ -120,89 +102,80 @@ public class DisplayPlaylistsFragment extends Fragment {
it.remove();
}
if (add_new != null) {
add_new.setOnClickListener(view -> {
AlertDialog.Builder dialogBuilder = new MaterialAlertDialogBuilder(context, dialogStyle());
LayoutInflater inflater1 = ((Activity) context).getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.add_playlist_peertube, new LinearLayout(context), 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);
binding.addNew.setOnClickListener(view -> {
AlertDialog.Builder dialogBuilder = new MaterialAlertDialogBuilder(requireActivity(), dialogStyle());
bindingAlert = AddPlaylistPeertubeBinding.inflate(getLayoutInflater());
dialogBuilder.setView(bindingAlert.getRoot());
ChannelsVM viewModelC = new ViewModelProvider(this).get(ChannelsVM.class);
viewModelC.get(MY_CHANNELS, null).observe(DisplayPlaylistsFragment.this.requireActivity(), this::manageVIewChannels);
ChannelsVM viewModelC = new ViewModelProvider(this).get(ChannelsVM.class);
viewModelC.get(MY_CHANNELS, null).observe(DisplayPlaylistsFragment.this.requireActivity(), this::manageVIewChannels);
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
bindingAlert.displayName.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
bindingAlert.description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
if (bindingAlert.displayName.getText() != null && bindingAlert.displayName.getText().toString().trim().length() > 0) {
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
Playlist playlist = new Playlist();
playlist.setDisplayName(display_name.getText().toString().trim());
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
playlist.setDescription(description.getText().toString().trim());
}
String idChannel = null;
if (channelToSend != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
idChannel = channelM.getValue();
}
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
Item privacyItem = new Item();
privacyItem.setLabel(privacyM.getValue());
privacyItem.setId(privacyM.getKey());
if (privacyItem.getLabel().equals("Public") && (playlist.getVideoChannel() == null)) {
Toasty.error(context, context.getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
} else {
if (privacyToSend != null) {
playlist.setPrivacy(privacyItem);
}
PlaylistParams playlistParams = new PlaylistParams();
playlistParams.setVideoChannelId(idChannel);
playlistParams.setDisplayName(playlist.getDisplayName());
playlistParams.setDescription(playlist.getDescription());
new Thread(() -> {
APIResponse apiResponse = new RetrofitPeertubeAPI(context).createOrUpdatePlaylist(PlaylistsVM.action.CREATE_PLAYLIST, null, playlistParams, null);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (getActivity() == null)
return;
playlist.setId(apiResponse.getActionReturn());
playlists.add(0, playlist);
playlistAdapter.notifyDataSetChanged();
};
mainHandler.post(myRunnable);
add_new.setEnabled(true);
}).start();
dialog.dismiss();
add_new.setEnabled(false);
}
} else {
Toasty.error(context, context.getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
Playlist playlist = new Playlist();
playlist.setDisplayName(bindingAlert.displayName.getText().toString().trim());
if (bindingAlert.description.getText() != null && bindingAlert.description.getText().toString().trim().length() > 0) {
playlist.setDescription(bindingAlert.description.getText().toString().trim());
}
String idChannel = null;
if (channelToSend != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
idChannel = channelM.getValue();
}
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
Item privacyItem = new Item();
privacyItem.setLabel(privacyM.getValue());
privacyItem.setId(privacyM.getKey());
if (privacyItem.getLabel().equals("Public") && (playlist.getVideoChannel() == null)) {
Toasty.error(requireActivity(), getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
} else {
if (privacyToSend != null) {
playlist.setPrivacy(privacyItem);
}
PlaylistParams playlistParams = new PlaylistParams();
playlistParams.setVideoChannelId(idChannel);
playlistParams.setDisplayName(playlist.getDisplayName());
playlistParams.setDescription(playlist.getDescription());
new Thread(() -> {
APIResponse apiResponse = new RetrofitPeertubeAPI(requireActivity()).createOrUpdatePlaylist(PlaylistsVM.action.CREATE_PLAYLIST, null, playlistParams, null);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (getActivity() == null)
return;
playlist.setId(apiResponse.getActionReturn());
playlists.add(0, playlist);
playlistAdapter.notifyDataSetChanged();
};
mainHandler.post(myRunnable);
binding.addNew.setEnabled(true);
}).start();
});
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
dialog.dismiss();
binding.addNew.setEnabled(false);
}
} else {
Toasty.error(requireActivity(), getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
}
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.action_playlist_create));
alertDialog.setOnDismissListener(dialogInterface -> {
//Hide keyboard
InputMethodManager imm = (InputMethodManager) context.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();
});
}
return rootView;
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) requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(bindingAlert.displayName.getWindowToken(), 0);
});
if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
});
return binding.getRoot();
}
@ -212,23 +185,18 @@ public class DisplayPlaylistsFragment extends Fragment {
}
@Override
public void onAttach(@NotNull Context context) {
super.onAttach(context);
this.context = context;
}
@Override
public void onDestroy() {
super.onDestroy();
binding = null;
}
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE);
add_new.setEnabled(true);
binding.loader.setVisibility(View.GONE);
binding.addNew.setEnabled(true);
if (apiResponse.getError() != null) {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
Toasty.error(requireActivity(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
@ -236,26 +204,26 @@ public class DisplayPlaylistsFragment extends Fragment {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
this.playlists.addAll(apiResponse.getPlaylists());
playlistAdapter.notifyDataSetChanged();
textviewNoAction.setVisibility(View.GONE);
binding.noAction.setVisibility(View.GONE);
} else {
textviewNoAction.setVisibility(View.VISIBLE);
binding.noAction.setVisibility(View.VISIBLE);
}
} else if (actionType == PlaylistsVM.action.CREATE_PLAYLIST) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
Intent intent = new Intent(context, PlaylistsActivity.class);
Intent intent = new Intent(requireActivity(), PlaylistsActivity.class);
Bundle b = new Bundle();
b.putSerializable("playlist", apiResponse.getPlaylists().get(0));
intent.putExtras(b);
context.startActivity(intent);
startActivity(intent);
this.playlists.add(0, apiResponse.getPlaylists().get(0));
playlistAdapter.notifyDataSetChanged();
textviewNoAction.setVisibility(View.GONE);
binding.noAction.setVisibility(View.GONE);
} else {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
Toasty.error(requireActivity(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
}
} else if (actionType == PlaylistsVM.action.DELETE_PLAYLIST) {
if (this.playlists.size() == 0)
textviewNoAction.setVisibility(View.VISIBLE);
binding.noAction.setVisibility(View.VISIBLE);
}
}
@ -263,9 +231,9 @@ public class DisplayPlaylistsFragment extends Fragment {
public void manageVIewChannels(APIResponse apiResponse) {
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
Toasty.error(requireActivity(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
else
Toasty.error(context, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
@ -286,9 +254,9 @@ public class DisplayPlaylistsFragment extends Fragment {
channelToSend = new HashMap<>();
channelToSend.put(channelName[0], channelId[0]);
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(context,
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(requireActivity(),
android.R.layout.simple_spinner_dropdown_item, channelName);
set_upload_channel.setAdapter(adapterChannel);
bindingAlert.setUploadChannel.setAdapter(adapterChannel);
LinkedHashMap<String, String> translations = null;
if (peertubeInformation.getTranslations() != null)
@ -313,12 +281,12 @@ public class DisplayPlaylistsFragment extends Fragment {
i++;
}
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(context,
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(requireActivity(),
android.R.layout.simple_spinner_dropdown_item, privaciesA);
set_upload_privacy.setAdapter(adapterPrivacies);
bindingAlert.setUploadPrivacy.setAdapter(adapterPrivacies);
//Manage privacies
set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
bindingAlert.setUploadPrivacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies());
@ -342,7 +310,7 @@ public class DisplayPlaylistsFragment extends Fragment {
}
});
//Manage languages
set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
bindingAlert.setUploadChannel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels);

View File

@ -52,16 +52,13 @@
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent">
<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/no_action_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:padding="10dp"
android:text="@string/no_videos"
android:textSize="25sp" />
android:text="@string/no_videos" />
</RelativeLayout>
<!-- Main Loader -->
<RelativeLayout
@ -71,11 +68,10 @@
android:gravity="center"
android:visibility="gone">
<com.github.ybq.android.spinkit.SpinKitView
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:SpinKit_Color="?colorAccent" />
android:layout_gravity="center" />
</RelativeLayout>
<!-- Loader for next videos -->
<RelativeLayout
@ -88,11 +84,10 @@
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent">
<com.github.ybq.android.spinkit.SpinKitView
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:SpinKit_Color="?colorAccent" />
android:layout_gravity="center" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -33,15 +33,13 @@
android:layout_height="wrap_content"
android:visibility="gone">
<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/no_action_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:padding="10dp"
android:text="@string/action_playlist_add"
android:textSize="25sp" />
android:text="@string/action_playlist_add" />
</RelativeLayout>
<!-- Main Loader -->
<RelativeLayout
@ -51,11 +49,10 @@
android:gravity="center"
android:visibility="gone">
<com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto"
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:SpinKit_Color="?colorAccent" />
android:layout_gravity="center" />
</RelativeLayout>
<!-- Loader for next items -->
<RelativeLayout
@ -67,11 +64,10 @@
android:gravity="bottom|center_horizontal"
android:visibility="gone">
<com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto"
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:SpinKit_Color="?colorAccent" />
android:layout_gravity="center" />
</RelativeLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton