some fixes

This commit is contained in:
Thomas 2022-05-13 10:58:38 +02:00
parent 1c54d44a22
commit 1ef0389997
10 changed files with 270 additions and 310 deletions

2
.gitignore vendored
View File

@ -9,6 +9,4 @@
.cxx .cxx
/app/release/ /app/release/
/app/fdroid_full/release/ /app/fdroid_full/release/
/app/google_full/
/app/google_acad/
/frostwire-jlibtorrent/ /frostwire-jlibtorrent/

View File

@ -61,7 +61,7 @@ public class AboutActivity extends BaseActivity {
//Developer click for Mastodon account //Developer click for Mastodon account
TextView developer_mastodon = findViewById(R.id.developer_mastodon); TextView developer_mastodon = findViewById(R.id.developer_mastodon);
SpannableString content = new SpannableString(developer_mastodon.getText().toString()); SpannableString content = new SpannableString(developer_mastodon.getText().toString());
content.setSpan(new ForegroundColorSpan(ContextCompat.getColor(AboutActivity.this, Helper.getColorAccent())), 0, content.length(), 0); content.setSpan(new ForegroundColorSpan(Helper.fetchAccentColor(AboutActivity.this)), 0, content.length(), 0);
developer_mastodon.setText(content); developer_mastodon.setText(content);
developer_mastodon.setOnClickListener(v -> { developer_mastodon.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://toot.fedilab.app/@apps")); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://toot.fedilab.app/@apps"));
@ -118,7 +118,7 @@ public class AboutActivity extends BaseActivity {
TextView license = findViewById(R.id.license); TextView license = findViewById(R.id.license);
content = new SpannableString(license.getText().toString()); content = new SpannableString(license.getText().toString());
content.setSpan(new ForegroundColorSpan(ContextCompat.getColor(AboutActivity.this, Helper.getColorAccent())), 0, content.length(), 0); content.setSpan(new ForegroundColorSpan(Helper.fetchAccentColor(AboutActivity.this)), 0, content.length(), 0);
content.setSpan(new UnderlineSpan(), 0, content.length(), 0); content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
license.setText(content); license.setText(content);
license.setOnClickListener(v -> { license.setOnClickListener(v -> {

View File

@ -77,7 +77,7 @@ public class AccountActivity extends BaseActivity {
SpannableString content_create = new SpannableString(getString(R.string.join_peertube)); SpannableString content_create = new SpannableString(getString(R.string.join_peertube));
content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0); content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0);
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(AccountActivity.this, Helper.getColorAccent())), 0, content_create.length(), content_create.setSpan(new ForegroundColorSpan(Helper.fetchAccentColor(AccountActivity.this)), 0, content_create.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE); Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

View File

@ -87,7 +87,7 @@ public class LoginActivity extends BaseActivity {
content_create = new SpannableString(getString(R.string.join_peertube)); content_create = new SpannableString(getString(R.string.join_peertube));
content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0); content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0);
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, Helper.getColorAccent())), 0, content_create.length(), content_create.setSpan(new ForegroundColorSpan(Helper.fetchAccentColor(LoginActivity.this)), 0, content_create.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE); Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
binding.createAnAccountPeertube.setText(content_create, TextView.BufferType.SPANNABLE); binding.createAnAccountPeertube.setText(content_create, TextView.BufferType.SPANNABLE);

View File

@ -37,9 +37,7 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -66,6 +64,7 @@ import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.AccountData; import app.fedilab.fedilabtube.client.data.AccountData;
import app.fedilab.fedilabtube.client.data.ChannelData.Channel; import app.fedilab.fedilabtube.client.data.ChannelData.Channel;
import app.fedilab.fedilabtube.databinding.ActivityShowChannelBinding;
import app.fedilab.fedilabtube.drawer.OwnAccountsAdapter; import app.fedilab.fedilabtube.drawer.OwnAccountsAdapter;
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment; import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment; import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
@ -83,34 +82,25 @@ import es.dmoral.toasty.Toasty;
public class ShowChannelActivity extends BaseActivity { public class ShowChannelActivity extends BaseActivity {
private Button account_follow;
private ViewPager mPager;
private TabLayout tabLayout;
private TextView account_note, subscriber_count;
private Map<String, Boolean> relationship; private Map<String, Boolean> relationship;
private ImageView account_pp;
private TextView account_dn;
private Channel channel; private Channel channel;
private action doAction; private action doAction;
private String channelAcct; private String channelAcct;
private boolean sepiaSearch; private boolean sepiaSearch;
private String peertubeInstance; private String peertubeInstance;
private ActivityShowChannelBinding binding;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
Theme.setTheme(this, HelperInstance.getLiveInstance(this),false); Theme.setTheme(this, HelperInstance.getLiveInstance(this),false);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_channel); binding = ActivityShowChannelBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setTitle(""); setTitle("");
Bundle b = getIntent().getExtras(); Bundle b = getIntent().getExtras();
account_follow = findViewById(R.id.account_follow); binding.accountFollow.setEnabled(false);
subscriber_count = findViewById(R.id.subscriber_count); binding.accountPp.setBackgroundResource(R.drawable.account_pp_border);
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) { if (b != null) {
channel = b.getParcelable("channel"); channel = b.getParcelable("channel");
channelAcct = b.getString("channelId"); channelAcct = b.getString("channelId");
@ -125,38 +115,20 @@ public class ShowChannelActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
tabLayout = findViewById(R.id.account_tabLayout);
account_note = findViewById(R.id.account_note);
ChannelsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(ChannelsVM.class); ChannelsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(ChannelsVM.class);
viewModel.get(sepiaSearch ? peertubeInstance : null, CHANNEL, channelAcct == null ? channel.getAcct() : channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts); viewModel.get(sepiaSearch ? peertubeInstance : null, CHANNEL, channelAcct == null ? channel.getAcct() : channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts);
manageChannel(); manageChannel();
if (MainActivity.typeOfConnection == MainActivity.TypeOfConnection.SURFING) { if (MainActivity.typeOfConnection == MainActivity.TypeOfConnection.SURFING) {
int[][] states = new int[][]{ binding.accountFollow.setText(getString(R.string.action_follow));
new int[]{android.R.attr.state_enabled}, // enabled binding.accountFollow.setEnabled(true);
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[]{
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent())
};
account_follow.setBackgroundTintList(new ColorStateList(states, colors));
account_follow.setText(getString(R.string.action_follow));
account_follow.setEnabled(true);
new Thread(() -> { new Thread(() -> {
try { try {
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<AccountData.Account> accounts = new AccountDAO(ShowChannelActivity.this, db).getAllAccount(); List<AccountData.Account> accounts = new AccountDAO(ShowChannelActivity.this, db).getAllAccount();
runOnUiThread(() -> { runOnUiThread(() -> {
account_follow.setVisibility(View.VISIBLE); binding.accountFollow.setVisibility(View.VISIBLE);
account_follow.setOnClickListener(v -> { binding.accountFollow.setOnClickListener(v -> {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(ShowChannelActivity.this); AlertDialog.Builder builderSingle = new AlertDialog.Builder(ShowChannelActivity.this);
builderSingle.setTitle(getString(R.string.list_of_accounts)); builderSingle.setTitle(getString(R.string.list_of_accounts));
if (accounts != null && accounts.size() > 0) { if (accounts != null && accounts.size() > 0) {
@ -255,19 +227,17 @@ public class ShowChannelActivity extends BaseActivity {
} }
setTitle(channel.getAcct()); setTitle(channel.getAcct());
binding.accountTabLayout.addTab(binding.accountTabLayout.newTab().setText(getString(R.string.videos)));
mPager = findViewById(R.id.account_viewpager); binding.accountViewpager.setOffscreenPageLimit(1);
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.videos)));
mPager.setOffscreenPageLimit(1);
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter); binding.accountViewpager.setAdapter(mPagerAdapter);
ViewGroup.LayoutParams params = tabLayout.getLayoutParams(); ViewGroup.LayoutParams params = binding.accountTabLayout.getLayoutParams();
params.height = 0; params.height = 0;
tabLayout.setLayoutParams(params); binding.accountTabLayout.setLayoutParams(params);
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { binding.accountViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override @Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@ -275,7 +245,7 @@ public class ShowChannelActivity extends BaseActivity {
@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position); TabLayout.Tab tab = binding.accountTabLayout.getTabAt(position);
if (tab != null) if (tab != null)
tab.select(); tab.select();
} }
@ -286,10 +256,10 @@ public class ShowChannelActivity extends BaseActivity {
} }
}); });
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { binding.accountTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override @Override
public void onTabSelected(TabLayout.Tab tab) { public void onTabSelected(TabLayout.Tab tab) {
mPager.setCurrentItem(tab.getPosition()); binding.accountViewpager.setCurrentItem(tab.getPosition());
} }
@Override @Override
@ -300,8 +270,8 @@ public class ShowChannelActivity extends BaseActivity {
@Override @Override
public void onTabReselected(TabLayout.Tab tab) { public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment = null; Fragment fragment = null;
if (mPager.getAdapter() != null) if (binding.accountViewpager.getAdapter() != null)
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition()); fragment = (Fragment) binding.accountViewpager.getAdapter().instantiateItem(binding.accountViewpager, tab.getPosition());
switch (tab.getPosition()) { switch (tab.getPosition()) {
case 0: case 0:
if (fragment != null) { if (fragment != null) {
@ -319,19 +289,19 @@ public class ShowChannelActivity extends BaseActivity {
} }
}); });
account_dn.setText(channel.getDisplayName()); binding.accountDn.setText(channel.getDisplayName());
manageNotes(channel); manageNotes(channel);
Helper.loadAvatar(ShowChannelActivity.this, channel, account_pp); Helper.loadAvatar(ShowChannelActivity.this, channel, binding.accountPp);
//Follow button //Follow button
String target = channel.getAcct(); String target = channel.getAcct();
account_follow.setOnClickListener(v -> { binding.accountFollow.setOnClickListener(v -> {
if (doAction == action.NOTHING) { if (doAction == action.NOTHING) {
Toasty.info(ShowChannelActivity.this, getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show(); Toasty.info(ShowChannelActivity.this, getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show();
} else if (doAction == action.FOLLOW) { } else if (doAction == action.FOLLOW) {
account_follow.setEnabled(false); binding.accountFollow.setEnabled(false);
PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class); PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class);
viewModel.post(FOLLOW, target, null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(FOLLOW, apiResponse)); viewModel.post(FOLLOW, target, null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(FOLLOW, apiResponse));
} else if (doAction == action.UNFOLLOW) { } else if (doAction == action.UNFOLLOW) {
@ -342,14 +312,14 @@ public class ShowChannelActivity extends BaseActivity {
unfollowConfirm.setMessage(channel.getAcct()); unfollowConfirm.setMessage(channel.getAcct());
unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
unfollowConfirm.setPositiveButton(R.string.yes, (dialog, which) -> { unfollowConfirm.setPositiveButton(R.string.yes, (dialog, which) -> {
account_follow.setEnabled(false); binding.accountFollow.setEnabled(false);
PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class); PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class);
viewModel.post(UNFOLLOW, target, null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(UNFOLLOW, apiResponse)); viewModel.post(UNFOLLOW, target, null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(UNFOLLOW, apiResponse));
dialog.dismiss(); dialog.dismiss();
}); });
unfollowConfirm.show(); unfollowConfirm.show();
} else { } else {
account_follow.setEnabled(false); binding.accountFollow.setEnabled(false);
PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class); PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class);
viewModel.post(UNFOLLOW, target, null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(UNFOLLOW, apiResponse)); viewModel.post(UNFOLLOW, target, null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(UNFOLLOW, apiResponse));
} }
@ -378,37 +348,19 @@ public class ShowChannelActivity extends BaseActivity {
//Manages the visibility of the button //Manages the visibility of the button
private void manageButtonVisibility() { private void manageButtonVisibility() {
if (relationship == null || MainActivity.typeOfConnection == SURFING) if (relationship == null || MainActivity.typeOfConnection == SURFING || channel == null)
return; return;
binding.accountFollow.setEnabled(true);
int[][] states = new int[][]{ Boolean isFollowing = relationship.get(channel.getAcct());
new int[]{android.R.attr.state_enabled}, // enabled if (isFollowing != null && isFollowing) {
new int[]{-android.R.attr.state_enabled}, // disabled binding.accountFollow.setText(R.string.action_unfollow);
new int[]{-android.R.attr.state_checked}, // unchecked binding.accountFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowChannelActivity.this, R.color.red_1)));
new int[]{android.R.attr.state_pressed} // pressed
};
int[] colors = new int[]{
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent())
};
account_follow.setBackgroundTintList(new ColorStateList(states, colors));
account_follow.setEnabled(true);
boolean isFollowing = relationship.get(channel.getAcct());
if (isFollowing) {
account_follow.setText(R.string.action_unfollow);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
account_follow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowChannelActivity.this, R.color.red_1)));
}
doAction = action.UNFOLLOW; doAction = action.UNFOLLOW;
} else { } else {
account_follow.setText(R.string.action_follow); binding.accountFollow.setText(R.string.action_follow);
doAction = action.FOLLOW; doAction = action.FOLLOW;
} }
account_follow.setVisibility(View.VISIBLE); binding.accountFollow.setVisibility(View.VISIBLE);
} }
@ -457,8 +409,8 @@ public class ShowChannelActivity extends BaseActivity {
if (channel.getOwnerAccount() != null) { if (channel.getOwnerAccount() != null) {
this.channel.setOwnerAccount(channel.getOwnerAccount()); this.channel.setOwnerAccount(channel.getOwnerAccount());
} }
subscriber_count.setText(getString(R.string.followers_count, Helper.withSuffix(channel.getFollowersCount()))); binding.subscriberCount.setText(getString(R.string.followers_count, Helper.withSuffix(channel.getFollowersCount())));
subscriber_count.setVisibility(View.VISIBLE); binding.subscriberCount.setVisibility(View.VISIBLE);
manageNotes(channel); manageNotes(channel);
} }
} }
@ -471,11 +423,11 @@ public class ShowChannelActivity extends BaseActivity {
else else
spannableString = new SpannableString(Html.fromHtml(channel.getDescription())); spannableString = new SpannableString(Html.fromHtml(channel.getDescription()));
account_note.setText(spannableString, TextView.BufferType.SPANNABLE); binding.accountNote.setText(spannableString, TextView.BufferType.SPANNABLE);
account_note.setMovementMethod(LinkMovementMethod.getInstance()); binding.accountNote.setMovementMethod(LinkMovementMethod.getInstance());
account_note.setVisibility(View.VISIBLE); binding.accountNote.setVisibility(View.VISIBLE);
} else { } else {
account_note.setVisibility(View.GONE); binding.accountNote.setVisibility(View.GONE);
} }
} }

View File

@ -64,7 +64,7 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
//Profile picture //Profile picture
Helper.loadAvatar(context, channel, holder.binding.accountPp); Helper.loadAvatar(context, channel, holder.binding.accountPp);
if (channel.isSelected()) { if (channel.isSelected()) {
holder.binding.mainContainer.setBackgroundColor(ColorUtils.setAlphaComponent(ContextCompat.getColor(context, Helper.getColorAccent()), 50)); holder.binding.mainContainer.setBackgroundColor(ColorUtils.setAlphaComponent(Helper.fetchAccentColor(context), 50));
} else { } else {
holder.binding.mainContainer.setBackgroundColor(Color.TRANSPARENT); holder.binding.mainContainer.setBackgroundColor(Color.TRANSPARENT);
} }

View File

@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -24,6 +25,7 @@ import androidx.preference.PreferenceScreen;
import androidx.preference.SeekBarPreference; import androidx.preference.SeekBarPreference;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import com.avatarfirst.avatargenlib.AvatarGenerator;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
@ -39,6 +41,7 @@ import java.util.Set;
import app.fedilab.fedilabtube.BuildConfig; import app.fedilab.fedilabtube.BuildConfig;
import app.fedilab.fedilabtube.activities.MainActivity; import app.fedilab.fedilabtube.activities.MainActivity;
import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.activities.MyAccountActivity;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.UserSettings; import app.fedilab.fedilabtube.client.entities.UserSettings;
@ -89,226 +92,240 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (getActivity() != null) { requireActivity();
SharedPreferences sharedpreferences = getActivity().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = requireActivity().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
if (key.compareTo(getString(R.string.set_video_mode_choice)) == 0) { if (key.compareTo(getString(R.string.set_video_mode_choice)) == 0) {
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice)); ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
if (set_video_mode_choice != null) { if (set_video_mode_choice != null) {
switch (set_video_mode_choice.getValue()) { switch (set_video_mode_choice.getValue()) {
case "0": case "0":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL); editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
break; break;
case "1": case "1":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_MAGNET); editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_MAGNET);
break; break;
case "2": case "2":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_WEBVIEW); editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_WEBVIEW);
break; break;
case "3": case "3":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_TORRENT); editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_TORRENT);
break; break;
} }
}
} }
if (key.compareTo(getString(R.string.set_theme_choice)) == 0) {
ListPreference set_theme_choice = findPreference(getString(R.string.set_theme_choice));
if (set_theme_choice != null) {
int choice;
switch (set_theme_choice.getValue()) {
case "0":
choice = Helper.LIGHT_MODE;
break;
case "1":
choice = Helper.DARK_MODE;
break;
default:
choice = Helper.DEFAULT_MODE;
}
editor.putInt(Helper.SET_THEME, choice);
editor.apply();
ThemeHelper.switchTo(choice);
}
}
if (key.compareTo(getString(R.string.set_video_sensitive_choice)) == 0) {
ListPreference set_video_sensitive_choice = findPreference(getString(R.string.set_video_sensitive_choice));
if (set_video_sensitive_choice != null) {
editor.putString(getString(R.string.set_video_sensitive_choice), set_video_sensitive_choice.getValue());
editor.apply();
if (Helper.isLoggedIn(getActivity())) {
new Thread(() -> {
UserSettings userSettings = new UserSettings();
userSettings.setNsfwPolicy(set_video_sensitive_choice.getValue());
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity());
api.updateUser(userSettings);
userMe.setNsfwPolicy(set_video_sensitive_choice.getValue());
} catch (Exception | Error e) {
e.printStackTrace();
}
}).start();
}
}
}
if (key.compareTo(getString(R.string.set_video_quality_choice)) == 0) {
ListPreference set_video_quality_choice = findPreference(getString(R.string.set_video_quality_choice));
if (set_video_quality_choice != null) {
switch (set_video_quality_choice.getValue()) {
case "0":
editor.putInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_HIGH);
break;
case "1":
editor.putInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_MEDIUM);
break;
case "2":
editor.putInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_LOW);
break;
}
}
}
if (key.compareTo(getString(R.string.set_video_cache_choice)) == 0) {
SeekBarPreference set_video_cache_choice = findPreference(getString(R.string.set_video_cache_choice));
assert set_video_cache_choice != null;
final int progress = set_video_cache_choice.getValue();
set_video_cache_choice.setSummary(getActivity().getString(R.string.video_cache_value, progress * 10));
editor.putInt(Helper.SET_VIDEO_CACHE, progress * 10);
}
if (key.compareTo(getString(R.string.set_video_minimize_choice)) == 0) {
SwitchPreference set_video_minimize_choice = findPreference(
getString(R.string.set_video_minimize_choice));
assert set_video_minimize_choice != null;
editor.putBoolean(getString(R.string.set_video_minimize_choice), set_video_minimize_choice.isChecked());
}
if (key.compareTo(getString(R.string.set_autoplay_choice)) == 0) {
SwitchPreference set_autoplay_choice = findPreference(getString(R.string.set_autoplay_choice));
assert set_autoplay_choice != null;
editor.putBoolean(getString(R.string.set_autoplay_choice), set_autoplay_choice.isChecked());
if (Helper.isLoggedIn(getActivity())) {
new Thread(() -> {
UserSettings userSettings = new UserSettings();
userSettings.setAutoPlayVideo(set_autoplay_choice.isChecked());
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity());
api.updateUser(userSettings);
} catch (Exception | Error e) {
e.printStackTrace();
}
}).start();
}
}
if (key.compareTo(getString(R.string.set_fullscreen_choice)) == 0) {
SwitchPreference set_fullscreen_choice = findPreference(getString(R.string.set_fullscreen_choice));
assert set_fullscreen_choice != null;
editor.putBoolean(getString(R.string.set_fullscreen_choice), set_fullscreen_choice.isChecked());
}
if (key.compareTo(getString(R.string.set_autoplay_next_video_choice)) == 0) {
SwitchPreference set_autoplay_next_video_choice = findPreference(getString(R.string.set_autoplay_next_video_choice));
assert set_autoplay_next_video_choice != null;
editor.putBoolean(getString(R.string.set_autoplay_next_video_choice), set_autoplay_next_video_choice.isChecked());
if (Helper.isLoggedIn(getActivity())) {
new Thread(() -> {
UserSettings userSettings = new UserSettings();
userSettings.setAutoPlayNextVideo(set_autoplay_next_video_choice.isChecked());
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity());
api.updateUser(userSettings);
} catch (Exception | Error e) {
e.printStackTrace();
}
}).start();
}
}
if (key.compareTo(getString(R.string.set_play_screen_lock_choice)) == 0) {
SwitchPreference set_play_screen_lock_choice = findPreference(getString(R.string.set_play_screen_lock_choice));
assert set_play_screen_lock_choice != null;
editor.putBoolean(getString(R.string.set_play_screen_lock_choice), set_play_screen_lock_choice.isChecked());
}
if (key.compareTo(getString(R.string.set_video_in_list_choice)) == 0) {
SwitchPreference set_video_in_list_choice = findPreference(getString(R.string.set_video_in_list_choice));
assert set_video_in_list_choice != null;
editor.putBoolean(getString(R.string.set_video_in_list_choice), set_video_in_list_choice.isChecked());
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
}
if (key.compareTo(getString(R.string.set_cast_choice)) == 0) {
SwitchPreference set_cast_choice = findPreference(getString(R.string.set_cast_choice));
assert set_cast_choice != null;
editor.putInt(getString(R.string.set_cast_choice), set_cast_choice.isChecked() ? 1 : 0);
Intent intentBC = new Intent(Helper.RECEIVE_CAST_SETTINGS);
Bundle b = new Bundle();
b.putInt("state_asked", set_cast_choice.isChecked() ? 1 : 0);
intentBC.putExtras(b);
LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intentBC);
}
if (key.compareTo(getString(R.string.set_video_language_choice)) == 0) {
MultiSelectListPreference set_video_language_choice = findPreference(getString(R.string.set_video_language_choice));
assert set_video_language_choice != null;
editor.putStringSet(getString(R.string.set_video_language_choice), set_video_language_choice.getValues());
if (Helper.isLoggedIn(getActivity())) {
new Thread(() -> {
UserSettings userSettings = new UserSettings();
Set<String> language_choiceValues = set_video_language_choice.getValues();
userSettings.setVideoLanguages(new ArrayList<>(language_choiceValues));
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity());
api.updateUser(userSettings);
} catch (Exception | Error e) {
e.printStackTrace();
}
}).start();
}
}
editor.apply();
} }
if (key.compareTo(getString(R.string.set_theme_choice)) == 0) {
ListPreference set_theme_choice = findPreference(getString(R.string.set_theme_choice));
if (set_theme_choice != null) {
int choice;
switch (set_theme_choice.getValue()) {
case "0":
choice = Helper.LIGHT_MODE;
break;
case "1":
choice = Helper.DARK_MODE;
break;
default:
choice = Helper.DEFAULT_MODE;
}
editor.putInt(Helper.SET_THEME, choice);
editor.apply();
ThemeHelper.switchTo(choice);
}
}
if (key.compareTo(getString(R.string.set_video_sensitive_choice)) == 0) {
ListPreference set_video_sensitive_choice = findPreference(getString(R.string.set_video_sensitive_choice));
if (set_video_sensitive_choice != null) {
editor.putString(getString(R.string.set_video_sensitive_choice), set_video_sensitive_choice.getValue());
editor.apply();
if (Helper.isLoggedIn(getActivity())) {
new Thread(() -> {
UserSettings userSettings = new UserSettings();
userSettings.setNsfwPolicy(set_video_sensitive_choice.getValue());
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity());
api.updateUser(userSettings);
userMe.setNsfwPolicy(set_video_sensitive_choice.getValue());
} catch (Exception | Error e) {
e.printStackTrace();
}
}).start();
}
}
}
if (key.compareTo(getString(R.string.set_video_quality_choice)) == 0) {
ListPreference set_video_quality_choice = findPreference(getString(R.string.set_video_quality_choice));
if (set_video_quality_choice != null) {
switch (set_video_quality_choice.getValue()) {
case "0":
editor.putInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_HIGH);
break;
case "1":
editor.putInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_MEDIUM);
break;
case "2":
editor.putInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_LOW);
break;
}
}
}
if (key.compareTo(getString(R.string.set_video_cache_choice)) == 0) {
SeekBarPreference set_video_cache_choice = findPreference(getString(R.string.set_video_cache_choice));
assert set_video_cache_choice != null;
final int progress = set_video_cache_choice.getValue();
set_video_cache_choice.setSummary(requireActivity().getString(R.string.video_cache_value, progress * 10));
editor.putInt(Helper.SET_VIDEO_CACHE, progress * 10);
}
if (key.compareTo(getString(R.string.set_video_minimize_choice)) == 0) {
SwitchPreference set_video_minimize_choice = findPreference(
getString(R.string.set_video_minimize_choice));
assert set_video_minimize_choice != null;
editor.putBoolean(getString(R.string.set_video_minimize_choice), set_video_minimize_choice.isChecked());
}
if (key.compareTo(getString(R.string.set_autoplay_choice)) == 0) {
SwitchPreference set_autoplay_choice = findPreference(getString(R.string.set_autoplay_choice));
assert set_autoplay_choice != null;
editor.putBoolean(getString(R.string.set_autoplay_choice), set_autoplay_choice.isChecked());
if (Helper.isLoggedIn(getActivity())) {
new Thread(() -> {
UserSettings userSettings = new UserSettings();
userSettings.setAutoPlayVideo(set_autoplay_choice.isChecked());
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity());
api.updateUser(userSettings);
} catch (Exception | Error e) {
e.printStackTrace();
}
}).start();
}
}
if (key.compareTo(getString(R.string.set_fullscreen_choice)) == 0) {
SwitchPreference set_fullscreen_choice = findPreference(getString(R.string.set_fullscreen_choice));
assert set_fullscreen_choice != null;
editor.putBoolean(getString(R.string.set_fullscreen_choice), set_fullscreen_choice.isChecked());
}
if (key.compareTo(getString(R.string.set_autoplay_next_video_choice)) == 0) {
SwitchPreference set_autoplay_next_video_choice = findPreference(getString(R.string.set_autoplay_next_video_choice));
assert set_autoplay_next_video_choice != null;
editor.putBoolean(getString(R.string.set_autoplay_next_video_choice), set_autoplay_next_video_choice.isChecked());
if (Helper.isLoggedIn(getActivity())) {
new Thread(() -> {
UserSettings userSettings = new UserSettings();
userSettings.setAutoPlayNextVideo(set_autoplay_next_video_choice.isChecked());
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity());
api.updateUser(userSettings);
} catch (Exception | Error e) {
e.printStackTrace();
}
}).start();
}
}
if (key.compareTo(getString(R.string.set_play_screen_lock_choice)) == 0) {
SwitchPreference set_play_screen_lock_choice = findPreference(getString(R.string.set_play_screen_lock_choice));
assert set_play_screen_lock_choice != null;
editor.putBoolean(getString(R.string.set_play_screen_lock_choice), set_play_screen_lock_choice.isChecked());
}
if (key.compareTo(getString(R.string.set_video_in_list_choice)) == 0) {
SwitchPreference set_video_in_list_choice = findPreference(getString(R.string.set_video_in_list_choice));
assert set_video_in_list_choice != null;
editor.putBoolean(getString(R.string.set_video_in_list_choice), set_video_in_list_choice.isChecked());
Intent intent = new Intent(requireActivity(), MainActivity.class);
startActivity(intent);
}
if (key.compareTo(getString(R.string.set_cast_choice)) == 0) {
SwitchPreference set_cast_choice = findPreference(getString(R.string.set_cast_choice));
assert set_cast_choice != null;
editor.putInt(getString(R.string.set_cast_choice), set_cast_choice.isChecked() ? 1 : 0);
Intent intentBC = new Intent(Helper.RECEIVE_CAST_SETTINGS);
Bundle b = new Bundle();
b.putInt("state_asked", set_cast_choice.isChecked() ? 1 : 0);
intentBC.putExtras(b);
LocalBroadcastManager.getInstance(requireActivity()).sendBroadcast(intentBC);
}
if (key.compareTo(getString(R.string.set_video_language_choice)) == 0) {
MultiSelectListPreference set_video_language_choice = findPreference(getString(R.string.set_video_language_choice));
assert set_video_language_choice != null;
editor.putStringSet(getString(R.string.set_video_language_choice), set_video_language_choice.getValues());
if (Helper.isLoggedIn(getActivity())) {
new Thread(() -> {
UserSettings userSettings = new UserSettings();
Set<String> language_choiceValues = set_video_language_choice.getValues();
userSettings.setVideoLanguages(new ArrayList<>(language_choiceValues));
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity());
api.updateUser(userSettings);
} catch (Exception | Error e) {
e.printStackTrace();
}
}).start();
}
}
editor.apply();
} }
private void createPref() { private void createPref() {
getPreferenceScreen().removeAll(); getPreferenceScreen().removeAll();
addPreferencesFromResource(R.xml.main_preferences); addPreferencesFromResource(R.xml.main_preferences);
PreferenceScreen preferenceScreen = getPreferenceScreen(); PreferenceScreen preferenceScreen = getPreferenceScreen();
FragmentActivity context = getActivity(); FragmentActivity context = requireActivity();
assert context != null;
if (preferenceScreen == null) { if (preferenceScreen == null) {
Toasty.error(getActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
return; return;
} }
//****** My Account ****** //****** My Account ******
Preference my_account = findPreference("my_account"); Preference my_account = findPreference("my_account");
assert my_account != null; if (my_account != null) {
if (!Helper.isLoggedIn(getActivity()) || userMe == null) { my_account.setOnPreferenceClickListener(preference -> {
my_account.setVisible(false); startActivity(new Intent(requireActivity(), MyAccountActivity.class));
} else { return false;
my_account.setTitle(userMe.getUsername()); });
my_account.setSummary(userMe.getEmail()); if (!Helper.isLoggedIn(getActivity()) || userMe == null) {
Resources resources = getResources(); my_account.setVisible(false);
Drawable defaultAvatar = ResourcesCompat.getDrawable(resources, R.drawable.missing_peertube, null); } else {
my_account.setIcon(defaultAvatar); my_account.setTitle(userMe.getUsername());
String avatarUrl = null; my_account.setSummary(userMe.getEmail());
if (userMe.getAccount().getAvatar() != null) { Resources resources = getResources();
avatarUrl = "https://" + HelperInstance.getLiveInstance(context) + userMe.getAccount().getAvatar().getPath(); Drawable defaultAvatar = ResourcesCompat.getDrawable(resources, R.drawable.missing_peertube, null);
my_account.setIcon(defaultAvatar);
String avatarUrl = null;
BitmapDrawable avatar = null;
if (userMe.getAccount().getAvatar() != null) {
avatarUrl = "https://" + HelperInstance.getLiveInstance(context) + userMe.getAccount().getAvatar().getPath();
} else {
avatar = new AvatarGenerator.AvatarBuilder(context)
.setLabel(userMe.getAccount().getAcct())
.setAvatarSize(120)
.setTextSize(30)
.toSquare()
.setBackgroundColor(Helper.fetchAccentColor(context))
.build();
}
Glide.with(requireActivity())
.asDrawable()
.load(avatarUrl != null ? avatarUrl : avatar)
.into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
my_account.setIcon(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
} }
Glide.with(getActivity())
.asDrawable()
.load(avatarUrl != null ? avatarUrl : R.drawable.missing_peertube)
.into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
my_account.setIcon(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
} }
//****** App theme ******* //****** App theme *******
ListPreference set_theme_choice = findPreference(getString(R.string.set_theme_choice)); ListPreference set_theme_choice = findPreference(getString(R.string.set_theme_choice));
@ -369,7 +386,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
assert set_video_minimize_choice != null; assert set_video_minimize_choice != null;
set_video_minimize_choice.setChecked(minimized); set_video_minimize_choice.setChecked(minimized);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O
|| !getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { || !requireActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
set_video_minimize_choice.setVisible(false); set_video_minimize_choice.setVisible(false);
} }

View File

@ -665,9 +665,6 @@ public class Helper {
return context.getResources().getBoolean(R.bool.is_tablet); return context.getResources().getBoolean(R.bool.is_tablet);
} }
public static int getColorAccent() {
return R.color.colorAccent;
}
public static boolean isOwner(Context context, Account account) { public static boolean isOwner(Context context, Account account) {

View File

@ -5,12 +5,8 @@
android:key="app_prefs"> android:key="app_prefs">
<Preference <Preference
android:key="my_account"> android:key="my_account"/>
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="app.fedilab.fedilabtube.activities"
android:targetClass="app.fedilab.fedilabtube.activities.MyAccountActivity" />
</Preference>
<PreferenceCategory android:title="@string/video_settings"> <PreferenceCategory android:title="@string/video_settings">
<androidx.preference.ListPreference <androidx.preference.ListPreference
android:icon="@drawable/ic_baseline_slow_motion_video_24" android:icon="@drawable/ic_baseline_slow_motion_video_24"

View File

@ -42,7 +42,7 @@ android {
} }
ext { ext {
libtorrentVersion = '1.2.11.0' libtorrentVersion = '1.2.16.0'
} }
// Custom task which downloads the appropriate version of JAR files for jlibtorrent // Custom task which downloads the appropriate version of JAR files for jlibtorrent