Last fixes

This commit is contained in:
Thomas 2020-11-11 10:34:28 +01:00
parent 17c84f6c37
commit 431c21e066
32 changed files with 537 additions and 514 deletions

View File

@ -101,7 +101,6 @@ public class LoginActivity extends AppCompatActivity {
}
if (!BuildConfig.full_instances) {
binding.loginUid.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {

View File

@ -83,20 +83,11 @@ public class MainActivity extends AppCompatActivity {
public static int PICK_INSTANCE = 5641;
public static int PICK_INSTANCE_SURF = 5642;
public static UserMe userMe;
final FragmentManager fm = getSupportFragmentManager();
Fragment active;
private DisplayVideosFragment recentFragment, locaFragment, trendingFragment, subscriptionFragment, mostLikedFragment;
private DisplayOverviewFragment overviewFragment;
public static UserMe userMe;
public enum TypeOfConnection{
UNKNOWN,
NORMAL,
SURFING
}
private TypeOfConnection typeOfConnection;
private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= item -> {
DisplayVideosFragment displayVideosFragment = null;
@ -130,7 +121,66 @@ public class MainActivity extends AppCompatActivity {
return false;
}
};
private TypeOfConnection typeOfConnection;
@SuppressLint("ApplySharedPref")
public static void showRadioButtonDialogFullInstances(Activity activity, boolean storeInDb) {
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
AlertDialog.Builder alt_bld = new AlertDialog.Builder(activity);
alt_bld.setTitle(R.string.instance_choice);
String instance = Helper.getLiveInstance(activity);
final EditText input = new EditText(activity);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
alt_bld.setView(input);
input.setText(instance);
alt_bld.setPositiveButton(R.string.validate,
(dialog, which) -> new Thread(() -> {
try {
String newInstance = input.getText().toString().trim();
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.commit();
if (storeInDb) {
newInstance = newInstance.trim().toLowerCase();
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(activity, newInstance, null).getAboutInstance();
SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StoredInstanceDAO(activity, db).insertInstance(aboutInstance, newInstance);
activity.runOnUiThread(() -> {
dialog.dismiss();
Helper.logoutNoRemoval(activity);
});
} else {
activity.runOnUiThread(() -> {
dialog.dismiss();
Intent intent = new Intent(activity, MainActivity.class);
activity.startActivity(intent);
});
}
} else {
activity.runOnUiThread(() -> Toasty.error(activity, activity.getString(R.string.not_valide_instance), Toast.LENGTH_LONG).show());
}
} catch (Exception e) {
e.printStackTrace();
}
}).start());
alt_bld.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
alt_bld.setNeutralButton(R.string.help, (dialog, which) -> {
Intent intent = new Intent(activity, InstancePickerActivity.class);
if (storeInDb) {
activity.startActivityForResult(intent, PICK_INSTANCE_SURF);
} else {
activity.startActivityForResult(intent, PICK_INSTANCE);
}
});
AlertDialog alert = alt_bld.create();
alert.show();
}
private void setTitleCustom(int titleRId) {
Toolbar toolbar = findViewById(R.id.toolbar);
@ -290,7 +340,8 @@ public class MainActivity extends AppCompatActivity {
runOnUiThread(() -> Helper.logoutCurrentUser(MainActivity.this, finalAccount));
error.printStackTrace();
}
}}).start();
}
}).start();
} else {
navView.inflateMenu(R.menu.bottom_nav_menu);
@ -590,68 +641,6 @@ public class MainActivity extends AppCompatActivity {
alert.show();
}
@SuppressLint("ApplySharedPref")
public static void showRadioButtonDialogFullInstances(Activity activity, boolean storeInDb) {
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
AlertDialog.Builder alt_bld = new AlertDialog.Builder(activity);
alt_bld.setTitle(R.string.instance_choice);
String instance = Helper.getLiveInstance(activity);
final EditText input = new EditText(activity);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
alt_bld.setView(input);
input.setText(instance);
alt_bld.setPositiveButton(R.string.validate,
(dialog, which) -> new Thread(() -> {
try {
String newInstance = input.getText().toString().trim();
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.commit();
if( storeInDb) {
newInstance = newInstance.trim().toLowerCase();
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(activity, newInstance, null).getAboutInstance();
SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StoredInstanceDAO(activity, db).insertInstance(aboutInstance, newInstance);
activity.runOnUiThread(() -> {
dialog.dismiss();
Helper.logoutNoRemoval(activity);
});
}else {
activity.runOnUiThread(() -> {
dialog.dismiss();
Intent intent = new Intent(activity, MainActivity.class);
activity.startActivity(intent);
});
}
} else {
activity.runOnUiThread(() -> Toasty.error(activity, activity.getString(R.string.not_valide_instance), Toast.LENGTH_LONG).show());
}
} catch (Exception e) {
e.printStackTrace();
}
}).start());
alt_bld.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
alt_bld.setNeutralButton(R.string.help, (dialog, which) -> {
Intent intent = new Intent(activity, InstancePickerActivity.class);
if(storeInDb) {
activity.startActivityForResult(intent, PICK_INSTANCE_SURF);
}else{
activity.startActivityForResult(intent, PICK_INSTANCE);
}
});
AlertDialog alert = alt_bld.create();
alert.show();
}
@SuppressLint("ApplySharedPref")
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
@ -664,15 +653,13 @@ public class MainActivity extends AppCompatActivity {
editor.commit();
finish();
}
}else if (requestCode == PICK_INSTANCE_SURF && resultCode == Activity.RESULT_OK) {
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.commit();
}
}
finish();
}
}
public enum TypeOfConnection {
UNKNOWN,
NORMAL,
SURFING
}
}

View File

@ -17,20 +17,26 @@ package app.fedilab.fedilabtube;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.InstanceData;
import app.fedilab.fedilabtube.databinding.ActivityManageInstancesBinding;
import app.fedilab.fedilabtube.drawer.AboutInstanceAdapter;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import app.fedilab.fedilabtube.sqlite.StoredInstanceDAO;
import app.fedilab.fedilabtube.viewmodel.InfoInstanceVM;
import static app.fedilab.fedilabtube.MainActivity.PICK_INSTANCE_SURF;
@ -40,6 +46,8 @@ import static app.fedilab.fedilabtube.MainActivity.showRadioButtonDialogFullInst
public class ManageInstancesActivity extends AppCompatActivity implements AboutInstanceAdapter.AllInstancesRemoved {
private ActivityManageInstancesBinding binding;
private List<InstanceData.AboutInstance> aboutInstances;
private AboutInstanceAdapter aboutInstanceAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -55,7 +63,13 @@ public class ManageInstancesActivity extends AppCompatActivity implements AboutI
binding.noAction.setVisibility(View.GONE);
binding.lvInstances.setVisibility(View.GONE);
binding.actionButton.setOnClickListener(v -> showRadioButtonDialogFullInstances(ManageInstancesActivity.this, true));
aboutInstances = new ArrayList<>();
aboutInstanceAdapter = new AboutInstanceAdapter(this.aboutInstances);
aboutInstanceAdapter.allInstancesRemoved = this;
binding.lvInstances.setAdapter(aboutInstanceAdapter);
LinearLayoutManager layoutManager
= new LinearLayoutManager(ManageInstancesActivity.this);
binding.lvInstances.setLayoutManager(layoutManager);
InfoInstanceVM viewModelInfoInstance = new ViewModelProvider(ManageInstancesActivity.this).get(InfoInstanceVM.class);
viewModelInfoInstance.getInstances().observe(ManageInstancesActivity.this, this::manageVIewInfoInstance);
}
@ -69,6 +83,8 @@ public class ManageInstancesActivity extends AppCompatActivity implements AboutI
}
binding.noAction.setVisibility(View.GONE);
binding.lvInstances.setVisibility(View.VISIBLE);
this.aboutInstances.addAll(aboutInstances);
aboutInstanceAdapter.notifyItemRangeInserted(0, aboutInstances.size());
}
@ -77,6 +93,7 @@ public class ManageInstancesActivity extends AppCompatActivity implements AboutI
super.onBackPressed();
overridePendingTransition(R.anim.slide_out_up, R.anim.slide_in_up_down);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
@ -94,7 +111,13 @@ public class ManageInstancesActivity extends AppCompatActivity implements AboutI
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_INSTANCE_SURF && resultCode == Activity.RESULT_OK) {
if (data != null && data.getData() != null) {
Helper.logoutNoRemoval(ManageInstancesActivity.this);
new Thread(() -> {
String newInstance = data.getData().toString().trim().toLowerCase();
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(ManageInstancesActivity.this, newInstance, null).getAboutInstance();
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StoredInstanceDAO(ManageInstancesActivity.this, db).insertInstance(aboutInstance, newInstance);
runOnUiThread(() -> new Handler().post(() -> Helper.logoutNoRemoval(ManageInstancesActivity.this)));
}).start();
}
}
}

View File

@ -13,6 +13,7 @@ package app.fedilab.fedilabtube;
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.Manifest;
import android.app.Activity;
import android.content.Context;
@ -59,8 +60,8 @@ import static app.fedilab.fedilabtube.worker.WorkHelper.NOTIFICATION_WORKER;
public class MyAccountActivity extends AppCompatActivity {
ActivityMyAccountSettingsBinding binding;
private static final int PICK_IMAGE = 466;
ActivityMyAccountSettingsBinding binding;
private Uri inputData;
private String fileName;
private NotificationSettings notificationSettings;

View File

@ -152,6 +152,7 @@ import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved, Player.EventListener, VideoListener, TorrentListener {
public static String video_id;
public static List<String> playedVideos = new ArrayList<>();
private String peertubeInstance, videoUuid;
private FullScreenMediaController.fullscreen fullscreen;
private ImageView fullScreenIcon;
@ -175,10 +176,19 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private List<Comment> commentsThread;
private BroadcastReceiver mPowerKeyReceiver = null;
private boolean isPlayInMinimized;
public static List<String> playedVideos = new ArrayList<>();
private VideoData.Video nextVideo;
private TorrentStream torrentStream;
private String show_more_content;
private videoOrientation videoOrientationType;
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null) {
activity.getWindow().getDecorView();
InputMethodManager imm = (InputMethodManager) activity.getSystemService(INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
}
}
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
@ -213,22 +223,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
@Override
public void onStreamStopped() {}
enum videoOrientation {
LANDSCAPE,
PORTRAIT
}
private videoOrientation videoOrientationType;
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null) {
activity.getWindow().getDecorView();
InputMethodManager imm = (InputMethodManager) activity.getSystemService(INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
}
public void onStreamStopped() {
}
@Override
@ -422,7 +417,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.postCommentButton.setOnClickListener(v -> openPostComment(null, 0));
}
private void manageVIewVideos(APIResponse apiResponse) {
if (apiResponse == null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
playVideo();
@ -459,7 +453,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
public void manageVIewCommentReply(Comment comment, APIResponse apiResponse) {
if (apiResponse == null || apiResponse.getError() != null || apiResponse.getCommentThreadData() == null) {
if (apiResponse == null || apiResponse.getError() == null)
@ -618,7 +611,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
@ -676,7 +668,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
this.fullscreen = fullscreen;
}
public void manageCaptions(APIResponse apiResponse) {
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getCaptions() == null || apiResponse.getCaptions().size() == 0) {
return;
@ -684,7 +675,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
captions = apiResponse.getCaptions();
}
public void manageNextVideos(APIResponse apiResponse) {
if (apiResponse == null || apiResponse.getError() != null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
return;
@ -713,7 +703,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
player.addMediaItem(mediaItem);
}
@SuppressLint("ClickableViewAccessibility")
public void manageVIewVideo(APIResponse apiResponse) {
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
@ -1072,7 +1061,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
change();
}
@Override
public void onDestroy() {
super.onDestroy();
@ -1153,7 +1141,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onUserLeaveHint() {
@ -1175,7 +1162,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@Override
public void onBackPressed() {
if (binding.postComment.getVisibility() == View.VISIBLE) {
@ -1191,7 +1177,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
if (isInPictureInPictureMode) {
@ -1205,7 +1190,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
public void displayResolution() {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(PeertubeActivity.this);
builderSingle.setTitle(R.string.pickup_resolution);
@ -1243,7 +1227,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
builderSingle.show();
}
private void initFullscreenDialog() {
fullScreenDialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen) {
@ -1272,10 +1255,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
fullScreenDialog.show();
}
public void openCommentThread(Comment comment) {
@ -1359,7 +1338,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.replyThread.startAnimation(animate);
}
public void openPostComment(Comment comment, int position) {
if (comment != null) {
binding.replyContent.setVisibility(View.VISIBLE);
@ -1610,7 +1588,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
public void addElement(String playlistId, String videoId, APIResponse apiResponse) {
if (apiResponse != null && apiResponse.getActionReturn() != null) {
@ -1626,8 +1603,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
private void updateHistory(long position) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean storeInHistory = sharedpreferences.getBoolean(getString(R.string.set_store_in_history), true);
@ -1648,8 +1623,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.noActionText.setVisibility(View.VISIBLE);
}
private void playNextVideo() {
if (nextVideo != null) {
Intent intent = new Intent(PeertubeActivity.this, PeertubeActivity.class);
@ -1664,8 +1637,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@Override
public void onMediaItemTransition(MediaItem mediaItem, int reason) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
@ -1676,10 +1647,14 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@Override
public void onPlayerError(ExoPlaybackException error) {
}
enum videoOrientation {
LANDSCAPE,
PORTRAIT
}
}

View File

@ -61,7 +61,6 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (BuildConfig.full_instances) {
binding.loginInstanceContainer.setVisibility(View.VISIBLE);
binding.titleLoginInstance.setVisibility(View.VISIBLE);

View File

@ -66,8 +66,8 @@ import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.MY_CHA
public class PeertubeUploadActivity extends AppCompatActivity {
private final int PICK_IVDEO = 52378;
public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724;
private final int PICK_IVDEO = 52378;
private Button set_upload_file, set_upload_submit;
private Spinner set_upload_privacy, set_upload_channel;
private TextView set_upload_file_name;

View File

@ -68,7 +68,7 @@ public interface PeertubeService {
//Instance info
@GET("config/about")
Call<InstanceData.AboutInstance> configAbout();
Call<InstanceData.InstanceInfo> configAbout();
@GET("{nodeInfoPath}")
Call<WellKnownNodeinfo.NodeInfo> getNodeinfo(@Path(value = "nodeInfoPath", encoded = true) String nodeInfoPath);

View File

@ -599,16 +599,17 @@ public class RetrofitPeertubeAPI {
/**
* About the instance
*
* @return AboutInstance
*/
public InstanceData.AboutInstance getAboutInstance() {
PeertubeService peertubeService = init();
Call<InstanceData.AboutInstance> about = peertubeService.configAbout();
Call<InstanceData.InstanceInfo> about = peertubeService.configAbout();
try {
Response<InstanceData.AboutInstance> response = about.execute();
Response<InstanceData.InstanceInfo> response = about.execute();
if (response.isSuccessful() && response.body() != null) {
return response.body();
return response.body().getInstance();
}
} catch (IOException e) {
e.printStackTrace();
@ -1058,7 +1059,6 @@ public class RetrofitPeertubeAPI {
}
/**
* Get video description
*
@ -1073,7 +1073,8 @@ public class RetrofitPeertubeAPI {
if (response.isSuccessful() && response.body() != null) {
return response.body();
}
} catch (IOException ignored) {}
} catch (IOException ignored) {
}
return null;
}

View File

@ -242,29 +242,21 @@ public class InstanceData {
}
}
public static class AboutInstance implements Parcelable, Serializable {
public static class InstanceInfo {
@SerializedName("instance")
private AboutInstance instance;
@SerializedName("name")
private String name;
@SerializedName("shortDescription")
private String shortDescription;
@SerializedName("description")
private String description;
@SerializedName("terms")
private String terms;
private String host;
public AboutInstance(){}
protected AboutInstance(Parcel in) {
name = in.readString();
shortDescription = in.readString();
description = in.readString();
terms = in.readString();
host = in.readString();
public AboutInstance getInstance() {
return instance;
}
public void setInstance(AboutInstance instance) {
this.instance = instance;
}
}
public static class AboutInstance implements Parcelable, Serializable {
public static final Creator<AboutInstance> CREATOR = new Creator<AboutInstance>() {
@Override
public AboutInstance createFromParcel(Parcel in) {
@ -276,6 +268,26 @@ public class InstanceData {
return new AboutInstance[size];
}
};
@SerializedName("name")
private String name;
@SerializedName("shortDescription")
private String shortDescription;
@SerializedName("description")
private String description;
@SerializedName("terms")
private String terms;
private String host;
public AboutInstance() {
}
protected AboutInstance(Parcel in) {
name = in.readString();
shortDescription = in.readString();
description = in.readString();
terms = in.readString();
host = in.readString();
}
public String getName() {
return name;

View File

@ -9,6 +9,17 @@ import com.google.gson.annotations.SerializedName;
@SuppressWarnings({"unused", "RedundantSuppression"})
public class File implements Parcelable {
public static final Parcelable.Creator<File> CREATOR = new Parcelable.Creator<File>() {
@Override
public File createFromParcel(Parcel source) {
return new File(source);
}
@Override
public File[] newArray(int size) {
return new File[size];
}
};
@SerializedName("fileDownloadUrl")
private String fileDownloadUrl;
@SerializedName("fileUrl")
@ -28,6 +39,21 @@ public class File implements Parcelable {
@SerializedName("torrentUrl")
private String torrentUrl;
public File() {
}
protected File(Parcel in) {
this.fileDownloadUrl = in.readString();
this.fileUrl = in.readString();
this.fps = in.readInt();
this.magnetUri = in.readString();
this.metadataUrl = in.readString();
this.resolutions = in.readParcelable(Item.class.getClassLoader());
this.size = in.readLong();
this.torrentDownloadUrl = in.readString();
this.torrentUrl = in.readString();
}
public String getFileDownloadUrl() {
return fileDownloadUrl;
}
@ -100,7 +126,6 @@ public class File implements Parcelable {
this.torrentUrl = torrentUrl;
}
@Override
public int describeContents() {
return 0;
@ -118,31 +143,4 @@ public class File implements Parcelable {
dest.writeString(this.torrentDownloadUrl);
dest.writeString(this.torrentUrl);
}
public File() {
}
protected File(Parcel in) {
this.fileDownloadUrl = in.readString();
this.fileUrl = in.readString();
this.fps = in.readInt();
this.magnetUri = in.readString();
this.metadataUrl = in.readString();
this.resolutions = in.readParcelable(Item.class.getClassLoader());
this.size = in.readLong();
this.torrentDownloadUrl = in.readString();
this.torrentUrl = in.readString();
}
public static final Parcelable.Creator<File> CREATOR = new Parcelable.Creator<File>() {
@Override
public File createFromParcel(Parcel source) {
return new File(source);
}
@Override
public File[] newArray(int size) {
return new File[size];
}
};
}

View File

@ -37,26 +37,14 @@ public class UserSettings {
return videosHistoryEnabled;
}
public void setVideosHistoryEnabled(Boolean videosHistoryEnabled) {
this.videosHistoryEnabled = videosHistoryEnabled;
}
public Boolean isAutoPlayVideo() {
return autoPlayVideo;
}
public void setAutoPlayVideo(Boolean autoPlayVideo) {
this.autoPlayVideo = autoPlayVideo;
}
public Boolean isWebTorrentEnabled() {
return webTorrentEnabled;
}
public void setWebTorrentEnabled(Boolean webTorrentEnabled) {
this.webTorrentEnabled = webTorrentEnabled;
}
public List<String> getVideoLanguages() {
return videoLanguages;
}
@ -93,26 +81,38 @@ public class UserSettings {
return videosHistoryEnabled;
}
public void setVideosHistoryEnabled(Boolean videosHistoryEnabled) {
this.videosHistoryEnabled = videosHistoryEnabled;
}
public Boolean getAutoPlayVideo() {
return autoPlayVideo;
}
public void setAutoPlayVideo(Boolean autoPlayVideo) {
this.autoPlayVideo = autoPlayVideo;
}
public Boolean getWebTorrentEnabled() {
return webTorrentEnabled;
}
public void setWebTorrentEnabled(Boolean webTorrentEnabled) {
this.webTorrentEnabled = webTorrentEnabled;
}
public Boolean isAutoPlayNextVideo() {
return autoPlayNextVideo;
}
public Boolean getAutoPlayNextVideo() {
return autoPlayNextVideo;
}
public void setAutoPlayNextVideo(Boolean autoPlayNextVideo) {
this.autoPlayNextVideo = autoPlayNextVideo;
}
public Boolean getAutoPlayNextVideo() {
return autoPlayNextVideo;
}
public String getFileName() {
return fileName;
}

View File

@ -22,10 +22,14 @@ 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;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.PopupMenu;
@ -35,24 +39,23 @@ import java.util.List;
import app.fedilab.fedilabtube.MainActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.InstanceData;
import app.fedilab.fedilabtube.databinding.DrawerAboutInstanceBinding;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import app.fedilab.fedilabtube.sqlite.StoredInstanceDAO;
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final List<InstanceData.AboutInstance> aboutInstances;
private final AboutInstanceAdapter aboutInstanceAdapter;
public AllInstancesRemoved allInstancesRemoved;
private Context context;
public AboutInstanceAdapter(List<InstanceData.AboutInstance> aboutInstances) {
aboutInstanceAdapter = this;
this.aboutInstances = aboutInstances;
}
@ -85,7 +88,17 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.View
final InstanceData.AboutInstance aboutInstance = aboutInstances.get(i);
holder.binding.aboutInstanceDescription.setText(aboutInstance.getShortDescription());
holder.binding.aboutInstanceHost.setText(aboutInstance.getHost());
SpannableString spannableString;
if (aboutInstance.getShortDescription() != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
spannableString = new SpannableString(Html.fromHtml(aboutInstance.getShortDescription(), FROM_HTML_MODE_LEGACY));
else
spannableString = new SpannableString(Html.fromHtml(aboutInstance.getShortDescription()));
holder.binding.aboutInstanceDescription.setText(spannableString, TextView.BufferType.SPANNABLE);
}
holder.binding.aboutInstanceName.setText(aboutInstance.getName());
holder.binding.playlistContainer.setOnClickListener(v -> {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -112,8 +125,10 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.View
new Thread(() -> {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StoredInstanceDAO(context, db).removeInstance(aboutInstance.getHost());
aboutInstances.remove(aboutInstance);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
notifyItemRemoved(i);
if (aboutInstances.size() == 0) {
allInstancesRemoved.onAllInstancesRemoved();
}
@ -128,6 +143,7 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.View
}
return true;
});
popup.show();
});
}

View File

@ -74,10 +74,10 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
private final List<Comment> comments;
private final CommentListAdapter commentListAdapter;
private final boolean isThread;
public AllCommentRemoved allCommentRemoved;
boolean isVideoOwner;
private Context context;
private final boolean isThread;
public CommentListAdapter(List<Comment> comments, boolean isVideoOwner, boolean isThread) {
this.comments = comments;

View File

@ -21,21 +21,6 @@ import androidx.preference.PreferenceScreen;
import androidx.preference.SeekBarPreference;
import androidx.preference.SwitchPreference;
/* 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 com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
@ -60,6 +45,21 @@ import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
import static app.fedilab.fedilabtube.MainActivity.userMe;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
@ -282,6 +282,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
my_account.setIcon(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
@ -307,7 +308,6 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
}
//****** Video mode *******
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
List<String> array = Arrays.asList(getResources().getStringArray(R.array.settings_video_mode));

View File

@ -13,6 +13,7 @@ package app.fedilab.fedilabtube.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 java.util.List;
import app.fedilab.fedilabtube.client.data.CommentData;

View File

@ -748,6 +748,7 @@ public class Helper {
/**
* Forward the intent (open an URL) to another app
*
* @param activity Activity
* @param i Intent
*/

View File

@ -14,6 +14,7 @@ package app.fedilab.fedilabtube.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 android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;

View File

@ -23,7 +23,6 @@ import androidx.appcompat.app.AlertDialog;
import java.util.List;
import app.fedilab.fedilabtube.LoginActivity;
import app.fedilab.fedilabtube.MainActivity;
import app.fedilab.fedilabtube.R;

View File

@ -266,6 +266,7 @@ public class AccountDAO {
return null;
}
}
/**
* Test if the current user is already stored in data base
*

View File

@ -59,6 +59,9 @@ public class Sqlite extends SQLiteOpenHelper {
static final String COL_UUID = "UUID";
static final String COL_CACHE = "CACHE";
static final String COL_DATE = "DATE";
static final String COL_USER_INSTANCE = "USER_INSTANCE";
static final String TABLE_BOOKMARKED_INSTANCES = "BOOKMARKED_INSTANCES";
static final String COL_ABOUT = "ABOUT";
private static final String CREATE_TABLE_USER_ACCOUNT = "CREATE TABLE " + TABLE_USER_ACCOUNT + " ("
+ COL_USER_ID + " TEXT, " + COL_USERNAME + " TEXT NOT NULL, " + COL_ACCT + " TEXT NOT NULL, "
+ COL_DISPLAYED_NAME + " TEXT NOT NULL, " + COL_LOCKED + " INTEGER NOT NULL, "
@ -82,10 +85,6 @@ public class Sqlite extends SQLiteOpenHelper {
+ COL_INSTANCE + " TEXT NOT NULL, "
+ COL_CACHE + " TEXT NOT NULL, "
+ COL_DATE + " TEXT NOT NULL)";
static final String COL_USER_INSTANCE = "USER_INSTANCE";
static final String TABLE_BOOKMARKED_INSTANCES = "BOOKMARKED_INSTANCES";
static final String COL_ABOUT = "ABOUT";
private final String CREATE_TABLE_STORED_INSTANCES = "CREATE TABLE "
+ TABLE_BOOKMARKED_INSTANCES + "("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "

View File

@ -42,36 +42,6 @@ public class StoredInstanceDAO {
this.db = db;
}
/**
* Insert instance info in database
*
* @param aboutInstance AboutInstance
* @param targetedInstance String
* @return boolean
*/
public boolean insertInstance(InstanceData.AboutInstance aboutInstance, String targetedInstance) {
ContentValues values = new ContentValues();
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(context);
values.put(Sqlite.COL_USER_ID, userId);
values.put(Sqlite.COL_USER_INSTANCE, instance);
values.put(Sqlite.COL_ABOUT, aboutInstanceToStringStorage(aboutInstance));
values.put(Sqlite.COL_INSTANCE, targetedInstance);
//Inserts account
try {
db.insertOrThrow(Sqlite.TABLE_BOOKMARKED_INSTANCES, null, values);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* Unserialized AboutInstance
*
@ -102,6 +72,35 @@ public class StoredInstanceDAO {
}
}
/**
* Insert instance info in database
*
* @param aboutInstance AboutInstance
* @param targetedInstance String
* @return boolean
*/
public boolean insertInstance(InstanceData.AboutInstance aboutInstance, String targetedInstance) {
ContentValues values = new ContentValues();
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(context);
values.put(Sqlite.COL_USER_ID, userId != null ? userId : "_ALL_");
values.put(Sqlite.COL_USER_INSTANCE, instance != null ? instance : "_ALL_");
values.put(Sqlite.COL_ABOUT, aboutInstanceToStringStorage(aboutInstance));
values.put(Sqlite.COL_INSTANCE, targetedInstance);
//Inserts account
try {
db.insertOrThrow(Sqlite.TABLE_BOOKMARKED_INSTANCES, null, values);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* Insert instance info in database
*
@ -129,7 +128,6 @@ public class StoredInstanceDAO {
}
/**
* Returns all Instance in db
*
@ -147,7 +145,6 @@ public class StoredInstanceDAO {
}
/***
* Method to hydrate an Account from database
* @param c Cursor
@ -184,7 +181,9 @@ public class StoredInstanceDAO {
List<InstanceData.AboutInstance> aboutInstances = new ArrayList<>();
while (c.moveToNext()) {
String aboutInstanceStr = c.getString(c.getColumnIndex(Sqlite.COL_ABOUT));
String instance = c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE));
InstanceData.AboutInstance aboutInstance = restoreAboutInstanceFromString(aboutInstanceStr);
aboutInstance.setHost(instance);
aboutInstances.add(aboutInstance);
}
//Close the cursor

View File

@ -37,17 +37,15 @@ import app.fedilab.fedilabtube.R;
public class MastalabWebChromeClient extends WebChromeClient implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
private FrameLayout videoViewContainer;
private CustomViewCallback videoViewCallback;
private ToggledFullscreenCallback toggledFullscreenCallback;
private final CustomWebview webView;
private final View activityNonVideoView;
private final ViewGroup activityVideoView;
private final ProgressBar pbar;
private boolean isVideoFullscreen;
private final Activity activity;
private FrameLayout videoViewContainer;
private CustomViewCallback videoViewCallback;
private ToggledFullscreenCallback toggledFullscreenCallback;
private boolean isVideoFullscreen;
public MastalabWebChromeClient(Activity activity, CustomWebview webView, FrameLayout activityNonVideoView, ViewGroup activityVideoView) {
@ -113,7 +111,6 @@ public class MastalabWebChromeClient extends WebChromeClient implements MediaPla
public void onShowCustomView(View view, CustomViewCallback callback) {
if (view instanceof FrameLayout) {
if (((AppCompatActivity) activity).getSupportActionBar() != null)
//noinspection ConstantConditions
((AppCompatActivity) activity).getSupportActionBar().hide();
// A video wants to be shown
FrameLayout frameLayout = (FrameLayout) view;
@ -178,7 +175,6 @@ public class MastalabWebChromeClient extends WebChromeClient implements MediaPla
@Override
public void onHideCustomView() {
if (((AppCompatActivity) activity).getSupportActionBar() != null)
//noinspection ConstantConditions
((AppCompatActivity) activity).getSupportActionBar().show();
// This method should be manually called on video end in all cases because it's not always called automatically.
// This method must be manually called on back key press (from this class' onBackPressed() method).

View File

@ -61,9 +61,9 @@ import static android.content.Context.NOTIFICATION_SERVICE;
public class NotificationsWorker extends Worker {
private final NotificationManager notificationManager;
public static String FETCH_NOTIFICATION_CHANNEL_ID = "fetch_notification_peertube";
public static int pendingNotificationID = 1;
private final NotificationManager notificationManager;
public NotificationsWorker(
@NonNull Context context,

View File

@ -13,7 +13,9 @@ package app.fedilab.fedilabtube.worker;
*
* 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 androidx.work.BackoffPolicy;
import androidx.work.Constraints;
import androidx.work.ExistingPeriodicWorkPolicy;

View File

@ -32,21 +32,34 @@
android:layout_marginBottom="5dp">
<TextView
android:id="@+id/about_instance_name"
android:id="@+id/about_instance_host"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textSize="18sp"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/instance_more"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_marginTop="5dp"
android:id="@+id/about_instance_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/instance_more"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/about_instance_host" />
<TextView
android:id="@+id/about_instance_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/instance_more"
app:layout_constraintTop_toBottomOf="@+id/about_instance_name" />