mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-06-05 21:09:11 +02:00
Compare commits
55 Commits
Author | SHA1 | Date | |
---|---|---|---|
31e87a18bb | |||
07546abb7e | |||
124e0d8505 | |||
94b969c428 | |||
cb9f8605d5 | |||
5660fb15e5 | |||
d02fdba671 | |||
d8de74ce7a | |||
2129727cc5 | |||
119ad4884b | |||
3617fb3229 | |||
b272a5b5f9 | |||
58404694e0 | |||
c4c745dbc0 | |||
2f909d5ffa | |||
c714e6a625 | |||
bb2c129762 | |||
42b0574143 | |||
df0b18f535 | |||
e8427b883d | |||
4027a8b725 | |||
a1b816030a | |||
8c7d1c692b | |||
7588a48cb5 | |||
014302c3a8 | |||
f632aa4712 | |||
81de1c1aa0 | |||
d89c998a35 | |||
4c83a14786 | |||
43e6d0baeb | |||
f7eb17fd94 | |||
27990d56e9 | |||
6d56c7f803 | |||
a680046574 | |||
445cc85091 | |||
06797160a0 | |||
b146ca064f | |||
f139d02c2c | |||
0fcad881bf | |||
9eacccf504 | |||
1334419ed9 | |||
19779c2cf6 | |||
f6ca2e8265 | |||
14faca9b35 | |||
c782fd14ae | |||
c82e9e2ad2 | |||
38e9d9f090 | |||
6d66b2f08b | |||
4c51a7c7e8 | |||
2636b86e3e | |||
0950bbb415 | |||
ae458f98fa | |||
b16803b5ed | |||
dc9dc14fd5 | |||
1f61e7f613 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
/app/release/
|
||||
|
73
.gitlab-ci.yml
Normal file
73
.gitlab-ci.yml
Normal file
@ -0,0 +1,73 @@
|
||||
# This file is a template, and might need editing before it works on your project.
|
||||
# Read more about this script on this blog post https://about.gitlab.com/2018/10/24/setting-up-gitlab-ci-for-android-projects/, by Jason Lenny
|
||||
# If you are interested in using Android with FastLane for publishing take a look at the Android-Fastlane template.
|
||||
|
||||
image: openjdk:8-jdk
|
||||
|
||||
variables:
|
||||
|
||||
# ANDROID_COMPILE_SDK is the version of Android you're compiling with.
|
||||
# It should match compileSdkVersion.
|
||||
ANDROID_COMPILE_SDK: "30"
|
||||
|
||||
# ANDROID_BUILD_TOOLS is the version of the Android build tools you are using.
|
||||
# It should match buildToolsVersion.
|
||||
ANDROID_BUILD_TOOLS: "30.0.2"
|
||||
|
||||
# It's what version of the command line tools we're going to download from the official site.
|
||||
# Official Site-> https://developer.android.com/studio/index.html
|
||||
# There, look down below at the cli tools only, sdk tools package is of format:
|
||||
# commandlinetools-os_type-ANDROID_SDK_TOOLS_latest.zip
|
||||
# when the script was last modified for latest compileSdkVersion, it was which is written down below
|
||||
ANDROID_SDK_TOOLS: "6609375"
|
||||
|
||||
# Packages installation before running script
|
||||
before_script:
|
||||
- apt-get --quiet update --yes
|
||||
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
|
||||
|
||||
# Setup path as android_home for moving/exporting the downloaded sdk into it
|
||||
- export ANDROID_HOME="${PWD}/android-home"
|
||||
# Create a new directory at specified location
|
||||
- install -d $ANDROID_HOME
|
||||
# Here we are installing androidSDK tools from official source,
|
||||
# (the key thing here is the url from where you are downloading these sdk tool for command line, so please do note this url pattern there and here as well)
|
||||
# after that unzipping those tools and
|
||||
# then running a series of SDK manager commands to install necessary android SDK packages that'll allow the app to build
|
||||
- wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
|
||||
# move to the archive at ANDROID_HOME
|
||||
- pushd $ANDROID_HOME
|
||||
- unzip -d cmdline-tools cmdline-tools.zip
|
||||
- popd
|
||||
- export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/
|
||||
|
||||
# Nothing fancy here, just checking sdkManager version
|
||||
- sdkmanager --version
|
||||
|
||||
# use yes to accept all licenses
|
||||
- yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses || true
|
||||
- sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-${ANDROID_COMPILE_SDK}"
|
||||
- sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"
|
||||
- sdkmanager --sdk_root=${ANDROID_HOME} "build-tools;${ANDROID_BUILD_TOOLS}"
|
||||
|
||||
# Not necessary, but just for surity
|
||||
- chmod +x ./gradlew
|
||||
|
||||
# Basic android and gradle stuff
|
||||
# Check linting
|
||||
lintDebug:
|
||||
interruptible: true
|
||||
stage: build
|
||||
script:
|
||||
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
|
||||
|
||||
# Make Project
|
||||
assembleDebug:
|
||||
interruptible: true
|
||||
stage: build
|
||||
script:
|
||||
- ./gradlew assembleDebug
|
||||
artifacts:
|
||||
paths:
|
||||
- app/build/outputs/
|
||||
|
12
README.md
12
README.md
@ -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)
|
||||
L’application 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)
|
||||
|
@ -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 7
|
||||
versionName "1.0.5"
|
||||
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.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
|
||||
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.3.0'
|
||||
implementation "androidx.fragment:fragment:1.2.5"
|
||||
@ -51,8 +52,8 @@ dependencies {
|
||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||
implementation 'androidx.browser:browser:1.2.0'
|
||||
testImplementation 'junit:junit:4.13'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
|
||||
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
|
||||
implementation 'com.github.GrenderG:Toasty:1.4.2'
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
|
||||
<application
|
||||
android:name=".FedilabTupe"
|
||||
android:name=".FedilabTube"
|
||||
android:allowBackup="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
@ -26,10 +26,10 @@
|
||||
tools:replace="android:allowBackup">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
@ -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>
|
||||
|
256
app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java
Normal file
256
app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java
Normal 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.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;
|
||||
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
|
||||
|
||||
|
||||
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", AccountsVM.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", AccountsVM.accountFetch.CHANNEL);
|
||||
}
|
||||
displayAccountsFragment.setArguments(bundle);
|
||||
return displayAccountsFragment;
|
||||
default:
|
||||
return new DisplayNotificationsFragment();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -15,9 +15,9 @@ 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;
|
||||
@ -26,6 +26,7 @@ import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
@ -35,16 +36,10 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
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;
|
||||
@ -52,34 +47,32 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
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 app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||
|
||||
|
||||
public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylistActionInterface, OnRetrievePeertubeInterface {
|
||||
public class AllPlaylistsActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private AsyncTask<Void, Void, Void> asyncTask;
|
||||
|
||||
PlaylistAdapter playlistAdapter;
|
||||
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;
|
||||
private Playlist playlistToEdit;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -97,134 +90,33 @@ 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;
|
||||
|
||||
PlaylistsVM viewModel = new ViewModelProvider(AllPlaylistsActivity.this).get(PlaylistsVM.class);
|
||||
viewModel.manage(PlaylistsVM.action.GET_PLAYLIST, null, null, null).observe(AllPlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLIST, apiResponse));
|
||||
|
||||
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());
|
||||
if (privaciesInit.size() > 0) {
|
||||
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
|
||||
privacyToSend = new HashMap<>();
|
||||
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
|
||||
|
||||
|
||||
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);
|
||||
dialogBuilder.setView(dialogView);
|
||||
EditText display_name = dialogView.findViewById(R.id.display_name);
|
||||
EditText description = dialogView.findViewById(R.id.description);
|
||||
set_upload_channel = dialogView.findViewById(R.id.set_upload_channel);
|
||||
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
|
||||
|
||||
|
||||
new RetrievePeertubeChannelsAsyncTask(AllPlaylistsActivity.this, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
||||
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
||||
|
||||
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());
|
||||
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(AllPlaylistsActivity.this, 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(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);
|
||||
}
|
||||
playlists = new ArrayList<>();
|
||||
ListView lv_playlist = findViewById(R.id.lv_playlist);
|
||||
playlistAdapter = new PlaylistAdapter(AllPlaylistsActivity.this, playlists, textviewNoAction);
|
||||
lv_playlist.setAdapter(playlistAdapter);
|
||||
|
||||
@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(AllPlaylistsActivity.this, 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 -> {
|
||||
//Hide keyboard
|
||||
InputMethodManager imm = (InputMethodManager) 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();
|
||||
});
|
||||
add_new.setOnClickListener(view -> manageAlert(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (asyncTask != null && !asyncTask.isCancelled()) {
|
||||
asyncTask.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -237,22 +129,16 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
add_new.setEnabled(true);
|
||||
if (apiResponse.getError() != null) {
|
||||
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionType == ManagePlaylistsAsyncTask.action.GET_PLAYLIST) {
|
||||
if (actionType == PlaylistsVM.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);
|
||||
@ -260,19 +146,123 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
||||
}
|
||||
}
|
||||
|
||||
public void manageAlert(Playlist playlistParam) {
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
playlistToEdit = playlistParam;
|
||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(AllPlaylistsActivity.this);
|
||||
LayoutInflater inflater1 = getLayoutInflater();
|
||||
View dialogView = inflater1.inflate(R.layout.add_playlist, new LinearLayout(AllPlaylistsActivity.this), false);
|
||||
dialogBuilder.setView(dialogView);
|
||||
EditText display_name = dialogView.findViewById(R.id.display_name);
|
||||
EditText description = dialogView.findViewById(R.id.description);
|
||||
set_upload_channel = dialogView.findViewById(R.id.set_upload_channel);
|
||||
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
|
||||
|
||||
|
||||
ChannelsVM viewModelC = new ViewModelProvider(AllPlaylistsActivity.this).get(ChannelsVM.class);
|
||||
viewModelC.get().observe(AllPlaylistsActivity.this, this::manageVIewChannels);
|
||||
|
||||
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
||||
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
||||
|
||||
if (playlistToEdit != null) {
|
||||
display_name.setText(playlistToEdit.getDisplayName());
|
||||
description.setText(playlistToEdit.getDescription());
|
||||
}
|
||||
dialogBuilder.setPositiveButton(R.string.validate, null);
|
||||
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||
|
||||
AlertDialog alertDialog = dialogBuilder.create();
|
||||
alertDialog.setOnShowListener(dialogInterface -> {
|
||||
|
||||
Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
button.setOnClickListener(view -> {
|
||||
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) {
|
||||
PlaylistElement playlistElement = new PlaylistElement();
|
||||
playlistElement.setDisplayName(display_name.getText().toString().trim());
|
||||
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
|
||||
playlistElement.setDescription(description.getText().toString().trim());
|
||||
}
|
||||
playlistElement.setVideoChannelId(idChannel);
|
||||
String idPrivacy;
|
||||
String label;
|
||||
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
|
||||
idPrivacy = String.valueOf(privacyM.getKey());
|
||||
label = privacyM.getValue();
|
||||
if ((label.trim().compareTo("Public") == 0 && (playlistElement.getVideoChannelId() == null || playlistElement.getVideoChannelId().trim().compareTo("null") == 0))) {
|
||||
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
if (privacyToSend != null) {
|
||||
playlistElement.setPrivacy(idPrivacy);
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
String playlistId;
|
||||
if (playlistToEdit == null) {
|
||||
playlistId = new PeertubeAPI(AllPlaylistsActivity.this).createPlaylist(playlistElement);
|
||||
} else {
|
||||
playlistId = playlistToEdit.getId();
|
||||
playlistElement.setPlaylistId(playlistId);
|
||||
new PeertubeAPI(AllPlaylistsActivity.this).updatePlaylist(playlistElement);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
Playlist playlist;
|
||||
if (playlistToEdit == null) {
|
||||
playlist = new Playlist();
|
||||
} else {
|
||||
playlist = playlistToEdit;
|
||||
}
|
||||
playlist.setId(playlistId);
|
||||
playlist.setDescription(playlistElement.getDescription());
|
||||
playlist.setDisplayName(playlistElement.getDisplayName());
|
||||
playlist.setVideoChannelId(playlistElement.getVideoChannelId());
|
||||
playlist.setPrivacy(privacyToSend);
|
||||
if (playlistToEdit == null) {
|
||||
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();
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
} else {
|
||||
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_display_name), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (playlistToEdit == null) {
|
||||
alertDialog.setTitle(getString(R.string.action_playlist_create));
|
||||
} else {
|
||||
alertDialog.setTitle(getString(R.string.action_playlist_edit));
|
||||
}
|
||||
alertDialog.setOnDismissListener(dialogInterface -> {
|
||||
//Hide keyboard
|
||||
InputMethodManager imm = (InputMethodManager) 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
||||
public void manageVIewChannels(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
@ -282,26 +272,24 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
||||
}
|
||||
|
||||
//Populate channels
|
||||
List<Account> accounts = apiResponse.getAccounts();
|
||||
String[] channelName = new String[accounts.size() + 1];
|
||||
String[] channelId = new String[accounts.size() + 1];
|
||||
List<Account> channels = apiResponse.getAccounts();
|
||||
String[] channelName = new String[channels.size() + 1];
|
||||
String[] channelId = new String[channels.size() + 1];
|
||||
int i = 1;
|
||||
channelName[0] = "";
|
||||
channelId[0] = "";
|
||||
channels = new HashMap<>();
|
||||
for (Account account : accounts) {
|
||||
channels.put(account.getUsername(), account.getId());
|
||||
channelId[0] = "null";
|
||||
|
||||
for (Account account : channels) {
|
||||
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);
|
||||
|
||||
|
||||
LinkedHashMap<String, String> translations = null;
|
||||
if (peertubeInformation.getTranslations() != null)
|
||||
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
|
||||
@ -329,6 +317,19 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
||||
android.R.layout.simple_spinner_dropdown_item, privaciesA);
|
||||
set_upload_privacy.setAdapter(adapterPrivacies);
|
||||
|
||||
if (playlistToEdit != null) {
|
||||
it = playlistToEdit.getPrivacy().entrySet().iterator();
|
||||
Map.Entry<Integer, String> pair = null;
|
||||
while (it.hasNext()) {
|
||||
pair = it.next();
|
||||
}
|
||||
if (pair != null) {
|
||||
set_upload_privacy.setSelection(pair.getKey() - 1);
|
||||
}
|
||||
} else {
|
||||
set_upload_privacy.setSelection(2);
|
||||
}
|
||||
|
||||
//Manage privacies
|
||||
set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
@ -353,23 +354,23 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (playlistToEdit != null) {
|
||||
it = playlistToEdit.getPrivacy().entrySet().iterator();
|
||||
Map.Entry<Integer, String> pair = null;
|
||||
while (it.hasNext()) {
|
||||
pair = it.next();
|
||||
}
|
||||
if (pair != null) {
|
||||
set_upload_privacy.setSelection(pair.getKey() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
//Manage languages
|
||||
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
|
||||
@ -377,5 +378,18 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (playlistToEdit != null) {
|
||||
int position = 0;
|
||||
int k = 1;
|
||||
for (Account ac : channels) {
|
||||
if (playlistToEdit.getVideoChannelId() != null && ac.getId().compareTo(playlistToEdit.getVideoChannelId()) == 0) {
|
||||
position = k;
|
||||
break;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
set_upload_channel.setSelection(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -16,59 +16,39 @@ 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;
|
||||
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;
|
||||
|
||||
import static app.fedilab.fedilabtube.client.HttpsConnection.updateCredential;
|
||||
|
||||
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 -> {
|
||||
@ -344,9 +219,9 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
|
||||
parameters.put(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
|
||||
parameters.put("grant_type", "password");
|
||||
try {
|
||||
parameters.put("username", URLEncoder.encode(login_uid.getText().toString().trim().toLowerCase(), "UTF-8"));
|
||||
parameters.put("username", URLEncoder.encode(login_uid.getText().toString().trim(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
parameters.put("username", login_uid.getText().toString().trim().toLowerCase());
|
||||
parameters.put("username", login_uid.getText().toString().trim());
|
||||
}
|
||||
try {
|
||||
parameters.put("password", URLEncoder.encode(login_passwd.getText().toString(), "UTF-8"));
|
||||
@ -357,37 +232,41 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
|
||||
String oauthUrl = "/api/v1/users/token";
|
||||
try {
|
||||
String responseLogin = new HttpsConnection(LoginActivity.this).post("https://" + finalInstance + oauthUrl, 30, parameters, null);
|
||||
runOnUiThread(() -> {
|
||||
JSONObject resobjLogin;
|
||||
try {
|
||||
resobjLogin = new JSONObject(responseLogin);
|
||||
String token = resobjLogin.getString("access_token");
|
||||
String refresh_token = resobjLogin.getString("refresh_token");
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
editor.apply();
|
||||
//Update the account with the token;
|
||||
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, host).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(() -> connectionButton.setEnabled(true));
|
||||
}
|
||||
});
|
||||
proceedLogin(responseLogin, host);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
parameters.clear();
|
||||
parameters.put(Helper.CLIENT_ID, sharedpreferences.getString(Helper.CLIENT_ID, null));
|
||||
parameters.put(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
|
||||
parameters.put("grant_type", "password");
|
||||
try {
|
||||
parameters.put("username", URLEncoder.encode(login_uid.getText().toString().toLowerCase().trim(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e2) {
|
||||
parameters.put("username", login_uid.getText().toString().toLowerCase().trim());
|
||||
}
|
||||
try {
|
||||
parameters.put("password", URLEncoder.encode(login_passwd.getText().toString(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e2) {
|
||||
parameters.put("password", login_passwd.getText().toString());
|
||||
}
|
||||
parameters.put("scope", "user");
|
||||
try {
|
||||
String responseLogin = new HttpsConnection(LoginActivity.this).post("https://" + finalInstance + oauthUrl, 30, parameters, null);
|
||||
proceedLogin(responseLogin, host);
|
||||
} catch (final Exception e2) {
|
||||
e2.printStackTrace();
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
String message;
|
||||
if (e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
|
||||
message = e.getLocalizedMessage();
|
||||
else if (e.getMessage() != null && e.getMessage().trim().length() > 0)
|
||||
message = e.getMessage();
|
||||
if (e2.getLocalizedMessage() != null && e2.getLocalizedMessage().trim().length() > 0)
|
||||
message = e2.getLocalizedMessage();
|
||||
else if (e2.getMessage() != null && e2.getMessage().trim().length() > 0)
|
||||
message = e2.getMessage();
|
||||
else
|
||||
message = getString(R.string.client_error);
|
||||
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
@ -413,6 +292,27 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
|
||||
});
|
||||
}
|
||||
|
||||
private void proceedLogin(String responseLogin, String host) {
|
||||
runOnUiThread(() -> {
|
||||
JSONObject resobjLogin;
|
||||
try {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
resobjLogin = new JSONObject(responseLogin);
|
||||
String token = resobjLogin.getString("access_token");
|
||||
String refresh_token = resobjLogin.getString("refresh_token");
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
editor.apply();
|
||||
//Update the account with the token;
|
||||
updateCredential(LoginActivity.this, token, client_id, client_secret, refresh_token, host);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(() -> connectionButton.setEnabled(true));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
@ -431,50 +331,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);
|
||||
}
|
||||
|
||||
}
|
@ -14,10 +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.os.AsyncTask;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -26,7 +27,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,34 +38,81 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
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.PeertubeInformation;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
|
||||
import static app.fedilab.fedilabtube.helper.Helper.academies;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public static PeertubeInformation peertubeInformation;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
BottomNavigationView navView = findViewById(R.id.nav_view);
|
||||
|
||||
try {
|
||||
new RetrievePeertubeInformationAsyncTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} catch (Exception ignored) {
|
||||
if (Helper.isLoggedIn(MainActivity.this)) {
|
||||
navView.inflateMenu(R.menu.bottom_nav_menu_connected);
|
||||
} else {
|
||||
navView.inflateMenu(R.menu.bottom_nav_menu);
|
||||
}
|
||||
|
||||
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 Thread(() -> {
|
||||
try {
|
||||
peertubeInformation = new PeertubeAPI(MainActivity.this).getPeertubeInformation();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
|
||||
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
|
||||
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
||||
@ -74,7 +125,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 +145,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 +176,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) {
|
||||
@ -126,14 +191,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
} else if (item.getItemId() == R.id.action_myvideos) {
|
||||
Intent intent = new Intent(MainActivity.this, MyVideosActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.MYVIDEOS);
|
||||
bundle.putSerializable("type", FeedsVM.Type.MYVIDEOS);
|
||||
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", FeedsVM.Type.PEERTUBE_HISTORY);
|
||||
intent.putExtras(bundle);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
@ -158,6 +223,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
private void showRadioButtonDialog() {
|
||||
|
||||
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
|
||||
@ -166,7 +232,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
String acad = Helper.getLiveInstance(MainActivity.this);
|
||||
int i = 0;
|
||||
for (String item : academies) {
|
||||
if (item.compareTo(acad) == 0) {
|
||||
if (Helper.getPeertubeUrl(item).compareTo(acad) == 0) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
@ -178,10 +244,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
editor.commit();
|
||||
dialog.dismiss();
|
||||
recreate();
|
||||
|
||||
});
|
||||
alt_bld.setPositiveButton(R.string.close, (dialog, id) -> dialog.dismiss());
|
||||
AlertDialog alert = alt_bld.create();
|
||||
alert.show();
|
||||
|
||||
}
|
||||
}
|
@ -20,15 +20,13 @@ import android.view.MenuItem;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayStatusFragment;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
|
||||
|
||||
public class MyVideosActivity extends AppCompatActivity implements OnRetrieveFeedsInterface {
|
||||
public class MyVideosActivity extends AppCompatActivity {
|
||||
|
||||
private RetrieveFeedsAsyncTask.Type type;
|
||||
private FeedsVM.Type type;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -41,12 +39,14 @@ public class MyVideosActivity extends AppCompatActivity implements OnRetrieveFee
|
||||
|
||||
Bundle b = getIntent().getExtras();
|
||||
if (b != null)
|
||||
type = (RetrieveFeedsAsyncTask.Type) b.get("type");
|
||||
type = (FeedsVM.Type) b.get("type");
|
||||
|
||||
if (type == RetrieveFeedsAsyncTask.Type.MYVIDEOS) {
|
||||
if (type == FeedsVM.Type.MYVIDEOS) {
|
||||
setTitle(R.string.my_videos);
|
||||
} else if (type == RetrieveFeedsAsyncTask.Type.PSUBSCRIPTIONS) {
|
||||
} else if (type == FeedsVM.Type.PSUBSCRIPTIONS) {
|
||||
setTitle(R.string.subscriptions);
|
||||
} else if (type == FeedsVM.Type.PEERTUBE_HISTORY) {
|
||||
setTitle(R.string.my_history);
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
@ -69,9 +69,4 @@ public class MyVideosActivity extends AppCompatActivity implements OnRetrieveFee
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
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 +38,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;
|
||||
@ -53,6 +54,7 @@ import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@ -76,15 +78,10 @@ import java.util.Objects;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleCommentsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.TLSSocketFactory;
|
||||
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.client.entities.Playlist;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
|
||||
@ -94,24 +91,25 @@ import app.fedilab.fedilabtube.drawer.StatusListAdapter;
|
||||
import app.fedilab.fedilabtube.helper.CacheDataSourceFactory;
|
||||
import app.fedilab.fedilabtube.helper.FullScreenMediaController;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.PeertubeFavoritesDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
import app.fedilab.fedilabtube.viewmodel.CommentVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import app.fedilab.fedilabtube.webview.CustomWebview;
|
||||
import app.fedilab.fedilabtube.webview.MastalabWebChromeClient;
|
||||
import app.fedilab.fedilabtube.webview.MastalabWebViewClient;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST;
|
||||
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST_FOR_VIDEO;
|
||||
import static app.fedilab.fedilabtube.helper.Helper.getAttColor;
|
||||
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
|
||||
import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLIST;
|
||||
import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLIST_FOR_VIDEO;
|
||||
|
||||
|
||||
public class PeertubeActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, OnPostActionInterface, OnPlaylistActionInterface {
|
||||
public class PeertubeActivity extends AppCompatActivity {
|
||||
|
||||
public static String video_id;
|
||||
private String peertubeInstance, videoId;
|
||||
@ -133,6 +131,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
private EditText add_comment_write;
|
||||
private List<PlaylistElement> playlistForVideo;
|
||||
private List<Playlist> playlists;
|
||||
private PlaylistsVM playlistsViewModel;
|
||||
|
||||
public static void hideKeyboard(Activity activity) {
|
||||
if (activity != null && activity.getWindow() != null) {
|
||||
@ -174,7 +173,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 +198,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);
|
||||
@ -251,11 +250,13 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
initFullscreenDialog();
|
||||
initFullscreenButton();
|
||||
}
|
||||
playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class);
|
||||
if (Helper.isLoggedIn(PeertubeActivity.this)) {
|
||||
new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST, null, null, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
playlistsViewModel.manage(GET_PLAYLIST, null, null, null).observe(PeertubeActivity.this, apiResponse -> manageVIewPlaylists(GET_PLAYLIST, apiResponse));
|
||||
}
|
||||
|
||||
new RetrievePeertubeSingleAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
FeedsVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(FeedsVM.class);
|
||||
feedsViewModel.getVideo(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewVideo);
|
||||
}
|
||||
|
||||
public void change() {
|
||||
@ -296,8 +297,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 +306,51 @@ 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) {
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.REPORT_VIDEO, peertube.getId(), report_content.getText().toString(), null).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_VIDEO, apiResponse));
|
||||
alertDialog.dismiss();
|
||||
dialog.dismiss();
|
||||
} else if (type == PeertubeAPI.reportType.ACCOUNT) {
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.REPORT_ACCOUNT, peertube.getAccount().getId(), report_content.getText().toString(), null).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_ACCOUNT, apiResponse));
|
||||
alertDialog.dismiss();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
androidx.appcompat.app.AlertDialog alertDialog2 = dialogBuilder.create();
|
||||
alertDialog2.show();
|
||||
}
|
||||
|
||||
public FullScreenMediaController.fullscreen getFullscreen() {
|
||||
return fullscreen;
|
||||
}
|
||||
@ -318,15 +359,14 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
this.fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
public void manageVIewVideo(APIResponse apiResponse) {
|
||||
|
||||
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
||||
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
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,9 +374,7 @@ 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);
|
||||
|
||||
playlistsViewModel.manage(GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse2 -> manageVIewPlaylists(GET_PLAYLIST_FOR_VIDEO, apiResponse2));
|
||||
|
||||
add_comment_read.setOnClickListener(v -> {
|
||||
if (isLoggedIn(PeertubeActivity.this)) {
|
||||
@ -354,7 +392,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
if (isLoggedIn(PeertubeActivity.this)) {
|
||||
String comment = add_comment_write.getText().toString();
|
||||
if (comment.trim().length() > 0) {
|
||||
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.PEERTUBECOMMENT, peertube.getId(), comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.PEERTUBECOMMENT, peertube.getAccount().getId(), comment, null).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(PeertubeAPI.StatusAction.PEERTUBECOMMENT, apiResponse1));
|
||||
add_comment_write.setText("");
|
||||
add_comment_read.setVisibility(View.VISIBLE);
|
||||
add_comment_write.setVisibility(View.GONE);
|
||||
@ -408,11 +447,11 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
});
|
||||
if (finalIsPresent) {
|
||||
item1.setTitle(playlist.getDisplayName());
|
||||
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, finalElementId, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, finalElementId, null).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.DELETE_VIDEOS, apiResponse3));
|
||||
playlistForVideo.remove(finalPlaylistElementFinal);
|
||||
} else {
|
||||
item1.setTitle("✔ " + playlist.getDisplayName());
|
||||
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3));
|
||||
PlaylistElement playlistElement = new PlaylistElement();
|
||||
playlistElement.setPlaylistElementId(finalElementId);
|
||||
playlistElement.setPlaylistId(playlist.getId());
|
||||
@ -427,7 +466,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
|
||||
|
||||
if (peertube.isCommentsEnabled()) {
|
||||
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
||||
commentViewModel.getComment(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewComment);
|
||||
write_comment_container.setVisibility(View.VISIBLE);
|
||||
|
||||
} else {
|
||||
@ -452,7 +492,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
peertube_like_count.setOnClickListener(v -> {
|
||||
if (isLoggedIn(PeertubeActivity.this)) {
|
||||
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
|
||||
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), newState, null).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(PeertubeAPI.StatusAction.RATEVIDEO, apiResponse1));
|
||||
peertube.setMyRating(newState);
|
||||
int count = Integer.parseInt(peertube_like_count.getText().toString());
|
||||
if (newState.compareTo("none") == 0) {
|
||||
@ -472,7 +513,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
peertube_dislike_count.setOnClickListener(v -> {
|
||||
if (isLoggedIn(PeertubeActivity.this)) {
|
||||
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
|
||||
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), newState, null).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(PeertubeAPI.StatusAction.RATEVIDEO, apiResponse1));
|
||||
peertube.setMyRating(newState);
|
||||
int count = Integer.parseInt(peertube_dislike_count.getText().toString());
|
||||
if (newState.compareTo("none") == 0) {
|
||||
@ -496,7 +538,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 +546,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 +566,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();
|
||||
@ -601,8 +643,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
public void manageVIewComment(APIResponse apiResponse) {
|
||||
if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 501)) {
|
||||
if (apiResponse == null)
|
||||
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
@ -628,10 +670,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
@ -674,7 +712,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 +724,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);
|
||||
@ -702,11 +740,17 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
builderSingle.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
|
||||
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) {
|
||||
|
||||
if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT)
|
||||
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT) {
|
||||
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
||||
commentViewModel.getComment(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewComment);
|
||||
} 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() {
|
||||
@ -787,8 +831,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||
|
||||
if (actionType == GET_PLAYLIST_FOR_VIDEO && apiResponse != null) {
|
||||
playlistForVideo = apiResponse.getPlaylistForVideos();
|
||||
|
@ -14,50 +14,67 @@ 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.os.AsyncTask;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
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 androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
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;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleAsyncTask;
|
||||
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.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import mabbas007.tagsedittext.TagsEditText;
|
||||
|
||||
import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
|
||||
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||
|
||||
|
||||
public class PeertubeEditUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, OnPostActionInterface {
|
||||
public class PeertubeEditUploadActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
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 +88,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 +119,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;
|
||||
@ -109,7 +130,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
|
||||
builderInner.setMessage(getString(R.string.delete_video_confirmation));
|
||||
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||
new PostActionAsyncTask(PeertubeEditUploadActivity.this, PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO, videoId, null, null).observe(PeertubeEditUploadActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO, apiResponse));
|
||||
dialog.dismiss();
|
||||
});
|
||||
builderInner.show();
|
||||
@ -197,15 +219,15 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
|
||||
|
||||
|
||||
String peertubeInstance = Helper.getLiveInstance(PeertubeEditUploadActivity.this);
|
||||
new RetrievePeertubeSingleAsyncTask(PeertubeEditUploadActivity.this, peertubeInstance, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
FeedsVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(FeedsVM.class);
|
||||
feedsViewModel.getVideo(peertubeInstance, videoId).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo);
|
||||
channels = new LinkedHashMap<>();
|
||||
|
||||
setTitle(R.string.edit_video);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
public void manageVIewVideo(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
@ -216,14 +238,15 @@ 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();
|
||||
peertube.setUpdate(false);
|
||||
set_upload_submit.setEnabled(true);
|
||||
} else {
|
||||
new RetrievePeertubeChannelsAsyncTask(PeertubeEditUploadActivity.this, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
ChannelsVM viewModelC = new ViewModelProvider(PeertubeEditUploadActivity.this).get(ChannelsVM.class);
|
||||
viewModelC.get().observe(PeertubeEditUploadActivity.this, this::manageVIewChannels);
|
||||
}
|
||||
|
||||
languageToSend = peertube.getLanguage();
|
||||
@ -231,6 +254,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();
|
||||
@ -482,7 +526,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
|
||||
List<String> tags = p_video_tags.getTags();
|
||||
peertube.setTags(tags);
|
||||
set_upload_submit.setEnabled(false);
|
||||
new PostPeertubeAsyncTask(PeertubeEditUploadActivity.this, peertube, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
|
||||
FeedsVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(FeedsVM.class);
|
||||
feedsViewModel.updateVideo(peertube).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo);
|
||||
});
|
||||
|
||||
set_upload_privacy.setSelection(privacyPosition);
|
||||
@ -498,13 +543,76 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
@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 onRetrievePeertubeChannels(APIResponse apiResponse) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public void manageVIewChannels(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||
if (apiResponse.getError().getError() != null)
|
||||
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
@ -543,8 +651,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
|
||||
set_upload_submit.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
|
||||
@SuppressWarnings("unused")
|
||||
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) {
|
||||
Intent intent = new Intent(PeertubeEditUploadActivity.this, MainActivity.class);
|
||||
intent.putExtra(Helper.INTENT_ACTION, Helper.RELOAD_MYVIDEOS);
|
||||
startActivity(intent);
|
||||
|
@ -15,30 +15,33 @@ package app.fedilab.fedilabtube;
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Patterns;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.CreatePeertubeAccountAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.AccountCreation;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPostStatusActionInterface;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
|
||||
|
||||
public class PeertubeRegisterActivity extends AppCompatActivity implements OnPostStatusActionInterface {
|
||||
public class PeertubeRegisterActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private Button signup;
|
||||
@ -55,16 +58,53 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
signup = findViewById(R.id.signup);
|
||||
EditText username = findViewById(R.id.username);
|
||||
EditText email = findViewById(R.id.email);
|
||||
EditText password = findViewById(R.id.password);
|
||||
EditText password_confirm = findViewById(R.id.password_confirm);
|
||||
TextInputEditText username = findViewById(R.id.username);
|
||||
TextInputEditText email = findViewById(R.id.email);
|
||||
TextInputEditText password = findViewById(R.id.password);
|
||||
TextInputEditText password_confirm = findViewById(R.id.password_confirm);
|
||||
CheckBox agreement = findViewById(R.id.agreement);
|
||||
error_message = findViewById(R.id.error_message);
|
||||
|
||||
|
||||
username.setOnFocusChangeListener((view, focused) -> {
|
||||
if (!focused && username.getText() != null) {
|
||||
Pattern patternUsername = Pattern.compile("^[a-z0-9._]{1,50}$");
|
||||
Matcher matcherMaxId = patternUsername.matcher(username.getText().toString());
|
||||
if (!matcherMaxId.matches()) {
|
||||
username.setError(getString(R.string.username_error));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
email.setOnFocusChangeListener((view, focused) -> {
|
||||
if (!focused && email.getText() != null) {
|
||||
Pattern patternUsername = Patterns.EMAIL_ADDRESS;
|
||||
Matcher matcherMaxId = patternUsername.matcher(email.getText().toString());
|
||||
if (!matcherMaxId.matches()) {
|
||||
email.setError(getString(R.string.email_error));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
password.setOnFocusChangeListener((view, focused) -> {
|
||||
if (!focused && password.getText() != null) {
|
||||
if (password.getText().length() < 6) {
|
||||
password.setError(getString(R.string.password_length_error));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
password_confirm.setOnFocusChangeListener((view, focused) -> {
|
||||
if (!focused && password_confirm.getText() != null && password.getText() != null) {
|
||||
if (password_confirm.getText().toString().compareTo(password.getText().toString()) != 0) {
|
||||
password_confirm.setError(getString(R.string.password));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
signup.setOnClickListener(view -> {
|
||||
error_message.setVisibility(View.GONE);
|
||||
if (username.getText().toString().trim().length() == 0 || email.getText().toString().trim().length() == 0 ||
|
||||
if (username.getText() == null || email.getText() == null || password.getText() == null || password_confirm.getText() == null || username.getText().toString().trim().length() == 0 || email.getText().toString().trim().length() == 0 ||
|
||||
password.getText().toString().trim().length() == 0 || password_confirm.getText().toString().trim().length() == 0 || !agreement.isChecked()) {
|
||||
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.all_field_filled)).show();
|
||||
return;
|
||||
@ -101,29 +141,13 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
||||
accountCreation.setPassword(password.getText().toString().trim());
|
||||
accountCreation.setPasswordConfirm(password_confirm.getText().toString().trim());
|
||||
accountCreation.setUsername(username.getText().toString().trim());
|
||||
new CreatePeertubeAccountAsyncTask(PeertubeRegisterActivity.this, accountCreation, Helper.getPeertubeUrl(instance), PeertubeRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
|
||||
});
|
||||
accountCreation.setInstance(instance);
|
||||
|
||||
TextView agreement_text = findViewById(R.id.agreement_text);
|
||||
String tos = getString(R.string.tos);
|
||||
String serverrules = getString(R.string.server_rules);
|
||||
String content_agreement = getString(R.string.agreement_check,
|
||||
"<a href='https://apps.education.fr/cgu#peertube' >" + serverrules + "</a>",
|
||||
"<a href='https://apps.education.fr/bonnes-pratiques/' >" + tos + "</a>"
|
||||
);
|
||||
agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
agreement_text.setText(Html.fromHtml(content_agreement));
|
||||
setTitle(R.string.create_an_account);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPostStatusAction(APIResponse apiResponse) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
APIResponse apiResponse = new PeertubeAPI(PeertubeRegisterActivity.this, instance, null).createAccount(accountCreation);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
if (apiResponse.getError() != null) {
|
||||
String errorMessage;
|
||||
if (apiResponse.getError().getError() != null) {
|
||||
@ -157,6 +181,30 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
||||
alertDialog.setTitle(getString(R.string.account_created));
|
||||
alertDialog.setMessage(getString(R.string.account_created_message, apiResponse.getStringData()));
|
||||
alertDialog.show();
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
|
||||
});
|
||||
|
||||
TextView agreement_text = findViewById(R.id.agreement_text);
|
||||
String tos = getString(R.string.tos);
|
||||
String serverrules = getString(R.string.server_rules);
|
||||
String content_agreement = getString(R.string.agreement_check,
|
||||
"<a href='https://apps.education.fr/cgu#peertube' >" + serverrules + "</a>",
|
||||
"<a href='https://apps.education.fr/bonnes-pratiques/' >" + tos + "</a>"
|
||||
);
|
||||
agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
agreement_text.setText(Html.fromHtml(content_agreement));
|
||||
setTitle(R.string.create_an_account);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
@ -24,7 +23,6 @@ import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.view.MenuItem;
|
||||
@ -40,17 +38,11 @@ import android.widget.Toast;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
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;
|
||||
@ -61,17 +53,16 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||
|
||||
|
||||
public class PeertubeUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, UploadStatusDelegate {
|
||||
public class PeertubeUploadActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private final int PICK_IVDEO = 52378;
|
||||
@ -85,7 +76,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) {
|
||||
@ -103,12 +94,10 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
|
||||
set_upload_submit = findViewById(R.id.set_upload_submit);
|
||||
video_title = findViewById(R.id.video_title);
|
||||
|
||||
new RetrievePeertubeChannelsAsyncTask(PeertubeUploadActivity.this, PeertubeUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
ChannelsVM viewModelC = new ViewModelProvider(PeertubeUploadActivity.this).get(ChannelsVM.class);
|
||||
viewModelC.get().observe(PeertubeUploadActivity.this, this::manageVIewChannels);
|
||||
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,13 +141,8 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
uploadReceiver.unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
@ -168,14 +153,7 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
||||
public void manageVIewChannels(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(PeertubeUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
@ -327,7 +305,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 +315,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 +324,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
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ 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.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -23,6 +22,7 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
@ -30,18 +30,17 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.client.entities.Playlist;
|
||||
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_LIST_VIDEOS;
|
||||
import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_LIST_VIDEOS;
|
||||
|
||||
|
||||
public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistActionInterface {
|
||||
public class PlaylistsActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
LinearLayoutManager mLayoutManager;
|
||||
@ -54,6 +53,7 @@ public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistAc
|
||||
private boolean firstLoad;
|
||||
private boolean flag_loading;
|
||||
private PeertubeAdapter peertubeAdapter;
|
||||
private PlaylistsVM viewModel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -101,7 +101,7 @@ public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistAc
|
||||
|
||||
setTitle(playlist.getDisplayName());
|
||||
|
||||
|
||||
viewModel = new ViewModelProvider(PlaylistsActivity.this).get(PlaylistsVM.class);
|
||||
lv_playlist.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||
@ -111,7 +111,7 @@ public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistAc
|
||||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
new ManagePlaylistsAsyncTask(PlaylistsActivity.this, GET_LIST_VIDEOS, playlist, null, max_id, PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null, max_id).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
@ -127,10 +127,10 @@ public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistAc
|
||||
firstLoad = true;
|
||||
flag_loading = true;
|
||||
swiped = true;
|
||||
new ManagePlaylistsAsyncTask(PlaylistsActivity.this, GET_LIST_VIDEOS, playlist, null, null, PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
});
|
||||
|
||||
new ManagePlaylistsAsyncTask(PlaylistsActivity.this, GET_LIST_VIDEOS, playlist, null, null, PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
}
|
||||
|
||||
|
||||
@ -144,8 +144,7 @@ public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistAc
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
//Discards 404 - error which can often happen due to toots which have been deleted
|
||||
|
@ -21,13 +21,11 @@ import android.widget.Toast;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayStatusFragment;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
|
||||
public class SearchActivity extends AppCompatActivity implements OnRetrieveFeedsInterface {
|
||||
public class SearchActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private String search;
|
||||
@ -69,9 +67,4 @@ public class SearchActivity extends AppCompatActivity implements OnRetrieveFeeds
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -17,15 +17,18 @@ package app.fedilab.fedilabtube;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
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;
|
||||
@ -37,36 +40,27 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.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.Relationship;
|
||||
import app.fedilab.fedilabtube.client.entities.Status;
|
||||
import app.fedilab.fedilabtube.client.entities.StatusDrawerParams;
|
||||
import app.fedilab.fedilabtube.drawer.StatusListAdapter;
|
||||
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.OnRetrieveFeedsAccountInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrieveRelationshipInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.RelationshipVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
|
||||
@ -74,40 +68,32 @@ 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 {
|
||||
|
||||
|
||||
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 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,97 +103,78 @@ 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();
|
||||
}
|
||||
statuses = new ArrayList<>();
|
||||
StatusDrawerParams statusDrawerParams = new StatusDrawerParams();
|
||||
statusDrawerParams.setType(RetrieveFeedsAsyncTask.Type.USER);
|
||||
statusDrawerParams.setTargetedId(accountId);
|
||||
statusDrawerParams.setStatuses(statuses);
|
||||
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());
|
||||
AccountsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(AccountsVM.class);
|
||||
if (account != null) {
|
||||
ManageAccount();
|
||||
manageAccount();
|
||||
viewModel.getAccounts(null, account.getAcct(), AccountsVM.accountFetch.SINGLE_CHANNEL).observe(ShowAccountActivity.this, this::manageViewAccounts);
|
||||
} else {
|
||||
viewModel.getAccounts(null, accountId, AccountsVM.accountFetch.SINGLE_CHANNEL).observe(ShowAccountActivity.this, this::manageViewAccounts);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.MUTE, account.getchannelOwner() != null ? account.getchannelOwner().getAcct() : account.getAcct(), null, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.MUTE, apiResponse));
|
||||
} 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 {
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.REPORT_ACCOUNT, account.getId(), report_content.getText().toString(), null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_ACCOUNT, apiResponse));
|
||||
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();
|
||||
if (isLoggedIn(ShowAccountActivity.this)) {
|
||||
retrieveRelationship = new RetrieveRelationshipAsyncTask(ShowAccountActivity.this, accountIdRelation, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
RelationshipVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(RelationshipVM.class);
|
||||
viewModel.get(accountIdRelation).observe(ShowAccountActivity.this, this::manageVIewRelationship);
|
||||
}
|
||||
|
||||
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 +246,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();
|
||||
@ -309,7 +258,8 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||
Toasty.info(ShowAccountActivity.this, getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show();
|
||||
} else if (doAction == action.FOLLOW) {
|
||||
account_follow.setEnabled(false);
|
||||
new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.FOLLOW, target, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.FOLLOW, target, null, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.FOLLOW, apiResponse));
|
||||
} else if (doAction == action.UNFOLLOW) {
|
||||
boolean confirm_unfollow = sharedpreferences.getBoolean(Helper.SET_UNFOLLOW_VALIDATION, true);
|
||||
if (confirm_unfollow) {
|
||||
@ -319,55 +269,32 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||
unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
unfollowConfirm.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||
account_follow.setEnabled(false);
|
||||
new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.UNFOLLOW, target, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.UNFOLLOW, target, null, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.UNFOLLOW, apiResponse));
|
||||
dialog.dismiss();
|
||||
});
|
||||
unfollowConfirm.show();
|
||||
} else {
|
||||
account_follow.setEnabled(false);
|
||||
new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.UNFOLLOW, target, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.UNFOLLOW, target, null, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.UNFOLLOW, apiResponse));
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
TextView account_date = findViewById(R.id.account_date);
|
||||
account_date.setText(Helper.shortDateToString(account.getCreated_at()));
|
||||
account_date.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeedsAccount(List<Status> statuses) {
|
||||
if (statuses != null) {
|
||||
this.statuses.addAll(statuses);
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
public void manageVIewRelationship(APIResponse apiResponse) {
|
||||
|
||||
if (apiResponse.getError() != null) {
|
||||
Toasty.error(ShowAccountActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveRelationship(Relationship relationship, Error error) {
|
||||
|
||||
if (error != null) {
|
||||
Toasty.error(ShowAccountActivity.this, error.getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
this.relationship = relationship;
|
||||
List<Relationship> relationships = apiResponse.getRelationships();
|
||||
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 +322,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;
|
||||
@ -430,29 +355,63 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (retrieveRelationship != null && !retrieveRelationship.isCancelled()) {
|
||||
retrieveRelationship.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String targetedId, Error error) {
|
||||
|
||||
if (error != null) {
|
||||
Toasty.error(ShowAccountActivity.this, error.getError(), Toast.LENGTH_LONG).show();
|
||||
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) {
|
||||
|
||||
if (apiResponse.getError() != null) {
|
||||
Toasty.error(ShowAccountActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
String target = account.getAcct();
|
||||
//IF action is unfollow or mute, sends an intent to remove statuses
|
||||
if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW) {
|
||||
Bundle b = new Bundle();
|
||||
b.putString("receive_action", targetedId);
|
||||
b.putString("receive_action", apiResponse.getTargetedId());
|
||||
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) {
|
||||
RelationshipVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(RelationshipVM.class);
|
||||
viewModel.get(target).observe(ShowAccountActivity.this, this::manageVIewRelationship);
|
||||
} else if (statusAction == PeertubeAPI.StatusAction.MUTE) {
|
||||
Toasty.info(ShowAccountActivity.this, getString(R.string.muted_done), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void manageViewAccounts(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 +420,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 {
|
||||
|
||||
@ -476,7 +435,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||
if (position == 0) {
|
||||
DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment();
|
||||
bundle = new Bundle();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
|
||||
bundle.putSerializable("type", FeedsVM.Type.USER);
|
||||
bundle.putString("targetedid", account.getAcct());
|
||||
bundle.putBoolean("ischannel", ischannel);
|
||||
displayStatusFragment.setArguments(bundle);
|
||||
|
@ -17,7 +17,6 @@ package app.fedilab.fedilabtube;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.webkit.CookieManager;
|
||||
@ -36,11 +35,12 @@ import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.UpdateAccountInfoAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.HttpsConnection;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.webview.CustomWebview;
|
||||
|
||||
import static app.fedilab.fedilabtube.client.HttpsConnection.updateCredential;
|
||||
|
||||
|
||||
public class WebviewConnectActivity extends AppCompatActivity {
|
||||
|
||||
@ -135,7 +135,7 @@ public class WebviewConnectActivity extends AppCompatActivity {
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
editor.putString(Helper.PREF_INSTANCE, new URL(url).getHost());
|
||||
editor.apply();
|
||||
new UpdateAccountInfoAsyncTask(WebviewConnectActivity.this, token, clientId, clientSecret, refresh_token, new URL(url).getHost()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
updateCredential(WebviewConnectActivity.this, token, clientId, clientSecret, refresh_token, new URL(url).getHost());
|
||||
finish();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -1,55 +0,0 @@
|
||||
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.client.entities.AccountCreation;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPostStatusActionInterface;
|
||||
|
||||
|
||||
public class CreatePeertubeAccountAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private OnPostStatusActionInterface listener;
|
||||
private APIResponse apiResponse;
|
||||
private AccountCreation accountCreation;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String instance;
|
||||
|
||||
public CreatePeertubeAccountAsyncTask(Context context, AccountCreation accountCreation, String instance, OnPostStatusActionInterface onPostStatusActionInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.listener = onPostStatusActionInterface;
|
||||
this.accountCreation = accountCreation;
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
apiResponse = new PeertubeAPI(contextReference.get(), instance, null).createAccount(accountCreation);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onPostStatusAction(apiResponse);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
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.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
||||
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.Playlist;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class ManagePlaylistsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private OnPlaylistActionInterface listener;
|
||||
private APIResponse apiResponse;
|
||||
private int statusCode;
|
||||
private action apiAction;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String max_id;
|
||||
private Playlist playlist;
|
||||
private String videoId;
|
||||
|
||||
public ManagePlaylistsAsyncTask(Context context, action apiAction, Playlist playlist, String videoId, String max_id, OnPlaylistActionInterface onPlaylistActionInterface) {
|
||||
contextReference = new WeakReference<>(context);
|
||||
this.listener = onPlaylistActionInterface;
|
||||
this.apiAction = apiAction;
|
||||
this.max_id = max_id;
|
||||
this.playlist = playlist;
|
||||
this.videoId = videoId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(contextReference.get());
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance);
|
||||
if (account == null) {
|
||||
account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
|
||||
}
|
||||
if (account == null) {
|
||||
statusCode = 403;
|
||||
apiResponse = new APIResponse();
|
||||
apiResponse.setPlaylists(new ArrayList<>());
|
||||
} else if (apiAction == action.GET_PLAYLIST) {
|
||||
apiResponse = new PeertubeAPI(contextReference.get()).getPlayists(account.getUsername());
|
||||
} else if (apiAction == action.GET_LIST_VIDEOS) {
|
||||
apiResponse = new PeertubeAPI(contextReference.get()).getPlaylistVideos(playlist.getId(), max_id, null);
|
||||
} else if (apiAction == action.DELETE_PLAYLIST) {
|
||||
statusCode = new PeertubeAPI(contextReference.get()).deletePlaylist(playlist.getId());
|
||||
} else if (apiAction == action.ADD_VIDEOS) {
|
||||
statusCode = new PeertubeAPI(contextReference.get()).addVideoPlaylist(playlist.getId(), videoId);
|
||||
} else if (apiAction == action.DELETE_VIDEOS) {
|
||||
statusCode = new PeertubeAPI(contextReference.get()).deleteVideoPlaylist(playlist.getId(), videoId);
|
||||
} else if (apiAction == action.GET_PLAYLIST_FOR_VIDEO) {
|
||||
apiResponse = new PeertubeAPI(contextReference.get()).getPlaylistForVideo(videoId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onActionDone(this.apiAction, apiResponse, statusCode);
|
||||
}
|
||||
|
||||
public enum action {
|
||||
GET_PLAYLIST,
|
||||
GET_LIST_VIDEOS,
|
||||
CREATE_PLAYLIST,
|
||||
DELETE_PLAYLIST,
|
||||
ADD_VIDEOS,
|
||||
DELETE_VIDEOS,
|
||||
GET_PLAYLIST_FOR_VIDEO,
|
||||
}
|
||||
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
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.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
|
||||
|
||||
|
||||
public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private OnPostActionInterface listener;
|
||||
private int statusCode;
|
||||
private PeertubeAPI.StatusAction apiAction;
|
||||
private String targetedId, targetedComment;
|
||||
private String comment;
|
||||
private WeakReference<Context> contextReference;
|
||||
private Error error;
|
||||
|
||||
|
||||
public PostActionAsyncTask(Context context, PeertubeAPI.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.listener = onPostActionInterface;
|
||||
this.apiAction = apiAction;
|
||||
this.targetedId = targetedId;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public PostActionAsyncTask(Context context, String targetedId, String comment, String targetedComment, OnPostActionInterface onPostActionInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.listener = onPostActionInterface;
|
||||
this.apiAction = PeertubeAPI.StatusAction.PEERTUBEREPLY;
|
||||
this.targetedId = targetedId;
|
||||
this.comment = comment;
|
||||
this.targetedComment = targetedComment;
|
||||
}
|
||||
|
||||
public PostActionAsyncTask(Context context, PeertubeAPI.StatusAction apiAction, String targetedId, String comment, OnPostActionInterface onPostActionInterface) {
|
||||
contextReference = new WeakReference<>(context);
|
||||
this.listener = onPostActionInterface;
|
||||
this.apiAction = apiAction;
|
||||
this.targetedId = targetedId;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(contextReference.get());
|
||||
if (apiAction == PeertubeAPI.StatusAction.FOLLOW || apiAction == PeertubeAPI.StatusAction.UNFOLLOW)
|
||||
statusCode = peertubeAPI.postAction(apiAction, targetedId);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.RATEVIDEO)
|
||||
statusCode = peertubeAPI.postRating(targetedId, comment);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT)
|
||||
statusCode = peertubeAPI.postComment(targetedId, comment);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEREPLY)
|
||||
statusCode = peertubeAPI.postReply(targetedId, comment, targetedComment);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT) {
|
||||
statusCode = peertubeAPI.deleteComment(targetedId, comment);
|
||||
targetedId = comment;
|
||||
} else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO) {
|
||||
statusCode = peertubeAPI.deleteVideo(targetedId);
|
||||
}
|
||||
error = peertubeAPI.getError();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
if (listener != null) {
|
||||
listener.onPostAction(statusCode, apiAction, targetedId, error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
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.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
|
||||
|
||||
public class PostPeertubeAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrievePeertubeInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private Peertube peertube;
|
||||
|
||||
|
||||
public PostPeertubeAsyncTask(Context context, Peertube peertube, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.listener = onRetrievePeertubeInterface;
|
||||
this.peertube = peertube;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.updateVideo(peertube);
|
||||
if (apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0)
|
||||
apiResponse.getPeertubes().get(0).setUpdate(true);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrievePeertube(apiResponse);
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
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 RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrieveAccountsInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String name;
|
||||
|
||||
public RetrieveAccountsAsyncTask(Context context, String name, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.name = name;
|
||||
this.listener = onRetrieveAccountsInterface;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getPeertubeChannel(name);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveAccounts(apiResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
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.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
|
||||
import app.fedilab.fedilabtube.sqlite.PeertubeFavoritesDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private Type action;
|
||||
private APIResponse apiResponse;
|
||||
private String max_id;
|
||||
private OnRetrieveFeedsInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String target;
|
||||
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.action = action;
|
||||
this.max_id = max_id;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, String target, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.action = action;
|
||||
this.max_id = max_id;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
|
||||
if (action == null)
|
||||
return null;
|
||||
switch (action) {
|
||||
case USER:
|
||||
apiResponse = peertubeAPI.getVideos(target, max_id);
|
||||
break;
|
||||
case MYVIDEOS:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getMyVideos(max_id);
|
||||
break;
|
||||
case PEERTUBE_HISTORY:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getMyHistory(max_id);
|
||||
break;
|
||||
case CHANNEL:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getVideosChannel(target, max_id);
|
||||
break;
|
||||
|
||||
case CACHE_BOOKMARKS_PEERTUBE:
|
||||
apiResponse = new APIResponse();
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<Peertube> peertubes = new PeertubeFavoritesDAO(contextReference.get(), db).getAllPeertube();
|
||||
apiResponse.setPeertubes(peertubes);
|
||||
break;
|
||||
case PSUBSCRIPTIONS:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getSubscriptionsTL(max_id);
|
||||
break;
|
||||
case POVERVIEW:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getOverviewTL(max_id);
|
||||
break;
|
||||
case PTRENDING:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getTrendingTL(max_id);
|
||||
break;
|
||||
case PRECENTLYADDED:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getRecentlyAddedTL(max_id);
|
||||
break;
|
||||
case PLOCAL:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getLocalTL(max_id);
|
||||
break;
|
||||
case PPUBLIC:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getPublicTL(max_id);
|
||||
break;
|
||||
case PMOSTLIKED:
|
||||
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.getLikedTL(max_id);
|
||||
break;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveFeeds(apiResponse);
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
|
||||
USER,
|
||||
|
||||
PPUBLIC,
|
||||
PSUBSCRIPTIONS,
|
||||
POVERVIEW,
|
||||
PTRENDING,
|
||||
PRECENTLYADDED,
|
||||
PMOSTLIKED,
|
||||
PLOCAL,
|
||||
CHANNEL,
|
||||
MYVIDEOS,
|
||||
PEERTUBE_HISTORY,
|
||||
|
||||
CACHE_BOOKMARKS_PEERTUBE,
|
||||
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
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.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
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.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class RetrievePeertubeChannelsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrievePeertubeInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
|
||||
public RetrievePeertubeChannelsAsyncTask(Context context, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.listener = onRetrievePeertubeInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(contextReference.get());
|
||||
Account account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance);
|
||||
if (account == null) {
|
||||
account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
|
||||
}
|
||||
apiResponse = peertubeAPI.getPeertubeChannel(account.getUsername());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrievePeertubeChannels(apiResponse);
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
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.HttpsConnection;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
|
||||
|
||||
|
||||
public class RetrievePeertubeInformationAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
public static PeertubeInformation peertubeInformation;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
|
||||
public RetrievePeertubeInformationAsyncTask(Context context) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
try {
|
||||
peertubeInformation = peertubeAPI.getPeertubeInformation();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
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.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeNotificationsInterface;
|
||||
|
||||
|
||||
public class RetrievePeertubeNotificationsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private APIResponse apiResponse;
|
||||
private String max_id;
|
||||
private Account account;
|
||||
private OnRetrievePeertubeNotificationsInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
public RetrievePeertubeNotificationsAsyncTask(Context context, Account account, String max_id, OnRetrievePeertubeNotificationsInterface onRetrievePeertubeNotificationsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.max_id = max_id;
|
||||
this.listener = onRetrievePeertubeNotificationsInterface;
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI api;
|
||||
if (account == null) {
|
||||
api = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = api.getNotifications(max_id);
|
||||
} else {
|
||||
if (this.contextReference.get() == null) {
|
||||
apiResponse.setError(new Error());
|
||||
return null;
|
||||
}
|
||||
api = new PeertubeAPI(this.contextReference.get(), account.getInstance(), account.getToken());
|
||||
apiResponse = api.getNotificationsSince(max_id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrievePeertubeNotifications(apiResponse, account);
|
||||
}
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
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.OnRetrieveFeedsInterface;
|
||||
|
||||
|
||||
public class RetrievePeertubeSearchAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private String query, max_id;
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrieveFeedsInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
public RetrievePeertubeSearchAsyncTask(Context context, String max_id, String query, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.query = query;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.max_id = max_id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = api.searchPeertube(query, max_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveFeeds(apiResponse);
|
||||
}
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
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.content.SharedPreferences;
|
||||
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.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
|
||||
|
||||
public class RetrievePeertubeSingleAsyncTask extends AsyncTask<Void, Void, APIResponse> {
|
||||
|
||||
|
||||
private String videoId;
|
||||
private OnRetrievePeertubeInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String instanceName;
|
||||
|
||||
|
||||
public RetrievePeertubeSingleAsyncTask(Context context, String instanceName, String videoId, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.videoId = videoId;
|
||||
this.listener = onRetrievePeertubeInterface;
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected APIResponse doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
APIResponse apiResponse = peertubeAPI.getSinglePeertube(this.instanceName, videoId, token);
|
||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
||||
String rate = new PeertubeAPI(this.contextReference.get()).getRating(videoId);
|
||||
if (rate != null)
|
||||
apiResponse.getPeertubes().get(0).setMyRating(rate);
|
||||
}
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(APIResponse apiResponse) {
|
||||
listener.onRetrievePeertube(apiResponse);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
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.OnRetrievePeertubeInterface;
|
||||
|
||||
|
||||
public class RetrievePeertubeSingleCommentsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private APIResponse apiResponse;
|
||||
private String videoId;
|
||||
private OnRetrievePeertubeInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String instanceName;
|
||||
|
||||
|
||||
public RetrievePeertubeSingleCommentsAsyncTask(Context context, String instanceName, String videoId, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.videoId = videoId;
|
||||
this.listener = onRetrievePeertubeInterface;
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = api.getSinglePeertubeComments(this.instanceName, videoId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrievePeertubeComments(apiResponse);
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
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.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.Relationship;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrieveRelationshipInterface;
|
||||
|
||||
|
||||
public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private String accountId;
|
||||
private Relationship relationship;
|
||||
private OnRetrieveRelationshipInterface listener;
|
||||
private Error error;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
public RetrieveRelationshipAsyncTask(Context context, String accountId, OnRetrieveRelationshipInterface onRetrieveRelationshipInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.listener = onRetrieveRelationshipInterface;
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
|
||||
relationship = new Relationship();
|
||||
relationship.setFollowing(api.isFollowing(accountId));
|
||||
error = api.getError();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveRelationship(relationship, error);
|
||||
}
|
||||
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
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.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
import app.fedilab.fedilabtube.MainActivity;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private String token, client_id, client_secret, refresh_token;
|
||||
private String host;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
public UpdateAccountInfoAsyncTask(Context context, String token, String client_id, String client_secret, String refresh_token, String host) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.token = token;
|
||||
this.host = host;
|
||||
this.client_id = client_id;
|
||||
this.client_secret = client_secret;
|
||||
this.refresh_token = refresh_token;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Account account;
|
||||
if (this.contextReference == null) {
|
||||
return null;
|
||||
}
|
||||
String instance;
|
||||
if (host.startsWith("tube")) {
|
||||
instance = host;
|
||||
} else {
|
||||
instance = Helper.getPeertubeUrl(host);
|
||||
}
|
||||
account = new PeertubeAPI(this.contextReference.get()).verifyCredentials(token, instance);
|
||||
if (account == null)
|
||||
return null;
|
||||
try {
|
||||
//At the state the instance can be encoded
|
||||
instance = URLDecoder.decode(instance, "utf-8");
|
||||
} catch (UnsupportedEncodingException ignored) {
|
||||
}
|
||||
|
||||
SharedPreferences sharedpreferences = this.contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
account.setToken(token);
|
||||
account.setClient_id(client_id);
|
||||
account.setClient_secret(client_secret);
|
||||
account.setRefresh_token(refresh_token);
|
||||
account.setInstance(instance);
|
||||
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
boolean userExists = new AccountDAO(this.contextReference.get(), db).userExist(account);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||
editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator());
|
||||
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin());
|
||||
if (!host.startsWith("tube")) {
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
}
|
||||
editor.apply();
|
||||
if (userExists)
|
||||
new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);
|
||||
else {
|
||||
if (account.getUsername() != null && account.getCreated_at() != null)
|
||||
new AccountDAO(this.contextReference.get(), db).insertAccount(account);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
|
||||
if (this.contextReference.get() != null) {
|
||||
Intent mainActivity = new Intent(this.contextReference.get(), MainActivity.class);
|
||||
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.ADD_USER_INTENT);
|
||||
this.contextReference.get().startActivity(mainActivity);
|
||||
((Activity) this.contextReference.get()).finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -23,9 +23,10 @@ import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.client.entities.PeertubeNotification;
|
||||
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;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@SuppressWarnings({"unused", "RedundantSuppression"})
|
||||
public class APIResponse {
|
||||
|
||||
private List<Account> accounts = null;
|
||||
@ -35,11 +36,13 @@ public class APIResponse {
|
||||
private List<PeertubeNotification> peertubeNotifications = null;
|
||||
private List<Playlist> playlists = null;
|
||||
private List<String> domains = null;
|
||||
private List<Relationship> relationships = null;
|
||||
private Error error = null;
|
||||
private String since_id, max_id;
|
||||
private List<PlaylistElement> playlistForVideos;
|
||||
private Instance instance;
|
||||
private String stringData;
|
||||
private int statusCode;
|
||||
|
||||
public List<Account> getAccounts() {
|
||||
return accounts;
|
||||
@ -150,4 +153,20 @@ public class APIResponse {
|
||||
public void setStringData(String stringData) {
|
||||
this.stringData = stringData;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public List<Relationship> getRelationships() {
|
||||
return relationships;
|
||||
}
|
||||
|
||||
public void setRelationships(List<Relationship> relationships) {
|
||||
this.relationships = relationships;
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,14 @@ 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.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
|
||||
@ -34,6 +39,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Authenticator;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -41,6 +47,7 @@ import java.net.MalformedURLException;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -55,16 +62,19 @@ import java.util.regex.Pattern;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import app.fedilab.fedilabtube.MainActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.helper.FileNameCleaner;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnDownloadInterface;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@SuppressWarnings({"unused", "RedundantSuppression"})
|
||||
public class HttpsConnection {
|
||||
|
||||
|
||||
private static final String LINE_FEED = "\r\n";
|
||||
private HttpsURLConnection httpsURLConnection;
|
||||
private String since_id, max_id;
|
||||
private Context context;
|
||||
@ -107,6 +117,65 @@ public class HttpsConnection {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user credentials
|
||||
*
|
||||
* @param _mContext Context
|
||||
* @param token String
|
||||
* @param client_id String
|
||||
* @param client_secret String
|
||||
* @param refresh_token String
|
||||
* @param host String
|
||||
*/
|
||||
public static void updateCredential(Context _mContext, String token, String client_id, String client_secret, String refresh_token, String host) {
|
||||
new Thread(() -> {
|
||||
Account account;
|
||||
String instance;
|
||||
if (host.startsWith("tube")) {
|
||||
instance = host;
|
||||
} else {
|
||||
instance = Helper.getPeertubeUrl(host);
|
||||
}
|
||||
account = new PeertubeAPI(_mContext).verifyCredentials(token, instance);
|
||||
if (account == null)
|
||||
return;
|
||||
try {
|
||||
//At the state the instance can be encoded
|
||||
instance = URLDecoder.decode(instance, "utf-8");
|
||||
} catch (UnsupportedEncodingException ignored) {
|
||||
}
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
account.setToken(token);
|
||||
account.setClient_id(client_id);
|
||||
account.setClient_secret(client_secret);
|
||||
account.setRefresh_token(refresh_token);
|
||||
account.setInstance(instance);
|
||||
SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
boolean userExists = new AccountDAO(_mContext, db).userExist(account);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||
editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator());
|
||||
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin());
|
||||
if (!host.startsWith("tube")) {
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
}
|
||||
editor.apply();
|
||||
if (userExists)
|
||||
new AccountDAO(_mContext, db).updateAccountCredential(account);
|
||||
else {
|
||||
if (account.getUsername() != null && account.getCreated_at() != null)
|
||||
new AccountDAO(_mContext, db).insertAccount(account);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
Intent mainActivity = new Intent(_mContext, MainActivity.class);
|
||||
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.ADD_USER_INTENT);
|
||||
_mContext.startActivity(mainActivity);
|
||||
((Activity) _mContext).finish();
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get calls
|
||||
@ -158,10 +227,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 +261,6 @@ public class HttpsConnection {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public String get(String urlConnection) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
||||
|
||||
|
||||
@ -243,6 +309,93 @@ public class HttpsConnection {
|
||||
return response;
|
||||
}
|
||||
|
||||
public String postBoundary(boundaryType type, 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 (type == boundaryType.POST) {
|
||||
httpsURLConnection.setRequestMethod("POST");
|
||||
} else if (type == boundaryType.PUT) {
|
||||
httpsURLConnection.setRequestMethod("PUT");
|
||||
}
|
||||
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 +424,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));
|
||||
|
||||
|
||||
@ -311,71 +462,6 @@ public class HttpsConnection {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Download method which works for http and https connections
|
||||
* @param downloadUrl String download url
|
||||
* @param listener OnDownloadInterface, listener which manages progress
|
||||
*/
|
||||
public void download(final String downloadUrl, final OnDownloadInterface listener) {
|
||||
new Thread(() -> {
|
||||
URL url;
|
||||
HttpsURLConnection httpsURLConnection;
|
||||
try {
|
||||
url = new URL(downloadUrl);
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
int responseCode = httpsURLConnection.getResponseCode();
|
||||
|
||||
// always check HTTP response code first
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
String fileName = "";
|
||||
String disposition = httpsURLConnection.getHeaderField("Content-Disposition");
|
||||
|
||||
if (disposition != null) {
|
||||
// extracts file name from header field
|
||||
int index = disposition.indexOf("filename=");
|
||||
if (index > 0) {
|
||||
fileName = disposition.substring(index + 10,
|
||||
disposition.length() - 1);
|
||||
}
|
||||
} else {
|
||||
// extracts file name from URL
|
||||
fileName = downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1
|
||||
);
|
||||
}
|
||||
fileName = FileNameCleaner.cleanFileName(fileName);
|
||||
// opens input stream from the HTTP connection
|
||||
InputStream inputStream = httpsURLConnection.getInputStream();
|
||||
File saveDir = context.getCacheDir();
|
||||
final String saveFilePath = saveDir + File.separator + fileName;
|
||||
|
||||
// opens an output stream to save into file
|
||||
FileOutputStream outputStream = new FileOutputStream(saveFilePath);
|
||||
|
||||
int bytesRead;
|
||||
byte[] buffer = new byte[CHUNK_SIZE];
|
||||
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
outputStream.close();
|
||||
inputStream.close();
|
||||
} else {
|
||||
final Error error = new Error();
|
||||
error.setError(String.valueOf(responseCode));
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
error.setError(context.getString(R.string.toast_error));
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
public InputStream getPicture(final String downloadUrl) {
|
||||
|
||||
URL url;
|
||||
@ -495,10 +581,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 +627,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 +656,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 +724,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);
|
||||
@ -690,7 +769,6 @@ public class HttpsConnection {
|
||||
return max_id;
|
||||
}
|
||||
|
||||
|
||||
private void getSinceMaxId() {
|
||||
|
||||
if (httpsURLConnection == null)
|
||||
@ -735,6 +813,10 @@ public class HttpsConnection {
|
||||
}
|
||||
}
|
||||
|
||||
public enum boundaryType {
|
||||
POST,
|
||||
PUT
|
||||
}
|
||||
|
||||
public class HttpsConnectionException extends Exception {
|
||||
|
||||
|
@ -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"));
|
||||
}
|
||||
@ -224,17 +227,24 @@ public class PeertubeAPI {
|
||||
*/
|
||||
public static Peertube parsePeertube(JSONObject resobj) {
|
||||
Peertube peertube = new Peertube();
|
||||
if (resobj.has("video")) {
|
||||
if (resobj.has("video") && !resobj.isNull("video")) {
|
||||
try {
|
||||
resobj = resobj.getJSONObject("video");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (!resobj.has("name")) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
peertube.setId(resobj.getString("id"));
|
||||
peertube.setCache(resobj);
|
||||
if (resobj.has("uuid")) {
|
||||
peertube.setUuid(resobj.getString("uuid"));
|
||||
}
|
||||
|
||||
peertube.setName(resobj.getString("name"));
|
||||
peertube.setDescription(resobj.getString("description"));
|
||||
peertube.setEmbedPath(resobj.getString("embedPath"));
|
||||
@ -254,28 +264,35 @@ 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<>();
|
||||
LinkedHashMap<Integer, String> license = new LinkedHashMap<>();
|
||||
LinkedHashMap<Integer, String> privacy = new LinkedHashMap<>();
|
||||
category.put(resobj.getJSONObject("category").getInt("id"), resobj.getJSONObject("category").getString("label"));
|
||||
|
||||
if (!resobj.getJSONObject("category").isNull("id")) {
|
||||
license.put(resobj.getJSONObject("category").getInt("id"), resobj.getJSONObject("category").getString("label"));
|
||||
} else {
|
||||
license.put(1, resobj.getJSONObject("category").getString("label"));
|
||||
}
|
||||
if (!resobj.getJSONObject("licence").isNull("id")) {
|
||||
license.put(resobj.getJSONObject("licence").getInt("id"), resobj.getJSONObject("licence").getString("label"));
|
||||
} else {
|
||||
license.put(1, 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);
|
||||
peertube.setPrivacy(privacy);
|
||||
} catch (Exception ignored) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -344,7 +361,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 +368,6 @@ public class PeertubeAPI {
|
||||
resolutions.add(attObj.getJSONObject("resolution").getString("id"));
|
||||
}
|
||||
peertube.setResolution(resolutions);
|
||||
peertube.setStreamService(false);
|
||||
}
|
||||
try {
|
||||
LinkedHashMap<String, String> langue = new LinkedHashMap<>();
|
||||
@ -393,7 +408,9 @@ public class PeertubeAPI {
|
||||
playlist.setDescription(resobj.getString("description"));
|
||||
playlist.setDisplayName(resobj.getString("displayName"));
|
||||
playlist.setLocal(resobj.getBoolean("isLocal"));
|
||||
playlist.setVideoChannelId(resobj.getString("videoChannel"));
|
||||
if (resobj.has("videoChannel") && !resobj.isNull("videoChannel")) {
|
||||
playlist.setVideoChannelId(resobj.getJSONObject("videoChannel").getString("id"));
|
||||
}
|
||||
playlist.setThumbnailPath(resobj.getString("thumbnailPath"));
|
||||
playlist.setOwnerAccount(parseAccountResponsePeertube(resobj.getJSONObject("ownerAccount")));
|
||||
playlist.setVideosLength(resobj.getInt("videosLength"));
|
||||
@ -424,16 +441,19 @@ public class PeertubeAPI {
|
||||
private static Account parseAccountResponsePeertube(JSONObject accountObject) {
|
||||
Account account = new Account();
|
||||
try {
|
||||
account.setId(accountObject.get("id").toString());
|
||||
account.setUuid(accountObject.get("id").toString());
|
||||
account.setUsername(accountObject.get("name").toString());
|
||||
account.setAcct(accountObject.get("name").toString() + "@" + accountObject.get("host"));
|
||||
account.setDisplay_name(accountObject.get("name").toString());
|
||||
account.setHost(accountObject.get("host").toString());
|
||||
account.setId(accountObject.getString("id"));
|
||||
account.setUuid(accountObject.getString("id"));
|
||||
account.setUsername(accountObject.getString("name"));
|
||||
account.setAcct(accountObject.getString("name") + "@" + accountObject.get("host"));
|
||||
account.setDisplay_name(accountObject.get("displayName").toString());
|
||||
account.setHost(accountObject.getString("host"));
|
||||
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()));
|
||||
account.setCreated_at(Helper.mstStringToDate(accountObject.getString("createdAt")));
|
||||
else
|
||||
account.setCreated_at(new Date());
|
||||
if (accountObject.has("followersCount"))
|
||||
@ -446,14 +466,16 @@ public class PeertubeAPI {
|
||||
account.setFollowing_count(0);
|
||||
account.setStatuses_count(0);
|
||||
if (accountObject.has("description"))
|
||||
account.setNote(accountObject.get("description").toString());
|
||||
account.setNote(accountObject.getString("description"));
|
||||
else
|
||||
account.setNote("");
|
||||
|
||||
account.setUrl(accountObject.get("url").toString());
|
||||
if (accountObject.has("url")) {
|
||||
account.setUrl(accountObject.getString("url"));
|
||||
}
|
||||
if (accountObject.has("avatar") && !accountObject.isNull("avatar")) {
|
||||
account.setAvatar(accountObject.getJSONObject("avatar").get("path").toString());
|
||||
account.setAvatar_static(accountObject.getJSONObject("avatar").get("path").toString());
|
||||
account.setAvatar(accountObject.getJSONObject("avatar").getString("path"));
|
||||
account.setAvatar_static(accountObject.getJSONObject("avatar").getString("path"));
|
||||
} else {
|
||||
account.setAvatar("null");
|
||||
account.setAvatar_static("null");
|
||||
@ -718,6 +740,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 +816,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();
|
||||
}
|
||||
}
|
||||
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();
|
||||
@ -780,7 +857,7 @@ public class PeertubeAPI {
|
||||
params.put("username", accountCreation.getUsername());
|
||||
params.put("email", accountCreation.getEmail());
|
||||
params.put("password", accountCreation.getPassword());
|
||||
new HttpsConnection(context).post(getAbsoluteUrl("/users/register"), 30, params, null);
|
||||
new HttpsConnection(context).post(getAbsoluteUrlForInstance(accountCreation.getInstance(), "/users/register"), 30, params, null);
|
||||
apiResponse.setStringData(accountCreation.getEmail());
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
@ -791,6 +868,65 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a channel fot the authenticated user
|
||||
*
|
||||
* @param acct String
|
||||
* @param channelCreation ChannelCreation
|
||||
*/
|
||||
public void updateChannel(String acct, 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.put(getAbsoluteUrl(String.format("/video-channels/%s", acct)), 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 +943,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 +961,7 @@ public class PeertubeAPI {
|
||||
* @param accountId String account fetched
|
||||
* @return Account entity
|
||||
*/
|
||||
@SuppressWarnings({"unused", "RedundantSuppression"})
|
||||
public Account getAccount(String accountId) {
|
||||
|
||||
account = new Account();
|
||||
@ -838,27 +977,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1103,34 +1252,65 @@ public class PeertubeAPI {
|
||||
*/
|
||||
public APIResponse getSubscriptionsTL(String max_id) {
|
||||
try {
|
||||
return getTL("/users/me/subscriptions/videos", "-publishedAt", null, max_id, null, null);
|
||||
return getTL(true, "/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();
|
||||
setError(e.getStatusCode(), e);
|
||||
return apiResponse;
|
||||
}
|
||||
if (values.containsKey("refresh_token") && values.get("refresh_token") != null)
|
||||
targetedAccount.setRefresh_token(values.get("refresh_token"));
|
||||
new AccountDAO(context, db).updateAccount(targetedAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves subscriptions *synchronously*
|
||||
*
|
||||
* @param max_id String id max
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getSubscriptionUsers(String max_id) {
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
try {
|
||||
return getTL("/users/me/subscriptions/videos", "-publishedAt", null, max_id, null, null);
|
||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||
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);
|
||||
return apiResponse;
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setAccounts(accounts);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1141,7 +1321,7 @@ public class PeertubeAPI {
|
||||
*/
|
||||
public APIResponse getOverviewTL(String max_id) {
|
||||
try {
|
||||
return getTL("/overviews/videos", null, null, max_id, null, null);
|
||||
return getTL(false, "/overviews/videos", null, null, max_id, null, null);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
return apiResponse;
|
||||
@ -1156,7 +1336,7 @@ public class PeertubeAPI {
|
||||
*/
|
||||
public APIResponse getLikedTL(String max_id) {
|
||||
try {
|
||||
return getTL("/videos/", "-likes", null, max_id, null, null);
|
||||
return getTL(false, "/videos/", "-likes", null, max_id, null, null);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
return apiResponse;
|
||||
@ -1171,7 +1351,7 @@ public class PeertubeAPI {
|
||||
*/
|
||||
public APIResponse getTrendingTL(String max_id) {
|
||||
try {
|
||||
return getTL("/videos/", "-trending", null, max_id, null, null);
|
||||
return getTL(false, "/videos/", "-trending", null, max_id, null, null);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
return apiResponse;
|
||||
@ -1186,7 +1366,7 @@ public class PeertubeAPI {
|
||||
*/
|
||||
public APIResponse getRecentlyAddedTL(String max_id) {
|
||||
try {
|
||||
return getTL("/videos/", "-publishedAt", null, max_id, null, null);
|
||||
return getTL(false, "/videos/", "-publishedAt", null, max_id, null, null);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
return apiResponse;
|
||||
@ -1201,7 +1381,7 @@ public class PeertubeAPI {
|
||||
*/
|
||||
public APIResponse getLocalTL(String max_id) {
|
||||
try {
|
||||
return getTL("/videos/", "-publishedAt", "local", max_id, null, null);
|
||||
return getTL(true, "/videos/", "-publishedAt", "local", max_id, null, null);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
return apiResponse;
|
||||
@ -1216,7 +1396,7 @@ public class PeertubeAPI {
|
||||
*/
|
||||
public APIResponse getPublicTL(String max_id) {
|
||||
try {
|
||||
return getTL("/videos/", "-publishedAt", null, max_id, null, null);
|
||||
return getTL(false, "/videos/", "-publishedAt", null, max_id, null, null);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
return apiResponse;
|
||||
@ -1231,7 +1411,7 @@ public class PeertubeAPI {
|
||||
* @return APIResponse
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private APIResponse getTL(String action, String sort, String filter, String max_id, String since_id, String min_id) throws HttpsConnection.HttpsConnectionException {
|
||||
private APIResponse getTL(boolean needToken, String action, String sort, String filter, String max_id, String since_id, String min_id) throws HttpsConnection.HttpsConnectionException {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if (max_id != null)
|
||||
@ -1253,7 +1433,7 @@ public class PeertubeAPI {
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(action), 60, params, needToken ? prefKeyOauthTokenT : null);
|
||||
if (!action.equals("/overviews/videos")) {
|
||||
JSONArray values = new JSONObject(response).getJSONArray("data");
|
||||
peertubes = parsePeertube(values);
|
||||
@ -1325,6 +1505,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 +1630,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 +1682,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 +1747,49 @@ 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(HttpsConnection.boundaryType.POST, getAbsoluteUrl("/video-playlists/"), 60, params, prefKeyOauthTokenT);
|
||||
playlistId = new JSONObject(response).getJSONObject("videoPlaylist").getString("id");
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return playlistId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a Playlist
|
||||
*
|
||||
* @param playlistElement PlaylistElement, the playlist elements
|
||||
*/
|
||||
public void updatePlaylist(PlaylistElement playlistElement) throws HttpsConnection.HttpsConnectionException {
|
||||
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());
|
||||
httpsConnection.postBoundary(HttpsConnection.boundaryType.PUT, getAbsoluteUrl(String.format("/video-playlists/%s", playlistElement.getPlaylistId())), 60, params, prefKeyOauthTokenT);
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Playlist
|
||||
*
|
||||
@ -1685,6 +1944,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 +1988,6 @@ public class PeertubeAPI {
|
||||
return peertubeNotifications;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse json response for several howto
|
||||
*
|
||||
@ -1723,8 +2003,10 @@ public class PeertubeAPI {
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Peertube peertube = parsePeertube(resobj);
|
||||
i++;
|
||||
if (peertube != null && (peertube.getName() == null || !peertube.getName().toLowerCase().contains("youtube video downloader"))) {
|
||||
peertubes.add(peertube);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
}
|
||||
@ -1774,6 +2056,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 +2106,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;
|
||||
}
|
||||
@ -1834,14 +2135,30 @@ public class PeertubeAPI {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private String getAbsoluteUrlForInstance(String instance, String action) {
|
||||
return "https://" + instance + "/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
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -22,6 +22,7 @@ public class AccountCreation {
|
||||
private String email;
|
||||
private String password;
|
||||
private String passwordConfirm;
|
||||
private String instance;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
@ -62,4 +63,12 @@ public class AccountCreation {
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setInstance(String instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
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 id;
|
||||
private String displayName;
|
||||
private String name;
|
||||
private String description;
|
||||
private String support;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -49,9 +49,9 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import app.fedilab.fedilabtube.helper.CustomQuoteSpan;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ -88,7 +88,7 @@ public class Status implements Parcelable {
|
||||
private String language;
|
||||
private String content;
|
||||
private SpannableString contentSpan;
|
||||
private transient RetrieveFeedsAsyncTask.Type type;
|
||||
private transient FeedsVM.Type type;
|
||||
private String conversationId;
|
||||
private String contentType;
|
||||
|
||||
@ -118,7 +118,7 @@ public class Status implements Parcelable {
|
||||
this.content = in.readString();
|
||||
this.contentSpan = (SpannableString) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
|
||||
int tmpType = in.readInt();
|
||||
this.type = tmpType == -1 ? null : RetrieveFeedsAsyncTask.Type.values()[tmpType];
|
||||
this.type = tmpType == -1 ? null : FeedsVM.Type.values()[tmpType];
|
||||
this.conversationId = in.readString();
|
||||
this.contentType = in.readString();
|
||||
}
|
||||
@ -620,11 +620,11 @@ public class Status implements Parcelable {
|
||||
this.replies_count = replies_count;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask.Type getType() {
|
||||
public FeedsVM.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(RetrieveFeedsAsyncTask.Type type) {
|
||||
public void setType(FeedsVM.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
@ -16,12 +16,12 @@ package app.fedilab.fedilabtube.client.entities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class StatusDrawerParams {
|
||||
private List<Status> statuses;
|
||||
private RetrieveFeedsAsyncTask.Type type;
|
||||
private FeedsVM.Type type;
|
||||
private String targetedId;
|
||||
private int position;
|
||||
|
||||
@ -34,11 +34,11 @@ public class StatusDrawerParams {
|
||||
this.statuses = statuses;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask.Type getType() {
|
||||
public FeedsVM.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(RetrieveFeedsAsyncTask.Type type) {
|
||||
public void setType(FeedsVM.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,122 @@
|
||||
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 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.entities.Account;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
||||
|
||||
public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
EventListener listener;
|
||||
private List<Account> accounts;
|
||||
private Context context;
|
||||
|
||||
public AccountsHorizontalListAdapter(List<Account> accounts, EventListener listener) {
|
||||
this.accounts = accounts;
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -14,50 +14,66 @@ 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;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelStoreOwner;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.AccountActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.ShowAccountActivity;
|
||||
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.Error;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayPlaylistsFragment;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
|
||||
public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnPostActionInterface {
|
||||
public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
public AllAccountsRemoved allAccountsRemoved;
|
||||
public EditAlertDialog editAlertDialog;
|
||||
private List<Account> accounts;
|
||||
|
||||
private Context context;
|
||||
private AccountsListAdapter accountsListAdapter;
|
||||
private AccountsVM.accountFetch type;
|
||||
|
||||
public AccountsListAdapter(String targetedId, List<Account> accounts) {
|
||||
public AccountsListAdapter(AccountsVM.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,21 +86,67 @@ 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);
|
||||
if (type == AccountsVM.accountFetch.CHANNEL) {
|
||||
holder.account_action.hide();
|
||||
holder.more_actions.setVisibility(View.VISIBLE);
|
||||
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 = () -> {
|
||||
accounts.remove(account);
|
||||
notifyDataSetChanged();
|
||||
if (accounts.size() == 0) {
|
||||
allAccountsRemoved.onAllAccountsRemoved();
|
||||
}
|
||||
};
|
||||
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 == AccountsVM.accountFetch.MUTED) {
|
||||
holder.account_action.setOnClickListener(v -> {
|
||||
PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.UNMUTE, account.getAcct(), null, null).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.UNMUTE, apiResponse));
|
||||
});
|
||||
} else {
|
||||
holder.account_action.hide();
|
||||
}
|
||||
|
||||
|
||||
PeertubeAPI.StatusAction doAction = null;
|
||||
holder.account_follow.hide();
|
||||
|
||||
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("@", ""));
|
||||
holder.account_un.setText(String.format("@%s", account.getUsername()));
|
||||
holder.account_ac.setText(account.getAcct());
|
||||
if (account.getUsername().equals(account.getAcct()))
|
||||
holder.account_ac.setVisibility(View.GONE);
|
||||
else
|
||||
holder.account_ac.setVisibility(View.VISIBLE);
|
||||
if (account.getNote() == null) {
|
||||
account.setNote("");
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
holder.account_ds.setText(Html.fromHtml(account.getNote(), Html.FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
@ -96,14 +158,77 @@ 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 == AccountsVM.accountFetch.MUTED) {
|
||||
holder.account_action.show();
|
||||
holder.account_action.setImageResource(R.drawable.ic_baseline_volume_mute_24);
|
||||
}
|
||||
|
||||
holder.more_actions.setOnClickListener(view -> {
|
||||
PopupMenu popup = new PopupMenu(context, holder.more_actions);
|
||||
popup.getMenuInflater()
|
||||
.inflate(R.menu.playlist_menu, popup.getMenu());
|
||||
if (accounts.size() == 1) {
|
||||
popup.getMenu().findItem(R.id.action_delete).setEnabled(false);
|
||||
}
|
||||
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_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();
|
||||
break;
|
||||
case R.id.action_edit:
|
||||
if (context instanceof AccountActivity) {
|
||||
editAlertDialog.show(account);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
popup.show();
|
||||
});
|
||||
|
||||
holder.account_pp.setOnClickListener(v -> {
|
||||
@ -117,6 +242,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -129,69 +255,70 @@ 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) {
|
||||
Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show();
|
||||
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null) {
|
||||
Toasty.error(context, apiResponse.getError().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)) {
|
||||
if (account.getId().equals(apiResponse.getTargetedId())) {
|
||||
account.setFollowType(Account.followAction.FOLLOW);
|
||||
account.setMakingAction(false);
|
||||
}
|
||||
}
|
||||
accountsListAdapter.notifyDataSetChanged();
|
||||
}*/
|
||||
}
|
||||
if (statusAction == PeertubeAPI.StatusAction.UNMUTE) {
|
||||
Account tmpAccount = null;
|
||||
int position = 0;
|
||||
for (Account account : accounts) {
|
||||
if (account.getAcct().equals(apiResponse.getTargetedId())) {
|
||||
tmpAccount = account;
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
if (tmpAccount != null) {
|
||||
accounts.remove(position);
|
||||
accountsListAdapter.notifyItemRemoved(position);
|
||||
}
|
||||
}
|
||||
if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW) {
|
||||
for (Account account : accounts) {
|
||||
if (account.getId().equals(targetedId)) {
|
||||
if (account.getId().equals(apiResponse.getTargetedId())) {
|
||||
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) {
|
||||
}
|
||||
if (accounts.size() == 0) {
|
||||
allAccountsRemoved.onAllAccountsRemoved();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface AllAccountsRemoved {
|
||||
void onAllAccountsRemoved();
|
||||
}
|
||||
|
||||
public interface EditAlertDialog {
|
||||
void show(Account account);
|
||||
}
|
||||
|
||||
private static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView account_pp;
|
||||
TextView account_ac;
|
||||
TextView account_dn;
|
||||
TextView account_un;
|
||||
TextView account_ds;
|
||||
TextView account_sc;
|
||||
TextView account_fgc;
|
||||
TextView account_frc;
|
||||
ImageButton more_actions;
|
||||
LinearLayout account_info;
|
||||
FloatingActionButton account_follow;
|
||||
FloatingActionButton account_action;
|
||||
LinearLayout account_container;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
@ -199,13 +326,13 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
account_pp = itemView.findViewById(R.id.account_pp);
|
||||
account_dn = itemView.findViewById(R.id.account_dn);
|
||||
account_ac = itemView.findViewById(R.id.account_ac);
|
||||
account_un = itemView.findViewById(R.id.account_un);
|
||||
account_ds = itemView.findViewById(R.id.account_ds);
|
||||
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);
|
||||
more_actions = itemView.findViewById(R.id.more_actions);
|
||||
account_container = itemView.findViewById(R.id.account_container);
|
||||
}
|
||||
}
|
||||
|
@ -36,14 +36,12 @@ import app.fedilab.fedilabtube.PeertubeActivity;
|
||||
import app.fedilab.fedilabtube.PeertubeEditUploadActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.ShowAccountActivity;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnActionInterface;
|
||||
|
||||
|
||||
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnActionInterface {
|
||||
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private List<Peertube> peertubes;
|
||||
private Context context;
|
||||
@ -74,28 +72,43 @@ 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().getHost().compareTo(Helper.getLiveInstance(context)) == 0 && userId != null && peertube.getAccount().getId() != null && peertube.getAccount().getId().compareTo(userId) == 0;
|
||||
|
||||
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_duration.setText(Helper.secondsToString(peertube.getDuration()));
|
||||
holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, peertube.getCreated_at())));
|
||||
holder.peertube_views.setText(context.getString(R.string.number_view_video, Helper.withSuffix(peertube.getView())));
|
||||
|
||||
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();
|
||||
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);
|
||||
});
|
||||
@ -151,11 +164,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActionDone(APIResponse apiResponse, int statusCode) {
|
||||
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
LinearLayout main_container, bottom_container;
|
||||
ImageView peertube_profile, peertube_video_image;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -17,30 +17,36 @@ 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 androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelStoreOwner;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import app.fedilab.fedilabtube.AllPlaylistsActivity;
|
||||
import app.fedilab.fedilabtube.PlaylistsActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.Playlist;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
|
||||
|
||||
public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInterface {
|
||||
public class PlaylistAdapter extends BaseAdapter {
|
||||
|
||||
private List<Playlist> playlists;
|
||||
private LayoutInflater layoutInflater;
|
||||
@ -78,22 +84,34 @@ 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();
|
||||
}
|
||||
|
||||
if (playlist.getOwnerAccount() != null) {
|
||||
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,7 +119,19 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
||||
holder.search_container.setOnLongClickListener(v -> {
|
||||
if (playlist.getDisplayName().compareTo("Watch later") == 0) {
|
||||
holder.playlist_more.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.playlist_more.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
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));
|
||||
@ -109,27 +139,39 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
|
||||
.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);
|
||||
PlaylistsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class);
|
||||
viewModel.manage(PlaylistsVM.action.DELETE_PLAYLIST, playlist, null, null).observe((LifecycleOwner) context, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.DELETE_PLAYLIST, apiResponse));
|
||||
|
||||
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:
|
||||
if (context instanceof AllPlaylistsActivity) {
|
||||
((AllPlaylistsActivity) context).manageAlert(playlist);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
popup.show();
|
||||
|
||||
return false;
|
||||
});
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,7 +17,6 @@ package app.fedilab.fedilabtube.drawer;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
@ -35,6 +34,9 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelStoreOwner;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.List;
|
||||
@ -43,20 +45,19 @@ import java.util.regex.Pattern;
|
||||
|
||||
import app.fedilab.fedilabtube.PeertubeActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask;
|
||||
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.Status;
|
||||
import app.fedilab.fedilabtube.client.entities.StatusDrawerParams;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
|
||||
public class StatusListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnPostActionInterface {
|
||||
public class StatusListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
|
||||
private Context context;
|
||||
@ -121,7 +122,8 @@ public class StatusListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
builderInner.setMessage(R.string.delete_comment_confirm);
|
||||
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||
new PostActionAsyncTask(context, PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT, PeertubeActivity.video_id, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT, PeertubeActivity.video_id, status.getId(), null).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT, apiResponse));
|
||||
dialog.dismiss();
|
||||
});
|
||||
builderInner.show();
|
||||
@ -173,18 +175,17 @@ public class StatusListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
Helper.loadGiF(context, accountForUrl, holder.status_account_profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String targetedId, Error error) {
|
||||
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) {
|
||||
|
||||
if (error != null) {
|
||||
Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show();
|
||||
if (apiResponse.getError() != null) {
|
||||
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (statusAction == PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT) {
|
||||
int position = 0;
|
||||
for (Status status : statuses) {
|
||||
if (status.getId().equals(targetedId)) {
|
||||
if (status.getId().equals(apiResponse.getTargetedId())) {
|
||||
statuses.remove(status);
|
||||
statusListAdapter.notifyItemRemoved(position);
|
||||
break;
|
||||
|
@ -14,63 +14,78 @@ 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.Button;
|
||||
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.lifecycle.ViewModelProvider;
|
||||
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.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 app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
|
||||
public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccountsInterface {
|
||||
public class DisplayAccountsFragment extends Fragment implements AccountsListAdapter.AllAccountsRemoved, AccountsListAdapter.EditAlertDialog {
|
||||
|
||||
private boolean flag_loading;
|
||||
private Context context;
|
||||
private AsyncTask<Void, Void, Void> 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 AccountsVM.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 = (AccountsVM.accountFetch) bundle.getSerializable("accountFetch");
|
||||
}
|
||||
name = bundle.getString("name", null);
|
||||
}
|
||||
max_id = null;
|
||||
@ -81,16 +96,25 @@ 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 -> manageAlert(null));
|
||||
}
|
||||
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;
|
||||
accountsListAdapter.editAlertDialog = this;
|
||||
lv_accounts.setAdapter(accountsListAdapter);
|
||||
|
||||
TextView no_action_text = rootView.findViewById(R.id.no_action_text);
|
||||
if (accountFetch == AccountsVM.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 +127,13 @@ 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);
|
||||
AccountsVM viewModel = new ViewModelProvider(DisplayAccountsFragment.this).get(AccountsVM.class);
|
||||
if (accountFetch == null) {
|
||||
viewModel.getAccounts(null, name, AccountsVM.accountFetch.SINGLE_ACCOUNT).observe(DisplayAccountsFragment.this.requireActivity(), apiResponse -> manageViewAccounts(apiResponse));
|
||||
} else {
|
||||
String param = accountFetch == AccountsVM.accountFetch.CHANNEL ? name : max_id;
|
||||
viewModel.getAccounts(param, null, accountFetch).observe(DisplayAccountsFragment.this.requireActivity(), apiResponse -> manageViewAccounts(apiResponse));
|
||||
}
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
@ -113,11 +143,26 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
||||
}
|
||||
});
|
||||
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
|
||||
|
||||
asyncTask = new RetrieveAccountsAsyncTask(context, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
||||
if (accountFetch == null) {
|
||||
viewModel.getAccounts(null, name, AccountsVM.accountFetch.SINGLE_ACCOUNT).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
|
||||
} else {
|
||||
String param = accountFetch == AccountsVM.accountFetch.CHANNEL ? name : null;
|
||||
viewModel.getAccounts(param, null, accountFetch).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
|
||||
}
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (accountFetch == AccountsVM.accountFetch.CHANNEL) {
|
||||
action_button.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
action_button.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
@ -136,10 +181,9 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||
asyncTask.cancel(true);
|
||||
}
|
||||
|
||||
public void scrollToTop() {
|
||||
@ -147,8 +191,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
||||
lv_accounts.setAdapter(accountsListAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveAccounts(APIResponse apiResponse) {
|
||||
private void manageViewAccounts(APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
if (apiResponse.getError() != null) {
|
||||
@ -159,7 +202,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
||||
return;
|
||||
}
|
||||
flag_loading = (apiResponse.getMax_id() == null);
|
||||
|
||||
List<Account> accounts = apiResponse.getAccounts();
|
||||
if (!swiped && firstLoad && (accounts == null || accounts.size() == 0))
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
@ -167,9 +209,8 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
|
||||
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 +230,133 @@ 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);
|
||||
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
||||
if (accountFetch == null) {
|
||||
viewModel.getAccounts(null, name, AccountsVM.accountFetch.SINGLE_ACCOUNT).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
|
||||
} else {
|
||||
String param = accountFetch == AccountsVM.accountFetch.CHANNEL ? name : null;
|
||||
viewModel.getAccounts(param, null, accountFetch).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAllAccountsRemoved() {
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
|
||||
public void manageAlert(ChannelCreation oldChannelValues) {
|
||||
|
||||
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);
|
||||
if (oldChannelValues != null) {
|
||||
display_name.setText(oldChannelValues.getDisplayName());
|
||||
name.setText(oldChannelValues.getName());
|
||||
description.setText(oldChannelValues.getDescription());
|
||||
name.setEnabled(false);
|
||||
}
|
||||
dialogBuilder.setPositiveButton(R.string.validate, null);
|
||||
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||
|
||||
AlertDialog alertDialog = dialogBuilder.create();
|
||||
|
||||
alertDialog.setOnShowListener(dialogInterface -> {
|
||||
|
||||
Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
button.setOnClickListener(view -> {
|
||||
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 {
|
||||
if (oldChannelValues == null) {
|
||||
new PeertubeAPI(context).createChannel(channelCreation);
|
||||
} else {
|
||||
new PeertubeAPI(context).updateChannel(channelCreation.getName() + "@" + Helper.getLiveInstance(context), channelCreation);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
if (oldChannelValues == null) {
|
||||
Account channel = new Account();
|
||||
channel.setAcct(channelCreation.getName() + "@" + Helper.getLiveInstance(context));
|
||||
channel.setUsername(channelCreation.getName());
|
||||
channel.setDisplay_name(channelCreation.getDisplayName());
|
||||
channel.setNote(channelCreation.getDescription());
|
||||
accounts.add(0, channel);
|
||||
accountsListAdapter.notifyItemInserted(0);
|
||||
} else {
|
||||
int position = 0;
|
||||
for (Account account : accounts) {
|
||||
if (account.getId().compareTo(oldChannelValues.getId()) == 0) {
|
||||
account.setNote(channelCreation.getDescription());
|
||||
account.setDisplay_name(channelCreation.getDisplayName());
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
accountsListAdapter.notifyItemChanged(position);
|
||||
}
|
||||
action_button.setEnabled(true);
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
action_button.setEnabled(true);
|
||||
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();
|
||||
alertDialog.dismiss();
|
||||
action_button.setEnabled(false);
|
||||
} else {
|
||||
Toasty.error(context, context.getString(R.string.error_display_name_channel), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
});
|
||||
if (oldChannelValues == null) {
|
||||
alertDialog.setTitle(getString(R.string.action_channel_create));
|
||||
} else {
|
||||
alertDialog.setTitle(getString(R.string.action_channel_edit));
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(Account account) {
|
||||
ChannelCreation oldChannelValues = new ChannelCreation();
|
||||
oldChannelValues.setName(account.getUsername());
|
||||
oldChannelValues.setDescription(account.getNote());
|
||||
oldChannelValues.setDisplayName(account.getDisplay_name());
|
||||
oldChannelValues.setId(account.getId());
|
||||
manageAlert(oldChannelValues);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,201 @@
|
||||
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.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.lifecycle.ViewModelProvider;
|
||||
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.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.PeertubeNotification;
|
||||
import app.fedilab.fedilabtube.drawer.PeertubeNotificationsListAdapter;
|
||||
import app.fedilab.fedilabtube.viewmodel.NotificationsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
|
||||
public class DisplayNotificationsFragment extends Fragment {
|
||||
|
||||
private boolean flag_loading;
|
||||
private Context context;
|
||||
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;
|
||||
NotificationsVM viewModel = new ViewModelProvider(DisplayNotificationsFragment.this).get(NotificationsVM.class);
|
||||
viewModel.getNotifications(null, max_id).observe(DisplayNotificationsFragment.this.requireActivity(), apiResponse -> manageVIewNotifications(apiResponse));
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
|
||||
|
||||
NotificationsVM viewModel = new ViewModelProvider(this).get(NotificationsVM.class);
|
||||
viewModel.getNotifications(null, null).observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
rootView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (getActivity() != null && getActivity() != null) {
|
||||
View action_button = getActivity().findViewById(R.id.action_button);
|
||||
if (action_button != null) {
|
||||
action_button.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
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);
|
||||
NotificationsVM viewModel = new ViewModelProvider(this).get(NotificationsVM.class);
|
||||
viewModel.getNotifications(null, null).observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications);
|
||||
|
||||
}
|
||||
|
||||
private void manageVIewNotifications(APIResponse apiResponse) {
|
||||
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);
|
||||
}
|
||||
}
|
@ -16,11 +16,10 @@ 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;
|
||||
@ -40,18 +39,12 @@ import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
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;
|
||||
@ -61,25 +54,24 @@ import java.util.Map;
|
||||
|
||||
import app.fedilab.fedilabtube.PlaylistsActivity;
|
||||
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 app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||
|
||||
|
||||
public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActionInterface, OnRetrievePeertubeInterface {
|
||||
public class DisplayPlaylistsFragment extends Fragment {
|
||||
|
||||
|
||||
private Context context;
|
||||
private AsyncTask<Void, Void, Void> asyncTask;
|
||||
private List<Playlist> playlists;
|
||||
private RelativeLayout mainLoader;
|
||||
private FloatingActionButton add_new;
|
||||
@ -110,14 +102,11 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
||||
playlists = new ArrayList<>();
|
||||
playlistAdapter = new PlaylistAdapter(context, playlists, textviewNoAction);
|
||||
lv_playlist.setAdapter(playlistAdapter);
|
||||
asyncTask = new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, DisplayPlaylistsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
|
||||
viewModel.manage(PlaylistsVM.action.GET_PLAYLIST, null, null, null).observe(DisplayPlaylistsFragment.this.requireActivity(), apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLIST, apiResponse));
|
||||
|
||||
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 +120,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);
|
||||
@ -142,14 +130,13 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
||||
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
|
||||
|
||||
|
||||
new RetrievePeertubeChannelsAsyncTask(context, DisplayPlaylistsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
ChannelsVM viewModelC = new ViewModelProvider(this).get(ChannelsVM.class);
|
||||
viewModelC.get().observe(DisplayPlaylistsFragment.this.requireActivity(), this::manageVIewChannels);
|
||||
|
||||
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) {
|
||||
|
||||
@ -174,57 +161,38 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
||||
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;
|
||||
PlaylistElement playlistElement = new PlaylistElement();
|
||||
playlistElement.setVideoChannelId(idChannel);
|
||||
playlistElement.setPrivacy(idPrivacy);
|
||||
playlistElement.setDisplayName(playlist.getDisplayName());
|
||||
playlistElement.setDescription(playlist.getDescription());
|
||||
new Thread(() -> {
|
||||
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;
|
||||
String returnedId = new PeertubeAPI(context).createPlaylist(playlistElement);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
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) {
|
||||
playlist.setId(returnedId);
|
||||
playlists.add(0, playlist);
|
||||
playlistAdapter.notifyDataSetChanged();
|
||||
};
|
||||
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);
|
||||
@ -233,11 +201,9 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
||||
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 -> {
|
||||
@ -267,15 +233,13 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||
asyncTask.cancel(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
add_new.setEnabled(true);
|
||||
if (apiResponse.getError() != null) {
|
||||
@ -283,7 +247,7 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionType == ManagePlaylistsAsyncTask.action.GET_PLAYLIST) {
|
||||
if (actionType == PlaylistsVM.action.GET_PLAYLIST) {
|
||||
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
||||
this.playlists.addAll(apiResponse.getPlaylists());
|
||||
playlistAdapter.notifyDataSetChanged();
|
||||
@ -291,7 +255,7 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
||||
} else {
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else if (actionType == ManagePlaylistsAsyncTask.action.CREATE_PLAYLIST) {
|
||||
} else if (actionType == PlaylistsVM.action.CREATE_PLAYLIST) {
|
||||
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
||||
Intent intent = new Intent(context, PlaylistsActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
@ -304,25 +268,14 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
||||
} else {
|
||||
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else if (actionType == ManagePlaylistsAsyncTask.action.DELETE_PLAYLIST) {
|
||||
} else if (actionType == PlaylistsVM.action.DELETE_PLAYLIST) {
|
||||
if (this.playlists.size() == 0)
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
||||
public void manageVIewChannels(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
|
@ -17,20 +17,21 @@ package app.fedilab.fedilabtube.fragment;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Rect;
|
||||
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.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.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -42,33 +43,34 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
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.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
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.OnRetrieveFeedsInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.SearchVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask.Type.POVERVIEW;
|
||||
import static app.fedilab.fedilabtube.viewmodel.FeedsVM.Type.POVERVIEW;
|
||||
import static app.fedilab.fedilabtube.viewmodel.FeedsVM.Type.PSUBSCRIPTIONS;
|
||||
|
||||
|
||||
public class DisplayStatusFragment extends Fragment implements OnPostActionInterface, OnRetrieveFeedsInterface {
|
||||
public class DisplayStatusFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener {
|
||||
|
||||
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private GridLayoutManager gLayoutManager;
|
||||
private boolean flag_loading;
|
||||
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 RetrieveFeedsAsyncTask.Type type;
|
||||
private List<Account> accounts;
|
||||
private FeedsVM.Type type;
|
||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||
private boolean firstLoad;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
@ -79,6 +81,12 @@ 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;
|
||||
private FeedsVM viewModelFeeds;
|
||||
private SearchVM viewModelSearch;
|
||||
private AccountsVM viewModelAccounts;
|
||||
|
||||
public DisplayStatusFragment() {
|
||||
}
|
||||
@ -90,6 +98,7 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
||||
|
||||
|
||||
peertubes = new ArrayList<>();
|
||||
accounts = new ArrayList<>();
|
||||
context = getContext();
|
||||
Bundle bundle = this.getArguments();
|
||||
|
||||
@ -97,7 +106,7 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
||||
search_peertube = bundle.getString("search_peertube", null);
|
||||
targetedId = bundle.getString("targetedid", null);
|
||||
ischannel = bundle.getBoolean("ischannel", false);
|
||||
type = (RetrieveFeedsAsyncTask.Type) bundle.get("type");
|
||||
type = (FeedsVM.Type) bundle.get("type");
|
||||
}
|
||||
|
||||
if (getArguments() != null && type == null) {
|
||||
@ -106,15 +115,19 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
||||
|
||||
|
||||
if (ischannel) {
|
||||
type = RetrieveFeedsAsyncTask.Type.CHANNEL;
|
||||
type = FeedsVM.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 +143,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);
|
||||
@ -140,31 +159,50 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
||||
lv_status.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
|
||||
lv_status.setLayoutManager(gLayoutManager);
|
||||
}
|
||||
|
||||
|
||||
viewModelAccounts = new ViewModelProvider(DisplayStatusFragment.this).get(AccountsVM.class);
|
||||
viewModelFeeds = new ViewModelProvider(DisplayStatusFragment.this).get(FeedsVM.class);
|
||||
viewModelSearch = new ViewModelProvider(DisplayStatusFragment.this).get(SearchVM.class);
|
||||
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
|
||||
if (context != null) {
|
||||
//Load data depending of the value
|
||||
if (search_peertube == null) { //Not a Peertube search
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", targetedId, DisplayStatusFragment.this).execute();
|
||||
viewModelFeeds.getVideos(type, "0", targetedId, forAccount).observe(DisplayStatusFragment.this.requireActivity(), this::manageVIewVideos);
|
||||
} else {
|
||||
asyncTask = new RetrievePeertubeSearchAsyncTask(context, "0", search_peertube, DisplayStatusFragment.this).execute();
|
||||
viewModelSearch.getVideos("0", search_peertube).observe(DisplayStatusFragment.this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
} else {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
if (context != null) {
|
||||
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();
|
||||
|
||||
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) {
|
||||
viewModelAccounts.getAccounts(max_id_accounts, null, AccountsVM.accountFetch.SUBSCRIPTION).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageViewAccounts(apiResponse));
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
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) {
|
||||
@ -174,9 +212,9 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
||||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
if (search_peertube == null) { //Not a Peertube search
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).execute();
|
||||
viewModelFeeds.getVideos(type, max_id, null, forAccount).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse));
|
||||
} else {
|
||||
asyncTask = new RetrievePeertubeSearchAsyncTask(context, max_id, search_peertube, DisplayStatusFragment.this).execute();
|
||||
viewModelSearch.getVideos(max_id, search_peertube).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse));
|
||||
}
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@ -193,9 +231,9 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
||||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
if (search_peertube == null) { //Not a Peertube search
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).execute();
|
||||
viewModelFeeds.getVideos(type, max_id, null, forAccount).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse));
|
||||
} else {
|
||||
asyncTask = new RetrievePeertubeSearchAsyncTask(context, max_id, search_peertube, DisplayStatusFragment.this).execute();
|
||||
viewModelSearch.getVideos(max_id, search_peertube).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse));
|
||||
}
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@ -207,8 +245,15 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
||||
}
|
||||
});
|
||||
}
|
||||
if (type == PSUBSCRIPTIONS) {
|
||||
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
||||
viewModel.getAccounts(max_id, null, AccountsVM.accountFetch.SUBSCRIPTION).observe(DisplayStatusFragment.this.requireActivity(), this::manageViewAccounts);
|
||||
}
|
||||
|
||||
|
||||
display_all.setOnClickListener(v -> {
|
||||
forAccount = null;
|
||||
pullToRefresh();
|
||||
});
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@ -250,12 +295,28 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||
asyncTask.cancel(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
|
||||
private void manageViewAccounts(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void manageVIewVideos(APIResponse apiResponse) {
|
||||
//hide loaders
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
@ -327,27 +388,31 @@ 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();
|
||||
if (forAccount == null) {
|
||||
for (Account account : accounts) {
|
||||
account.setSelected(false);
|
||||
}
|
||||
accountsHorizontalListAdapter.notifyItemRangeRemoved(0, accounts.size());
|
||||
}
|
||||
if (search_peertube == null) { //Not a Peertube search
|
||||
viewModelFeeds.getVideos(type, "0", targetedId, forAccount).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
} else {
|
||||
viewModelSearch.getVideos("0", search_peertube).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
|
||||
|
||||
public void click(String forAccount) {
|
||||
this.forAccount = forAccount;
|
||||
pullToRefresh();
|
||||
}
|
||||
|
||||
|
||||
static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private int spanCount;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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 {
|
||||
@ -355,12 +361,12 @@ public class Helper {
|
||||
long months = days / 30;
|
||||
long years = days / 365;
|
||||
|
||||
String format = DateFormat.getDateInstance(DateFormat.SHORT).format(dateToot);
|
||||
String format = DateFormat.getDateInstance(DateFormat.LONG).format(dateToot);
|
||||
if (years > 0) {
|
||||
return format;
|
||||
} else if (months > 0 || days > 7) {
|
||||
//Removes the year depending of the locale from DateFormat.SHORT format
|
||||
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
|
||||
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
|
||||
df.applyPattern(df.toPattern().replaceAll("[^\\p{Alpha}]*y+[^\\p{Alpha}]*", ""));
|
||||
return df.format(dateToot);
|
||||
} else if (days > 0)
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.client.APIResponse;
|
||||
|
||||
public interface OnActionInterface {
|
||||
void onActionDone(APIResponse apiResponse, int statusCode);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 interface OnDownloadInterface {
|
||||
void onDownloaded(String saveFilePath, String downloadUrl, Error error);
|
||||
|
||||
void onUpdateProgress(int progress);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
|
||||
public interface OnPlaylistActionInterface {
|
||||
void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
|
||||
public interface OnPostActionInterface {
|
||||
void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.client.APIResponse;
|
||||
|
||||
public interface OnPostStatusActionInterface {
|
||||
void onPostStatusAction(APIResponse apiResponse);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
|
||||
public interface OnRetrieveAccountInterface {
|
||||
void onRetrieveAccount(Account account, Error error);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.client.APIResponse;
|
||||
|
||||
public interface OnRetrieveAccountsInterface {
|
||||
void onRetrieveAccounts(APIResponse apiResponse);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.client.entities.Status;
|
||||
|
||||
public interface OnRetrieveFeedsAccountInterface {
|
||||
void onRetrieveFeedsAccount(List<Status> statuses);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.client.APIResponse;
|
||||
|
||||
public interface OnRetrieveFeedsInterface {
|
||||
void onRetrieveFeeds(APIResponse apiResponse);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.client.APIResponse;
|
||||
|
||||
public interface OnRetrievePeertubeInterface {
|
||||
void onRetrievePeertube(APIResponse apiResponse);
|
||||
|
||||
void onRetrievePeertubeComments(APIResponse apiResponse);
|
||||
|
||||
void onRetrievePeertubeChannels(APIResponse apiResponse);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
|
||||
public interface OnRetrievePeertubeNotificationsInterface {
|
||||
void onRetrievePeertubeNotifications(APIResponse apiResponse, Account account);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* 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 app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.Relationship;
|
||||
|
||||
public interface OnRetrieveRelationshipInterface {
|
||||
void onRetrieveRelationship(Relationship relationship, Error error);
|
||||
}
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -130,7 +130,9 @@ public class PeertubeFavoritesDAO {
|
||||
//Restore cached status
|
||||
try {
|
||||
Peertube peertube = PeertubeAPI.parsePeertube(new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE))));
|
||||
if (peertube != null) {
|
||||
peertubes.add(peertube);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -0,0 +1,78 @@
|
||||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* 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.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
|
||||
|
||||
public class AccountsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
public AccountsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getAccounts(String max_id, String name, accountFetch type) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadAccounts(max_id, name, type);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void loadAccounts(String max_id, String name, accountFetch type) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = null;
|
||||
if (type == accountFetch.SUBSCRIPTION) {
|
||||
apiResponse = peertubeAPI.getSubscriptionUsers(max_id);
|
||||
} else if (type == accountFetch.MUTED) {
|
||||
apiResponse = peertubeAPI.getMuted(max_id);
|
||||
} else if (type == accountFetch.CHANNEL) {
|
||||
apiResponse = peertubeAPI.getPeertubeChannel(max_id);
|
||||
} else if (type == accountFetch.SINGLE_ACCOUNT) {
|
||||
apiResponse = peertubeAPI.getPeertubeChannel(name);
|
||||
} else if (type == accountFetch.SINGLE_CHANNEL) {
|
||||
apiResponse = peertubeAPI.getPeertubeChannelInfo(name);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
APIResponse finalApiResponse = apiResponse;
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(finalApiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public enum accountFetch {
|
||||
SUBSCRIPTION,
|
||||
CHANNEL,
|
||||
MUTED,
|
||||
SINGLE_ACCOUNT,
|
||||
SINGLE_CHANNEL
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* 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.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class ChannelsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
public ChannelsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> get() {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getChannels();
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void getChannels() {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(_mContext);
|
||||
Account account = new AccountDAO(_mContext, db).getUniqAccount(userId, instance);
|
||||
if (account == null) {
|
||||
account = new AccountDAO(_mContext, db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
|
||||
}
|
||||
APIResponse apiResponse = peertubeAPI.getPeertubeChannel(account.getUsername());
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* 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.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
|
||||
|
||||
public class CommentVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
public CommentVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getComment(String instanceName, String videoId) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getSingle(instanceName, videoId);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
|
||||
private void getSingle(String instanceName, String videoId) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI api = new PeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = api.getSinglePeertubeComments(instanceName, videoId);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
193
app/src/main/java/app/fedilab/fedilabtube/viewmodel/FeedsVM.java
Normal file
193
app/src/main/java/app/fedilab/fedilabtube/viewmodel/FeedsVM.java
Normal file
@ -0,0 +1,193 @@
|
||||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* 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.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.PeertubeFavoritesDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class FeedsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
public FeedsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getVideos(Type action, String max_id, String target, String forAccount) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadVideos(action, max_id, target, forAccount);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
|
||||
public LiveData<APIResponse> getVideo(String instanceName, String videoId) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getSingle(instanceName, videoId);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> updateVideo(Peertube peertube) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
update(peertube);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void update(Peertube peertube) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = peertubeAPI.updateVideo(peertube);
|
||||
if (apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0)
|
||||
apiResponse.getPeertubes().get(0).setUpdate(true);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.postValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
private void getSingle(String instanceName, String videoId) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
APIResponse apiResponse = peertubeAPI.getSinglePeertube(instanceName, videoId, token);
|
||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
||||
String rate = new PeertubeAPI(_mContext).getRating(videoId);
|
||||
if (rate != null)
|
||||
apiResponse.getPeertubes().get(0).setMyRating(rate);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void loadVideos(Type action, String max_id, String target, String forAccount) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
if (action == null)
|
||||
return;
|
||||
APIResponse apiResponse = null;
|
||||
switch (action) {
|
||||
case USER:
|
||||
apiResponse = peertubeAPI.getVideos(target, max_id);
|
||||
break;
|
||||
case MYVIDEOS:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
apiResponse = peertubeAPI.getMyVideos(max_id);
|
||||
break;
|
||||
case PEERTUBE_HISTORY:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
apiResponse = peertubeAPI.getMyHistory(max_id);
|
||||
break;
|
||||
case CHANNEL:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
apiResponse = peertubeAPI.getVideosChannel(target, max_id);
|
||||
break;
|
||||
case CACHE_BOOKMARKS_PEERTUBE:
|
||||
apiResponse = new APIResponse();
|
||||
SQLiteDatabase db = Sqlite.getInstance(_mContext, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<Peertube> peertubes = new PeertubeFavoritesDAO(_mContext, db).getAllPeertube();
|
||||
apiResponse.setPeertubes(peertubes);
|
||||
break;
|
||||
case PSUBSCRIPTIONS:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
if (forAccount == null) {
|
||||
apiResponse = peertubeAPI.getSubscriptionsTL(max_id);
|
||||
} else {
|
||||
apiResponse = peertubeAPI.getVideosChannel(forAccount, max_id);
|
||||
}
|
||||
break;
|
||||
case POVERVIEW:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
apiResponse = peertubeAPI.getOverviewTL(max_id);
|
||||
break;
|
||||
case PTRENDING:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
apiResponse = peertubeAPI.getTrendingTL(max_id);
|
||||
break;
|
||||
case PRECENTLYADDED:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
apiResponse = peertubeAPI.getRecentlyAddedTL(max_id);
|
||||
break;
|
||||
case PLOCAL:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
apiResponse = peertubeAPI.getLocalTL(max_id);
|
||||
break;
|
||||
case PPUBLIC:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
apiResponse = peertubeAPI.getPublicTL(max_id);
|
||||
break;
|
||||
case PMOSTLIKED:
|
||||
peertubeAPI = new PeertubeAPI(_mContext);
|
||||
apiResponse = peertubeAPI.getLikedTL(max_id);
|
||||
break;
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
APIResponse finalApiResponse = apiResponse;
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(finalApiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
|
||||
USER,
|
||||
PPUBLIC,
|
||||
PSUBSCRIPTIONS,
|
||||
POVERVIEW,
|
||||
PTRENDING,
|
||||
PRECENTLYADDED,
|
||||
PMOSTLIKED,
|
||||
PLOCAL,
|
||||
CHANNEL,
|
||||
MYVIDEOS,
|
||||
PEERTUBE_HISTORY,
|
||||
CACHE_BOOKMARKS_PEERTUBE,
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* 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.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
public class NotificationsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
public NotificationsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getNotifications(Account account, String max_id) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadNotifications(account, max_id);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void loadNotifications(Account account, String max_id) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI api;
|
||||
APIResponse apiResponse;
|
||||
if (account == null) {
|
||||
api = new PeertubeAPI(_mContext);
|
||||
apiResponse = api.getNotifications(max_id);
|
||||
} else {
|
||||
if (_mContext == null) {
|
||||
apiResponse = new APIResponse();
|
||||
apiResponse.setError(new Error());
|
||||
}
|
||||
api = new PeertubeAPI(_mContext, account.getInstance(), account.getToken());
|
||||
apiResponse = api.getNotificationsSince(max_id);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
APIResponse finalApiResponse = apiResponse;
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(finalApiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* 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.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
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.Playlist;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class PlaylistsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
public PlaylistsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> manage(action apiAction, Playlist playlist, String videoId, String max_id) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
managePlaylists(apiAction, playlist, videoId, max_id);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void managePlaylists(action apiAction, Playlist playlist, String videoId, String max_id) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(_mContext);
|
||||
SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(_mContext, db).getUniqAccount(userId, instance);
|
||||
if (account == null) {
|
||||
account = new AccountDAO(_mContext, db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
|
||||
}
|
||||
int statusCode = -1;
|
||||
APIResponse apiResponse = null;
|
||||
if (account == null) {
|
||||
statusCode = 403;
|
||||
apiResponse = new APIResponse();
|
||||
apiResponse.setPlaylists(new ArrayList<>());
|
||||
} else if (apiAction == action.GET_PLAYLIST) {
|
||||
apiResponse = new PeertubeAPI(_mContext).getPlayists(account.getUsername());
|
||||
} else if (apiAction == action.GET_LIST_VIDEOS) {
|
||||
apiResponse = new PeertubeAPI(_mContext).getPlaylistVideos(playlist.getId(), max_id, null);
|
||||
} else if (apiAction == action.DELETE_PLAYLIST) {
|
||||
statusCode = new PeertubeAPI(_mContext).deletePlaylist(playlist.getId());
|
||||
} else if (apiAction == action.ADD_VIDEOS) {
|
||||
statusCode = new PeertubeAPI(_mContext).addVideoPlaylist(playlist.getId(), videoId);
|
||||
} else if (apiAction == action.DELETE_VIDEOS) {
|
||||
statusCode = new PeertubeAPI(_mContext).deleteVideoPlaylist(playlist.getId(), videoId);
|
||||
} else if (apiAction == action.GET_PLAYLIST_FOR_VIDEO) {
|
||||
apiResponse = new PeertubeAPI(_mContext).getPlaylistForVideo(videoId);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
if (apiResponse != null) {
|
||||
apiResponse.setStatusCode(statusCode);
|
||||
}
|
||||
APIResponse finalApiResponse = apiResponse;
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(finalApiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public enum action {
|
||||
GET_PLAYLIST,
|
||||
GET_LIST_VIDEOS,
|
||||
CREATE_PLAYLIST,
|
||||
DELETE_PLAYLIST,
|
||||
ADD_VIDEOS,
|
||||
DELETE_VIDEOS,
|
||||
GET_PLAYLIST_FOR_VIDEO,
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* 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.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
|
||||
|
||||
public class PostActionsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
public PostActionsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> post(PeertubeAPI.StatusAction apiAction, String targetedId, String comment, String targetedComment) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
makeAction(apiAction, targetedId, comment, targetedComment);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void makeAction(PeertubeAPI.StatusAction apiAction, String targetedId, String comment, String targetedComment) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
int statusCode = -1;
|
||||
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)
|
||||
statusCode = peertubeAPI.postRating(targetedId, comment);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT)
|
||||
statusCode = peertubeAPI.postComment(targetedId, comment);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEREPLY)
|
||||
statusCode = peertubeAPI.postReply(targetedId, comment, targetedComment);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT) {
|
||||
statusCode = peertubeAPI.deleteComment(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);
|
||||
}
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
apiResponse.setError(peertubeAPI.getError());
|
||||
apiResponse.setStatusCode(statusCode);
|
||||
apiResponse.setTargetedId(targetedId);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* 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.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.Relationship;
|
||||
|
||||
|
||||
public class RelationshipVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
public RelationshipVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> get(String targetedId) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getRelationShip(targetedId);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void getRelationShip(String targetedId) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI api = new PeertubeAPI(_mContext);
|
||||
List<Relationship> relationships = api.isFollowing(targetedId);
|
||||
Error error = api.getError();
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
apiResponse.setRelationships(relationships);
|
||||
apiResponse.setError(error);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* 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.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
|
||||
|
||||
public class SearchVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
public SearchVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getVideos(String max_id, String query) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadVideos(max_id, query);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void loadVideos(String max_id, String query) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI api = new PeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = api.searchPeertube(query, max_id);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
10
app/src/main/res/drawable/ic_baseline_arrow_white_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_arrow_white_24.xml
Normal 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>
|
10
app/src/main/res/drawable/ic_baseline_delete_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_delete_24.xml
Normal 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>
|
10
app/src/main/res/drawable/ic_baseline_history_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_history_24.xml
Normal 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>
|
10
app/src/main/res/drawable/ic_baseline_report_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_report_24.xml
Normal 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>
|
@ -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>
|
10
app/src/main/res/drawable/ic_baseline_volume_mute_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_volume_mute_24.xml
Normal 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>
|
@ -5,49 +5,57 @@
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<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:fillColor="#000000"
|
||||
android:fillType="evenOdd"
|
||||
android:strokeColor="#00000000"/>
|
||||
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: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:endY="13.806534"
|
||||
android:startX="12"
|
||||
android:startY="4"
|
||||
android:type="linear">
|
||||
<item android:offset="0" android:color="#FF000000"/>
|
||||
<item android:offset="1" android:color="#3F000000"/>
|
||||
<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: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:endY="18.221992"
|
||||
android:startX="12"
|
||||
android:startY="0"
|
||||
android:type="linear">
|
||||
<item android:offset="0" android:color="#FF000000"/>
|
||||
<item android:offset="1" android:color="#3F000000"/>
|
||||
<item
|
||||
android:color="#FF000000"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#3F000000"
|
||||
android:offset="1" />
|
||||
</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"/>
|
||||
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>
|
||||
|
15
app/src/main/res/drawable/rounded_corner.xml
Normal file
15
app/src/main/res/drawable/rounded_corner.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@android:color/black" />
|
||||
|
||||
<solid android:color="@android:color/black" />
|
||||
|
||||
<padding
|
||||
android:bottom="1dp"
|
||||
android:left="1dp"
|
||||
android:right="1dp"
|
||||
android:top="1dp" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
165
app/src/main/res/layout/activity_account.xml
Normal file
165
app/src/main/res/layout/activity_account.xml
Normal 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>
|
@ -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
|
||||
|
@ -14,18 +14,11 @@
|
||||
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">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/not_connected"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/step_instance"
|
||||
@ -139,166 +132,4 @@
|
||||
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"
|
||||
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" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardview_profile"
|
||||
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">
|
||||
|
||||
<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_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>
|
||||
</LinearLayout>
|
@ -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"
|
||||
|
@ -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>
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -14,7 +14,12 @@
|
||||
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"
|
||||
<ScrollView 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">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
@ -64,14 +69,18 @@
|
||||
android:labelFor="@+id/username"
|
||||
android:text="@string/username" />
|
||||
|
||||
<EditText
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/username_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:errorEnabled="true">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="text"
|
||||
android:maxLength="30"
|
||||
android:singleLine="true" />
|
||||
android:maxLength="50" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/username_indicator"
|
||||
@ -86,13 +95,17 @@
|
||||
android:labelFor="@+id/email"
|
||||
android:text="@string/email" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/email"
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/email_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textEmailAddress"
|
||||
android:singleLine="true" />
|
||||
app:errorEnabled="true">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/email"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
@ -107,13 +120,19 @@
|
||||
android:labelFor="@+id/password"
|
||||
android:text="@string/password" />
|
||||
|
||||
<EditText
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/password_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:errorEnabled="true">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textPassword"
|
||||
android:singleLine="true" />
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
@ -128,13 +147,19 @@
|
||||
android:labelFor="@+id/password_confirm"
|
||||
android:text="@string/password_confirm" />
|
||||
|
||||
<EditText
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/password_confirm_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:errorEnabled="true">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/password_confirm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textPassword"
|
||||
android:singleLine="true" />
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -160,4 +185,5 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sign_up" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
@ -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" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:padding="2dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/account_pp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/action_back">
|
||||
|
||||
<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">
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_dn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="18sp" />
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/subscriber_count"
|
||||
app:layout_constraintStart_toEndOf="@+id/account_pp"
|
||||
app:layout_constraintTop_toTopOf="@+id/account_pp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_un"
|
||||
android:id="@+id/subscriber_count"
|
||||
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: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_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/names_container" />
|
||||
app:layout_constraintStart_toEndOf="@id/subscriber_count"
|
||||
app:layout_constraintTop_toBottomOf="@id/account_dn" />
|
||||
|
||||
<ImageButton
|
||||
<Button
|
||||
android:id="@+id/header_edit_profile"
|
||||
style="@style/Widget.AppCompat.Button.Colored"
|
||||
android:layout_width="45dp"
|
||||
android:layout_height="45dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
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>
|
||||
|
||||
|
||||
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>
|
76
app/src/main/res/layout/add_channel.xml
Normal file
76
app/src/main/res/layout/add_channel.xml
Normal 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>
|
||||
|
@ -38,11 +38,6 @@
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_dn"
|
||||
android:layout_width="match_parent"
|
||||
@ -51,14 +46,6 @@
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_un"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_ac"
|
||||
android:layout_width="match_parent"
|
||||
@ -147,18 +134,21 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/more_actions"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/display_more"
|
||||
android:src="@drawable/ic_baseline_more_vert_24"
|
||||
android:visibility="gone" />
|
||||
|
||||
<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"
|
||||
@ -167,6 +157,4 @@
|
||||
app:backgroundTint="?colorAccent"
|
||||
app:fabSize="mini" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
47
app/src/main/res/layout/drawer_horizontal_account.xml
Normal file
47
app/src/main/res/layout/drawer_horizontal_account.xml
Normal 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>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user