Filter languages
This commit is contained in:
parent
7a8e2f32b4
commit
a1790bf32d
|
@ -194,6 +194,8 @@
|
|||
|
||||
<string name="set_video_mode_choice" translatable="false">set_video_mode_choice</string>
|
||||
<string name="set_video_minimize_choice" translatable="false">set_video_minimize_choice</string>
|
||||
<string name="set_video_language_choice" translatable="false">set_video_language_choice</string>
|
||||
|
||||
<string name="set_video_mode_description">Permet de changer le mode de lecture pour les vidéos (normal, streaming ou via un navigateur).</string>
|
||||
<string name="register_account">Créer un compte</string>
|
||||
<string name="preview">Aperçu</string>
|
||||
|
@ -251,4 +253,9 @@
|
|||
|
||||
<string name="set_video_minimize">Réduire la taille des vidéos</string>
|
||||
<string name="set_video_minimize_description">Réduit la taille des vidéos quand l\'application est en arrière plan (Android N+)</string>
|
||||
|
||||
|
||||
<string name="set_video_language">Filtrer les langues</string>
|
||||
<string name="set_video_language_description">Filtrer les vidéos en fonction de la langue</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -136,6 +136,9 @@
|
|||
|
||||
<string name="set_video_mode_choice" translatable="false">set_video_mode_choice</string>
|
||||
<string name="set_video_minimize_choice" translatable="false">set_video_minimize_choice</string>
|
||||
<string name="set_video_language_choice" translatable="false">set_video_language_choice</string>
|
||||
|
||||
|
||||
<string name="captions">Captions</string>
|
||||
<string name="pickup_captions">Pickup captions</string>
|
||||
<string name="none">None</string>
|
||||
|
@ -267,4 +270,8 @@
|
|||
|
||||
<string name="set_video_minimize">Minimize videos size</string>
|
||||
<string name="set_video_minimize_description">Minize videos size when the app is in background (Android N+)</string>
|
||||
|
||||
|
||||
<string name="set_video_language">Language filter</string>
|
||||
<string name="set_video_language_description">Filter videos with different languages</string>
|
||||
</resources>
|
|
@ -75,9 +75,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelector;
|
|||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.exoplayer2.ui.PlayerControlView;
|
||||
import com.google.android.exoplayer2.ui.PlayerView;
|
||||
import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
@ -360,7 +358,11 @@ public class PeertubeActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
if (playInMinimized && player != null) {
|
||||
enterVideoMode();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_report) {
|
||||
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
|
||||
|
@ -707,8 +709,7 @@ public class PeertubeActivity extends AppCompatActivity {
|
|||
if (player != null)
|
||||
player.release();
|
||||
|
||||
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
|
||||
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
|
||||
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory());
|
||||
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this, trackSelector);
|
||||
ProgressiveMediaSource videoSource;
|
||||
MediaSource subtitleSource = null;
|
||||
|
@ -724,13 +725,16 @@ public class PeertubeActivity extends AppCompatActivity {
|
|||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
||||
if (uri != null)
|
||||
subtitleSource = new SingleSampleMediaSource(uri, dataSourceFactory, subtitleFormat, C.TIME_UNSET);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(uri, subtitleFormat, C.TIME_UNSET);
|
||||
// subtitleSource = new SingleSampleMediaSource(uri, dataSourceFactory, subtitleFormat, C.TIME_UNSET);
|
||||
|
||||
} else {
|
||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
||||
if (uri != null)
|
||||
subtitleSource = new SingleSampleMediaSource(uri, cacheDataSourceFactory, subtitleFormat, C.TIME_UNSET);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(uri, subtitleFormat, C.TIME_UNSET);
|
||||
// subtitleSource = new SingleSampleMediaSource(uri, cacheDataSourceFactory, subtitleFormat, C.TIME_UNSET);
|
||||
}
|
||||
|
||||
playerView.setPlayer(player);
|
||||
|
@ -744,13 +748,13 @@ public class PeertubeActivity extends AppCompatActivity {
|
|||
player.seekTo(0, position);
|
||||
player.setPlayWhenReady(true);
|
||||
|
||||
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
dialogBuilder.setOnDismissListener(dialogInterface -> {
|
||||
|
||||
});
|
||||
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> dialog.dismiss());
|
||||
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||
|
||||
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create();
|
||||
alertDialog.setTitle(getString(R.string.pickup_captions));
|
||||
|
@ -817,9 +821,14 @@ public class PeertubeActivity extends AppCompatActivity {
|
|||
Toasty.error(PeertubeActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
List<Status> statuses = apiResponse.getStatuses();
|
||||
List<Status> statuses = new ArrayList<>();
|
||||
for (Status status : apiResponse.getStatuses()) {
|
||||
if (status.getContent() != null && status.getContent().trim().length() > 0) {
|
||||
statuses.add(status);
|
||||
}
|
||||
}
|
||||
RecyclerView lv_comments = findViewById(R.id.peertube_comments);
|
||||
if (statuses != null && statuses.size() > 0) {
|
||||
if (statuses.size() > 0) {
|
||||
lv_comments.setVisibility(View.VISIBLE);
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
|
@ -891,7 +900,7 @@ public class PeertubeActivity extends AppCompatActivity {
|
|||
} else {
|
||||
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
||||
if (onStopCalled) {
|
||||
finish();
|
||||
finishAndRemoveTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import app.fedilab.fedilabtube.BuildConfig;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
|
@ -1494,7 +1495,16 @@ public class PeertubeAPI {
|
|||
params.put("sort", "publishedAt");
|
||||
if (filter != null)
|
||||
params.put("filter", filter);
|
||||
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
Set<String> selection = sharedpreferences.getStringSet(context.getString(R.string.set_video_language_choice), null);
|
||||
if (selection != null && selection.size() > 0) {
|
||||
StringBuilder parameters = new StringBuilder();
|
||||
for (String languageOneOf : selection)
|
||||
parameters.append("languageOneOf[]=").append(languageOneOf).append("&");
|
||||
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16));
|
||||
params.put("languageOneOf[]", parameters.toString());
|
||||
}
|
||||
boolean nsfw = sharedpreferences.getBoolean(Helper.SET_VIDEO_NSFW, false);
|
||||
params.put("nsfw", String.valueOf(nsfw));
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
|
|
|
@ -111,7 +111,7 @@ public class StatusListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
status.setVisibility("public");
|
||||
}
|
||||
|
||||
if (status.getAccount().getId().equals(userId))
|
||||
if (status.getAccount() != null && status.getAccount().getId().equals(userId))
|
||||
holder.status_peertube_delete.setVisibility(View.VISIBLE);
|
||||
else
|
||||
holder.status_peertube_delete.setVisibility(View.GONE);
|
||||
|
@ -150,23 +150,23 @@ public class StatusListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
final Account accountForUrl;
|
||||
accountForUrl = status.getAccount();
|
||||
holder.status_account_displayname.setVisibility(View.GONE);
|
||||
holder.status_account_displayname_owner.setText(status.getAccount().getUsername().replace("@", ""), TextView.BufferType.SPANNABLE);
|
||||
if (status.getAccount() != null) {
|
||||
holder.status_account_displayname_owner.setText(status.getAccount().getUsername().replace("@", ""), TextView.BufferType.SPANNABLE);
|
||||
Spannable wordtoSpan;
|
||||
Pattern hashAcct;
|
||||
wordtoSpan = new SpannableString("@" + status.getAccount().getAcct());
|
||||
hashAcct = Pattern.compile("(@" + status.getAccount().getAcct() + ")");
|
||||
Matcher matcherAcct = hashAcct.matcher(wordtoSpan);
|
||||
while (matcherAcct.find()) {
|
||||
int matchStart = matcherAcct.start(1);
|
||||
int matchEnd = matcherAcct.end();
|
||||
if (wordtoSpan.length() >= matchEnd && matchStart < matchEnd) {
|
||||
wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, android.R.color.darker_gray)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
|
||||
Spannable wordtoSpan;
|
||||
Pattern hashAcct;
|
||||
wordtoSpan = new SpannableString("@" + status.getAccount().getAcct());
|
||||
hashAcct = Pattern.compile("(@" + status.getAccount().getAcct() + ")");
|
||||
Matcher matcherAcct = hashAcct.matcher(wordtoSpan);
|
||||
while (matcherAcct.find()) {
|
||||
int matchStart = matcherAcct.start(1);
|
||||
int matchEnd = matcherAcct.end();
|
||||
if (wordtoSpan.length() >= matchEnd && matchStart < matchEnd) {
|
||||
wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, android.R.color.darker_gray)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
holder.status_account_username.setText(wordtoSpan);
|
||||
}
|
||||
holder.status_account_username.setText(wordtoSpan);
|
||||
|
||||
|
||||
holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at()));
|
||||
|
|
|
@ -6,17 +6,26 @@ import android.os.Bundle;
|
|||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.MultiSelectListPreference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
|
@ -82,8 +91,14 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
|||
}
|
||||
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_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());
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
@ -117,6 +132,29 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
|||
|
||||
boolean minimized = sharedpref.getBoolean(getString(R.string.set_video_minimize_choice), true);
|
||||
SwitchPreference set_video_minimize_choice = findPreference(getString(R.string.set_video_minimize_choice));
|
||||
assert set_video_minimize_choice != null;
|
||||
set_video_minimize_choice.setChecked(minimized);
|
||||
|
||||
|
||||
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
||||
List<CharSequence> entriesLanguages = new ArrayList<>();
|
||||
List<CharSequence> valuesLanguages = new ArrayList<>();
|
||||
Iterator<Map.Entry<String, String>> it = languages.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> pair = it.next();
|
||||
entriesLanguages.add(pair.getValue());
|
||||
valuesLanguages.add(pair.getKey());
|
||||
it.remove();
|
||||
}
|
||||
MultiSelectListPreference set_video_language_choice = findPreference(getString(R.string.set_video_language_choice));
|
||||
Set<String> selection = sharedpref.getStringSet(getString(R.string.set_video_language_choice), null);
|
||||
assert set_video_language_choice != null;
|
||||
set_video_language_choice.setEntries(entriesLanguages.toArray(new CharSequence[]{}));
|
||||
set_video_language_choice.setEntryValues(valuesLanguages.toArray(new CharSequence[]{}));
|
||||
|
||||
if (selection != null) {
|
||||
set_video_language_choice.setValues(selection);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z" />
|
||||
</vector>
|
|
@ -14,4 +14,11 @@
|
|||
android:key="@string/set_video_minimize_choice"
|
||||
android:summary="@string/set_video_minimize_description"
|
||||
android:title="@string/set_video_minimize" />
|
||||
|
||||
<androidx.preference.MultiSelectListPreference
|
||||
android:icon="@drawable/ic_baseline_language_24"
|
||||
android:key="@string/set_video_language_choice"
|
||||
android:summary="@string/set_video_language_description"
|
||||
android:title="@string/set_video_language" />
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue