More update on view
This commit is contained in:
parent
6ef2683e5e
commit
8b26deb064
|
@ -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,
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -29,12 +26,12 @@ import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
|
import app.fedilab.android.databinding.FragmentRecyclerviewPeertubeBinding;
|
||||||
import app.fedilab.android.peertube.client.APIResponse;
|
import app.fedilab.android.peertube.client.APIResponse;
|
||||||
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
|
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
|
||||||
import app.fedilab.android.peertube.client.data.AccountData;
|
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 {
|
public class DisplayAccountsFragment extends Fragment implements AccountsListAdapter.AllAccountsRemoved {
|
||||||
|
|
||||||
private boolean flag_loading;
|
private boolean flag_loading;
|
||||||
private Context context;
|
|
||||||
private AccountsListAdapter accountsListAdapter;
|
private AccountsListAdapter accountsListAdapter;
|
||||||
private String max_id;
|
private String max_id;
|
||||||
private List<AccountData.PeertubeAccount> accounts;
|
private List<AccountData.PeertubeAccount> accounts;
|
||||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
|
||||||
private boolean firstLoad;
|
private boolean firstLoad;
|
||||||
private SwipeRefreshLayout swipeRefreshLayout;
|
|
||||||
private RecyclerView lv_accounts;
|
|
||||||
private View rootView;
|
|
||||||
private RetrofitPeertubeAPI.DataType accountFetch;
|
private RetrofitPeertubeAPI.DataType accountFetch;
|
||||||
|
private FragmentRecyclerviewPeertubeBinding binding;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
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();
|
Bundle bundle = this.getArguments();
|
||||||
accounts = new ArrayList<>();
|
accounts = new ArrayList<>();
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
|
@ -75,27 +67,18 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
|
|
||||||
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
|
binding.lvElements.addItemDecoration(new DividerItemDecoration(requireActivity(), DividerItemDecoration.VERTICAL));
|
||||||
|
binding.loader.setVisibility(View.VISIBLE);
|
||||||
|
binding.loadingNext.setVisibility(View.GONE);
|
||||||
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);
|
|
||||||
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
|
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
|
||||||
accountsListAdapter.allAccountsRemoved = this;
|
accountsListAdapter.allAccountsRemoved = this;
|
||||||
lv_accounts.setAdapter(accountsListAdapter);
|
binding.lvElements.setAdapter(accountsListAdapter);
|
||||||
TextView no_action_text = rootView.findViewById(R.id.no_action_text);
|
|
||||||
if (accountFetch == RetrofitPeertubeAPI.DataType.MUTED) {
|
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;
|
final LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
|
||||||
mLayoutManager = new LinearLayoutManager(context);
|
binding.lvElements.setLayoutManager(mLayoutManager);
|
||||||
lv_accounts.setLayoutManager(mLayoutManager);
|
binding.lvElements.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
||||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
if (dy > 0) {
|
if (dy > 0) {
|
||||||
int visibleItemCount = mLayoutManager.getChildCount();
|
int visibleItemCount = mLayoutManager.getChildCount();
|
||||||
|
@ -106,18 +89,18 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
AccountsVM viewModel = new ViewModelProvider(DisplayAccountsFragment.this).get(AccountsVM.class);
|
AccountsVM viewModel = new ViewModelProvider(DisplayAccountsFragment.this).get(AccountsVM.class);
|
||||||
viewModel.getAccounts(accountFetch, max_id).observe(DisplayAccountsFragment.this.requireActivity(), apiResponse -> manageViewAccounts(apiResponse));
|
viewModel.getAccounts(accountFetch, max_id).observe(DisplayAccountsFragment.this.requireActivity(), apiResponse -> manageViewAccounts(apiResponse));
|
||||||
nextElementLoader.setVisibility(View.VISIBLE);
|
binding.loadingNext.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
||||||
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.MUTED, max_id).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
|
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.MUTED, max_id).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
|
||||||
return rootView;
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -134,7 +117,7 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
rootView = null;
|
binding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scrollToTop() {
|
public void scrollToTop() {
|
||||||
if (lv_accounts != null)
|
binding.lvElements.setAdapter(accountsListAdapter);
|
||||||
lv_accounts.setAdapter(accountsListAdapter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void manageViewAccounts(APIResponse apiResponse) {
|
private void manageViewAccounts(APIResponse apiResponse) {
|
||||||
mainLoader.setVisibility(View.GONE);
|
binding.loader.setVisibility(View.GONE);
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
binding.loadingNext.setVisibility(View.GONE);
|
||||||
if (apiResponse.getError() != null) {
|
if (apiResponse.getError() != null) {
|
||||||
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;
|
flag_loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -181,9 +157,9 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
||||||
max_id = "0";
|
max_id = "0";
|
||||||
}
|
}
|
||||||
if (firstLoad && (accounts == null || accounts.size() == 0))
|
if (firstLoad && (accounts == null || accounts.size() == 0))
|
||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
binding.noAction.setVisibility(View.VISIBLE);
|
||||||
else
|
else
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
binding.noAction.setVisibility(View.GONE);
|
||||||
max_id = String.valueOf(Integer.parseInt(max_id) + 20);
|
max_id = String.valueOf(Integer.parseInt(max_id) + 20);
|
||||||
if (accounts != null && accounts.size() > 0) {
|
if (accounts != null && accounts.size() > 0) {
|
||||||
int previousPosition = this.accounts.size();
|
int previousPosition = this.accounts.size();
|
||||||
|
@ -192,11 +168,11 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
||||||
if (previousPosition == 0) {
|
if (previousPosition == 0) {
|
||||||
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
|
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
|
||||||
accountsListAdapter.allAccountsRemoved = this;
|
accountsListAdapter.allAccountsRemoved = this;
|
||||||
lv_accounts.setAdapter(accountsListAdapter);
|
binding.lvElements.setAdapter(accountsListAdapter);
|
||||||
} else
|
} else
|
||||||
accountsListAdapter.notifyItemRangeChanged(currentPosition, accounts.size());
|
accountsListAdapter.notifyItemRangeChanged(currentPosition, accounts.size());
|
||||||
}
|
}
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
binding.swipeContainer.setRefreshing(false);
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,14 +181,14 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
||||||
accounts = new ArrayList<>();
|
accounts = new ArrayList<>();
|
||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swipeRefreshLayout.setRefreshing(true);
|
binding.swipeContainer.setRefreshing(true);
|
||||||
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
||||||
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.MUTED, null).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
|
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.MUTED, null).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAllAccountsRemoved() {
|
public void onAllAccountsRemoved() {
|
||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
binding.noAction.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
||||||
private ChannelListAdapter channelListAdapter;
|
private ChannelListAdapter channelListAdapter;
|
||||||
private List<ChannelData.Channel> channels;
|
private List<ChannelData.Channel> channels;
|
||||||
private String name;
|
private String name;
|
||||||
private View rootView;
|
|
||||||
private FloatingActionButton action_button;
|
private FloatingActionButton action_button;
|
||||||
private FragmentRecyclerviewPeertubeBinding binding;
|
private FragmentRecyclerviewPeertubeBinding binding;
|
||||||
private AddChannelPeertubeBinding bindingDialog;
|
private AddChannelPeertubeBinding bindingDialog;
|
||||||
|
@ -88,8 +87,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
||||||
|
|
||||||
|
|
||||||
binding = FragmentRecyclerviewPeertubeBinding.inflate(LayoutInflater.from(context));
|
binding = FragmentRecyclerviewPeertubeBinding.inflate(LayoutInflater.from(context));
|
||||||
rootView = binding.getRoot();
|
|
||||||
context = getContext();
|
|
||||||
Bundle bundle = this.getArguments();
|
Bundle bundle = this.getArguments();
|
||||||
channels = new ArrayList<>();
|
channels = new ArrayList<>();
|
||||||
max_id = "0";
|
max_id = "0";
|
||||||
|
@ -119,7 +116,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
||||||
binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);
|
binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);
|
||||||
|
|
||||||
loadChannels(max_id);
|
loadChannels(max_id);
|
||||||
return rootView;
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadChannels(String max_id) {
|
private void loadChannels(String max_id) {
|
||||||
|
@ -168,7 +165,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
rootView = null;
|
binding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,8 +25,6 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -35,7 +33,6 @@ import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@ -45,6 +42,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
|
import app.fedilab.android.databinding.FragmentOverviewPeertubeBinding;
|
||||||
import app.fedilab.android.peertube.client.APIResponse;
|
import app.fedilab.android.peertube.client.APIResponse;
|
||||||
import app.fedilab.android.peertube.client.data.VideoData;
|
import app.fedilab.android.peertube.client.data.VideoData;
|
||||||
import app.fedilab.android.peertube.client.entities.OverviewVideo;
|
import app.fedilab.android.peertube.client.entities.OverviewVideo;
|
||||||
|
@ -63,20 +61,16 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
|
||||||
private LinearLayoutManager mLayoutManager;
|
private LinearLayoutManager mLayoutManager;
|
||||||
private GridLayoutManager gLayoutManager;
|
private GridLayoutManager gLayoutManager;
|
||||||
private boolean flag_loading;
|
private boolean flag_loading;
|
||||||
private Context context;
|
|
||||||
private PeertubeAdapter peertubeAdapater;
|
private PeertubeAdapter peertubeAdapater;
|
||||||
private int page;
|
private int page;
|
||||||
private List<VideoData.Video> peertubes;
|
private List<VideoData.Video> peertubes;
|
||||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
|
||||||
private boolean firstLoad;
|
private boolean firstLoad;
|
||||||
private SwipeRefreshLayout swipeRefreshLayout;
|
|
||||||
private TextView textviewNoActionText;
|
|
||||||
private View rootView;
|
private View rootView;
|
||||||
private RecyclerView lv_status;
|
private RecyclerView lv_status;
|
||||||
private TimelineVM viewModelFeeds;
|
private TimelineVM viewModelFeeds;
|
||||||
private Map<String, Boolean> relationship;
|
private Map<String, Boolean> relationship;
|
||||||
private Map<String, List<PlaylistExist>> playlists;
|
private Map<String, List<PlaylistExist>> playlists;
|
||||||
|
private FragmentOverviewPeertubeBinding binding;
|
||||||
|
|
||||||
public DisplayOverviewFragment() {
|
public DisplayOverviewFragment() {
|
||||||
}
|
}
|
||||||
|
@ -84,23 +78,17 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
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<>();
|
peertubes = new ArrayList<>();
|
||||||
context = getContext();
|
|
||||||
lv_status = rootView.findViewById(R.id.lv_status);
|
lv_status = rootView.findViewById(R.id.lv_status);
|
||||||
page = 1;
|
page = 1;
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
|
|
||||||
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
|
binding.loader.setVisibility(View.VISIBLE);
|
||||||
mainLoader = rootView.findViewById(R.id.loader);
|
binding.loadingNextStatus.setVisibility(View.GONE);
|
||||||
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);
|
|
||||||
|
|
||||||
peertubeAdapater = new PeertubeAdapter(this.peertubes);
|
peertubeAdapater = new PeertubeAdapter(this.peertubes);
|
||||||
|
|
||||||
|
@ -110,19 +98,19 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
|
||||||
lv_status.setAdapter(peertubeAdapater);
|
lv_status.setAdapter(peertubeAdapater);
|
||||||
|
|
||||||
|
|
||||||
if (!Helper.isTablet(context)) {
|
if (!Helper.isTablet(requireActivity())) {
|
||||||
mLayoutManager = new LinearLayoutManager(context);
|
mLayoutManager = new LinearLayoutManager(requireActivity());
|
||||||
lv_status.setLayoutManager(mLayoutManager);
|
lv_status.setLayoutManager(mLayoutManager);
|
||||||
} else {
|
} else {
|
||||||
gLayoutManager = new GridLayoutManager(context, 2);
|
gLayoutManager = new GridLayoutManager(requireActivity(), 2);
|
||||||
int spanCount = (int) Helper.convertDpToPixel(2, context);
|
int spanCount = (int) Helper.convertDpToPixel(2, requireActivity());
|
||||||
int spacing = (int) Helper.convertDpToPixel(5, context);
|
int spacing = (int) Helper.convertDpToPixel(5, requireActivity());
|
||||||
lv_status.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
|
lv_status.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
|
||||||
lv_status.setLayoutManager(gLayoutManager);
|
lv_status.setLayoutManager(gLayoutManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModelFeeds = new ViewModelProvider(DisplayOverviewFragment.this).get(TimelineVM.class);
|
viewModelFeeds = new ViewModelProvider(DisplayOverviewFragment.this).get(TimelineVM.class);
|
||||||
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
|
binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);
|
||||||
loadTimeline(page);
|
loadTimeline(page);
|
||||||
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
|
@ -131,14 +119,14 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
|
||||||
if (dy > 0) {
|
if (dy > 0) {
|
||||||
int visibleItemCount = mLayoutManager.getChildCount();
|
int visibleItemCount = mLayoutManager.getChildCount();
|
||||||
int totalItemCount = mLayoutManager.getItemCount();
|
int totalItemCount = mLayoutManager.getItemCount();
|
||||||
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
|
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||||
if (!flag_loading) {
|
if (!flag_loading) {
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
loadTimeline(page);
|
loadTimeline(page);
|
||||||
nextElementLoader.setVisibility(View.VISIBLE);
|
binding.loadingNextStatus.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
binding.loadingNextStatus.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (gLayoutManager != null) {
|
} else if (gLayoutManager != null) {
|
||||||
|
@ -146,14 +134,14 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
|
||||||
if (dy > 0) {
|
if (dy > 0) {
|
||||||
int visibleItemCount = gLayoutManager.getChildCount();
|
int visibleItemCount = gLayoutManager.getChildCount();
|
||||||
int totalItemCount = gLayoutManager.getItemCount();
|
int totalItemCount = gLayoutManager.getItemCount();
|
||||||
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
|
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||||
if (!flag_loading) {
|
if (!flag_loading) {
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
loadTimeline(page);
|
loadTimeline(page);
|
||||||
nextElementLoader.setVisibility(View.VISIBLE);
|
binding.loadingNextStatus.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
binding.loadingNextStatus.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,11 +155,9 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (swipeRefreshLayout != null) {
|
binding.swipeContainer.setEnabled(false);
|
||||||
swipeRefreshLayout.setEnabled(false);
|
binding.swipeContainer.setRefreshing(false);
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
binding.swipeContainer.clearAnimation();
|
||||||
swipeRefreshLayout.clearAnimation();
|
|
||||||
}
|
|
||||||
if (getActivity() != null) {
|
if (getActivity() != null) {
|
||||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
if (imm != null && getView() != null) {
|
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
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
|
@ -207,16 +187,16 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
|
||||||
|
|
||||||
private void manageVIewVideos(APIResponse apiResponse) {
|
private void manageVIewVideos(APIResponse apiResponse) {
|
||||||
//hide loaders
|
//hide loaders
|
||||||
mainLoader.setVisibility(View.GONE);
|
binding.loader.setVisibility(View.GONE);
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
binding.loadingNextStatus.setVisibility(View.GONE);
|
||||||
//handle other API error
|
//handle other API error
|
||||||
if (this.peertubes == null || apiResponse == null || apiResponse.getOverviewVideo() == null || (apiResponse.getError() != null)) {
|
if (this.peertubes == null || apiResponse == null || apiResponse.getOverviewVideo() == null || (apiResponse.getError() != null)) {
|
||||||
if (apiResponse == 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 {
|
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;
|
flag_loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -313,11 +293,11 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
|
||||||
} else
|
} else
|
||||||
peertubeAdapater.notifyItemRangeInserted(previousPosition, totalAdded);
|
peertubeAdapater.notifyItemRangeInserted(previousPosition, totalAdded);
|
||||||
//remove handlers
|
//remove handlers
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
binding.swipeContainer.setRefreshing(false);
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
binding.noAction.setVisibility(View.GONE);
|
||||||
if (firstLoad && (this.peertubes == null || this.peertubes.size() == 0)) {
|
if (firstLoad && (this.peertubes == null || this.peertubes.size() == 0)) {
|
||||||
textviewNoActionText.setText(R.string.no_video_to_display);
|
binding.noActionText.setText(R.string.no_video_to_display);
|
||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
binding.noAction.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
flag_loading = false;
|
flag_loading = false;
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
|
@ -339,7 +319,7 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
swipeRefreshLayout.setEnabled(true);
|
binding.swipeContainer.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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.client.RetrofitPeertubeAPI.DataType.MY_CHANNELS;
|
||||||
import static app.fedilab.android.peertube.helper.Helper.peertubeInformation;
|
import static app.fedilab.android.peertube.helper.Helper.peertubeInformation;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -32,22 +31,14 @@ import android.view.WindowManager;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
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 android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
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.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -57,6 +48,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
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.activities.PlaylistsActivity;
|
||||||
import app.fedilab.android.peertube.client.APIResponse;
|
import app.fedilab.android.peertube.client.APIResponse;
|
||||||
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
|
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
|
||||||
|
@ -73,41 +66,30 @@ import es.dmoral.toasty.Toasty;
|
||||||
public class DisplayPlaylistsFragment extends Fragment {
|
public class DisplayPlaylistsFragment extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
private Context context;
|
|
||||||
private List<Playlist> playlists;
|
private List<Playlist> playlists;
|
||||||
private RelativeLayout mainLoader;
|
|
||||||
private FloatingActionButton add_new;
|
|
||||||
private PlaylistAdapter playlistAdapter;
|
private PlaylistAdapter playlistAdapter;
|
||||||
private RelativeLayout textviewNoAction;
|
|
||||||
private HashMap<Integer, String> privacyToSend;
|
private HashMap<Integer, String> privacyToSend;
|
||||||
private HashMap<String, String> channelToSend;
|
private HashMap<String, String> channelToSend;
|
||||||
private Spinner set_upload_channel;
|
|
||||||
private Spinner set_upload_privacy;
|
|
||||||
private HashMap<String, String> channels;
|
private HashMap<String, String> channels;
|
||||||
|
private FragmentPlaylistsPeertubeBinding binding;
|
||||||
|
private AddPlaylistPeertubeBinding bindingAlert;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
//View for fragment is the same that fragment accounts
|
//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<>();
|
playlists = new ArrayList<>();
|
||||||
|
|
||||||
|
binding.loader.setVisibility(View.VISIBLE);
|
||||||
RecyclerView lv_playlist = rootView.findViewById(R.id.lv_playlist);
|
binding.loadingNextItems.setVisibility(View.GONE);
|
||||||
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);
|
|
||||||
playlists = new ArrayList<>();
|
playlists = new ArrayList<>();
|
||||||
playlistAdapter = new PlaylistAdapter(playlists, false);
|
playlistAdapter = new PlaylistAdapter(playlists, false);
|
||||||
lv_playlist.setAdapter(playlistAdapter);
|
binding.lvPlaylist.setAdapter(playlistAdapter);
|
||||||
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
|
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));
|
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());
|
LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
||||||
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
|
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
|
||||||
|
@ -120,89 +102,80 @@ public class DisplayPlaylistsFragment extends Fragment {
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_new != null) {
|
binding.addNew.setOnClickListener(view -> {
|
||||||
add_new.setOnClickListener(view -> {
|
AlertDialog.Builder dialogBuilder = new MaterialAlertDialogBuilder(requireActivity(), dialogStyle());
|
||||||
AlertDialog.Builder dialogBuilder = new MaterialAlertDialogBuilder(context, dialogStyle());
|
bindingAlert = AddPlaylistPeertubeBinding.inflate(getLayoutInflater());
|
||||||
LayoutInflater inflater1 = ((Activity) context).getLayoutInflater();
|
dialogBuilder.setView(bindingAlert.getRoot());
|
||||||
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);
|
|
||||||
|
|
||||||
ChannelsVM viewModelC = new ViewModelProvider(this).get(ChannelsVM.class);
|
ChannelsVM viewModelC = new ViewModelProvider(this).get(ChannelsVM.class);
|
||||||
viewModelC.get(MY_CHANNELS, null).observe(DisplayPlaylistsFragment.this.requireActivity(), this::manageVIewChannels);
|
viewModelC.get(MY_CHANNELS, null).observe(DisplayPlaylistsFragment.this.requireActivity(), this::manageVIewChannels);
|
||||||
|
|
||||||
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
bindingAlert.displayName.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
||||||
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
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) -> {
|
Playlist playlist = new Playlist();
|
||||||
|
playlist.setDisplayName(bindingAlert.displayName.getText().toString().trim());
|
||||||
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
|
if (bindingAlert.description.getText() != null && bindingAlert.description.getText().toString().trim().length() > 0) {
|
||||||
|
playlist.setDescription(bindingAlert.description.getText().toString().trim());
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
|
|
||||||
});
|
dialog.dismiss();
|
||||||
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> 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();
|
|
||||||
});
|
});
|
||||||
}
|
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||||
return rootView;
|
|
||||||
|
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
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
binding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||||
mainLoader.setVisibility(View.GONE);
|
binding.loader.setVisibility(View.GONE);
|
||||||
add_new.setEnabled(true);
|
binding.addNew.setEnabled(true);
|
||||||
if (apiResponse.getError() != null) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,26 +204,26 @@ public class DisplayPlaylistsFragment extends Fragment {
|
||||||
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
||||||
this.playlists.addAll(apiResponse.getPlaylists());
|
this.playlists.addAll(apiResponse.getPlaylists());
|
||||||
playlistAdapter.notifyDataSetChanged();
|
playlistAdapter.notifyDataSetChanged();
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
binding.noAction.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
binding.noAction.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
} else if (actionType == PlaylistsVM.action.CREATE_PLAYLIST) {
|
} else if (actionType == PlaylistsVM.action.CREATE_PLAYLIST) {
|
||||||
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
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();
|
Bundle b = new Bundle();
|
||||||
b.putSerializable("playlist", apiResponse.getPlaylists().get(0));
|
b.putSerializable("playlist", apiResponse.getPlaylists().get(0));
|
||||||
intent.putExtras(b);
|
intent.putExtras(b);
|
||||||
context.startActivity(intent);
|
startActivity(intent);
|
||||||
this.playlists.add(0, apiResponse.getPlaylists().get(0));
|
this.playlists.add(0, apiResponse.getPlaylists().get(0));
|
||||||
playlistAdapter.notifyDataSetChanged();
|
playlistAdapter.notifyDataSetChanged();
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
binding.noAction.setVisibility(View.GONE);
|
||||||
} else {
|
} 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) {
|
} else if (actionType == PlaylistsVM.action.DELETE_PLAYLIST) {
|
||||||
if (this.playlists.size() == 0)
|
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) {
|
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) {
|
||||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
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
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,9 +254,9 @@ public class DisplayPlaylistsFragment extends Fragment {
|
||||||
|
|
||||||
channelToSend = new HashMap<>();
|
channelToSend = new HashMap<>();
|
||||||
channelToSend.put(channelName[0], channelId[0]);
|
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);
|
android.R.layout.simple_spinner_dropdown_item, channelName);
|
||||||
set_upload_channel.setAdapter(adapterChannel);
|
bindingAlert.setUploadChannel.setAdapter(adapterChannel);
|
||||||
|
|
||||||
LinkedHashMap<String, String> translations = null;
|
LinkedHashMap<String, String> translations = null;
|
||||||
if (peertubeInformation.getTranslations() != null)
|
if (peertubeInformation.getTranslations() != null)
|
||||||
|
@ -313,12 +281,12 @@ public class DisplayPlaylistsFragment extends Fragment {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(context,
|
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(requireActivity(),
|
||||||
android.R.layout.simple_spinner_dropdown_item, privaciesA);
|
android.R.layout.simple_spinner_dropdown_item, privaciesA);
|
||||||
set_upload_privacy.setAdapter(adapterPrivacies);
|
bindingAlert.setUploadPrivacy.setAdapter(adapterPrivacies);
|
||||||
|
|
||||||
//Manage privacies
|
//Manage privacies
|
||||||
set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
bindingAlert.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());
|
||||||
|
@ -342,7 +310,7 @@ public class DisplayPlaylistsFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//Manage languages
|
//Manage languages
|
||||||
set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
bindingAlert.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);
|
||||||
|
|
|
@ -52,16 +52,13 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
<TextView
|
|
||||||
android:id="@+id/no_action_text"
|
android:id="@+id/no_action_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:padding="10dp"
|
android:text="@string/no_videos" />
|
||||||
android:text="@string/no_videos"
|
|
||||||
android:textSize="25sp" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
<!-- Main Loader -->
|
<!-- Main Loader -->
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -71,11 +68,10 @@
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<com.github.ybq.android.spinkit.SpinKitView
|
<ProgressBar
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center" />
|
||||||
app:SpinKit_Color="?colorAccent" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
<!-- Loader for next videos -->
|
<!-- Loader for next videos -->
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -88,11 +84,10 @@
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:layout_constraintBottom_toBottomOf="parent">
|
app:layout_constraintBottom_toBottomOf="parent">
|
||||||
|
|
||||||
<com.github.ybq.android.spinkit.SpinKitView
|
<ProgressBar
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center" />
|
||||||
app:SpinKit_Color="?colorAccent" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
|
@ -33,15 +33,13 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<TextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:id="@+id/no_action_text"
|
android:id="@+id/no_action_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:padding="10dp"
|
android:text="@string/action_playlist_add" />
|
||||||
android:text="@string/action_playlist_add"
|
|
||||||
android:textSize="25sp" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
<!-- Main Loader -->
|
<!-- Main Loader -->
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -51,11 +49,10 @@
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:visibility="gone">
|
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_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center" />
|
||||||
app:SpinKit_Color="?colorAccent" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
<!-- Loader for next items -->
|
<!-- Loader for next items -->
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -67,11 +64,10 @@
|
||||||
android:gravity="bottom|center_horizontal"
|
android:gravity="bottom|center_horizontal"
|
||||||
android:visibility="gone">
|
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_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center" />
|
||||||
app:SpinKit_Color="?colorAccent" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
|
Loading…
Reference in New Issue