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
/app/release/
/app/fdroid_full/release/
/app/google_full/
/app/google_acad/
/frostwire-jlibtorrent/

View File

@ -61,7 +61,7 @@ public class AboutActivity extends BaseActivity {
//Developer click for Mastodon account
TextView developer_mastodon = findViewById(R.id.developer_mastodon);
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.setOnClickListener(v -> {
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);
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);
license.setText(content);
license.setOnClickListener(v -> {

View File

@ -77,7 +77,7 @@ public class AccountActivity extends BaseActivity {
SpannableString content_create = new SpannableString(getString(R.string.join_peertube));
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);

View File

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

View File

@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
@ -24,6 +25,7 @@ import androidx.preference.PreferenceScreen;
import androidx.preference.SeekBarPreference;
import androidx.preference.SwitchPreference;
import com.avatarfirst.avatargenlib.AvatarGenerator;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
@ -39,6 +41,7 @@ import java.util.Set;
import app.fedilab.fedilabtube.BuildConfig;
import app.fedilab.fedilabtube.activities.MainActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.activities.MyAccountActivity;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.UserSettings;
@ -89,227 +92,241 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (getActivity() != null) {
SharedPreferences sharedpreferences = getActivity().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
requireActivity();
SharedPreferences sharedpreferences = requireActivity().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
if (key.compareTo(getString(R.string.set_video_mode_choice)) == 0) {
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
if (set_video_mode_choice != null) {
switch (set_video_mode_choice.getValue()) {
case "0":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
break;
case "1":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_MAGNET);
break;
case "2":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_WEBVIEW);
break;
case "3":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_TORRENT);
break;
}
if (key.compareTo(getString(R.string.set_video_mode_choice)) == 0) {
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
if (set_video_mode_choice != null) {
switch (set_video_mode_choice.getValue()) {
case "0":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
break;
case "1":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_MAGNET);
break;
case "2":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_WEBVIEW);
break;
case "3":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_TORRENT);
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() {
getPreferenceScreen().removeAll();
addPreferencesFromResource(R.xml.main_preferences);
PreferenceScreen preferenceScreen = getPreferenceScreen();
FragmentActivity context = getActivity();
assert context != null;
FragmentActivity context = requireActivity();
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;
}
//****** My Account ******
Preference my_account = findPreference("my_account");
assert my_account != null;
if (!Helper.isLoggedIn(getActivity()) || userMe == null) {
my_account.setVisible(false);
} else {
my_account.setTitle(userMe.getUsername());
my_account.setSummary(userMe.getEmail());
Resources resources = getResources();
Drawable defaultAvatar = ResourcesCompat.getDrawable(resources, R.drawable.missing_peertube, null);
my_account.setIcon(defaultAvatar);
String avatarUrl = null;
if (userMe.getAccount().getAvatar() != null) {
avatarUrl = "https://" + HelperInstance.getLiveInstance(context) + userMe.getAccount().getAvatar().getPath();
if (my_account != null) {
my_account.setOnPreferenceClickListener(preference -> {
startActivity(new Intent(requireActivity(), MyAccountActivity.class));
return false;
});
if (!Helper.isLoggedIn(getActivity()) || userMe == null) {
my_account.setVisible(false);
} else {
my_account.setTitle(userMe.getUsername());
my_account.setSummary(userMe.getEmail());
Resources resources = getResources();
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 *******
ListPreference set_theme_choice = findPreference(getString(R.string.set_theme_choice));
List<String> arrayTheme = Arrays.asList(getResources().getStringArray(R.array.settings_theme));
@ -369,7 +386,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
assert set_video_minimize_choice != null;
set_video_minimize_choice.setChecked(minimized);
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);
}

View File

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

View File

@ -5,12 +5,8 @@
android:key="app_prefs">
<Preference
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>
android:key="my_account"/>
<PreferenceCategory android:title="@string/video_settings">
<androidx.preference.ListPreference
android:icon="@drawable/ic_baseline_slow_motion_video_24"

View File

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