Merge branch 'master' into full_version

This commit is contained in:
Thomas 2020-09-13 15:25:59 +02:00
commit 7827c97bf9
79 changed files with 1919 additions and 2304 deletions

73
.gitlab-ci.yml Normal file
View 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/

View File

@ -10,8 +10,8 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode 6
versionName "1.0.4"
versionCode 7
versionName "1.0.5"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -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>

View File

@ -40,13 +40,13 @@ import com.google.android.material.tabs.TabLayout;
import org.jetbrains.annotations.NotNull;
import app.fedilab.fedilabtube.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
import app.fedilab.fedilabtube.fragment.DisplayNotificationsFragment;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
public class AccountActivity extends AppCompatActivity {
@ -228,7 +228,7 @@ public class AccountActivity extends AppCompatActivity {
case 2:
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
if (position == 1) {
bundle.putSerializable("accountFetch", RetrieveAccountsAsyncTask.accountFetch.MUTED);
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();
@ -236,7 +236,7 @@ public class AccountActivity extends AppCompatActivity {
String instance = Helper.getLiveInstance(AccountActivity.this);
Account account = new AccountDAO(AccountActivity.this, db).getUniqAccount(userId, instance);
bundle.putString("name", account.getUsername() + "@" + account.getInstance());
bundle.putSerializable("accountFetch", RetrieveAccountsAsyncTask.accountFetch.CHANNEL);
bundle.putSerializable("accountFetch", AccountsVM.accountFetch.CHANNEL);
}
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;

View File

@ -15,7 +15,6 @@ package app.fedilab.fedilabtube;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -27,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;
@ -36,6 +36,7 @@ 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;
@ -46,8 +47,6 @@ 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;
@ -55,18 +54,17 @@ 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.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 {
PlaylistAdapter playlistAdapter;
private AsyncTask<Void, Void, Void> asyncTask;
private RelativeLayout mainLoader;
private RelativeLayout textviewNoAction;
private HashMap<Integer, String> privacyToSend;
@ -74,6 +72,7 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
private Spinner set_upload_privacy;
private String idChannel;
private List<Playlist> playlists;
private Playlist playlistToEdit;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -93,7 +92,9 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
nextElementLoader.setVisibility(View.GONE);
idChannel = null;
asyncTask = new ManagePlaylistsAsyncTask(AllPlaylistsActivity.this, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
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));
FloatingActionButton add_new = findViewById(R.id.add_new);
@ -110,24 +111,72 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
playlistAdapter = new PlaylistAdapter(AllPlaylistsActivity.this, playlists, textviewNoAction);
lv_playlist.setAdapter(playlistAdapter);
add_new.setOnClickListener(view -> {
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);
add_new.setOnClickListener(view -> manageAlert(null));
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
new RetrievePeertubeChannelsAsyncTask(AllPlaylistsActivity.this, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE);
if (apiResponse.getError() != null) {
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
if (actionType == PlaylistsVM.action.GET_PLAYLIST) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
playlists.addAll(apiResponse.getPlaylists());
playlistAdapter.notifyDataSetChanged();
textviewNoAction.setVisibility(View.GONE);
} else {
textviewNoAction.setVisibility(View.VISIBLE);
}
}
}
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
public void manageAlert(Playlist playlistParam) {
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
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());
@ -140,7 +189,7 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
idPrivacy = String.valueOf(privacyM.getKey());
label = privacyM.getValue();
if ((label.equals("Public") && (playlistElement.getVideoChannelId() == null || playlistElement.getVideoChannelId().equals("")))) {
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) {
@ -148,15 +197,30 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
}
new Thread(() -> {
try {
String playlistId = new PeertubeAPI(AllPlaylistsActivity.this).createPlaylist(playlistElement);
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 = new Playlist();
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);
playlists.add(playlist);
if (playlistToEdit == null) {
playlists.add(playlist);
}
playlistAdapter.notifyDataSetChanged();
};
mainHandler.post(myRunnable);
@ -173,80 +237,32 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
mainHandler.post(myRunnable);
}
}).start();
dialog.dismiss();
alertDialog.dismiss();
}
} 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();
});
}
@Override
public void onDestroy() {
super.onDestroy();
if (asyncTask != null && !asyncTask.isCancelled()) {
asyncTask.cancel(true);
if (playlistToEdit == null) {
alertDialog.setTitle(getString(R.string.action_playlist_create));
} else {
alertDialog.setTitle(getString(R.string.action_playlist_edit));
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
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 onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
mainLoader.setVisibility(View.GONE);
if (apiResponse.getError() != null) {
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
if (actionType == ManagePlaylistsAsyncTask.action.GET_PLAYLIST) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
playlists.addAll(apiResponse.getPlaylists());
playlistAdapter.notifyDataSetChanged();
textviewNoAction.setVisibility(View.GONE);
} else {
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(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
@ -256,14 +272,14 @@ 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] = "null";
for (Account account : accounts) {
for (Account account : channels) {
channelName[i] = account.getUsername();
channelId[i] = account.getId();
i++;
@ -273,6 +289,7 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
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());
@ -300,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
@ -324,6 +354,18 @@ 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
@ -336,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);
}
}
}

View File

@ -16,7 +16,6 @@ package app.fedilab.fedilabtube;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
@ -42,11 +41,12 @@ import java.net.URLEncoder;
import java.util.Arrays;
import java.util.HashMap;
import app.fedilab.fedilabtube.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.fedilabtube.client.HttpsConnection;
import app.fedilab.fedilabtube.helper.Helper;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.client.HttpsConnection.updateCredential;
public class LoginActivity extends AppCompatActivity {
@ -232,37 +232,41 @@ public class LoginActivity extends AppCompatActivity {
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();
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();
else
message = getString(R.string.client_error);
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
});
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 (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();
@ -288,6 +292,27 @@ public class LoginActivity extends AppCompatActivity {
});
}
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();

View File

@ -19,7 +19,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@ -41,20 +40,21 @@ import org.jetbrains.annotations.NotNull;
import java.util.LinkedHashMap;
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask;
import app.fedilab.fedilabtube.client.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.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
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);
@ -67,17 +67,20 @@ public class MainActivity extends AppCompatActivity {
navView.inflateMenu(R.menu.bottom_nav_menu);
}
try {
peertubeInformation = new PeertubeInformation();
peertubeInformation.setCategories(new LinkedHashMap<>());
peertubeInformation.setLanguages(new LinkedHashMap<>());
peertubeInformation.setLicences(new LinkedHashMap<>());
peertubeInformation.setPrivacies(new LinkedHashMap<>());
peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>());
peertubeInformation.setTranslations(new LinkedHashMap<>());
new RetrievePeertubeInformationAsyncTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (Exception ignored) {
}
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.
@ -188,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_history) {
Intent intent = new Intent(MainActivity.this, MyVideosActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PEERTUBE_HISTORY);
bundle.putSerializable("type", FeedsVM.Type.PEERTUBE_HISTORY);
intent.putExtras(bundle);
startActivity(intent);
return true;
@ -229,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++;
@ -242,6 +245,7 @@ public class MainActivity extends AppCompatActivity {
dialog.dismiss();
recreate();
});
alt_bld.setPositiveButton(R.string.close, (dialog, id) -> dialog.dismiss());
AlertDialog alert = alt_bld.create();
alert.show();
}

View File

@ -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,13 +39,13 @@ 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 == RetrieveFeedsAsyncTask.Type.PEERTUBE_HISTORY) {
} else if (type == FeedsVM.Type.PEERTUBE_HISTORY) {
setTitle(R.string.my_history);
}
@ -71,9 +69,4 @@ public class MyVideosActivity extends AppCompatActivity implements OnRetrieveFee
return super.onOptionsItemSelected(item);
}
@Override
public void onRetrieveFeeds(APIResponse apiResponse) {
}
}

View File

@ -26,7 +26,6 @@ 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;
@ -55,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;
@ -78,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;
@ -96,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;
@ -135,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) {
@ -253,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() {
@ -336,11 +335,13 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
Toasty.info(PeertubeActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
} else {
if (type == PeertubeAPI.reportType.VIDEO) {
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.REPORT_VIDEO, peertube.getId(), report_content.getText().toString(), PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
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) {
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.REPORT_ACCOUNT, peertube.getAccount().getId(), report_content.getText().toString(), PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
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();
}
@ -358,8 +359,7 @@ 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();
@ -374,8 +374,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
peertube = apiResponse.getPeertubes().get(0);
//TODO: currently streaming service gives the wrong values for duration
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)) {
@ -393,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);
@ -447,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());
@ -466,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 {
@ -491,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) {
@ -511,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) {
@ -640,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();
@ -667,10 +670,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
}
}
@Override
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
}
@Override
public void onDestroy() {
@ -741,11 +740,12 @@ 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);
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) {
@ -831,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();

View File

@ -21,7 +21,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
@ -38,6 +37,7 @@ 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;
@ -56,26 +56,21 @@ 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;
@ -135,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();
@ -223,16 +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();
@ -250,7 +245,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
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();
@ -530,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);
@ -614,13 +611,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
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().getError() != null)
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
@ -659,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);

View File

@ -15,6 +15,8 @@ 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;
@ -33,16 +35,13 @@ 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;
@ -143,7 +142,52 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
accountCreation.setPasswordConfirm(password_confirm.getText().toString().trim());
accountCreation.setUsername(username.getText().toString().trim());
accountCreation.setInstance(instance);
new CreatePeertubeAccountAsyncTask(PeertubeRegisterActivity.this, accountCreation, Helper.getPeertubeUrl(instance), PeertubeRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
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) {
try {
String[] resp = apiResponse.getError().getError().split(":");
if (resp.length == 2)
errorMessage = apiResponse.getError().getError().split(":")[1];
else if (resp.length == 3)
errorMessage = apiResponse.getError().getError().split(":")[2];
else
errorMessage = getString(R.string.toast_error);
} catch (Exception e) {
errorMessage = getString(R.string.toast_error);
}
} else {
errorMessage = getString(R.string.toast_error);
}
error_message.setText(errorMessage);
error_message.setVisibility(View.VISIBLE);
signup.setEnabled(true);
return;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeRegisterActivity.this);
dialogBuilder.setCancelable(false);
dialogBuilder.setPositiveButton(R.string.validate, (dialog, which) -> {
dialog.dismiss();
finish();
});
AlertDialog alertDialog = dialogBuilder.create();
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);
@ -164,44 +208,6 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
}
@Override
public void onPostStatusAction(APIResponse apiResponse) {
if (apiResponse.getError() != null) {
String errorMessage;
if (apiResponse.getError().getError() != null) {
try {
String[] resp = apiResponse.getError().getError().split(":");
if (resp.length == 2)
errorMessage = apiResponse.getError().getError().split(":")[1];
else if (resp.length == 3)
errorMessage = apiResponse.getError().getError().split(":")[2];
else
errorMessage = getString(R.string.toast_error);
} catch (Exception e) {
errorMessage = getString(R.string.toast_error);
}
} else {
errorMessage = getString(R.string.toast_error);
}
error_message.setText(errorMessage);
error_message.setVisibility(View.VISIBLE);
signup.setEnabled(true);
return;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeRegisterActivity.this);
dialogBuilder.setCancelable(false);
dialogBuilder.setPositiveButton(R.string.validate, (dialog, which) -> {
dialog.dismiss();
finish();
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.account_created));
alertDialog.setMessage(getString(R.string.account_created_message, apiResponse.getStringData()));
alertDialog.show();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {

View File

@ -23,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;
@ -39,6 +38,7 @@ 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.UploadNotificationAction;
@ -53,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 {
public class PeertubeUploadActivity extends AppCompatActivity {
private final int PICK_IVDEO = 52378;
@ -95,7 +94,8 @@ 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<>();
setTitle(R.string.upload_video);
}
@ -143,10 +143,6 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri
super.onDestroy();
}
@Override
public void onRetrievePeertube(APIResponse apiResponse) {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@ -157,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();

View File

@ -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

View File

@ -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) {
}
}

View File

@ -17,7 +17,6 @@ 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;
@ -41,6 +40,7 @@ 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;
@ -48,29 +48,19 @@ 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.asynctasks.RetrieveSingleAccountAsyncTask;
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.OnRetrieveAccountsInterface;
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;
@ -78,11 +68,9 @@ 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, OnRetrieveAccountsInterface {
public class ShowAccountActivity extends AppCompatActivity {
private List<Status> statuses;
private StatusListAdapter statusListAdapter;
private Button account_follow;
private ViewPager mPager;
private TabLayout tabLayout;
@ -93,7 +81,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
private Account account;
private String accountId;
private boolean ischannel;
private AsyncTask<Void, Void, List<Relationship>> retrieveRelationship;
private action doAction;
@Override
@ -119,13 +106,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
} 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);
@ -135,11 +115,12 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
account_note = findViewById(R.id.account_note);
AccountsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(AccountsVM.class);
if (account != null) {
manageAccount();
new RetrieveSingleAccountAsyncTask(ShowAccountActivity.this, account.getAcct(), RetrieveSingleAccountAsyncTask.actionType.CHANNEL, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
viewModel.getAccounts(null, account.getAcct(), AccountsVM.accountFetch.SINGLE_CHANNEL).observe(ShowAccountActivity.this, this::manageViewAccounts);
} else {
new RetrieveSingleAccountAsyncTask(ShowAccountActivity.this, accountId, RetrieveSingleAccountAsyncTask.actionType.CHANNEL, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
viewModel.getAccounts(null, accountId, AccountsVM.accountFetch.SINGLE_CHANNEL).observe(ShowAccountActivity.this, this::manageViewAccounts);
}
}
@ -158,7 +139,8 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
finish();
return true;
} else if (item.getItemId() == R.id.action_mute) {
new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.MUTE, account.getchannelOwner() != null ? account.getchannelOwner().getAcct() : account.getAcct(), ShowAccountActivity.this).execute();
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();
@ -170,7 +152,8 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
if (report_content.getText().toString().trim().length() == 0) {
Toasty.info(ShowAccountActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
} else {
new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.REPORT_ACCOUNT, account.getId(), report_content.getText().toString(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
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();
}
});
@ -185,7 +168,8 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
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);
}
setTitle(account.getAcct());
@ -274,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) {
@ -284,41 +269,29 @@ 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));
}
}
});
}
@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(List<Relationship> relationships, Error error) {
if (error != null) {
Toasty.error(ShowAccountActivity.this, error.getError(), Toast.LENGTH_LONG).show();
return;
}
List<Relationship> relationships = apiResponse.getRelationships();
this.relationship = relationships.get(0);
manageButtonVisibility();
@ -382,35 +355,32 @@ 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);
}
if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW || statusAction == PeertubeAPI.StatusAction.FOLLOW) {
retrieveRelationship = new RetrieveRelationshipAsyncTask(ShowAccountActivity.this, target, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
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();
}
}
@Override
public void onRetrieveAccounts(APIResponse apiResponse) {
public void manageViewAccounts(APIResponse apiResponse) {
if (apiResponse.getAccounts() != null && apiResponse.getAccounts().size() == 1) {
Account account = apiResponse.getAccounts().get(0);
if (this.account == null) {
@ -465,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);

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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,
}
}

View File

@ -1,98 +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
|| 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);
targetedId = comment;
} else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO) {
statusCode = peertubeAPI.deleteVideo(targetedId);
} else if (apiAction == PeertubeAPI.StatusAction.REPORT_ACCOUNT) {
statusCode = peertubeAPI.report(PeertubeAPI.reportType.ACCOUNT, targetedId, comment);
} else if (apiAction == PeertubeAPI.StatusAction.REPORT_VIDEO) {
statusCode = peertubeAPI.report(PeertubeAPI.reportType.VIDEO, targetedId, comment);
}
error = peertubeAPI.getError();
return null;
}
@Override
protected void onPostExecute(Void result) {
if (listener != null) {
listener.onPostAction(statusCode, apiAction, targetedId, error);
}
}
}

View File

@ -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);
}
}

View File

@ -1,50 +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 RetrieveAccountSubscriptionsAsyncTask extends AsyncTask<Void, Void, APIResponse> {
private OnRetrieveAccountsInterface listener;
private WeakReference<Context> contextReference;
private String max_id;
public RetrieveAccountSubscriptionsAsyncTask(Context context, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.max_id = max_id;
this.listener = onRetrieveAccountsInterface;
}
@Override
protected APIResponse doInBackground(Void... params) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
return peertubeAPI.getSubscriptionUsers(max_id);
}
@Override
protected void onPostExecute(APIResponse apiResponse) {
listener.onRetrieveAccounts(apiResponse);
}
}

View File

@ -1,66 +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, APIResponse> {
private OnRetrieveAccountsInterface listener;
private WeakReference<Context> contextReference;
private String max_id;
private accountFetch type;
public RetrieveAccountsAsyncTask(Context context, String max_id, accountFetch type, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.max_id = max_id;
this.listener = onRetrieveAccountsInterface;
this.type = type;
}
@Override
protected APIResponse doInBackground(Void... params) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
if (type == accountFetch.SUBSCRIPTION) {
return peertubeAPI.getSubscriptionUsers(max_id);
} else if (type == accountFetch.MUTED) {
return peertubeAPI.getMuted(max_id);
} else if (type == accountFetch.CHANNEL) {
return peertubeAPI.getPeertubeChannel(max_id);
} else {
return null;
}
}
@Override
protected void onPostExecute(APIResponse apiResponse) {
listener.onRetrieveAccounts(apiResponse);
}
public enum accountFetch {
SUBSCRIPTION,
CHANNEL,
MUTED
}
}

View File

@ -1,158 +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;
private String forAccount;
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;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, String target, String forAccount, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
this.listener = onRetrieveFeedsInterface;
this.target = target;
this.forAccount = forAccount;
}
@Override
protected Void doInBackground(Void... params) {
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());
if (forAccount == null) {
apiResponse = peertubeAPI.getSubscriptionsTL(max_id);
} else {
apiResponse = peertubeAPI.getVideosChannel(forAccount, 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,
}
}

View File

@ -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);
}
}

View File

@ -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) {
}
}

View File

@ -1,69 +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, 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 APIResponse doInBackground(Void... params) {
PeertubeAPI api;
APIResponse apiResponse;
if (account == null) {
api = new PeertubeAPI(this.contextReference.get());
apiResponse = api.getNotifications(max_id);
} else {
if (this.contextReference.get() == null) {
apiResponse = new APIResponse();
apiResponse.setError(new Error());
return apiResponse;
}
api = new PeertubeAPI(this.contextReference.get(), account.getInstance(), account.getToken());
apiResponse = api.getNotificationsSince(max_id);
}
return apiResponse;
}
@Override
protected void onPostExecute(APIResponse apiResponse) {
listener.onRetrievePeertubeNotifications(apiResponse, account);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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 java.util.List;
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, List<Relationship>> {
private String accountId;
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 List<Relationship> doInBackground(Void... params) {
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
List<Relationship> relationships = api.isFollowing(accountId);
error = api.getError();
return relationships;
}
@Override
protected void onPostExecute(List<Relationship> relationships) {
listener.onRetrieveRelationship(relationships, error);
}
}

View File

@ -1,63 +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 RetrieveSingleAccountAsyncTask extends AsyncTask<Void, Void, APIResponse> {
private OnRetrieveAccountsInterface listener;
private WeakReference<Context> contextReference;
private String name;
private actionType type;
public RetrieveSingleAccountAsyncTask(Context context, String name, actionType type, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.name = name;
this.listener = onRetrieveAccountsInterface;
this.type = type;
}
@Override
protected APIResponse doInBackground(Void... params) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
if (type == actionType.ACCOUNT) {
return peertubeAPI.getPeertubeChannel(name);
} else if (type == actionType.CHANNEL) {
return peertubeAPI.getPeertubeChannelInfo(name);
} else {
return null;
}
}
@Override
protected void onPostExecute(APIResponse apiResponse) {
listener.onRetrieveAccounts(apiResponse);
}
public enum actionType {
ACCOUNT,
CHANNEL
}
}

View File

@ -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();
}
}
}

View File

@ -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;
}
}

View File

@ -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,14 +62,15 @@ 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 {
@ -109,6 +117,66 @@ 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
*
@ -241,7 +309,7 @@ public class HttpsConnection {
return response;
}
public String postBoundary(String urlConnection, int timeout, LinkedHashMap<String, String> paramaters, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
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();
@ -253,6 +321,12 @@ public class HttpsConnection {
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);
@ -323,7 +397,6 @@ public class HttpsConnection {
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);
Map<String, Object> params = new LinkedHashMap<>();
@ -389,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;
@ -761,7 +769,6 @@ public class HttpsConnection {
return max_id;
}
private void getSinceMaxId() {
if (httpsURLConnection == null)
@ -806,6 +813,10 @@ public class HttpsConnection {
}
}
public enum boundaryType {
POST,
PUT
}
public class HttpsConnectionException extends Exception {

View File

@ -227,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);
peertube.setUuid(resobj.getString("uuid"));
if (resobj.has("uuid")) {
peertube.setUuid(resobj.getString("uuid"));
}
peertube.setName(resobj.getString("name"));
peertube.setDescription(resobj.getString("description"));
peertube.setEmbedPath(resobj.getString("embedPath"));
@ -267,15 +274,25 @@ public class PeertubeAPI {
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"));
license.put(resobj.getJSONObject("licence").getInt("id"), resobj.getJSONObject("licence").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();
@ -391,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"));
@ -422,19 +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"))
@ -447,16 +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("");
if (accountObject.has("url")) {
account.setUrl(accountObject.get("url").toString());
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");
@ -870,6 +889,28 @@ public class PeertubeAPI {
}
}
/**
* 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
*
@ -920,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();
@ -1210,7 +1252,7 @@ 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) {
setError(e.getStatusCode(), e);
return apiResponse;
@ -1279,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;
@ -1294,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;
@ -1309,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;
@ -1324,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;
@ -1339,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;
@ -1354,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;
@ -1369,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)
@ -1391,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);
@ -1720,7 +1762,7 @@ public class PeertubeAPI {
params.put("privacy", playlistElement.getPrivacy());
params.put("videoChannelId", playlistElement.getVideoChannelId());
params.put("description", playlistElement.getDescription());
String response = httpsConnection.postBoundary(getAbsoluteUrl("/video-playlists/"), 60, params, prefKeyOauthTokenT);
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();
@ -1728,6 +1770,25 @@ public class PeertubeAPI {
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
@ -1942,7 +2003,7 @@ public class PeertubeAPI {
JSONObject resobj = jsonArray.getJSONObject(i);
Peertube peertube = parsePeertube(resobj);
i++;
if (peertube.getName() == null || !peertube.getName().toLowerCase().contains("youtube video downloader")) {
if (peertube != null && (peertube.getName() == null || !peertube.getName().toLowerCase().contains("youtube video downloader"))) {
peertubes.add(peertube);
}
}
@ -2074,6 +2135,7 @@ public class PeertubeAPI {
}
@SuppressWarnings("SameParameterValue")
private String getAbsoluteUrlForInstance(String instance, String action) {
return "https://" + instance + "/api/v1" + action;
}

View File

@ -16,11 +16,20 @@ package app.fedilab.fedilabtube.client.entities;
* 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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -22,7 +22,6 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
@ -32,24 +31,18 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
import es.dmoral.toasty.Toasty;
public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnPostActionInterface {
public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
EventListener listener;
private List<Account> accounts;
private Context context;
private AccountsHorizontalListAdapter accountsListAdapter;
public AccountsHorizontalListAdapter(List<Account> accounts, EventListener listener) {
this.accounts = accounts;
this.accountsListAdapter = this;
this.listener = listener;
}
@ -92,56 +85,6 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
return accounts.size();
}
private Account getItemAt(int position) {
if (accounts.size() > position)
return accounts.get(position);
else
return null;
}
@Override
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String targetedId, Error error) {
if (error != null) {
Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show();
return;
}
if (statusAction == PeertubeAPI.StatusAction.FOLLOW) {
/* if (action == RetrieveAccountsAsyncTask.Type.CHANNELS) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new InstancesDAO(context, db).insertInstance(accounts.get(0).getAcct().split("@")[1], accounts.get(0).getAcct().split("@")[0], "PEERTUBE_CHANNEL");
} else {
for (Account account : accounts) {
if (account.getId().equals(targetedId)) {
account.setFollowType(Account.followAction.FOLLOW);
account.setMakingAction(false);
}
}
accountsListAdapter.notifyDataSetChanged();
}*/
}
if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW) {
for (Account account : accounts) {
if (account.getId().equals(targetedId)) {
account.setFollowType(Account.followAction.NOT_FOLLOW);
account.setMakingAction(false);
}
}
accountsListAdapter.notifyDataSetChanged();
}
}
private void notifyAccountChanged(Account account) {
for (int i = 0; i < accountsListAdapter.getItemCount(); i++) {
//noinspection ConstantConditions
if (accountsListAdapter.getItemAt(i) != null && accountsListAdapter.getItemAt(i).getId().equals(account.getId())) {
try {
accountsListAdapter.notifyItemChanged(i);
} catch (Exception ignored) {
}
}
}
}
public interface EventListener {
void click(String forAccount);

View File

@ -26,6 +26,7 @@ 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;
@ -33,36 +34,41 @@ 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.asynctasks.PostActionAsyncTask;
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.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 RetrieveAccountsAsyncTask.accountFetch type;
private AccountsVM.accountFetch type;
public AccountsListAdapter(RetrieveAccountsAsyncTask.accountFetch type, List<Account> accounts) {
public AccountsListAdapter(AccountsVM.accountFetch type, List<Account> accounts) {
this.accounts = accounts;
this.accountsListAdapter = this;
this.type = type;
@ -80,8 +86,9 @@ 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 == RetrieveAccountsAsyncTask.accountFetch.CHANNEL) {
holder.account_action.show();
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 -> {
@ -97,15 +104,10 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
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();
accounts.remove(account);
notifyDataSetChanged();
if (accounts.size() == 0) {
allAccountsRemoved.onAllAccountsRemoved();
}
};
mainHandler.post(myRunnable);
@ -127,22 +129,24 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
.show();
});
} else if (type == RetrieveAccountsAsyncTask.accountFetch.MUTED) {
holder.account_action.setOnClickListener(v -> new PostActionAsyncTask(context, PeertubeAPI.StatusAction.UNMUTE, account.getAcct(), AccountsListAdapter.this).execute());
} else 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();
}
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_dn.setText(account.getDisplay_name());
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
@ -159,11 +163,73 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
holder.account_action.setEnabled(true);
}
//Follow button
if (type == RetrieveAccountsAsyncTask.accountFetch.MUTED) {
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 -> {
Intent intent = new Intent(context, ShowAccountActivity.class);
@ -189,16 +255,15 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
return accounts.size();
}
@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) {
for (Account account : accounts) {
if (account.getId().equals(targetedId)) {
if (account.getId().equals(apiResponse.getTargetedId())) {
account.setFollowType(Account.followAction.FOLLOW);
account.setMakingAction(false);
}
@ -209,7 +274,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
Account tmpAccount = null;
int position = 0;
for (Account account : accounts) {
if (account.getAcct().equals(targetedId)) {
if (account.getAcct().equals(apiResponse.getTargetedId())) {
tmpAccount = account;
break;
}
@ -222,7 +287,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
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);
}
@ -239,15 +304,19 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
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_action;
LinearLayout account_container;
@ -257,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_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);
}
}

View File

@ -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,7 +72,7 @@ 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 && userId != null && peertube.getAccount().getId() != null && 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());
@ -92,7 +90,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
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())));
@ -166,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;

View File

@ -17,7 +17,6 @@ package app.fedilab.fedilabtube.drawer;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -30,21 +29,24 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
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;
@ -93,9 +95,11 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
holder = (ViewHolder) convertView.getTag();
}
Glide.with(context)
.load("https://" + playlist.getOwnerAccount().getHost() + playlist.getThumbnailPath())
.into(holder.preview_playlist);
if (playlist.getOwnerAccount() != null) {
Glide.with(context)
.load("https://" + playlist.getOwnerAccount().getHost() + playlist.getThumbnailPath())
.into(holder.preview_playlist);
}
holder.preview_title.setText(playlist.getDisplayName());
if (playlist.getDescription() != null && playlist.getDescription().trim().compareTo("null") != 0 && playlist.getDescription().length() > 0) {
@ -115,6 +119,11 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
context.startActivity(intent);
});
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);
@ -130,7 +139,9 @@ 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();
@ -138,9 +149,11 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
.show();
break;
/*case R.id.action_edit:
break;*/
case R.id.action_edit:
if (context instanceof AllPlaylistsActivity) {
((AllPlaylistsActivity) context).manageAlert(playlist);
}
break;
}
return true;
});
@ -150,8 +163,7 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte
return convertView;
}
@Override
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
}

View File

@ -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;

View File

@ -16,7 +16,6 @@ package app.fedilab.fedilabtube.fragment;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -25,6 +24,7 @@ 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;
@ -34,7 +34,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -46,23 +46,21 @@ import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrieveSingleAccountAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.HttpsConnection;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.ChannelCreation;
import app.fedilab.fedilabtube.drawer.AccountsListAdapter;
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
import es.dmoral.toasty.Toasty;
public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccountsInterface, AccountsListAdapter.AllAccountsRemoved {
public class DisplayAccountsFragment extends Fragment implements AccountsListAdapter.AllAccountsRemoved, AccountsListAdapter.EditAlertDialog {
private boolean flag_loading;
private Context context;
private AsyncTask<Void, Void, APIResponse> asyncTask;
private AccountsListAdapter accountsListAdapter;
private String max_id;
private List<Account> accounts;
@ -73,7 +71,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
private boolean swiped;
private RecyclerView lv_accounts;
private View rootView;
private RetrieveAccountsAsyncTask.accountFetch accountFetch;
private AccountsVM.accountFetch accountFetch;
private FloatingActionButton action_button;
@Override
@ -86,7 +84,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
accounts = new ArrayList<>();
if (bundle != null) {
if (bundle.containsKey("accountFetch")) {
accountFetch = (RetrieveAccountsAsyncTask.accountFetch) bundle.getSerializable("accountFetch");
accountFetch = (AccountsVM.accountFetch) bundle.getSerializable("accountFetch");
}
name = bundle.getString("name", null);
}
@ -100,78 +98,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
if (getActivity() != null) {
action_button = getActivity().findViewById(R.id.action_button);
action_button.setOnClickListener(view -> {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
LayoutInflater inflater1 = ((Activity) context).getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.add_channel, new LinearLayout(context), false);
dialogBuilder.setView(dialogView);
EditText display_name = dialogView.findViewById(R.id.display_name);
EditText name = dialogView.findViewById(R.id.name);
EditText description = dialogView.findViewById(R.id.description);
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0 && name.getText() != null && name.getText().toString().trim().length() > 0) {
ChannelCreation channelCreation = new ChannelCreation();
channelCreation.setDisplayName(display_name.getText().toString().trim());
channelCreation.setName(name.getText().toString().trim());
if (description.getText() != null && description.getText().toString().trim().length() > 0) {
channelCreation.setDescription(description.getText().toString().trim());
}
new Thread(() -> {
try {
new PeertubeAPI(context).createChannel(channelCreation);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
DisplayPlaylistsFragment displayPlaylistsFragment;
if (getActivity() == null)
return;
displayPlaylistsFragment = (DisplayPlaylistsFragment) getActivity().getSupportFragmentManager().findFragmentByTag("CHANNELS");
final FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
if (displayPlaylistsFragment != null) {
ft.detach(displayPlaylistsFragment);
ft.attach(displayPlaylistsFragment);
ft.commit();
}
action_button.setEnabled(true);
};
mainHandler.post(myRunnable);
} catch (HttpsConnection.HttpsConnectionException e) {
action_button.setEnabled(true);
e.printStackTrace();
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (e.getMessage() != null) {
Toasty.error(context, e.getMessage(), Toast.LENGTH_LONG).show();
} else {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
};
mainHandler.post(myRunnable);
}
}).start();
dialog.dismiss();
action_button.setEnabled(false);
} else {
Toasty.error(context, context.getString(R.string.error_display_name_channel), Toast.LENGTH_LONG).show();
}
});
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.action_channel_create));
alertDialog.setOnDismissListener(dialogInterface -> {
//Hide keyboard
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(display_name.getWindowToken(), 0);
});
if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
});
action_button.setOnClickListener(view -> manageAlert(null));
}
lv_accounts = rootView.findViewById(R.id.lv_elements);
lv_accounts.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
@ -182,9 +109,10 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
nextElementLoader.setVisibility(View.GONE);
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 == RetrieveAccountsAsyncTask.accountFetch.MUTED) {
if (accountFetch == AccountsVM.accountFetch.MUTED) {
no_action_text.setText(context.getString(R.string.no_muted));
}
final LinearLayoutManager mLayoutManager;
@ -199,11 +127,12 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
AccountsVM viewModel = new ViewModelProvider(DisplayAccountsFragment.this).get(AccountsVM.class);
if (accountFetch == null) {
asyncTask = new RetrieveSingleAccountAsyncTask(context, name, RetrieveSingleAccountAsyncTask.actionType.ACCOUNT, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
viewModel.getAccounts(null, name, AccountsVM.accountFetch.SINGLE_ACCOUNT).observe(DisplayAccountsFragment.this.requireActivity(), apiResponse -> manageViewAccounts(apiResponse));
} else {
String param = accountFetch == RetrieveAccountsAsyncTask.accountFetch.CHANNEL ? name : max_id;
asyncTask = new RetrieveAccountsAsyncTask(context, param, accountFetch, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
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);
}
@ -214,12 +143,12 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
}
});
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
if (accountFetch == null) {
asyncTask = new RetrieveSingleAccountAsyncTask(context, name, RetrieveSingleAccountAsyncTask.actionType.ACCOUNT, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
viewModel.getAccounts(null, name, AccountsVM.accountFetch.SINGLE_ACCOUNT).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
} else {
String param = accountFetch == RetrieveAccountsAsyncTask.accountFetch.CHANNEL ? name : null;
asyncTask = new RetrieveAccountsAsyncTask(context, param, accountFetch, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
String param = accountFetch == AccountsVM.accountFetch.CHANNEL ? name : null;
viewModel.getAccounts(param, null, accountFetch).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
}
return rootView;
}
@ -227,7 +156,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
@Override
public void onResume() {
super.onResume();
if (accountFetch == RetrieveAccountsAsyncTask.accountFetch.CHANNEL) {
if (accountFetch == AccountsVM.accountFetch.CHANNEL) {
action_button.setVisibility(View.VISIBLE);
} else {
action_button.setVisibility(View.GONE);
@ -252,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() {
@ -263,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) {
@ -275,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);
@ -283,7 +209,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
textviewNoAction.setVisibility(View.GONE);
max_id = apiResponse.getMax_id();
if (swiped) {
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
lv_accounts.setAdapter(accountsListAdapter);
@ -305,11 +230,12 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
flag_loading = true;
swiped = true;
swipeRefreshLayout.setRefreshing(true);
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
if (accountFetch == null) {
asyncTask = new RetrieveSingleAccountAsyncTask(context, name, RetrieveSingleAccountAsyncTask.actionType.ACCOUNT, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
viewModel.getAccounts(null, name, AccountsVM.accountFetch.SINGLE_ACCOUNT).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
} else {
String param = accountFetch == RetrieveAccountsAsyncTask.accountFetch.CHANNEL ? name : null;
asyncTask = new RetrieveAccountsAsyncTask(context, param, accountFetch, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
String param = accountFetch == AccountsVM.accountFetch.CHANNEL ? name : null;
viewModel.getAccounts(param, null, accountFetch).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
}
}
@ -317,4 +243,120 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
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);
}
}

View File

@ -15,7 +15,6 @@ package app.fedilab.fedilabtube.fragment;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -25,6 +24,7 @@ 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;
@ -34,20 +34,17 @@ import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeNotificationsAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.PeertubeNotification;
import app.fedilab.fedilabtube.drawer.PeertubeNotificationsListAdapter;
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeNotificationsInterface;
import app.fedilab.fedilabtube.viewmodel.NotificationsVM;
import es.dmoral.toasty.Toasty;
public class DisplayNotificationsFragment extends Fragment implements OnRetrievePeertubeNotificationsInterface {
public class DisplayNotificationsFragment extends Fragment {
private boolean flag_loading;
private Context context;
private AsyncTask<Void, Void, APIResponse> asyncTask;
private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter;
private String max_id;
private List<PeertubeNotification> notifications;
@ -95,7 +92,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
asyncTask = new RetrievePeertubeNotificationsAsyncTask(context, null, max_id, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
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 {
@ -106,7 +104,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
});
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
asyncTask = new RetrievePeertubeNotificationsAsyncTask(context, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
NotificationsVM viewModel = new ViewModelProvider(this).get(NotificationsVM.class);
viewModel.getNotifications(null, null).observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications);
return rootView;
}
@ -116,6 +115,17 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
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);
@ -130,8 +140,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
public void onDestroy() {
super.onDestroy();
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
asyncTask.cancel(true);
}
public void scrollToTop() {
@ -147,11 +155,12 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
flag_loading = true;
swiped = true;
swipeRefreshLayout.setRefreshing(true);
asyncTask = new RetrievePeertubeNotificationsAsyncTask(context, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
NotificationsVM viewModel = new ViewModelProvider(this).get(NotificationsVM.class);
viewModel.getNotifications(null, null).observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications);
}
@Override
public void onRetrievePeertubeNotifications(APIResponse apiResponse, Account account) {
private void manageVIewNotifications(APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if (apiResponse.getError() != null) {

View File

@ -17,7 +17,6 @@ package app.fedilab.fedilabtube.fragment;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -40,6 +39,7 @@ 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;
@ -54,8 +54,6 @@ 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;
@ -63,18 +61,17 @@ 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.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;
@ -105,7 +102,9 @@ 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<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
@ -131,7 +130,8 @@ 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)});
@ -168,19 +168,14 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
playlistElement.setDescription(playlist.getDescription());
new Thread(() -> {
try {
new PeertubeAPI(context).createPlaylist(playlistElement);
String returnedId = new PeertubeAPI(context).createPlaylist(playlistElement);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
DisplayPlaylistsFragment displayPlaylistsFragment;
if (getActivity() == null)
return;
displayPlaylistsFragment = (DisplayPlaylistsFragment) getActivity().getSupportFragmentManager().findFragmentByTag("PLAYLISTS");
final FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
if (displayPlaylistsFragment != null) {
ft.detach(displayPlaylistsFragment);
ft.attach(displayPlaylistsFragment);
ft.commit();
}
playlist.setId(returnedId);
playlists.add(0, playlist);
playlistAdapter.notifyDataSetChanged();
};
mainHandler.post(myRunnable);
add_new.setEnabled(true);
@ -238,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) {
@ -254,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();
@ -262,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();
@ -275,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();

View File

@ -17,10 +17,8 @@ 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;
@ -33,6 +31,7 @@ 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;
@ -44,40 +43,34 @@ import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSearchAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.Peertube;
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface;
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
import 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.asynctasks.RetrieveFeedsAsyncTask.Type.PSUBSCRIPTIONS;
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, OnRetrieveAccountsInterface, AccountsHorizontalListAdapter.EventListener {
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 AccountsHorizontalListAdapter accountsHorizontalListAdapter;
private String max_id, max_id_accounts;
private List<Peertube> peertubes;
private List<Account> accounts;
private RetrieveFeedsAsyncTask.Type type;
private FeedsVM.Type type;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
@ -91,6 +84,9 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
private boolean check_ScrollingUp;
private String forAccount;
private ConstraintLayout top_account_container;
private FeedsVM viewModelFeeds;
private SearchVM viewModelSearch;
private AccountsVM viewModelAccounts;
public DisplayStatusFragment() {
}
@ -110,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) {
@ -119,7 +115,7 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
if (ischannel) {
type = RetrieveFeedsAsyncTask.Type.CHANNEL;
type = FeedsVM.Type.CHANNEL;
}
forAccount = null;
@ -163,26 +159,15 @@ 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();
} else {
asyncTask = new RetrievePeertubeSearchAsyncTask(context, "0", search_peertube, DisplayStatusFragment.this).execute();
}
//Load data depending of the value
if (search_peertube == null) { //Not a Peertube search
viewModelFeeds.getVideos(type, "0", targetedId, forAccount).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();
}
}
}, 500);
viewModelSearch.getVideos("0", search_peertube).observe(DisplayStatusFragment.this.requireActivity(), this::manageVIewVideos);
}
lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
@ -192,7 +177,7 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
new RetrieveAccountsAsyncTask(context, max_id_accounts, RetrieveAccountsAsyncTask.accountFetch.SUBSCRIPTION, DisplayStatusFragment.this).execute();
viewModelAccounts.getAccounts(max_id_accounts, null, AccountsVM.accountFetch.SUBSCRIPTION).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageViewAccounts(apiResponse));
}
}
}
@ -227,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);
}
@ -246,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);
}
@ -261,7 +246,8 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
});
}
if (type == PSUBSCRIPTIONS) {
new RetrieveAccountsAsyncTask(context, max_id, RetrieveAccountsAsyncTask.accountFetch.SUBSCRIPTION, DisplayStatusFragment.this).execute();
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 -> {
@ -309,13 +295,10 @@ 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 onRetrieveAccounts(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);
@ -332,8 +315,8 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
}
}
@Override
public void onRetrieveFeeds(APIResponse apiResponse) {
private void manageVIewVideos(APIResponse apiResponse) {
//hide loaders
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
@ -417,18 +400,13 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
accountsHorizontalListAdapter.notifyItemRangeRemoved(0, accounts.size());
}
if (search_peertube == null) { //Not a Peertube search
asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", targetedId, forAccount, DisplayStatusFragment.this).execute();
viewModelFeeds.getVideos(type, "0", targetedId, forAccount).observe(this.requireActivity(), this::manageVIewVideos);
} else {
asyncTask = new RetrievePeertubeSearchAsyncTask(context, "0", search_peertube, DisplayStatusFragment.this).execute();
viewModelSearch.getVideos("0", search_peertube).observe(this.requireActivity(), this::manageVIewVideos);
}
}
@Override
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
}
@Override
public void click(String forAccount) {
this.forAccount = forAccount;

View File

@ -361,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)

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -1,24 +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.Error;
import app.fedilab.fedilabtube.client.entities.Relationship;
public interface OnRetrieveRelationshipInterface {
void onRetrieveRelationship(List<Relationship> relationships, Error error);
}

View File

@ -130,7 +130,9 @@ public class PeertubeFavoritesDAO {
//Restore cached status
try {
Peertube peertube = PeertubeAPI.parsePeertube(new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE))));
peertubes.add(peertube);
if (peertube != null) {
peertubes.add(peertube);
}
} catch (JSONException e) {
e.printStackTrace();
}

View File

@ -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
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View 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,
}
}

View File

@ -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();
}
}

View File

@ -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,
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View 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>

View File

@ -38,26 +38,13 @@
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
<TextView
android:id="@+id/account_dn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/account_dn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
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>
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="18sp" />
<TextView
android:id="@+id/account_ac"
@ -147,6 +134,15 @@
</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" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/account_action"

View File

@ -15,6 +15,7 @@
see <http://www.gnu.org/licenses>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -39,13 +40,34 @@
android:textStyle="bold"
android:visibility="gone" />
<ImageView
android:id="@+id/peertube_video_image"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="@string/image_preview"
android:gravity="center"
android:scaleType="centerCrop" />
android:layout_height="200dp">
<ImageView
android:id="@+id/peertube_video_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="@string/image_preview"
android:gravity="center"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/peertube_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/rounded_corner"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:id="@+id/bottom_container"
@ -93,16 +115,10 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/peertube_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/peertube_views"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp" />
android:layout_height="wrap_content" />
<TextView
android:id="@+id/peertube_date"

View File

@ -34,9 +34,9 @@
<ImageView
android:id="@+id/preview_playlist"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_height="100dp"
android:contentDescription="@string/preview"
android:scaleType="centerInside"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/preview_title"
app:layout_constraintStart_toStartOf="parent"
@ -46,6 +46,7 @@
android:id="@+id/preview_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/playlist_more"
@ -76,12 +77,11 @@
<ImageButton
android:id="@+id/playlist_more"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -6,11 +6,9 @@
android:icon="@drawable/ic_baseline_delete_24"
android:title="@string/delete"
app:showAsAction="ifRoom" />
<!--
<item
android:id="@+id/action_edit"
android:icon="@drawable/ic_baseline_edit_24"
android:title="@string/edit"
app:showAsAction="ifRoom" />
-->
</menu>

View File

@ -14,7 +14,7 @@
<argument
android:name="type"
android:defaultValue="POVERVIEW"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType=".viewmodel.FeedsVM$Type" />
</fragment>
@ -26,7 +26,7 @@
<argument
android:name="type"
android:defaultValue="PTRENDING"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType=".viewmodel.FeedsVM$Type" />
</fragment>
<fragment
@ -37,7 +37,7 @@
<argument
android:name="type"
android:defaultValue="PMOSTLIKED"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType=".viewmodel.FeedsVM$Type" />
</fragment>
@ -49,7 +49,7 @@
<argument
android:name="type"
android:defaultValue="PRECENTLYADDED"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType=".viewmodel.FeedsVM$Type" />
</fragment>
@ -61,7 +61,7 @@
<argument
android:name="type"
android:defaultValue="PLOCAL"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType=".viewmodel.FeedsVM$Type" />
</fragment>

View File

@ -14,7 +14,7 @@
<argument
android:name="type"
android:defaultValue="POVERVIEW"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType="app.fedilab.fedilabtube.viewmodel.FeedsVM$Type" />
</fragment>
@ -26,7 +26,7 @@
<argument
android:name="type"
android:defaultValue="PSUBSCRIPTIONS"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType="app.fedilab.fedilabtube.viewmodel.FeedsVM$Type" />
</fragment>
@ -38,7 +38,7 @@
<argument
android:name="type"
android:defaultValue="PTRENDING"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType="app.fedilab.fedilabtube.viewmodel.FeedsVM$Type" />
</fragment>
<fragment
@ -49,7 +49,7 @@
<argument
android:name="type"
android:defaultValue="PMOSTLIKED"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType="app.fedilab.fedilabtube.viewmodel.FeedsVM$Type" />
</fragment>
@ -61,7 +61,7 @@
<argument
android:name="type"
android:defaultValue="PRECENTLYADDED"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
app:argType="app.fedilab.fedilabtube.viewmodel.FeedsVM$Type" />
</fragment>
</navigation>

View File

@ -152,8 +152,9 @@
<string name="action_lists_confirm_delete">Êtes-vous sûr de vouloir supprimer définitivement cette liste de lecture ?</string>
<string name="action_channel_confirm_delete">Êtes-vous sûr de vouloir supprimer définitivement cette chaîne ?</string>
<string name="action_playlist_create">Créer une liste de lecture</string>
<string name="action_playlist_edit">Modifier une liste de lecture</string>
<string name="display_name">Nom d\'affichage</string>
<string name="error_channel_mandatory">Un canal est requis lorsque la liste de lecture est publique.</string>
<string name="error_channel_mandatory">Une chaîne est requise lorsque la liste de lecture est publique.</string>
<string name="error_display_name">Vous devez fournir un nom d\'affichage !</string>
<string name="error_display_name_channel">Vous devez fournir un nom d\'affichage et un nom pour la chaîne!</string>
<string name="action_playlist_empty_content">Cette liste de lecture est vide.</string>
@ -205,6 +206,7 @@
<string name="title_channel">Chaînes</string>
<string name="name">Nom</string>
<string name="action_channel_create">Créer une chaîne</string>
<string name="action_channel_edit">Modifier une chaîne</string>
<string name="delete_channel">Supprimer la chaîne</string>
<string name="display_list">Afficher la liste</string>
<string name="delete_list">Supprimer la liste de lecture</string>

View File

@ -0,0 +1,9 @@
Changements :
- Modification des chaînes et des listes de lecture
- Quelques changements visuels
- Quelques améliorations UX
Corrections :
- Plusieurs petites corrections de bug.