From 67417bd65c6730e9ad0c67a77381cfd68fc01697 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 26 Jun 2020 14:34:39 +0200 Subject: [PATCH] some changes --- app/build.gradle | 32 +- .../fedilab/fedilabtube/PeertubeActivity.java | 164 +--- .../PeertubeEditUploadActivity.java | 60 +- .../fedilabtube/PeertubeUploadActivity.java | 9 +- .../fedilab/fedilabtube/WebviewActivity.java | 171 ++++ .../asynctasks/PostActionAsyncTask.java | 7 + .../asynctasks/PostPeertubeAsyncTask.java | 44 + .../asynctasks/RetrieveFeedsAsyncTask.java | 13 +- .../fedilabtube/client/entities/Status.java | 892 +----------------- .../client/entities/StatusDrawerParams.java | 46 + .../{ui/video => drawer}/PeertubeAdapter.java | 9 +- .../fedilabtube/drawer/StatusListAdapter.java | 219 +++++ .../fragment/DisplayStatusFragment.java | 306 ++++++ .../helper/CacheDataSourceFactory.java | 56 ++ .../fedilabtube/helper/CustomQuoteSpan.java | 54 ++ .../fedilab/fedilabtube/helper/Helper.java | 113 ++- .../ui/dashboard/DashboardFragment.java | 35 - .../ui/dashboard/DashboardViewModel.java | 19 - .../notifications/NotificationsFragment.java | 35 - .../notifications/NotificationsViewModel.java | 19 - .../ui/video/VideoListFragment.java | 87 -- .../fedilabtube/ui/video/VideoListModel.java | 19 - .../webview/MastalabWebViewClient.java | 14 +- .../res/drawable/ic_baseline_bookmark_24.xml | 10 + .../ic_baseline_bookmark_border_24.xml | 10 + .../res/drawable/ic_baseline_check_24.xml | 10 + .../res/drawable/ic_baseline_close_24.xml | 10 + .../drawable/ic_baseline_fullscreen_24.xml | 10 + .../ic_baseline_fullscreen_exit_24.xml | 10 + .../ic_baseline_thumb_down_alt_24.xml | 10 + .../drawable/ic_baseline_thumb_up_alt_24.xml | 10 + app/src/main/res/layout/activity_peertube.xml | 302 ++++++ .../res/layout/activity_peertube_edit.xml | 258 +++++ .../res/layout/activity_peertube_upload.xml | 105 +++ app/src/main/res/layout/activity_webview.xml | 39 + .../main/res/layout/drawer_status_compact.xml | 107 +++ .../res/layout/exo_playback_control_view.xml | 126 +++ app/src/main/res/layout/fragment_video.xml | 2 +- app/src/main/res/layout/simple_bar.xml | 39 + app/src/main/res/layout/webview_actionbar.xml | 26 + app/src/main/res/menu/main_showaccount.xml | 31 + app/src/main/res/menu/main_webview.xml | 9 + app/src/main/res/values/colors.xml | 4 + app/src/main/res/values/strings.xml | 46 +- 44 files changed, 2297 insertions(+), 1300 deletions(-) create mode 100644 app/src/main/java/app/fedilab/fedilabtube/WebviewActivity.java create mode 100644 app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostPeertubeAsyncTask.java create mode 100644 app/src/main/java/app/fedilab/fedilabtube/client/entities/StatusDrawerParams.java rename app/src/main/java/app/fedilab/fedilabtube/{ui/video => drawer}/PeertubeAdapter.java (95%) create mode 100644 app/src/main/java/app/fedilab/fedilabtube/drawer/StatusListAdapter.java create mode 100644 app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayStatusFragment.java create mode 100644 app/src/main/java/app/fedilab/fedilabtube/helper/CacheDataSourceFactory.java create mode 100644 app/src/main/java/app/fedilab/fedilabtube/helper/CustomQuoteSpan.java delete mode 100644 app/src/main/java/app/fedilab/fedilabtube/ui/dashboard/DashboardFragment.java delete mode 100644 app/src/main/java/app/fedilab/fedilabtube/ui/dashboard/DashboardViewModel.java delete mode 100644 app/src/main/java/app/fedilab/fedilabtube/ui/notifications/NotificationsFragment.java delete mode 100644 app/src/main/java/app/fedilab/fedilabtube/ui/notifications/NotificationsViewModel.java delete mode 100644 app/src/main/java/app/fedilab/fedilabtube/ui/video/VideoListFragment.java delete mode 100644 app/src/main/java/app/fedilab/fedilabtube/ui/video/VideoListModel.java create mode 100644 app/src/main/res/drawable/ic_baseline_bookmark_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_bookmark_border_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_check_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_close_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_fullscreen_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_fullscreen_exit_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_thumb_down_alt_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_thumb_up_alt_24.xml create mode 100644 app/src/main/res/layout/activity_peertube.xml create mode 100644 app/src/main/res/layout/activity_peertube_edit.xml create mode 100644 app/src/main/res/layout/activity_peertube_upload.xml create mode 100644 app/src/main/res/layout/activity_webview.xml create mode 100644 app/src/main/res/layout/drawer_status_compact.xml create mode 100644 app/src/main/res/layout/exo_playback_control_view.xml create mode 100644 app/src/main/res/layout/simple_bar.xml create mode 100644 app/src/main/res/layout/webview_actionbar.xml create mode 100644 app/src/main/res/menu/main_showaccount.xml create mode 100644 app/src/main/res/menu/main_webview.xml diff --git a/app/build.gradle b/app/build.gradle index 6c0a378..8b059e3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "app.fedilab.fedilabtube" - minSdkVersion 16 + minSdkVersion 19 targetSdkVersion 29 versionCode 1 versionName "1.0" @@ -20,6 +20,17 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +allprojects { + repositories { + maven { url "https://jitpack.io" } + maven { url "https://maven.google.com"} + } } dependencies { @@ -28,11 +39,22 @@ dependencies { implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.vectordrawable:vectordrawable:1.1.0' - implementation 'androidx.navigation:navigation-fragment:2.1.0' - implementation 'androidx.navigation:navigation-ui:2.1.0' - implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0' - testImplementation 'junit:junit:4.12' + implementation 'androidx.navigation:navigation-fragment:2.3.0' + implementation 'androidx.navigation:navigation-ui:2.3.0' + implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' + implementation 'org.jetbrains:annotations-java5:15.0' + implementation 'androidx.browser:browser:1.2.0' + testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation 'com.github.GrenderG:Toasty:1.4.2' + implementation 'com.google.android.exoplayer:exoplayer:2.10.6' + implementation "com.github.mabbas007:TagsEditText:1.0.5" + implementation "com.github.bumptech.glide:glide:4.11.0" + implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" + implementation 'org.apache.poi:poi:3.16' + implementation "net.gotev:uploadservice:3.5.2" + implementation "net.gotev:uploadservice-okhttp:3.5.2" + implementation "com.google.code.gson:gson:2.8.6" } \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 9866fd6..20f4715 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -6,13 +6,11 @@ import android.Manifest; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.database.sqlite.SQLiteDatabase; -import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; @@ -54,12 +52,10 @@ import com.google.android.exoplayer2.ui.PlayerControlView; import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; -import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory; import com.google.android.exoplayer2.util.Util; import org.jetbrains.annotations.NotNull; -import java.lang.ref.WeakReference; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -71,13 +67,20 @@ import javax.net.ssl.HttpsURLConnection; import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask; import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask; +import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask; +import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleAsyncTask; import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleCommentsAsyncTask; import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.TLSSocketFactory; import app.fedilab.fedilabtube.client.entities.Account; +import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.client.entities.Peertube; import app.fedilab.fedilabtube.client.entities.Playlist; +import app.fedilab.fedilabtube.client.entities.Status; +import app.fedilab.fedilabtube.client.entities.StatusDrawerParams; +import app.fedilab.fedilabtube.drawer.StatusListAdapter; +import app.fedilab.fedilabtube.helper.CacheDataSourceFactory; import app.fedilab.fedilabtube.helper.FullScreenMediaController; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface; @@ -91,7 +94,9 @@ import app.fedilab.fedilabtube.webview.MastalabWebChromeClient; import app.fedilab.fedilabtube.webview.MastalabWebViewClient; import es.dmoral.toasty.Toasty; +import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST; import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST_FOR_VIDEO; +import static app.fedilab.fedilabtube.helper.Helper.changeDrawableColor; public class PeertubeActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, OnPostActionInterface, OnPlaylistActionInterface { @@ -195,7 +200,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); assert inflater != null; View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(PeertubeActivity.this), false); - view.setBackground(new ColorDrawable(ContextCompat.getColor(PeertubeActivity.this, R.color.cyanea_primary))); actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); @@ -259,9 +263,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee initFullscreenButton(); } - if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) { - new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST, null, null, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } + new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST, null, null, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new RetrievePeertubeSingleAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -306,64 +308,16 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee public boolean onCreateOptionsMenu(@NotNull Menu menu) { getMenuInflater().inflate(R.menu.main_webview, menu); menu.findItem(R.id.action_go).setVisible(false); - menu.findItem(R.id.action_block).setVisible(false); - menu.findItem(R.id.action_comment).setVisible(true); - if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) { - MenuItem item = menu.findItem(R.id.action_comment); - if (item != null) - item.setVisible(false); - } return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; - case R.id.action_comment: - if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { - Toasty.info(PeertubeActivity.this, getString(R.string.retrieve_remote_status), Toast.LENGTH_LONG).show(); - new commentTask(new WeakReference<>(PeertubeActivity.this), peertube).execute(); - } else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) { - if (!peertube.isCommentsEnabled()) { - Toasty.info(PeertubeActivity.this, getString(R.string.comment_no_allowed_peertube), Toast.LENGTH_LONG).show(); - return true; - } - int style; - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); - if (theme == Helper.THEME_DARK) { - style = R.style.DialogDark; - } else if (theme == Helper.THEME_BLACK) { - style = R.style.DialogBlack; - } else { - style = R.style.Dialog; - } - AlertDialog.Builder builderInner; - builderInner = new AlertDialog.Builder(PeertubeActivity.this, style); - builderInner.setTitle(R.string.comment); - EditText input = new EditText(PeertubeActivity.this); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - input.setLayoutParams(lp); - builderInner.setView(input); - builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); - builderInner.setPositiveButton(R.string.validate, (dialog, which) -> { - String comment = input.getText().toString(); - if (comment.trim().length() > 0) { - new PostActionAsyncTask(PeertubeActivity.this, API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - dialog.dismiss(); - } - }); - builderInner.show(); - } - return true; - default: - return super.onOptionsItemSelected(item); + if (item.getItemId() == android.R.id.home) { + finish(); + return true; } + return super.onOptionsItemSelected(item); } public FullScreenMediaController.fullscreen getFullscreen() { @@ -524,9 +478,9 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee Drawable img; if (peertubes == null || peertubes.size() == 0) - img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border); + img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_bookmark_border_24); else - img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube); + img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_bookmark_24); peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, img, null, null); peertube_bookmark.setOnClickListener(v -> { @@ -539,9 +493,9 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee Toasty.success(PeertubeActivity.this, getString(R.string.bookmark_remove_peertube), Toast.LENGTH_SHORT).show(); } if (peertubes1 != null && peertubes1.size() > 0) //Was initially in cache - peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border), null, null); + peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_bookmark_border_24), null, null); else - peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube), null, null); + peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_bookmark_24), null, null); }); peertube_share.setOnClickListener(v -> { @@ -600,21 +554,13 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee } List statuses = apiResponse.getStatuses(); RecyclerView lv_comments = findViewById(R.id.peertube_comments); - if (statuses == null || statuses.size() == 0) { - if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) { - RelativeLayout no_action = findViewById(R.id.no_action); - no_action.setVisibility(View.VISIBLE); - lv_comments.setVisibility(View.GONE); - } - } else { + if (statuses != null && statuses.size() > 0) { lv_comments.setVisibility(View.VISIBLE); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - boolean isOnWifi = Helper.isOnWIFI(PeertubeActivity.this); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); StatusDrawerParams statusDrawerParams = new StatusDrawerParams(); statusDrawerParams.setType(RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE); statusDrawerParams.setTargetedId(userId); - statusDrawerParams.setOnWifi(isOnWifi); statusDrawerParams.setStatuses(statuses); StatusListAdapter statusListAdapter = new StatusListAdapter(statusDrawerParams); LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this); @@ -655,16 +601,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee public void displayResolution() { SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); - int style; - if (theme == Helper.THEME_DARK) { - style = R.style.DialogDark; - } else if (theme == Helper.THEME_BLACK) { - style = R.style.DialogBlack; - } else { - style = R.style.Dialog; - } - AlertDialog.Builder builderSingle = new AlertDialog.Builder(PeertubeActivity.this, style); + + AlertDialog.Builder builderSingle = new AlertDialog.Builder(PeertubeActivity.this); builderSingle.setTitle(R.string.pickup_resolution); final ArrayAdapter arrayAdapter = new ArrayAdapter<>(PeertubeActivity.this, android.R.layout.select_dialog_item); for (String resolution : peertube.getResolution()) @@ -709,9 +647,9 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee } @Override - public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) { + public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) { - if (peertube.isCommentsEnabled() && statusAction == API.StatusAction.PEERTUBECOMMENT) + if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT) new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -731,7 +669,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee ((ViewGroup) playerView.getParent()).removeView(playerView); fullScreenDialog.addContentView(playerView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_fullscreen_exit)); + fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_fullscreen_exit_24)); fullScreenMode = true; fullScreenDialog.show(); } @@ -742,7 +680,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee ((FrameLayout) findViewById(R.id.main_media_frame)).addView(playerView); fullScreenMode = false; fullScreenDialog.dismiss(); - fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_fullscreen)); + fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_fullscreen_24)); } private void initFullscreenButton() { @@ -767,12 +705,12 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee private void changeColor() { if (peertube.getMyRating() != null && peertube.getMyRating().equals("like")) { - changeDrawableColor(PeertubeActivity.this, R.drawable.ic_thumb_up_peertube, R.color.positive_thumbs); - Drawable thumbUp = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_thumb_up_peertube); + changeDrawableColor(PeertubeActivity.this, R.drawable.ic_baseline_thumb_up_alt_24, R.color.positive_thumbs); + Drawable thumbUp = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_thumb_up_alt_24); peertube_like_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbUp, null, null); } else if (peertube.getMyRating() != null && peertube.getMyRating().equals("dislike")) { - changeDrawableColor(PeertubeActivity.this, R.drawable.ic_thumb_down_peertube, R.color.negative_thumbs); - Drawable thumbDown = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_thumb_down_peertube); + changeDrawableColor(PeertubeActivity.this, R.drawable.ic_baseline_thumb_down_alt_24, R.color.negative_thumbs); + Drawable thumbDown = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_thumb_down_alt_24); peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null); } } @@ -787,48 +725,4 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee } } - private static class commentTask extends AsyncTask { - - private WeakReference contextReference; - private Peertube peertube; - - commentTask(WeakReference contextReference, Peertube peertube) { - this.peertube = peertube; - this.contextReference = contextReference; - } - - @Override - protected app.fedilab.android.client.Entities.Status doInBackground(Void... voids) { - - List remoteStatuses = null; - if (peertube != null) { - APIResponse search = new API(contextReference.get()).search("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid()); - if (search != null && search.getResults() != null) { - remoteStatuses = search.getResults().getStatuses(); - } - } - if (remoteStatuses != null && remoteStatuses.size() > 0) { - return remoteStatuses.get(0); - } else { - return null; - } - } - - @Override - protected void onPostExecute(app.fedilab.android.client.Entities.Status remoteStatuses) { - Intent intent = new Intent(contextReference.get(), TootActivity.class); - Bundle b = new Bundle(); - if (remoteStatuses == null) { - Toasty.error(contextReference.get(), contextReference.get().getString(R.string.toast_error), Toast.LENGTH_SHORT).show(); - return; - } - if (remoteStatuses.getReblog() != null) { - b.putParcelable("tootReply", remoteStatuses.getReblog()); - } else { - b.putParcelable("tootReply", remoteStatuses); - } - intent.putExtras(b); - contextReference.get().startActivity(intent); - } - } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java index b02600d..4cb3b51 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java @@ -4,7 +4,6 @@ package app.fedilab.fedilabtube; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.drawable.ColorDrawable; import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; @@ -23,7 +22,7 @@ import android.widget.Toast; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; +import androidx.appcompat.app.AppCompatActivity; import java.util.HashMap; import java.util.Iterator; @@ -31,24 +30,26 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import app.fedilab.android.asynctasks.PostActionAsyncTask; -import app.fedilab.android.asynctasks.PostPeertubeAsyncTask; -import app.fedilab.android.asynctasks.RetrievePeertubeChannelsAsyncTask; -import app.fedilab.android.asynctasks.RetrievePeertubeSingleAsyncTask; -import app.fedilab.android.client.API; -import app.fedilab.android.client.APIResponse; -import app.fedilab.android.client.Entities.Account; -import app.fedilab.android.client.Entities.Peertube; -import app.fedilab.android.helper.Helper; -import app.fedilab.android.interfaces.OnPostActionInterface; -import app.fedilab.android.interfaces.OnRetrievePeertubeInterface; +import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask; +import app.fedilab.fedilabtube.asynctasks.PostPeertubeAsyncTask; +import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask; +import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleAsyncTask; +import app.fedilab.fedilabtube.client.APIResponse; +import app.fedilab.fedilabtube.client.PeertubeAPI; +import app.fedilab.fedilabtube.client.entities.Account; +import app.fedilab.fedilabtube.client.entities.Error; +import app.fedilab.fedilabtube.client.entities.Peertube; +import app.fedilab.fedilabtube.helper.Helper; +import app.fedilab.fedilabtube.interfaces.OnPostActionInterface; +import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface; import es.dmoral.toasty.Toasty; import mabbas007.tagsedittext.TagsEditText; import static android.os.AsyncTask.THREAD_POOL_EXECUTOR; -import static app.fedilab.android.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation; +import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation; -public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrievePeertubeInterface, OnPostActionInterface { + +public class PeertubeEditUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, OnPostActionInterface { HashMap categoryToSend; @@ -70,17 +71,7 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie super.onCreate(savedInstanceState); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); - switch (theme) { - case Helper.THEME_LIGHT: - setTheme(R.style.AppTheme_Fedilab); - break; - case Helper.THEME_BLACK: - setTheme(R.style.AppThemeBlack); - break; - default: - setTheme(R.style.AppThemeDark); - } + Bundle b = getIntent().getExtras(); if (b != null) { @@ -96,7 +87,6 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); assert inflater != null; View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(PeertubeEditUploadActivity.this), false); - view.setBackground(new ColorDrawable(ContextCompat.getColor(PeertubeEditUploadActivity.this, R.color.cyanea_primary))); actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); @@ -123,21 +113,11 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie set_upload_delete.setOnClickListener(v -> { AlertDialog.Builder builderInner; - SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - int theme1 = sharedpreferences1.getInt(Helper.SET_THEME, Helper.THEME_DARK); - int style; - if (theme1 == Helper.THEME_DARK) { - style = R.style.DialogDark; - } else if (theme1 == Helper.THEME_BLACK) { - style = R.style.DialogBlack; - } else { - style = R.style.Dialog; - } - builderInner = new AlertDialog.Builder(PeertubeEditUploadActivity.this, style); + builderInner = new AlertDialog.Builder(PeertubeEditUploadActivity.this); builderInner.setMessage(getString(R.string.delete_video_confirmation)); builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { - new PostActionAsyncTask(PeertubeEditUploadActivity.this, API.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR); + new PostActionAsyncTask(PeertubeEditUploadActivity.this, PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR); dialog.dismiss(); }); builderInner.show(); @@ -579,7 +559,7 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie } @Override - public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) { + public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) { Intent intent = new Intent(PeertubeEditUploadActivity.this, MainActivity.class); intent.putExtra(Helper.INTENT_ACTION, Helper.RELOAD_MYVIDEOS); startActivity(intent); diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java index 16ea246..9e18f38 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java @@ -10,7 +10,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.database.Cursor; -import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -54,10 +53,14 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask; import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.entities.Account; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface; +import es.dmoral.toasty.Toasty; + +import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation; public class PeertubeUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, UploadStatusDelegate { @@ -80,7 +83,6 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); ActionBar actionBar = getSupportActionBar(); @@ -88,7 +90,6 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); assert inflater != null; View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(PeertubeUploadActivity.this), false); - view.setBackground(new ColorDrawable(ContextCompat.getColor(PeertubeUploadActivity.this, R.color.cyanea_primary))); actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); @@ -322,7 +323,7 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri uploadConfig.getCompleted().message = getString(R.string.upload_video_success); uploadConfig.getError().message = getString(R.string.toast_error); uploadConfig.getCancelled().message = getString(R.string.toast_cancelled); - uploadConfig.getCompleted().actions.add(new UploadNotificationAction(R.drawable.ic_check, getString(R.string.video_uploaded_action), clickIntent)); + uploadConfig.getCompleted().actions.add(new UploadNotificationAction(R.drawable.ic_baseline_check_24, getString(R.string.video_uploaded_action), clickIntent)); if (video_title != null && video_title.getText() != null && video_title.getText().toString().trim().length() > 0) { filename = video_title.getText().toString().trim(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/WebviewActivity.java b/app/src/main/java/app/fedilab/fedilabtube/WebviewActivity.java new file mode 100644 index 0000000..7f9150b --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/WebviewActivity.java @@ -0,0 +1,171 @@ + +package app.fedilab.fedilabtube; + + +import android.Manifest; +import android.annotation.SuppressLint; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.FrameLayout; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; + +import org.jetbrains.annotations.NotNull; + +import app.fedilab.fedilabtube.helper.Helper; +import app.fedilab.fedilabtube.webview.CustomWebview; +import app.fedilab.fedilabtube.webview.MastalabWebChromeClient; +import app.fedilab.fedilabtube.webview.MastalabWebViewClient; +import es.dmoral.toasty.Toasty; + + +public class WebviewActivity extends AppCompatActivity { + + private String url; + private boolean peertubeLink; + private CustomWebview webView; + + + @SuppressLint("SetJavaScriptEnabled") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + + setContentView(R.layout.activity_webview); + Bundle b = getIntent().getExtras(); + if (b != null) { + url = b.getString("url", null); + peertubeLink = b.getBoolean("peertubeLink", false); + } + if (url == null) + finish(); + if (getSupportActionBar() != null) + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + webView = Helper.initializeWebview(WebviewActivity.this, R.id.webview, null); + setTitle(""); + FrameLayout webview_container = findViewById(R.id.webview_container); + final ViewGroup videoLayout = findViewById(R.id.videoLayout); // Your own view, read class comments + webView.getSettings().setJavaScriptEnabled(true); + + + MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(WebviewActivity.this, webView, webview_container, videoLayout); + mastalabWebChromeClient.setOnToggledFullscreen(fullscreen -> { + + if (fullscreen) { + videoLayout.setVisibility(View.VISIBLE); + WindowManager.LayoutParams attrs = getWindow().getAttributes(); + attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; + attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; + getWindow().setAttributes(attrs); + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); + } else { + WindowManager.LayoutParams attrs = getWindow().getAttributes(); + attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; + attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; + getWindow().setAttributes(attrs); + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); + videoLayout.setVisibility(View.GONE); + } + }); + webView.setWebChromeClient(mastalabWebChromeClient); + MastalabWebViewClient mastalabWebViewClient = new MastalabWebViewClient(WebviewActivity.this); + webView.setWebViewClient(mastalabWebViewClient); + webView.setDownloadListener((url, userAgent, contentDisposition, mimetype, contentLength) -> { + + if (Build.VERSION.SDK_INT >= 23) { + if (ContextCompat.checkSelfPermission(WebviewActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(WebviewActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(WebviewActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE); + } else { + Helper.manageDownloads(WebviewActivity.this, url); + } + } else { + Helper.manageDownloads(WebviewActivity.this, url); + } + }); + if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")) + url = "http://" + url; + webView.loadUrl(url); + } + + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + return super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onCreateOptionsMenu(@NotNull Menu menu) { + getMenuInflater().inflate(R.menu.main_webview, menu); + if (peertubeLink) { + menu.findItem(R.id.action_go).setVisible(false); + } + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + case R.id.action_go: + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + try { + startActivity(browserIntent); + } catch (Exception e) { + Toasty.error(WebviewActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + } + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + public void setUrl(String newUrl) { + this.url = newUrl; + } + + @Override + public void onPause() { + super.onPause(); + if (webView != null) + webView.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + if (webView != null) + webView.onResume(); + } + + @Override + public void onBackPressed() { + if (webView.canGoBack()) { + webView.goBack(); + } else { + super.onBackPressed(); + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (webView != null) + webView.destroy(); + } + +} diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java index c963288..ae295c3 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java +++ b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java @@ -32,6 +32,13 @@ public class PostActionAsyncTask extends AsyncTask { this.account = account; } + public PostActionAsyncTask(Context context, PeertubeAPI.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface) { + this.contextReference = new WeakReference<>(context); + this.listener = onPostActionInterface; + this.apiAction = apiAction; + this.targetedId = targetedId; + } + public PostActionAsyncTask(Context context, String targetedId, String comment, String targetedComment, OnPostActionInterface onPostActionInterface) { this.contextReference = new WeakReference<>(context); this.listener = onPostActionInterface; diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostPeertubeAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostPeertubeAsyncTask.java new file mode 100644 index 0000000..3333650 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostPeertubeAsyncTask.java @@ -0,0 +1,44 @@ + +package app.fedilab.fedilabtube.asynctasks; + +import android.content.Context; +import android.os.AsyncTask; + +import java.lang.ref.WeakReference; + +import app.fedilab.fedilabtube.client.APIResponse; +import app.fedilab.fedilabtube.client.PeertubeAPI; +import app.fedilab.fedilabtube.client.entities.Peertube; +import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface; + + +public class PostPeertubeAsyncTask extends AsyncTask { + + + private APIResponse apiResponse; + private OnRetrievePeertubeInterface listener; + private WeakReference contextReference; + private Peertube peertube; + + + public PostPeertubeAsyncTask(Context context, Peertube peertube, OnRetrievePeertubeInterface onRetrievePeertubeInterface) { + this.contextReference = new WeakReference<>(context); + this.listener = onRetrievePeertubeInterface; + this.peertube = peertube; + } + + + @Override + protected Void doInBackground(Void... params) { + PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get()); + apiResponse = peertubeAPI.updateVideo(peertube); + if (apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0) + apiResponse.getPeertubes().get(0).setUpdate(true); + return null; + } + + @Override + protected void onPostExecute(Void result) { + listener.onRetrievePeertube(apiResponse); + } +} diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrieveFeedsAsyncTask.java index 964d2ba..00ad11b 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrieveFeedsAsyncTask.java @@ -6,13 +6,13 @@ import android.database.sqlite.SQLiteDatabase; import android.os.AsyncTask; import java.lang.ref.WeakReference; -import java.util.ArrayList; import java.util.List; import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.entities.Peertube; import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface; +import app.fedilab.fedilabtube.sqlite.PeertubeFavoritesDAO; import app.fedilab.fedilabtube.sqlite.Sqlite; @@ -36,6 +36,13 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { private String social; + public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) { + this.contextReference = new WeakReference<>(context); + this.action = action; + this.max_id = max_id; + this.listener = onRetrieveFeedsInterface; + this.search = null; + } public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, String search, OnRetrieveFeedsInterface onRetrieveFeedsInterface) { this.contextReference = new WeakReference<>(context); @@ -49,7 +56,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { @Override protected Void doInBackground(Void... params) { PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get()); - SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + if (action == null) return null; switch (action) { @@ -74,7 +81,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { case CACHE_BOOKMARKS_PEERTUBE: apiResponse = new APIResponse(); - db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); List peertubes = new PeertubeFavoritesDAO(contextReference.get(), db).getAllPeertube(); apiResponse.setPeertubes(peertubes); break; diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/entities/Status.java b/app/src/main/java/app/fedilab/fedilabtube/client/entities/Status.java index de050ab..5351cf4 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/entities/Status.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/entities/Status.java @@ -1,18 +1,9 @@ package app.fedilab.fedilabtube.client.entities; -import android.app.Activity; -import android.content.ClipData; -import android.content.ClipboardManager; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.Bitmap; -import android.graphics.drawable.Drawable; -import android.net.Uri; import android.os.Build; -import android.os.Bundle; -import android.os.Handler; import android.os.Parcel; import android.os.Parcelable; import android.preference.PreferenceManager; @@ -24,27 +15,17 @@ import android.text.Spanned; import android.text.TextPaint; import android.text.TextUtils; import android.text.style.ClickableSpan; -import android.text.style.ImageSpan; import android.text.style.QuoteSpan; import android.text.style.URLSpan; -import android.util.Patterns; import android.view.View; -import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.PopupMenu; import androidx.core.content.ContextCompat; -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.target.CustomTarget; -import com.bumptech.glide.request.transition.Transition; import java.lang.ref.WeakReference; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -55,18 +36,15 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; -import app.fedilab.fedilabtube.PeertubeActivity; import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask; +import app.fedilab.fedilabtube.helper.CustomQuoteSpan; import app.fedilab.fedilabtube.helper.Helper; -import es.dmoral.toasty.Toasty; - -import static android.content.Context.MODE_PRIVATE; -@SuppressWarnings({"WeakerAccess", "unused"}) +@SuppressWarnings("unused") public class Status implements Parcelable { public static final Creator CREATOR = new Creator() { @@ -86,65 +64,23 @@ public class Status implements Parcelable { private Account account; private String in_reply_to_id; private String in_reply_to_account_id; - private Status reblog; private Date created_at; - private int reblogs_count; private int favourites_count; private int replies_count; - private boolean reblogged; private boolean favourited; private boolean muted; private boolean pinned; private boolean sensitive; private boolean bookmarked; private String visibility; - private boolean attachmentShown = false; - private boolean spoilerShown = false; private List mentions; private List tags; private String language; - private boolean isTranslated = false; - private transient boolean isEmojiFound = false; - private transient boolean isPollEmojiFound = false; - private transient boolean isImageFound = false; - private transient boolean isEmojiTranslateFound = false; - private boolean isTranslationShown = false; - private boolean isNew = false; - private boolean isVisible = true; - private boolean fetchMore = false; - private String content, contentCW, contentTranslated; - private SpannableString contentSpan, contentSpanCW, contentSpanTranslated; + private String content; + private SpannableString contentSpan; private transient RetrieveFeedsAsyncTask.Type type; - private int itemViewType; private String conversationId; - private boolean isExpanded = false; - private int numberLines = -1; - private boolean showSpoiler = false; - private String quickReplyContent; - private String quickReplyPrivacy; - private boolean showBottomLine = false; - private boolean showTopLine = false; - private List conversationProfilePicture; - private String webviewURL = null; - - private boolean isBoostAnimated = false, isFavAnimated = false; - private String scheduled_at; private String contentType; - private boolean isNotice = false; - - private int media_height; - private boolean cached = false; - private boolean autoHiddenCW = false; - private boolean customFeaturesDisplayed = false; - private boolean shortReply = false; - - private int warningFetched = -1; - private List imageURL; - private int viewType; - private boolean isFocused = false; - private transient long db_id; - private transient boolean commentsFetched = false; - private transient List comments = new ArrayList<>(); public Status() { } @@ -156,68 +92,30 @@ public class Status implements Parcelable { this.account = in.readParcelable(Account.class.getClassLoader()); this.in_reply_to_id = in.readString(); this.in_reply_to_account_id = in.readString(); - this.reblog = in.readParcelable(Status.class.getClassLoader()); long tmpCreated_at = in.readLong(); this.created_at = tmpCreated_at == -1 ? null : new Date(tmpCreated_at); - this.reblogs_count = in.readInt(); this.favourites_count = in.readInt(); this.replies_count = in.readInt(); - this.reblogged = in.readByte() != 0; this.favourited = in.readByte() != 0; this.muted = in.readByte() != 0; this.pinned = in.readByte() != 0; this.sensitive = in.readByte() != 0; this.bookmarked = in.readByte() != 0; this.visibility = in.readString(); - this.attachmentShown = in.readByte() != 0; - this.spoilerShown = in.readByte() != 0; this.mentions = in.createTypedArrayList(Mention.CREATOR); this.tags = in.createTypedArrayList(Tag.CREATOR); this.language = in.readString(); - this.isTranslated = in.readByte() != 0; - this.isTranslationShown = in.readByte() != 0; - this.isNew = in.readByte() != 0; - this.isVisible = in.readByte() != 0; - this.fetchMore = in.readByte() != 0; this.content = in.readString(); - this.contentCW = in.readString(); - this.contentTranslated = in.readString(); this.contentSpan = (SpannableString) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - this.contentSpanCW = (SpannableString) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - this.contentSpanTranslated = (SpannableString) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); int tmpType = in.readInt(); this.type = tmpType == -1 ? null : RetrieveFeedsAsyncTask.Type.values()[tmpType]; - this.itemViewType = in.readInt(); this.conversationId = in.readString(); - this.isExpanded = in.readByte() != 0; - this.numberLines = in.readInt(); - this.conversationProfilePicture = in.createStringArrayList(); - this.webviewURL = in.readString(); - this.isBoostAnimated = in.readByte() != 0; - this.isFavAnimated = in.readByte() != 0; - this.scheduled_at = in.readString(); this.contentType = in.readString(); - this.showSpoiler = in.readByte() != 0; - this.isNotice = in.readByte() != 0; - this.media_height = in.readInt(); - this.cached = in.readByte() != 0; - this.autoHiddenCW = in.readByte() != 0; - this.customFeaturesDisplayed = in.readByte() != 0; - this.shortReply = in.readByte() != 0; - this.warningFetched = in.readInt(); - this.imageURL = in.createStringArrayList(); - this.viewType = in.readInt(); - this.isFocused = in.readByte() != 0; - this.quickReplyContent = in.readString(); - this.quickReplyPrivacy = in.readString(); - this.showBottomLine = in.readByte() != 0; - this.showTopLine = in.readByte() != 0; } public static void fillSpan(WeakReference contextWeakReference, Status status) { Status.transform(contextWeakReference, status); - Status.makeImage(contextWeakReference, status); } @@ -226,12 +124,10 @@ public class Status implements Parcelable { if (status == null) return; SpannableString spannableStringContent, spannableStringCW; - if ((status.getReblog() != null && status.getReblog().getContent() == null) || (status.getReblog() == null && status.getContent() == null)) + if (status.getContent() == null) return; - String content = status.getReblog() != null ? status.getReblog().getContent() : status.getContent(); - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - + String content = status.getContent(); Pattern aLink = Pattern.compile("]*(((?!"); Matcher matcherALink = aLink.matcher(content); @@ -263,28 +159,11 @@ public class Status implements Parcelable { } } - - - - int i = 1; - content = content.replaceAll("(<\\s?p\\s?>)>(((?!(

)|(<\\s?p\\s?>|<\\s?br\\s?/?>|<\\s?/p\\s?>$)", "
$2

"); content = content.replaceAll("^<\\s?p\\s?>(.*)<\\s?/p\\s?>$", "$1"); spannableStringContent = new SpannableString(content); - String spoilerText = ""; - if (status.getReblog() != null && status.getReblog().getSpoiler_text() != null) - spoilerText = status.getReblog().getSpoiler_text(); - else if (status.getSpoiler_text() != null) - spoilerText = status.getSpoiler_text(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - spannableStringCW = new SpannableString(Html.fromHtml(spoilerText, Html.FROM_HTML_MODE_LEGACY)); - else - spannableStringCW = new SpannableString(Html.fromHtml(spoilerText)); if (spannableStringContent.length() > 0) status.setContentSpan(treatment(context, spannableStringContent, status)); - if (spannableStringCW.length() > 0) - status.setContentSpanCW(spannableStringCW); - } private static SpannableString treatment(final Context context, SpannableString spannableString, Status status) { @@ -292,7 +171,7 @@ public class Status implements Parcelable { URLSpan[] urls = spannableString.getSpans(0, spannableString.length(), URLSpan.class); for (URLSpan span : urls) spannableString.removeSpan(span); - List mentions = status.getReblog() != null ? status.getReblog().getMentions() : status.getMentions(); + List mentions = status.getMentions(); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); @@ -420,14 +299,12 @@ public class Status implements Parcelable { spannableStringT.setSpan(new ClickableSpan() { @Override public void onClick(@NonNull View textView) { - if (account.getId() == null) { - CrossActions.doCrossProfile(context, account); - } else { - Intent intent = new Intent(context, ShowAccountActivity.class); + if (account.getId() != null) { + /* Intent intent = new Intent(context, ShowAccountActivity.class); Bundle b = new Bundle(); b.putString("accountId", account.getId()); intent.putExtras(b); - context.startActivity(intent); + context.startActivity(intent);*/ } } @@ -464,141 +341,6 @@ public class Status implements Parcelable { spannableStringT = SpannableStringBuilder.valueOf(ssb); endPosition = startPosition + key.length(); } - if (endPosition <= spannableStringT.toString().length() && endPosition >= startPosition) { - spannableStringT.setSpan(new LongClickableSpan() { - @Override - public void onClick(@NonNull View textView) { - String finalUrl = url; - Pattern link = Pattern.compile("https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[\\w._-]*[0-9]*)(/[0-9]+)?$"); - Matcher matcherLink = link.matcher(url); - link = Pattern.compile("(https?://[\\da-z.-]+\\.[a-z.]{2,10})/videos/watch/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$"); - matcherLink = link.matcher(url); - if (matcherLink.find()) { //Peertubee video - Intent intent = new Intent(context, PeertubeActivity.class); - Bundle b = new Bundle(); - String url = matcherLink.group(1) + "/videos/watch/" + matcherLink.group(2); - b.putString("peertubeLinkToFetch", url); - b.putString("peertube_instance", Objects.requireNonNull(matcherLink.group(1)).replace("https://", "").replace("http://", "")); - b.putString("video_id", matcherLink.group(2)); - intent.putExtras(b); - context.startActivity(intent); - } else { - if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")) - finalUrl = "http://" + url; - Helper.openBrowser(context, finalUrl); - } - } - - @Override - public void onLongClick(@NonNull View textView) { - PopupMenu popup = new PopupMenu(context, textView); - popup.getMenuInflater() - .inflate(R.menu.links_popup, popup.getMenu()); - int style; - if (theme == Helper.THEME_DARK) { - style = R.style.DialogDark; - } else if (theme == Helper.THEME_BLACK) { - style = R.style.DialogBlack; - } else { - style = R.style.Dialog; - } - popup.setOnMenuItemClickListener(item -> { - switch (item.getItemId()) { - case R.id.action_show_link: - AlertDialog.Builder builder = new AlertDialog.Builder(context, style); - builder.setMessage(url); - builder.setTitle(context.getString(R.string.display_full_link)); - builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss()) - .show(); - break; - case R.id.action_share_link: - Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); - sendIntent.putExtra(Intent.EXTRA_TEXT, url); - sendIntent.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); - break; - - case R.id.action_open_other_app: - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(url)); - try { - context.startActivity(intent); - } catch (Exception e) { - Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); - } - break; - case R.id.action_copy_link: - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, url); - if (clipboard != null) { - clipboard.setPrimaryClip(clip); - Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show(); - } - break; - case R.id.action_unshorten: - Thread thread = new Thread() { - @Override - public void run() { - String response = new HttpsConnection(context, null).checkUrl(url); - - Handler mainHandler = new Handler(context.getMainLooper()); - - Runnable myRunnable = () -> { - AlertDialog.Builder builder1 = new AlertDialog.Builder(context, style); - if (response != null) { - builder1.setMessage(context.getString(R.string.redirect_detected, url, response)); - builder1.setNegativeButton(R.string.copy_link, (dialog, which) -> { - ClipboardManager clipboard1 = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip1 = ClipData.newPlainText(Helper.CLIP_BOARD, response); - if (clipboard1 != null) { - clipboard1.setPrimaryClip(clip1); - Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show(); - } - dialog.dismiss(); - }); - builder1.setNeutralButton(R.string.share_link, (dialog, which) -> { - Intent sendIntent1 = new Intent(Intent.ACTION_SEND); - sendIntent1.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); - sendIntent1.putExtra(Intent.EXTRA_TEXT, url); - sendIntent1.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent1, context.getString(R.string.share_with))); - dialog.dismiss(); - }); - } else { - builder1.setMessage(R.string.no_redirect); - } - builder1.setTitle(context.getString(R.string.check_redirect)); - builder1.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss()) - .show(); - - }; - mainHandler.post(myRunnable); - - } - }; - thread.start(); - break; - } - return true; - }); - popup.setOnDismissListener(menu -> BaseActivity.canShowActionMode = true); - popup.show(); - textView.clearFocus(); - BaseActivity.canShowActionMode = false; - } - - - @Override - public void updateDrawState(@NonNull TextPaint ds) { - super.updateDrawState(ds); - ds.setUnderlineText(false); - ds.setColor(link_color); - } - }, - startPosition, endPosition, - Spanned.SPAN_INCLUSIVE_EXCLUSIVE); - } } } @@ -614,55 +356,23 @@ public class Status implements Parcelable { spannableStringT.setSpan(new ClickableSpan() { @Override public void onClick(@NonNull View textView) { - if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { - Intent intent = new Intent(context, HashTagActivity.class); - Bundle b = new Bundle(); - b.putString("tag", tag.substring(1)); - intent.putExtras(b); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); - } + /* Intent intent = new Intent(context, HashTagActivity.class); + Bundle b = new Bundle(); + b.putString("tag", tag.substring(1)); + intent.putExtras(b); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent);*/ } @Override public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - ds.setColor(link_color); } }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } - if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) { - matcher = Helper.groupPattern.matcher(spannableStringT); - while (matcher.find()) { - int matchStart = matcher.start(1); - int matchEnd = matcher.end(); - final String groupname = spannableStringT.toString().substring(matchStart, matchEnd); - if (matchStart >= 0 && matchEnd <= spannableStringT.toString().length() && matchEnd >= matchStart) - spannableStringT.setSpan(new ClickableSpan() { - @Override - public void onClick(@NonNull View textView) { - if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { - Intent intent = new Intent(context, GroupActivity.class); - Bundle b = new Bundle(); - b.putString("groupname", groupname.substring(1)); - intent.putExtras(b); - context.startActivity(intent); - } - } - - @Override - public void updateDrawState(@NonNull TextPaint ds) { - super.updateDrawState(ds); - ds.setUnderlineText(false); - ds.setColor(link_color); - } - }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); - - } - } Pattern carriagePattern = Pattern.compile("(\\n)+$"); matcher = carriagePattern.matcher(spannableStringT); @@ -676,109 +386,6 @@ public class Status implements Parcelable { return SpannableString.valueOf(spannableStringT); } - public static void transformTranslation(Context context, Status status) { - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - int l_c = prefs.getInt("theme_link_color", -1); - if (l_c == -1) { - l_c = ThemeHelper.getAttColor(context, R.attr.linkColor); - } - final int link_color = l_c; - - if ((context instanceof Activity && ((Activity) context).isFinishing()) || status == null) - return; - if ((status.getReblog() != null && status.getReblog().getContent() == null) || (status.getReblog() == null && status.getContent() == null)) - return; - SpannableString spannableStringTranslated; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - spannableStringTranslated = new SpannableString(Html.fromHtml(status.getContentTranslated(), Html.FROM_HTML_MODE_LEGACY)); - else - spannableStringTranslated = new SpannableString(Html.fromHtml(status.getContentTranslated())); - - status.setContentSpanTranslated(treatment(context, spannableStringTranslated, status)); - - SpannableString contentSpanTranslated = status.getContentSpanTranslated(); - Matcher matcherALink = Patterns.WEB_URL.matcher(contentSpanTranslated.toString()); - while (matcherALink.find()) { - int matchStart = matcherALink.start(); - int matchEnd = matcherALink.end(); - final String url = contentSpanTranslated.toString().substring(matcherALink.start(1), matcherALink.end(1)); - if (matchStart >= 0 && matchEnd <= contentSpanTranslated.toString().length() && matchEnd >= matchStart) - contentSpanTranslated.setSpan(new ClickableSpan() { - @Override - public void onClick(@NonNull View textView) { - String finalUrl = url; - if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")) - finalUrl = "http://" + url; - Helper.openBrowser(context, finalUrl); - } - - @Override - public void updateDrawState(@NonNull TextPaint ds) { - super.updateDrawState(ds); - ds.setUnderlineText(false); - ds.setColor(link_color); - } - }, - matchStart, matchEnd, - Spanned.SPAN_INCLUSIVE_EXCLUSIVE); - - } - status.setContentSpanTranslated(contentSpanTranslated); - } - - - private static void makeImage(final WeakReference contextWeakReference, Status status) { - Context context = contextWeakReference.get(); - if (context instanceof Activity && ((Activity) context).isFinishing()) - return; - if (status.getAccount() == null) - return; - if (status.getImageURL() == null || status.getImageURL().size() == 0) - return; - - SpannableString contentSpan = status.getContentSpan(); - - final int[] i = {0}; - for (final String img : status.getImageURL()) { - final String name = img.split("\\|")[0]; - final String imgURL = img.split("\\|")[1]; - Glide.with(context) - .asBitmap() - .load(imgURL) - .into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Bitmap resource, Transition transition) { - - int w = resource.getWidth(); - int h = resource.getHeight(); - if (w > 300) { - h = (h * 300) / w; - w = 300; - } - if (contentSpan != null && contentSpan.toString().contains(name)) { - //emojis can be used several times so we have to loop - for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(name, startPosition + 1)) != -1; startPosition++) { - final int endPosition = startPosition + name.length(); - if (endPosition <= contentSpan.toString().length() && endPosition >= startPosition) - contentSpan.setSpan( - new ImageSpan(context, - Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(w, context), - (int) Helper.convertDpToPixel(h, context), false)), startPosition, - endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - } - } - } - - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { - - } - }); - - } - } - private static void replaceQuoteSpans(Context context, Spannable spannable) { QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class); @@ -787,10 +394,9 @@ public class Status implements Parcelable { int end = spannable.getSpanEnd(quoteSpan); int flags = spannable.getSpanFlags(quoteSpan); spannable.removeSpan(quoteSpan); - int colord = ContextCompat.getColor(context, R.color.cyanea_accent_reference); spannable.setSpan(new CustomQuoteSpan( - ContextCompat.getColor(context, R.color.transparent), - colord, + ContextCompat.getColor(context, android.R.color.transparent), + R.color.colorAccent, 10, 20), start, @@ -807,68 +413,23 @@ public class Status implements Parcelable { dest.writeParcelable(this.account, flags); dest.writeString(this.in_reply_to_id); dest.writeString(this.in_reply_to_account_id); - dest.writeParcelable(this.reblog, flags); dest.writeLong(this.created_at != null ? this.created_at.getTime() : -1); - dest.writeInt(this.reblogs_count); dest.writeInt(this.favourites_count); dest.writeInt(this.replies_count); - dest.writeByte(this.reblogged ? (byte) 1 : (byte) 0); dest.writeByte(this.favourited ? (byte) 1 : (byte) 0); dest.writeByte(this.muted ? (byte) 1 : (byte) 0); dest.writeByte(this.pinned ? (byte) 1 : (byte) 0); dest.writeByte(this.sensitive ? (byte) 1 : (byte) 0); dest.writeByte(this.bookmarked ? (byte) 1 : (byte) 0); dest.writeString(this.visibility); - dest.writeByte(this.attachmentShown ? (byte) 1 : (byte) 0); - dest.writeByte(this.spoilerShown ? (byte) 1 : (byte) 0); - dest.writeTypedList(this.media_attachments); - dest.writeParcelable(this.art_attachment, flags); dest.writeTypedList(this.mentions); - dest.writeTypedList(this.emojis); - dest.writeTypedList(this.reactions); dest.writeTypedList(this.tags); - dest.writeParcelable(this.application, flags); - dest.writeParcelable(this.card, flags); dest.writeString(this.language); - dest.writeByte(this.isTranslated ? (byte) 1 : (byte) 0); - dest.writeByte(this.isTranslationShown ? (byte) 1 : (byte) 0); - dest.writeByte(this.isNew ? (byte) 1 : (byte) 0); - dest.writeByte(this.isVisible ? (byte) 1 : (byte) 0); - dest.writeByte(this.fetchMore ? (byte) 1 : (byte) 0); dest.writeString(this.content); - dest.writeString(this.contentCW); - dest.writeString(this.contentTranslated); TextUtils.writeToParcel(this.contentSpan, dest, flags); - TextUtils.writeToParcel(this.contentSpanCW, dest, flags); - TextUtils.writeToParcel(this.contentSpanTranslated, dest, flags); dest.writeInt(this.type == null ? -1 : this.type.ordinal()); - dest.writeInt(this.itemViewType); dest.writeString(this.conversationId); - dest.writeByte(this.isExpanded ? (byte) 1 : (byte) 0); - dest.writeInt(this.numberLines); - dest.writeStringList(this.conversationProfilePicture); - dest.writeString(this.webviewURL); - dest.writeByte(this.isBoostAnimated ? (byte) 1 : (byte) 0); - dest.writeByte(this.isFavAnimated ? (byte) 1 : (byte) 0); - dest.writeString(this.scheduled_at); dest.writeString(this.contentType); - dest.writeByte(this.showSpoiler ? (byte) 1 : (byte) 0); - dest.writeByte(this.isNotice ? (byte) 1 : (byte) 0); - dest.writeParcelable(this.poll, flags); - dest.writeInt(this.media_height); - dest.writeByte(this.cached ? (byte) 1 : (byte) 0); - dest.writeByte(this.autoHiddenCW ? (byte) 1 : (byte) 0); - dest.writeByte(this.customFeaturesDisplayed ? (byte) 1 : (byte) 0); - dest.writeByte(this.shortReply ? (byte) 1 : (byte) 0); - dest.writeInt(this.warningFetched); - dest.writeStringList(this.imageURL); - dest.writeInt(this.viewType); - dest.writeByte(this.isFocused ? (byte) 1 : (byte) 0); - dest.writeString(this.quickReplyContent); - dest.writeString(this.quickReplyPrivacy); - dest.writeByte(this.showBottomLine ? (byte) 1 : (byte) 0); - dest.writeByte(this.showTopLine ? (byte) 1 : (byte) 0); - } public String getId() { @@ -923,34 +484,7 @@ public class Status implements Parcelable { return content; } - public void setContent(Context context, String content) { - //Remove UTM by default - this.content = Helper.remove_tracking_param(context, content); - } - public boolean isShortReply() { - return shortReply; - } - - public void setShortReply(boolean shortReply) { - this.shortReply = shortReply; - } - - public Status getReblog() { - return reblog; - } - - public void setReblog(Status reblog) { - this.reblog = reblog; - } - - public int getReblogs_count() { - return reblogs_count; - } - - public void setReblogs_count(int reblogs_count) { - this.reblogs_count = reblogs_count; - } public Date getCreated_at() { return created_at; @@ -968,15 +502,6 @@ public class Status implements Parcelable { this.favourites_count = favourites_count; } - - public boolean isReblogged() { - return reblogged; - } - - public void setReblogged(boolean reblogged) { - this.reblogged = reblogged; - } - public boolean isFavourited() { return favourited; } @@ -1001,22 +526,6 @@ public class Status implements Parcelable { this.sensitive = sensitive; } - public String getSpoiler_text() { - return contentCW; - } - - public void setSpoiler_text(String spoiler_text) { - this.contentCW = spoiler_text; - } - - public ArrayList getMedia_attachments() { - return media_attachments; - } - - public void setMedia_attachments(ArrayList media_attachments) { - this.media_attachments = media_attachments; - } - public List getMentions() { return mentions; } @@ -1046,14 +555,6 @@ public class Status implements Parcelable { return tag_names.toString(); } - public Application getApplication() { - return application; - } - - public void setApplication(Application application) { - this.application = application; - } - public String getVisibility() { return visibility; } @@ -1062,21 +563,7 @@ public class Status implements Parcelable { this.visibility = visibility; } - public boolean isAttachmentShown() { - return attachmentShown; - } - public void setAttachmentShown(boolean attachmentShown) { - this.attachmentShown = attachmentShown; - } - - public boolean isSpoilerShown() { - return spoilerShown; - } - - public void setSpoilerShown(boolean spoilerShown) { - this.spoilerShown = spoilerShown; - } public String getLanguage() { return language; @@ -1086,69 +573,6 @@ public class Status implements Parcelable { this.language = language; } - public boolean isTranslated() { - return isTranslated; - } - - public void setTranslated(boolean translated) { - isTranslated = translated; - } - - public boolean isTranslationShown() { - return isTranslationShown; - } - - public void setTranslationShown(boolean translationShown) { - isTranslationShown = translationShown; - } - - public String getContentTranslated() { - return contentTranslated; - } - - public void setContentTranslated(String content_translated) { - this.contentTranslated = content_translated; - } - - public boolean isNew() { - return isNew; - } - - public void setNew(boolean aNew) { - isNew = aNew; - } - - public boolean isVisible() { - return isVisible; - } - - public void setVisible(boolean visible) { - isVisible = visible; - } - - public List getEmojis() { - return emojis; - } - - public void setEmojis(List emojis) { - this.emojis = emojis; - } - - public boolean isEmojiFound() { - return isEmojiFound; - } - - public void setEmojiFound(boolean emojiFound) { - isEmojiFound = emojiFound; - } - - public boolean isImageFound() { - return isImageFound; - } - - public void setImageFound(boolean imageFound) { - isImageFound = imageFound; - } public SpannableString getContentSpan() { return contentSpan; @@ -1158,38 +582,7 @@ public class Status implements Parcelable { this.contentSpan = contentSpan; } - public SpannableString getContentSpanCW() { - return contentSpanCW; - } - public void setContentSpanCW(SpannableString contentSpanCW) { - this.contentSpanCW = contentSpanCW; - } - - public SpannableString getContentSpanTranslated() { - return contentSpanTranslated; - } - - public void setContentSpanTranslated(SpannableString contentSpanTranslated) { - this.contentSpanTranslated = contentSpanTranslated; - } - - - public boolean isEmojiTranslateFound() { - return isEmojiTranslateFound; - } - - public void setEmojiTranslateFound(boolean emojiTranslateFound) { - isEmojiTranslateFound = emojiTranslateFound; - } - - public boolean isFetchMore() { - return fetchMore; - } - - public void setFetchMore(boolean fetchMore) { - this.fetchMore = fetchMore; - } @Override @@ -1197,14 +590,6 @@ public class Status implements Parcelable { return otherStatus != null && (otherStatus == this || otherStatus instanceof Status && this.getId().equals(((Status) otherStatus).getId())); } - public Card getCard() { - return card; - } - - public void setCard(Card card) { - this.card = card; - } - public boolean isMuted() { return muted; } @@ -1214,9 +599,6 @@ public class Status implements Parcelable { } public boolean isBookmarked() { - if (this.getReblog() != null && this.getReblog().isBookmarked()) { - bookmarked = true; - } return bookmarked; } @@ -1240,29 +622,7 @@ public class Status implements Parcelable { this.type = type; } - public List getConversationProfilePicture() { - return conversationProfilePicture; - } - public void setConversationProfilePicture(List conversationProfilePicture) { - this.conversationProfilePicture = conversationProfilePicture; - } - - public String getWebviewURL() { - return webviewURL; - } - - public void setWebviewURL(String webviewURL) { - this.webviewURL = webviewURL; - } - - public int getItemViewType() { - return itemViewType; - } - - public void setItemViewType(int itemViewType) { - this.itemViewType = itemViewType; - } public String getConversationId() { return conversationId; @@ -1272,45 +632,7 @@ public class Status implements Parcelable { this.conversationId = conversationId; } - public boolean isExpanded() { - return isExpanded; - } - public void setExpanded(boolean expanded) { - isExpanded = expanded; - } - - public int getNumberLines() { - return numberLines; - } - - public void setNumberLines(int numberLines) { - this.numberLines = numberLines; - } - - public boolean isBoostAnimated() { - return isBoostAnimated; - } - - public void setBoostAnimated(boolean boostAnimated) { - isBoostAnimated = boostAnimated; - } - - public boolean isFavAnimated() { - return isFavAnimated; - } - - public void setFavAnimated(boolean favAnimated) { - isFavAnimated = favAnimated; - } - - public Attachment getArt_attachment() { - return art_attachment; - } - - public void setArt_attachment(Attachment art_attachment) { - this.art_attachment = art_attachment; - } @Override public int describeContents() { @@ -1318,14 +640,6 @@ public class Status implements Parcelable { } - public String getScheduled_at() { - return scheduled_at; - } - - public void setScheduled_at(String scheduled_at) { - this.scheduled_at = scheduled_at; - } - public String getContentType() { return contentType; } @@ -1334,175 +648,5 @@ public class Status implements Parcelable { this.contentType = contentType; } - public boolean isShowSpoiler() { - return showSpoiler; - } - - public void setShowSpoiler(boolean showSpoiler) { - this.showSpoiler = showSpoiler; - } - - - public boolean isNotice() { - return isNotice; - } - - public void setNotice(boolean notice) { - isNotice = notice; - } - - public Poll getPoll() { - return poll; - } - - public void setPoll(Poll poll) { - this.poll = poll; - } - - public int getMedia_height() { - return media_height; - } - - public void setMedia_height(int media_height) { - this.media_height = media_height; - } - - public boolean iscached() { - return cached; - } - - public void setcached(boolean cached) { - this.cached = cached; - } - - public boolean isAutoHiddenCW() { - return autoHiddenCW; - } - - public void setAutoHiddenCW(boolean autoHiddenCW) { - this.autoHiddenCW = autoHiddenCW; - } - - public boolean isCustomFeaturesDisplayed() { - return customFeaturesDisplayed; - } - - public void setCustomFeaturesDisplayed(boolean customFeaturesDisplayed) { - this.customFeaturesDisplayed = customFeaturesDisplayed; - } - - public int getWarningFetched() { - return warningFetched; - } - - public void setWarningFetched(int warningFetched) { - this.warningFetched = warningFetched; - } - - public List getImageURL() { - return imageURL; - } - - public void setImageURL(List imageURL) { - this.imageURL = imageURL; - } - - public int getViewType() { - return viewType; - } - - public void setViewType(Context context) { - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false); - boolean isConsoleMode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false); - if (isCompactMode) - this.viewType = COMPACT_STATUS; - else if (isConsoleMode) - this.viewType = CONSOLE_STATUS; - else - this.viewType = DISPLAYED_STATUS; - - } - - public boolean isFocused() { - return isFocused; - } - - public void setFocused(boolean focused) { - isFocused = focused; - } - - public long getDb_id() { - return db_id; - } - - public void setDb_id(long db_id) { - this.db_id = db_id; - } - - - public boolean isCommentsFetched() { - return commentsFetched; - } - - public void setCommentsFetched(boolean commentsFetched) { - this.commentsFetched = commentsFetched; - } - - public List getComments() { - return comments; - } - - public void setComments(List comments) { - this.comments = comments; - } - - public String getQuickReplyContent() { - return quickReplyContent; - } - - public void setQuickReplyContent(String quickReplyContent) { - this.quickReplyContent = quickReplyContent; - } - - public String getQuickReplyPrivacy() { - return quickReplyPrivacy; - } - - public void setQuickReplyPrivacy(String quickReplyPrivacy) { - this.quickReplyPrivacy = quickReplyPrivacy; - } - - public boolean isShowBottomLine() { - return showBottomLine; - } - - public void setShowBottomLine(boolean showBottomLine) { - this.showBottomLine = showBottomLine; - } - - public boolean isShowTopLine() { - return showTopLine; - } - - public void setShowTopLine(boolean showTopLine) { - this.showTopLine = showTopLine; - } - - public boolean isPollEmojiFound() { - return isPollEmojiFound; - } - - public void setPollEmojiFound(boolean pollEmojiFound) { - isPollEmojiFound = pollEmojiFound; - } - - public List getReactions() { - return reactions; - } - - public void setReactions(List reactions) { - this.reactions = reactions; - } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/entities/StatusDrawerParams.java b/app/src/main/java/app/fedilab/fedilabtube/client/entities/StatusDrawerParams.java new file mode 100644 index 0000000..a3f97e2 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/client/entities/StatusDrawerParams.java @@ -0,0 +1,46 @@ +package app.fedilab.fedilabtube.client.entities; + +import java.util.List; + +import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask; + +public class StatusDrawerParams { + private List statuses; + private RetrieveFeedsAsyncTask.Type type; + private String targetedId; + private int position; + + + public List getStatuses() { + return statuses; + } + + public void setStatuses(List statuses) { + this.statuses = statuses; + } + + public RetrieveFeedsAsyncTask.Type getType() { + return type; + } + + public void setType(RetrieveFeedsAsyncTask.Type type) { + this.type = type; + } + + public String getTargetedId() { + return targetedId; + } + + public void setTargetedId(String targetedId) { + this.targetedId = targetedId; + } + + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } +} diff --git a/app/src/main/java/app/fedilab/fedilabtube/ui/video/PeertubeAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java similarity index 95% rename from app/src/main/java/app/fedilab/fedilabtube/ui/video/PeertubeAdapter.java rename to app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java index 5546f65..3c2d20c 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/ui/video/PeertubeAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java @@ -1,4 +1,4 @@ -package app.fedilab.fedilabtube.ui.video; +package app.fedilab.fedilabtube.drawer; @@ -36,12 +36,10 @@ public class PeertubeAdapter extends RecyclerView.Adapter peertubes; private Context context; - private String instance; - public PeertubeAdapter(String instance, List peertubes) { + public PeertubeAdapter(List peertubes) { this.peertubes = peertubes; - this.instance = instance; } @@ -102,8 +100,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, PeertubeActivity.class); Bundle b = new Bundle(); - if ((instance == null || instance.trim().length() == 0) ) - instance = Helper.getLiveInstance(context); + String instance = Helper.getLiveInstance(context); String finalUrl = "https://" + instance + peertube.getEmbedPath(); Pattern link = Pattern.compile("(https?://[\\da-z.-]+\\.[a-z.]{2,10})/videos/embed/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$"); Matcher matcherLink = link.matcher(finalUrl); diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/StatusListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/StatusListAdapter.java new file mode 100644 index 0000000..b8f9278 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/StatusListAdapter.java @@ -0,0 +1,219 @@ +package app.fedilab.fedilabtube.drawer; + + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.AsyncTask; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.method.LinkMovementMethod; +import android.text.style.ForegroundColorSpan; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import app.fedilab.fedilabtube.PeertubeActivity; +import app.fedilab.fedilabtube.R; +import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask; +import app.fedilab.fedilabtube.client.PeertubeAPI; +import app.fedilab.fedilabtube.client.entities.Account; +import app.fedilab.fedilabtube.client.entities.Error; +import app.fedilab.fedilabtube.client.entities.Status; +import app.fedilab.fedilabtube.client.entities.StatusDrawerParams; +import app.fedilab.fedilabtube.helper.Helper; +import app.fedilab.fedilabtube.interfaces.OnPostActionInterface; +import es.dmoral.toasty.Toasty; + +import static android.content.Context.MODE_PRIVATE; + + + +public class StatusListAdapter extends RecyclerView.Adapter implements OnPostActionInterface { + + + + private Context context; + private List statuses; + + private StatusListAdapter statusListAdapter; + + + public StatusListAdapter(StatusDrawerParams statusDrawerParams) { + statuses = statusDrawerParams.getStatuses(); + statusListAdapter = this; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public int getItemCount() { + return statuses.size(); + } + + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + + context = parent.getContext(); + LayoutInflater layoutInflater = LayoutInflater.from(this.context); + return new ViewHolder(layoutInflater.inflate(R.layout.drawer_status_compact, parent, false)); + } + + @SuppressLint({"SetJavaScriptEnabled", "ClickableViewAccessibility"}) + @Override + public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) { + + context = viewHolder.itemView.getContext(); + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + + + final ViewHolder holder = (ViewHolder) viewHolder; + + final Status status = statuses.get(i); + + + if (status == null) + return; + if (status.getVisibility() == null) { + status.setVisibility("public"); + } + + if (status.getAccount().getId().equals(userId)) + holder.status_peertube_delete.setVisibility(View.VISIBLE); + else + holder.status_peertube_delete.setVisibility(View.GONE); + holder.status_peertube_delete.setOnClickListener(v -> { + AlertDialog.Builder builderInner; + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(R.string.delete_comment); + builderInner.setMessage(R.string.delete_comment_confirm); + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { + new PostActionAsyncTask(context, PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT, PeertubeActivity.video_id, null, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + dialog.dismiss(); + }); + builderInner.show(); + }); + + + holder.status_content.setOnTouchListener((view, motionEvent) -> { + if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) { + try { + view.requestFocus(); + } catch (Exception ignored) { + } + } + return false; + }); + + //Click on a conversation + + holder.status_content.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE); + + holder.status_content.setMovementMethod(LinkMovementMethod.getInstance()); + + + final Account accountForUrl; + accountForUrl = status.getAccount(); + holder.status_account_displayname.setVisibility(View.GONE); + holder.status_account_displayname_owner.setText(status.getAccount().getUsername().replace("@", ""), TextView.BufferType.SPANNABLE); + + + Spannable wordtoSpan; + Pattern hashAcct; + wordtoSpan = new SpannableString("@" + status.getAccount().getAcct()); + hashAcct = Pattern.compile("(@" + status.getAccount().getAcct() + ")"); + Matcher matcherAcct = hashAcct.matcher(wordtoSpan); + while (matcherAcct.find()) { + int matchStart = matcherAcct.start(1); + int matchEnd = matcherAcct.end(); + if (wordtoSpan.length() >= matchEnd && matchStart < matchEnd) { + wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, android.R.color.darker_gray)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + } + + } + holder.status_account_username.setText(wordtoSpan); + + + holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at())); + + + Helper.loadGiF(context, accountForUrl, holder.status_account_profile); + } + + @Override + public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String targetedId, Error error) { + + if (error != null) { + Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show(); + return; + } + + if (statusAction == PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT) { + int position = 0; + for (Status status : statuses) { + if (status.getId().equals(targetedId)) { + statuses.remove(status); + statusListAdapter.notifyItemRemoved(position); + break; + } + position++; + } + } + } + + + static class ViewHolder extends RecyclerView.ViewHolder { + + TextView status_content; + TextView status_account_username; + TextView status_account_displayname, status_account_displayname_owner; + ImageView status_account_profile; + TextView status_toot_date; + LinearLayout main_container; + LinearLayout status_content_container; + TextView status_peertube_delete; + + @SuppressLint("SetJavaScriptEnabled") + ViewHolder(View itemView) { + super(itemView); + status_content = itemView.findViewById(R.id.status_content); + status_account_username = itemView.findViewById(R.id.status_account_username); + status_account_displayname = itemView.findViewById(R.id.status_account_displayname); + status_account_displayname_owner = itemView.findViewById(R.id.status_account_displayname_owner); + status_account_profile = itemView.findViewById(R.id.status_account_profile); + status_toot_date = itemView.findViewById(R.id.status_toot_date); + main_container = itemView.findViewById(R.id.main_container); + status_content_container = itemView.findViewById(R.id.status_content_container); + status_peertube_delete = itemView.findViewById(R.id.status_peertube_delete); + + } + + public View getView() { + return itemView; + } + + + } + +} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayStatusFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayStatusFragment.java new file mode 100644 index 0000000..271e3cb --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayStatusFragment.java @@ -0,0 +1,306 @@ +package app.fedilab.fedilabtube.fragment; + +import android.content.Context; +import android.content.SharedPreferences; +import android.database.sqlite.SQLiteDatabase; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.RelativeLayout; +import android.widget.TextView; +import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.List; + + +import app.fedilab.fedilabtube.R; +import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask; +import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSearchAsyncTask; +import app.fedilab.fedilabtube.client.APIResponse; +import app.fedilab.fedilabtube.client.PeertubeAPI; +import app.fedilab.fedilabtube.client.entities.Error; +import app.fedilab.fedilabtube.client.entities.Peertube; +import app.fedilab.fedilabtube.drawer.PeertubeAdapter; +import app.fedilab.fedilabtube.helper.Helper; +import app.fedilab.fedilabtube.interfaces.OnPostActionInterface; +import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface; +import app.fedilab.fedilabtube.sqlite.Sqlite; +import es.dmoral.toasty.Toasty; + + +public class DisplayStatusFragment extends Fragment implements OnPostActionInterface, OnRetrieveFeedsInterface { + + + private LinearLayoutManager mLayoutManager; + private boolean flag_loading; + private Context context; + private AsyncTask asyncTask; + private PeertubeAdapter peertubeAdapater; + private String max_id; + private List peertubes; + private RetrieveFeedsAsyncTask.Type type; + private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; + private boolean firstLoad; + private SwipeRefreshLayout swipeRefreshLayout; + private SharedPreferences sharedpreferences; + private boolean isSwipped; + private String search_peertube; + private TextView textviewNoActionText; + private boolean ischannel; + private boolean ownVideos; + private View rootView; + private RecyclerView lv_status; + + public DisplayStatusFragment() { + } + + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + rootView = inflater.inflate(R.layout.fragment_video, container, false); + + peertubes = new ArrayList<>(); + context = getContext(); + Bundle bundle = this.getArguments(); + + if (bundle != null) { + type = (RetrieveFeedsAsyncTask.Type) bundle.get("type"); + String targetedId = bundle.getString("targetedid", null); + String tag = bundle.getString("tag", null); + search_peertube = bundle.getString("search_peertube", null); + String remote_channel_name = bundle.getString("remote_channel_name", null); + String instanceType = bundle.getString("instanceType", "MASTODON"); + ischannel = bundle.getBoolean("ischannel", false); + int timelineId = bundle.getInt("timelineId"); + } + if (ischannel) { + type = RetrieveFeedsAsyncTask.Type.CHANNEL; + } + + assert context != null; + SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + + + lv_status = rootView.findViewById(R.id.lv_status); + + isSwipped = false; + max_id = null; + flag_loading = true; + firstLoad = true; + + assert context != null; + sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer); + + mainLoader = rootView.findViewById(R.id.loader); + nextElementLoader = rootView.findViewById(R.id.loading_next_status); + textviewNoAction = rootView.findViewById(R.id.no_action); + textviewNoActionText = rootView.findViewById(R.id.no_action_text); + mainLoader.setVisibility(View.VISIBLE); + nextElementLoader.setVisibility(View.GONE); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context != null ? Helper.getLiveInstance(context) : null); + + + + peertubeAdapater = new PeertubeAdapter(this.peertubes); + lv_status.setAdapter(peertubeAdapater); + mLayoutManager = new LinearLayoutManager(context); + + lv_status.setLayoutManager(mLayoutManager); + + + swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh); + if (context != null) { + //Load data depending of the value + if (search_peertube == null) { //Not a Peertube search + asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", DisplayStatusFragment.this).execute(); + } else { + asyncTask = new RetrievePeertubeSearchAsyncTask(context, "0", search_peertube, DisplayStatusFragment.this).execute(); + } + } else { + new Handler(Looper.getMainLooper()).postDelayed(() -> { + if (context != null) { + if (search_peertube == null) { //Not a Peertube search + asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", DisplayStatusFragment.this).execute(); + } else { + asyncTask = new RetrievePeertubeSearchAsyncTask(context, "0", search_peertube, DisplayStatusFragment.this).execute(); + } + } + }, 500); + } + + lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() { + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + + int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition(); + if (dy > 0) { + int visibleItemCount = mLayoutManager.getChildCount(); + int totalItemCount = mLayoutManager.getItemCount(); + if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { + if (!flag_loading) { + flag_loading = true; + if (search_peertube == null) { //Not a Peertube search + asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).execute(); + } else { + asyncTask = new RetrievePeertubeSearchAsyncTask(context, max_id, search_peertube, DisplayStatusFragment.this).execute(); + } + nextElementLoader.setVisibility(View.VISIBLE); + } + } else { + nextElementLoader.setVisibility(View.GONE); + } + } + } + }); + + + return rootView; + } + + @Override + public void onPause() { + super.onPause(); + if (swipeRefreshLayout != null) { + swipeRefreshLayout.setEnabled(false); + swipeRefreshLayout.setRefreshing(false); + swipeRefreshLayout.clearAnimation(); + } + if (getActivity() != null) { + InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null && getView() != null) { + imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); + } + } + } + + + @Override + public void onCreate(Bundle saveInstance) { + super.onCreate(saveInstance); + } + + + @Override + public void onAttach(@NotNull Context context) { + super.onAttach(context); + this.context = context; + } + + + @Override + public void onStop() { + super.onStop(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING) + asyncTask.cancel(true); + } + + @Override + public void onRetrieveFeeds(APIResponse apiResponse) { + //hide loaders + mainLoader.setVisibility(View.GONE); + nextElementLoader.setVisibility(View.GONE); + //handle other API error but discards 404 - error which can often happen due to toots which have been deleted + if (this.peertubes == null || apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) { + if (apiResponse == null) + Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + else { + Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); + } + swipeRefreshLayout.setRefreshing(false); + flag_loading = false; + return; + } + int previousPosition = this.peertubes.size(); + if (max_id == null) + max_id = "0"; + //max_id needs to work like an offset + int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE); + max_id = String.valueOf(Integer.parseInt(max_id) + tootPerPage); + if (apiResponse.getPeertubes() == null) { + return; + } + this.peertubes.addAll(apiResponse.getPeertubes()); + //If no item were inserted previously the adapter is created + if (previousPosition == 0) { + peertubeAdapater = new PeertubeAdapter(this.peertubes); + lv_status.setAdapter(peertubeAdapater); + } else + peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size()); + //remove handlers + swipeRefreshLayout.setRefreshing(false); + textviewNoAction.setVisibility(View.GONE); + if (firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0)) { + textviewNoActionText.setText(R.string.no_video_to_display); + textviewNoAction.setVisibility(View.VISIBLE); + } + flag_loading = false; + firstLoad = false; + } + + + @Override + public void onDestroyView() { + if (lv_status != null) { + try { + lv_status.setAdapter(null); + } catch (Exception ignored) { + } + } + super.onDestroyView(); + rootView = null; + } + + @Override + public void onResume() { + super.onResume(); + swipeRefreshLayout.setEnabled(true); + } + + + + public void scrollToTop() { + if (mLayoutManager != null) { + mLayoutManager.scrollToPositionWithOffset(0, 0); + } + } + + + public void pullToRefresh() { + if (peertubes.size() > 0) { + int size = peertubes.size(); + isSwipped = true; + peertubes.clear(); + peertubes = new ArrayList<>(); + max_id = "0"; + peertubeAdapater.notifyItemRangeRemoved(0, size); + if (search_peertube == null) { //Not a Peertube search + asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", DisplayStatusFragment.this).execute(); + } else { + asyncTask = new RetrievePeertubeSearchAsyncTask(context, "0", search_peertube, DisplayStatusFragment.this).execute(); + } + } + } + + + @Override + public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) { + + } +} diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/CacheDataSourceFactory.java b/app/src/main/java/app/fedilab/fedilabtube/helper/CacheDataSourceFactory.java new file mode 100644 index 0000000..974c47e --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/helper/CacheDataSourceFactory.java @@ -0,0 +1,56 @@ +package app.fedilab.fedilabtube.helper; + +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.DefaultHttpDataSourceFactory; +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 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; + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); + DefaultBandwidthMeter.Builder bandwidthMeterBuilder = new DefaultBandwidthMeter.Builder(context); + DefaultBandwidthMeter bandwidthMeter = bandwidthMeterBuilder.build(); + defaultDatasourceFactory = new DefaultDataSourceFactory(this.context, + bandwidthMeter, + new DefaultHttpDataSourceFactory(userAgent, 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); + } +} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/CustomQuoteSpan.java b/app/src/main/java/app/fedilab/fedilabtube/helper/CustomQuoteSpan.java new file mode 100644 index 0000000..1a8b163 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/helper/CustomQuoteSpan.java @@ -0,0 +1,54 @@ +package app.fedilab.fedilabtube.helper; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.text.Layout; +import android.text.style.LeadingMarginSpan; +import android.text.style.LineBackgroundSpan; + +import org.jetbrains.annotations.NotNull; + +/** + * Original work from @heath-borders: https://stackoverflow.com/a/29114976/3197259 + */ +public class CustomQuoteSpan implements LeadingMarginSpan, LineBackgroundSpan { + private final int backgroundColor; + private final int stripeColor; + private final float stripeWidth; + private final float gap; + + public CustomQuoteSpan(int backgroundColor, int stripeColor, float stripeWidth, float gap) { + this.backgroundColor = backgroundColor; + this.stripeColor = stripeColor; + this.stripeWidth = stripeWidth; + this.gap = gap; + } + + @Override + public int getLeadingMargin(boolean first) { + return (int) (stripeWidth + gap); + } + + @Override + public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, + CharSequence text, int start, int end, boolean first, Layout layout) { + Paint.Style style = p.getStyle(); + int paintColor = p.getColor(); + + p.setStyle(Paint.Style.FILL); + p.setColor(stripeColor); + + c.drawRect(x, top, x + dir * stripeWidth, bottom, p); + + p.setStyle(style); + p.setColor(paintColor); + } + + @Override + public void drawBackground(@NotNull Canvas c, @NotNull Paint p, int left, int right, int top, int baseline, int bottom, @NotNull CharSequence text, int start, int end, int lnum) { + int paintColor = p.getColor(); + p.setColor(backgroundColor); + c.drawRect(left, top, right, bottom, p); + p.setColor(paintColor); + } +} diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java index 52e8f38..5b20339 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java +++ b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java @@ -1,22 +1,33 @@ package app.fedilab.fedilabtube.helper; -import android.annotation.SuppressLint; import android.app.Activity; import android.app.DownloadManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.util.TypedValue; +import android.view.View; import android.view.WindowManager; +import android.webkit.CookieManager; import android.webkit.URLUtil; +import android.webkit.WebChromeClient; +import android.webkit.WebSettings; import android.widget.ImageView; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; +import androidx.browser.customtabs.CustomTabsIntent; import androidx.core.content.ContextCompat; +import androidx.core.graphics.drawable.DrawableCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.CenterCrop; @@ -35,7 +46,10 @@ import java.util.TimeZone; import java.util.regex.Pattern; import app.fedilab.fedilabtube.R; +import app.fedilab.fedilabtube.WebviewActivity; import app.fedilab.fedilabtube.client.entities.Account; +import app.fedilab.fedilabtube.webview.CustomWebview; +import app.fedilab.fedilabtube.webview.ProxyHelper; import es.dmoral.toasty.Toasty; import static android.content.Context.DOWNLOAD_SERVICE; @@ -77,6 +91,17 @@ public class Helper { )); + public static final int RELOAD_MYVIDEOS = 10; + + + public static final String SET_VIDEO_MODE = "set_video_mode"; + public static final int VIDEO_MODE_TORRENT = 0; + public static final int VIDEO_MODE_WEBVIEW = 1; + public static final int VIDEO_MODE_DIRECT = 2; + + public static final String SET_SHARE_DETAILS = "set_share_details"; + public static final int DEFAULT_VIDEO_CACHE_MB = 100; + public static final String TAG = "mastodon_etalab"; public static final String CLIENT_NAME_VALUE = "Fedilab"; public static final String OAUTH_SCOPES = "read write follow"; @@ -88,7 +113,7 @@ public class Helper { "(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,10}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); - + public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_A-zÀ-ÿ]+)"); public static final String SET_ALLOW_STREAM = "set_allow_stream"; public static final String SET_CUSTOM_USER_AGENT = "set_custom_user_agent"; public static final String SET_VIDEO_CACHE = "set_video_cache"; @@ -101,6 +126,8 @@ public class Helper { public static final String SET_PROXY_LOGIN = "set_proxy_login"; public static final String SET_PROXY_PASSWORD = "set_proxy_password"; + public static final String INTENT_ACTION = "intent_action"; + public static final String PREF_KEY_ID = "userID"; public static final String PREF_IS_MODERATOR = "is_moderator"; public static final String PREF_IS_ADMINISTRATOR = "is_administrator"; @@ -108,8 +135,9 @@ public class Helper { public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob"; public static final String REDIRECT_CONTENT_WEB = "mastalab://backtomastalab"; 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"; public static final String CLIENT_NAME = "client_name"; public static final String APP_PREFS = "app_prefs"; public static final String ID = "id"; @@ -128,6 +156,9 @@ public class Helper { public static final String LAST_NOTIFICATION_MAX_ID = "last_notification_max_id"; public static final int VIDEOS_PER_PAGE = 40; public static final String SET_VIDEO_NSFW = "set_video_nsfw"; + public static final String SET_EMBEDDED_BROWSER = "set_embedded_browser"; + public static final String SET_CUSTOM_TABS = "set_custom_tabs"; + public static final String SET_DISPLAY_CONFIRM = "set_display_confirm"; /** * Returns the peertube URL depending of the academic domain name @@ -374,7 +405,7 @@ public class Helper { if (custom_tabs) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); - builder.setToolbarColor(ContextCompat.getColor(context, R.color.mastodonC1)); + builder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary)); try { customTabsIntent.launchUrl(context, Uri.parse(url)); } catch (Exception ignored) { @@ -395,6 +426,53 @@ public class Helper { } + public static CustomWebview initializeWebview(Activity activity, int webviewId, View rootView) { + + CustomWebview webView; + if (rootView == null) { + webView = activity.findViewById(webviewId); + } else { + webView = rootView.findViewById(webviewId); + } + final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + + webView.getSettings().setJavaScriptEnabled(true); + webView.getSettings().setUseWideViewPort(true); + webView.getSettings().setLoadWithOverviewMode(true); + webView.getSettings().setSupportZoom(true); + webView.getSettings().setDisplayZoomControls(false); + webView.getSettings().setBuiltInZoomControls(true); + webView.getSettings().setAllowContentAccess(true); + webView.getSettings().setLoadsImagesAutomatically(true); + webView.getSettings().setSupportMultipleWindows(false); + webView.getSettings().setMediaPlaybackRequiresUserGesture(true); + String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); + webView.getSettings().setUserAgentString(user_agent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + CookieManager cookieManager = CookieManager.getInstance(); + cookieManager.setAcceptThirdPartyCookies(webView, false); + } + webView.setBackgroundColor(Color.TRANSPARENT); + webView.getSettings().setAppCacheEnabled(true); + webView.getSettings().setDatabaseEnabled(true); + webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); + webView.setWebChromeClient(new WebChromeClient() { + @Override + public Bitmap getDefaultVideoPoster() { + return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888); + } + }); + boolean proxyEnabled = sharedpreferences.getBoolean(Helper.SET_PROXY_ENABLED, false); + if (proxyEnabled) { + String host = sharedpreferences.getString(Helper.SET_PROXY_HOST, "127.0.0.1"); + int port = sharedpreferences.getInt(Helper.SET_PROXY_PORT, 8118); + ProxyHelper.setProxy(activity, webView, host, port, WebviewActivity.class.getName()); + } + + return webView; + } + + /** * Manage downloads with URLs * @@ -431,4 +509,31 @@ public class Helper { alert.show(); } + + /** + * change color of a drawable + * + * @param drawable int the drawable + * @param hexaColor example 0xffff00 + */ + public static Drawable changeDrawableColor(Context context, int drawable, int hexaColor) { + Drawable mDrawable = ContextCompat.getDrawable(context, drawable); + int color; + try { + color = Color.parseColor(context.getString(hexaColor)); + } catch (Resources.NotFoundException e) { + try { + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = context.getTheme(); + theme.resolveAttribute(hexaColor, typedValue, true); + color = typedValue.data; + } catch (Resources.NotFoundException ed) { + color = hexaColor; + } + } + assert mDrawable != null; + mDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); + DrawableCompat.setTint(mDrawable, color); + return mDrawable; + } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/ui/dashboard/DashboardFragment.java b/app/src/main/java/app/fedilab/fedilabtube/ui/dashboard/DashboardFragment.java deleted file mode 100644 index 83e5e09..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/ui/dashboard/DashboardFragment.java +++ /dev/null @@ -1,35 +0,0 @@ -package app.fedilab.fedilabtube.ui.dashboard; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.Observer; -import androidx.lifecycle.ViewModelProviders; - -import app.fedilab.fedilabtube.R; - -public class DashboardFragment extends Fragment { - - private DashboardViewModel dashboardViewModel; - - public View onCreateView(@NonNull LayoutInflater inflater, - ViewGroup container, Bundle savedInstanceState) { - dashboardViewModel = - ViewModelProviders.of(this).get(DashboardViewModel.class); - View root = inflater.inflate(R.layout.fragment_dashboard, container, false); - final TextView textView = root.findViewById(R.id.text_dashboard); - dashboardViewModel.getText().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(@Nullable String s) { - textView.setText(s); - } - }); - return root; - } -} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/ui/dashboard/DashboardViewModel.java b/app/src/main/java/app/fedilab/fedilabtube/ui/dashboard/DashboardViewModel.java deleted file mode 100644 index 19da877..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/ui/dashboard/DashboardViewModel.java +++ /dev/null @@ -1,19 +0,0 @@ -package app.fedilab.fedilabtube.ui.dashboard; - -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; - -public class DashboardViewModel extends ViewModel { - - private MutableLiveData mText; - - public DashboardViewModel() { - mText = new MutableLiveData<>(); - mText.setValue("This is dashboard fragment"); - } - - public LiveData getText() { - return mText; - } -} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/ui/notifications/NotificationsFragment.java b/app/src/main/java/app/fedilab/fedilabtube/ui/notifications/NotificationsFragment.java deleted file mode 100644 index a8edc05..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/ui/notifications/NotificationsFragment.java +++ /dev/null @@ -1,35 +0,0 @@ -package app.fedilab.fedilabtube.ui.notifications; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.Observer; -import androidx.lifecycle.ViewModelProviders; - -import app.fedilab.fedilabtube.R; - -public class NotificationsFragment extends Fragment { - - private NotificationsViewModel notificationsViewModel; - - public View onCreateView(@NonNull LayoutInflater inflater, - ViewGroup container, Bundle savedInstanceState) { - notificationsViewModel = - ViewModelProviders.of(this).get(NotificationsViewModel.class); - View root = inflater.inflate(R.layout.fragment_notifications, container, false); - final TextView textView = root.findViewById(R.id.text_notifications); - notificationsViewModel.getText().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(@Nullable String s) { - textView.setText(s); - } - }); - return root; - } -} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/ui/notifications/NotificationsViewModel.java b/app/src/main/java/app/fedilab/fedilabtube/ui/notifications/NotificationsViewModel.java deleted file mode 100644 index 967525e..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/ui/notifications/NotificationsViewModel.java +++ /dev/null @@ -1,19 +0,0 @@ -package app.fedilab.fedilabtube.ui.notifications; - -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; - -public class NotificationsViewModel extends ViewModel { - - private MutableLiveData mText; - - public NotificationsViewModel() { - mText = new MutableLiveData<>(); - mText.setValue("This is notifications fragment"); - } - - public LiveData getText() { - return mText; - } -} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/ui/video/VideoListFragment.java b/app/src/main/java/app/fedilab/fedilabtube/ui/video/VideoListFragment.java deleted file mode 100644 index eb7fb44..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/ui/video/VideoListFragment.java +++ /dev/null @@ -1,87 +0,0 @@ -package app.fedilab.fedilabtube.ui.video; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.AsyncTask; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.Observer; -import androidx.lifecycle.ViewModelProviders; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import app.fedilab.fedilabtube.R; -import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask; -import app.fedilab.fedilabtube.client.entities.Peertube; - -public class VideoListFragment extends Fragment { - - private VideoListModel videoListModel; - private LinearLayoutManager mLayoutManager; - private boolean flag_loading; - private Context context; - private AsyncTask asyncTask; - private PeertubeAdapter peertubeAdapater; - private String max_id; - private List peertubes; - private RetrieveFeedsAsyncTask.Type type; - private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; - private boolean firstLoad; - private SwipeRefreshLayout swipeRefreshLayout; - private String targetedId; - private String tag; - private RecyclerView lv_status; - private boolean showMediaOnly, showPinned, showReply; - private Intent streamingFederatedIntent, streamingLocalIntent; - private boolean firstTootsLoaded; - private String userId, instance; - private SharedPreferences sharedpreferences; - private boolean isSwipped; - private String remoteInstance; - private String instanceType; - private String search_peertube, remote_channel_name; - private String initialBookMark; - private String updatedBookMark; - private String lastReadToot; - private TextView textviewNoActionText; - private boolean ischannel; - private boolean ownVideos; - private BroadcastReceiver receive_action; - private BroadcastReceiver receive_data; - private Date lastReadTootDate, initialBookMarkDate, updatedBookMarkDate; - private int timelineId; - private String currentfilter; - private View rootView; - public View onCreateView(@NonNull LayoutInflater inflater, - ViewGroup container, Bundle savedInstanceState) { - videoListModel = - ViewModelProviders.of(this).get(VideoListModel.class); - View root = inflater.inflate(R.layout.fragment_video, container, false); - final TextView textView = root.findViewById(R.id.text_home); - - peertubes = new ArrayList<>(); - - videoListModel.getText().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(@Nullable String s) { - textView.setText(s); - } - }); - return root; - } -} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/ui/video/VideoListModel.java b/app/src/main/java/app/fedilab/fedilabtube/ui/video/VideoListModel.java deleted file mode 100644 index 3a69e73..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/ui/video/VideoListModel.java +++ /dev/null @@ -1,19 +0,0 @@ -package app.fedilab.fedilabtube.ui.video; - -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; - -public class VideoListModel extends ViewModel { - - private MutableLiveData mText; - - public VideoListModel() { - mText = new MutableLiveData<>(); - mText.setValue("This is home fragment"); - } - - public LiveData getText() { - return mText; - } -} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/webview/MastalabWebViewClient.java b/app/src/main/java/app/fedilab/fedilabtube/webview/MastalabWebViewClient.java index e7b7516..daae8af 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/webview/MastalabWebViewClient.java +++ b/app/src/main/java/app/fedilab/fedilabtube/webview/MastalabWebViewClient.java @@ -14,18 +14,14 @@ import android.widget.TextView; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; -import java.util.ArrayList; -import java.util.List; - import app.fedilab.fedilabtube.R; public class MastalabWebViewClient extends WebViewClient { - public List domains = new ArrayList<>(); private Activity activity; - private int count = 0; + public MastalabWebViewClient(Activity activity) { this.activity = activity; @@ -37,11 +33,6 @@ public class MastalabWebViewClient extends WebViewClient { } - public List getDomains() { - return this.domains; - } - - @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (URLUtil.isNetworkUrl(url)) { @@ -56,9 +47,6 @@ public class MastalabWebViewClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); - count = 0; - domains = new ArrayList<>(); - domains.clear(); ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar(); LayoutInflater mInflater = LayoutInflater.from(activity); if (actionBar != null) { diff --git a/app/src/main/res/drawable/ic_baseline_bookmark_24.xml b/app/src/main/res/drawable/ic_baseline_bookmark_24.xml new file mode 100644 index 0000000..7e480e2 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_bookmark_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_bookmark_border_24.xml b/app/src/main/res/drawable/ic_baseline_bookmark_border_24.xml new file mode 100644 index 0000000..61dc4cf --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_bookmark_border_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_check_24.xml b/app/src/main/res/drawable/ic_baseline_check_24.xml new file mode 100644 index 0000000..0432fa6 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_check_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_close_24.xml b/app/src/main/res/drawable/ic_baseline_close_24.xml new file mode 100644 index 0000000..16d6d37 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_close_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_fullscreen_24.xml b/app/src/main/res/drawable/ic_baseline_fullscreen_24.xml new file mode 100644 index 0000000..804cebc --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_fullscreen_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_fullscreen_exit_24.xml b/app/src/main/res/drawable/ic_baseline_fullscreen_exit_24.xml new file mode 100644 index 0000000..1efbe0a --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_fullscreen_exit_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_thumb_down_alt_24.xml b/app/src/main/res/drawable/ic_baseline_thumb_down_alt_24.xml new file mode 100644 index 0000000..ccd0921 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_thumb_down_alt_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_thumb_up_alt_24.xml b/app/src/main/res/drawable/ic_baseline_thumb_up_alt_24.xml new file mode 100644 index 0000000..11d7f2f --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_thumb_up_alt_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_peertube.xml b/app/src/main/res/layout/activity_peertube.xml new file mode 100644 index 0000000..6839465 --- /dev/null +++ b/app/src/main/res/layout/activity_peertube.xml @@ -0,0 +1,302 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_peertube_edit.xml b/app/src/main/res/layout/activity_peertube_edit.xml new file mode 100644 index 0000000..b650fe1 --- /dev/null +++ b/app/src/main/res/layout/activity_peertube_edit.xml @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +