From 43d8f6e5ffc18cb5fd07e46de42728c487ffebd9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 8 May 2020 18:52:19 +0200 Subject: Add support button --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fa54ae20b..7ba373c84 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { defaultConfig { minSdkVersion 19 targetSdkVersion 29 - versionCode 365 - versionName "2.35.2" + versionCode 366 + versionName "2.35.3" multiDexEnabled true renderscriptTargetApi 28 as int renderscriptSupportModeEnabled true -- cgit v1.2.3 From 6dab48af0c86f758800ac92aa69af6bb99fcb708 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 9 May 2020 12:29:44 +0200 Subject: Fix corgidon support --- app/src/main/java/app/fedilab/android/client/API.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index 43007d129..b49b2b44c 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -2205,6 +2205,9 @@ public class API { JSONObject resobj = new JSONObject(response); JSONObject jsonObject = resobj.getJSONObject("software"); String name = jsonObject.getString("name").toUpperCase(); + if( name.compareTo("CORGIDON") == 0 ){ + name = "MASTODON"; + } instanceNodeInfo.setName(name); instanceNodeInfo.setVersion(jsonObject.getString("version")); instanceNodeInfo.setOpenRegistrations(resobj.getBoolean("openRegistrations")); -- cgit v1.2.3 From 8914ac7c3270d0b29890afd305299fae23fde577 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 10 May 2020 11:19:22 +0200 Subject: some changes --- app/build.gradle | 4 +-- .../main/java/app/fedilab/android/client/API.java | 3 ++ .../fedilab/android/client/Entities/Status.java | 27 +++++++++++++++ .../fedilab/android/drawers/StatusListAdapter.java | 4 ++- .../java/app/fedilab/android/helper/Helper.java | 39 ++++++++++++---------- 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6e554190e..5d3fd286a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 29 - buildToolsVersion "29.0.2" + buildToolsVersion "29.0.3" defaultConfig { minSdkVersion 19 targetSdkVersion 29 @@ -87,7 +87,7 @@ dependencies { } annotationProcessor "com.github.bumptech.glide:compiler:4.11.0" annotationProcessor 'com.android.support:support-annotations:28.0.0' - implementation "org.conscrypt:conscrypt-android:2.2.1" + implementation "org.conscrypt:conscrypt-android:2.4.0" implementation "com.evernote:android-job:1.2.6" implementation "com.google.code.gson:gson:2.8.5" implementation "com.google.guava:guava:28.2-android" diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index 9d48bac3a..dd1014435 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -2195,6 +2195,9 @@ public class API { JSONObject resobj = new JSONObject(response); JSONObject jsonObject = resobj.getJSONObject("software"); String name = jsonObject.getString("name").toUpperCase(); + if( name.compareTo("CORGIDON") == 0 ){ + name = "MASTODON"; + } instanceNodeInfo.setName(name); instanceNodeInfo.setVersion(jsonObject.getString("version")); instanceNodeInfo.setOpenRegistrations(resobj.getBoolean("openRegistrations")); diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Status.java b/app/src/main/java/app/fedilab/android/client/Entities/Status.java index cee832d47..183203e85 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/Status.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/Status.java @@ -309,6 +309,33 @@ public class Status implements Parcelable { } } + matcher = Helper.ouichesPattern.matcher(content); + + while (matcher.find()) { + Attachment attachment = new Attachment(); + attachment.setType("audio"); + String tag = matcher.group(1); + attachment.setId(tag); + if( tag == null){ + continue; + } + attachment.setRemote_url("https://ouich.es/mp3/"+tag+".mp3"); + attachment.setUrl("https://ouich.es/mp3/"+tag+".mp3"); + if( status.getMedia_attachments() == null) { + status.setMedia_attachments(new ArrayList<>()); + } + boolean alreadyAdded = false; + for(Attachment at: status.getMedia_attachments()){ + if( tag.compareTo(at.getId()) == 0 ){ + alreadyAdded = true; + break; + } + } + if( !alreadyAdded) { + status.getMedia_attachments().add(attachment); + } + } + Pattern aLink = Pattern.compile("]*(((?!"); Matcher matcherALink = aLink.matcher(content); int count = 0; diff --git a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java index 940633362..72c882333 100644 --- a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java @@ -607,9 +607,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct @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); - context = viewHolder.itemView.getContext(); + if (viewHolder.getItemViewType() != HIDDEN_STATUS) { final ViewHolder holder = (ViewHolder) viewHolder; diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 1816699de..83aa1107e 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -518,6 +518,7 @@ public class Helper { public static final Pattern twitterPattern = Pattern.compile("((@[\\w]+)@twitter\\.com)"); public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)"); public static final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)"); + public static final Pattern ouichesPattern = Pattern.compile("ouich\\.es/tag/(\\w+)"); public static final Pattern xmppPattern = Pattern.compile("xmpp:[-a-zA-Z0-9+$&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"); //Default values public final static int DEFAULT_VIDEO_WIDTH = 640; @@ -1927,27 +1928,30 @@ public class Helper { } if (!urlHeader.contains("missing.png")) { ImageView backgroundImage = headerLayout.findViewById(R.id.back_ground_image); - Glide.with(activity) - .asDrawable() - .load(urlHeader) - .into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Drawable resource, Transition transition) { - - backgroundImage.setImageDrawable(resource); - if (theme == THEME_LIGHT) { - backgroundImage.setImageAlpha(80); - } else { - backgroundImage.setImageAlpha(60); + if( isValidContextForGlide(activity)){ + Glide.with(activity) + .asDrawable() + .load(urlHeader) + .into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Drawable resource, Transition transition) { + + backgroundImage.setImageDrawable(resource); + if (theme == THEME_LIGHT) { + backgroundImage.setImageAlpha(80); + } else { + backgroundImage.setImageAlpha(60); + } + } - } + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { + } + }); + } - } - }); } } profilePicture.setOnClickListener(null); @@ -3210,6 +3214,7 @@ public class Helper { } } else { Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(url)); try { context.startActivity(intent); -- cgit v1.2.3 From 853286fa1a8988dce32debf52b424124e12def1f Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 10 May 2020 14:22:25 +0200 Subject: ouiches support --- app/src/main/java/app/fedilab/android/client/Entities/Status.java | 4 ++-- app/src/main/java/app/fedilab/android/helper/Helper.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Status.java b/app/src/main/java/app/fedilab/android/client/Entities/Status.java index bfc01b740..9a6a00000 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/Status.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/Status.java @@ -320,8 +320,8 @@ public class Status implements Parcelable { if( tag == null){ continue; } - attachment.setRemote_url("https://ouich.es/mp3/"+tag+".mp3"); - attachment.setUrl("https://ouich.es/mp3/"+tag+".mp3"); + attachment.setRemote_url("http://ouich.es/mp3/"+tag+".mp3"); + attachment.setUrl("http://ouich.es/mp3/"+tag+".mp3"); if( status.getMedia_attachments() == null) { status.setMedia_attachments(new ArrayList<>()); } diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index ceeae75c7..c95fb25f6 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -512,6 +512,7 @@ public class Helper { public static final Pattern twitterPattern = Pattern.compile("((@[\\w]+)@twitter\\.com)"); public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)"); public static final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)"); + public static final Pattern ouichesPattern = Pattern.compile("https://ouich\\.es/tag/(\\w+)"); public static final Pattern xmppPattern = Pattern.compile("xmpp:[-a-zA-Z0-9+$&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"); //Default values public final static int DEFAULT_VIDEO_WIDTH = 640; -- cgit v1.2.3 From 236f8e5f6f69d8b19cbd21ca2fe50113b68c4d3d Mon Sep 17 00:00:00 2001 From: Ash <> Date: Fri, 15 May 2020 04:39:50 +0530 Subject: Fix: unblock option not working in account activity's menu --- .../java/app/fedilab/android/activities/ShowAccountActivity.java | 9 +++++++-- app/src/main/res/values/strings.xml | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java index bb39b6732..96edc6d7b 100644 --- a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java @@ -1330,8 +1330,13 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt return true; case R.id.action_block: builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); - builderInner.setTitle(stringArrayConf[1]); - doActionAccount = API.StatusAction.BLOCK; + if (relationship.isBlocking()) { + builderInner.setTitle(stringArrayConf[5]); + doActionAccount = API.StatusAction.UNBLOCK; + } else { + builderInner.setTitle(stringArrayConf[1]); + doActionAccount = API.StatusAction.BLOCK; + } break; case R.id.action_block_instance: builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b0a84b134..202aadd38 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -115,6 +115,7 @@ Report this toot? Block this domain? Unmute this account? + Unblock this account? -- cgit v1.2.3 From d5ef4f05a1506d85481ef68d1198fd471782c055 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 16 May 2020 11:12:49 +0200 Subject: copy release notes --- .../main/java/app/fedilab/android/helper/CacheDataSourceFactory.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 app/src/main/java/app/fedilab/android/helper/CacheDataSourceFactory.java diff --git a/app/src/main/java/app/fedilab/android/helper/CacheDataSourceFactory.java b/app/src/main/java/app/fedilab/android/helper/CacheDataSourceFactory.java new file mode 100644 index 000000000..71012f898 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/helper/CacheDataSourceFactory.java @@ -0,0 +1,4 @@ +package app.fedilab.android.helper; + +public class CacheDataSourceFactory { +} -- cgit v1.2.3 From dd26a6aeb50f8f18c6e5080b1e6097361fca6fe0 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 16 May 2020 11:32:09 +0200 Subject: video cache --- .../android/activities/BaseMainActivity.java | 10 +- .../android/activities/PeertubeActivity.java | 134 +++++++++++-------- .../android/activities/SettingsActivity.java | 2 +- .../android/activities/WebviewConnectActivity.java | 2 +- .../DownloadTrackingDomainsAsyncTask.java | 1 - .../main/java/app/fedilab/android/client/API.java | 20 +-- .../android/client/Entities/ManageTimelines.java | 9 +- .../fedilab/android/client/Entities/Status.java | 55 +++++--- .../fedilab/android/drawers/StatusListAdapter.java | 11 +- .../android/fragments/ColorSettingsFragment.java | 2 +- .../android/fragments/ContentSettingsFragment.java | 148 +++++++++++++++------ .../android/fragments/MediaSliderFragment.java | 32 +++-- .../android/helper/CacheDataSourceFactory.java | 48 ++++++- .../java/app/fedilab/android/helper/Helper.java | 31 +++-- .../app/fedilab/android/helper/ThemeHelper.java | 23 ++-- .../android/imageeditor/ColorPickerAdapter.java | 22 +-- .../android/imageeditor/EmojiBSFragment.java | 16 +-- .../android/imageeditor/PropertiesBSFragment.java | 11 +- .../android/imageeditor/StickerBSFragment.java | 18 ++- .../imageeditor/TextEditorDialogFragment.java | 61 ++++----- .../imageeditor/tools/EditingToolsAdapter.java | 9 +- .../BackupNotificationInDataBaseService.java | 27 ++-- .../services/BackupStatusInDataBaseService.java | 27 ++-- .../android/services/BackupStatusService.java | 22 +-- .../services/LiveNotificationDelayedService.java | 65 +++++---- .../android/services/LiveNotificationService.java | 1 - .../StreamingFederatedTimelineService.java | 43 +++--- .../services/StreamingHomeTimelineService.java | 43 +++--- .../services/StreamingLocalTimelineService.java | 41 +++--- .../app/fedilab/android/sqlite/DomainBlockDAO.java | 3 +- .../res/layout-sw600dp/activity_show_account.xml | 14 +- app/src/main/res/layout-sw600dp/drawer_account.xml | 14 +- app/src/main/res/layout/activity_edit_profile.xml | 2 +- app/src/main/res/layout/activity_login.xml | 10 +- .../res/layout/activity_manage_accounts_list.xml | 2 +- app/src/main/res/layout/activity_peertube.xml | 2 +- .../main/res/layout/activity_peertube_upload.xml | 2 +- app/src/main/res/layout/activity_show_account.xml | 14 +- app/src/main/res/layout/add_blocked_instance.xml | 2 +- app/src/main/res/layout/add_filter.xml | 2 +- app/src/main/res/layout/add_list.xml | 2 +- app/src/main/res/layout/add_playlist.xml | 2 +- app/src/main/res/layout/dialog_create_folder.xml | 2 +- app/src/main/res/layout/dialog_profile.xml | 2 +- app/src/main/res/layout/domains_blocked.xml | 2 +- app/src/main/res/layout/drawer_account.xml | 14 +- app/src/main/res/layout/drawer_account_admin.xml | 8 +- .../res/layout/drawer_account_follow_request.xml | 4 +- app/src/main/res/layout/drawer_account_list.xml | 4 +- .../main/res/layout/drawer_account_main_search.xml | 12 +- app/src/main/res/layout/drawer_account_reply.xml | 2 +- app/src/main/res/layout/drawer_account_search.xml | 4 +- app/src/main/res/layout/drawer_emoji_search.xml | 3 +- app/src/main/res/layout/drawer_notification.xml | 4 +- app/src/main/res/layout/drawer_report.xml | 6 +- app/src/main/res/layout/drawer_status.xml | 19 ++- app/src/main/res/layout/drawer_status_compact.xml | 18 +-- app/src/main/res/layout/drawer_status_console.xml | 20 +-- app/src/main/res/layout/drawer_status_focused.xml | 20 +-- .../main/res/layout/drawer_status_main_search.xml | 6 +- app/src/main/res/layout/drawer_suggestions.xml | 2 +- app/src/main/res/layout/filter_regex.xml | 2 +- .../main/res/layout/fragment_settings_reveal.xml | 94 +++++++++++-- app/src/main/res/layout/fragment_slide_media.xml | 2 +- app/src/main/res/layout/nav_header_main.xml | 2 +- app/src/main/res/layout/popup_contact.xml | 3 +- app/src/main/res/layout/search_instance.xml | 2 +- app/src/main/res/layout/search_toot.xml | 2 +- app/src/main/res/layout/simple_bar.xml | 2 +- app/src/main/res/layout/simple_bar_add.xml | 2 +- .../main/res/layout/simple_bar_muted_instance.xml | 2 +- app/src/main/res/layout/simple_bar_search.xml | 2 +- app/src/main/res/layout/tags_all.xml | 2 +- app/src/main/res/layout/tags_any.xml | 2 +- app/src/main/res/layout/tags_instance.xml | 2 +- app/src/main/res/layout/tags_name.xml | 2 +- app/src/main/res/layout/webview_actionbar.xml | 2 +- app/src/main/res/values/strings.xml | 6 + 78 files changed, 741 insertions(+), 547 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java index c1928b179..f22ff876b 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java @@ -1258,7 +1258,7 @@ public abstract class BaseMainActivity extends BaseActivity int lastReleaseNoteRead = sharedpreferences.getInt(Helper.SET_POPUP_RELEASE_NOTES, 0); int versionCode = BuildConfig.VERSION_CODE; - if (lastReleaseNoteRead != versionCode ) { //Need to push release notes + if (lastReleaseNoteRead != versionCode) { //Need to push release notes if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { new RetrieveRemoteDataAsyncTask(BaseMainActivity.this, BaseMainActivity.this).execute(); } @@ -1279,12 +1279,12 @@ public abstract class BaseMainActivity extends BaseActivity Button liberapay_support = dialogReleaseNoteView.findViewById(R.id.liberapay_support); release_title.setText(getString(R.string.release_note_title, BuildConfig.VERSION_NAME)); release_notes.setText(finalContent); - if( BuildConfig.DONATIONS) { + if (BuildConfig.DONATIONS) { liberapay_support.setVisibility(View.VISIBLE); - }else{ + } else { liberapay_support.setVisibility(View.GONE); } - liberapay_support.setOnClickListener(v->{ + liberapay_support.setOnClickListener(v -> { Intent intentLiberapay = new Intent(Intent.ACTION_VIEW); intentLiberapay.setData(Uri.parse("https://liberapay.com/tom79")); try { @@ -1693,7 +1693,7 @@ public abstract class BaseMainActivity extends BaseActivity } }); } - if( trackingDomains != null){ + if (trackingDomains != null) { trackingDomains = null; } if (hidde_menu != null) diff --git a/app/src/main/java/app/fedilab/android/activities/PeertubeActivity.java b/app/src/main/java/app/fedilab/android/activities/PeertubeActivity.java index c188ecc4e..7d67984e1 100644 --- a/app/src/main/java/app/fedilab/android/activities/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/PeertubeActivity.java @@ -60,10 +60,10 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.SimpleExoPlayer; -import com.google.android.exoplayer2.source.ExtractorMediaSource; +import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; -import com.google.android.exoplayer2.ui.PlaybackControlView; -import com.google.android.exoplayer2.ui.SimpleExoPlayerView; +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.util.Util; @@ -96,6 +96,7 @@ import app.fedilab.android.client.Entities.Status; import app.fedilab.android.client.Entities.StatusDrawerParams; import app.fedilab.android.client.TLSSocketFactory; import app.fedilab.android.drawers.StatusListAdapter; +import app.fedilab.android.helper.CacheDataSourceFactory; import app.fedilab.android.helper.CrossActions; import app.fedilab.android.helper.FullScreenMediaController; import app.fedilab.android.helper.Helper; @@ -130,7 +131,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube private ScrollView peertube_information_container; private Peertube peertube; private TextView toolbar_title; - private SimpleExoPlayerView playerView; + private PlayerView playerView; private SimpleExoPlayer player; private boolean fullScreenMode; private Dialog fullScreenDialog; @@ -278,7 +279,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube peertube_information_container.setVisibility(View.VISIBLE); } }); - String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, null); + String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); if (user_agent != null) { webview_video.getSettings().setUserAgentString(user_agent); } @@ -369,40 +370,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube 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 AsyncTask() { - - private List remoteStatuses; - private WeakReference contextReference = new WeakReference<>(PeertubeActivity.this); - - @Override - protected Void doInBackground(Void... voids) { - - 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(); - } - } - return null; - } - - @Override - protected void onPostExecute(Void result) { - Intent intent = new Intent(contextReference.get(), TootActivity.class); - Bundle b = new Bundle(); - if (remoteStatuses == null || remoteStatuses.size() == 0) { - Toasty.error(contextReference.get(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show(); - return; - } - if (remoteStatuses.get(0).getReblog() != null) { - b.putParcelable("tootReply", remoteStatuses.get(0).getReblog()); - } else { - b.putParcelable("tootReply", remoteStatuses.get(0)); - } - intent.putExtras(b); //Put your id to your next Intent - contextReference.get().startActivity(intent); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + 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(); @@ -443,6 +411,52 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube } } + 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); //Put your id to your next Intent + contextReference.get().startActivity(intent); + } + } + + public FullScreenMediaController.fullscreen getFullscreen() { return fullscreen; } @@ -583,16 +597,24 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube if (mode == Helper.VIDEO_MODE_DIRECT) { - DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this, - Util.getUserAgent(PeertubeActivity.this, "Mastalab"), null); - ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory) - .createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService()))); + String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); + int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB); + ProgressiveMediaSource videoSource; + if( video_cache == 0) { + DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this, + Util.getUserAgent(PeertubeActivity.this, userAgent), null); + videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) + .createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService()))); + }else{ + CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this, video_cache * 1024 * 1024, 5 * 1024 * 1024); + videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) + .createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService()))); + } player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this); playerView.setPlayer(player); loader.setVisibility(View.GONE); - player.prepare(videoSource); player.setPlayWhenReady(true); } @@ -777,7 +799,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube if (playerView != null) { loader.setVisibility(View.VISIBLE); long position = player.getCurrentPosition(); - PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller); + PlayerControlView controlView = playerView.findViewById(R.id.exo_controller); resolution = controlView.findViewById(R.id.resolution); resolution.setText(String.format("%sp", res)); if (mode == Helper.VIDEO_MODE_DIRECT) { @@ -786,11 +808,19 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this); playerView.setPlayer(player); loader.setVisibility(View.GONE); - DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this, - Util.getUserAgent(PeertubeActivity.this, "Mastalab"), null); - - ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory) - .createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService()))); + String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); + int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB); + ProgressiveMediaSource videoSource; + if( video_cache == 0) { + DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this, + Util.getUserAgent(PeertubeActivity.this, userAgent), null); + videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) + .createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService()))); + }else{ + CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this, video_cache * 1024 * 1024, 5 * 1024 * 1024); + videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) + .createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService()))); + } player.prepare(videoSource); player.seekTo(0, position); player.setPlayWhenReady(true); @@ -842,7 +872,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube private void initFullscreenButton() { - PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller); + PlayerControlView controlView = playerView.findViewById(R.id.exo_controller); fullScreenIcon = controlView.findViewById(R.id.exo_fullscreen_icon); View fullScreenButton = controlView.findViewById(R.id.exo_fullscreen_button); fullScreenButton.setOnClickListener(v -> { @@ -854,7 +884,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube } private void initResolution() { - PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller); + PlayerControlView controlView = playerView.findViewById(R.id.exo_controller); resolution = controlView.findViewById(R.id.resolution); resolution.setText(String.format("%sp", peertube.getResolution().get(0))); resolution.setOnClickListener(v -> displayResolution()); diff --git a/app/src/main/java/app/fedilab/android/activities/SettingsActivity.java b/app/src/main/java/app/fedilab/android/activities/SettingsActivity.java index 55495958c..9be6379ca 100644 --- a/app/src/main/java/app/fedilab/android/activities/SettingsActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/SettingsActivity.java @@ -154,7 +154,7 @@ public class SettingsActivity extends BaseActivity { } @Override - public void onDestroy(){ + public void onDestroy() { super.onDestroy(); } diff --git a/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java b/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java index c920816e1..f360dcc3c 100644 --- a/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java @@ -125,7 +125,7 @@ public class WebviewConnectActivity extends BaseActivity { webView = findViewById(R.id.webviewConnect); clearCookies(WebviewConnectActivity.this); webView.getSettings().setJavaScriptEnabled(true); - String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, null); + String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); if (user_agent != null) { webView.getSettings().setUserAgentString(user_agent); } diff --git a/app/src/main/java/app/fedilab/android/asynctasks/DownloadTrackingDomainsAsyncTask.java b/app/src/main/java/app/fedilab/android/asynctasks/DownloadTrackingDomainsAsyncTask.java index e1ad99c1b..8dfb2132f 100644 --- a/app/src/main/java/app/fedilab/android/asynctasks/DownloadTrackingDomainsAsyncTask.java +++ b/app/src/main/java/app/fedilab/android/asynctasks/DownloadTrackingDomainsAsyncTask.java @@ -33,7 +33,6 @@ import java.util.List; import javax.net.ssl.HttpsURLConnection; import app.fedilab.android.R; -import app.fedilab.android.helper.Helper; import app.fedilab.android.sqlite.DomainBlockDAO; import app.fedilab.android.sqlite.Sqlite; import es.dmoral.toasty.Toasty; diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index b49b2b44c..312dec3ac 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -2205,7 +2205,7 @@ public class API { JSONObject resobj = new JSONObject(response); JSONObject jsonObject = resobj.getJSONObject("software"); String name = jsonObject.getString("name").toUpperCase(); - if( name.compareTo("CORGIDON") == 0 ){ + if (name.compareTo("CORGIDON") == 0) { name = "MASTODON"; } instanceNodeInfo.setName(name); @@ -3699,14 +3699,16 @@ public class API { if (apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0) { for (Status status : apiResponse.getStatuses()) { if (status.getMedia_attachments() != null) { - String statusSerialized = Helper.statusToStringStorage(status); - for (Attachment attachment : status.getMedia_attachments()) { - Status newStatus = Helper.restoreStatusFromString(statusSerialized); - if (newStatus == null) - break; - newStatus.setArt_attachment(attachment); - apiResponseReply.getStatuses().add(newStatus); - } + try { + String statusSerialized = Helper.statusToStringStorage(status); + for (Attachment attachment : status.getMedia_attachments()) { + Status newStatus = Helper.restoreStatusFromString(statusSerialized); + if (newStatus == null) + break; + newStatus.setArt_attachment(attachment); + apiResponseReply.getStatuses().add(newStatus); + } + }catch (Exception ignored){} } } } diff --git a/app/src/main/java/app/fedilab/android/client/Entities/ManageTimelines.java b/app/src/main/java/app/fedilab/android/client/Entities/ManageTimelines.java index fb2ec3b98..a59f94d7d 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/ManageTimelines.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/ManageTimelines.java @@ -500,10 +500,11 @@ public class ManageTimelines { if (mPageReferenceMap != null) { FragmentTransaction fragTransaction = ((MainActivity) context).getSupportFragmentManager().beginTransaction(); DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition()); - assert displayStatusFragment != null; - fragTransaction.detach(displayStatusFragment); - fragTransaction.attach(displayStatusFragment); - fragTransaction.commit(); + if (displayStatusFragment != null) { + fragTransaction.detach(displayStatusFragment); + fragTransaction.attach(displayStatusFragment); + fragTransaction.commit(); + } } } }); diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Status.java b/app/src/main/java/app/fedilab/android/client/Entities/Status.java index 9a6a00000..edd0862c5 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/Status.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/Status.java @@ -310,31 +310,42 @@ public class Status implements Parcelable { } } + matcher = Helper.bibliogramPattern.matcher(content); + boolean bibliogram = sharedpreferences.getBoolean(Helper.SET_BIBLIOGRAM, false); + if (bibliogram) { + while (matcher.find()) { + final String bibliogram_directory = matcher.group(2); + String bibliogramHost = sharedpreferences.getString(Helper.SET_BIBLIOGRAM_HOST, Helper.DEFAULT_BIBLIOGRAM_HOST).toLowerCase(); + content = content.replaceAll("https://" + Pattern.quote(matcher.group()), Matcher.quoteReplacement("https://" + bibliogramHost + bibliogram_directory)); + content = content.replaceAll(">" + Pattern.quote(matcher.group()), Matcher.quoteReplacement(">" + bibliogramHost + bibliogram_directory)); + } + } + matcher = Helper.ouichesPattern.matcher(content); while (matcher.find()) { - Attachment attachment = new Attachment(); - attachment.setType("audio"); - String tag = matcher.group(1); - attachment.setId(tag); - if( tag == null){ - continue; - } - attachment.setRemote_url("http://ouich.es/mp3/"+tag+".mp3"); - attachment.setUrl("http://ouich.es/mp3/"+tag+".mp3"); - if( status.getMedia_attachments() == null) { - status.setMedia_attachments(new ArrayList<>()); - } - boolean alreadyAdded = false; - for(Attachment at: status.getMedia_attachments()){ - if( tag.compareTo(at.getId()) == 0 ){ - alreadyAdded = true; - break; - } - } - if( !alreadyAdded) { - status.getMedia_attachments().add(attachment); - } + Attachment attachment = new Attachment(); + attachment.setType("audio"); + String tag = matcher.group(1); + attachment.setId(tag); + if (tag == null) { + continue; + } + attachment.setRemote_url("http://ouich.es/mp3/" + tag + ".mp3"); + attachment.setUrl("http://ouich.es/mp3/" + tag + ".mp3"); + if (status.getMedia_attachments() == null) { + status.setMedia_attachments(new ArrayList<>()); + } + boolean alreadyAdded = false; + for (Attachment at : status.getMedia_attachments()) { + if (tag.compareTo(at.getId()) == 0) { + alreadyAdded = true; + break; + } + } + if (!alreadyAdded) { + status.getMedia_attachments().add(attachment); + } } Pattern aLink = Pattern.compile("]*(((?!"); diff --git a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java index a23d15d46..7af1c7045 100644 --- a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java @@ -2289,6 +2289,15 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct url = url.replaceAll("https://" + Pattern.quote(matcher.group()), Matcher.quoteReplacement("https://" + nitterHost + nitter_directory)); } } + boolean bibliogram = sharedpreferences.getBoolean(Helper.SET_BIBLIOGRAM, false); + if (bibliogram) { + Matcher matcher = Helper.bibliogramPattern.matcher(url); + while (matcher.find()) { + final String bibliogram_directory = matcher.group(2); + String bibliogramHost = sharedpreferences.getString(Helper.SET_BIBLIOGRAM_HOST, Helper.DEFAULT_BIBLIOGRAM_HOST).toLowerCase(); + url = url.replaceAll("https://" + Pattern.quote(matcher.group()), Matcher.quoteReplacement("https://" + bibliogramHost + bibliogram_directory)); + } + } Helper.openBrowser(context, url); }); } else if (card.getType().toLowerCase().equals("video") && (display_video_preview || (type == RetrieveFeedsAsyncTask.Type.CONTEXT && viewHolder.getAdapterPosition() == conversationPosition))) { @@ -2298,7 +2307,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct .into(holder.webview_preview_card); holder.status_cardview.setVisibility(View.GONE); holder.status_cardview_video.setVisibility(View.VISIBLE); - String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, null); + String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); if (user_agent != null) { holder.status_cardview_webview.getSettings().setUserAgentString(user_agent); } diff --git a/app/src/main/java/app/fedilab/android/fragments/ColorSettingsFragment.java b/app/src/main/java/app/fedilab/android/fragments/ColorSettingsFragment.java index 7dcbe3ad7..a94eadc63 100644 --- a/app/src/main/java/app/fedilab/android/fragments/ColorSettingsFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/ColorSettingsFragment.java @@ -275,7 +275,7 @@ public class ColorSettingsFragment extends PreferenceFragmentCompat implements S entryValues[2] = String.valueOf(Helper.THEME_BLACK); pref_theme_picker.setEntries(entries); int default_theme_value; - switch (theme){ + switch (theme) { case Helper.THEME_LIGHT: default_theme_value = 1; break; diff --git a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java index c421d3db7..d8c00e20e 100644 --- a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java @@ -15,6 +15,7 @@ package app.fedilab.android.fragments; * see . */ +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.TimePickerDialog; import android.content.ComponentName; @@ -54,7 +55,6 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.SwitchCompat; import androidx.fragment.app.Fragment; @@ -345,6 +345,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot } context = getActivity(); + assert context != null; SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); @@ -468,9 +469,9 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot Button update_tracking_domains = rootView.findViewById(R.id.update_tracking_domains); - update_tracking_domains.setOnClickListener(v -> { - new DownloadTrackingDomainsAsyncTask(Objects.requireNonNull(getActivity()), update_tracking_domains).execute(); - }); + update_tracking_domains.setOnClickListener(v -> + new DownloadTrackingDomainsAsyncTask(Objects.requireNonNull(getActivity()), update_tracking_domains).execute() + ); Spinner set_attachment_group = rootView.findViewById(R.id.set_attachment_group); @@ -837,7 +838,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot TextView set_user_agent = rootView.findViewById(R.id.set_user_agent); - String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, null); + String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); if (user_agent != null) { set_user_agent.setText(user_agent); @@ -922,6 +923,55 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot } }); + + TextView set_bibliogram_host = rootView.findViewById(R.id.set_bibliogram_host); + boolean bibliogram = sharedpreferences.getBoolean(Helper.SET_BIBLIOGRAM, false); + final SwitchCompat set_bibliogram = rootView.findViewById(R.id.set_bibliogram); + set_bibliogram.setChecked(bibliogram); + + set_bibliogram.setOnClickListener(v -> { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_BIBLIOGRAM, set_bibliogram.isChecked()); + editor.apply(); + if (set_bibliogram.isChecked()) { + set_bibliogram_host.setVisibility(View.VISIBLE); + } else { + set_bibliogram_host.setVisibility(View.GONE); + } + }); + if (bibliogram) { + set_bibliogram_host.setVisibility(View.VISIBLE); + } else { + set_bibliogram_host.setVisibility(View.GONE); + } + + String bibliogramHost = sharedpreferences.getString(Helper.SET_BIBLIOGRAM_HOST, null); + if (bibliogramHost != null) { + set_bibliogram_host.setText(bibliogramHost); + } + set_bibliogram_host.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + if (s.toString().trim().length() > 0) { + editor.putString(Helper.SET_BIBLIOGRAM_HOST, s.toString().toLowerCase().trim()); + } else { + editor.putString(Helper.SET_BIBLIOGRAM_HOST, null); + } + editor.apply(); + } + }); + boolean long_press_media = sharedpreferences.getBoolean(Helper.SET_LONG_PRESS_MEDIA, true); final SwitchCompat set_long_press_media = rootView.findViewById(R.id.set_long_press_media); set_long_press_media.setChecked(long_press_media); @@ -976,6 +1026,32 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot getActivity().recreate(); }); + int video_cache_size = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB); + SeekBar set_video_cache_size = rootView.findViewById(R.id.set_video_cache_size); + set_video_cache_size.setMax(5*Helper.DEFAULT_VIDEO_CACHE_MB); + set_video_cache_size.setProgress(video_cache_size); + TextView set_video_cache = rootView.findViewById(R.id.set_video_cache); + set_video_cache.setText(String.valueOf(video_cache_size)); + set_video_cache_size.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + set_video_cache.setText(String.valueOf(progress)); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putInt(Helper.SET_VIDEO_CACHE, progress); + editor.apply(); + } + }); + + + int truncate_toots_size = sharedpreferences.getInt(Helper.SET_TRUNCATE_TOOTS_SIZE, 0); SeekBar set_truncate_size = rootView.findViewById(R.id.set_truncate_size); set_truncate_size.setMax(20); @@ -1543,40 +1619,37 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot final ArrayAdapter arrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, stringArray); dialog.setNegativeButton(R.string.cancel, (dialog1, position) -> dialog1.dismiss()); - dialog.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int position) { - String visibility = "public"; - - switch (position) { - case 0: - visibility = "public"; - set_toot_visibility.setImageResource(R.drawable.ic_public); - break; - case 1: - visibility = "unlisted"; - set_toot_visibility.setImageResource(R.drawable.ic_lock_open); - break; - case 2: - visibility = "private"; - set_toot_visibility.setImageResource(R.drawable.ic_lock_outline); - break; - case 3: - visibility = "direct"; - set_toot_visibility.setImageResource(R.drawable.ic_mail_outline); - break; - } - if (account != null) { - SharedPreferences.Editor editor = sharedpreferences12.edit(); - editor.putString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), visibility); - editor.apply(); - Toasty.info(context, context.getString(R.string.toast_visibility_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_SHORT).show(); - } else { - Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); - } + dialog.setAdapter(arrayAdapter, (dialog12, position) -> { + String visibility = "public"; - dialog.dismiss(); + switch (position) { + case 0: + visibility = "public"; + set_toot_visibility.setImageResource(R.drawable.ic_public); + break; + case 1: + visibility = "unlisted"; + set_toot_visibility.setImageResource(R.drawable.ic_lock_open); + break; + case 2: + visibility = "private"; + set_toot_visibility.setImageResource(R.drawable.ic_lock_outline); + break; + case 3: + visibility = "direct"; + set_toot_visibility.setImageResource(R.drawable.ic_mail_outline); + break; } + if (account != null) { + SharedPreferences.Editor editor = sharedpreferences12.edit(); + editor.putString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), visibility); + editor.apply(); + Toasty.info(context, context.getString(R.string.toast_visibility_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_SHORT).show(); + } else { + Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + } + + dialog12.dismiss(); }); dialog.show(); }); @@ -2175,6 +2248,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot set_change_locale.setSelection(positionSpinnerLanguage); countLanguage = 0; set_change_locale.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @SuppressLint("ApplySharedPref") @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { if (countLanguage > 0) { diff --git a/app/src/main/java/app/fedilab/android/fragments/MediaSliderFragment.java b/app/src/main/java/app/fedilab/android/fragments/MediaSliderFragment.java index 36e6e4313..1c963ba4a 100644 --- a/app/src/main/java/app/fedilab/android/fragments/MediaSliderFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/MediaSliderFragment.java @@ -51,8 +51,9 @@ import com.github.chrisbanes.photoview.PhotoView; import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; -import com.google.android.exoplayer2.source.ExtractorMediaSource; -import com.google.android.exoplayer2.ui.SimpleExoPlayerView; + +import com.google.android.exoplayer2.source.ProgressiveMediaSource; +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.util.Util; @@ -70,6 +71,7 @@ import app.fedilab.android.R; import app.fedilab.android.activities.SlideMediaActivity; import app.fedilab.android.client.Entities.Attachment; import app.fedilab.android.client.TLSSocketFactory; +import app.fedilab.android.helper.CacheDataSourceFactory; import app.fedilab.android.helper.Helper; import app.fedilab.android.webview.CustomWebview; import app.fedilab.android.webview.MastalabWebChromeClient; @@ -132,7 +134,7 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl ImageView next = rootView.findViewById(R.id.media_next); imageView = rootView.findViewById(R.id.media_picture); - SimpleExoPlayerView videoView = rootView.findViewById(R.id.media_video); + PlayerView videoView = rootView.findViewById(R.id.media_video); if (theme == Helper.THEME_BLACK) { changeDrawableColor(context, prev, R.color.dark_icon); changeDrawableColor(context, next, R.color.dark_icon); @@ -236,10 +238,20 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl } videoView.setVisibility(View.VISIBLE); Uri uri = Uri.parse(url); - DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, - Util.getUserAgent(context, "Fedilab"), null); - ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory) - .createMediaSource(uri); + + String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); + int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB); + ProgressiveMediaSource videoSource; + if( video_cache == 0) { + DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, + Util.getUserAgent(context, userAgent), null); + videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) + .createMediaSource(uri); + }else{ + CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(context, video_cache * 1024 * 1024, 5 * 1024 * 1024); + videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) + .createMediaSource(uri); + } player = ExoPlayerFactory.newSimpleInstance(context); if (type.toLowerCase().equals("gifv")) player.setRepeatMode(Player.REPEAT_MODE_ONE); @@ -278,7 +290,7 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl webview_video.setWebChromeClient(mastalabWebChromeClient); webview_video.getSettings().setDomStorageEnabled(true); webview_video.getSettings().setAppCacheEnabled(true); - String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, null); + String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); if (user_agent != null) { webview_video.getSettings().setUserAgentString(user_agent); } @@ -453,6 +465,10 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl } } catch (Exception ignored) { } + if (timer != null) { + timer.cancel(); + timer = null; + } super.onDestroy(); } diff --git a/app/src/main/java/app/fedilab/android/helper/CacheDataSourceFactory.java b/app/src/main/java/app/fedilab/android/helper/CacheDataSourceFactory.java index 71012f898..2ab4f83c0 100644 --- a/app/src/main/java/app/fedilab/android/helper/CacheDataSourceFactory.java +++ b/app/src/main/java/app/fedilab/android/helper/CacheDataSourceFactory.java @@ -1,4 +1,48 @@ package app.fedilab.android.helper; -public class CacheDataSourceFactory { -} +import android.content.Context; +import android.content.SharedPreferences; + +import com.google.android.exoplayer2.database.ExoDatabaseProvider; +import com.google.android.exoplayer2.upstr