Fix issue #58 - Remove more option menu for other channels
This commit is contained in:
parent
24ad4dbc0f
commit
2500035c33
|
@ -17,6 +17,7 @@ package app.fedilab.fedilabtube.drawer;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
@ -45,15 +46,13 @@ import app.fedilab.fedilabtube.helper.Helper;
|
|||
public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private final List<Channel> channels;
|
||||
private final boolean myChannel;
|
||||
public AllChannelRemoved allChannelRemoved;
|
||||
public EditAlertDialog editAlertDialog;
|
||||
private Context context;
|
||||
|
||||
|
||||
public ChannelListAdapter(List<Channel> channels, boolean myChannel) {
|
||||
public ChannelListAdapter(List<Channel> channels) {
|
||||
this.channels = channels;
|
||||
this.myChannel = myChannel;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -77,7 +76,7 @@ public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||
//Profile picture
|
||||
Helper.loadGiF(context, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, holder.account_pp);
|
||||
|
||||
if (!this.myChannel) {
|
||||
if (!isMyChannel(channel)) {
|
||||
holder.more_actions.setVisibility(View.GONE);
|
||||
}
|
||||
holder.more_actions.setOnClickListener(view -> {
|
||||
|
@ -132,6 +131,20 @@ public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||
|
||||
}
|
||||
|
||||
|
||||
private boolean isMyChannel(Channel channel) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String channeIdOwner = channel.getOwnerAccount().getId();
|
||||
String channeInstanceOwner = channel.getOwnerAccount().getHost();
|
||||
String instanceShar = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||
String userIdShar = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
if (channeIdOwner != null && channeInstanceOwner != null && instanceShar != null && userIdShar != null) {
|
||||
return channeIdOwner.compareTo(userIdShar) == 0 && channeInstanceOwner.compareTo(instanceShar) == 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
|
|
|
@ -177,7 +177,9 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
accounts.add(block.getBlockedAccount());
|
||||
}
|
||||
}
|
||||
|
||||
if (max_id == null) {
|
||||
max_id = "0";
|
||||
}
|
||||
if (firstLoad && (accounts == null || accounts.size() == 0))
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
else
|
||||
|
|
|
@ -73,7 +73,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
private List<ChannelData.Channel> channels;
|
||||
private String name;
|
||||
private View rootView;
|
||||
private boolean myChannels;
|
||||
private FloatingActionButton action_button;
|
||||
private FragmentRecyclerviewBinding binding;
|
||||
private AddChannelBinding bindingDialog;
|
||||
|
@ -90,11 +89,9 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
context = getContext();
|
||||
Bundle bundle = this.getArguments();
|
||||
channels = new ArrayList<>();
|
||||
myChannels = true;
|
||||
max_id = "0";
|
||||
if (bundle != null) {
|
||||
name = bundle.getString("name", null);
|
||||
myChannels = bundle.getBoolean("myChannels", true);
|
||||
search_peertube = bundle.getString("search_peertube", null);
|
||||
}
|
||||
|
||||
|
@ -107,7 +104,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
}
|
||||
|
||||
binding.lvElements.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
|
||||
channelListAdapter = new ChannelListAdapter(this.channels, myChannels);
|
||||
channelListAdapter = new ChannelListAdapter(this.channels);
|
||||
channelListAdapter.allChannelRemoved = this;
|
||||
channelListAdapter.editAlertDialog = this;
|
||||
binding.lvElements.setAdapter(channelListAdapter);
|
||||
|
@ -210,7 +207,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
int currentPosition = this.channels.size();
|
||||
this.channels.addAll(channels);
|
||||
if (currentPosition == 0) {
|
||||
channelListAdapter = new ChannelListAdapter(this.channels, myChannels);
|
||||
channelListAdapter = new ChannelListAdapter(this.channels);
|
||||
channelListAdapter.allChannelRemoved = DisplayChannelsFragment.this;
|
||||
channelListAdapter.editAlertDialog = DisplayChannelsFragment.this;
|
||||
binding.lvElements.setAdapter(channelListAdapter);
|
||||
|
|
Loading…
Reference in New Issue