forked from mirrors/Fedilab
Some changes
This commit is contained in:
parent
4c5232039a
commit
82a5bfebb4
25 changed files with 130 additions and 346 deletions
|
@ -29,7 +29,7 @@ import android.webkit.MimeTypeMap;
|
|||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class BasePeertubeActivity extends BaseBarActivity {
|
|||
|
||||
protected ActivityPeertubeBinding binding;
|
||||
protected VideoData.Video peertube;
|
||||
protected SimpleExoPlayer player;
|
||||
protected ExoPlayer player;
|
||||
protected String videoURL;
|
||||
protected String subtitlesStr;
|
||||
|
||||
|
|
|
@ -106,6 +106,7 @@ import java.util.regex.Pattern;
|
|||
import app.fedilab.android.activities.AboutActivity;
|
||||
import app.fedilab.android.activities.LoginActivity;
|
||||
import app.fedilab.android.activities.MainActivity;
|
||||
import app.fedilab.android.activities.PeertubeBaseMainActivity;
|
||||
import app.fedilab.android.databinding.ActivityMainBinding;
|
||||
import app.fedilab.android.databinding.NavHeaderMainBinding;
|
||||
import app.fedilab.android.mastodon.activities.ActionActivity;
|
||||
|
@ -334,6 +335,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
});
|
||||
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
|
||||
}
|
||||
|
||||
|
||||
filteredAccounts = new ArrayList<>();
|
||||
mamageNewIntent(getIntent());
|
||||
filterFetched = false;
|
||||
|
@ -598,6 +601,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null);
|
||||
}
|
||||
currentAccount = new Account(BaseMainActivity.this).getConnectedAccount();
|
||||
if (currentAccount.api == Account.API.PEERTUBE) {
|
||||
startActivity(new Intent(this, PeertubeBaseMainActivity.class));
|
||||
finish();
|
||||
}
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -1006,7 +1013,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
Bundle extras = intent.getExtras();
|
||||
String userIdIntent, instanceIntent, urlOfMessage;
|
||||
if (extras != null && extras.containsKey(Helper.INTENT_ACTION)) {
|
||||
userIdIntent = extras.getString(Helper.PREF_KEY_ID); //Id of the account in the intent
|
||||
userIdIntent = extras.getString(Helper.PREF_USER_ID); //Id of the account in the intent
|
||||
instanceIntent = extras.getString(Helper.PREF_INSTANCE);
|
||||
urlOfMessage = extras.getString(Helper.PREF_MESSAGE_URL);
|
||||
if (extras.getInt(Helper.INTENT_ACTION) == Helper.NOTIFICATION_INTENT) {
|
||||
|
|
|
@ -266,7 +266,7 @@ public class Account extends BaseAccount implements Serializable {
|
|||
if (token.getAccess_token() != null)
|
||||
values.put(Sqlite.COL_TOKEN, token.getAccess_token());
|
||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_USER_ID, null);
|
||||
String instance = HelperInstance.getLiveInstance(context);
|
||||
try {
|
||||
return db.update(Sqlite.TABLE_USER_ACCOUNT,
|
||||
|
|
|
@ -177,8 +177,6 @@ public class Helper {
|
|||
public static final String INSTANCE_SOCIAL_KEY = "jGj9gW3z9ptyIpB8CMGhAlTlslcemMV6AgoiImfw3vPP98birAJTHOWiu5ZWfCkLvcaLsFZw9e3Pb7TIwkbIyrj3z6S7r2oE6uy6EFHvls3YtapP8QKNZ980p9RfzTb4";
|
||||
public static final String WEBSITE_VALUE = "https://fedilab.app";
|
||||
|
||||
public static final String OLD_DB_NAME = "mastodon_etalab_db";
|
||||
|
||||
public static final String RECEIVE_TOAST_MESSAGE = "RECEIVE_TOAST_MESSAGE";
|
||||
public static final String RECEIVE_TOAST_TYPE = "RECEIVE_TOAST_TYPE";
|
||||
public static final String RECEIVE_TOAST_CONTENT = "RECEIVE_TOAST_CONTENT";
|
||||
|
@ -296,15 +294,16 @@ public class Helper {
|
|||
|
||||
public static final String SCHEDULE_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
|
||||
|
||||
|
||||
public static final String PREF_USER_TOKEN = "PREF_USER_TOKEN";
|
||||
public static final String PREF_USER_ID = "PREF_USER_ID";
|
||||
public static final String PREF_USER_INSTANCE = "PREF_USER_INSTANCE";
|
||||
public static final String PREF_IS_MODERATOR = "PREF_IS_MODERATOR";
|
||||
public static final String PREF_IS_ADMINISTRATOR = "PREF_IS_ADMINISTRATOR";
|
||||
public static final String PREF_KEY_ID = "PREF_KEY_ID";
|
||||
public static final String PREF_MESSAGE_URL = "PREF_MESSAGE_URL";
|
||||
public static final String PREF_INSTANCE = "PREF_INSTANCE";
|
||||
|
||||
|
||||
public static final String SET_SECURITY_PROVIDER = "SET_SECURITY_PROVIDER";
|
||||
|
||||
public static final int NOTIFICATION_INTENT = 1;
|
||||
|
|
|
@ -369,7 +369,7 @@ public class NotificationsHelper {
|
|||
final Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(Helper.INTENT_ACTION, Helper.NOTIFICATION_INTENT);
|
||||
intent.putExtra(Helper.PREF_KEY_ID, account.user_id);
|
||||
intent.putExtra(Helper.PREF_USER_ID, account.user_id);
|
||||
if (targeted_account != null)
|
||||
intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
|
||||
intent.putExtra(Helper.PREF_INSTANCE, account.instance);
|
||||
|
|
|
@ -14,6 +14,7 @@ package app.fedilab.android.peertube.activities;
|
|||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
|
||||
import static app.fedilab.android.peertube.activities.PeertubeMainActivity.badgeCount;
|
||||
|
||||
import android.content.Intent;
|
||||
|
@ -79,7 +80,7 @@ public class AccountActivity extends BaseBarActivity {
|
|||
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
String token = sharedpreferences.getString(PREF_USER_TOKEN, null);
|
||||
|
||||
BaseAccount baseAccount = null;
|
||||
try {
|
||||
|
|
|
@ -15,6 +15,7 @@ package app.fedilab.android.peertube.activities;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_AUTO;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
|
||||
import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.ActionType.ADD_COMMENT;
|
||||
import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.ActionType.RATEVIDEO;
|
||||
import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.ActionType.REPLY;
|
||||
|
@ -38,7 +39,6 @@ import android.content.SharedPreferences;
|
|||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
@ -85,12 +85,12 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import com.bumptech.glide.Glide;
|
||||
import com.github.vkay94.dtpv.youtube.YouTubeOverlay;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.PlaybackException;
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
|
||||
import com.google.android.exoplayer2.source.MergingMediaSource;
|
||||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
|
@ -106,7 +106,7 @@ import com.google.android.exoplayer2.upstream.DataSource;
|
|||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.android.exoplayer2.video.VideoListener;
|
||||
import com.google.android.exoplayer2.video.VideoSize;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -124,10 +124,13 @@ import java.util.regex.Pattern;
|
|||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.BasePeertubeActivity;
|
||||
import app.fedilab.android.databinding.ActivityPeertubeBinding;
|
||||
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
|
||||
import app.fedilab.android.mastodon.exception.DBException;
|
||||
import app.fedilab.android.mastodon.helper.CacheDataSourceFactory;
|
||||
import app.fedilab.android.peertube.client.APIResponse;
|
||||
import app.fedilab.android.peertube.client.MenuItemVideo;
|
||||
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.android.peertube.client.data.AccountData;
|
||||
import app.fedilab.android.peertube.client.data.CaptionData.Caption;
|
||||
import app.fedilab.android.peertube.client.data.CommentData;
|
||||
import app.fedilab.android.peertube.client.data.CommentData.Comment;
|
||||
|
@ -144,7 +147,6 @@ import app.fedilab.android.peertube.client.entities.UserSettings;
|
|||
import app.fedilab.android.peertube.drawer.CommentListAdapter;
|
||||
import app.fedilab.android.peertube.drawer.MenuAdapter;
|
||||
import app.fedilab.android.peertube.drawer.MenuItemAdapter;
|
||||
import app.fedilab.android.peertube.helper.CacheDataSourceFactory;
|
||||
import app.fedilab.android.peertube.helper.Helper;
|
||||
import app.fedilab.android.peertube.helper.HelperInstance;
|
||||
import app.fedilab.android.peertube.viewmodel.CaptionsVM;
|
||||
|
@ -153,15 +155,13 @@ import app.fedilab.android.peertube.viewmodel.PlaylistsVM;
|
|||
import app.fedilab.android.peertube.viewmodel.PostActionsVM;
|
||||
import app.fedilab.android.peertube.viewmodel.SearchVM;
|
||||
import app.fedilab.android.peertube.viewmodel.TimelineVM;
|
||||
import app.fedilab.android.peertube.viewmodel.mastodon.MastodonPostActionsVM;
|
||||
import app.fedilab.android.peertube.webview.CustomWebview;
|
||||
import app.fedilab.android.peertube.webview.MastalabWebChromeClient;
|
||||
import app.fedilab.android.peertube.webview.MastalabWebViewClient;
|
||||
import app.fedilab.android.sqlite.Sqlite;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
|
||||
public class PeertubeActivity extends BasePeertubeActivity implements CommentListAdapter.AllCommentRemoved, Player.EventListener, VideoListener, MenuAdapter.ItemClicked, MenuItemAdapter.ItemAction {
|
||||
public class PeertubeActivity extends BasePeertubeActivity implements CommentListAdapter.AllCommentRemoved, MenuAdapter.ItemClicked, MenuItemAdapter.ItemAction, Player.Listener {
|
||||
|
||||
public static String video_id;
|
||||
public static List<String> playedVideos = new ArrayList<>();
|
||||
|
@ -198,19 +198,11 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
public static void hideKeyboard(Activity activity) {
|
||||
if (activity != null && activity.getWindow() != null) {
|
||||
activity.getWindow().getDecorView();
|
||||
InputMethodManager imm = activity.getSystemService(INPUT_METHOD_SERVICE);
|
||||
assert imm != null;
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(INPUT_METHOD_SERVICE);
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
|
||||
if (width < height) {
|
||||
videoOrientationType = videoOrientation.PORTRAIT;
|
||||
} else {
|
||||
videoOrientationType = videoOrientation.LANDSCAPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -219,17 +211,18 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
super.onCreate(savedInstanceState);
|
||||
videoOrientationType = videoOrientation.LANDSCAPE;
|
||||
max_id = "0";
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
String token = sharedpreferences.getString(PREF_USER_TOKEN, null);
|
||||
if (Helper.canMakeAction(PeertubeActivity.this) && !sepiaSearch) {
|
||||
Account account = null;
|
||||
BaseAccount account = null;
|
||||
try {
|
||||
account = new app.fedilab.android.mastodon.client.entities.app.Account(PeertubeActivity.this).getAccountByToken(token);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
loadAvatar(PeertubeActivity.this, account, binding.myPp);
|
||||
if (account != null) {
|
||||
loadAvatar(PeertubeActivity.this, account.peertube_account, binding.myPp);
|
||||
}
|
||||
}
|
||||
isRemote = false;
|
||||
|
||||
|
@ -278,9 +271,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
binding.peertubeLikeCount.setVisibility(View.GONE);
|
||||
binding.peertubeDislikeCount.setVisibility(View.GONE);
|
||||
binding.peertubePlaylist.setVisibility(View.GONE);
|
||||
binding.peertubeReblog.setVisibility(View.VISIBLE);
|
||||
binding.peertubeFavorite.setVisibility(View.VISIBLE);
|
||||
binding.peertubeBookmark.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
binding.peertubePlaylist.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -424,7 +414,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
return;
|
||||
}
|
||||
peertube = apiResponse.getPeertubes().get(0);
|
||||
Matomo.sendScreen(PeertubeActivity.this, "VIDEO_REGARDEE", peertube.getUuid());
|
||||
if (peertube.isNsfw()) {
|
||||
binding.videoSensitive.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
|
@ -583,7 +572,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
private void playVideo() {
|
||||
if (player != null) {
|
||||
player.release();
|
||||
player = new SimpleExoPlayer.Builder(PeertubeActivity.this).build();
|
||||
player = new ExoPlayer.Builder(PeertubeActivity.this).build();
|
||||
binding.mediaVideo.player(player);
|
||||
binding.doubleTapPlayerView.setPlayer(player);
|
||||
binding.loader.setVisibility(View.GONE);
|
||||
|
@ -889,7 +878,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
binding.videoInformation.setOnClickListener(v -> {
|
||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeActivity.this);
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
View dialogView = inflater.inflate(R.layout.popup_video_info, new LinearLayout(PeertubeActivity.this), false);
|
||||
View dialogView = inflater.inflate(R.layout.popup_video_info_peertube, new LinearLayout(PeertubeActivity.this), false);
|
||||
TextView info_privacy = dialogView.findViewById(R.id.info_privacy);
|
||||
TextView info_published_at = dialogView.findViewById(R.id.info_published_at);
|
||||
TextView info_category = dialogView.findViewById(R.id.info_category);
|
||||
|
@ -1046,8 +1035,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
|
||||
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
|
||||
|
||||
player = new SimpleExoPlayer.Builder(PeertubeActivity.this).build();
|
||||
player.addVideoListener(PeertubeActivity.this);
|
||||
player = new ExoPlayer.Builder(PeertubeActivity.this).build();
|
||||
player.addListener(this);
|
||||
binding.mediaVideo.player(player);
|
||||
binding.doubleTapPlayerView.setPlayer(player);
|
||||
|
@ -1437,7 +1425,8 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
|
||||
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
|
||||
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
|
||||
if (!isInPictureInPictureMode) {
|
||||
if (onStopCalled) {
|
||||
isPlayInMinimized = false;
|
||||
|
@ -1446,7 +1435,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void toogleFullscreen(boolean fullscreen) {
|
||||
|
||||
if (fullscreen) {
|
||||
|
@ -1645,7 +1633,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
if (mode == Helper.VIDEO_MODE_NORMAL) {
|
||||
if (player != null)
|
||||
player.release();
|
||||
player = new SimpleExoPlayer.Builder(PeertubeActivity.this).build();
|
||||
player = new ExoPlayer.Builder(PeertubeActivity.this).build();
|
||||
binding.mediaVideo.player(player);
|
||||
binding.doubleTapPlayerView.setPlayer(player);
|
||||
binding.loader.setVisibility(View.GONE);
|
||||
|
@ -1688,7 +1676,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
player.release();
|
||||
|
||||
TrackSelector trackSelector = new DefaultTrackSelector(PeertubeActivity.this, new AdaptiveTrackSelection.Factory());
|
||||
player = new SimpleExoPlayer.Builder(PeertubeActivity.this).setTrackSelector(trackSelector).build();
|
||||
player = new ExoPlayer.Builder(PeertubeActivity.this).setTrackSelector(trackSelector).build();
|
||||
binding.mediaVideo.player(player);
|
||||
binding.doubleTapPlayerView.setPlayer(player);
|
||||
captionLang = item.getStrId();
|
||||
|
@ -1788,10 +1776,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
if (Helper.isLoggedIn(PeertubeActivity.this)) {
|
||||
PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModelComment.comment(ADD_COMMENT, peertube.getId(), null, commentStr).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, 0, apiResponse1));
|
||||
} else {//Remote account is posting a message
|
||||
String url = "https://" + peertube.getChannel().getHost() + "/videos/watch/" + peertube.getUuid();
|
||||
MastodonPostActionsVM viewModelCommentMastodon = new ViewModelProvider(PeertubeActivity.this).get(MastodonPostActionsVM.class);
|
||||
viewModelCommentMastodon.comment(url, commentStr).observe(PeertubeActivity.this, status -> manageVIewPostActionsMastodon(ADD_COMMENT, position, status));
|
||||
}
|
||||
binding.addCommentWrite.setText("");
|
||||
}
|
||||
|
@ -1801,9 +1785,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
if (Helper.isLoggedIn(PeertubeActivity.this)) {
|
||||
PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModelComment.comment(REPLY, peertube.getId(), comment.getId(), commentView).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(REPLY, position, apiResponse1));
|
||||
} else {//Remote account is posting a message
|
||||
MastodonPostActionsVM viewModelCommentMastodon = new ViewModelProvider(PeertubeActivity.this).get(MastodonPostActionsVM.class);
|
||||
viewModelCommentMastodon.comment(comment.getUrl(), commentView).observe(PeertubeActivity.this, status -> manageVIewPostActionsMastodon(REPLY, position, status));
|
||||
}
|
||||
binding.addCommentWrite.setText("");
|
||||
}
|
||||
|
@ -1848,7 +1829,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
public void openPostComment(Comment comment, int position) {
|
||||
if (comment != null) {
|
||||
binding.replyContent.setVisibility(View.VISIBLE);
|
||||
Account account = comment.getAccount();
|
||||
AccountData.PeertubeAccount account = comment.getAccount();
|
||||
loadAvatar(PeertubeActivity.this, account, binding.commentAccountProfile);
|
||||
binding.commentAccountDisplayname.setText(account.getDisplayName());
|
||||
binding.commentAccountUsername.setText(account.getAcct());
|
||||
|
@ -1934,33 +1915,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
}
|
||||
|
||||
|
||||
public void manageVIewPostActionsMastodon(RetrofitPeertubeAPI.ActionType statusAction, int position, app.fedilab.android.peertube.client.mastodon.Status status) {
|
||||
if (peertube.isCommentsEnabled() && statusAction == ADD_COMMENT) {
|
||||
if (status != null) {
|
||||
Comment comment = app.fedilab.android.peertube.client.mastodon.Status.convertStatusToComment(status);
|
||||
comments.add(0, comment);
|
||||
commentListAdapter.notifyItemInserted(0);
|
||||
}
|
||||
} else if (peertube.isCommentsEnabled() && statusAction == REPLY) {
|
||||
if (status != null) {
|
||||
Comment comment = app.fedilab.android.peertube.client.mastodon.Status.convertStatusToComment(status);
|
||||
if (commentsThread == null) {
|
||||
commentsThread = new ArrayList<>();
|
||||
}
|
||||
commentsThread.add(position + 1, comment);
|
||||
commentReplyListAdapter.notifyItemInserted(position + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void retrieveRemoteStatus(app.fedilab.android.peertube.client.mastodon.Status status) {
|
||||
this.status = status;
|
||||
if (status != null) {
|
||||
changeColorMastodon();
|
||||
binding.peertubeFavorite.setText(String.valueOf(status.getFavouriteCount()));
|
||||
binding.peertubeReblog.setText(String.valueOf(status.getReblogsCount()));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unused", "RedundantSuppression"})
|
||||
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, int position, APIResponse apiResponse) {
|
||||
|
@ -2040,13 +1994,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
}
|
||||
|
||||
|
||||
private void changeColorMastodon() {
|
||||
Drawable reblog = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_repeat_24);
|
||||
Drawable favorite = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_star_24);
|
||||
Drawable bookmark = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_bookmark_24);
|
||||
|
||||
}
|
||||
|
||||
private void changeColor() {
|
||||
|
||||
Drawable thumbUp = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_thumb_up_alt_24);
|
||||
|
@ -2063,13 +2010,13 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
}
|
||||
if (peertube.getMyRating() != null && peertube.getMyRating().compareTo("like") == 0) {
|
||||
if (thumbUp != null) {
|
||||
thumbUp.setColorFilter(getResources().getColor(R.color.positive_thumbs), PorterDuff.Mode.SRC_ATOP);
|
||||
DrawableCompat.setTint(thumbUp, getResources().getColor(R.color.positive_thumbs));
|
||||
thumbUp.setColorFilter(getAttColor(PeertubeActivity.this, R.attr.primaryColor), PorterDuff.Mode.SRC_ATOP);
|
||||
DrawableCompat.setTint(thumbUp, getAttColor(PeertubeActivity.this, R.attr.primaryColor));
|
||||
}
|
||||
} else if (peertube.getMyRating() != null && peertube.getMyRating().compareTo("dislike") == 0) {
|
||||
if (thumbDown != null) {
|
||||
thumbDown.setColorFilter(getResources().getColor(R.color.negative_thumbs), PorterDuff.Mode.SRC_ATOP);
|
||||
DrawableCompat.setTint(thumbDown, getResources().getColor(R.color.negative_thumbs));
|
||||
thumbDown.setColorFilter(getAttColor(PeertubeActivity.this, R.attr.colorError), PorterDuff.Mode.SRC_ATOP);
|
||||
DrawableCompat.setTint(thumbDown, getAttColor(PeertubeActivity.this, R.attr.colorError));
|
||||
}
|
||||
}
|
||||
binding.peertubeLikeCount.setCompoundDrawablesWithIntrinsicBounds(null, thumbUp, null, null);
|
||||
|
@ -2228,11 +2175,21 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerError(ExoPlaybackException error) {
|
||||
|
||||
public void onVideoSizeChanged(@NonNull VideoSize videoSize) {
|
||||
Player.Listener.super.onVideoSizeChanged(videoSize);
|
||||
if (videoSize.width < videoSize.height) {
|
||||
videoOrientationType = videoOrientation.PORTRAIT;
|
||||
} else {
|
||||
videoOrientationType = videoOrientation.LANDSCAPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPlayerError(PlaybackException error) {
|
||||
Player.Listener.super.onPlayerError(error);
|
||||
}
|
||||
|
||||
enum videoOrientation {
|
||||
LANDSCAPE,
|
||||
PORTRAIT
|
||||
|
|
|
@ -14,6 +14,8 @@ package app.fedilab.android.peertube.activities;
|
|||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
|
||||
import static app.fedilab.android.peertube.helper.Helper.peertubeInformation;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
@ -147,7 +149,7 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
|
|||
WellKnownNodeinfo.NodeInfo instanceNodeInfo = new RetrofitPeertubeAPI(activity, newInstance, null).getNodeInfo();
|
||||
if (instanceNodeInfo.getSoftware() != null && instanceNodeInfo.getSoftware().getName().trim().toLowerCase().compareTo("peertube") == 0) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_INSTANCE, newInstance);
|
||||
editor.putString(PREF_INSTANCE, newInstance);
|
||||
editor.commit();
|
||||
if (storeInDb) {
|
||||
newInstance = newInstance.trim().toLowerCase();
|
||||
|
@ -352,8 +354,8 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
|
|||
String tokenStr = Helper.getToken(PeertubeMainActivity.this);
|
||||
String instance = HelperInstance.getLiveInstance(PeertubeMainActivity.this);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String instanceShar = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||
String userIdShar = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instanceShar = sharedpreferences.getString(PREF_INSTANCE, null);
|
||||
String userIdShar = sharedpreferences.getString(PREF_USER_ID, null);
|
||||
BaseAccount account = null;
|
||||
try {
|
||||
account = new Account(PeertubeMainActivity.this).getAccountByToken(tokenStr);
|
||||
|
@ -399,8 +401,7 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
|
|||
e.printStackTrace();
|
||||
}
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_ID, account.user_id);
|
||||
editor.putString(Helper.PREF_KEY_NAME, account.peertube_account.getUsername());
|
||||
editor.putString(PREF_USER_ID, account.user_id);
|
||||
editor.putBoolean(getString(R.string.set_autoplay_choice), userMe.isAutoPlayVideo());
|
||||
editor.putBoolean(getString(R.string.set_store_in_history), userMe.isVideosHistoryEnabled());
|
||||
editor.putBoolean(getString(R.string.set_autoplay_next_video_choice), userMe.isAutoPlayNextVideo());
|
||||
|
@ -686,7 +687,7 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
|
|||
alt_bld.setSingleChoiceItems(academiesKey, position, (dialog, item) -> {
|
||||
String newInstance = academiesValue[item];
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_INSTANCE, newInstance);
|
||||
editor.putString(PREF_INSTANCE, newInstance);
|
||||
editor.commit();
|
||||
dialog.dismiss();
|
||||
recreate();
|
||||
|
@ -704,7 +705,7 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
|
|||
if (data != null && data.getData() != null) {
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_INSTANCE, String.valueOf(data.getData()));
|
||||
editor.putString(PREF_INSTANCE, String.valueOf(data.getData()));
|
||||
editor.commit();
|
||||
recreate();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,10 @@ package app.fedilab.android.peertube.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 static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -174,9 +178,8 @@ public class RetrofitPeertubeAPI {
|
|||
boolean userExists = false;
|
||||
try {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_ID, account.user_id);
|
||||
editor.putString(Helper.PREF_KEY_NAME, peertubeAccount.getUsername());
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
editor.putString(PREF_USER_ID, account.user_id);
|
||||
editor.putString(PREF_INSTANCE, host);
|
||||
editor.apply();
|
||||
new Account(activity).insertOrUpdate(account);
|
||||
} catch (DBException e) {
|
||||
|
@ -250,7 +253,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (oauthParams.getGrant_type().compareTo("refresh_token") == 0 && tokenReply != null) {
|
||||
SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, tokenReply.getAccess_token());
|
||||
editor.putString(PREF_USER_TOKEN, tokenReply.getAccess_token());
|
||||
editor.putString(Helper.PREF_SOFTWARE, null);
|
||||
editor.putString(Helper.PREF_REMOTE_INSTANCE, null);
|
||||
editor.apply();
|
||||
|
|
|
@ -644,6 +644,7 @@ public class VideoData implements Serializable {
|
|||
public static class UserHistory implements Serializable {
|
||||
|
||||
|
||||
|
||||
@SerializedName("currentTime")
|
||||
long currentTime;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ package app.fedilab.android.peertube.drawer;
|
|||
|
||||
|
||||
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
|
@ -45,6 +46,7 @@ import app.fedilab.android.databinding.DrawerAboutInstancePeertubeBinding;
|
|||
import app.fedilab.android.peertube.client.data.InstanceData;
|
||||
import app.fedilab.android.peertube.helper.Helper;
|
||||
import app.fedilab.android.peertube.sqlite.StoredInstanceDAO;
|
||||
import app.fedilab.android.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
@ -127,7 +129,7 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
holder.binding.instanceContainer.setOnClickListener(v -> {
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_INSTANCE, aboutInstance.getHost());
|
||||
editor.putString(PREF_INSTANCE, aboutInstance.getHost());
|
||||
editor.commit();
|
||||
Helper.logoutNoRemoval((Activity) context);
|
||||
});
|
||||
|
|
|
@ -14,6 +14,9 @@ package app.fedilab.android.peertube.drawer;
|
|||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -136,8 +139,8 @@ public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String channeIdOwner = channel.getOwnerAccount().getId();
|
||||
String channeInstanceOwner = channel.getOwnerAccount().getHost();
|
||||
String instanceShar = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||
String userIdShar = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instanceShar = sharedpreferences.getString(PREF_INSTANCE, null);
|
||||
String userIdShar = sharedpreferences.getString(PREF_USER_ID, null);
|
||||
if (channeIdOwner != null && channeInstanceOwner != null && instanceShar != null && userIdShar != null) {
|
||||
return channeIdOwner.compareTo(userIdShar) == 0 && channeInstanceOwner.compareTo(instanceShar) == 0;
|
||||
} else {
|
||||
|
|
|
@ -76,10 +76,10 @@ public class OwnAccountsAdapter extends ArrayAdapter<BaseAccount> {
|
|||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
ac
|
||||
holder.account_un.setText(String.format("@%s", account.getAcct()));
|
||||
|
||||
holder.account_un.setText(String.format("@%s", account.peertube_account.getAcct()));
|
||||
//Profile picture
|
||||
Helper.loadAvatar(holder.account_pp.getContext(), account, holder.account_pp);
|
||||
Helper.loadAvatar(holder.account_pp.getContext(), account.peertube_account, holder.account_pp);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,9 +119,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
return;
|
||||
}
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
|
||||
|
||||
assert userId != null;
|
||||
|
||||
boolean videoInList = sharedpreferences.getBoolean(context.getString(R.string.set_video_in_list_choice), false);
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ package app.fedilab.android.peertube.drawer;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -110,15 +109,8 @@ public class PlaylistAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||
playlists.remove(playlist);
|
||||
notifyDataSetChanged();
|
||||
if (!locale) {
|
||||
PlaylistsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class);
|
||||
viewModel.manage(PlaylistsVM.action.DELETE_PLAYLIST, playlist, null).observe((LifecycleOwner) context, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.DELETE_PLAYLIST, apiResponse));
|
||||
} else {
|
||||
new Thread(() -> {
|
||||
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new ManagePlaylistsDAO(context, db).removePlaylist(playlist.getUuid());
|
||||
}).start();
|
||||
}
|
||||
if (playlists.size() == 0) {
|
||||
allPlaylistRemoved.onAllPlaylistRemoved();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import java.util.List;
|
|||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.peertube.client.APIResponse;
|
||||
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.android.peertube.client.data.AccountData;
|
||||
import app.fedilab.android.peertube.client.data.BlockData;
|
||||
import app.fedilab.android.peertube.drawer.AccountsListAdapter;
|
||||
import app.fedilab.android.peertube.viewmodel.AccountsVM;
|
||||
|
@ -49,7 +50,7 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
private Context context;
|
||||
private AccountsListAdapter accountsListAdapter;
|
||||
private String max_id;
|
||||
private List<Account> accounts;
|
||||
private List<AccountData.PeertubeAccount> accounts;
|
||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||
private boolean firstLoad;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
@ -168,7 +169,7 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
return;
|
||||
}
|
||||
flag_loading = (apiResponse.getMax_id() == null);
|
||||
List<Account> accounts = apiResponse.getAccounts();
|
||||
List<AccountData.PeertubeAccount> accounts = apiResponse.getAccounts();
|
||||
if (accountFetch == RetrofitPeertubeAPI.DataType.MUTED) {
|
||||
accounts = new ArrayList<>();
|
||||
List<BlockData.Block> blockList = apiResponse.getMuted();
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
package app.fedilab.android.peertube.helper;
|
||||
/* 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 com.google.android.exoplayer2.database.ExoDatabaseProvider;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.FileDataSource;
|
||||
import com.google.android.exoplayer2.upstream.cache.CacheDataSink;
|
||||
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
|
||||
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
|
||||
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
public class CacheDataSourceFactory implements DataSource.Factory {
|
||||
private static SimpleCache sDownloadCache;
|
||||
private final Context context;
|
||||
private final DefaultDataSourceFactory defaultDatasourceFactory;
|
||||
private final long maxFileSize;
|
||||
|
||||
public CacheDataSourceFactory(Context context) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.maxFileSize = 5 * 1024 * 1024;
|
||||
DefaultBandwidthMeter.Builder bandwidthMeterBuilder = new DefaultBandwidthMeter.Builder(context);
|
||||
DefaultBandwidthMeter bandwidthMeter = bandwidthMeterBuilder.build();
|
||||
defaultDatasourceFactory = new DefaultDataSourceFactory(this.context,
|
||||
bandwidthMeter,
|
||||
new DefaultHttpDataSourceFactory(Util.getUserAgent(context, null), bandwidthMeter));
|
||||
}
|
||||
|
||||
public static SimpleCache getInstance(Context context) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(video_cache * 1024 * 1024);
|
||||
ExoDatabaseProvider exoDatabaseProvider = new ExoDatabaseProvider(context);
|
||||
if (sDownloadCache == null)
|
||||
sDownloadCache = new SimpleCache(new File(context.getCacheDir(), "media"), evictor, exoDatabaseProvider);
|
||||
return sDownloadCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource createDataSource() {
|
||||
SimpleCache simpleCache = getInstance(context);
|
||||
return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(),
|
||||
new FileDataSource(), new CacheDataSink(simpleCache, maxFileSize),
|
||||
CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, null);
|
||||
}
|
||||
}
|
|
@ -16,6 +16,9 @@ package app.fedilab.android.peertube.helper;
|
|||
|
||||
import static android.content.Context.DOWNLOAD_SERVICE;
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
|
@ -122,7 +125,8 @@ public class Helper {
|
|||
public static final String OAUTH_SCOPES_PEERTUBE = "openid profile";
|
||||
public static final String OAUTH_SCOPES_MASTODON = "read write follow";
|
||||
public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob";
|
||||
public static final String PREF_KEY_OAUTH_TOKEN = "oauth_token";
|
||||
public static final String PREF_SOFTWARE = "pref_software";
|
||||
public static final String PREF_REMOTE_INSTANCE = "pref_remote_instance";
|
||||
public static final Pattern redirectPattern = Pattern.compile("externalAuthToken=(\\w+)&username=([\\w.-]+)");
|
||||
public static final String SET_VIDEO_CACHE = "set_video_cache";
|
||||
public static final String RECEIVE_CAST_SETTINGS = "receive_cast_settings";
|
||||
|
@ -131,9 +135,6 @@ public class Helper {
|
|||
public static final String SET_PROXY_HOST = "set_proxy_host";
|
||||
public static final String SET_PROXY_PORT = "set_proxy_port";
|
||||
public static final String INTENT_ACTION = "intent_action";
|
||||
public static final String PREF_KEY_ID = "userID";
|
||||
public static final String PREF_KEY_NAME = "my_user_name";
|
||||
public static final String PREF_INSTANCE = "instance";
|
||||
public static final int EXTERNAL_STORAGE_REQUEST_CODE = 84;
|
||||
public static final String SET_VIDEOS_PER_PAGE = "set_videos_per_page";
|
||||
public static final String VIDEO_ID = "video_id_update";
|
||||
|
@ -565,11 +566,11 @@ public class Helper {
|
|||
public static void logoutNoRemoval(Activity activity) {
|
||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(PREF_KEY_OAUTH_TOKEN, null);
|
||||
editor.putString(PREF_USER_TOKEN, null);
|
||||
editor.putString(CLIENT_ID, null);
|
||||
editor.putString(CLIENT_SECRET, null);
|
||||
editor.putString(PREF_KEY_ID, null);
|
||||
editor.putString(ID, null);
|
||||
editor.putString(PREF_USER_ID, null);
|
||||
editor.putString(PREF_INSTANCE, null);
|
||||
editor.apply();
|
||||
Intent loginActivity = new Intent(activity, PeertubeMainActivity.class);
|
||||
activity.startActivity(loginActivity);
|
||||
|
@ -619,7 +620,7 @@ public class Helper {
|
|||
*/
|
||||
public static PeertubeMainActivity.TypeOfConnection isLoggedInType(Context context) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(PREF_USER_TOKEN, null);
|
||||
String prefSoftware = sharedpreferences.getString(PREF_SOFTWARE, null);
|
||||
if (prefKeyOauthTokenT != null && prefSoftware == null) {
|
||||
return PeertubeMainActivity.TypeOfConnection.NORMAL;
|
||||
|
@ -633,7 +634,7 @@ public class Helper {
|
|||
public static String getToken(Context context) {
|
||||
if (isLoggedInType(context) == PeertubeMainActivity.TypeOfConnection.NORMAL) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
return sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
return sharedpreferences.getString(PREF_USER_TOKEN, null);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -660,28 +661,24 @@ public class Helper {
|
|||
|
||||
public static boolean isOwner(Context context, AccountData.PeertubeAccount account) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
String userName = sharedpreferences.getString(Helper.PREF_KEY_NAME, "");
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, "");
|
||||
if (instance != null && userName != null) {
|
||||
return account.getUsername().compareTo(userName) == 0 && account.getHost().compareTo(instance) == 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
String userId = sharedpreferences.getString(PREF_USER_ID, "");
|
||||
String instance = sharedpreferences.getString(PREF_INSTANCE, "");
|
||||
return account.getUserId().compareTo(userId) == 0 && account.getHost().compareTo(instance) == 0;
|
||||
}
|
||||
|
||||
public static boolean isVideoOwner(Context context, VideoData.Video video) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
String userName = sharedpreferences.getString(Helper.PREF_KEY_NAME, "");
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, "");
|
||||
String userId = sharedpreferences.getString(PREF_USER_ID, "");
|
||||
String instance = sharedpreferences.getString(PREF_INSTANCE, "");
|
||||
if (video == null) {
|
||||
return false;
|
||||
}
|
||||
AccountData.PeertubeAccount account = video.getAccount();
|
||||
ChannelData.Channel channel = video.getChannel();
|
||||
if (account != null && instance != null && userName != null) {
|
||||
return account.getUsername().compareTo(userName) == 0 && account.getHost().compareTo(instance) == 0;
|
||||
} else if (channel != null && instance != null && userName != null) {
|
||||
return channel.getName().compareTo(userName) == 0 && channel.getHost().compareTo(instance) == 0;
|
||||
if (account != null) {
|
||||
return account.getUserId().compareTo(userId) == 0 && account.getHost().compareTo(instance) == 0;
|
||||
} else if (channel != null) {
|
||||
return channel.getOwnerAccount().getUserId().compareTo(userId) == 0 && channel.getHost().compareTo(instance) == 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ package app.fedilab.android.peertube.helper;
|
|||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
|
@ -29,7 +31,7 @@ public class HelperInstance {
|
|||
*/
|
||||
public static String getLiveInstance(Context context) {
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
return sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||
return sharedpreferences.getString(PREF_INSTANCE, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@ package app.fedilab.android.peertube.helper;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
@ -57,10 +60,9 @@ public class SwitchAccountHelper {
|
|||
final BaseAccount account = accountArray[which];
|
||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.token);
|
||||
editor.putString(Helper.PREF_INSTANCE, account.instance);
|
||||
editor.putString(Helper.PREF_KEY_ID, account.user_id);
|
||||
editor.putString(Helper.PREF_KEY_NAME, account.peertube_account != null ? account.peertube_account.getUsername() : null);
|
||||
editor.putString(PREF_USER_TOKEN, account.token);
|
||||
editor.putString(PREF_INSTANCE, account.instance);
|
||||
editor.putString(PREF_USER_ID, account.user_id);
|
||||
editor.apply();
|
||||
dialog.dismiss();
|
||||
Intent intent = new Intent(activity, BaseMainActivity.class);
|
||||
|
|
|
@ -14,6 +14,8 @@ package app.fedilab.android.peertube.sqlite;
|
|||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -88,7 +90,7 @@ public class StoredInstanceDAO {
|
|||
}
|
||||
ContentValues values = new ContentValues();
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String userId = sharedpreferences.getString(PREF_USER_ID, null);
|
||||
String instance = HelperInstance.getLiveInstance(context);
|
||||
|
||||
values.put(Sqlite.COL_USER_ID, userId != null ? userId : "_ALL_");
|
||||
|
|
|
@ -14,12 +14,8 @@ package app.fedilab.android.peertube.viewmodel;
|
|||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -28,6 +24,8 @@ import androidx.lifecycle.AndroidViewModel;
|
|||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.android.mastodon.client.entities.app.Account;
|
||||
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
|
||||
import app.fedilab.android.peertube.client.APIResponse;
|
||||
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.android.peertube.client.data.AccountData;
|
||||
|
@ -59,10 +57,9 @@ public class ChannelsVM extends AndroidViewModel {
|
|||
String finalElement = element;
|
||||
try {
|
||||
if (type == RetrofitPeertubeAPI.DataType.MY_CHANNELS) {
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String token = Helper.getToken(_mContext);
|
||||
AccountData.PeertubeAccount account = new AccountDAO(_mContext, db).getAccountByToken(token);
|
||||
BaseAccount baseAccount = new Account(_mContext).getAccountByToken(token);
|
||||
AccountData.PeertubeAccount account = baseAccount.peertube_account;
|
||||
finalElement = account.getUsername() + "@" + account.getHost();
|
||||
}
|
||||
RetrofitPeertubeAPI retrofitPeertubeAPI;
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.android.peertube.client.data.InstanceData;
|
||||
import app.fedilab.android.peertube.sqlite.StoredInstanceDAO;
|
||||
import app.fedilab.android.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class InfoInstanceVM extends AndroidViewModel {
|
||||
|
|
|
@ -24,8 +24,10 @@ import androidx.lifecycle.AndroidViewModel;
|
|||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
|
||||
import app.fedilab.android.peertube.client.APIResponse;
|
||||
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.android.peertube.client.entities.Error;
|
||||
|
||||
|
||||
public class NotificationsVM extends AndroidViewModel {
|
||||
|
@ -35,13 +37,13 @@ public class NotificationsVM extends AndroidViewModel {
|
|||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getNotifications(Account account, String max_id) {
|
||||
public LiveData<APIResponse> getNotifications(BaseAccount account, String max_id) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadNotifications(account, max_id);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void loadNotifications(Account account, String max_id) {
|
||||
private void loadNotifications(BaseAccount account, String max_id) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
|
@ -55,7 +57,7 @@ public class NotificationsVM extends AndroidViewModel {
|
|||
apiResponse = new APIResponse();
|
||||
apiResponse.setError(new Error());
|
||||
}
|
||||
api = new RetrofitPeertubeAPI(_mContext, account.getHost(), account.getToken());
|
||||
api = new RetrofitPeertubeAPI(_mContext, account.instance, account.token);
|
||||
apiResponse = api.getNotifications(null, max_id);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
package app.fedilab.android.peertube.viewmodel.mastodon;
|
||||
/* Copyright 2021 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.android.peertube.client.mastodon.RetrofitMastodonAPI;
|
||||
import app.fedilab.android.peertube.client.mastodon.Status;
|
||||
|
||||
|
||||
public class MastodonPostActionsVM extends AndroidViewModel {
|
||||
private MutableLiveData<Status> statusMutableLiveData;
|
||||
|
||||
public MastodonPostActionsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
|
||||
public LiveData<Status> post(RetrofitMastodonAPI.actionType type, Status status) {
|
||||
statusMutableLiveData = new MutableLiveData<>();
|
||||
postAction(type, status);
|
||||
return statusMutableLiveData;
|
||||
}
|
||||
|
||||
public LiveData<Status> comment(String url, String content) {
|
||||
statusMutableLiveData = new MutableLiveData<>();
|
||||
postComment(url, content);
|
||||
return statusMutableLiveData;
|
||||
}
|
||||
|
||||
public LiveData<Status> searchRemoteStatus(String url) {
|
||||
statusMutableLiveData = new MutableLiveData<>();
|
||||
search(url);
|
||||
return statusMutableLiveData;
|
||||
}
|
||||
|
||||
private void search(String videoURL) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
RetrofitMastodonAPI mastodonAPI = new RetrofitMastodonAPI(_mContext);
|
||||
Status status = null;
|
||||
try {
|
||||
status = mastodonAPI.search(videoURL);
|
||||
} catch (Error error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Status finalStatus = status;
|
||||
Runnable myRunnable = () -> statusMutableLiveData.setValue(finalStatus);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void postComment(String videoURL, String content) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
RetrofitMastodonAPI mastodonAPI = new RetrofitMastodonAPI(_mContext);
|
||||
Status status = null;
|
||||
try {
|
||||
status = mastodonAPI.commentAction(videoURL, content);
|
||||
} catch (Error error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Status finalStatus = status;
|
||||
Runnable myRunnable = () -> statusMutableLiveData.setValue(finalStatus);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
private void postAction(RetrofitMastodonAPI.actionType type, Status status) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
RetrofitMastodonAPI mastodonAPI = new RetrofitMastodonAPI(_mContext);
|
||||
Status statusReply = mastodonAPI.postAction(type, status);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> statusMutableLiveData.setValue(statusReply);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue