2020-06-27 17:58:13 +02:00
|
|
|
package app.fedilab.fedilabtube;
|
2020-07-01 16:36:08 +02:00
|
|
|
/* Copyright 2020 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of TubeLab
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.ColorStateList;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.Html;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
2020-09-03 19:08:53 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2020-06-27 17:58:13 +02:00
|
|
|
import android.view.View;
|
2020-07-01 17:39:15 +02:00
|
|
|
import android.view.ViewGroup;
|
2020-09-03 18:57:10 +02:00
|
|
|
import android.widget.Button;
|
2020-09-03 19:08:53 +02:00
|
|
|
import android.widget.EditText;
|
2020-06-27 17:58:13 +02:00
|
|
|
import android.widget.ImageView;
|
2020-09-03 19:08:53 +02:00
|
|
|
import android.widget.LinearLayout;
|
2020-06-27 17:58:13 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
2020-09-08 10:11:11 +02:00
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
2020-06-27 17:58:13 +02:00
|
|
|
import androidx.viewpager.widget.PagerAdapter;
|
|
|
|
import androidx.viewpager.widget.ViewPager;
|
|
|
|
|
|
|
|
import com.google.android.material.tabs.TabLayout;
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
import java.util.ArrayList;
|
2020-06-27 17:58:13 +02:00
|
|
|
import java.util.List;
|
2020-09-26 16:46:51 +02:00
|
|
|
import java.util.Map;
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
import app.fedilab.fedilabtube.client.APIResponse;
|
2020-09-26 16:46:51 +02:00
|
|
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
|
|
|
import app.fedilab.fedilabtube.client.data.ChannelData.Channel;
|
2020-06-27 17:58:13 +02:00
|
|
|
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
|
2020-09-25 18:58:04 +02:00
|
|
|
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
|
2020-06-27 17:58:13 +02:00
|
|
|
import app.fedilab.fedilabtube.helper.Helper;
|
2020-09-26 16:46:51 +02:00
|
|
|
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
2020-09-08 10:11:11 +02:00
|
|
|
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
2020-09-08 12:08:49 +02:00
|
|
|
import app.fedilab.fedilabtube.viewmodel.RelationshipVM;
|
2020-09-27 16:33:43 +02:00
|
|
|
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
2020-06-27 17:58:13 +02:00
|
|
|
import es.dmoral.toasty.Toasty;
|
|
|
|
|
|
|
|
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
|
2020-09-26 16:46:51 +02:00
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.FOLLOW;
|
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.MUTE;
|
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT;
|
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.UNFOLLOW;
|
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.CHANNEL;
|
2020-06-27 19:08:52 +02:00
|
|
|
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
public class ShowChannelActivity extends AppCompatActivity {
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
|
2020-09-03 18:57:10 +02:00
|
|
|
private Button account_follow;
|
2020-06-27 17:58:13 +02:00
|
|
|
private ViewPager mPager;
|
|
|
|
private TabLayout tabLayout;
|
2020-09-03 18:58:36 +02:00
|
|
|
private TextView account_note, subscriber_count;
|
2020-10-07 17:46:15 +02:00
|
|
|
private Map<String, Boolean> relationship;
|
2020-06-27 17:58:13 +02:00
|
|
|
private ImageView account_pp;
|
|
|
|
private TextView account_dn;
|
2020-09-26 16:46:51 +02:00
|
|
|
private Channel channel;
|
2020-06-27 17:58:13 +02:00
|
|
|
private action doAction;
|
2020-09-26 16:46:51 +02:00
|
|
|
private String channelAcct;
|
2020-10-10 15:05:39 +02:00
|
|
|
private boolean sepiaSearch;
|
|
|
|
private String peertubeInstance;
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2020-10-16 17:03:07 +02:00
|
|
|
setContentView(R.layout.activity_show_channel);
|
2020-06-27 17:58:13 +02:00
|
|
|
setTitle("");
|
|
|
|
Bundle b = getIntent().getExtras();
|
|
|
|
account_follow = findViewById(R.id.account_follow);
|
2020-09-03 18:58:36 +02:00
|
|
|
subscriber_count = findViewById(R.id.subscriber_count);
|
2020-06-27 17:58:13 +02:00
|
|
|
account_follow.setEnabled(false);
|
|
|
|
account_pp = findViewById(R.id.account_pp);
|
|
|
|
account_dn = findViewById(R.id.account_dn);
|
|
|
|
account_pp.setBackgroundResource(R.drawable.account_pp_border);
|
|
|
|
if (b != null) {
|
2020-09-26 16:46:51 +02:00
|
|
|
channel = b.getParcelable("channel");
|
|
|
|
channelAcct = b.getString("channelId");
|
2020-10-10 15:05:39 +02:00
|
|
|
sepiaSearch = b.getBoolean("sepia_search", false);
|
|
|
|
peertubeInstance = b.getString("peertube_instance", null);
|
|
|
|
|
2020-06-27 17:58:13 +02:00
|
|
|
} else {
|
2020-09-26 16:46:51 +02:00
|
|
|
Toasty.error(ShowChannelActivity.this, getString(R.string.toast_error_loading_account), Toast.LENGTH_LONG).show();
|
2020-06-27 17:58:13 +02:00
|
|
|
}
|
2020-09-03 19:08:53 +02:00
|
|
|
|
2020-09-03 18:58:36 +02:00
|
|
|
if (getSupportActionBar() != null) {
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
}
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
tabLayout = findViewById(R.id.account_tabLayout);
|
|
|
|
account_note = findViewById(R.id.account_note);
|
|
|
|
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
ChannelsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(ChannelsVM.class);
|
2020-10-17 18:50:20 +02:00
|
|
|
viewModel.get(sepiaSearch ? peertubeInstance : null, CHANNEL, channelAcct == null ? channel.getAcct() : channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts);
|
2020-09-27 14:12:06 +02:00
|
|
|
manageChannel();
|
2020-06-27 17:58:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 18:58:36 +02:00
|
|
|
@Override
|
2020-09-03 19:08:53 +02:00
|
|
|
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.main_account, menu);
|
2020-10-10 15:05:39 +02:00
|
|
|
if (!Helper.isLoggedIn(ShowChannelActivity.this) || sepiaSearch) {
|
2020-09-03 19:08:53 +02:00
|
|
|
menu.findItem(R.id.action_mute).setVisible(false);
|
|
|
|
}
|
2020-09-03 18:58:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-03 19:08:53 +02:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
if (item.getItemId() == android.R.id.home) {
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
} else if (item.getItemId() == R.id.action_mute) {
|
2020-09-26 16:46:51 +02:00
|
|
|
PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class);
|
2020-09-29 17:42:15 +02:00
|
|
|
viewModel.post(MUTE, channel.getOwnerAccount().getAcct(), null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(MUTE, apiResponse));
|
2020-09-03 19:08:53 +02:00
|
|
|
} else if (item.getItemId() == R.id.action_report) {
|
2020-09-26 16:46:51 +02:00
|
|
|
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(ShowChannelActivity.this);
|
2020-09-03 19:08:53 +02:00
|
|
|
LayoutInflater inflater1 = getLayoutInflater();
|
2020-09-26 16:46:51 +02:00
|
|
|
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(ShowChannelActivity.this), false);
|
2020-09-03 19:08:53 +02:00
|
|
|
dialogBuilder.setView(dialogView);
|
|
|
|
EditText report_content = dialogView.findViewById(R.id.report_content);
|
|
|
|
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
|
|
|
dialogBuilder.setPositiveButton(R.string.report, (dialog, id) -> {
|
|
|
|
if (report_content.getText().toString().trim().length() == 0) {
|
2020-09-26 16:46:51 +02:00
|
|
|
Toasty.info(ShowChannelActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
|
2020-09-03 19:08:53 +02:00
|
|
|
} else {
|
2020-09-26 16:46:51 +02:00
|
|
|
PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class);
|
|
|
|
viewModel.post(REPORT_ACCOUNT, channel.getId(), report_content.getText().toString()).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(REPORT_ACCOUNT, apiResponse));
|
2020-09-03 19:08:53 +02:00
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create();
|
|
|
|
alertDialog.show();
|
2020-11-11 10:34:28 +01:00
|
|
|
} else if (item.getItemId() == R.id.action_share && channel != null) {
|
2020-11-08 10:43:27 +01:00
|
|
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via));
|
|
|
|
String extra_text = channel.getUrl();
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
try {
|
|
|
|
startActivity(Intent.createChooser(sendIntent, getString(R.string.share_with)));
|
|
|
|
} catch (Exception e) {
|
|
|
|
Toasty.error(ShowChannelActivity.this, getString(R.string.toast_error), Toasty.LENGTH_LONG).show();
|
|
|
|
}
|
2020-11-11 10:42:40 +01:00
|
|
|
}else if (item.getItemId() == R.id.action_display_account) {
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
Intent intent = new Intent(ShowChannelActivity.this, ShowAccountActivity.class);
|
|
|
|
b.putParcelable("account", channel.getOwnerAccount());
|
|
|
|
b.putString("accountAcct", channel.getOwnerAccount().getAcct());
|
|
|
|
intent.putExtras(b);
|
|
|
|
startActivity(intent);
|
2020-09-03 19:08:53 +02:00
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
private void manageChannel() {
|
2020-06-27 17:58:13 +02:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
String accountIdRelation = channel.getAcct();
|
2020-11-11 10:37:49 +01:00
|
|
|
if (isLoggedIn(ShowChannelActivity.this)) {
|
2020-09-26 16:46:51 +02:00
|
|
|
RelationshipVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(RelationshipVM.class);
|
|
|
|
List<String> uids = new ArrayList<>();
|
|
|
|
uids.add(accountIdRelation);
|
|
|
|
viewModel.get(uids).observe(ShowChannelActivity.this, this::manageVIewRelationship);
|
2020-06-27 19:08:52 +02:00
|
|
|
}
|
2020-06-27 17:58:13 +02:00
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
setTitle(channel.getAcct());
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
mPager = findViewById(R.id.account_viewpager);
|
2020-09-26 16:46:51 +02:00
|
|
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.videos)));
|
|
|
|
mPager.setOffscreenPageLimit(1);
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
|
|
|
|
mPager.setAdapter(mPagerAdapter);
|
2020-09-26 16:46:51 +02:00
|
|
|
ViewGroup.LayoutParams params = tabLayout.getLayoutParams();
|
|
|
|
params.height = 0;
|
|
|
|
tabLayout.setLayoutParams(params);
|
2020-06-27 17:58:13 +02:00
|
|
|
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageSelected(int position) {
|
|
|
|
TabLayout.Tab tab = tabLayout.getTabAt(position);
|
|
|
|
if (tab != null)
|
|
|
|
tab.select();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageScrollStateChanged(int state) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onTabSelected(TabLayout.Tab tab) {
|
|
|
|
mPager.setCurrentItem(tab.getPosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabUnselected(TabLayout.Tab tab) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabReselected(TabLayout.Tab tab) {
|
|
|
|
Fragment fragment = null;
|
|
|
|
if (mPager.getAdapter() != null)
|
|
|
|
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
|
|
|
|
switch (tab.getPosition()) {
|
|
|
|
case 0:
|
|
|
|
if (fragment != null) {
|
2020-09-25 18:58:04 +02:00
|
|
|
DisplayVideosFragment displayVideosFragment = ((DisplayVideosFragment) fragment);
|
|
|
|
displayVideosFragment.scrollToTop();
|
2020-06-27 17:58:13 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (fragment != null) {
|
|
|
|
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
|
|
|
|
displayAccountsFragment.scrollToTop();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
account_dn.setText(channel.getDisplayName());
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
manageNotes(channel);
|
2020-10-17 18:50:20 +02:00
|
|
|
Helper.loadGiF(ShowChannelActivity.this, sepiaSearch ? peertubeInstance : null, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, account_pp);
|
2020-06-27 17:58:13 +02:00
|
|
|
//Follow button
|
2020-09-26 16:46:51 +02:00
|
|
|
String target = channel.getAcct();
|
2020-07-01 17:39:15 +02:00
|
|
|
|
2020-06-27 17:58:13 +02:00
|
|
|
account_follow.setOnClickListener(v -> {
|
|
|
|
if (doAction == action.NOTHING) {
|
2020-09-26 16:46:51 +02:00
|
|
|
Toasty.info(ShowChannelActivity.this, getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show();
|
2020-06-27 17:58:13 +02:00
|
|
|
} else if (doAction == action.FOLLOW) {
|
|
|
|
account_follow.setEnabled(false);
|
2020-09-26 16:46:51 +02:00
|
|
|
PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class);
|
|
|
|
viewModel.post(FOLLOW, target, null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(FOLLOW, apiResponse));
|
2020-06-27 17:58:13 +02:00
|
|
|
} else if (doAction == action.UNFOLLOW) {
|
|
|
|
boolean confirm_unfollow = sharedpreferences.getBoolean(Helper.SET_UNFOLLOW_VALIDATION, true);
|
|
|
|
if (confirm_unfollow) {
|
2020-09-26 16:46:51 +02:00
|
|
|
AlertDialog.Builder unfollowConfirm = new AlertDialog.Builder(ShowChannelActivity.this);
|
2020-06-27 17:58:13 +02:00
|
|
|
unfollowConfirm.setTitle(getString(R.string.unfollow_confirm));
|
2020-09-26 16:46:51 +02:00
|
|
|
unfollowConfirm.setMessage(channel.getAcct());
|
2020-06-27 17:58:13 +02:00
|
|
|
unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
|
|
|
unfollowConfirm.setPositiveButton(R.string.yes, (dialog, which) -> {
|
|
|
|
account_follow.setEnabled(false);
|
2020-09-26 16:46:51 +02:00
|
|
|
PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class);
|
|
|
|
viewModel.post(UNFOLLOW, target, null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(UNFOLLOW, apiResponse));
|
2020-06-27 17:58:13 +02:00
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
unfollowConfirm.show();
|
|
|
|
} else {
|
|
|
|
account_follow.setEnabled(false);
|
2020-09-26 16:46:51 +02:00
|
|
|
PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class);
|
|
|
|
viewModel.post(UNFOLLOW, target, null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(UNFOLLOW, apiResponse));
|
2020-06-27 17:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-08 12:08:49 +02:00
|
|
|
public void manageVIewRelationship(APIResponse apiResponse) {
|
2020-06-27 17:58:13 +02:00
|
|
|
|
2020-09-08 12:08:49 +02:00
|
|
|
if (apiResponse.getError() != null) {
|
2020-09-26 16:46:51 +02:00
|
|
|
Toasty.error(ShowChannelActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
2020-06-27 17:58:13 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-09-26 16:46:51 +02:00
|
|
|
this.relationship = apiResponse.getRelationships();
|
2020-06-27 17:58:13 +02:00
|
|
|
manageButtonVisibility();
|
|
|
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Manages the visibility of the button
|
|
|
|
private void manageButtonVisibility() {
|
|
|
|
if (relationship == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
int[][] states = new int[][]{
|
|
|
|
new int[]{android.R.attr.state_enabled}, // enabled
|
|
|
|
new int[]{-android.R.attr.state_enabled}, // disabled
|
|
|
|
new int[]{-android.R.attr.state_checked}, // unchecked
|
|
|
|
new int[]{android.R.attr.state_pressed} // pressed
|
|
|
|
};
|
|
|
|
|
|
|
|
int[] colors = new int[]{
|
2020-09-26 16:46:51 +02:00
|
|
|
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
|
|
|
|
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
|
|
|
|
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
|
|
|
|
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent())
|
2020-06-27 17:58:13 +02:00
|
|
|
};
|
|
|
|
account_follow.setBackgroundTintList(new ColorStateList(states, colors));
|
|
|
|
}
|
|
|
|
account_follow.setEnabled(true);
|
2020-09-26 16:46:51 +02:00
|
|
|
|
2020-10-07 17:46:15 +02:00
|
|
|
boolean isFollowing = relationship.get(channel.getAcct());
|
2020-09-26 16:46:51 +02:00
|
|
|
if (isFollowing) {
|
2020-09-03 18:57:10 +02:00
|
|
|
account_follow.setText(R.string.action_unfollow);
|
2020-06-27 17:58:13 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
2020-09-26 16:46:51 +02:00
|
|
|
account_follow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowChannelActivity.this, R.color.red_1)));
|
2020-06-27 17:58:13 +02:00
|
|
|
}
|
|
|
|
doAction = action.UNFOLLOW;
|
2020-09-26 16:46:51 +02:00
|
|
|
} else {
|
2020-09-03 18:57:10 +02:00
|
|
|
account_follow.setText(R.string.action_follow);
|
2020-06-27 17:58:13 +02:00
|
|
|
doAction = action.FOLLOW;
|
|
|
|
}
|
2020-10-14 10:31:02 +02:00
|
|
|
account_follow.setVisibility(View.VISIBLE);
|
2020-06-27 17:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) {
|
2020-09-08 10:11:11 +02:00
|
|
|
|
|
|
|
if (apiResponse.getError() != null) {
|
2020-09-26 16:46:51 +02:00
|
|
|
Toasty.error(ShowChannelActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
2020-06-27 17:58:13 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-09-26 16:46:51 +02:00
|
|
|
String target = channel.getAcct();
|
2020-06-27 17:58:13 +02:00
|
|
|
//IF action is unfollow or mute, sends an intent to remove statuses
|
2020-09-26 16:46:51 +02:00
|
|
|
if (statusAction == RetrofitPeertubeAPI.ActionType.UNFOLLOW) {
|
2020-06-27 17:58:13 +02:00
|
|
|
Bundle b = new Bundle();
|
2020-09-08 10:11:11 +02:00
|
|
|
b.putString("receive_action", apiResponse.getTargetedId());
|
2020-06-27 17:58:13 +02:00
|
|
|
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
|
|
|
|
intentBC.putExtras(b);
|
|
|
|
}
|
2020-09-26 16:46:51 +02:00
|
|
|
if (statusAction == RetrofitPeertubeAPI.ActionType.UNFOLLOW || statusAction == RetrofitPeertubeAPI.ActionType.FOLLOW) {
|
|
|
|
RelationshipVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(RelationshipVM.class);
|
|
|
|
List<String> uris = new ArrayList<>();
|
|
|
|
uris.add(target);
|
|
|
|
viewModel.get(uris).observe(ShowChannelActivity.this, this::manageVIewRelationship);
|
|
|
|
} else if (statusAction == RetrofitPeertubeAPI.ActionType.MUTE) {
|
|
|
|
Toasty.info(ShowChannelActivity.this, getString(R.string.muted_done), Toast.LENGTH_LONG).show();
|
2020-09-03 19:08:53 +02:00
|
|
|
}
|
2020-06-27 17:58:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-08 12:08:49 +02:00
|
|
|
public void manageViewAccounts(APIResponse apiResponse) {
|
2020-09-26 16:46:51 +02:00
|
|
|
if (apiResponse.getChannels() != null && apiResponse.getChannels().size() == 1) {
|
|
|
|
Channel channel = apiResponse.getChannels().get(0);
|
|
|
|
if (this.channel == null) {
|
|
|
|
this.channel = channel;
|
|
|
|
manageChannel();
|
2020-09-03 19:08:53 +02:00
|
|
|
}
|
2020-09-29 17:42:15 +02:00
|
|
|
if (channel.getOwnerAccount() != null) {
|
2020-09-26 16:46:51 +02:00
|
|
|
this.channel.setOwnerAccount(channel.getOwnerAccount());
|
2020-09-29 17:42:15 +02:00
|
|
|
}
|
2020-09-26 16:46:51 +02:00
|
|
|
subscriber_count.setText(getString(R.string.followers_count, Helper.withSuffix(channel.getFollowersCount())));
|
2020-09-03 18:58:36 +02:00
|
|
|
subscriber_count.setVisibility(View.VISIBLE);
|
2020-09-26 16:46:51 +02:00
|
|
|
manageNotes(channel);
|
2020-09-03 18:58:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
private void manageNotes(Channel channel) {
|
|
|
|
if (channel.getDescription() != null && channel.getDescription().compareTo("null") != 0 && channel.getDescription().trim().length() > 0) {
|
2020-09-03 18:58:36 +02:00
|
|
|
SpannableString spannableString;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
2020-09-26 16:46:51 +02:00
|
|
|
spannableString = new SpannableString(Html.fromHtml(channel.getDescription(), FROM_HTML_MODE_LEGACY));
|
2020-09-03 18:58:36 +02:00
|
|
|
else
|
2020-09-26 16:46:51 +02:00
|
|
|
spannableString = new SpannableString(Html.fromHtml(channel.getDescription()));
|
2020-09-03 18:58:36 +02:00
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
account_note.setText(spannableString, TextView.BufferType.SPANNABLE);
|
2020-09-03 18:58:36 +02:00
|
|
|
account_note.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
account_note.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
account_note.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
2020-06-27 17:58:13 +02:00
|
|
|
|
|
|
|
public enum action {
|
|
|
|
FOLLOW,
|
|
|
|
UNFOLLOW,
|
|
|
|
NOTHING
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-03 19:08:53 +02:00
|
|
|
* Pager adapter for the 2 fragments
|
2020-06-27 17:58:13 +02:00
|
|
|
*/
|
|
|
|
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
|
|
|
|
|
|
|
|
ScreenSlidePagerAdapter(FragmentManager fm) {
|
|
|
|
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
@Override
|
|
|
|
public Fragment getItem(int position) {
|
2020-10-10 15:05:39 +02:00
|
|
|
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
|
2020-06-27 17:58:13 +02:00
|
|
|
Bundle bundle = new Bundle();
|
2020-10-16 17:03:07 +02:00
|
|
|
bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.CHANNEL_VIDEOS);
|
2020-10-10 15:05:39 +02:00
|
|
|
bundle.putString("channelId", channel.getAcct());
|
|
|
|
bundle.putString("peertube_instance", channel.getHost());
|
|
|
|
bundle.putBoolean("sepia_search", sepiaSearch);
|
|
|
|
displayVideosFragment.setArguments(bundle);
|
|
|
|
return displayVideosFragment;
|
2020-06-27 17:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
2020-09-26 16:46:51 +02:00
|
|
|
return 1;
|
2020-06-27 17:58:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|