1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-06-05 21:09:11 +02:00

22 Commits
1.0.0 ... 1.0.3

Author SHA1 Message Date
a680046574 change version code 2020-09-04 18:49:05 +02:00
445cc85091 Update Fdroid description 2020-09-04 18:20:05 +02:00
06797160a0 update README.md 2020-09-04 18:18:02 +02:00
b146ca064f Prepare release 1.0.3 2020-09-04 18:14:26 +02:00
f139d02c2c clean 2020-09-04 16:58:50 +02:00
0fcad881bf clean 2020-09-04 15:58:49 +02:00
9eacccf504 Change request 2020-09-04 15:56:18 +02:00
1334419ed9 Add some features 2020-09-03 19:08:53 +02:00
19779c2cf6 Retrieve subscriber count + change layout for profiles 2020-09-03 18:58:36 +02:00
f6ca2e8265 Remove useless features 2020-09-03 18:57:53 +02:00
14faca9b35 Remove entry in menu 2020-09-03 18:57:40 +02:00
c782fd14ae Change bottom menu depending if the user is authenticated or not 2020-09-03 18:57:26 +02:00
c82e9e2ad2 Change displayed videos when clicking a followed account 2020-09-03 18:57:10 +02:00
38e9d9f090 display accounts 2020-09-03 18:56:48 +02:00
6d66b2f08b Some updates 2020-09-03 18:56:28 +02:00
4c51a7c7e8 Fix refresh token issue 2020-07-25 19:15:26 +02:00
2636b86e3e release notes 2020-07-24 08:53:16 +02:00
0950bbb415 release notes 2020-07-22 11:06:56 +02:00
ae458f98fa new release 2020-07-22 11:06:11 +02:00
b16803b5ed more space 2020-07-22 11:03:54 +02:00
dc9dc14fd5 Fix authentication 2020-07-22 10:55:59 +02:00
1f61e7f613 Allow to report videos and accounts 2020-07-21 18:49:13 +02:00
82 changed files with 3572 additions and 1437 deletions

View File

@ -16,15 +16,21 @@ Si vous connectez votre compte, vous pourrez interagir avec les vidéos :
- Écrire/supprimer un commentaire,
- Ajouter/supprimer des vidéos dans les listes de lecture,
- Gérer les listes de lecture,
- Créer/Supprimer des listes de lecture,
- Suivre une chaîne,
- Thumbs-up/down,
- Téléverser des vidéos,
- Modifier vos vidéos,
- Supprimer vos vidéos,
- Voir vos notifications.
- Créer/supprimer une chaîne
- Mettre des comptes en sourdine
- Signaler des vidéos ou des comptes
- Voir l'historique
### Télécharger
Les fichiers apk (debug) sont téléchargeables sur [Framadrive](https://framadrive.org/s/HzzxraPdmF5FDYd)
Lapplication sera par la suite publiée sur F-Droid.
[Fdroid](https://f-droid.org/packages/app.fedilab.fedilabtube/)
[GooglePlay](https://play.google.com/store/apps/details?id=app.fedilab.fedilabtube)

View File

@ -3,15 +3,15 @@ apply plugin: 'com.android.application'
apply plugin: "androidx.navigation.safeargs"
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "app.fedilab.fedilabtube"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0.0"
targetSdkVersion 30
versionCode 5
versionName "1.0.3"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@ -40,9 +40,10 @@ allprojects {
dependencies {
implementation "androidx.multidex:multidex:2.0.1"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation "androidx.fragment:fragment:1.2.5"

View File

@ -16,7 +16,7 @@
<application
android:name=".FedilabTupe"
android:name=".FedilabTube"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
@ -49,8 +49,12 @@
android:name=".ShowAccountActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:theme="@style/AppThemeNoActionBar"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name=".AccountActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden"/>
<activity
android:name=".SearchActivity"
android:configChanges="orientation|screenSize"
@ -85,22 +89,29 @@
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden">
</activity>
<activity
android:name=".SettingsActivity"
android:configChanges="orientation|screenSize"
android:label="@string/settings"
android:windowSoftInputMode="stateAlwaysHidden">
</activity>
<activity
android:name=".PeertubeRegisterActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:label="@string/register_account"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name=".PeertubeUploadActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:label="@string/upload_video"
android:windowSoftInputMode="stateAlwaysHidden" />
<receiver
android:name=".services.PeertubeUploadReceiver"
android:exported="false">
<intent-filter>
<action android:name="app.fedilab.android.uploadservice.broadcast.status" />
<action android:name="app.fedilab.fedilabtube.uploadservice.broadcast.status" />
</intent-filter>
</receiver>
</application>

View File

@ -0,0 +1,256 @@
package app.fedilab.fedilabtube;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import org.jetbrains.annotations.NotNull;
import app.fedilab.fedilabtube.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
import app.fedilab.fedilabtube.fragment.DisplayNotificationsFragment;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
public class AccountActivity extends AppCompatActivity {
private ViewPager mPager;
private TabLayout tabLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account);
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
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, R.color.colorAccent)), 0, content_create.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(AccountActivity.this);
TextView instanceView = findViewById(R.id.instance);
Account account = new AccountDAO(AccountActivity.this, db).getUniqAccount(userId, instance);
if (account == null) {
account = new AccountDAO(AccountActivity.this, db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
}
if (account == null) {
Helper.logoutCurrentUser(AccountActivity.this, null);
return;
}
ImageView profile_picture = findViewById(R.id.profile_picture);
TextView username = findViewById(R.id.username);
TextView displayname = findViewById(R.id.displayname);
setTitle(String.format("@%s", account.getUsername()));
Helper.loadGiF(AccountActivity.this, account, profile_picture);
username.setText(String.format("@%s", account.getUsername()));
displayname.setText(account.getDisplay_name());
instanceView.setText(account.getInstance());
Button logout_button = findViewById(R.id.logout_button);
Account finalAccount = account;
logout_button.setOnClickListener(v -> {
AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(AccountActivity.this);
dialogBuilderLogoutAccount.setMessage(getString(R.string.logout_account_confirmation, finalAccount.getUsername()));
dialogBuilderLogoutAccount.setPositiveButton(R.string.action_logout, (dialog, id) -> {
Helper.logoutCurrentUser(AccountActivity.this, finalAccount);
dialog.dismiss();
});
dialogBuilderLogoutAccount.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialogLogoutAccount = dialogBuilderLogoutAccount.create();
alertDialogLogoutAccount.show();
});
Button settings = findViewById(R.id.settings);
settings.setOnClickListener(v -> {
Intent intent = new Intent(AccountActivity.this, SettingsActivity.class);
startActivity(intent);
});
tabLayout = findViewById(R.id.account_tabLayout);
mPager = findViewById(R.id.account_viewpager);
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_notifications)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_muted)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_channel)));
mPager.setOffscreenPageLimit(3);
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
if (tab != null)
tab.select();
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment = null;
if (mPager.getAdapter() != null)
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
switch (tab.getPosition()) {
case 0:
if (fragment != null) {
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
displayNotificationsFragment.scrollToTop();
}
break;
case 1:
case 2:
if (fragment != null) {
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
displayAccountsFragment.scrollToTop();
}
break;
}
}
});
PagerAdapter mPagerAdapter = new AccountsPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onDestroy() {
super.onDestroy();
}
/**
* Pager adapter for three tabs (notifications, muted, blocked)
*/
private class AccountsPagerAdapter extends FragmentStatePagerAdapter {
AccountsPagerAdapter(FragmentManager fm) {
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}
@NotNull
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
switch (position) {
case 1:
case 2:
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
if (position == 1) {
bundle.putSerializable("accountFetch", RetrieveAccountsAsyncTask.accountFetch.MUTED);
} else {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(AccountActivity.this);
Account account = new AccountDAO(AccountActivity.this, db).getUniqAccount(userId, instance);
bundle.putString("name", account.getUsername() + "@" + account.getInstance());
bundle.putSerializable("accountFetch", RetrieveAccountsAsyncTask.accountFetch.CHANNEL);
}
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
default:
return new DisplayNotificationsFragment();
}
}
@Override
public int getCount() {
return 3;
}
}
}

View File

@ -15,9 +15,10 @@ package app.fedilab.fedilabtube;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.InputFilter;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -38,13 +39,6 @@ import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import net.gotev.uploadservice.MultipartUploadRequest;
import net.gotev.uploadservice.ServerResponse;
import net.gotev.uploadservice.UploadInfo;
import net.gotev.uploadservice.UploadNotificationConfig;
import net.gotev.uploadservice.UploadStatusDelegate;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -55,10 +49,12 @@ import java.util.Map;
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.HttpsConnection;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Playlist;
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
import app.fedilab.fedilabtube.drawer.PlaylistAdapter;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
import es.dmoral.toasty.Toasty;
@ -69,17 +65,15 @@ import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyn
public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylistActionInterface, OnRetrievePeertubeInterface {
PlaylistAdapter playlistAdapter;
private AsyncTask<Void, Void, Void> asyncTask;
private RelativeLayout mainLoader;
private FloatingActionButton add_new;
private RelativeLayout textviewNoAction;
private HashMap<Integer, String> privacyToSend;
private HashMap<String, String> channelToSend;
private Spinner set_upload_channel;
private Spinner set_upload_privacy;
private HashMap<String, String> channels;
private String idChannel;
private List<Playlist> playlists;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -97,20 +91,26 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
RelativeLayout nextElementLoader = findViewById(R.id.loading_next_items);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
idChannel = null;
asyncTask = new ManagePlaylistsAsyncTask(AllPlaylistsActivity.this, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
add_new = findViewById(R.id.add_new);
FloatingActionButton add_new = findViewById(R.id.add_new);
LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
privacyToSend = new HashMap<>();
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
if (privaciesInit.size() > 0) {
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
privacyToSend = new HashMap<>();
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
}
playlists = new ArrayList<>();
ListView lv_playlist = findViewById(R.id.lv_playlist);
playlistAdapter = new PlaylistAdapter(AllPlaylistsActivity.this, playlists, textviewNoAction);
lv_playlist.setAdapter(playlistAdapter);
add_new.setOnClickListener(view -> {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(AllPlaylistsActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.add_playlist, new LinearLayout(AllPlaylistsActivity.this), false);
@ -129,73 +129,51 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
Playlist playlist = new Playlist();
playlist.setDisplayName(display_name.getText().toString().trim());
PlaylistElement playlistElement = new PlaylistElement();
playlistElement.setDisplayName(display_name.getText().toString().trim());
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
playlist.setDescription(description.getText().toString().trim());
}
String idChannel = null;
if (channelToSend != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
idChannel = channelM.getValue();
if (idChannel.length() > 0)
playlist.setVideoChannelId(idChannel);
playlistElement.setDescription(description.getText().toString().trim());
}
playlistElement.setVideoChannelId(idChannel);
String idPrivacy;
String label;
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
String label = privacyM.getValue();
String idPrivacy = String.valueOf(privacyM.getKey());
if (label.equals("Public") && (playlist.getVideoChannelId() == null || playlist.getVideoChannelId().equals(""))) {
idPrivacy = String.valueOf(privacyM.getKey());
label = privacyM.getValue();
if ((label.equals("Public") && (playlistElement.getVideoChannelId() == null || playlistElement.getVideoChannelId().equals("")))) {
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
} else {
if (privacyToSend != null) {
playlist.setPrivacy(privacyToSend);
playlistElement.setPrivacy(idPrivacy);
}
//new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.CREATE_PLAYLIST, playlist, null, null, DisplayPlaylistsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
uploadConfig.getCompleted().autoClear = true;
try {
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
new MultipartUploadRequest(AllPlaylistsActivity.this, "https://" + Helper.getLiveInstance(AllPlaylistsActivity.this) + "/api/v1/video-playlists/")
//.addFileToUpload(uri.toString().replace("file://",""), "videofile")
.addHeader("Authorization", "Bearer " + token)
.setNotificationConfig(uploadConfig)
// .addParameter("name", filename)
.addParameter("videoChannelId", idChannel)
.addParameter("privacy", idPrivacy)
.addParameter("displayName", playlist.getDisplayName())
.addParameter("description", playlist.getDescription())
.setMaxRetries(1)
.setDelegate(new UploadStatusDelegate() {
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
// your code here
}
@Override
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) {
// your code here
exception.printStackTrace();
}
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
asyncTask = new ManagePlaylistsAsyncTask(AllPlaylistsActivity.this, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
// your code here
}
})
.startUpload();
} catch (MalformedURLException e) {
e.printStackTrace();
}
new Thread(() -> {
try {
String playlistId = new PeertubeAPI(AllPlaylistsActivity.this).createPlaylist(playlistElement);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
Playlist playlist = new Playlist();
playlist.setId(playlistId);
playlist.setDescription(playlistElement.getDescription());
playlist.setDisplayName(playlistElement.getDisplayName());
playlist.setPrivacy(privacyToSend);
playlists.add(playlist);
playlistAdapter.notifyDataSetChanged();
};
mainHandler.post(myRunnable);
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (e.getMessage() != null) {
Toasty.error(AllPlaylistsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
} else {
Toasty.error(AllPlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
};
mainHandler.post(myRunnable);
}
}).start();
dialog.dismiss();
add_new.setEnabled(false);
}
} else {
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
@ -240,7 +218,6 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
@Override
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
mainLoader.setVisibility(View.GONE);
add_new.setEnabled(true);
if (apiResponse.getError() != null) {
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
@ -248,11 +225,8 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
if (actionType == ManagePlaylistsAsyncTask.action.GET_PLAYLIST) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
List<Playlist> playlists = new ArrayList<>();
ListView lv_playlist = findViewById(R.id.lv_playlist);
PlaylistAdapter playlistAdapter = new PlaylistAdapter(AllPlaylistsActivity.this, playlists, textviewNoAction);
playlists.addAll(apiResponse.getPlaylists());
lv_playlist.setAdapter(playlistAdapter);
playlistAdapter.notifyDataSetChanged();
textviewNoAction.setVisibility(View.GONE);
} else {
textviewNoAction.setVisibility(View.VISIBLE);
@ -287,17 +261,14 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
String[] channelId = new String[accounts.size() + 1];
int i = 1;
channelName[0] = "";
channelId[0] = "";
channels = new HashMap<>();
channelId[0] = "null";
for (Account account : accounts) {
channels.put(account.getUsername(), account.getId());
channelName[i] = account.getUsername();
channelId[i] = account.getId();
i++;
}
channelToSend = new HashMap<>();
channelToSend.put(channelName[0], channelId[0]);
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(AllPlaylistsActivity.this,
android.R.layout.simple_spinner_dropdown_item, channelName);
set_upload_channel.setAdapter(adapterChannel);
@ -357,19 +328,7 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels);
Iterator<Map.Entry<String, String>> it = channelsCheck.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
if (i == position) {
channelToSend = new HashMap<>();
channelToSend.put(pair.getKey(), pair.getValue());
break;
}
it.remove();
i++;
}
idChannel = channelId[position];
}
@Override

View File

@ -21,12 +21,12 @@ import androidx.multidex.MultiDexApplication;
import net.gotev.uploadservice.UploadService;
public class FedilabTupe extends MultiDexApplication {
public class FedilabTube extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(FedilabTupe.this);
MultiDex.install(FedilabTube.this);
UploadService.NAMESPACE = BuildConfig.APPLICATION_ID;
}

View File

@ -16,7 +16,6 @@ package app.fedilab.fedilabtube;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.SpannableString;
@ -24,51 +23,32 @@ import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
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.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.textfield.TextInputLayout;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeNotificationsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.HttpsConnection;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.PeertubeNotification;
import app.fedilab.fedilabtube.drawer.PeertubeNotificationsListAdapter;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeNotificationsInterface;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import es.dmoral.toasty.Toasty;
public class LoginActivity extends AppCompatActivity implements OnRetrievePeertubeNotificationsInterface {
public class LoginActivity extends AppCompatActivity {
//Peertube notification type
@ -82,23 +62,11 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
public static int MY_VIDEO_IMPORT_ERROR = 8;
private static String client_id;
private static String client_secret;
// public static int NEW_USER_REGISTRATION = 9;
//public static int NEW_FOLLOW = 10;
// public static int COMMENT_MENTION = 11;
LinearLayoutManager mLayoutManager;
private EditText login_uid;
private EditText login_passwd;
private Button connectionButton;
private String actionToken;
private boolean flag_loading;
private PeertubeNotificationsListAdapter notificationsListAdapter;
private String max_id;
private List<PeertubeNotification> notifications;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private boolean swiped;
private AsyncTask<Void, Void, Void> asyncTask;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -153,99 +121,6 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
}
}
});
LinearLayout connected = findViewById(R.id.connected);
LinearLayout not_connected = findViewById(R.id.not_connected);
if (Helper.isLoggedIn(LoginActivity.this)) {
not_connected.setVisibility(View.GONE);
connected.setVisibility(View.VISIBLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(LoginActivity.this);
TextView instanceView = findViewById(R.id.instance);
Account account = new AccountDAO(LoginActivity.this, db).getUniqAccount(userId, instance);
if (account == null) {
account = new AccountDAO(LoginActivity.this, db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
}
if (account != null) {
ImageView profile_picture = findViewById(R.id.profile_picture);
TextView username = findViewById(R.id.username);
TextView displayname = findViewById(R.id.displayname);
Helper.loadGiF(LoginActivity.this, account, profile_picture);
username.setText(String.format("@%s", account.getUsername()));
displayname.setText(account.getDisplay_name());
instanceView.setText(account.getInstance());
Button logout_button = findViewById(R.id.logout_button);
Account finalAccount = account;
logout_button.setOnClickListener(v -> {
AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(LoginActivity.this);
dialogBuilderLogoutAccount.setMessage(getString(R.string.logout_account_confirmation, finalAccount.getUsername()));
dialogBuilderLogoutAccount.setPositiveButton(R.string.action_logout, (dialog, id) -> {
Helper.logoutCurrentUser(LoginActivity.this, finalAccount);
dialog.dismiss();
});
dialogBuilderLogoutAccount.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialogLogoutAccount = dialogBuilderLogoutAccount.create();
alertDialogLogoutAccount.show();
});
} else {
Helper.logoutCurrentUser(LoginActivity.this, null);
}
max_id = null;
firstLoad = true;
flag_loading = true;
notifications = new ArrayList<>();
swiped = false;
swipeRefreshLayout = findViewById(R.id.swipeContainer);
RecyclerView lv_notifications = findViewById(R.id.lv_notifications);
mainLoader = findViewById(R.id.loader);
nextElementLoader = findViewById(R.id.loading_next_notifications);
textviewNoAction = findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
notificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications);
lv_notifications.setAdapter(notificationsListAdapter);
mLayoutManager = new LinearLayoutManager(LoginActivity.this);
lv_notifications.setLayoutManager(mLayoutManager);
lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
asyncTask = new RetrievePeertubeNotificationsAsyncTask(LoginActivity.this, null, max_id, LoginActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
}
}
}
});
swipeRefreshLayout.setOnRefreshListener(() -> {
max_id = null;
firstLoad = true;
flag_loading = true;
swiped = true;
asyncTask = new RetrievePeertubeNotificationsAsyncTask(LoginActivity.this, null, null, LoginActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
});
asyncTask = new RetrievePeertubeNotificationsAsyncTask(LoginActivity.this, null, max_id, LoginActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
connected.setVisibility(View.GONE);
not_connected.setVisibility(View.VISIBLE);
}
connectionButton.setOnClickListener(v -> {
@ -431,50 +306,7 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
@Override
public void onDestroy() {
super.onDestroy();
if (asyncTask != null && !asyncTask.isCancelled()) {
asyncTask.cancel(true);
}
}
@Override
public void onRetrievePeertubeNotifications(APIResponse apiResponse, Account account) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if (apiResponse.getError() != null) {
Toasty.error(LoginActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
flag_loading = false;
swipeRefreshLayout.setRefreshing(false);
swiped = false;
return;
}
int previousPosition = notifications.size();
max_id = apiResponse.getMax_id();
List<PeertubeNotification> notifications = apiResponse.getPeertubeNotifications();
if (!swiped && firstLoad && (notifications == null || notifications.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
if (swiped) {
if (previousPosition > 0) {
this.notifications.subList(0, previousPosition).clear();
notificationsListAdapter.notifyItemRangeRemoved(0, previousPosition);
}
swiped = false;
}
if (notifications != null && notifications.size() > 0) {
this.notifications.addAll(notifications);
notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
} else {
if (firstLoad)
textviewNoAction.setVisibility(View.VISIBLE);
}
swipeRefreshLayout.setRefreshing(false);
firstLoad = false;
//The initial call comes from a classic tab refresh
flag_loading = (max_id == null);
}
}

View File

@ -14,9 +14,11 @@ package app.fedilab.fedilabtube;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
@ -26,7 +28,10 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.navigation.NavController;
import androidx.navigation.NavGraph;
import androidx.navigation.NavInflater;
import androidx.navigation.Navigation;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
@ -34,10 +39,18 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedHashMap;
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
import static app.fedilab.fedilabtube.helper.Helper.academies;
public class MainActivity extends AppCompatActivity {
@ -48,19 +61,54 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main);
BottomNavigationView navView = findViewById(R.id.nav_view);
if (Helper.isLoggedIn(MainActivity.this)) {
navView.inflateMenu(R.menu.bottom_nav_menu_connected);
} else {
navView.inflateMenu(R.menu.bottom_nav_menu);
}
try {
peertubeInformation = new PeertubeInformation();
peertubeInformation.setCategories(new LinkedHashMap<>());
peertubeInformation.setLanguages(new LinkedHashMap<>());
peertubeInformation.setLicences(new LinkedHashMap<>());
peertubeInformation.setPrivacies(new LinkedHashMap<>());
peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>());
peertubeInformation.setTranslations(new LinkedHashMap<>());
new RetrievePeertubeInformationAsyncTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (Exception ignored) {
}
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_discover, R.id.navigation_trending, R.id.navigation_most_liked, R.id.navigation_recently_added, R.id.navigation_home)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
AppBarConfiguration appBarConfiguration;
//Bottom menu won't be the same if the user is authenticated
//When the user is authenticated, the subscription entry will be added and the local one removed.
if (Helper.isLoggedIn(MainActivity.this)) {
appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_discover, R.id.navigation_subscription, R.id.navigation_trending, R.id.navigation_most_liked, R.id.navigation_recently_added)
.build();
} else {
appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_discover, R.id.navigation_trending, R.id.navigation_most_liked, R.id.navigation_recently_added, R.id.navigation_home)
.build();
}
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
if (navHostFragment != null) {
NavInflater inflater = navHostFragment.getNavController().getNavInflater();
NavGraph graph;
//the menu is inflated for authenticated or not authenticated account
if (Helper.isLoggedIn(MainActivity.this)) {
graph = inflater.inflate(R.navigation.mobile_navigation_connected);
} else {
graph = inflater.inflate(R.navigation.mobile_navigation);
}
navHostFragment.getNavController().setGraph(graph);
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
}
}
@Override
@ -74,7 +122,8 @@ public class MainActivity extends AppCompatActivity {
public boolean onQueryTextSubmit(String query) {
Intent intent = new Intent(MainActivity.this, SearchActivity.class);
Bundle b = new Bundle();
b.putString("search", query.trim());
String search = query.trim();
b.putString("search", search);
intent.putExtras(b);
startActivity(intent);
if (!searchView.isIconified()) {
@ -93,19 +142,27 @@ public class MainActivity extends AppCompatActivity {
MenuItem uploadItem = menu.findItem(R.id.action_upload);
MenuItem myVideosItem = menu.findItem(R.id.action_myvideos);
MenuItem playslistItem = menu.findItem(R.id.action_playlist);
MenuItem subscriptionItem = menu.findItem(R.id.action_subscription);
MenuItem historyItem = menu.findItem(R.id.action_history);
if (Helper.isLoggedIn(MainActivity.this)) {
instanceItem.setVisible(false);
uploadItem.setVisible(true);
myVideosItem.setVisible(true);
playslistItem.setVisible(true);
subscriptionItem.setVisible(true);
historyItem.setVisible(true);
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(MainActivity.this);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(MainActivity.this, db).getUniqAccount(userId, instance);
if (account != null) {
new Thread(() -> new PeertubeAPI(MainActivity.this).refreshToken(account.getToken(), account.getInstance())).start();
}
} else {
instanceItem.setVisible(true);
uploadItem.setVisible(false);
myVideosItem.setVisible(false);
playslistItem.setVisible(false);
subscriptionItem.setVisible(false);
historyItem.setVisible(false);
}
return true;
}
@ -116,7 +173,12 @@ public class MainActivity extends AppCompatActivity {
showRadioButtonDialog();
return true;
} else if (item.getItemId() == R.id.action_account) {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
Intent intent;
if (Helper.isLoggedIn(MainActivity.this)) {
intent = new Intent(MainActivity.this, AccountActivity.class);
} else {
intent = new Intent(MainActivity.this, LoginActivity.class);
}
startActivity(intent);
return true;
} else if (item.getItemId() == R.id.action_upload) {
@ -130,10 +192,10 @@ public class MainActivity extends AppCompatActivity {
intent.putExtras(bundle);
startActivity(intent);
return true;
} else if (item.getItemId() == R.id.action_subscription) {
} else if (item.getItemId() == R.id.action_history) {
Intent intent = new Intent(MainActivity.this, MyVideosActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PSUBSCRIPTIONS);
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PEERTUBE_HISTORY);
intent.putExtras(bundle);
startActivity(intent);
return true;
@ -158,6 +220,7 @@ public class MainActivity extends AppCompatActivity {
}
}
@SuppressLint("ApplySharedPref")
private void showRadioButtonDialog() {
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
@ -178,10 +241,8 @@ public class MainActivity extends AppCompatActivity {
editor.commit();
dialog.dismiss();
recreate();
});
AlertDialog alert = alt_bld.create();
alert.show();
}
}

View File

@ -47,6 +47,8 @@ public class MyVideosActivity extends AppCompatActivity implements OnRetrieveFee
setTitle(R.string.my_videos);
} else if (type == RetrieveFeedsAsyncTask.Type.PSUBSCRIPTIONS) {
setTitle(R.string.subscriptions);
} else if (type == RetrieveFeedsAsyncTask.Type.PEERTUBE_HISTORY) {
setTitle(R.string.my_history);
}
if (savedInstanceState == null) {

View File

@ -30,6 +30,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
@ -38,6 +39,7 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
@ -174,7 +176,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
peertube_playlist.setVisibility(View.VISIBLE);
peertube_bookmark.setVisibility(View.GONE);
if( Helper.isTablet(PeertubeActivity.this)) {
if (Helper.isTablet(PeertubeActivity.this)) {
RelativeLayout video_container = findViewById(R.id.video_container);
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
@ -199,9 +201,9 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_DIRECT);
if (mode != Helper.VIDEO_MODE_WEBVIEW && mode != Helper.VIDEO_MODE_DIRECT)
mode = Helper.VIDEO_MODE_DIRECT;
mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
if (mode != Helper.VIDEO_MODE_WEBVIEW && mode != Helper.VIDEO_MODE_NORMAL)
mode = Helper.VIDEO_MODE_NORMAL;
if (mode == Helper.VIDEO_MODE_WEBVIEW) {
webview_video.setVisibility(View.VISIBLE);
playerView.setVisibility(View.GONE);
@ -296,8 +298,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
@Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_webview, menu);
menu.findItem(R.id.action_go).setVisible(false);
getMenuInflater().inflate(R.menu.main_peertube, menu);
return true;
}
@ -306,10 +307,49 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
if (item.getItemId() == android.R.id.home) {
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);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report_choice, new LinearLayout(PeertubeActivity.this), false);
dialogBuilder.setView(dialogView);
Button report_video = dialogView.findViewById(R.id.report_video);
Button report_account = dialogView.findViewById(R.id.report_account);
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
report_video.setOnClickListener(v -> reportAlert(PeertubeAPI.reportType.VIDEO, alertDialog));
report_account.setOnClickListener(v -> reportAlert(PeertubeAPI.reportType.ACCOUNT, alertDialog));
return true;
}
return super.onOptionsItemSelected(item);
}
private void reportAlert(PeertubeAPI.reportType type, androidx.appcompat.app.AlertDialog alertDialog) {
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(PeertubeActivity.this), false);
dialogBuilder.setView(dialogView);
EditText report_content = dialogView.findViewById(R.id.report_content);
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
dialogBuilder.setPositiveButton(R.string.report, (dialog, id) -> {
if (report_content.getText().toString().trim().length() == 0) {
Toasty.info(PeertubeActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
} else {
if (type == PeertubeAPI.reportType.VIDEO) {
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.REPORT_VIDEO, peertube.getId(), report_content.getText().toString(), PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
alertDialog.dismiss();
dialog.dismiss();
} else if (type == PeertubeAPI.reportType.ACCOUNT) {
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.REPORT_ACCOUNT, peertube.getAccount().getId(), report_content.getText().toString(), PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
alertDialog.dismiss();
dialog.dismiss();
}
}
});
androidx.appcompat.app.AlertDialog alertDialog2 = dialogBuilder.create();
alertDialog2.show();
}
public FullScreenMediaController.fullscreen getFullscreen() {
return fullscreen;
}
@ -326,7 +366,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
loader.setVisibility(View.GONE);
return;
}
if (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService()) == null) {
if (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this) == null) {
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
loader.setVisibility(View.GONE);
return;
@ -334,7 +374,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
peertube = apiResponse.getPeertubes().get(0);
//TODO: currently streaming service gives the wrong values for duration
peertube.setStreamService(false);
new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -496,7 +535,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
e.printStackTrace();
}
if (mode == Helper.VIDEO_MODE_DIRECT) {
if (mode == Helper.VIDEO_MODE_NORMAL) {
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
ProgressiveMediaSource videoSource;
@ -504,11 +543,11 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
Util.getUserAgent(PeertubeActivity.this, null), null);
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService())));
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
} else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService())));
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
}
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
@ -524,10 +563,10 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
} else {
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null, peertube.isStreamService()));
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null, PeertubeActivity.this));
}
} else {
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null, peertube.isStreamService()));
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null, PeertubeActivity.this));
}
});
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
@ -674,7 +713,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
PlayerControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution);
resolution.setText(String.format("%sp", res));
if (mode == Helper.VIDEO_MODE_DIRECT) {
if (mode == Helper.VIDEO_MODE_NORMAL) {
if (player != null)
player.release();
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
@ -686,11 +725,11 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
Util.getUserAgent(PeertubeActivity.this, null), null);
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
.createMediaSource(Uri.parse(peertube.getFileUrl(res, PeertubeActivity.this)));
} else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
.createMediaSource(Uri.parse(peertube.getFileUrl(res, PeertubeActivity.this)));
}
player.prepare(videoSource);
player.seekTo(0, position);
@ -705,8 +744,13 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
@Override
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT)
if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT) {
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else if (statusAction == PeertubeAPI.StatusAction.REPORT_ACCOUNT) {
Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show();
} else if (statusAction == PeertubeAPI.StatusAction.REPORT_VIDEO) {
Toasty.success(PeertubeActivity.this, getString(R.string.successful_video_report), Toasty.LENGTH_LONG).show();
}
}
private void initFullscreenDialog() {

View File

@ -14,27 +14,47 @@ package app.fedilab.fedilabtube;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide;
import net.gotev.uploadservice.MultipartUploadRequest;
import net.gotev.uploadservice.ServerResponse;
import net.gotev.uploadservice.UploadInfo;
import net.gotev.uploadservice.UploadNotificationConfig;
import net.gotev.uploadservice.UploadStatusDelegate;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask;
import app.fedilab.fedilabtube.asynctasks.PostPeertubeAsyncTask;
@ -58,6 +78,8 @@ import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyn
public class PeertubeEditUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, OnPostActionInterface {
private final int PICK_IMAGE = 50378;
private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724;
HashMap<Integer, String> categoryToSend;
HashMap<Integer, String> licenseToSend;
HashMap<Integer, String> privacyToSend;
@ -71,6 +93,9 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
private LinkedHashMap<String, String> channels;
private String videoId;
private Account channel;
private ImageView p_video_preview;
private Button set_preview;
private Peertube peertube;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -99,9 +124,10 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
p_video_title = findViewById(R.id.p_video_title);
p_video_description = findViewById(R.id.p_video_description);
p_video_tags = findViewById(R.id.p_video_tags);
p_video_preview = findViewById(R.id.p_video_preview);
set_upload_nsfw = findViewById(R.id.set_upload_nsfw);
set_upload_enable_comments = findViewById(R.id.set_upload_enable_comments);
set_preview = findViewById(R.id.set_preview);
set_upload_delete.setOnClickListener(v -> {
AlertDialog.Builder builderInner;
@ -201,6 +227,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
channels = new LinkedHashMap<>();
setTitle(R.string.edit_video);
}
@ -216,7 +243,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
}
//Peertube video
Peertube peertube = apiResponse.getPeertubes().get(0);
peertube = apiResponse.getPeertubes().get(0);
if (peertube.isUpdate()) {
Toasty.success(PeertubeEditUploadActivity.this, getString(R.string.toast_peertube_video_updated), Toast.LENGTH_LONG).show();
@ -231,6 +258,27 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
privacyToSend = peertube.getPrivacy();
categoryToSend = peertube.getCategory();
Glide.with(PeertubeEditUploadActivity.this)
.load("https://" + peertube.getInstance() + peertube.getThumbnailPath())
.into(p_video_preview);
set_preview.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(PeertubeEditUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PeertubeEditUploadActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/jpg");
String[] mimetypes = {"image/jpg", "image/jpeg"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IMAGE);
});
if (languageToSend == null) {
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
Map.Entry<String, String> entryString = languages.entrySet().iterator().next();
@ -498,6 +546,74 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) {
if (data == null || data.getData() == null) {
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
return;
}
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
uploadConfig.getCompleted().autoClear = true;
try {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
Uri uri = data.getData();
try {
String uploadId = UUID.randomUUID().toString();
new MultipartUploadRequest(PeertubeEditUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeEditUploadActivity.this) + "/api/v1/" + String.format("/videos/%s", peertube.getId()))
.addFileToUpload(uri.toString().replace("file://", ""), "previewfile")
.setMethod("PUT")
.addHeader("Authorization", "Bearer " + token)
.setNotificationConfig(uploadConfig)
.setMaxRetries(2)
.setDelegate(new UploadStatusDelegate() {
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
// your code here
}
@Override
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) {
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
Glide.with(PeertubeEditUploadActivity.this)
.load(uri)
.into(p_video_preview);
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
// your code here
}
})
.startUpload();
} catch (FileNotFoundException e) {
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
} catch (MalformedURLException e) {
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onRetrievePeertubeComments(APIResponse apiResponse) {

View File

@ -15,7 +15,6 @@ package app.fedilab.fedilabtube;
* see <http://www.gnu.org/licenses>. */
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
@ -42,15 +41,8 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import net.gotev.uploadservice.MultipartUploadRequest;
import net.gotev.uploadservice.ServerResponse;
import net.gotev.uploadservice.UploadInfo;
import net.gotev.uploadservice.UploadNotificationAction;
import net.gotev.uploadservice.UploadNotificationConfig;
import net.gotev.uploadservice.UploadServiceSingleBroadcastReceiver;
import net.gotev.uploadservice.UploadStatusDelegate;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.Date;
@ -71,7 +63,7 @@ import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
public class PeertubeUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, UploadStatusDelegate {
public class PeertubeUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface {
private final int PICK_IVDEO = 52378;
@ -85,7 +77,7 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
private String filename;
private HashMap<Integer, String> privacyToSend;
private HashMap<String, String> channelToSend;
private UploadServiceSingleBroadcastReceiver uploadReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -105,10 +97,7 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
new RetrievePeertubeChannelsAsyncTask(PeertubeUploadActivity.this, PeertubeUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
channels = new HashMap<>();
uploadReceiver = new UploadServiceSingleBroadcastReceiver(this);
uploadReceiver.register(this);
setTitle(R.string.upload_video);
}
@Override
@ -122,6 +111,7 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
set_upload_submit.setEnabled(true);
uri = data.getData();
String uriString = uri.toString();
File myFile = new File(uriString);
filename = null;
@ -151,7 +141,6 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
@Override
public void onDestroy() {
super.onDestroy();
uploadReceiver.unregister(this);
}
@Override
@ -327,7 +316,6 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
filename = video_title.getText().toString().trim();
}
String uploadId = UUID.randomUUID().toString();
uploadReceiver.setUploadID(uploadId);
new MultipartUploadRequest(PeertubeUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
.addFileToUpload(uri.toString().replace("file://", ""), "videofile")
.addHeader("Authorization", "Bearer " + token)
@ -338,7 +326,7 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
.addParameter("nsfw", "false")
.addParameter("commentsEnabled", "true")
.addParameter("waitTranscoding", "true")
.setMaxRetries(2)
.setMaxRetries(3)
.startUpload();
finish();
} catch (Exception exc) {
@ -347,37 +335,4 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
}
});
}
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
// your code here
}
@Override
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) {
// your code here
exception.printStackTrace();
}
@SuppressLint("ApplySharedPref")
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
try {
JSONObject response = new JSONObject(serverResponse.getBodyAsString());
String videoID = response.getJSONObject("video").get("id").toString();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.VIDEO_ID, videoID);
editor.commit();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
// your code here
}
}

View File

@ -0,0 +1,43 @@
package app.fedilab.fedilabtube;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import app.fedilab.fedilabtube.fragment.SettingsFragment;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -23,9 +23,13 @@ import android.os.Bundle;
import android.text.Html;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -40,8 +44,6 @@ import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.bumptech.glide.Glide;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout;
import org.jetbrains.annotations.NotNull;
@ -52,6 +54,7 @@ import java.util.List;
import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrieveRelationshipAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrieveSingleAccountAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
@ -64,6 +67,7 @@ import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
import app.fedilab.fedilabtube.fragment.DisplayStatusFragment;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsAccountInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrieveRelationshipInterface;
@ -74,40 +78,35 @@ import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
public class ShowAccountActivity extends AppCompatActivity implements OnPostActionInterface, OnRetrieveFeedsAccountInterface, OnRetrieveRelationshipInterface, OnRetrieveFeedsInterface {
public class ShowAccountActivity extends AppCompatActivity implements OnPostActionInterface, OnRetrieveFeedsAccountInterface, OnRetrieveRelationshipInterface, OnRetrieveFeedsInterface, OnRetrieveAccountsInterface {
private List<Status> statuses;
private StatusListAdapter statusListAdapter;
private ImageButton account_follow;
private Button account_follow;
private ViewPager mPager;
private TabLayout tabLayout;
private TextView account_note;
private String userId;
private TextView account_note, subscriber_count;
private Relationship relationship;
private int maxScrollSize;
private boolean avatarShown = true;
private ImageView account_pp;
private TextView account_dn;
private TextView account_un;
private Account account;
private String accountId;
private boolean ischannel;
private AsyncTask<Void, Void, Void> retrieveRelationship;
private AsyncTask<Void, Void, List<Relationship>> retrieveRelationship;
private action doAction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
setContentView(R.layout.activity_show_account);
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_un = findViewById(R.id.account_un);
account_pp.setBackgroundResource(R.drawable.account_pp_border);
if (b != null) {
account = b.getParcelable("account");
@ -117,8 +116,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
accountId = account.getId();
}
ischannel = b.getBoolean("ischannel", false);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
} else {
Toasty.error(ShowAccountActivity.this, getString(R.string.toast_error_loading_account), Toast.LENGTH_LONG).show();
}
@ -130,23 +127,60 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
statusListAdapter = new StatusListAdapter(statusDrawerParams);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
tabLayout = findViewById(R.id.account_tabLayout);
account_note = findViewById(R.id.account_note);
/*header_edit_profile.setOnClickListener(v -> {
Intent intent = new Intent(ShowAccountActivity.this, EditProfileActivity.class);
startActivity(intent);
});*/
ImageView action_back = findViewById(R.id.action_back);
action_back.setOnClickListener(v -> finish());
if (account != null) {
ManageAccount();
manageAccount();
new RetrieveSingleAccountAsyncTask(ShowAccountActivity.this, account.getAcct(), RetrieveSingleAccountAsyncTask.actionType.CHANNEL, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
new RetrieveSingleAccountAsyncTask(ShowAccountActivity.this, accountId, RetrieveSingleAccountAsyncTask.actionType.CHANNEL, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
private void ManageAccount() {
@Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_account, menu);
if (!Helper.isLoggedIn(ShowAccountActivity.this)) {
menu.findItem(R.id.action_mute).setVisible(false);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
} else if (item.getItemId() == R.id.action_mute) {
new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.MUTE, account.getchannelOwner() != null ? account.getchannelOwner().getAcct() : account.getAcct(), ShowAccountActivity.this).execute();
} else if (item.getItemId() == R.id.action_report) {
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(ShowAccountActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(ShowAccountActivity.this), false);
dialogBuilder.setView(dialogView);
EditText report_content = dialogView.findViewById(R.id.report_content);
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
dialogBuilder.setPositiveButton(R.string.report, (dialog, id) -> {
if (report_content.getText().toString().trim().length() == 0) {
Toasty.info(ShowAccountActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
} else {
new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.REPORT_ACCOUNT, account.getId(), report_content.getText().toString(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
});
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
}
return super.onOptionsItemSelected(item);
}
private void manageAccount() {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String accountIdRelation = account.getAcct();
@ -154,60 +188,9 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
retrieveRelationship = new RetrieveRelationshipAsyncTask(ShowAccountActivity.this, accountIdRelation, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
String urlHeader = account.getHeader();
if (urlHeader != null && urlHeader.startsWith("/")) {
urlHeader = "https://" + Helper.getLiveInstance(ShowAccountActivity.this) + account.getHeader();
}
if (urlHeader != null && !urlHeader.contains("missing.png")) {
ImageView banner_pp = findViewById(R.id.banner_pp);
Glide.with(banner_pp.getContext())
.load(urlHeader)
.into(banner_pp);
}
TextView actionbar_title = findViewById(R.id.show_account_title);
if (account.getAcct() != null)
actionbar_title.setText(account.getAcct());
ImageView pp_actionBar = findViewById(R.id.pp_actionBar);
if (account.getAvatar() != null) {
Helper.loadGiF(ShowAccountActivity.this, account, pp_actionBar);
}
final AppBarLayout appBar = findViewById(R.id.appBar);
maxScrollSize = appBar.getTotalScrollRange();
setTitle(account.getAcct());
appBar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
LinearLayout toolbarContent = findViewById(R.id.toolbar_content);
if (toolbarContent != null) {
if (Math.abs(verticalOffset) - appBar.getTotalScrollRange() == 0) {
if (toolbarContent.getVisibility() == View.GONE)
toolbarContent.setVisibility(View.VISIBLE);
} else {
if (toolbarContent.getVisibility() == View.VISIBLE)
toolbarContent.setVisibility(View.GONE);
}
}
if (maxScrollSize == 0)
maxScrollSize = appBarLayout.getTotalScrollRange();
int percentage = (Math.abs(verticalOffset)) * 100 / maxScrollSize;
if (percentage >= 40 && avatarShown) {
avatarShown = false;
account_pp.animate()
.scaleY(0).scaleX(0)
.setDuration(400)
.start();
}
if (percentage <= 40 && !avatarShown) {
avatarShown = true;
account_pp.animate()
.scaleY(1).scaleX(1)
.start();
}
});
mPager = findViewById(R.id.account_viewpager);
if (!ischannel) {
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.videos)));
@ -279,27 +262,9 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
});
account_dn.setText(account.getDisplay_name());
if (!ischannel || account.getAcct().split("-").length < 4) {
account_un.setText(String.format("@%s", account.getAcct()));
} else {
account_un.setVisibility(View.GONE);
}
SpannableString spannableString;
if (account.getNote() != null && account.getNote().compareTo("null") != 0 && account.getNote().trim().length() > 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
spannableString = new SpannableString(Html.fromHtml(account.getNote(), FROM_HTML_MODE_LEGACY));
else
spannableString = new SpannableString(Html.fromHtml(account.getNote()));
account.setNoteSpan(spannableString);
account_note.setText(account.getNoteSpan(), TextView.BufferType.SPANNABLE);
account_note.setMovementMethod(LinkMovementMethod.getInstance());
account_note.setVisibility(View.VISIBLE);
} else {
account_note.setVisibility(View.GONE);
}
manageNotes(account);
Helper.loadGiF(ShowAccountActivity.this, account, account_pp);
//Follow button
String target = account.getAcct();
@ -330,11 +295,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
}
});
TextView account_date = findViewById(R.id.account_date);
account_date.setText(Helper.shortDateToString(account.getCreated_at()));
account_date.setVisibility(View.VISIBLE);
}
@Override
@ -353,21 +313,15 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
}
@Override
public void onRetrieveRelationship(Relationship relationship, Error error) {
public void onRetrieveRelationship(List<Relationship> relationships, Error error) {
if (error != null) {
Toasty.error(ShowAccountActivity.this, error.getError(), Toast.LENGTH_LONG).show();
return;
}
this.relationship = relationship;
this.relationship = relationships.get(0);
manageButtonVisibility();
//The authenticated account is followed by the account
if (relationship != null && relationship.isFollowed_by() && !accountId.equals(userId)) {
TextView account_followed_by = findViewById(R.id.account_followed_by);
account_followed_by.setVisibility(View.VISIBLE);
}
invalidateOptionsMenu();
}
@ -395,26 +349,24 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
}
account_follow.setEnabled(true);
if (relationship.isFollowing()) {
account_follow.setImageResource(R.drawable.ic_user_minus);
account_follow.setText(R.string.action_unfollow);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
account_follow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowAccountActivity.this, R.color.red_1)));
}
doAction = action.UNFOLLOW;
account_follow.setContentDescription(getString(R.string.action_unfollow));
if (ischannel) {
account_follow.setVisibility(View.VISIBLE);
} else {
account_follow.setVisibility(View.GONE);
}
} else if (!relationship.isFollowing()) {
account_follow.setImageResource(R.drawable.ic_user_plus);
account_follow.setText(R.string.action_follow);
doAction = action.FOLLOW;
if (ischannel) {
account_follow.setVisibility(View.VISIBLE);
} else {
account_follow.setVisibility(View.GONE);
}
account_follow.setContentDescription(getString(R.string.action_follow));
} else {
account_follow.setVisibility(View.GONE);
doAction = action.NOTHING;
@ -450,9 +402,46 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
intentBC.putExtras(b);
}
retrieveRelationship = new RetrieveRelationshipAsyncTask(ShowAccountActivity.this, target, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW || statusAction == PeertubeAPI.StatusAction.FOLLOW) {
retrieveRelationship = new RetrieveRelationshipAsyncTask(ShowAccountActivity.this, target, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else if (statusAction == PeertubeAPI.StatusAction.MUTE) {
Toasty.info(ShowAccountActivity.this, getString(R.string.muted_done), Toast.LENGTH_LONG).show();
}
}
@Override
public void onRetrieveAccounts(APIResponse apiResponse) {
if (apiResponse.getAccounts() != null && apiResponse.getAccounts().size() == 1) {
Account account = apiResponse.getAccounts().get(0);
if (this.account == null) {
this.account = account;
manageAccount();
}
if (account.getchannelOwner() != null) {
this.account.setchannelOwner(account.getchannelOwner());
}
subscriber_count.setText(getString(R.string.followers_count, Helper.withSuffix(account.getFollowers_count())));
subscriber_count.setVisibility(View.VISIBLE);
manageNotes(account);
}
}
private void manageNotes(Account account) {
if (account.getNote() != null && account.getNote().compareTo("null") != 0 && account.getNote().trim().length() > 0) {
SpannableString spannableString;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
spannableString = new SpannableString(Html.fromHtml(account.getNote(), FROM_HTML_MODE_LEGACY));
else
spannableString = new SpannableString(Html.fromHtml(account.getNote()));
account.setNoteSpan(spannableString);
account_note.setText(account.getNoteSpan(), TextView.BufferType.SPANNABLE);
account_note.setMovementMethod(LinkMovementMethod.getInstance());
account_note.setVisibility(View.VISIBLE);
} else {
account_note.setVisibility(View.GONE);
}
}
public enum action {
FOLLOW,
@ -461,7 +450,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
}
/**
* Pager adapter for the 4 fragments
* Pager adapter for the 2 fragments
*/
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {

View File

@ -65,9 +65,10 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
PeertubeAPI peertubeAPI = new PeertubeAPI(contextReference.get());
if (apiAction == PeertubeAPI.StatusAction.FOLLOW || apiAction == PeertubeAPI.StatusAction.UNFOLLOW)
if (apiAction == PeertubeAPI.StatusAction.FOLLOW || apiAction == PeertubeAPI.StatusAction.UNFOLLOW
|| apiAction == PeertubeAPI.StatusAction.MUTE || apiAction == PeertubeAPI.StatusAction.UNMUTE) {
statusCode = peertubeAPI.postAction(apiAction, targetedId);
else if (apiAction == PeertubeAPI.StatusAction.RATEVIDEO)
} else if (apiAction == PeertubeAPI.StatusAction.RATEVIDEO)
statusCode = peertubeAPI.postRating(targetedId, comment);
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT)
statusCode = peertubeAPI.postComment(targetedId, comment);
@ -78,6 +79,10 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
targetedId = comment;
} else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO) {
statusCode = peertubeAPI.deleteVideo(targetedId);
} else if (apiAction == PeertubeAPI.StatusAction.REPORT_ACCOUNT) {
statusCode = peertubeAPI.report(PeertubeAPI.reportType.ACCOUNT, targetedId, comment);
} else if (apiAction == PeertubeAPI.StatusAction.REPORT_VIDEO) {
statusCode = peertubeAPI.report(PeertubeAPI.reportType.VIDEO, targetedId, comment);
}
error = peertubeAPI.getError();
return null;

View File

@ -0,0 +1,50 @@
package app.fedilab.fedilabtube.asynctasks;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface;
public class RetrieveAccountSubscriptionsAsyncTask extends AsyncTask<Void, Void, APIResponse> {
private OnRetrieveAccountsInterface listener;
private WeakReference<Context> contextReference;
private String max_id;
public RetrieveAccountSubscriptionsAsyncTask(Context context, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.max_id = max_id;
this.listener = onRetrieveAccountsInterface;
}
@Override
protected APIResponse doInBackground(Void... params) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
return peertubeAPI.getSubscriptionUsers(max_id);
}
@Override
protected void onPostExecute(APIResponse apiResponse) {
listener.onRetrieveAccounts(apiResponse);
}
}

View File

@ -24,31 +24,43 @@ import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface;
public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, APIResponse> {
private APIResponse apiResponse;
private OnRetrieveAccountsInterface listener;
private WeakReference<Context> contextReference;
private String name;
private String max_id;
private accountFetch type;
public RetrieveAccountsAsyncTask(Context context, String name, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
public RetrieveAccountsAsyncTask(Context context, String max_id, accountFetch type, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.name = name;
this.max_id = max_id;
this.listener = onRetrieveAccountsInterface;
this.type = type;
}
@Override
protected Void doInBackground(Void... params) {
protected APIResponse doInBackground(Void... params) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
apiResponse = peertubeAPI.getPeertubeChannel(name);
return null;
if (type == accountFetch.SUBSCRIPTION) {
return peertubeAPI.getSubscriptionUsers(max_id);
} else if (type == accountFetch.MUTED) {
return peertubeAPI.getMuted(max_id);
} else if (type == accountFetch.CHANNEL) {
return peertubeAPI.getPeertubeChannel(max_id);
} else {
return null;
}
}
@Override
protected void onPostExecute(Void result) {
protected void onPostExecute(APIResponse apiResponse) {
listener.onRetrieveAccounts(apiResponse);
}
public enum accountFetch {
SUBSCRIPTION,
CHANNEL,
MUTED
}
}

View File

@ -38,7 +38,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
private OnRetrieveFeedsInterface listener;
private WeakReference<Context> contextReference;
private String target;
private String forAccount;
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
@ -56,6 +56,15 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.target = target;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, String target, String forAccount, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
this.listener = onRetrieveFeedsInterface;
this.target = target;
this.forAccount = forAccount;
}
@Override
protected Void doInBackground(Void... params) {
@ -88,7 +97,11 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
break;
case PSUBSCRIPTIONS:
peertubeAPI = new PeertubeAPI(this.contextReference.get());
apiResponse = peertubeAPI.getSubscriptionsTL(max_id);
if (forAccount == null) {
apiResponse = peertubeAPI.getSubscriptionsTL(max_id);
} else {
apiResponse = peertubeAPI.getVideosChannel(forAccount, max_id);
}
break;
case POVERVIEW:
peertubeAPI = new PeertubeAPI(this.contextReference.get());

View File

@ -26,10 +26,9 @@ import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeNotificationsInterface;
public class RetrievePeertubeNotificationsAsyncTask extends AsyncTask<Void, Void, Void> {
public class RetrievePeertubeNotificationsAsyncTask extends AsyncTask<Void, Void, APIResponse> {
private APIResponse apiResponse;
private String max_id;
private Account account;
private OnRetrievePeertubeNotificationsInterface listener;
@ -44,24 +43,26 @@ public class RetrievePeertubeNotificationsAsyncTask extends AsyncTask<Void, Void
@Override
protected Void doInBackground(Void... params) {
protected APIResponse doInBackground(Void... params) {
PeertubeAPI api;
APIResponse apiResponse;
if (account == null) {
api = new PeertubeAPI(this.contextReference.get());
apiResponse = api.getNotifications(max_id);
} else {
if (this.contextReference.get() == null) {
apiResponse = new APIResponse();
apiResponse.setError(new Error());
return null;
return apiResponse;
}
api = new PeertubeAPI(this.contextReference.get(), account.getInstance(), account.getToken());
apiResponse = api.getNotificationsSince(max_id);
}
return null;
return apiResponse;
}
@Override
protected void onPostExecute(Void result) {
protected void onPostExecute(APIResponse apiResponse) {
listener.onRetrievePeertubeNotifications(apiResponse, account);
}

View File

@ -18,6 +18,7 @@ import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import java.util.List;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Error;
@ -25,11 +26,10 @@ import app.fedilab.fedilabtube.client.entities.Relationship;
import app.fedilab.fedilabtube.interfaces.OnRetrieveRelationshipInterface;
public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, List<Relationship>> {
private String accountId;
private Relationship relationship;
private OnRetrieveRelationshipInterface listener;
private Error error;
private WeakReference<Context> contextReference;
@ -41,18 +41,17 @@ public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
}
@Override
protected Void doInBackground(Void... params) {
protected List<Relationship> doInBackground(Void... params) {
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
relationship = new Relationship();
relationship.setFollowing(api.isFollowing(accountId));
List<Relationship> relationships = api.isFollowing(accountId);
error = api.getError();
return null;
return relationships;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveRelationship(relationship, error);
protected void onPostExecute(List<Relationship> relationships) {
listener.onRetrieveRelationship(relationships, error);
}
}

View File

@ -0,0 +1,63 @@
package app.fedilab.fedilabtube.asynctasks;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface;
public class RetrieveSingleAccountAsyncTask extends AsyncTask<Void, Void, APIResponse> {
private OnRetrieveAccountsInterface listener;
private WeakReference<Context> contextReference;
private String name;
private actionType type;
public RetrieveSingleAccountAsyncTask(Context context, String name, actionType type, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.name = name;
this.listener = onRetrieveAccountsInterface;
this.type = type;
}
@Override
protected APIResponse doInBackground(Void... params) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
if (type == actionType.ACCOUNT) {
return peertubeAPI.getPeertubeChannel(name);
} else if (type == actionType.CHANNEL) {
return peertubeAPI.getPeertubeChannelInfo(name);
} else {
return null;
}
}
@Override
protected void onPostExecute(APIResponse apiResponse) {
listener.onRetrieveAccounts(apiResponse);
}
public enum actionType {
ACCOUNT,
CHANNEL
}
}

View File

@ -61,10 +61,12 @@ import app.fedilab.fedilabtube.helper.FileNameCleaner;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnDownloadInterface;
@SuppressWarnings("unused")
public class HttpsConnection {
private static final String LINE_FEED = "\r\n";
private HttpsURLConnection httpsURLConnection;
private String since_id, max_id;
private Context context;
@ -107,7 +109,6 @@ public class HttpsConnection {
}
}
/**
* Get calls
*
@ -158,10 +159,8 @@ public class HttpsConnection {
httpsURLConnection.setUseCaches(true);
httpsURLConnection.setDefaultUseCaches(true);
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
if (token != null && !token.startsWith("Basic "))
if (token != null)
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
else if (token != null && token.startsWith("Basic "))
httpsURLConnection.setRequestProperty("Authorization", token);
httpsURLConnection.setRequestMethod("GET");
String response;
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
@ -194,7 +193,6 @@ public class HttpsConnection {
return response;
}
public String get(String urlConnection) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
@ -243,6 +241,88 @@ public class HttpsConnection {
return response;
}
public String postBoundary(String urlConnection, int timeout, LinkedHashMap<String, String> paramaters, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
URL url = new URL(urlConnection);
String boundary = "----TubeLabBoundary" + System.currentTimeMillis();
if (proxy != null)
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
else
httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setConnectTimeout(timeout * 1000);
httpsURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
if (token != null)
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
StringBuilder postData = new StringBuilder();
if (paramaters != null) {
Iterator<Map.Entry<String, String>> it = paramaters.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
postData = addFormField(postData, pair.getKey(), pair.getValue(), boundary);
it.remove();
}
postData.append("--").append(boundary).append("--");
}
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
OutputStream outputStream = httpsURLConnection.getOutputStream();
outputStream.write(postDataBytes);
String response;
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
getSinceMaxId();
response = converToString(httpsURLConnection.getInputStream());
} else {
String error = null;
if (httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
if (scanner.hasNext()) {
error = scanner.next();
}
} catch (Exception e) {
e.printStackTrace();
}
}
int responseCode = httpsURLConnection.getResponseCode();
try {
httpsURLConnection.getInputStream().close();
} catch (Exception ignored) {
}
throw new HttpsConnectionException(responseCode, error);
}
getSinceMaxId();
httpsURLConnection.getInputStream().close();
return response;
}
/**
* Adds a form field to the request
*
* @param writer StringBuilder
* @param name field name
* @param value field value
*/
private StringBuilder addFormField(StringBuilder writer, String name, String value, String boundary) {
if (writer != null) {
writer.append("--").append(boundary).append(LINE_FEED);
writer.append("Content-Disposition: form-data; name=\"").append(name).append("\"")
.append(LINE_FEED);
writer.append("Content-Type: text/plain; charset=").append(StandardCharsets.UTF_8).append(
LINE_FEED);
writer.append(LINE_FEED);
writer.append(value).append(LINE_FEED);
}
return writer;
}
public String post(String urlConnection, int timeout, HashMap<String, String> paramaters, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
URL url = new URL(urlConnection);
@ -271,10 +351,8 @@ public class HttpsConnection {
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
httpsURLConnection.setRequestMethod("POST");
if (token != null && !token.startsWith("Basic "))
if (token != null)
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
else if (token != null && token.startsWith("Basic "))
httpsURLConnection.setRequestProperty("Authorization", token);
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
@ -495,10 +573,8 @@ public class HttpsConnection {
httpsURLConnection.setConnectTimeout(timeout * 1000);
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
httpsURLConnection.setRequestMethod("PATCH");
if (token != null && !token.startsWith("Basic "))
if (token != null)
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
else if (token != null && token.startsWith("Basic "))
httpsURLConnection.setRequestProperty("Authorization", token);
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
httpsURLConnection.setDoOutput(true);
@ -543,7 +619,6 @@ public class HttpsConnection {
}
httpsURLConnection.getInputStream().close();
return response;
}
public String put(String urlConnection, int timeout, HashMap<String, String> paramaters, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
@ -573,10 +648,8 @@ public class HttpsConnection {
httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setConnectTimeout(timeout * 1000);
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
if (token != null && !token.startsWith("Basic "))
if (token != null)
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
else if (token != null && token.startsWith("Basic "))
httpsURLConnection.setRequestProperty("Authorization", token);
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
httpsURLConnection.setRequestMethod("PUT");
@ -643,10 +716,8 @@ public class HttpsConnection {
else
httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
if (token != null && !token.startsWith("Basic "))
if (token != null)
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token);
else if (token != null && token.startsWith("Basic "))
httpsURLConnection.setRequestProperty("Authorization", token);
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpsURLConnection.setRequestMethod("DELETE");
httpsURLConnection.setConnectTimeout(timeout * 1000);

View File

@ -14,6 +14,7 @@ package app.fedilab.fedilabtube.client;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
@ -44,6 +45,7 @@ import java.util.Objects;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.AccountCreation;
import app.fedilab.fedilabtube.client.entities.ChannelCreation;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.Instance;
import app.fedilab.fedilabtube.client.entities.Peertube;
@ -55,6 +57,7 @@ import app.fedilab.fedilabtube.client.entities.PeertubeNotification;
import app.fedilab.fedilabtube.client.entities.PeertubeVideoNotification;
import app.fedilab.fedilabtube.client.entities.Playlist;
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
import app.fedilab.fedilabtube.client.entities.Relationship;
import app.fedilab.fedilabtube.client.entities.Status;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
@ -77,7 +80,6 @@ public class PeertubeAPI {
private APIResponse apiResponse;
private Error APIError;
public PeertubeAPI(Context context) {
this.context = context;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -166,6 +168,7 @@ public class PeertubeAPI {
peertubeAccountNotification.setDisplayName(channel.getString("displayName"));
peertubeAccountNotification.setName(channel.getString("name"));
peertubeAccountNotification.setId(channel.getString("id"));
peertubeAccountNotification.setHost(channel.getString("host"));
if (channel.has("avatar")) {
peertubeAccountNotification.setAvatar(channel.getJSONObject("avatar").getString("path"));
}
@ -254,13 +257,11 @@ public class PeertubeAPI {
peertube.setCommentsEnabled(resobj.getBoolean("commentsEnabled"));
} catch (Exception ignored) {
}
try {
peertube.setCreated_at(Helper.mstStringToDate(resobj.getString("createdAt")));
} catch (ParseException e) {
e.printStackTrace();
}
try {
LinkedHashMap<String, String> langue = new LinkedHashMap<>();
LinkedHashMap<Integer, String> category = new LinkedHashMap<>();
@ -270,7 +271,6 @@ public class PeertubeAPI {
license.put(resobj.getJSONObject("licence").getInt("id"), resobj.getJSONObject("licence").getString("label"));
privacy.put(resobj.getJSONObject("privacy").getInt("id"), resobj.getJSONObject("privacy").getString("label"));
langue.put(resobj.getJSONObject("language").getString("id"), resobj.getJSONObject("language").getString("label"));
peertube.setCategory(category);
peertube.setLicense(license);
peertube.setLanguage(langue);
@ -344,7 +344,6 @@ public class PeertubeAPI {
resolutions.add(attObj.getJSONObject("resolution").getString("id"));
}
peertube.setResolution(resolutions);
peertube.setStreamService(true);
} else {
JSONArray files = resobj.getJSONArray("files");
for (int j = 0; j < files.length(); j++) {
@ -352,7 +351,6 @@ public class PeertubeAPI {
resolutions.add(attObj.getJSONObject("resolution").getString("id"));
}
peertube.setResolution(resolutions);
peertube.setStreamService(false);
}
try {
LinkedHashMap<String, String> langue = new LinkedHashMap<>();
@ -432,6 +430,9 @@ public class PeertubeAPI {
account.setHost(accountObject.get("host").toString());
account.setSocial("PEERTUBE");
account.setInstance(accountObject.getString("host"));
if (accountObject.has("ownerAccount")) {
account.setchannelOwner(parseAccountResponsePeertube(accountObject.getJSONObject("ownerAccount")));
}
if (accountObject.has("createdAt"))
account.setCreated_at(Helper.mstStringToDate(accountObject.get("createdAt").toString()));
else
@ -450,7 +451,9 @@ public class PeertubeAPI {
else
account.setNote("");
account.setUrl(accountObject.get("url").toString());
if (accountObject.has("url")) {
account.setUrl(accountObject.get("url").toString());
}
if (accountObject.has("avatar") && !accountObject.isNull("avatar")) {
account.setAvatar(accountObject.getJSONObject("avatar").get("path").toString());
account.setAvatar_static(accountObject.getJSONObject("avatar").get("path").toString());
@ -718,6 +721,69 @@ public class PeertubeAPI {
return peertubeInformation;
}
/**
* Refresh token and update user data
*
* @param token String
* @param instance String
*/
public void refreshToken(String token, String instance) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if (token == null) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instanceC = Helper.getLiveInstance(context);
Account accountToLogout = new AccountDAO(context, db).getUniqAccount(userId, instanceC);
Helper.logoutCurrentUser((Activity) context, accountToLogout);
return;
}
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(token);
String newToken = null, newRefreshToken = null;
if (targetedAccount != null) {
HashMap<String, String> values = refreshToken(targetedAccount.getClient_id(), targetedAccount.getClient_secret(), targetedAccount.getRefresh_token());
if (values.containsKey("access_token") && values.get("access_token") != null) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
//This account is currently logged in, the token is updated
if (values.get("access_token") != null) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, values.get("access_token"));
editor.apply();
}
}
if (values.containsKey("refresh_token") && values.get("refresh_token") != null) {
newRefreshToken = values.get("refresh_token");
}
if (values.containsKey("access_token") && values.get("access_token") != null) {
newToken = values.get("access_token");
}
String response;
try {
response = new HttpsConnection(context).get("https://" + instance + "/api/v1/users/me", 60, null, newToken);
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
account = parseAccountResponsePeertube(accountObject);
} catch (IOException | NoSuchAlgorithmException | KeyManagementException | JSONException e) {
e.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
//setError(e.getStatusCode(), e);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instanceC = Helper.getLiveInstance(context);
Account accountToLogout = new AccountDAO(context, db).getUniqAccount(userId, instanceC);
Helper.logoutCurrentUser((Activity) context, accountToLogout);
return;
}
if (newRefreshToken != null && newToken != null) {
account.setRefresh_token(newRefreshToken);
account.setToken(newToken);
}
account.setInstance(instance);
new AccountDAO(context, db).updateAccount(account);
}
}
/***
* Verifiy credential of the authenticated user *synchronously*
* @return Account
@ -731,46 +797,38 @@ public class PeertubeAPI {
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e) {
if (e.getStatusCode() == 401 || e.getStatusCode() == 403) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(token);
if (targetedAccount != null) {
HashMap<String, String> values = refreshToken(targetedAccount.getClient_id(), targetedAccount.getClient_secret(), targetedAccount.getRefresh_token());
if (values.containsKey("access_token") && values.get("access_token") != null) {
targetedAccount.setToken(values.get("access_token"));
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String tokenShared = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
//This account is currently logged in, the token is updated
if (tokenShared != null && token.compareTo(tokenShared) == 0) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, targetedAccount.getToken());
editor.apply();
}
}
if (values.containsKey("refresh_token") && values.get("refresh_token") != null)
targetedAccount.setRefresh_token(values.get("refresh_token"));
new AccountDAO(context, db).updateAccount(targetedAccount);
String response;
try {
response = new HttpsConnection(context).get("https://" + instance + "/api/v1/users/me", 60, null, targetedAccount.getToken());
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
account = parseAccountResponsePeertube(accountObject);
} catch (IOException | NoSuchAlgorithmException | KeyManagementException | JSONException e1) {
e1.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e1) {
e1.printStackTrace();
setError(e.getStatusCode(), e);
}
} else {
setError(e.getStatusCode(), e);
}
e.printStackTrace();
}
setError(e.getStatusCode(), e);
}
return account;
}
public int report(reportType type, String id, String reason) {
actionCode = -1;
try {
HashMap<String, String> params = new HashMap<>();
switch (type) {
case VIDEO:
params.put("video", id);
break;
case ACCOUNT:
params.put("account", id);
break;
case COMMENT:
params.put("comment", id);
break;
}
params.put("reason", reason);
HttpsConnection httpsConnection = new HttpsConnection(context);
httpsConnection.post(getAbsoluteUrl("/abuses"), 30, params, null);
actionCode = httpsConnection.getActionCode();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
e.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}
return actionCode;
}
public APIResponse createAccount(AccountCreation accountCreation) {
apiResponse = new APIResponse();
@ -791,6 +849,43 @@ public class PeertubeAPI {
return apiResponse;
}
/**
* Create a channel fot the authenticated user
*
* @param channelCreation channelCreation
*/
public void createChannel(ChannelCreation channelCreation) throws HttpsConnection.HttpsConnectionException {
actionCode = -1;
try {
HashMap<String, String> params = new HashMap<>();
params.put("displayName", channelCreation.getDisplayName());
params.put("name", channelCreation.getName());
params.put("description", channelCreation.getDescription());
params.put("support", channelCreation.getSupport());
HttpsConnection httpsConnection = new HttpsConnection(context);
httpsConnection.post(getAbsoluteUrl("/video-channels"), 30, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
e.printStackTrace();
}
}
/**
* Delete a Channel
*
* @param channelId String, the channel id
*/
public void deleteChannel(String channelId) throws HttpsConnection.HttpsConnectionException {
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
httpsConnection.delete(getAbsoluteUrl(String.format("/video-channels/%s", channelId)), 60, null, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
e.printStackTrace();
}
}
/***
* Verifiy credential of the authenticated user *synchronously*
* @return Account
@ -807,11 +902,13 @@ public class PeertubeAPI {
String response = new HttpsConnection(context).post(getAbsoluteUrl("/users/token"), 60, params, null);
JSONObject resobj = new JSONObject(response);
String token = resobj.getString("access_token");
if (resobj.has("refresh_token"))
refresh_token = resobj.getString("refresh_token");
String refresh = resobj.getString("refresh_token");
newValues.put("access_token", token);
newValues.put("refresh_token", refresh_token);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) {
newValues.put("refresh_token", refresh);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}
return newValues;
@ -823,6 +920,7 @@ public class PeertubeAPI {
* @param accountId String account fetched
* @return Account entity
*/
@SuppressWarnings("unused")
public Account getAccount(String accountId) {
account = new Account();
@ -838,27 +936,37 @@ public class PeertubeAPI {
return account;
}
public List<Relationship> isFollowing(String uri) {
ArrayList<String> uris = new ArrayList<>();
uris.add(uri);
return isFollowing(uris);
}
/**
* Returns a relationship between the authenticated account and an account
*
* @param uri String accounts fetched
* @param uris Array String accounts uri fetched
* @return Relationship entity
*/
public boolean isFollowing(String uri) {
public List<Relationship> isFollowing(ArrayList<String> uris) {
HashMap<String, String> params = new HashMap<>();
params.put("uris", uri);
StringBuilder parameters = new StringBuilder();
for (String uri : uris)
parameters.append("uris[]=").append(uri).append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(7));
params.put("uris[]", parameters.toString());
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl("/users/me/subscriptions/exist"), 60, params, prefKeyOauthTokenT);
return new JSONObject(response).getBoolean(uri);
return parseRelationShip(uris, new JSONObject(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
}
return false;
return null;
}
/**
@ -1105,34 +1213,65 @@ public class PeertubeAPI {
try {
return getTL("/users/me/subscriptions/videos", "-publishedAt", null, max_id, null, null);
} catch (HttpsConnection.HttpsConnectionException e) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
if (targetedAccount != null && (e.getStatusCode() == 401 || e.getStatusCode() == 403)) {
HashMap<String, String> values = refreshToken(targetedAccount.getClient_id(), targetedAccount.getClient_secret(), targetedAccount.getRefresh_token());
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if (values.containsKey("access_token") && values.get("access_token") != null) {
targetedAccount.setToken(values.get("access_token"));
//This account is currently logged in, the token is updated
SharedPreferences.Editor editor = sharedpreferences.edit();
prefKeyOauthTokenT = targetedAccount.getToken();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, targetedAccount.getToken());
editor.apply();
}
if (values.containsKey("refresh_token") && values.get("refresh_token") != null)
targetedAccount.setRefresh_token(values.get("refresh_token"));
new AccountDAO(context, db).updateAccount(targetedAccount);
try {
return getTL("/users/me/subscriptions/videos", "-publishedAt", null, max_id, null, null);
} catch (HttpsConnection.HttpsConnectionException e1) {
setError(e.getStatusCode(), e);
return apiResponse;
}
}
setError(e.getStatusCode(), e);
return apiResponse;
}
}
/**
* Retrieves subscriptions *synchronously*
*
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getSubscriptionUsers(String max_id) {
List<Account> accounts = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
HashMap<String, String> params = new HashMap<>();
if (max_id != null)
params.put("start", max_id);
params.put("sort", "-createdAt");
String response = httpsConnection.get(getAbsoluteUrl("/users/me/subscriptions"), 10, params, prefKeyOauthTokenT);
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
accounts = parseAccountResponsePeertube(jsonArray);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
}
/**
* Retrieves muted accounts *synchronously*
*
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getMuted(String max_id) {
List<Account> accounts = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
HashMap<String, String> params = new HashMap<>();
if (max_id != null)
params.put("start", max_id);
params.put("sort", "-createdAt");
String response = httpsConnection.get(getAbsoluteUrl("/users/me/blocklist/accounts"), 10, params, prefKeyOauthTokenT);
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
accounts = parseBlockedAccountResponsePeertube(jsonArray);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
}
/**
* Retrieves overview videos *synchronously*
*
@ -1325,6 +1464,32 @@ public class PeertubeAPI {
return apiResponse;
}
/**
* Retrieves Peertube channel info from an account *synchronously*
* Peertube channels are dealt like accounts
*
* @return APIResponse
*/
public APIResponse getPeertubeChannelInfo(String name) {
List<Account> accounts = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/video-channels/%s", name)), 60, null, null);
JSONObject jsonObject = new JSONObject(response);
Account account = parseAccountResponsePeertube(jsonObject);
accounts.add(account);
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
}
/**
* Retrieves Peertube videos from an instance *synchronously*
*
@ -1424,6 +1589,15 @@ public class PeertubeAPI {
action = String.format("/users/me/subscriptions/%s", targetedId);
actionCall = "DELETE";
break;
case MUTE:
action = "/users/me/blocklist/accounts";
params = new HashMap<>();
params.put("accountName", targetedId);
break;
case UNMUTE:
action = String.format("/users/me/blocklist/accounts/%s", targetedId);
actionCall = "DELETE";
break;
case RATEVIDEO:
action = String.format("/videos/%s/rate", targetedId);
params = new HashMap<>();
@ -1467,6 +1641,7 @@ public class PeertubeAPI {
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
e.printStackTrace();
}
@ -1531,6 +1706,30 @@ public class PeertubeAPI {
return apiResponse;
}
/**
* Create a Playlist
*
* @param playlistElement PlaylistElement, the playlist elements
*/
public String createPlaylist(PlaylistElement playlistElement) throws HttpsConnection.HttpsConnectionException {
String playlistId = "-1";
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
LinkedHashMap<String, String> params = new LinkedHashMap<>();
params.put("displayName", playlistElement.getDisplayName());
params.put("privacy", playlistElement.getPrivacy());
params.put("videoChannelId", playlistElement.getVideoChannelId());
params.put("description", playlistElement.getDescription());
String response = httpsConnection.postBoundary(getAbsoluteUrl("/video-playlists/"), 60, params, prefKeyOauthTokenT);
playlistId = new JSONObject(response).getJSONObject("videoPlaylist").getString("id");
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
}
return playlistId;
}
/**
* Delete a Playlist
*
@ -1685,6 +1884,28 @@ public class PeertubeAPI {
return apiResponse;
}
/**
* Parse json response for peertube relationship
*
* @param jsonObject JSONObject
* @return List<Relationship>
*/
private List<Relationship> parseRelationShip(ArrayList<String> uris, JSONObject jsonObject) {
List<Relationship> relationships = new ArrayList<>();
try {
for (String uri : uris) {
Relationship relationship = new Relationship();
relationship.setId(uri);
relationship.setFollowing(jsonObject.getBoolean(uri));
relationships.add(relationship);
}
return relationships;
} catch (JSONException e) {
setDefaultError(e);
}
return null;
}
/**
* Parse json response for peertube notifications
*
@ -1707,7 +1928,6 @@ public class PeertubeAPI {
return peertubeNotifications;
}
/**
* Parse json response for several howto
*
@ -1723,7 +1943,9 @@ public class PeertubeAPI {
JSONObject resobj = jsonArray.getJSONObject(i);
Peertube peertube = parsePeertube(resobj);
i++;
peertubes.add(peertube);
if (peertube.getName() == null || !peertube.getName().toLowerCase().contains("youtube video downloader")) {
peertubes.add(peertube);
}
}
} catch (JSONException e) {
setDefaultError(e);
@ -1774,6 +1996,25 @@ public class PeertubeAPI {
return playlists;
}
private List<Account> parseBlockedAccountResponsePeertube(JSONArray jsonArray) {
List<Account> accounts = new ArrayList<>();
try {
int i = 0;
while (i < jsonArray.length()) {
if (jsonArray.getJSONObject(i).has("blockedAccount")) {
JSONObject resobj = jsonArray.getJSONObject(i).getJSONObject("blockedAccount");
Account account = parseAccountResponsePeertube(resobj);
accounts.add(account);
}
i++;
}
} catch (JSONException e) {
setDefaultError(e);
}
return accounts;
}
private List<Account> parseAccountResponsePeertube(JSONArray jsonArray) {
List<Account> accounts = new ArrayList<>();
try {
@ -1805,7 +2046,7 @@ public class PeertubeAPI {
String errorM = jsonObject.getString("error");
message = "Error " + statusCode + " : " + errorM;
} catch (JSONException e) {
if (error.getMessage().split(".").length > 0) {
if (error.getMessage() != null && error.getMessage().split(".").length > 0) {
String errorM = error.getMessage().split(".")[0];
message = "Error " + statusCode + " : " + errorM;
}
@ -1833,15 +2074,25 @@ public class PeertubeAPI {
return Helper.instanceWithProtocol(context) + "/api/v1" + action;
}
public enum reportType {
ACCOUNT,
COMMENT,
VIDEO
}
public enum StatusAction {
FOLLOW,
UNFOLLOW,
MUTE,
UNMUTE,
RATEVIDEO,
PEERTUBECOMMENT,
PEERTUBEREPLY,
PEERTUBEDELETECOMMENT,
PEERTUBEDELETEVIDEO,
REPORT_ACCOUNT,
REPORT_VIDEO
}
}

View File

@ -64,7 +64,7 @@ public class Account implements Parcelable {
private boolean isFollowing;
private followAction followType = followAction.NOTHING;
private boolean isMakingAction = false;
private Account moved_to_account;
private Account channelOwner;
private boolean muting_notifications;
private String host;
private boolean isBot;
@ -80,6 +80,7 @@ public class Account implements Parcelable {
private String invite_request;
private String created_by_application_id;
private String invited_by_account_id;
private boolean isSelected;
public Account() {
}
@ -114,7 +115,7 @@ public class Account implements Parcelable {
int tmpFollowType = in.readInt();
this.followType = tmpFollowType == -1 ? null : followAction.values()[tmpFollowType];
this.isMakingAction = in.readByte() != 0;
this.moved_to_account = in.readParcelable(Account.class.getClassLoader());
this.channelOwner = in.readParcelable(Account.class.getClassLoader());
this.muting_notifications = in.readByte() != 0;
this.host = in.readString();
this.isBot = in.readByte() != 0;
@ -166,7 +167,7 @@ public class Account implements Parcelable {
dest.writeByte(this.isFollowing ? (byte) 1 : (byte) 0);
dest.writeInt(this.followType == null ? -1 : this.followType.ordinal());
dest.writeByte(this.isMakingAction ? (byte) 1 : (byte) 0);
dest.writeParcelable(this.moved_to_account, flags);
dest.writeParcelable(this.channelOwner, flags);
dest.writeByte(this.muting_notifications ? (byte) 1 : (byte) 0);
dest.writeString(this.host);
dest.writeByte(this.isBot ? (byte) 1 : (byte) 0);
@ -200,12 +201,12 @@ public class Account implements Parcelable {
isMakingAction = makingAction;
}
public Account getMoved_to_account() {
return moved_to_account;
public Account getchannelOwner() {
return channelOwner;
}
public void setMoved_to_account(Account moved_to_account) {
this.moved_to_account = moved_to_account;
public void setchannelOwner(Account moved_to_account) {
this.channelOwner = moved_to_account;
}
public boolean isMuting_notifications() {
@ -216,6 +217,14 @@ public class Account implements Parcelable {
this.muting_notifications = muting_notifications;
}
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
public String getHost() {
return host;

View File

@ -0,0 +1,55 @@
package app.fedilab.fedilabtube.client.entities;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
public class ChannelCreation {
private String displayName;
private String name;
private String description;
private String support;
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getSupport() {
return support;
}
public void setSupport(String support) {
this.support = support;
}
}

View File

@ -14,12 +14,17 @@ package app.fedilab.fedilabtube.client.entities;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.content.SharedPreferences;
import org.json.JSONObject;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import app.fedilab.fedilabtube.helper.Helper;
@SuppressWarnings("unused")
public class Peertube {
@ -54,7 +59,6 @@ public class Peertube {
private String headerType = null;
private String headerTypeValue = null;
private JSONObject cache;
private boolean streamService;
public Peertube() {
}
@ -173,11 +177,13 @@ public class Peertube {
this.account = account;
}
public String getFileUrl(String resolution, boolean streamService) {
public String getFileUrl(String resolution, Context context) {
if (resolution == null)
resolution = this.getResolution().get(0);
if (resolution == null)
return null;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean streamService = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL) == Helper.VIDEO_MODE_STREAMING;
if (streamService) {
return "https://" + this.host + "/static/streaming-playlists/hls/" + getUuid() + "/" + getUuid() + "-" + resolution + "-fragmented.mp4";
} else {
@ -205,11 +211,13 @@ public class Peertube {
}
public String getFileDownloadUrl(String resolution, boolean streamService) {
public String getFileDownloadUrl(String resolution, Context context) {
if (resolution == null)
resolution = this.getResolution().get(0);
if (resolution == null)
return null;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean streamService = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL) == Helper.VIDEO_MODE_STREAMING;
if (streamService) {
return "https://" + this.host + "/download/streaming-playlists/hls/videos/" + getUuid() + "/" + getUuid() + "-" + resolution + "-fragmented.mp4";
} else {
@ -347,12 +355,4 @@ public class Peertube {
public void setHeaderTypeValue(String headerTypeValue) {
this.headerTypeValue = headerTypeValue;
}
public boolean isStreamService() {
return streamService;
}
public void setStreamService(boolean streamService) {
this.streamService = streamService;
}
}

View File

@ -19,6 +19,10 @@ public class PlaylistElement {
private String playlistElementId;
private String playlistId;
private String videoChannelId;
private String privacy;
private String displayName;
private String description;
private long startTimestamp;
private long stopTimestamp;
@ -53,4 +57,36 @@ public class PlaylistElement {
public void setStopTimestamp(long stopTimestamp) {
this.stopTimestamp = stopTimestamp;
}
public String getVideoChannelId() {
return videoChannelId;
}
public void setVideoChannelId(String videoChannelId) {
this.videoChannelId = videoChannelId;
}
public String getPrivacy() {
return privacy;
}
public void setPrivacy(String privacy) {
this.privacy = privacy;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@ -0,0 +1,179 @@
package app.fedilab.fedilabtube.drawer;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
import es.dmoral.toasty.Toasty;
public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnPostActionInterface {
EventListener listener;
private List<Account> accounts;
private Context context;
private AccountsHorizontalListAdapter accountsListAdapter;
public AccountsHorizontalListAdapter(List<Account> accounts, EventListener listener) {
this.accounts = accounts;
this.accountsListAdapter = this;
this.listener = listener;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
context = parent.getContext();
LayoutInflater layoutInflater = LayoutInflater.from(context);
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_horizontal_account, parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
final AccountsHorizontalListAdapter.ViewHolder holder = (AccountsHorizontalListAdapter.ViewHolder) viewHolder;
final Account account = accounts.get(position);
if (account.getDisplay_name() != null && !account.getDisplay_name().trim().equals(""))
holder.account_dn.setText(account.getDisplay_name());
else
holder.account_dn.setText(account.getUsername().replace("@", ""));
//Profile picture
Helper.loadGiF(context, account, holder.account_pp, 270);
if (account.isSelected()) {
holder.main_container.setBackgroundColor(ColorUtils.setAlphaComponent(ContextCompat.getColor(context, R.color.colorAccent), 50));
} else {
holder.main_container.setBackgroundColor(Color.TRANSPARENT);
}
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return accounts.size();
}
private Account getItemAt(int position) {
if (accounts.size() > position)
return accounts.get(position);
else
return null;
}
@Override
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String targetedId, Error error) {
if (error != null) {
Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show();
return;
}
if (statusAction == PeertubeAPI.StatusAction.FOLLOW) {
/* if (action == RetrieveAccountsAsyncTask.Type.CHANNELS) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new InstancesDAO(context, db).insertInstance(accounts.get(0).getAcct().split("@")[1], accounts.get(0).getAcct().split("@")[0], "PEERTUBE_CHANNEL");
} else {
for (Account account : accounts) {
if (account.getId().equals(targetedId)) {
account.setFollowType(Account.followAction.FOLLOW);
account.setMakingAction(false);
}
}
accountsListAdapter.notifyDataSetChanged();
}*/
}
if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW) {
for (Account account : accounts) {
if (account.getId().equals(targetedId)) {
account.setFollowType(Account.followAction.NOT_FOLLOW);
account.setMakingAction(false);
}
}
accountsListAdapter.notifyDataSetChanged();
}
}
private void notifyAccountChanged(Account account) {
for (int i = 0; i < accountsListAdapter.getItemCount(); i++) {
//noinspection ConstantConditions
if (accountsListAdapter.getItemAt(i) != null && accountsListAdapter.getItemAt(i).getId().equals(account.getId())) {
try {
accountsListAdapter.notifyItemChanged(i);
} catch (Exception ignored) {
}
}
}
}
public interface EventListener {
void click(String forAccount);
}
private class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView account_pp;
TextView account_dn;
LinearLayout main_container;
ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
account_pp = itemView.findViewById(R.id.account_pp);
account_dn = itemView.findViewById(R.id.account_dn);
main_container = itemView.findViewById(R.id.main_container);
}
@Override
public void onClick(View v) {
Account account = accounts.get(getAdapterPosition());
listener.click(account.getAcct());
for (Account acc : accounts) {
if (acc.getAcct().compareTo(account.getAcct()) == 0) {
acc.setSelected(true);
} else {
acc.setSelected(false);
}
}
notifyItemRangeChanged(0, accounts.size());
}
}
}

View File

@ -14,10 +14,13 @@ package app.fedilab.fedilabtube.drawer;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.Html;
import android.text.util.Linkify;
import android.view.LayoutInflater;
@ -29,6 +32,8 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
@ -37,9 +42,13 @@ import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.ShowAccountActivity;
import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.fedilabtube.client.HttpsConnection;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.fragment.DisplayPlaylistsFragment;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
import es.dmoral.toasty.Toasty;
@ -47,17 +56,18 @@ import es.dmoral.toasty.Toasty;
public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnPostActionInterface {
public AllAccountsRemoved allAccountsRemoved;
private List<Account> accounts;
private Context context;
private AccountsListAdapter accountsListAdapter;
private RetrieveAccountsAsyncTask.accountFetch type;
public AccountsListAdapter(String targetedId, List<Account> accounts) {
public AccountsListAdapter(RetrieveAccountsAsyncTask.accountFetch type, List<Account> accounts) {
this.accounts = accounts;
this.accountsListAdapter = this;
this.type = type;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@ -70,10 +80,58 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
final AccountsListAdapter.ViewHolder holder = (AccountsListAdapter.ViewHolder) viewHolder;
final Account account = accounts.get(position);
PeertubeAPI.StatusAction doAction = null;
holder.account_follow.hide();
if (type == RetrieveAccountsAsyncTask.accountFetch.CHANNEL) {
holder.account_action.show();
holder.account_action.setImageResource(R.drawable.ic_baseline_delete_24);
holder.account_action.setContentDescription(context.getString(R.string.delete_channel));
holder.account_action.setOnClickListener(view -> {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getString(R.string.action_channel_delete) + ": " + account.getAcct());
builder.setMessage(context.getString(R.string.action_channel_confirm_delete));
builder.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.yes, (dialog, which) -> {
accounts.remove(account);
notifyDataSetChanged();
new Thread(() -> {
try {
new PeertubeAPI(context).deleteChannel(account.getAcct());
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
DisplayPlaylistsFragment displayPlaylistsFragment;
if (context == null)
return;
displayPlaylistsFragment = (DisplayPlaylistsFragment) ((AppCompatActivity) context).getSupportFragmentManager().findFragmentByTag("CHANNELS");
final FragmentTransaction ft = ((AppCompatActivity) context).getSupportFragmentManager().beginTransaction();
if (displayPlaylistsFragment != null) {
ft.detach(displayPlaylistsFragment);
ft.attach(displayPlaylistsFragment);
ft.commit();
}
};
mainHandler.post(myRunnable);
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (e.getMessage() != null) {
Toasty.error(context, e.getMessage(), Toast.LENGTH_LONG).show();
} else {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
};
mainHandler.post(myRunnable);
}
}).start();
dialog.dismiss();
})
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
.show();
});
} else if (type == RetrieveAccountsAsyncTask.accountFetch.MUTED) {
holder.account_action.setOnClickListener(v -> new PostActionAsyncTask(context, PeertubeAPI.StatusAction.UNMUTE, account.getAcct(), AccountsListAdapter.this).execute());
} else {
holder.account_action.hide();
}
if (account.getDisplay_name() != null && !account.getDisplay_name().trim().equals(""))
holder.account_dn.setText(account.getDisplay_name());
@ -96,15 +154,16 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
//Profile picture
Helper.loadGiF(context, account, holder.account_pp);
if (account.isMakingAction()) {
holder.account_follow.setEnabled(false);
holder.account_action.setEnabled(false);
} else {
holder.account_follow.setEnabled(true);
holder.account_action.setEnabled(true);
}
//Follow button
PeertubeAPI.StatusAction finalDoAction = doAction;
holder.account_follow.setOnClickListener(v -> {
if (type == RetrieveAccountsAsyncTask.accountFetch.MUTED) {
holder.account_action.show();
holder.account_action.setImageResource(R.drawable.ic_baseline_volume_mute_24);
}
});
holder.account_pp.setOnClickListener(v -> {
Intent intent = new Intent(context, ShowAccountActivity.class);
@ -117,6 +176,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
context.startActivity(intent);
});
}
@Override
@ -129,13 +189,6 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
return accounts.size();
}
private Account getItemAt(int position) {
if (accounts.size() > position)
return accounts.get(position);
else
return null;
}
@Override
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String targetedId, Error error) {
if (error != null) {
@ -144,18 +197,28 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
if (statusAction == PeertubeAPI.StatusAction.FOLLOW) {
/* if (action == RetrieveAccountsAsyncTask.Type.CHANNELS) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new InstancesDAO(context, db).insertInstance(accounts.get(0).getAcct().split("@")[1], accounts.get(0).getAcct().split("@")[0], "PEERTUBE_CHANNEL");
} else {
for (Account account : accounts) {
if (account.getId().equals(targetedId)) {
account.setFollowType(Account.followAction.FOLLOW);
account.setMakingAction(false);
}
for (Account account : accounts) {
if (account.getId().equals(targetedId)) {
account.setFollowType(Account.followAction.FOLLOW);
account.setMakingAction(false);
}
accountsListAdapter.notifyDataSetChanged();
}*/
}
accountsListAdapter.notifyDataSetChanged();
}
if (statusAction == PeertubeAPI.StatusAction.UNMUTE) {
Account tmpAccount = null;
int position = 0;
for (Account account : accounts) {
if (account.getAcct().equals(targetedId)) {
tmpAccount = account;
break;
}
position++;
}
if (tmpAccount != null) {
accounts.remove(position);
accountsListAdapter.notifyItemRemoved(position);
}
}
if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW) {
for (Account account : accounts) {
@ -165,22 +228,17 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
}
accountsListAdapter.notifyDataSetChanged();
}
}
private void notifyAccountChanged(Account account) {
for (int i = 0; i < accountsListAdapter.getItemCount(); i++) {
//noinspection ConstantConditions
if (accountsListAdapter.getItemAt(i) != null && accountsListAdapter.getItemAt(i).getId().equals(account.getId())) {
try {
accountsListAdapter.notifyItemChanged(i);
} catch (Exception ignored) {
}
if (accounts.size() == 0) {
allAccountsRemoved.onAllAccountsRemoved();
}
}
}
public interface AllAccountsRemoved {
void onAllAccountsRemoved();
}
private static class ViewHolder extends RecyclerView.ViewHolder {
ImageView account_pp;
TextView account_ac;
@ -191,7 +249,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
TextView account_fgc;
TextView account_frc;
LinearLayout account_info;
FloatingActionButton account_follow;
FloatingActionButton account_action;
LinearLayout account_container;
ViewHolder(View itemView) {
@ -204,7 +262,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
account_sc = itemView.findViewById(R.id.account_sc);
account_fgc = itemView.findViewById(R.id.account_fgc);
account_frc = itemView.findViewById(R.id.account_frc);
account_follow = itemView.findViewById(R.id.account_follow);
account_action = itemView.findViewById(R.id.account_action);
account_info = itemView.findViewById(R.id.account_info);
account_container = itemView.findViewById(R.id.account_container);
}

View File

@ -74,9 +74,23 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
boolean ownVideos = peertube.getAccount().getInstance().compareTo(Helper.getLiveInstance(context)) == 0 && peertube.getAccount().getId().compareTo(userId) == 0;
boolean ownVideos = peertube.getAccount().getInstance().compareTo(Helper.getLiveInstance(context)) == 0 && userId != null && peertube.getAccount().getId() != null && peertube.getAccount().getId().compareTo(userId) == 0;
holder.peertube_account_name.setText(account.getAcct());
if (peertube.getChannel() == null) {
holder.peertube_account_name.setText(account.getAcct());
if (account.getAvatar() != null && !account.getAvatar().equals("null") && !account.getAvatar().startsWith("http")) {
account.setAvatar("https://" + peertube.getInstance() + account.getAvatar());
account.setAvatar_static(account.getAvatar());
}
Helper.loadGiF(context, account, holder.peertube_profile);
} else {
holder.peertube_account_name.setText(peertube.getChannel().getAcct());
if (peertube.getChannel().getAvatar() != null && !peertube.getChannel().getAvatar().equals("null") && !peertube.getChannel().getAvatar().startsWith("http")) {
peertube.getChannel().setAvatar("https://" + peertube.getInstance() + peertube.getChannel().getAvatar());
peertube.getChannel().setAvatar_static(peertube.getChannel().getAvatar());
}
Helper.loadGiF(context, peertube.getChannel(), holder.peertube_profile);
}
holder.peertube_title.setText(peertube.getName());
holder.peertube_duration.setText(context.getString(R.string.duration_video, Helper.secondsToString(peertube.getDuration())));
holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, peertube.getCreated_at())));
@ -85,17 +99,18 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
Glide.with(holder.peertube_video_image.getContext())
.load("https://" + peertube.getInstance() + peertube.getThumbnailPath())
.into(holder.peertube_video_image);
if (account.getAvatar() != null && !account.getAvatar().equals("null") && !account.getAvatar().startsWith("http")) {
account.setAvatar("https://" + peertube.getInstance() + account.getAvatar());
account.setAvatar_static(account.getAvatar());
}
Helper.loadGiF(context, account, holder.peertube_profile);
if (!ownVideos) {
holder.peertube_profile.setOnClickListener(v -> {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putParcelable("account", peertube.getAccount());
if (peertube.getChannel() == null) {
b.putParcelable("account", peertube.getAccount());
} else {
b.putParcelable("account", peertube.getChannel());
b.putBoolean("ischannel", true);
}
intent.putExtras(b);
context.startActivity(intent);
});

View File

@ -68,7 +68,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
PeertubeAccountNotification accountAction = null;
PeertubeVideoNotification videoAction;
if (notification.getPeertubeActorFollow() != null) {
String profileUrl = "https://" + Helper.getLiveInstance(context) + notification.getPeertubeActorFollow().getFollower().getAvatar();
String profileUrl = notification.getPeertubeActorFollow().getFollower().getAvatar();
Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp);
accountAction = notification.getPeertubeActorFollow().getFollower();
String type = notification.getPeertubeActorFollow().getFollowing().getType();
@ -86,13 +86,13 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
holder.peertube_notif_pp.setOnClickListener(v -> {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putBoolean("peertubeaccount", true);
b.putString("accountId", finalAccountAction1.getName());
b.putString("accountId", finalAccountAction1.getName() + "@" + finalAccountAction1.getHost());
b.putBoolean("ischannel", true);
intent.putExtras(b);
context.startActivity(intent);
});
} else if (notification.getPeertubeComment() != null) { //Comment Notification
String profileUrl = "https://" + Helper.getLiveInstance(context) + notification.getPeertubeComment().getPeertubeAccountNotification().getAvatar();
String profileUrl = notification.getPeertubeComment().getPeertubeAccountNotification().getAvatar();
Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp);
accountAction = notification.getPeertubeComment().getPeertubeAccountNotification();
videoAction = notification.getPeertubeComment().getPeertubeVideoNotification();
@ -113,7 +113,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
});
} else {//Other Notifications
if (notification.getPeertubeVideoNotification() != null && notification.getPeertubeVideoNotification().getPeertubeAccountNotification() != null) {
String profileUrl = "https://" + Helper.getLiveInstance(context) + notification.getPeertubeVideoNotification().getPeertubeAccountNotification().getAvatar();
String profileUrl = notification.getPeertubeVideoNotification().getPeertubeAccountNotification().getAvatar();
Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp);
accountAction = notification.getPeertubeVideoNotification().getPeertubeAccountNotification();
videoAction = notification.getPeertubeVideoNotification();
@ -152,8 +152,8 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
if (finalAccountAction != null) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putBoolean("peertubeaccount", true);
b.putString("accountId", finalAccountAction.getName() + "@" + finalAccountAction.getHost());
b.putBoolean("ischannel", true);
intent.putExtras(b);
context.startActivity(intent);
}

View File

@ -17,20 +17,24 @@ package app.fedilab.fedilabtube.drawer;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import androidx.appcompat.widget.PopupMenu;
import com.bumptech.glide.Glide;
import java.util.List;
import java.util.Map;
import app.fedilab.fedilabtube.PlaylistsActivity;
import app.fedilab.fedilabtube.R;
@ -78,22 +82,32 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.drawer_playlist, parent, false);
holder = new ViewHolder();
holder.search_title = convertView.findViewById(R.id.search_keyword);
holder.search_container = convertView.findViewById(R.id.search_container);
holder.preview_title = convertView.findViewById(R.id.preview_title);
holder.preview_visibility = convertView.findViewById(R.id.preview_visibility);
holder.preview_description = convertView.findViewById(R.id.preview_description);
holder.playlist_container = convertView.findViewById(R.id.playlist_container);
holder.preview_playlist = convertView.findViewById(R.id.preview_playlist);
holder.playlist_more = convertView.findViewById(R.id.playlist_more);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Glide.with(context)
.load("https://" + playlist.getOwnerAccount().getHost() + playlist.getThumbnailPath())
.into(holder.preview_playlist);
Drawable next = ContextCompat.getDrawable(context, R.drawable.ic_baseline_arrow_forward_ios_24);
holder.search_title.setText(playlist.getDisplayName());
assert next != null;
final float scale = context.getResources().getDisplayMetrics().density;
next.setBounds(0, 0, (int) (30 * scale + 0.5f), (int) (30 * scale + 0.5f));
holder.search_title.setCompoundDrawables(null, null, next, null);
holder.preview_title.setText(playlist.getDisplayName());
if (playlist.getDescription() != null && playlist.getDescription().trim().compareTo("null") != 0 && playlist.getDescription().length() > 0) {
holder.preview_description.setText(playlist.getDescription());
holder.preview_description.setVisibility(View.VISIBLE);
} else {
holder.preview_description.setVisibility(View.GONE);
}
Map.Entry<Integer, String> privacyM = playlist.getPrivacy().entrySet().iterator().next();
holder.preview_visibility.setText(privacyM.getValue());
holder.search_container.setOnClickListener(v -> {
holder.playlist_container.setOnClickListener(v -> {
Intent intent = new Intent(context, PlaylistsActivity.class);
Bundle b = new Bundle();
b.putParcelable("playlist", playlist);
@ -101,23 +115,37 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
context.startActivity(intent);
});
holder.search_container.setOnLongClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getString(R.string.action_lists_delete) + ": " + playlist.getDisplayName());
builder.setMessage(context.getString(R.string.action_lists_confirm_delete));
builder.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.yes, (dialog, which) -> {
playlists.remove(playlist);
notifyDataSetChanged();
new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.DELETE_PLAYLIST, playlist, null, null, PlaylistAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (playlists.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE)
textviewNoAction.setVisibility(View.VISIBLE);
dialog.dismiss();
})
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
.show();
return false;
holder.playlist_more.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(context, holder.playlist_more);
popup.getMenuInflater()
.inflate(R.menu.playlist_menu, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
case R.id.action_delete:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getString(R.string.action_lists_delete) + ": " + playlist.getDisplayName());
builder.setMessage(context.getString(R.string.action_lists_confirm_delete));
builder.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.yes, (dialog, which) -> {
playlists.remove(playlist);
notifyDataSetChanged();
new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.DELETE_PLAYLIST, playlist, null, null, PlaylistAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (playlists.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE)
textviewNoAction.setVisibility(View.VISIBLE);
dialog.dismiss();
})
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
.show();
break;
/*case R.id.action_edit:
break;*/
}
return true;
});
popup.show();
});
return convertView;
}
@ -128,8 +156,10 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
}
private static class ViewHolder {
LinearLayout search_container;
TextView search_title;
LinearLayout playlist_container;
ImageView preview_playlist;
TextView preview_title, preview_visibility, preview_description;
ImageButton playlist_more;
}

View File

@ -14,63 +14,80 @@ package app.fedilab.fedilabtube.fragment;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrieveSingleAccountAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.HttpsConnection;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.ChannelCreation;
import app.fedilab.fedilabtube.drawer.AccountsListAdapter;
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface;
import es.dmoral.toasty.Toasty;
public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccountsInterface {
public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccountsInterface, AccountsListAdapter.AllAccountsRemoved {
private boolean flag_loading;
private Context context;
private AsyncTask<Void, Void, Void> asyncTask;
private AsyncTask<Void, Void, APIResponse> asyncTask;
private AccountsListAdapter accountsListAdapter;
private String max_id;
private List<Account> accounts;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private String targetedId, name;
private String name;
private boolean swiped;
private RecyclerView lv_accounts;
private View rootView;
private RetrieveAccountsAsyncTask.accountFetch accountFetch;
private FloatingActionButton action_button;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_accounts, container, false);
rootView = inflater.inflate(R.layout.fragment_recyclerview, container, false);
context = getContext();
Bundle bundle = this.getArguments();
accounts = new ArrayList<>();
if (bundle != null) {
if (bundle.containsKey("tag"))
targetedId = bundle.getString("tag", null);
else
targetedId = bundle.getString("targetedid", null);
if (bundle.containsKey("accountFetch")) {
accountFetch = (RetrieveAccountsAsyncTask.accountFetch) bundle.getSerializable("accountFetch");
}
name = bundle.getString("name", null);
}
max_id = null;
@ -81,16 +98,95 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
lv_accounts = rootView.findViewById(R.id.lv_accounts);
if (getActivity() != null) {
action_button = getActivity().findViewById(R.id.action_button);
action_button.setOnClickListener(view -> {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
LayoutInflater inflater1 = ((Activity) context).getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.add_channel, new LinearLayout(context), false);
dialogBuilder.setView(dialogView);
EditText display_name = dialogView.findViewById(R.id.display_name);
EditText name = dialogView.findViewById(R.id.name);
EditText description = dialogView.findViewById(R.id.description);
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0 && name.getText() != null && name.getText().toString().trim().length() > 0) {
ChannelCreation channelCreation = new ChannelCreation();
channelCreation.setDisplayName(display_name.getText().toString().trim());
channelCreation.setName(name.getText().toString().trim());
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
channelCreation.setDescription(description.getText().toString().trim());
}
new Thread(() -> {
try {
new PeertubeAPI(context).createChannel(channelCreation);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
DisplayPlaylistsFragment displayPlaylistsFragment;
if (getActivity() == null)
return;
displayPlaylistsFragment = (DisplayPlaylistsFragment) getActivity().getSupportFragmentManager().findFragmentByTag("CHANNELS");
final FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
if (displayPlaylistsFragment != null) {
ft.detach(displayPlaylistsFragment);
ft.attach(displayPlaylistsFragment);
ft.commit();
}
action_button.setEnabled(true);
};
mainHandler.post(myRunnable);
} catch (HttpsConnection.HttpsConnectionException e) {
action_button.setEnabled(true);
e.printStackTrace();
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (e.getMessage() != null) {
Toasty.error(context, e.getMessage(), Toast.LENGTH_LONG).show();
} else {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
};
mainHandler.post(myRunnable);
}
}).start();
dialog.dismiss();
action_button.setEnabled(false);
} else {
Toasty.error(context, context.getString(R.string.error_display_name_channel), Toast.LENGTH_LONG).show();
}
});
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.action_channel_create));
alertDialog.setOnDismissListener(dialogInterface -> {
//Hide keyboard
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(display_name.getWindowToken(), 0);
});
if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
});
}
lv_accounts = rootView.findViewById(R.id.lv_elements);
lv_accounts.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
mainLoader = rootView.findViewById(R.id.loader);
nextElementLoader = rootView.findViewById(R.id.loading_next_accounts);
nextElementLoader = rootView.findViewById(R.id.loading_next);
textviewNoAction = rootView.findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
accountsListAdapter = new AccountsListAdapter(targetedId, this.accounts);
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
accountsListAdapter.allAccountsRemoved = this;
lv_accounts.setAdapter(accountsListAdapter);
TextView no_action_text = rootView.findViewById(R.id.no_action_text);
if (accountFetch == RetrieveAccountsAsyncTask.accountFetch.MUTED) {
no_action_text.setText(context.getString(R.string.no_muted));
}
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(context);
lv_accounts.setLayoutManager(mLayoutManager);
@ -103,7 +199,12 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
asyncTask = new RetrieveAccountsAsyncTask(context, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (accountFetch == null) {
asyncTask = new RetrieveSingleAccountAsyncTask(context, name, RetrieveSingleAccountAsyncTask.actionType.ACCOUNT, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
String param = accountFetch == RetrieveAccountsAsyncTask.accountFetch.CHANNEL ? name : max_id;
asyncTask = new RetrieveAccountsAsyncTask(context, param, accountFetch, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
@ -114,10 +215,25 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
});
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
asyncTask = new RetrieveAccountsAsyncTask(context, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (accountFetch == null) {
asyncTask = new RetrieveSingleAccountAsyncTask(context, name, RetrieveSingleAccountAsyncTask.actionType.ACCOUNT, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
String param = accountFetch == RetrieveAccountsAsyncTask.accountFetch.CHANNEL ? name : null;
asyncTask = new RetrieveAccountsAsyncTask(context, param, accountFetch, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
return rootView;
}
@Override
public void onResume() {
super.onResume();
if (accountFetch == RetrieveAccountsAsyncTask.accountFetch.CHANNEL) {
action_button.setVisibility(View.VISIBLE);
} else {
action_button.setVisibility(View.GONE);
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
@ -169,7 +285,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
max_id = apiResponse.getMax_id();
if (swiped) {
accountsListAdapter = new AccountsListAdapter(targetedId, this.accounts);
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
lv_accounts.setAdapter(accountsListAdapter);
swiped = false;
}
@ -189,7 +305,16 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
flag_loading = true;
swiped = true;
swipeRefreshLayout.setRefreshing(true);
asyncTask = new RetrieveAccountsAsyncTask(context, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (accountFetch == null) {
asyncTask = new RetrieveSingleAccountAsyncTask(context, name, RetrieveSingleAccountAsyncTask.actionType.ACCOUNT, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
String param = accountFetch == RetrieveAccountsAsyncTask.accountFetch.CHANNEL ? name : null;
asyncTask = new RetrieveAccountsAsyncTask(context, param, accountFetch, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@Override
public void onAllAccountsRemoved() {
textviewNoAction.setVisibility(View.VISIBLE);
}
}

View File

@ -0,0 +1,192 @@
package app.fedilab.fedilabtube.fragment;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeNotificationsAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.PeertubeNotification;
import app.fedilab.fedilabtube.drawer.PeertubeNotificationsListAdapter;
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeNotificationsInterface;
import es.dmoral.toasty.Toasty;
public class DisplayNotificationsFragment extends Fragment implements OnRetrievePeertubeNotificationsInterface {
private boolean flag_loading;
private Context context;
private AsyncTask<Void, Void, APIResponse> asyncTask;
private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter;
private String max_id;
private List<PeertubeNotification> notifications;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private boolean swiped;
private RecyclerView lv_notifications;
private View rootView;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_recyclerview, container, false);
context = getContext();
notifications = new ArrayList<>();
max_id = null;
firstLoad = true;
flag_loading = true;
swiped = false;
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
lv_notifications = rootView.findViewById(R.id.lv_elements);
lv_notifications.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
mainLoader = rootView.findViewById(R.id.loader);
nextElementLoader = rootView.findViewById(R.id.loading_next);
textviewNoAction = rootView.findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
peertubeNotificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications);
lv_notifications.setAdapter(peertubeNotificationsListAdapter);
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(context);
lv_notifications.setLayoutManager(mLayoutManager);
lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
asyncTask = new RetrievePeertubeNotificationsAsyncTask(context, null, max_id, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
}
}
}
});
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
asyncTask = new RetrievePeertubeNotificationsAsyncTask(context, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return rootView;
}
@Override
public void onDestroyView() {
super.onDestroyView();
rootView = null;
}
@Override
public void onCreate(Bundle saveInstance) {
super.onCreate(saveInstance);
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
this.context = context;
}
public void onDestroy() {
super.onDestroy();
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
asyncTask.cancel(true);
}
public void scrollToTop() {
if (lv_notifications != null)
lv_notifications.setAdapter(peertubeNotificationsListAdapter);
}
public void pullToRefresh() {
max_id = null;
notifications = new ArrayList<>();
firstLoad = true;
flag_loading = true;
swiped = true;
swipeRefreshLayout.setRefreshing(true);
asyncTask = new RetrievePeertubeNotificationsAsyncTask(context, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public void onRetrievePeertubeNotifications(APIResponse apiResponse, Account account) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if (apiResponse.getError() != null) {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
flag_loading = false;
swipeRefreshLayout.setRefreshing(false);
swiped = false;
return;
}
int previousPosition = notifications.size();
max_id = apiResponse.getMax_id();
List<PeertubeNotification> notifications = apiResponse.getPeertubeNotifications();
if (!swiped && firstLoad && (notifications == null || notifications.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
if (swiped) {
if (previousPosition > 0) {
this.notifications.subList(0, previousPosition).clear();
peertubeNotificationsListAdapter.notifyItemRangeRemoved(0, previousPosition);
}
swiped = false;
}
if (notifications != null && notifications.size() > 0) {
this.notifications.addAll(notifications);
peertubeNotificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
} else {
if (firstLoad)
textviewNoAction.setVisibility(View.VISIBLE);
}
swipeRefreshLayout.setRefreshing(false);
firstLoad = false;
//The initial call comes from a classic tab refresh
flag_loading = (max_id == null);
}
}

View File

@ -16,11 +16,11 @@ package app.fedilab.fedilabtube.fragment;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.InputFilter;
import android.view.LayoutInflater;
import android.view.View;
@ -43,15 +43,8 @@ import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import net.gotev.uploadservice.MultipartUploadRequest;
import net.gotev.uploadservice.ServerResponse;
import net.gotev.uploadservice.UploadInfo;
import net.gotev.uploadservice.UploadNotificationConfig;
import net.gotev.uploadservice.UploadStatusDelegate;
import org.jetbrains.annotations.NotNull;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -64,10 +57,12 @@ import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.HttpsConnection;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Playlist;
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
import app.fedilab.fedilabtube.drawer.PlaylistAdapter;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
import es.dmoral.toasty.Toasty;
@ -113,11 +108,6 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
asyncTask = new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, DisplayPlaylistsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
add_new = rootView.findViewById(R.id.add_new);
LinkedHashMap<String, String> translations = null;
if (peertubeInformation != null && peertubeInformation.getTranslations() != null)
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
privacyToSend = new HashMap<>();
@ -131,7 +121,6 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
if (add_new != null) {
add_new.setOnClickListener(view -> {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
LayoutInflater inflater1 = ((Activity) context).getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.add_playlist, new LinearLayout(context), false);
@ -147,97 +136,79 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
Playlist playlist = new Playlist();
playlist.setDisplayName(display_name.getText().toString().trim());
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
playlist.setDescription(description.getText().toString().trim());
}
String idChannel = null;
if (channelToSend != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
idChannel = channelM.getValue();
if (idChannel.length() > 0)
playlist.setVideoChannelId(idChannel);
}
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
String label = privacyM.getValue();
String idPrivacy = String.valueOf(privacyM.getKey());
if (label.equals("Public") && (playlist.getVideoChannelId() == null || playlist.getVideoChannelId().equals(""))) {
Toasty.error(context, context.getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
} else {
if (privacyToSend != null) {
playlist.setPrivacy(privacyToSend);
}
//new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.CREATE_PLAYLIST, playlist, null, null, DisplayPlaylistsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
uploadConfig.getCompleted().autoClear = true;
try {
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
new MultipartUploadRequest(context, "https://" + Helper.getLiveInstance(context) + "/api/v1/video-playlists/")
//.addFileToUpload(uri.toString().replace("file://",""), "videofile")
.addHeader("Authorization", "Bearer " + token)
.setNotificationConfig(uploadConfig)
// .addParameter("name", filename)
.addParameter("videoChannelId", idChannel)
.addParameter("privacy", idPrivacy)
.addParameter("displayName", playlist.getDisplayName())
.addParameter("description", playlist.getDescription())
.setMaxRetries(1)
.setDelegate(new UploadStatusDelegate() {
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
// your code here
}
@Override
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) {
// your code here
exception.printStackTrace();
}
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
DisplayPlaylistsFragment displayPlaylistsFragment;
if (getActivity() == null)
return;
displayPlaylistsFragment = (DisplayPlaylistsFragment) getActivity().getSupportFragmentManager().findFragmentByTag("PLAYLISTS");
final FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
if (displayPlaylistsFragment != null) {
ft.detach(displayPlaylistsFragment);
ft.attach(displayPlaylistsFragment);
ft.commit();
}
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
// your code here
}
})
.startUpload();
} catch (MalformedURLException e) {
e.printStackTrace();
}
dialog.dismiss();
add_new.setEnabled(false);
}
} else {
Toasty.error(context, context.getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
Playlist playlist = new Playlist();
playlist.setDisplayName(display_name.getText().toString().trim());
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
playlist.setDescription(description.getText().toString().trim());
}
String idChannel = null;
if (channelToSend != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
idChannel = channelM.getValue();
if (idChannel.length() > 0)
playlist.setVideoChannelId(idChannel);
}
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
String label = privacyM.getValue();
String idPrivacy = String.valueOf(privacyM.getKey());
if (label.equals("Public") && (playlist.getVideoChannelId() == null || playlist.getVideoChannelId().equals(""))) {
Toasty.error(context, context.getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
} else {
if (privacyToSend != null) {
playlist.setPrivacy(privacyToSend);
}
PlaylistElement playlistElement = new PlaylistElement();
playlistElement.setVideoChannelId(idChannel);
playlistElement.setPrivacy(idPrivacy);
playlistElement.setDisplayName(playlist.getDisplayName());
playlistElement.setDescription(playlist.getDescription());
new Thread(() -> {
try {
new PeertubeAPI(context).createPlaylist(playlistElement);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
DisplayPlaylistsFragment displayPlaylistsFragment;
if (getActivity() == null)
return;
displayPlaylistsFragment = (DisplayPlaylistsFragment) getActivity().getSupportFragmentManager().findFragmentByTag("PLAYLISTS");
final FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
if (displayPlaylistsFragment != null) {
ft.detach(displayPlaylistsFragment);
ft.attach(displayPlaylistsFragment);
ft.commit();
}
};
mainHandler.post(myRunnable);
add_new.setEnabled(true);
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (e.getMessage() != null) {
Toasty.error(context, e.getMessage(), Toast.LENGTH_LONG).show();
} else {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
add_new.setEnabled(true);
};
mainHandler.post(myRunnable);
}
}).start();
dialog.dismiss();
add_new.setEnabled(false);
}
} else {
Toasty.error(context, context.getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
}
});
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.action_playlist_create));
alertDialog.setOnDismissListener(dialogInterface -> {

View File

@ -25,11 +25,13 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -42,22 +44,27 @@ import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSearchAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.Peertube;
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type.POVERVIEW;
import static app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type.PSUBSCRIPTIONS;
public class DisplayStatusFragment extends Fragment implements OnPostActionInterface, OnRetrieveFeedsInterface {
public class DisplayStatusFragment extends Fragment implements OnPostActionInterface, OnRetrieveFeedsInterface, OnRetrieveAccountsInterface, AccountsHorizontalListAdapter.EventListener {
private LinearLayoutManager mLayoutManager;
@ -66,8 +73,10 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
private Context context;
private AsyncTask<Void, Void, Void> asyncTask;
private PeertubeAdapter peertubeAdapater;
private String max_id;
private AccountsHorizontalListAdapter accountsHorizontalListAdapter;
private String max_id, max_id_accounts;
private List<Peertube> peertubes;
private List<Account> accounts;
private RetrieveFeedsAsyncTask.Type type;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
@ -79,6 +88,9 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
private View rootView;
private RecyclerView lv_status;
private String targetedId;
private boolean check_ScrollingUp;
private String forAccount;
private ConstraintLayout top_account_container;
public DisplayStatusFragment() {
}
@ -90,6 +102,7 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
peertubes = new ArrayList<>();
accounts = new ArrayList<>();
context = getContext();
Bundle bundle = this.getArguments();
@ -109,12 +122,16 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
type = RetrieveFeedsAsyncTask.Type.CHANNEL;
}
forAccount = null;
lv_status = rootView.findViewById(R.id.lv_status);
RecyclerView lv_accounts = rootView.findViewById(R.id.lv_accounts);
Button display_all = rootView.findViewById(R.id.display_all);
top_account_container = rootView.findViewById(R.id.top_account_container);
max_id = null;
max_id_accounts = null;
flag_loading = true;
firstLoad = true;
check_ScrollingUp = false;
assert context != null;
sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -130,6 +147,12 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
peertubeAdapater = new PeertubeAdapter(this.peertubes);
lv_status.setAdapter(peertubeAdapater);
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, this);
LinearLayoutManager layoutManager
= new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
lv_accounts.setLayoutManager(layoutManager);
lv_accounts.setAdapter(accountsHorizontalListAdapter);
if (!Helper.isTablet(context)) {
mLayoutManager = new LinearLayoutManager(context);
lv_status.setLayoutManager(mLayoutManager);
@ -162,9 +185,39 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
}, 500);
}
lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
new RetrieveAccountsAsyncTask(context, max_id_accounts, RetrieveAccountsAsyncTask.accountFetch.SUBSCRIPTION, DisplayStatusFragment.this).execute();
}
}
}
});
if (type != POVERVIEW) {
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (type == PSUBSCRIPTIONS) {
if (dy > 0) {
if (check_ScrollingUp) {
top_account_container.setVisibility(View.GONE);
final Handler handler = new Handler();
handler.postDelayed(() -> check_ScrollingUp = false, 300);
}
} else {
if (!check_ScrollingUp) {
top_account_container.setVisibility(View.VISIBLE);
final Handler handler = new Handler();
handler.postDelayed(() -> check_ScrollingUp = true, 300);
}
}
}
if (mLayoutManager != null) {
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (dy > 0) {
@ -207,8 +260,14 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
}
});
}
if (type == PSUBSCRIPTIONS) {
new RetrieveAccountsAsyncTask(context, max_id, RetrieveAccountsAsyncTask.accountFetch.SUBSCRIPTION, DisplayStatusFragment.this).execute();
}
display_all.setOnClickListener(v -> {
forAccount = null;
pullToRefresh();
});
return rootView;
}
@ -254,6 +313,25 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
asyncTask.cancel(true);
}
@Override
public void onRetrieveAccounts(APIResponse apiResponse) {
if (apiResponse != null && apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) {
if (top_account_container.getVisibility() == View.GONE) {
top_account_container.setVisibility(View.VISIBLE);
}
int previousPosition = accounts.size();
accounts.addAll(apiResponse.getAccounts());
accountsHorizontalListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getAccounts().size());
if (max_id_accounts == null) {
max_id_accounts = "0";
}
//max_id_accounts needs to work like an offset
int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE);
max_id_accounts = String.valueOf(Integer.parseInt(max_id_accounts) + tootPerPage);
}
}
@Override
public void onRetrieveFeeds(APIResponse apiResponse) {
//hide loaders
@ -327,17 +405,21 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
public void pullToRefresh() {
if (peertubes.size() > 0) {
int size = peertubes.size();
peertubes.clear();
peertubes = new ArrayList<>();
max_id = "0";
peertubeAdapater.notifyItemRangeRemoved(0, size);
if (search_peertube == null) { //Not a Peertube search
asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", targetedId, DisplayStatusFragment.this).execute();
} else {
asyncTask = new RetrievePeertubeSearchAsyncTask(context, "0", search_peertube, DisplayStatusFragment.this).execute();
int size = peertubes.size();
peertubes.clear();
peertubes = new ArrayList<>();
max_id = "0";
peertubeAdapater.notifyItemRangeRemoved(0, size);
if (forAccount == null) {
for (Account account : accounts) {
account.setSelected(false);
}
accountsHorizontalListAdapter.notifyItemRangeRemoved(0, accounts.size());
}
if (search_peertube == null) { //Not a Peertube search
asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", targetedId, forAccount, DisplayStatusFragment.this).execute();
} else {
asyncTask = new RetrievePeertubeSearchAsyncTask(context, "0", search_peertube, DisplayStatusFragment.this).execute();
}
}
@ -347,6 +429,11 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
}
@Override
public void click(String forAccount) {
this.forAccount = forAccount;
pullToRefresh();
}
static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {

View File

@ -0,0 +1,109 @@
package app.fedilab.fedilabtube.fragment;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import java.util.Arrays;
import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.helper.Helper;
import es.dmoral.toasty.Toasty;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.main_preferences);
createPref();
}
@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
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 && getActivity() != null) {
SharedPreferences sharedpreferences = getActivity().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
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_STREAMING);
break;
case "2":
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_WEBVIEW);
break;
}
editor.apply();
}
}
}
private void createPref() {
getPreferenceScreen().removeAll();
addPreferencesFromResource(R.xml.main_preferences);
PreferenceScreen preferenceScreen = getPreferenceScreen();
FragmentActivity context = getActivity();
assert context != null;
if (preferenceScreen == null) {
Toasty.error(getActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
return;
}
//****** Video mode *******
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
List<String> array = Arrays.asList(getResources().getStringArray(R.array.settings_video_mode));
CharSequence[] entries = array.toArray(new CharSequence[0]);
CharSequence[] entryValues = new CharSequence[3];
final SharedPreferences sharedpref = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int video_mode = sharedpref.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
entryValues[0] = String.valueOf(Helper.VIDEO_MODE_NORMAL);
entryValues[1] = String.valueOf(Helper.VIDEO_MODE_STREAMING);
entryValues[2] = String.valueOf(Helper.VIDEO_MODE_WEBVIEW);
if (set_video_mode_choice != null) {
set_video_mode_choice.setEntries(entries);
set_video_mode_choice.setEntryValues(entryValues);
set_video_mode_choice.setValueIndex(video_mode);
}
}
}

View File

@ -72,10 +72,13 @@ public class Helper {
public static final int RELOAD_MYVIDEOS = 10;
public static final String SET_VIDEO_MODE = "set_video_mode";
public static final int VIDEO_MODE_TORRENT = 0;
public static final int VIDEO_MODE_WEBVIEW = 1;
public static final int VIDEO_MODE_DIRECT = 2;
public static final int VIDEO_MODE_NORMAL = 0;
public static final int VIDEO_MODE_STREAMING = 1;
public static final int VIDEO_MODE_WEBVIEW = 2;
public static final int VIDEO_MODE_TORRENT = 3;
public static final int ADD_USER_INTENT = 5;
public static final int VIDEO_UPLOADED_INTENT = 6;
public static final String VIDEO_UPLOAD_ID = "VIDEO_UPLOAD_ID";
public static final String SET_SHARE_DETAILS = "set_share_details";
public static final int DEFAULT_VIDEO_CACHE_MB = 100;
public static final String TAG = "mastodon_etalab";
@ -239,6 +242,9 @@ public class Helper {
public static String getLiveInstance(Context context) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String acad = sharedpreferences.getString(Helper.PREF_INSTANCE, "tube.ac-lyon.fr");
if (acad == null) {
acad = "tube.ac-lyon.fr";
}
if (acad.startsWith("tube-")) {
return acad;
} else {
@ -407,14 +413,12 @@ public class Helper {
}
public static void loadGiF(final Context context, Account account, final ImageView imageView) {
public static void loadGiF(final Context context, Account account, final ImageView imageView, int round) {
if (account == null || account.getAvatar() == null || account.getAvatar().compareTo("null") == 0) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing_peertube)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(round)))
.into(imageView);
return;
}
@ -429,14 +433,14 @@ public class Helper {
Glide.with(imageView.getContext())
.load(url)
.thumbnail(0.1f)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(round)))
.into(imageView);
} catch (Exception e) {
try {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing_peertube)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(round)))
.into(imageView);
} catch (Exception ignored) {
@ -444,9 +448,21 @@ public class Helper {
}
}
public static void loadGiF(final Context context, Account account, final ImageView imageView) {
loadGiF(context, account, imageView, 10);
}
public static void loadGiF(final Context context, String url, final ImageView imageView) {
if (url == null || url.trim().toLowerCase().compareTo("null") == 0) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing_peertube)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
return;
}
if (url.startsWith("/")) {
url = Helper.getLiveInstance(context) + url;
}
@ -666,4 +682,5 @@ public class Helper {
return context.getResources().getBoolean(R.bool.is_tablet);
}
}

View File

@ -14,9 +14,11 @@ package app.fedilab.fedilabtube.interfaces;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import java.util.List;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.Relationship;
public interface OnRetrieveRelationshipInterface {
void onRetrieveRelationship(Relationship relationship, Error error);
void onRetrieveRelationship(List<Relationship> relationships, Error error);
}

View File

@ -14,6 +14,7 @@ package app.fedilab.fedilabtube.services;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -43,9 +44,9 @@ public class PeertubeUploadReceiver extends UploadServiceBroadcastReceiver {
@Override
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse,
Exception exception) {
// your code here
}
@SuppressLint("ApplySharedPref")
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
try {

View File

@ -68,9 +68,11 @@ public class AccountDAO {
values.put(Sqlite.COL_HEADER_STATIC, account.getHeader_static());
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
values.put(Sqlite.COL_INSTANCE, account.getInstance());
if (account.getClient_id() != null && account.getClient_secret() != null && account.getRefresh_token() != null) {
if (account.getClient_id() != null && account.getClient_secret() != null) {
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
}
if (account.getRefresh_token() != null) {
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
}
if (account.getToken() != null)
@ -114,9 +116,11 @@ public class AccountDAO {
values.put(Sqlite.COL_HEADER, account.getHeader());
values.put(Sqlite.COL_HEADER_STATIC, account.getHeader_static());
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
if (account.getClient_id() != null && account.getClient_secret() != null && account.getRefresh_token() != null) {
if (account.getClient_id() != null && account.getClient_secret() != null) {
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
}
if (account.getRefresh_token() != null) {
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
}
if (account.getToken() != null)
@ -153,9 +157,11 @@ public class AccountDAO {
values.put(Sqlite.COL_HEADER_STATIC, account.getHeader_static());
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
if (account.getClient_id() != null && account.getClient_secret() != null && account.getRefresh_token() != null) {
if (account.getClient_id() != null && account.getClient_secret() != null) {
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
}
if (account.getRefresh_token() != null) {
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
}
if (account.getToken() != null)

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z" />
</vector>

View File

@ -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="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z" />
</vector>

View File

@ -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="M15.73,3L8.27,3L3,8.27v7.46L8.27,21h7.46L21,15.73L21,8.27L15.73,3zM12,17.3c-0.72,0 -1.3,-0.58 -1.3,-1.3 0,-0.72 0.58,-1.3 1.3,-1.3 0.72,0 1.3,0.58 1.3,1.3 0,0.72 -0.58,1.3 -1.3,1.3zM13,13h-2L11,7h2v6z" />
</vector>

View File

@ -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="M13.05,9.79L10,7.5v9l3.05,-2.29L16,12zM13.05,9.79L10,7.5v9l3.05,-2.29L16,12zM13.05,9.79L10,7.5v9l3.05,-2.29L16,12zM11,4.07L11,2.05c-2.01,0.2 -3.84,1 -5.32,2.21L7.1,5.69c1.11,-0.86 2.44,-1.44 3.9,-1.62zM5.69,7.1L4.26,5.68C3.05,7.16 2.25,8.99 2.05,11h2.02c0.18,-1.46 0.76,-2.79 1.62,-3.9zM4.07,13L2.05,13c0.2,2.01 1,3.84 2.21,5.32l1.43,-1.43c-0.86,-1.1 -1.44,-2.43 -1.62,-3.89zM5.68,19.74C7.16,20.95 9,21.75 11,21.95v-2.02c-1.46,-0.18 -2.79,-0.76 -3.9,-1.62l-1.42,1.43zM22,12c0,5.16 -3.92,9.42 -8.95,9.95v-2.02C16.97,19.41 20,16.05 20,12s-3.03,-7.41 -6.95,-7.93L13.05,2.05C18.08,2.58 22,6.84 22,12z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="@android:color/white"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M7,9v6h4l5,5V4l-5,5H7z" />
</vector>

View File

@ -4,50 +4,58 @@
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,10m-3,0a3,3 0,1 1,6 0a3,3 0,1 1,-6 0"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="evenOdd"
android:strokeColor="#00000000"/>
<path
android:pathData="M16.3851,13.8501C17.4222,12.6992 18,11.4167 18,10C18,6.7409 15.2591,4 12,4C8.7409,4 6,6.7409 6,10C6,11.4186 6.5792,12.7028 7.6184,13.854C7.8034,14.059 8.1196,14.0752 8.3246,13.8902C8.5295,13.7051 8.5457,13.389 8.3607,13.184C7.4762,12.2041 7,11.1483 7,10C7,7.2932 9.2932,5 12,5C14.7068,5 17,7.2932 17,10C17,11.1467 16.525,12.201 15.6422,13.1807C15.4574,13.3859 15.4738,13.702 15.679,13.8869C15.8841,14.0717 16.2003,14.0553 16.3851,13.8501Z"
android:strokeWidth="1"
android:fillType="nonZero"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:startY="4"
android:startX="12"
android:endY="13.806534"
android:endX="12"
android:type="linear">
<item android:offset="0" android:color="#FF000000"/>
<item android:offset="1" android:color="#3F000000"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M17.5678,18.3077C20.316,16.4626 22,13.3733 22,10C22,4.4772 17.5228,0 12,0C6.4772,0 2,4.4772 2,10C2,13.3762 3.687,16.4679 6.439,18.3123C6.8978,18.6198 7.519,18.4971 7.8264,18.0383C8.1339,17.5796 8.0113,16.9584 7.5525,16.6509C5.3488,15.174 4,12.7021 4,10C4,5.5817 7.5817,2 12,2C16.4183,2 20,5.5817 20,10C20,12.6998 18.6536,15.1698 16.453,16.6472C15.9945,16.9551 15.8723,17.5764 16.1802,18.0349C16.488,18.4934 17.1093,18.6156 17.5678,18.3077Z"
android:strokeWidth="1"
android:fillType="nonZero"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:startY="0"
android:startX="12"
android:endY="18.221992"
android:endX="12"
android:type="linear">
<item android:offset="0" android:color="#FF000000"/>
<item android:offset="1" android:color="#3F000000"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M9.3292,15.9751C9.1474,14.8843 9.8983,14 10.9979,14L13.0021,14C14.1055,14 14.8534,14.8793 14.6708,15.9751L13.6634,22.0197C13.5731,22.5611 13.0573,23 12.501,23L11.499,23C10.9472,23 10.4277,22.5659 10.3366,22.0197L9.3292,15.9751Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="evenOdd"
android:strokeColor="#00000000"/>
<path
android:fillColor="#000000"
android:fillType="evenOdd"
android:pathData="M12,10m-3,0a3,3 0,1 1,6 0a3,3 0,1 1,-6 0"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillType="nonZero"
android:pathData="M16.3851,13.8501C17.4222,12.6992 18,11.4167 18,10C18,6.7409 15.2591,4 12,4C8.7409,4 6,6.7409 6,10C6,11.4186 6.5792,12.7028 7.6184,13.854C7.8034,14.059 8.1196,14.0752 8.3246,13.8902C8.5295,13.7051 8.5457,13.389 8.3607,13.184C7.4762,12.2041 7,11.1483 7,10C7,7.2932 9.2932,5 12,5C14.7068,5 17,7.2932 17,10C17,11.1467 16.525,12.201 15.6422,13.1807C15.4574,13.3859 15.4738,13.702 15.679,13.8869C15.8841,14.0717 16.2003,14.0553 16.3851,13.8501Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="12"
android:endY="13.806534"
android:startX="12"
android:startY="4"
android:type="linear">
<item
android:color="#FF000000"
android:offset="0" />
<item
android:color="#3F000000"
android:offset="1" />
</gradient>
</aapt:attr>
</path>
<path
android:fillType="nonZero"
android:pathData="M17.5678,18.3077C20.316,16.4626 22,13.3733 22,10C22,4.4772 17.5228,0 12,0C6.4772,0 2,4.4772 2,10C2,13.3762 3.687,16.4679 6.439,18.3123C6.8978,18.6198 7.519,18.4971 7.8264,18.0383C8.1339,17.5796 8.0113,16.9584 7.5525,16.6509C5.3488,15.174 4,12.7021 4,10C4,5.5817 7.5817,2 12,2C16.4183,2 20,5.5817 20,10C20,12.6998 18.6536,15.1698 16.453,16.6472C15.9945,16.9551 15.8723,17.5764 16.1802,18.0349C16.488,18.4934 17.1093,18.6156 17.5678,18.3077Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="12"
android:endY="18.221992"
android:startX="12"
android:startY="0"
android:type="linear">
<item
android:color="#FF000000"
android:offset="0" />
<item
android:color="#3F000000"
android:offset="1" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#000000"
android:fillType="evenOdd"
android:pathData="M9.3292,15.9751C9.1474,14.8843 9.8983,14 10.9979,14L13.0021,14C14.1055,14 14.8534,14.8793 14.6708,15.9751L13.6634,22.0197C13.5731,22.5611 13.0573,23 12.501,23L11.499,23C10.9472,23 10.4277,22.5659 10.3366,22.0197L9.3292,15.9751Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

View File

@ -0,0 +1,165 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2020 Thomas Schneider
This file is a part of TubeLab
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 3 of the
License, or (at your option) any later version.
TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".AccountActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/instance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<ImageView
android:id="@+id/profile_picture"
android:layout_width="60dp"
android:layout_height="60dp"
android:contentDescription="@string/profile_picture"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/displayname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintRight_toLeftOf="@+id/button_container"
app:layout_constraintStart_toEndOf="@+id/profile_picture"
app:layout_constraintTop_toTopOf="@+id/profile_picture" />
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/button_container"
app:layout_constraintStart_toEndOf="@+id/profile_picture"
app:layout_constraintTop_toTopOf="@+id/displayname" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/button_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/logout_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/action_logout"
android:textAllCaps="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/settings"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/settings"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logout_button" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/account_tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabSelectedTextColor="?colorAccent"
app:tabTextColor="@android:color/white" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/account_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin_button"
android:src="@drawable/ic_baseline_add_24"
android:tint="@android:color/white"
android:visibility="gone" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -52,9 +52,7 @@
android:gravity="center"
android:padding="10dp"
android:text="@string/action_playlist_add"
android:textSize="25sp"
android:textStyle="italic|bold"
android:typeface="serif" />
android:textSize="25sp" />
</RelativeLayout>
<!-- Main Loader -->
<RelativeLayout

View File

@ -14,291 +14,122 @@
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/not_connected"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/step_instance"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/main_logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:contentDescription="@string/app_logo"
android:src="@drawable/ic_launcher_foreground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/create_an_account_peertube"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:drawablePadding="10dp"
android:gravity="center"
android:text="@string/join_peertube"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/main_logo" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
android:paddingStart="50dp"
android:paddingEnd="50dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/step_instance"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/instance_chosen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:textColor="?colorAccent"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/main_logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:contentDescription="@string/app_logo"
android:src="@drawable/ic_launcher_foreground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_uid_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/instance_chosen">
<TextView
android:id="@+id/create_an_account_peertube"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:drawablePadding="10dp"
android:gravity="center"
android:text="@string/join_peertube"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/main_logo" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="50dp"
android:paddingEnd="50dp">
<TextView
android:id="@+id/instance_chosen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:textColor="?colorAccent"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_uid_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/instance_chosen">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/login_uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email_address"
android:inputType="textEmailAddress"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_passwd_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/login_uid_container"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/login_passwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:inputType="textPassword"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/login_button"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:drawablePadding="10dp"
android:gravity="center"
android:paddingStart="15dp"
android:paddingTop="12dp"
android:paddingEnd="20dp"
android:paddingBottom="12dp"
android:singleLine="true"
android:text="@string/login"
android:textAllCaps="false"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/login_passwd_container" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/connected"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="50dp"
android:paddingEnd="50dp">
<TextView
android:id="@+id/instance"
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/login_uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:hint="@string/email_address"
android:inputType="textEmailAddress"
android:singleLine="true" />
<androidx.cardview.widget.CardView
android:id="@+id/cardview_profile"
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_passwd_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/login_uid_container"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/login_passwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:src="@drawable/ic_launcher_foreground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/instance">
android:hint="@string/password"
android:inputType="textPassword"
android:singleLine="true" />
<androidx.constraintlayout.widget.ConstraintLayout
</com.google.android.material.textfield.TextInputLayout>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<Button
android:id="@+id/login_button"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:drawablePadding="10dp"
android:gravity="center"
android:paddingStart="15dp"
android:paddingTop="12dp"
android:paddingEnd="20dp"
android:paddingBottom="12dp"
android:singleLine="true"
android:text="@string/login"
android:textAllCaps="false"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/login_passwd_container" />
<ImageView
android:id="@+id/profile_picture"
android:layout_width="60dp"
android:layout_height="60dp"
android:contentDescription="@string/profile_picture"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/displayname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:textSize="18sp"
app:layout_constraintStart_toEndOf="@+id/profile_picture"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="@+id/profile_picture"
app:layout_constraintTop_toTopOf="@+id/displayname" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<Button
android:id="@+id/logout_button"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:drawablePadding="10dp"
android:gravity="center"
android:paddingStart="15dp"
android:paddingTop="12dp"
android:paddingEnd="20dp"
android:paddingBottom="12dp"
android:singleLine="true"
android:text="@string/action_logout"
android:textAllCaps="false"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cardview_profile" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/logout_button">
<!-- Listview Notifications -->
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv_notifications"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<RelativeLayout
android:id="@+id/no_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="@string/no_notifications"
android:textSize="25sp"
android:textStyle="italic|bold"
android:typeface="serif" />
</RelativeLayout>
<!-- Main Loader -->
<RelativeLayout
android:id="@+id/loader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
<!-- Loader for next notifications -->
<RelativeLayout
android:id="@+id/loading_next_notifications"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|center_horizontal"
android:gravity="bottom|center_horizontal"
android:visibility="gone">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminate="true" />
</RelativeLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

View File

@ -29,8 +29,7 @@
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
app:layout_constraintRight_toRightOf="parent" />
<fragment
android:id="@+id/nav_host_fragment"

View File

@ -77,9 +77,9 @@
<ScrollView
android:id="@+id/peertube_information_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="@dimen/video_comment_margin"
android:layout_marginEnd="@dimen/video_comment_margin"
android:layout_height="0dp"
android:layout_weight="2">
<LinearLayout
@ -112,10 +112,10 @@
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:drawableTop="@drawable/ic_baseline_visibility_24"
android:drawablePadding="5dp"
android:gravity="center_horizontal"
android:text="0"
app:drawableTopCompat="@drawable/ic_baseline_visibility_24"
tools:ignore="HardcodedText" />
<TextView
@ -127,10 +127,10 @@
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:drawableTop="@drawable/ic_baseline_thumb_up_alt_24"
android:drawablePadding="5dp"
android:gravity="center_horizontal"
android:text="0"
app:drawableTopCompat="@drawable/ic_baseline_thumb_up_alt_24"
tools:ignore="HardcodedText" />
<TextView
@ -142,10 +142,10 @@
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:drawableTop="@drawable/ic_baseline_thumb_down_alt_24"
android:drawablePadding="5dp"
android:gravity="center_horizontal"
android:text="0"
app:drawableTopCompat="@drawable/ic_baseline_thumb_down_alt_24"
tools:ignore="HardcodedText" />
<TextView
@ -157,10 +157,10 @@
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:drawableTop="@drawable/ic_baseline_bookmark_border_24"
android:drawablePadding="5dp"
android:gravity="center_horizontal"
android:text="" />
android:text=""
app:drawableTopCompat="@drawable/ic_baseline_bookmark_border_24" />
<TextView
android:id="@+id/peertube_playlist"
@ -171,11 +171,11 @@
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:drawableTop="@drawable/ic_baseline_list_24"
android:drawablePadding="5dp"
android:gravity="center_horizontal"
android:text=""
android:visibility="gone" />
android:visibility="gone"
app:drawableTopCompat="@drawable/ic_baseline_list_24" />
<LinearLayout
android:layout_width="0dp"
@ -192,11 +192,11 @@
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:drawableTop="@drawable/ic_baseline_share_24"
android:drawablePadding="5dp"
android:gravity="center_horizontal"
android:text="@string/share"
android:textSize="12sp" />
android:textSize="12sp"
app:drawableTopCompat="@drawable/ic_baseline_share_24" />
<TextView
android:id="@+id/peertube_download"
@ -207,11 +207,11 @@
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:drawableTop="@drawable/ic_baseline_cloud_upload_24"
android:drawablePadding="5dp"
android:gravity="center_horizontal"
android:text="@string/download"
android:textSize="12sp" />
android:textSize="12sp"
app:drawableTopCompat="@drawable/ic_baseline_cloud_upload_24" />
</LinearLayout>
<TextView
@ -226,9 +226,9 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:visibility="gone"
android:baselineAligned="false">
android:visibility="gone">
<LinearLayout
android:layout_width="wrap_content"
@ -274,13 +274,13 @@
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="@string/add_public_comment"
android:importantForAutofill="no"
android:inputType="textMultiLine"
android:maxLines="4"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:visibility="gone"
android:importantForAutofill="no" />
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
@ -304,9 +304,7 @@
android:gravity="center"
android:padding="10dp"
android:text="@string/no_comments"
android:textSize="25sp"
android:textStyle="italic|bold"
android:typeface="serif" />
android:textSize="25sp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>

View File

@ -45,6 +45,36 @@
android:inputType="text" />
</LinearLayout>
<!-- Video media -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/p_video_preview"
android:text="@string/preview" />
<ImageView
android:id="@+id/p_video_preview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="@string/preview"
android:scaleType="centerCrop" />
<Button
android:id="@+id/set_preview"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:gravity="center"
android:text="@string/change_preview" />
</LinearLayout>
<!-- Video tags -->
<LinearLayout
android:layout_width="match_parent"

View File

@ -56,9 +56,7 @@
android:gravity="center"
android:padding="10dp"
android:text="@string/action_playlist_empty_content"
android:textSize="25sp"
android:textStyle="italic|bold"
android:typeface="serif" />
android:textSize="25sp" />
</RelativeLayout>
<!-- Main Loader -->
<RelativeLayout

View File

@ -26,15 +26,17 @@
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
android:fitsSystemWindows="true"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll">
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
@ -43,37 +45,11 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/top_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/action_back"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:contentDescription="@string/go_back"
android:src="@drawable/ic_baseline_arrow_back_24"
android:tint="@android:color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/banner_pp"
android:layout_width="match_parent"
android:layout_height="@dimen/layout_height_header"
android:contentDescription="@string/profile_banner"
android:scaleType="centerCrop"
android:src="@drawable/default_banner"
app:layout_collapseMode="parallax"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<ImageView
android:id="@+id/account_pp"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="10dp"
@ -81,77 +57,61 @@
android:background="@drawable/account_pp_border"
android:contentDescription="@string/profile_picture"
android:padding="2dp"
app:layout_constraintTop_toBottomOf="@+id/action_back"
app:layout_constraintStart_toStartOf="parent"
app:layout_scrollFlags="scroll" />
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
<TextView
android:id="@+id/account_dn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:padding="2dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="10dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/subscriber_count"
app:layout_constraintStart_toEndOf="@+id/account_pp"
app:layout_constraintTop_toBottomOf="@+id/action_back">
app:layout_constraintTop_toTopOf="@+id/account_pp" />
<LinearLayout
android:layout_marginStart="10dp"
android:id="@+id/names_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/account_dn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@android:color/white"
android:textSize="18sp" />
<TextView
android:id="@+id/account_un"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<ImageButton
android:id="@+id/account_follow"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:contentDescription="@string/make_an_action"
android:scaleType="fitCenter"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/names_container" />
<ImageButton
android:id="@+id/header_edit_profile"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:contentDescription="@string/edit_profile"
android:scaleType="fitCenter"
android:src="@drawable/ic_baseline_edit_24"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/names_container" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/subscriber_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@android:color/white"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@id/account_follow"
app:layout_constraintStart_toEndOf="@+id/account_pp"
app:layout_constraintTop_toBottomOf="@id/account_dn" />
<Button
android:id="@+id/account_follow"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:contentDescription="@string/make_an_action"
android:scaleType="fitCenter"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/subscriber_count"
app:layout_constraintTop_toBottomOf="@id/account_dn" />
<Button
android:id="@+id/header_edit_profile"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:contentDescription="@string/edit_profile"
android:scaleType="fitCenter"
android:src="@drawable/ic_baseline_edit_24"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/subscriber_count"
app:layout_constraintTop_toBottomOf="@id/account_dn" />
</androidx.constraintlayout.widget.ConstraintLayout>
@ -176,89 +136,12 @@
android:textColor="@android:color/white"
android:textIsSelectable="true"
android:visibility="gone" />
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/account_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_marginEnd="3dp"
android:background="@drawable/colored_border"
android:singleLine="true"
android:textColor="?colorAccent"
android:visibility="gone" />
<TextView
android:id="@+id/account_followed_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_marginEnd="3dp"
android:background="@drawable/colored_border"
android:singleLine="true"
android:text="@string/followed_by"
android:textColor="?colorAccent"
android:visibility="gone" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</RelativeLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:theme="@style/ThemeOverlay.AppCompat.Light">
<LinearLayout
android:id="@+id/toolbar_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animationCache="true"
android:orientation="horizontal"
android:visibility="gone"
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@+id/pp_actionBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="10dp"
android:contentDescription="@string/profile_picture"
android:gravity="center_vertical" />
<TextView
android:id="@+id/show_account_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.tabs.TabLayout
android:id="@+id/account_tabLayout"
@ -274,6 +157,7 @@
android:id="@+id/account_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2020 Thomas Schneider
This file is a part of TubeLab
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 3 of the
License, or (at your option) any later version.
TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:labelFor="@+id/display_name"
android:text="@string/display_name" />
<EditText
android:id="@+id/display_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:importantForAutofill="no"
android:inputType="text"
android:singleLine="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:labelFor="@+id/name"
android:text="@string/name" />
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:importantForAutofill="no"
android:inputType="text"
android:singleLine="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:labelFor="@+id/description"
android:text="@string/description" />
<EditText
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:importantForAutofill="no"
android:inputType="text"
android:maxLines="5" />
</LinearLayout>
</ScrollView>

View File

@ -148,25 +148,17 @@
</LinearLayout>
<LinearLayout
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/account_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/account_follow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:contentDescription="@string/action_follow"
android:gravity="center"
android:scaleType="fitXY"
android:visibility="gone"
app:backgroundTint="?colorAccent"
app:fabSize="mini" />
</LinearLayout>
android:layout_margin="5dp"
android:contentDescription="@string/action_follow"
android:gravity="center"
android:scaleType="fitXY"
android:visibility="gone"
app:backgroundTint="?colorAccent"
app:fabSize="mini" />
</LinearLayout>

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2020 Thomas Schneider
This file is a part of TubeLab
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 3 of the
License, or (at your option) any later version.
TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<ImageView
android:id="@+id/account_pp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/profile_picture"
android:padding="2dp"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/account_dn"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:gravity="center"
android:padding="2dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?colorAccent"
android:textSize="14sp" />
</LinearLayout>

View File

@ -19,8 +19,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="?android:dividerHorizontal"
android:orientation="vertical"
android:gravity="bottom"
android:orientation="vertical"
android:showDividers="end">
<TextView
@ -84,7 +84,9 @@
android:id="@+id/peertube_account_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:singleLine="true" />
<LinearLayout
android:layout_width="match_parent"

View File

@ -14,25 +14,75 @@
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search_container"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/playlist_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="?android:dividerHorizontal"
android:orientation="vertical"
android:paddingTop="5dp"
android:showDividers="end">
<TextView
android:id="@+id/search_keyword"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
android:layout_marginBottom="5dp">
<ImageView
android:id="@+id/preview_playlist"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:contentDescription="@string/preview"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/preview_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/preview_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/playlist_more"
app:layout_constraintStart_toEndOf="@+id/preview_playlist"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/preview_visibility"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/preview_title"
app:layout_constraintTop_toBottomOf="@+id/preview_title" />
<TextView
android:id="@+id/preview_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/playlist_more"
app:layout_constraintStart_toStartOf="@+id/preview_title"
app:layout_constraintTop_toBottomOf="@+id/preview_visibility" />
<ImageButton
android:id="@+id/playlist_more"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/display_more"
android:src="@drawable/ic_baseline_more_vert_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

View File

@ -39,9 +39,7 @@
android:gravity="center"
android:padding="10dp"
android:text="@string/bookmark_peertube_empty"
android:textSize="25sp"
android:textStyle="italic|bold"
android:typeface="serif" />
android:textSize="25sp" />
</RelativeLayout>
<!-- Main Loader -->
<RelativeLayout

View File

@ -41,9 +41,7 @@
android:gravity="center"
android:padding="10dp"
android:text="@string/action_playlist_add"
android:textSize="25sp"
android:textStyle="italic|bold"
android:typeface="serif" />
android:textSize="25sp" />
</RelativeLayout>
<!-- Main Loader -->
<RelativeLayout

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2020 Thomas Schneider
This file is a part of TubeLab
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 3 of the
License, or (at your option) any later version.
TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/fab_margin"
android:paddingRight="@dimen/fab_margin">
<!-- Listview Accounts -->
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv_elements"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:scrollbars="none" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<RelativeLayout
android:id="@+id/no_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<TextView
android:id="@+id/no_action_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:padding="10dp"
android:text="@string/no_channels"
android:textSize="25sp" />
</RelativeLayout>
<!-- Main Loader -->
<RelativeLayout
android:id="@+id/loader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
<!-- Loader for next accounts -->
<RelativeLayout
android:id="@+id/loading_next"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|center_horizontal"
android:gravity="bottom|center_horizontal"
android:visibility="gone">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminate="true" />
</RelativeLayout>
</RelativeLayout>

View File

@ -14,19 +14,53 @@
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:fillViewport="true">
<RelativeLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:animateLayoutChanges="true"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/top_account_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent">
<!-- Scrollview for displaying accounts in bubbles -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv_accounts"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/display_all"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/display_all"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/all"
app:layout_constraintBottom_toBottomOf="@+id/lv_accounts"
app:layout_constraintLeft_toRightOf="@+id/lv_accounts"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="0dp"
android:layout_alignTop="@+id/top_account_container"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_account_container">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer"
@ -36,7 +70,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:scrollbars="none" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout>
@ -45,7 +79,8 @@
android:id="@+id/no_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/no_action_text"
@ -55,9 +90,7 @@
android:gravity="center"
android:padding="10dp"
android:text="@string/no_videos"
android:textSize="25sp"
android:textStyle="italic|bold"
android:typeface="serif" />
android:textSize="25sp" />
</RelativeLayout>
<!-- Main Loader -->
<RelativeLayout
@ -80,12 +113,13 @@
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|center_horizontal"
android:gravity="bottom|center_horizontal"
android:visibility="gone">
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminate="true" />
</RelativeLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/popup_padding">
<EditText
android:id="@+id/report_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/report_helper"
android:importantForAutofill="no"
android:inputType="textCapSentences|textMultiLine|textAutoCorrect"
android:minLines="3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/popup_padding">
<Button
android:id="@+id/report_video"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/report_video"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/report_account"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/report_account"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/report_video" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_discover"
android:icon="@drawable/ic_baseline_public_24"
android:title="@string/title_discover" />
<item
android:id="@+id/navigation_subscription"
android:icon="@drawable/ic_subscription"
android:title="@string/subscriptions" />
<item
android:id="@+id/navigation_trending"
android:icon="@drawable/ic_baseline_trending_up_24"
android:title="@string/title_trending" />
<item
android:id="@+id/navigation_most_liked"
android:icon="@drawable/ic_baseline_thumb_up_24"
android:title="@string/title_most_liked" />
<item
android:id="@+id/navigation_recently_added"
android:icon="@drawable/ic_baseline_add_circle_outline_24"
android:title="@string/title_recently_added" />
</menu>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_mute"
android:icon="@drawable/ic_baseline_volume_mute_24"
android:title="@string/action_mute"
app:showAsAction="never" />
<item
android:id="@+id/action_report"
android:icon="@drawable/ic_baseline_report_24"
android:title="@string/report"
app:showAsAction="never" />
</menu>

View File

@ -36,8 +36,8 @@
android:title="@string/my_videos"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_subscription"
android:icon="@drawable/ic_subscription"
android:title="@string/subscriptions"
android:id="@+id/action_history"
android:icon="@drawable/ic_baseline_history_24"
android:title="@string/my_history"
app:showAsAction="ifRoom" />
</menu>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_report"
android:icon="@drawable/ic_baseline_report_24"
android:title="@string/report"
app:showAsAction="ifRoom" />
</menu>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_delete"
android:icon="@drawable/ic_baseline_delete_24"
android:title="@string/delete"
app:showAsAction="ifRoom" />
<!--
<item
android:id="@+id/action_edit"
android:icon="@drawable/ic_baseline_edit_24"
android:title="@string/edit"
app:showAsAction="ifRoom" />
-->
</menu>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation"
app:startDestination="@id/navigation_discover">
<fragment
android:id="@+id/navigation_discover"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/title_discover"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="POVERVIEW"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
<fragment
android:id="@+id/navigation_subscription"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/subscriptions"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="PSUBSCRIPTIONS"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
<fragment
android:id="@+id/navigation_trending"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/title_trending"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="PTRENDING"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
<fragment
android:id="@+id/navigation_most_liked"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/title_most_liked"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="PMOSTLIKED"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
<fragment
android:id="@+id/navigation_recently_added"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/title_recently_added"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="PRECENTLYADDED"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
</navigation>

View File

@ -2,4 +2,5 @@
<resources>
<bool name="is_tablet">true</bool>
<dimen name="video_comment_margin">150dp</dimen>
<dimen name="margin_account">100dp</dimen>
</resources>

View File

@ -3,10 +3,13 @@
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">5dp</dimen>
<dimen name="fab_margin_button">16dp</dimen>
<dimen name="drawer_padding">2dp</dimen>
<dimen name="layout_height_header">100dp</dimen>
<dimen name="fab_margin_floating">16dp</dimen>
<dimen name="video_padding">0dp</dimen>
<bool name="is_tablet">false</bool>
<dimen name="video_comment_margin">0dp</dimen>
<dimen name="popup_padding">20dp</dimen>
<dimen name="margin_account">10dp</dimen>
</resources>

View File

@ -108,10 +108,11 @@
<string name="no_channels">Aucune chaîne !</string>
<string name="following">Suit</string>
<string name="followers">Abonné·e·s</string>
<string name="followers_count">%1$s Abonné·e·s</string>
<string name="nothing_to_do">Aucune action ne peut être réalisée</string>
<string name="unfollow_confirm">Voulez-vous vous désabonner de ce compte ?</string>
<string name="action_unfollow">Se désabonner</string>
<string name="action_follow">Suivre</string>
<string name="action_follow">S\'abonner</string>
<string name="search">Chercher</string>
<string name="toast_error_search">Une erreur sest produite lors de la recherche!</string>
<string name="no_result">Aucun résultat !</string>
@ -146,11 +147,14 @@
<string name="logout_account_confirmation">Voulez-vous vraiment déconnecter le compte @%1$s ?</string>
<string name="action_lists_delete">Supprimer la liste de lecture</string>
<string name="action_channel_delete">Supprimer la chaîne</string>
<string name="action_lists_confirm_delete">Êtes-vous sûr de vouloir supprimer définitivement cette liste de lecture ?</string>
<string name="action_channel_confirm_delete">Êtes-vous sûr de vouloir supprimer définitivement cette chaîne ?</string>
<string name="action_playlist_create">Créer une liste de lecture</string>
<string name="display_name">Nom d\'affichage</string>
<string name="error_channel_mandatory">Un canal est requis lorsque la liste de lecture est publique.</string>
<string name="error_display_name">Vous devez fournir un nom d\'affichage !</string>
<string name="error_display_name_channel">Vous devez fournir un nom d\'affichage et un nom pour la chaîne!</string>
<string name="action_playlist_empty_content">Cette liste de lecture est vide.</string>
<string name="playlists">Listes de lecture</string>
<string name="no_notifications">Aucune notification à afficher</string>
@ -167,4 +171,41 @@
<string name="peertube_video_unblacklist"><![CDATA[Votre vidéo <b>%1$s</b> nest plus blacklisté]]></string>
<string name="toast_code_error">Une erreur sest produite! Linstance na retourné aucun code d\autorisation!</string>
<string name="subscriptions">Abonnements</string>
<string name="report">Signaler</string>
<string name="report_video">Signaler la vidéo</string>
<string name="report_account">Signaler le compte</string>
<string name="report_helper">Quelques explications concernant votre signalement…</string>
<string name="successful_report">Le compte a été signalé !</string>
<string name="successful_video_report">La vidéo a été signalée !</string>
<string name="report_comment_size">Veuillez préciser les raisons.</string>
<string name="all">Tout</string>
<string name="my_history">Historique</string>
<string name="edit_video">Modifier une vidéo</string>
<string name="settings">Paramètres</string>
<string-array name="settings_video_mode">
<item>Normal</item>
<item>Streaming</item>
<item>Navigateur</item>
</string-array>
<string name="set_video_mode_choice" translatable="false">set_video_mode_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>
<string name="change_preview">Modifier l\'aperçu</string>
<string name="title_muted">Sourdine</string>
<string name="title_blocked">Bloqués</string>
<string name="no_muted">Aucun compte en sourdine !</string>
<string name="action_mute">Mettre en sourdine</string>
<string name="action_unmute">Réactiver le compte</string>
<string name="muted_done">Le compte a été mis en sourdine !</string>
<string name="title_channel">Chaînes</string>
<string name="name">Nom</string>
<string name="action_channel_create">Créer une chaîne</string>
<string name="delete_channel">Supprimer la chaîne</string>
<string name="display_list">Afficher la liste</string>
<string name="delete_list">Supprimer la liste de lecture</string>
<string name="edit">Modifier</string>
</resources>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:key="app_prefs">
<androidx.preference.ListPreference
android:icon="@drawable/ic_baseline_slow_motion_video_24"
android:key="@string/set_video_mode_choice"
android:summary="@string/set_video_mode_description"
android:title="@string/set_video_mode" />
</androidx.preference.PreferenceScreen>

View File

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
classpath 'com.android.tools.build:gradle:4.0.1'
def nav_version = "2.3.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// NOTE: Do not place your application dependencies here; they belong
@ -22,5 +22,4 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}
}

View File

@ -0,0 +1,9 @@
Nouveautés :
- Modifier la vignette des vidéos
- Mettre des comptes en sourdine
- Refonte de la présentation des chaînes et des listes de lecture
- Refonte de laffichage du compte
- Historique des vidéos regardées
- Possibilité de changer le mode pour les vidéos
- Possibilité de créer/supprimer une chaîne.
- Abonnements affichés dans des vignettes avec possibilité de filtrer les vidéos.

View File

@ -12,10 +12,14 @@ Si vous connectez votre compte, vous pourrez interagir avec les vidéos :
- Écrire/supprimer un commentaire,
- Ajouter/supprimer des vidéos dans les listes de lecture,
- Gérer les listes de lecture,
- Créer/Supprimer des listes de lecture,
- Suivre une chaîne,
- Thumbs-up/down,
- Téléverser des vidéos,
- Modifier vos vidéos,
- Supprimer vos vidéos,
- Voir vos notifications.
- Voir vos notifications,
- Créer/supprimer une chaîne,
- Mettre des comptes en sourdine,
- Signaler des vidéos ou des comptes,
- Voir l'historique.

View File

@ -0,0 +1,2 @@
- Signaler les vidéos ou les comptes
- Corrige un problème avec l'expiration du token

View File

@ -0,0 +1 @@
- Filter searches