mirror of
				https://framagit.org/tom79/fedilab-tube
				synced 2025-06-05 21:09:11 +02:00 
			
		
		
		
	Fix issue #58 - Remove more option menu for other channels
This commit is contained in:
		| @@ -17,6 +17,7 @@ package app.fedilab.fedilabtube.drawer; | |||||||
| import android.app.AlertDialog; | import android.app.AlertDialog; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.content.Intent; | import android.content.Intent; | ||||||
|  | import android.content.SharedPreferences; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.os.Handler; | import android.os.Handler; | ||||||
| import android.os.Looper; | import android.os.Looper; | ||||||
| @@ -45,15 +46,13 @@ import app.fedilab.fedilabtube.helper.Helper; | |||||||
| public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | ||||||
|  |  | ||||||
|     private final List<Channel> channels; |     private final List<Channel> channels; | ||||||
|     private final boolean myChannel; |  | ||||||
|     public AllChannelRemoved allChannelRemoved; |     public AllChannelRemoved allChannelRemoved; | ||||||
|     public EditAlertDialog editAlertDialog; |     public EditAlertDialog editAlertDialog; | ||||||
|     private Context context; |     private Context context; | ||||||
|  |  | ||||||
|  |  | ||||||
|     public ChannelListAdapter(List<Channel> channels, boolean myChannel) { |     public ChannelListAdapter(List<Channel> channels) { | ||||||
|         this.channels = channels; |         this.channels = channels; | ||||||
|         this.myChannel = myChannel; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @NonNull |     @NonNull | ||||||
| @@ -77,7 +76,7 @@ public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo | |||||||
|         //Profile picture |         //Profile picture | ||||||
|         Helper.loadGiF(context, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, holder.account_pp); |         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.setVisibility(View.GONE); | ||||||
|         } |         } | ||||||
|         holder.more_actions.setOnClickListener(view -> { |         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 |     @Override | ||||||
|     public long getItemId(int position) { |     public long getItemId(int position) { | ||||||
|         return position; |         return position; | ||||||
|   | |||||||
| @@ -177,7 +177,9 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda | |||||||
|                 accounts.add(block.getBlockedAccount()); |                 accounts.add(block.getBlockedAccount()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         if (max_id == null) { | ||||||
|  |             max_id = "0"; | ||||||
|  |         } | ||||||
|         if (firstLoad && (accounts == null || accounts.size() == 0)) |         if (firstLoad && (accounts == null || accounts.size() == 0)) | ||||||
|             textviewNoAction.setVisibility(View.VISIBLE); |             textviewNoAction.setVisibility(View.VISIBLE); | ||||||
|         else |         else | ||||||
|   | |||||||
| @@ -73,7 +73,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap | |||||||
|     private List<ChannelData.Channel> channels; |     private List<ChannelData.Channel> channels; | ||||||
|     private String name; |     private String name; | ||||||
|     private View rootView; |     private View rootView; | ||||||
|     private boolean myChannels; |  | ||||||
|     private FloatingActionButton action_button; |     private FloatingActionButton action_button; | ||||||
|     private FragmentRecyclerviewBinding binding; |     private FragmentRecyclerviewBinding binding; | ||||||
|     private AddChannelBinding bindingDialog; |     private AddChannelBinding bindingDialog; | ||||||
| @@ -90,11 +89,9 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap | |||||||
|         context = getContext(); |         context = getContext(); | ||||||
|         Bundle bundle = this.getArguments(); |         Bundle bundle = this.getArguments(); | ||||||
|         channels = new ArrayList<>(); |         channels = new ArrayList<>(); | ||||||
|         myChannels = true; |  | ||||||
|         max_id = "0"; |         max_id = "0"; | ||||||
|         if (bundle != null) { |         if (bundle != null) { | ||||||
|             name = bundle.getString("name", null); |             name = bundle.getString("name", null); | ||||||
|             myChannels = bundle.getBoolean("myChannels", true); |  | ||||||
|             search_peertube = bundle.getString("search_peertube", null); |             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)); |         binding.lvElements.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); | ||||||
|         channelListAdapter = new ChannelListAdapter(this.channels, myChannels); |         channelListAdapter = new ChannelListAdapter(this.channels); | ||||||
|         channelListAdapter.allChannelRemoved = this; |         channelListAdapter.allChannelRemoved = this; | ||||||
|         channelListAdapter.editAlertDialog = this; |         channelListAdapter.editAlertDialog = this; | ||||||
|         binding.lvElements.setAdapter(channelListAdapter); |         binding.lvElements.setAdapter(channelListAdapter); | ||||||
| @@ -210,7 +207,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap | |||||||
|             int currentPosition = this.channels.size(); |             int currentPosition = this.channels.size(); | ||||||
|             this.channels.addAll(channels); |             this.channels.addAll(channels); | ||||||
|             if (currentPosition == 0) { |             if (currentPosition == 0) { | ||||||
|                 channelListAdapter = new ChannelListAdapter(this.channels, myChannels); |                 channelListAdapter = new ChannelListAdapter(this.channels); | ||||||
|                 channelListAdapter.allChannelRemoved = DisplayChannelsFragment.this; |                 channelListAdapter.allChannelRemoved = DisplayChannelsFragment.this; | ||||||
|                 channelListAdapter.editAlertDialog = DisplayChannelsFragment.this; |                 channelListAdapter.editAlertDialog = DisplayChannelsFragment.this; | ||||||
|                 binding.lvElements.setAdapter(channelListAdapter); |                 binding.lvElements.setAdapter(channelListAdapter); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user