From faac9cd676ba7db34ed4644b154ed446a6eb18a5 Mon Sep 17 00:00:00 2001 From: Abdul Mannan Saeed <111820160@umt.edu.pk> Date: Thu, 9 Feb 2023 12:55:22 +0500 Subject: [PATCH] Bug Fixes Bug Fixes --- .idea/deploymentTargetDropDown.xml | 17 + .safedk/hashes.safedk | 4 +- .safedk/plugin.properties | 2 +- app/build.gradle | 13 +- app/fabric.properties | 4 +- app/proguard-rules.pro | 41 +- .../appManager/activityContextManager.java | 2 +- .../advertManager/advertController.java | 2 +- .../advertManager/advertViewController.java | 2 +- .../bookmarkHome/bookmarkAdapter.java | 13 +- .../bookmarkHome/bookmarkAdapterView.java | 2 +- .../bookmarkHome/bookmarkController.java | 2 +- .../bookmarkHome/bookmarkViewController.java | 2 +- .../bookmarkSettingController.java | 2 +- .../bookmarkSettingViewController.java | 2 +- .../bridgeManager/bridgeController.java | 2 +- .../bridgeManager/bridgeViewController.java | 2 +- .../externalShortcutController.java | 2 +- .../externalURLNavigationContoller.java | 2 +- .../appManager/helpManager/helpAdapter.java | 2 +- .../helpManager/helpController.java | 2 +- .../helpManager/helpViewController.java | 2 +- .../historyManager/historyAdapter.java | 4 +- .../historyManager/historyAdapterView.java | 2 +- .../historyManager/historyController.java | 2 +- .../historyManager/historyViewController.java | 2 +- .../homeManager/geckoManager/config.yaml | 56 - .../dataModel/geckoDataModel.java | 13 + .../delegateModel/autofillDelegate.java | 57 + .../delegateModel/contentDelegate.java | 218 ++ .../delegateModel/historyDelegate.java | 76 + .../{ => delegateModel}/mediaDelegate.java | 260 +- .../delegateModel/mediaSessionDelegate.java | 124 + .../promptDelegate.java} | 2136 ++++++++--------- .../delegateModel/scrollDelegate.java | 51 + .../selectionDelegate.java} | 949 ++++---- .../geckoManager/geckoClients.java | 163 +- .../geckoManager/geckoDownloadManager.java | 10 +- .../geckoManager/geckoSession.java | 915 ++----- .../{ => helperClasses}/errorHandler.java | 358 +-- .../helperClasses/intentHandler.java | 14 + .../helperClasses/preferences.java | 37 + .../homeManager/hintManager/hintAdapter.java | 4 +- .../homeController/homeController.java | 50 +- .../homeController/homeViewController.java | 23 +- .../languageManager/languageAdapter.java | 2 +- .../languageManager/languageController.java | 2 +- .../languageViewController.java | 2 +- .../orbotLogManager/orbotLogAdapter.java | 2 +- .../orbotLogManager/orbotLogController.java | 2 +- .../orbotManager/orbotController.java | 2 +- .../settingAccessibilityController.java | 2 +- .../settingAccessibilityViewController.java | 2 +- .../settingAdvanceController.java | 2 +- .../advanceManager/settingAdvanceModel.java | 2 +- .../settingAdvanceViewController.java | 2 +- .../advertSettingController.java | 2 +- .../clearManager/settingClearController.java | 2 +- .../settingClearViewController.java | 2 +- .../settingGeneralController.java | 2 +- .../settingGeneralViewController.java | 2 +- .../logManager/settingLogController.java | 2 +- .../settingNotificationController.java | 2 +- .../settingNotificationViewController.java | 2 +- .../settingPrivacyController.java | 2 +- .../privacyManager/settingPrivacyModel.java | 2 +- .../settingPrivacyViewController.java | 2 +- .../proxyStatusController.java | 2 +- .../proxyStatusViewController.java | 2 +- .../settingSearchController.java | 2 +- .../settingSearchViewController.java | 2 +- .../settingHomeController.java | 2 +- .../settingHomeViewController.java | 2 +- .../settingTrackingController.java | 2 +- .../trackingManager/settingTrackingModel.java | 2 +- .../settingTrackingViewController.java | 2 +- .../appManager/tabManager/tabAdapter.java | 2 +- .../appManager/tabManager/tabController.java | 2 +- .../tabManager/tabViewController.java | 2 +- .../onionservices/constants/enums.java | 20 +- .../dataManager/bookmarkDataModel.java | 3 +- .../dataManager/models/tabRowModel.java | 4 +- .../helperManager/helperMethod.java | 8 +- .../helperManager/sharedUIMethod.java | 2 +- .../netcipher/client/StrongHttpsClient.java | 2 +- .../adPluginManager/appLovinManager.java | 34 +- .../applovinBannerManager.java | 4 +- .../downloadPluginManager/blobDownloader.java | 2 +- .../downloadReciever.java | 2 +- .../messagePluginManager/messageManager.java | 2 +- .../localEngagementManager.java | 2 +- .../notifictionManager.java | 2 +- .../pluginManager/pluginEnums.java | 2 +- .../widgetManager/widgetController.java | 2 +- .../widgetManager/widgetViewController.java | 2 +- .../bookmark/xml/bx_border_recycleview.xml | 22 + .../layouts/bookmark/layout/bookmark_view.xml | 3 +- .../layouts/history/layout/history_view.xml | 1 + .../res/layouts/home/layout/hint_view.xml | 1 + .../res/layouts/home/layout/home_view.xml | 2 +- .../res/layouts/setting/layout/setting.xml | 12 +- .../res/layouts/tab/layout/tab_grid_view.xml | 2 +- app/src/main/res/values/colors.xml | 2 +- app/variables.gradle | 2 + memory-20230120T201423.alloc | 0 105 files changed, 2873 insertions(+), 2983 deletions(-) create mode 100644 .idea/deploymentTargetDropDown.xml delete mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/config.yaml create mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/dataModel/geckoDataModel.java create mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/autofillDelegate.java create mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/contentDelegate.java create mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/historyDelegate.java rename app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/{ => delegateModel}/mediaDelegate.java (73%) create mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/mediaSessionDelegate.java rename app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/{geckoPromptView.java => delegateModel/promptDelegate.java} (73%) create mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/scrollDelegate.java rename app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/{selectionActionDelegate.java => delegateModel/selectionDelegate.java} (89%) rename app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/{ => helperClasses}/errorHandler.java (97%) create mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/intentHandler.java create mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/preferences.java create mode 100644 app/src/main/res/custom-xml/bookmark/xml/bx_border_recycleview.xml delete mode 100644 memory-20230120T201423.alloc diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 00000000..774c5408 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.safedk/hashes.safedk b/.safedk/hashes.safedk index b5af034b..a2e7dbdc 100644 --- a/.safedk/hashes.safedk +++ b/.safedk/hashes.safedk @@ -1,3 +1,3 @@ -#Sat Feb 04 14:33:30 PKT 2023 +#Thu Feb 09 03:08:42 PKT 2023 \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= -json=2027486056 +json=-1378969876 diff --git a/.safedk/plugin.properties b/.safedk/plugin.properties index e48dbea2..adb42cee 100644 --- a/.safedk/plugin.properties +++ b/.safedk/plugin.properties @@ -1,5 +1,5 @@ # -#Sat Feb 04 14:33:30 PKT 2023 +#Thu Feb 09 03:08:42 PKT 2023 \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= sdk_analysis_plugin_version=4.8.3 set_multidex=true diff --git a/app/build.gradle b/app/build.gradle index 2ca55109..074843d7 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,15 +3,14 @@ import com.android.build.OutputFile plugins { id "com.jetbrains.python.envs" version "0.0.26" } - apply plugin: 'com.android.application' apply from: 'variables.gradle' apply plugin: 'kotlin-android' apply plugin: 'applovin-quality-service' -applovin { - apiKey "pCPe4EeU2ZQVwQPeHLgseRqHBX1V5pvo9Piuu4J809dRhadEgukXa1A8po_UeXu5hmPOTaP1v4QPaMKIEOhh50" -} +applovin { + apiKey project.ext.applovin_key +} android { @@ -30,7 +29,7 @@ android { } } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = project.ext.jvmTarget } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -76,7 +75,7 @@ android { orionRelease.root = project.ext.releaseRoot } - namespace 'com.example.myapplication' + namespace project.ext.application_id } dependencies { @@ -105,7 +104,7 @@ dependencies { /* Ads Manager */ implementation 'com.applovin:applovin-sdk:11.7.0' - implementation 'com.facebook.android:audience-network-sdk:6.10.0' + implementation 'com.facebook.android:audience-network-sdk:6.12.0' implementation 'com.applovin.mediation:facebook-adapter:6.12.0.1' /* Orbot Service */ diff --git a/app/fabric.properties b/app/fabric.properties index 48555c31..d3f5a12f 100755 --- a/app/fabric.properties +++ b/app/fabric.properties @@ -1,3 +1 @@ -#Contains API Secret used to validate your application. Commit to internal source control; avoid making secret public. -#Wed May 01 00:42:45 PKT 2019 -apiSecret=042501af0b2390b9f064ff9a0823e52a2dd04b2280c9b675925cebbb9620ecbf + diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 193375a0..8ba938dc 100755 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,35 +1,32 @@ -keep,includedescriptorclasses class net.sqlcipher.** { *; } -keep,includedescriptorclasses interface net.sqlcipher.** { *; } +-keep class org.mozilla.** {*;} +-keep class com.flurry.** { *; } +-keep class okhttp3.** { *; } +-keep interface okhttp3.** { *; } +-keepattributes Signature +-keepattributes Annotation +-keepattributes *Annotation*,EnclosingMethod,Signature +-keepclasseswithmembers class * { public (android.content.Context, android.util.AttributeSet, int); } + +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable -dontwarn javax.annotation.** -dontwarn org.codehaus.mojo.animal_sniffer.* --dontwarn okhttp3.internal.platform.ConscryptPlatform --dontwarn org.conscrypt.ConscryptHostnameVerifier -dontwarn okhttp3.* -dontwarn org.chromium.net.* - --keep class org.mozilla.** {*;} --keep class com.flurry.** { *; } -dontwarn com.flurry.** --keepattributes *Annotation*,EnclosingMethod,Signature --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet, int); - } - --dontobfuscate -# https://stackoverflow.com/questions/9651703/using-proguard-with-android-without-obfuscation --optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable - --keep class org.orbotproject.android.service.vpn.Tun2Socks { - void logTun2Socks(java.lang.String, java.lang.String, java.lang.String); -} - --keepattributes Signature --keepattributes Annotation --keep class okhttp3.** { *; } --keep interface okhttp3.** { *; } -dontwarn okhttp3.** -dontwarn okio.** +-dontobfuscate -dontoptimize -dontpreverify + +# -dontwarn okhttp3.internal.platform.ConscryptPlatform +# -dontwarn org.conscrypt.ConscryptHostnameVerifier +# -keep class org.orbotproject.android.service.vpn.Tun2Socks { +# void logTun2Socks(java.lang.String, java.lang.String, java.lang.String); +# } + + diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/activityContextManager.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/activityContextManager.java index c1eae870..f491e8bf 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/activityContextManager.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/activityContextManager.java @@ -4,7 +4,7 @@ import static com.hiddenservices.onionservices.constants.constants.CONST_PACKAGE import android.content.Context; import androidx.appcompat.app.AppCompatActivity; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.hiddenservices.onionservices.appManager.bookmarkManager.bookmarkHome.bookmarkController; import com.hiddenservices.onionservices.appManager.bridgeManager.bridgeController; import com.hiddenservices.onionservices.appManager.historyManager.historyController; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/advertManager/advertController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/advertManager/advertController.java index c287bb08..98c7a828 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/advertManager/advertController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/advertManager/advertController.java @@ -8,7 +8,7 @@ import android.webkit.WebChromeClient; import android.webkit.WebView; import android.widget.ProgressBar; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.hiddenservices.onionservices.eventObserver; import java.util.Collections; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/advertManager/advertViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/advertManager/advertViewController.java index 62ef46b1..ce5d8dd9 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/advertManager/advertViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/advertManager/advertViewController.java @@ -6,7 +6,7 @@ import android.widget.ProgressBar; import androidx.appcompat.app.AppCompatActivity; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.helperManager.sharedUIMethod; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/bookmarkManager/bookmarkHome/bookmarkAdapter.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/bookmarkManager/bookmarkHome/bookmarkAdapter.java index fa16302a..e4bb5cef 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/bookmarkManager/bookmarkHome/bookmarkAdapter.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/bookmarkManager/bookmarkHome/bookmarkAdapter.java @@ -15,11 +15,12 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import com.hiddenservices.onionservices.constants.enums; +import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.constants.strings; import com.hiddenservices.onionservices.dataManager.models.bookmarkRowModel; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.helperManager.helperMethod; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.ArrayList; import java.util.Arrays; @@ -446,10 +447,12 @@ public class bookmarkAdapter extends RecyclerView.Adapter= android.os.Build.VERSION_CODES.O) { + manager = mGeckoView.getContext().getSystemService(AutofillManager.class); + if (manager == null) { + return; + } + manager.notifyViewEntered(mGeckoView, data.getId(),displayRectForId(session, node)); + } + } + + @Override + public void onNodeFocus(@NonNull final GeckoSession session, @NonNull final Autofill.Node node, @NonNull final Autofill.NodeData data) { + final AutofillManager manager; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + manager = mGeckoView.getContext().getSystemService(AutofillManager.class); + if (manager == null) { + return; + } + manager.notifyViewEntered(mGeckoView, data.getId(),displayRectForId(session, node)); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/contentDelegate.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/contentDelegate.java new file mode 100644 index 00000000..1ddd58ec --- /dev/null +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/contentDelegate.java @@ -0,0 +1,218 @@ +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel; + + +import static com.hiddenservices.onionservices.constants.constants.CONST_GENESIS_HELP_URL_CACHE; +import static com.hiddenservices.onionservices.constants.constants.CONST_GENESIS_HELP_URL_CACHE_DARK; +import static com.hiddenservices.onionservices.constants.constants.CONST_GENESIS_URL_CACHED; +import static com.hiddenservices.onionservices.constants.constants.CONST_GENESIS_URL_CACHED_DARK; +import static com.hiddenservices.onionservices.pluginManager.pluginEnums.eMessageManager.M_LONG_PRESS_URL; +import static com.hiddenservices.onionservices.pluginManager.pluginEnums.eMessageManager.M_LONG_PRESS_WITH_LINK; +import android.content.ActivityNotFoundException; +import android.os.Handler; +import android.util.Log; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.UiThread; +import androidx.appcompat.app.AppCompatActivity; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.dataModel.geckoDataModel; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.geckoDownloadManager; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.geckoSession; +import com.hiddenservices.onionservices.constants.enums; +import com.hiddenservices.onionservices.constants.status; +import com.hiddenservices.onionservices.constants.strings; +import com.hiddenservices.onionservices.eventObserver; +import com.hiddenservices.onionservices.helperManager.helperMethod; +import org.json.JSONObject; +import org.mozilla.geckoview.GeckoSession; +import org.mozilla.geckoview.WebResponse; +import java.lang.ref.WeakReference; +import java.util.Arrays; + +public class contentDelegate implements GeckoSession.ContentDelegate { + + /*Private Variables*/ + + private WeakReference mContext; + private eventObserver.eventListener mEvent; + private geckoDataModel mGeckoDataModel; + private geckoSession mGeckoSession; + + private geckoDownloadManager mDownloadManager; + private int mCrashCount = 0; + + /*Initializations*/ + + public contentDelegate(WeakReference pContext, eventObserver.eventListener pEvent, geckoDataModel pGeckoDataModel, geckoSession pGeckoSession) { + this.mContext = pContext; + this.mEvent = pEvent; + this.mGeckoDataModel = pGeckoDataModel; + this.mGeckoSession = pGeckoSession; + + mDownloadManager = new geckoDownloadManager(); + } + + /*Local Listeners*/ + + @UiThread + public void onTitleChange(@NonNull GeckoSession var1, @Nullable String var2) { + if (var2 != null && !var2.equals(strings.GENERIC_EMPTY_STR) && var2.length() > 2 && !var2.equals("about:blank")) { + mGeckoDataModel.mCurrentTitle = var2; + } + } + + @Override + public void onFullScreen(@NonNull GeckoSession var1, boolean var2) { + mGeckoDataModel.mFullScreenStatus = var2; + mEvent.invokeObserver(Arrays.asList(var2, mGeckoDataModel.mSessionID), enums.etype.ON_FULL_SCREEN); + } + + @UiThread + @Override + public void onContextMenu(@NonNull GeckoSession var1, int var2, int var3, @NonNull GeckoSession.ContentDelegate.ContextElement var4) { + + String title = strings.GENERIC_EMPTY_STR; + if (var4.title != null) { + title = var4.title; + } + if (var4.type != 0 && var4.srcUri != null) { + if (var4.linkUri != null) { + mEvent.invokeObserver(Arrays.asList(var4.linkUri, mGeckoDataModel.mSessionID, var4.srcUri, title, mGeckoDataModel.mTheme, var4.altText, mGeckoSession, mContext.get()), M_LONG_PRESS_WITH_LINK); + } else { + try { + String mTitle = var4.title; + if (mTitle == null || mTitle.length() <= 0) { + mTitle = helperMethod.getDomainName(mGeckoDataModel.mCurrentURL) + "\n" + var4.srcUri; + } + mEvent.invokeObserver(Arrays.asList(var4.srcUri, mGeckoDataModel.mSessionID, mTitle, mGeckoDataModel.mTheme, mGeckoSession, mContext.get()), enums.etype.on_long_press); + } catch (Exception ex) { + ex.printStackTrace(); + Log.i("", ""); + } + } + } else if (var4.linkUri != null) { + mEvent.invokeObserver(Arrays.asList(var4.linkUri, mGeckoDataModel.mSessionID, title, mGeckoDataModel.mTheme, mGeckoSession, mContext.get()), M_LONG_PRESS_URL); + } + } + + @UiThread + @Override + public void onExternalResponse(@NonNull GeckoSession session, @NonNull WebResponse response) { + try { + if (response.headers.containsKey("Content-Disposition")) { + mDownloadManager.downloadFile(response, mGeckoSession, mContext.get(), mEvent); + } else if (response.headers.containsKey("Content-Type")) { + mDownloadManager.downloadFile(response, mGeckoSession, mContext.get(), mEvent); + } + } catch (ActivityNotFoundException e) { + mEvent.invokeObserver(Arrays.asList(response, mGeckoDataModel.mSessionID), enums.etype.on_handle_external_intent); + mGeckoSession.stop(); + } + } + + @UiThread + public void onFirstContentfulPaint(@NonNull GeckoSession var1) { + if (mGeckoDataModel.mCurrentURL.contains("167.86.99.31") || mGeckoDataModel.mCurrentURL.startsWith(CONST_GENESIS_URL_CACHED) || mGeckoDataModel.mCurrentURL.startsWith(CONST_GENESIS_URL_CACHED_DARK) || mGeckoDataModel.mCurrentURL.startsWith(CONST_GENESIS_HELP_URL_CACHE) || mGeckoDataModel.mCurrentURL.startsWith(CONST_GENESIS_HELP_URL_CACHE_DARK)) { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, false), enums.etype.M_ON_BANNER_UPDATE); + } else { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, true), enums.etype.M_ON_BANNER_UPDATE); + } + + if (!mGeckoDataModel.mCurrentURL.equals("about:blank")) { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme), enums.etype.ON_FIRST_PAINT); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme), enums.etype.ON_LOAD_REQUEST); + } + + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), enums.etype.ON_EXPAND_TOP_BAR); + } + + @UiThread + public void onWebAppManifest(@NonNull GeckoSession var1, @NonNull JSONObject var2) { + try { + mGeckoDataModel.mThemeChanged = true; + mGeckoDataModel.mTheme = var2.getString("theme_color"); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), enums.etype.ON_UPDATE_THEME); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL,mGeckoDataModel.mSessionID,mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme), enums.etype.M_INDEX_WEBSITE); + } catch (Exception ex) { + mGeckoDataModel.mTheme = null; + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), enums.etype.ON_UPDATE_THEME); + ex.printStackTrace(); + } + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme), enums.etype.ON_UPDATE_TAB_TITLE); + } + + @UiThread + public void onCrash(@NonNull GeckoSession session) { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme, mGeckoSession), enums.etype.ON_DESTROY_MEDIA); + + if (!mGeckoSession.isClosed() && status.sSettingIsAppStarted) { + if (mEvent == null) { + return; + } + Object mSessionObject = mEvent.invokeObserver(null, enums.etype.SESSION_ID); + if (mSessionObject == null || mGeckoDataModel.mSessionID == null) { + return; + } + String mSessionID = (String) mSessionObject; + if (mSessionID.equals(mGeckoDataModel.mSessionID)) { + if (mCrashCount <= 5) { + final Handler handler = new Handler(); + handler.postDelayed(() -> { + try { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme, this), enums.etype.M_OPEN_SESSION); + } catch (Exception ignored) { + } + }, mCrashCount * 500L); + } + mCrashCount += 1; + } + } + } + + @UiThread + public void onKill(@NonNull GeckoSession session) { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme, mGeckoSession), enums.etype.ON_DESTROY_MEDIA); + + if (!mGeckoSession.isClosed() && status.sSettingIsAppStarted) { + if (mEvent == null) { + return; + } + Object mSessionObject = mEvent.invokeObserver(null, enums.etype.SESSION_ID); + if (mSessionObject == null || mGeckoDataModel.mSessionID == null) { + return; + } + String mSessionID = (String) mSessionObject; + + + if (mSessionID.equals(mGeckoDataModel.mSessionID)) { + if (mCrashCount <= 5) { + final Handler handler = new Handler(); + handler.postDelayed(() -> { + if (status.sSettingIsAppStarted && !session.isOpen()) { + try { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme, this), enums.etype.M_OPEN_SESSION); + } catch (Exception ignored) { + } + } + }, mCrashCount * 500L); + } + mCrashCount += 1; + } + } + } + + /*Local Triggers*/ + + public boolean getFullScreenStatus() { + return !mGeckoDataModel.mFullScreenStatus; + } + + public void resetCrash() { + mCrashCount = 0; + } + + public geckoDownloadManager getDownloadManager(){ + return this.mDownloadManager; + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/historyDelegate.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/historyDelegate.java new file mode 100644 index 00000000..106f147e --- /dev/null +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/historyDelegate.java @@ -0,0 +1,76 @@ +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel; + + +import androidx.annotation.NonNull; +import androidx.annotation.UiThread; +import androidx.appcompat.app.AppCompatActivity; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.dataModel.geckoDataModel; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.geckoSession; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses.intentHandler; +import com.hiddenservices.onionservices.constants.enums; +import com.hiddenservices.onionservices.eventObserver; +import com.hiddenservices.onionservices.helperManager.helperMethod; +import org.mozilla.geckoview.GeckoSession; +import java.lang.ref.WeakReference; +import java.util.Arrays; + +public class historyDelegate implements GeckoSession.HistoryDelegate { + + /*Private Variables*/ + + private WeakReference mContext; + private GeckoSession.HistoryDelegate.HistoryList mHistory = null; + private eventObserver.eventListener mEvent; + private geckoDataModel mGeckoDataModel; + private geckoSession mGeckoSession; + private int mCurrentIndex = 0; + + /*Initializations*/ + + public historyDelegate(WeakReference pContext, eventObserver.eventListener pEvent, geckoDataModel pGeckoDataModel, geckoSession pGeckoSession) { + this.mContext = pContext; + this.mEvent = pEvent; + this.mGeckoDataModel = pGeckoDataModel; + this.mGeckoSession = pGeckoSession; + } + + @UiThread + public void onHistoryStateChange(@NonNull GeckoSession var1, @NonNull GeckoSession.HistoryDelegate.HistoryList var2) { + mHistory = var2; + if(mHistory !=null){ + setURL(mHistory.get(mHistory.getCurrentIndex()).getUri()); + mEvent.invokeObserver(Arrays.asList(mHistory, mGeckoDataModel.mSessionID), enums.etype.on_url_load); + if(mCurrentIndex != var2.getCurrentIndex()){ + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mHistory.get(mHistory.getCurrentIndex()).getTitle(), mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme, mGeckoSession), enums.etype.ON_UPDATE_SEARCH_BAR); + } + + Object mID = mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mHistory.get(mHistory.getCurrentIndex()).getTitle(), -1, mGeckoDataModel.mTheme, mGeckoSession, false), enums.etype.ON_UPDATE_HISTORY); + if (mID != null) { + mGeckoDataModel.mCurrentURL_ID = (int) mID; + } + } + mCurrentIndex = var2.getCurrentIndex(); + } + + /*Local Triggers*/ + + public void setURL(String pURL) { + if (helperMethod.getHost(pURL).endsWith(".onion")) { + pURL = pURL.replace("www.", ""); + } + + this.mGeckoDataModel.mCurrentURL = pURL; + if(pURL.startsWith("tel:")){ + intentHandler.actionDial(pURL, mContext); + } + } + + public boolean isHistoryEmpty(){ + if(mHistory!=null && mHistory.size()>0){ + return false; + }else { + return true; + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/mediaDelegate.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/mediaDelegate.java similarity index 73% rename from app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/mediaDelegate.java rename to app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/mediaDelegate.java index 58d94f68..7e5f7cd0 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/mediaDelegate.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/mediaDelegate.java @@ -1,126 +1,136 @@ -package com.hiddenservices.onionservices.appManager.homeManager.geckoManager; - - -import static android.content.Context.NOTIFICATION_SERVICE; -import android.app.Activity; -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.graphics.Bitmap; -import android.os.Build; -import android.widget.RemoteViews; -import androidx.core.app.NotificationCompat; -import androidx.core.app.NotificationManagerCompat; -import com.example.myapplication.R; -import com.hiddenservices.onionservices.constants.status; -import com.hiddenservices.onionservices.helperManager.helperMethod; -import com.hiddenservices.onionservices.pluginManager.pluginReciever.mediaNotificationReciever; -import org.mozilla.geckoview.GeckoSession; - -public class mediaDelegate implements GeckoSession.MediaDelegate { - private Context mContext; - - public mediaDelegate(Activity activity, Context pContext) { - mContext = pContext; - } - - public void onHideDefaultNotification(){ - NotificationManagerCompat.from(mContext).cancel(1030); - } - - public void showNotification(Context context, String title, String url, Bitmap mediaImage, boolean not_status) { - NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService( NOTIFICATION_SERVICE ) ; - if(title.length()<=0 || !status.sBackgroundMusic){ - return; - } - RemoteViews contentView; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ) { - contentView = new RemoteViews(context.getPackageName() , R.layout. media_notification_no_background ) ; - }else if (android.os.Build.VERSION. SDK_INT > Build.VERSION_CODES.N_MR1){ - contentView = new RemoteViews(context.getPackageName() , R.layout. media_notification_layout ) ; - }else { - contentView = new RemoteViews(context.getPackageName() , R.layout. media_notification_layout_small ) ; - } - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S ) { - contentView.setInt(R.id.layout,"setBackgroundResource", R.color.c_tab_background); - } - contentView.setTextViewText(R.id.header, title); - contentView.setTextViewText(R.id.body, "☍ " + url); - - try { - contentView.setImageViewBitmap(R.id.logo, mediaImage); - } catch (Throwable e) { - e.printStackTrace(); - } - - if (not_status){ - PendingIntent pIntent = helperMethod.onCreateActionIntent(context, mediaNotificationReciever.class, 1030, "media_play", 0); - contentView.setOnClickPendingIntent(R.id.trigger, pIntent); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ) { - contentView.setImageViewResource(R.id.trigger, R.drawable.ic_baseline_play_arrow_no_tint); - }else { - contentView.setImageViewResource(R.id.trigger, R.drawable.ic_baseline_play_arrow); - } - }else { - PendingIntent pIntent = helperMethod.onCreateActionIntent(context, mediaNotificationReciever.class, 1030, "media_pause", 1); - contentView.setOnClickPendingIntent(R.id.trigger, pIntent); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ) { - contentView.setImageViewResource(R.id.trigger, R.drawable.ic_baseline_pause_no_tint); - }else { - contentView.setImageViewResource(R.id.trigger, R.drawable.ic_baseline_pause); - } - } - - PendingIntent pIntentPrev = helperMethod.onCreateActionIntent(context, mediaNotificationReciever.class, 1030, "media_next", 2); - contentView.setOnClickPendingIntent(R.id.next, pIntentPrev); - - if(android.os.Build.VERSION. SDK_INT > Build.VERSION_CODES.N){ - PendingIntent pIntentNext = helperMethod.onCreateActionIntent(context, mediaNotificationReciever.class, 1030, "media_back", 3); - contentView.setOnClickPendingIntent(R.id.back, pIntentNext); - } - - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext, "1030" ) ; - - mBuilder.setPriority(Notification.PRIORITY_LOW); - mBuilder.setAutoCancel(true); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ - mBuilder.setCustomBigContentView(contentView); - mBuilder.setStyle(new NotificationCompat.DecoratedCustomViewStyle()); - }else { - mBuilder.setContent(contentView); - } - - mBuilder.setSmallIcon(R.drawable.ic_baseline_media) ; - mBuilder.setAutoCancel( true ) ; - if (android.os.Build.VERSION. SDK_INT >= android.os.Build.VERSION_CODES. O ) { - int importance = NotificationManager.IMPORTANCE_LOW ; - NotificationChannel notificationChannel = new NotificationChannel( "1030" , "NOTIFICATION_CHANNEL_NAME" , importance) ; - notificationChannel.setSound(null, null); - mBuilder.setChannelId("1030") ; - assert mNotificationManager != null; - mNotificationManager.createNotificationChannel(notificationChannel) ; - } - Notification notification = mBuilder.build(); - - mBuilder.setContentIntent(PendingIntent.getActivity(context, 1030, new Intent(context, mediaDelegate.class), PendingIntent.FLAG_IMMUTABLE)); - PendingIntent dummyIntent = null; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PendingIntent.getActivity(context, 1030, new Intent(), PendingIntent.FLAG_IMMUTABLE); - }else { - PendingIntent.getActivity(context, 1030, new Intent(), 0); - } - notification.fullScreenIntent = dummyIntent; - - if(!not_status){ - notification.flags |= Notification.FLAG_NO_CLEAR; - } - - notification.defaults = 0; - mNotificationManager.notify(1030 , notification) ; - - } +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel; + + +import static android.content.Context.NOTIFICATION_SERVICE; + +import android.annotation.SuppressLint; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.os.Build; +import android.widget.RemoteViews; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; +import com.hiddenservices.onionservices.R; +import com.hiddenservices.onionservices.constants.status; +import com.hiddenservices.onionservices.helperManager.helperMethod; +import com.hiddenservices.onionservices.pluginManager.pluginReciever.mediaNotificationReciever; +import org.mozilla.geckoview.GeckoSession; + +import java.lang.ref.WeakReference; + +public class mediaDelegate implements GeckoSession.MediaDelegate { + + /*Private Variables*/ + + private WeakReference mContext; + private static int S_NOTIFICATION_ID = 1030; + private static String S_NOTIFICATION_CHANNEL_ID = "1030"; + private static String S_NOTIFICATION_CHANNEL_NAME = "MEDIA_NOTIFICATION"; + + /*Initializations*/ + + public mediaDelegate(WeakReference pContext) { + mContext = pContext; + } + + public void onHideDefaultNotification(){ + NotificationManagerCompat.from(mContext.get()).cancel(S_NOTIFICATION_ID); + } + + /*Triggers*/ + + @SuppressLint("InlinedApi") + public void showNotification(Context context, String title, String url, Bitmap mediaImage, boolean media_status) { + NotificationManager mNotificationManager = (NotificationManager) mContext.get().getSystemService( NOTIFICATION_SERVICE ) ; + if(title.length()<=0 || !status.sBackgroundMusic){ + return; + } + RemoteViews contentView; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ) { + contentView = new RemoteViews(context.getPackageName() , R.layout. media_notification_no_background ) ; + }else if (android.os.Build.VERSION. SDK_INT > Build.VERSION_CODES.N_MR1){ + contentView = new RemoteViews(context.getPackageName() , R.layout. media_notification_layout ) ; + }else { + contentView = new RemoteViews(context.getPackageName() , R.layout. media_notification_layout_small ) ; + } + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S ) { + contentView.setInt(R.id.layout,"setBackgroundResource", R.color.c_tab_background); + } + contentView.setTextViewText(R.id.header, title); + contentView.setTextViewText(R.id.body, "☍ " + url); + + try { + contentView.setImageViewBitmap(R.id.logo, mediaImage); + } catch (Throwable e) { + e.printStackTrace(); + } + + if (!media_status){ + PendingIntent pIntent = helperMethod.onCreateActionIntent(context, mediaNotificationReciever.class, S_NOTIFICATION_ID, "media_play", 0); + contentView.setOnClickPendingIntent(R.id.trigger, pIntent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ) { + contentView.setImageViewResource(R.id.trigger, R.drawable.ic_baseline_play_arrow_no_tint); + }else { + contentView.setImageViewResource(R.id.trigger, R.drawable.ic_baseline_play_arrow); + } + }else { + PendingIntent pIntent = helperMethod.onCreateActionIntent(context, mediaNotificationReciever.class, S_NOTIFICATION_ID, "media_pause", 1); + contentView.setOnClickPendingIntent(R.id.trigger, pIntent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ) { + contentView.setImageViewResource(R.id.trigger, R.drawable.ic_baseline_pause_no_tint); + }else { + contentView.setImageViewResource(R.id.trigger, R.drawable.ic_baseline_pause); + } + } + + PendingIntent pIntentPrev = helperMethod.onCreateActionIntent(context, mediaNotificationReciever.class, S_NOTIFICATION_ID, "media_next", 2); + contentView.setOnClickPendingIntent(R.id.next, pIntentPrev); + + if(android.os.Build.VERSION. SDK_INT > Build.VERSION_CODES.N){ + PendingIntent pIntentNext = helperMethod.onCreateActionIntent(context, mediaNotificationReciever.class, S_NOTIFICATION_ID, "media_back", 3); + contentView.setOnClickPendingIntent(R.id.back, pIntentNext); + } + + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext.get(), S_NOTIFICATION_CHANNEL_ID ) ; + + mBuilder.setPriority(Notification.PRIORITY_LOW); + mBuilder.setAutoCancel(true); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ + mBuilder.setCustomBigContentView(contentView); + mBuilder.setStyle(new NotificationCompat.DecoratedCustomViewStyle()); + }else { + mBuilder.setContent(contentView); + } + + mBuilder.setSmallIcon(R.drawable.ic_baseline_media) ; + mBuilder.setAutoCancel( true ) ; + if (android.os.Build.VERSION. SDK_INT >= android.os.Build.VERSION_CODES. O ) { + int importance = NotificationManager.IMPORTANCE_LOW ; + NotificationChannel notificationChannel = new NotificationChannel( S_NOTIFICATION_CHANNEL_ID , S_NOTIFICATION_CHANNEL_NAME , importance) ; + notificationChannel.setSound(null, null); + mBuilder.setChannelId(S_NOTIFICATION_CHANNEL_ID) ; + assert mNotificationManager != null; + mNotificationManager.createNotificationChannel(notificationChannel) ; + } + Notification notification = mBuilder.build(); + + mBuilder.setContentIntent(PendingIntent.getActivity(context, S_NOTIFICATION_ID, new Intent(context, mediaDelegate.class), PendingIntent.FLAG_IMMUTABLE)); + notification.fullScreenIntent = null; + + if(media_status){ + notification.flags |= Notification.FLAG_NO_CLEAR; + } + + notification.defaults = 0; + mNotificationManager.notify(S_NOTIFICATION_ID , notification) ; + + } } \ No newline at end of file diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/mediaSessionDelegate.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/mediaSessionDelegate.java new file mode 100644 index 00000000..c819b353 --- /dev/null +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/mediaSessionDelegate.java @@ -0,0 +1,124 @@ +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel; + +import static com.hiddenservices.onionservices.constants.strings.GENERIC_EMPTY_STR; + +import android.graphics.Bitmap; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.dataModel.geckoDataModel; +import com.hiddenservices.onionservices.constants.enums; +import com.hiddenservices.onionservices.helperManager.helperMethod; +import org.mozilla.geckoview.GeckoSession; +import org.mozilla.geckoview.MediaSession; +import java.lang.ref.WeakReference; + +public class mediaSessionDelegate implements MediaSession.Delegate{ + + /*Private Variables*/ + + private MediaSession mMediaSession = null; + private mediaDelegate mMediaDelegate; + private WeakReference mContext; + private geckoDataModel mGeckoDataModel; + + private Bitmap mMediaImage; + private String mMediaTitle = GENERIC_EMPTY_STR; + + /*Initializations*/ + + public mediaSessionDelegate(WeakReference pContext, geckoDataModel pGeckoDataModel, mediaDelegate pMediaDelegate){ + this.mContext = pContext; + this.mMediaDelegate = pMediaDelegate; + this.mGeckoDataModel = pGeckoDataModel; + } + + /*Local Listeners*/ + + @Override + public void onActivated(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { + MediaSession.Delegate.super.onActivated(session, mediaSession); + mMediaSession = mediaSession; + } + + @Override + public void onDeactivated(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { + MediaSession.Delegate.super.onPause(session, mediaSession); + mMediaDelegate.onHideDefaultNotification(); + } + + @Override + public void onMetadata(@NonNull GeckoSession session, @NonNull MediaSession mediaSession, @NonNull MediaSession.Metadata meta) { + + try { + mMediaTitle = meta.title; + mMediaImage = meta.artwork.getBitmap(250).poll(2500); + mMediaDelegate.showNotification(mContext.get(), mMediaTitle, helperMethod.getHost(mGeckoDataModel.mCurrentURL), mMediaImage, true); + } catch (Throwable e) { + e.printStackTrace(); + } + + MediaSession.Delegate.super.onMetadata(session, mediaSession, meta); + } + + @Override + public void onFeatures(@NonNull GeckoSession session, @NonNull MediaSession mediaSession, long features) { + MediaSession.Delegate.super.onFeatures(session, mediaSession, features); + } + + @Override + public void onPlay(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { + MediaSession.Delegate.super.onPlay(session, mediaSession); + mMediaDelegate.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mGeckoDataModel.mCurrentURL), mMediaImage, true); + } + + @Override + public void onPause(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { + MediaSession.Delegate.super.onPause(session, mediaSession); + mMediaDelegate.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mGeckoDataModel.mCurrentURL), mMediaImage, false); + } + + @Override + public void onStop(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { + MediaSession.Delegate.super.onStop(session, mediaSession); + mMediaDelegate.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mGeckoDataModel.mCurrentURL), mMediaImage, false); + } + + @Override + public void onPositionState(@NonNull GeckoSession session, @NonNull MediaSession mediaSession, @NonNull MediaSession.PositionState state) { + MediaSession.Delegate.super.onPositionState(session, mediaSession, state); + } + + @Override + public void onFullscreen(@NonNull GeckoSession session, @NonNull MediaSession mediaSession, boolean enabled, @Nullable @org.jetbrains.annotations.Nullable MediaSession.ElementMetadata meta) { + MediaSession.Delegate.super.onFullscreen(session, mediaSession, enabled, meta); + } + + /*Triggers*/ + + public void onTrigger(enums.MediaController pCommands){ + if(mMediaSession!=null){ + if(pCommands.equals(enums.MediaController.PLAY)){ + mMediaDelegate.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mGeckoDataModel.mCurrentURL), mMediaImage, true); + mMediaSession.play(); + } + else if(pCommands.equals(enums.MediaController.PAUSE)){ + mMediaDelegate.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mGeckoDataModel.mCurrentURL), mMediaImage, false); + mMediaSession.pause(); + } + else if(pCommands.equals(enums.MediaController.STOP)){ + mMediaSession.stop(); + } + else if(pCommands.equals(enums.MediaController.DESTROY)){ + mMediaSession.stop(); + mMediaDelegate.onHideDefaultNotification(); + } + else if(pCommands.equals(enums.MediaController.SKIP_BACKWARD)){ + mMediaSession.previousTrack(); + } + else if(pCommands.equals(enums.MediaController.SKIP_FORWARD)){ + mMediaSession.nextTrack(); + } + } + } +} diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoPromptView.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/promptDelegate.java similarity index 73% rename from app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoPromptView.java rename to app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/promptDelegate.java index d743724a..59ce4f2a 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoPromptView.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/promptDelegate.java @@ -1,1103 +1,1035 @@ -package com.hiddenservices.onionservices.appManager.homeManager.geckoManager; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.app.AlertDialog; -import android.content.ActivityNotFoundException; -import android.content.ClipData; -import android.content.ContentResolver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.res.TypedArray; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.net.Uri; -import android.os.Build; -import android.text.InputType; -import android.text.format.DateFormat; -import android.util.Log; -import android.view.InflateException; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.webkit.MimeTypeMap; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.CheckedTextView; -import android.widget.DatePicker; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.ScrollView; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.TimePicker; - -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ShareCompat; - -import com.hiddenservices.onionservices.appManager.activityContextManager; -import com.hiddenservices.onionservices.helperManager.helperMethod; - -import java.io.File; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; - -import org.mozilla.geckoview.AllowOrDeny; -import org.mozilla.geckoview.GeckoResult; -import org.mozilla.geckoview.GeckoSession; -import org.mozilla.geckoview.SlowScriptResponse; - -final class geckoPromptView implements GeckoSession.PromptDelegate { - protected static final String LOGTAG = "BasicGeckoViewPrompt"; - - private final AppCompatActivity mActivity; - public int filePickerRequestCode = 1; - private int mFileType; - private GeckoResult mFileResponse; - private FilePrompt mFilePrompt; - - public geckoPromptView(final AppCompatActivity activity) { - mActivity = activity; - } - - public void stopMedia(){ - try { - activityContextManager.getInstance().getHomeController().onKillMedia(); - }catch (Exception ex){} - } - - @Override - public GeckoResult onAlertPrompt(final GeckoSession session, - final AlertPrompt prompt) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - return GeckoResult.fromValue(prompt.dismiss()); - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity) - .setTitle(prompt.title) - .setMessage(prompt.message) - .setPositiveButton(android.R.string.ok, /* onClickListener */ null); - GeckoResult res = new GeckoResult(); - createStandardDialog(builder, prompt, res).show(); - return res; - } - - @Override - public GeckoResult onButtonPrompt(final GeckoSession session, - final ButtonPrompt prompt) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - return GeckoResult.fromValue(prompt.dismiss()); - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity) - .setTitle(prompt.title) - .setMessage(prompt.message); - - GeckoResult res = new GeckoResult(); - - final DialogInterface.OnClickListener listener = - new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - if (which == DialogInterface.BUTTON_POSITIVE) { - res.complete(prompt.confirm(ButtonPrompt.Type.POSITIVE)); - } else if (which == DialogInterface.BUTTON_NEGATIVE) { - res.complete(prompt.confirm(ButtonPrompt.Type.NEGATIVE)); - } else { - res.complete(prompt.dismiss()); - } - } - }; - - builder.setPositiveButton(android.R.string.ok, listener); - builder.setNegativeButton(android.R.string.cancel, listener); - - createStandardDialog(builder, prompt, res).show(); - return res; - } - - public static String getMimeType(Context context, Uri uri) { - String extension; - - //Check uri format to avoid null - if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { - //If scheme is a content - final MimeTypeMap mime = MimeTypeMap.getSingleton(); - extension = mime.getExtensionFromMimeType(context.getContentResolver().getType(uri)); - } else { - //If scheme is a File - //This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file name with spaces and special characters. - extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString()); - - } - - return extension; - } - - static boolean mPopupOpened = false; - @Override - public GeckoResult onSharePrompt(final GeckoSession session, - final SharePrompt prompt) { - stopMedia(); - new Thread(){ - public void run(){ - try { - sleep(4000); - mPopupOpened = false; - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - }.start(); - if(!mPopupOpened){ - mPopupOpened = true; - }else { - return GeckoResult.fromValue(prompt.confirm(SharePrompt.Result.ABORT)); - } - try { - String m_data = prompt.uri; - if(prompt.text!=null){ - m_data += " : " + prompt.text; - } - - ShareCompat.IntentBuilder.from(mActivity) - .setType("text/x-uri") - .setChooserTitle(prompt.title) - .setText(m_data) - .startChooser(); - }catch (Exception ex){} - - return GeckoResult.fromValue(prompt.confirm(SharePrompt.Result.SUCCESS)); - - } - - @Nullable - @Override - public GeckoResult onRepostConfirmPrompt(final GeckoSession session, - final RepostConfirmPrompt prompt) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - return GeckoResult.fromValue(prompt.dismiss()); - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity) - .setTitle("Are you sure?") - .setMessage("To display this page, GeckoViewExample must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."); - - GeckoResult res = new GeckoResult<>(); - - final DialogInterface.OnClickListener listener = (dialog, which) -> { - if (which == DialogInterface.BUTTON_POSITIVE) { - res.complete(prompt.confirm(AllowOrDeny.ALLOW)); - } else if (which == DialogInterface.BUTTON_NEGATIVE) { - res.complete(prompt.confirm(AllowOrDeny.DENY)); - } else { - res.complete(prompt.dismiss()); - } - }; - - builder.setPositiveButton("Resend", listener); - builder.setNegativeButton("Cancel", listener); - - try { - if(mActivity!=null && !mActivity.isFinishing()) - { - createStandardDialog(builder, prompt, res).show(); - } - }catch (Exception ex){} - return res; - } - - @Nullable - @Override - public GeckoResult onBeforeUnloadPrompt(final GeckoSession session, - final BeforeUnloadPrompt prompt) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - return GeckoResult.fromValue(prompt.dismiss()); - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity) - .setTitle("Are you sure?") - .setMessage("This page is asking you to confirm that you want to leave - data you have entered may not be saved"); - - GeckoResult res = new GeckoResult<>(); - - final DialogInterface.OnClickListener listener = (dialog, which) -> { - if (which == DialogInterface.BUTTON_POSITIVE) { - res.complete(prompt.confirm(AllowOrDeny.ALLOW)); - } else if (which == DialogInterface.BUTTON_NEGATIVE) { - res.complete(prompt.confirm(AllowOrDeny.DENY)); - } else { - res.complete(prompt.dismiss()); - } - }; - - builder.setPositiveButton("Leave Page", listener); - builder.setNegativeButton("Stay on Page", listener); - - createStandardDialog(builder, prompt, res).show(); - return res; - } - - private int getViewPadding(final AlertDialog.Builder builder) { - stopMedia(); - final TypedArray attr = builder.getContext().obtainStyledAttributes( - new int[]{android.R.attr.listPreferredItemPaddingLeft}); - final int padding = attr.getDimensionPixelSize(0, 1); - attr.recycle(); - return padding; - } - - private LinearLayout addStandardLayout(final AlertDialog.Builder builder, - final String title, final String msg) { - stopMedia(); - final ScrollView scrollView = new ScrollView(builder.getContext()); - final LinearLayout container = new LinearLayout(builder.getContext()); - final int horizontalPadding = getViewPadding(builder); - final int verticalPadding = (msg == null || msg.isEmpty()) ? horizontalPadding : 0; - container.setOrientation(LinearLayout.VERTICAL); - container.setPadding(/* left */ horizontalPadding, /* top */ verticalPadding, - /* right */ horizontalPadding, /* bottom */ verticalPadding); - scrollView.addView(container); - builder.setTitle(title) - .setMessage(msg) - .setView(scrollView); - return container; - } - - private AlertDialog createStandardDialog(final AlertDialog.Builder builder, - final BasePrompt prompt, - final GeckoResult response) { - final AlertDialog dialog = builder.create(); - stopMedia(); - dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(final DialogInterface dialog) { - if (!prompt.isComplete()) { - response.complete(prompt.dismiss()); - } - } - }); - return dialog; - } - - @Override - public GeckoResult onTextPrompt(final GeckoSession session, - final TextPrompt prompt) { - final Activity activity = mActivity; - stopMedia(); - if (activity == null) { - return GeckoResult.fromValue(prompt.dismiss()); - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - final LinearLayout container = addStandardLayout(builder, prompt.title, prompt.message); - final EditText editText = new EditText(builder.getContext()); - editText.setText(prompt.defaultValue); - container.addView(editText); - - GeckoResult res = new GeckoResult(); - - builder.setNegativeButton(android.R.string.cancel, /* listener */ null) - .setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - res.complete(prompt.confirm(editText.getText().toString())); - } - }); - - createStandardDialog(builder, prompt, res).show(); - return res; - } - - @Override - public GeckoResult onAuthPrompt(final GeckoSession session, - final AuthPrompt prompt) { - final Activity activity = mActivity; - stopMedia(); - if (activity == null) { - return GeckoResult.fromValue(prompt.dismiss()); - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - final LinearLayout container = addStandardLayout(builder, prompt.title, prompt.message); - - final int flags = prompt.authOptions.flags; - final int level = prompt.authOptions.level; - final EditText username; - if ((flags & AuthPrompt.AuthOptions.Flags.ONLY_PASSWORD) == 0) { - username = new EditText(builder.getContext()); - username.setHint("Username"); - username.setText(prompt.authOptions.username); - container.addView(username); - } else { - username = null; - } - - final EditText password = new EditText(builder.getContext()); - password.setHint("Password"); - password.setText(prompt.authOptions.password); - password.setInputType(InputType.TYPE_CLASS_TEXT | - InputType.TYPE_TEXT_VARIATION_PASSWORD); - container.addView(password); - - if (level != AuthPrompt.AuthOptions.Level.NONE) { - final ImageView secure = new ImageView(builder.getContext()); - secure.setImageResource(android.R.drawable.ic_lock_lock); - container.addView(secure); - } - - GeckoResult res = new GeckoResult(); - - builder.setNegativeButton(android.R.string.cancel, /* listener */ null) - .setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - if ((flags & AuthPrompt.AuthOptions.Flags.ONLY_PASSWORD) == 0) { - res.complete(prompt.confirm(username.getText().toString(), - password.getText().toString())); - - } else { - res.complete(prompt.confirm(password.getText().toString())); - } - } - }); - createStandardDialog(builder, prompt, res).show(); - - return res; - } - - private static class ModifiableChoice { - public boolean modifiableSelected; - public String modifiableLabel; - public final ChoicePrompt.Choice choice; - - public ModifiableChoice(ChoicePrompt.Choice c) { - choice = c; - modifiableSelected = choice.selected; - modifiableLabel = choice.label; - } - } - - private void addChoiceItems(final int type, final ArrayAdapter list, - final ChoicePrompt.Choice[] items, final String indent) { - stopMedia(); - if (type == ChoicePrompt.Type.MENU) { - for (final ChoicePrompt.Choice item : items) { - list.add(new ModifiableChoice(item)); - } - return; - } - - for (final ChoicePrompt.Choice item : items) { - final ModifiableChoice modItem = new ModifiableChoice(item); - - final ChoicePrompt.Choice[] children = item.items; - - if (indent != null && children == null) { - modItem.modifiableLabel = indent + modItem.modifiableLabel; - } - list.add(modItem); - - if (children != null) { - final String newIndent; - if (type == ChoicePrompt.Type.SINGLE || type == ChoicePrompt.Type.MULTIPLE) { - newIndent = (indent != null) ? indent + '\t' : "\t"; - } else { - newIndent = null; - } - addChoiceItems(type, list, children, newIndent); - } - } - } - - private void onChoicePromptImpl(final GeckoSession session, final String title, - final String message, final int type, - final ChoicePrompt.Choice[] choices, final ChoicePrompt prompt, - final GeckoResult res) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - res.complete(prompt.dismiss()); - return; - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - addStandardLayout(builder, title, message); - - final ListView list = new ListView(builder.getContext()); - if (type == ChoicePrompt.Type.MULTIPLE) { - list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); - } - - final ArrayAdapter adapter = new ArrayAdapter( - builder.getContext(), android.R.layout.simple_list_item_1) { - private static final int TYPE_MENU_ITEM = 0; - private static final int TYPE_MENU_CHECK = 1; - private static final int TYPE_SEPARATOR = 2; - private static final int TYPE_GROUP = 3; - private static final int TYPE_SINGLE = 4; - private static final int TYPE_MULTIPLE = 5; - private static final int TYPE_COUNT = 6; - - private LayoutInflater mInflater; - private View mSeparator; - - @Override - public int getViewTypeCount() { - return TYPE_COUNT; - } - - @Override - public int getItemViewType(final int position) { - final ModifiableChoice item = getItem(position); - if (item.choice.separator) { - return TYPE_SEPARATOR; - } else if (type == ChoicePrompt.Type.MENU) { - return item.modifiableSelected ? TYPE_MENU_CHECK : TYPE_MENU_ITEM; - } else if (item.choice.items != null) { - return TYPE_GROUP; - } else if (type == ChoicePrompt.Type.SINGLE) { - return TYPE_SINGLE; - } else if (type == ChoicePrompt.Type.MULTIPLE) { - return TYPE_MULTIPLE; - } else { - throw new UnsupportedOperationException(); - } - } - - @Override - public boolean isEnabled(final int position) { - final ModifiableChoice item = getItem(position); - return !item.choice.separator && !item.choice.disabled && - ((type != ChoicePrompt.Type.SINGLE && - type != ChoicePrompt.Type.MULTIPLE) || - item.choice.items == null); - } - - @Override - public View getView(final int position, View view, - final ViewGroup parent) { - final int itemType = getItemViewType(position); - final int layoutId; - if (itemType == TYPE_SEPARATOR) { - if (mSeparator == null) { - mSeparator = new View(getContext()); - mSeparator.setLayoutParams(new ListView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, 2, itemType)); - final TypedArray attr = getContext().obtainStyledAttributes( - new int[]{android.R.attr.listDivider}); - mSeparator.setBackgroundResource(attr.getResourceId(0, 0)); - attr.recycle(); - } - return mSeparator; - } else if (itemType == TYPE_MENU_ITEM) { - layoutId = android.R.layout.simple_list_item_1; - } else if (itemType == TYPE_MENU_CHECK) { - layoutId = android.R.layout.simple_list_item_checked; - } else if (itemType == TYPE_GROUP) { - layoutId = android.R.layout.preference_category; - } else if (itemType == TYPE_SINGLE) { - layoutId = android.R.layout.simple_list_item_single_choice; - } else if (itemType == TYPE_MULTIPLE) { - layoutId = android.R.layout.simple_list_item_multiple_choice; - } else { - throw new UnsupportedOperationException(); - } - - if (view == null) { - if (mInflater == null) { - mInflater = LayoutInflater.from(builder.getContext()); - } - view = mInflater.inflate(layoutId, parent, false); - } - - final ModifiableChoice item = getItem(position); - final TextView text = (TextView) view; - text.setEnabled(!item.choice.disabled); - text.setText(item.modifiableLabel); - if (view instanceof CheckedTextView) { - final boolean selected = item.modifiableSelected; - if (itemType == TYPE_MULTIPLE) { - list.setItemChecked(position, selected); - } else { - ((CheckedTextView) view).setChecked(selected); - } - } - return view; - } - }; - addChoiceItems(type, adapter, choices, /* indent */ null); - - list.setAdapter(adapter); - builder.setView(list); - - final AlertDialog dialog; - if (type == ChoicePrompt.Type.SINGLE || type == ChoicePrompt.Type.MENU) { - dialog = createStandardDialog(builder, prompt, res); - list.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(final AdapterView parent, final View v, - final int position, final long id) { - final ModifiableChoice item = adapter.getItem(position); - if (type == ChoicePrompt.Type.MENU) { - final ChoicePrompt.Choice[] children = item.choice.items; - if (children != null) { - // Show sub-menu. - dialog.setOnDismissListener(null); - dialog.dismiss(); - onChoicePromptImpl(session, item.modifiableLabel, /* msg */ null, - type, children, prompt, res); - return; - } - } - res.complete(prompt.confirm(item.choice)); - dialog.dismiss(); - } - }); - } else if (type == ChoicePrompt.Type.MULTIPLE) { - list.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(final AdapterView parent, final View v, - final int position, final long id) { - final ModifiableChoice item = adapter.getItem(position); - item.modifiableSelected = ((CheckedTextView) v).isChecked(); - } - }); - builder.setNegativeButton(android.R.string.cancel, /* listener */ null) - .setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, - final int which) { - final int len = adapter.getCount(); - ArrayList items = new ArrayList<>(len); - for (int i = 0; i < len; i++) { - final ModifiableChoice item = adapter.getItem(i); - if (item.modifiableSelected) { - items.add(item.choice.id); - } - } - res.complete(prompt.confirm(items.toArray(new String[items.size()]))); - } - }); - dialog = createStandardDialog(builder, prompt, res); - } else { - throw new UnsupportedOperationException(); - } - try { - if(mActivity!=null && !mActivity.isFinishing()) - { - dialog.show(); - } - }catch (Exception ex){} - } - - @Override - public GeckoResult onChoicePrompt(final GeckoSession session, - final ChoicePrompt prompt) { - stopMedia(); - final GeckoResult res = new GeckoResult(); - onChoicePromptImpl(session, prompt.title, prompt.message, prompt.type, prompt.choices, - prompt, res); - return res; - } - - private static int parseColor(final String value, final int def) { - try { - return Color.parseColor(value); - } catch (final IllegalArgumentException e) { - return def; - } - } - - @Override - public GeckoResult onColorPrompt(final GeckoSession session, - final ColorPrompt prompt) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - return GeckoResult.fromValue(prompt.dismiss()); - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - addStandardLayout(builder, prompt.title, /* msg */ null); - - final int initial = parseColor(prompt.defaultValue, /* def */ 0); - final ArrayAdapter adapter = new ArrayAdapter( - builder.getContext(), android.R.layout.simple_list_item_1) { - private LayoutInflater mInflater; - - @Override - public int getViewTypeCount() { - return 2; - } - - @Override - public int getItemViewType(final int position) { - return (getItem(position) == initial) ? 1 : 0; - } - - @Override - public View getView(final int position, View view, - final ViewGroup parent) { - if (mInflater == null) { - mInflater = LayoutInflater.from(builder.getContext()); - } - final int color = getItem(position); - if (view == null) { - view = mInflater.inflate((color == initial) ? - android.R.layout.simple_list_item_checked : - android.R.layout.simple_list_item_1, parent, false); - } - view.setBackgroundResource(android.R.drawable.editbox_background); - view.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY); - return view; - } - }; - - adapter.addAll(0xffff4444 /* holo_red_light */, - 0xffcc0000 /* holo_red_dark */, - 0xffffbb33 /* holo_orange_light */, - 0xffff8800 /* holo_orange_dark */, - 0xff99cc00 /* holo_green_light */, - 0xff669900 /* holo_green_dark */, - 0xff33b5e5 /* holo_blue_light */, - 0xff0099cc /* holo_blue_dark */, - 0xffaa66cc /* holo_purple */, - 0xffffffff /* white */, - 0xffaaaaaa /* lighter_gray */, - 0xff555555 /* darker_gray */, - 0xff000000 /* black */); - - final ListView list = new ListView(builder.getContext()); - list.setAdapter(adapter); - builder.setView(list); - - GeckoResult res = new GeckoResult(); - - final AlertDialog dialog = createStandardDialog(builder, prompt, res); - list.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(final AdapterView parent, final View v, - final int position, final long id) { - res.complete(prompt.confirm(String.format("#%06x", 0xffffff & adapter.getItem(position)))); - dialog.dismiss(); - } - }); - dialog.show(); - - return res; - } - - private static Date parseDate(final SimpleDateFormat formatter, - final String value, - final boolean defaultToNow) { - try { - if (value != null && !value.isEmpty()) { - return formatter.parse(value); - } - } catch (final ParseException e) { - } - return defaultToNow ? new Date() : null; - } - - @SuppressWarnings("deprecation") - private static void setTimePickerTime(final TimePicker picker, final Calendar cal) { - if (Build.VERSION.SDK_INT >= 23) { - picker.setHour(cal.get(Calendar.HOUR_OF_DAY)); - picker.setMinute(cal.get(Calendar.MINUTE)); - } else { - picker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY)); - picker.setCurrentMinute(cal.get(Calendar.MINUTE)); - } - } - - @SuppressWarnings("deprecation") - private static void setCalendarTime(final Calendar cal, final TimePicker picker) { - if (Build.VERSION.SDK_INT >= 23) { - cal.set(Calendar.HOUR_OF_DAY, picker.getHour()); - cal.set(Calendar.MINUTE, picker.getMinute()); - } else { - cal.set(Calendar.HOUR_OF_DAY, picker.getCurrentHour()); - cal.set(Calendar.MINUTE, picker.getCurrentMinute()); - } - } - - @Override - public GeckoResult onDateTimePrompt(final GeckoSession session, - final DateTimePrompt prompt) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - return GeckoResult.fromValue(prompt.dismiss()); - } - final String format; - if (prompt.type == DateTimePrompt.Type.DATE) { - format = "yyyy-MM-dd"; - } else if (prompt.type == DateTimePrompt.Type.MONTH) { - format = "yyyy-MM"; - } else if (prompt.type == DateTimePrompt.Type.WEEK) { - format = "yyyy-'W'ww"; - } else if (prompt.type == DateTimePrompt.Type.TIME) { - format = "HH:mm"; - } else if (prompt.type == DateTimePrompt.Type.DATETIME_LOCAL) { - format = "yyyy-MM-dd'T'HH:mm"; - } else { - throw new UnsupportedOperationException(); - } - - final SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ROOT); - final Date minDate = parseDate(formatter, prompt.minValue, /* defaultToNow */ false); - final Date maxDate = parseDate(formatter, prompt.maxValue, /* defaultToNow */ false); - final Date date = parseDate(formatter, prompt.defaultValue, /* defaultToNow */ true); - final Calendar cal = formatter.getCalendar(); - cal.setTime(date); - - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - final LayoutInflater inflater = LayoutInflater.from(builder.getContext()); - final DatePicker datePicker; - if (prompt.type == DateTimePrompt.Type.DATE || prompt.type == DateTimePrompt.Type.MONTH || - prompt.type == DateTimePrompt.Type.WEEK || prompt.type == DateTimePrompt.Type.DATETIME_LOCAL) { - final int resId = builder.getContext().getResources().getIdentifier( - "date_picker_dialog", "layout", "android"); - DatePicker picker = null; - if (resId != 0) { - try { - picker = (DatePicker) inflater.inflate(resId, /* root */ null); - } catch (final ClassCastException | InflateException e) { - } - } - if (picker == null) { - picker = new DatePicker(builder.getContext()); - } - picker.init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), - cal.get(Calendar.DAY_OF_MONTH), /* listener */ null); - if (minDate != null) { - picker.setMinDate(minDate.getTime()); - } - if (maxDate != null) { - picker.setMaxDate(maxDate.getTime()); - } - datePicker = picker; - } else { - datePicker = null; - } - - final TimePicker timePicker; - if (prompt.type == DateTimePrompt.Type.TIME || prompt.type == DateTimePrompt.Type.DATETIME_LOCAL) { - final int resId = builder.getContext().getResources().getIdentifier( - "time_picker_dialog", "layout", "android"); - TimePicker picker = null; - if (resId != 0) { - try { - picker = (TimePicker) inflater.inflate(resId, /* root */ null); - } catch (final ClassCastException | InflateException e) { - } - } - if (picker == null) { - picker = new TimePicker(builder.getContext()); - } - setTimePickerTime(picker, cal); - picker.setIs24HourView(DateFormat.is24HourFormat(builder.getContext())); - timePicker = picker; - } else { - timePicker = null; - } - - final LinearLayout container = addStandardLayout(builder, prompt.title, /* msg */ null); - container.setPadding(/* left */ 0, /* top */ 0, /* right */ 0, /* bottom */ 0); - if (datePicker != null) { - container.addView(datePicker); - } - if (timePicker != null) { - container.addView(timePicker); - } - - GeckoResult res = new GeckoResult(); - - final DialogInterface.OnClickListener listener = - new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - if (which == DialogInterface.BUTTON_NEUTRAL) { - // Clear - res.complete(prompt.confirm("")); - return; - } - if (datePicker != null) { - cal.set(datePicker.getYear(), datePicker.getMonth(), - datePicker.getDayOfMonth()); - } - if (timePicker != null) { - setCalendarTime(cal, timePicker); - } - res.complete(prompt.confirm(formatter.format(cal.getTime()))); - } - }; - builder.setNegativeButton(android.R.string.cancel, /* listener */ null) - .setNeutralButton("Clear", listener) - .setPositiveButton(android.R.string.ok, listener); - createStandardDialog(builder, prompt, res).show(); - - return res; - } - - @Override - @TargetApi(19) - public GeckoResult onFilePrompt(GeckoSession session, FilePrompt prompt) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - return GeckoResult.fromValue(prompt.dismiss()); - } - - // Merge all given MIME types into one, using wildcard if needed. - String mimeType = null; - String mimeSubtype = null; - if (prompt.mimeTypes != null) { - for (final String rawType : prompt.mimeTypes) { - final String normalizedType = rawType.trim().toLowerCase(Locale.ROOT); - final int len = normalizedType.length(); - int slash = normalizedType.indexOf('/'); - if (slash < 0) { - slash = len; - } - final String newType = normalizedType.substring(0, slash); - final String newSubtype = normalizedType.substring(Math.min(slash + 1, len)); - if (mimeType == null) { - mimeType = newType; - } else if (!mimeType.equals(newType)) { - mimeType = "*"; - } - if (mimeSubtype == null) { - mimeSubtype = newSubtype; - } else if (!mimeSubtype.equals(newSubtype)) { - mimeSubtype = "*"; - } - } - } - - final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); - intent.setType((mimeType != null ? mimeType : "*") + '/' + - (mimeSubtype != null ? mimeSubtype : "*")); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); - if (Build.VERSION.SDK_INT >= 18 && prompt.type == FilePrompt.Type.MULTIPLE) { - intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); - } - if (Build.VERSION.SDK_INT >= 19 && prompt.mimeTypes.length > 0) { - intent.putExtra(Intent.EXTRA_MIME_TYPES, prompt.mimeTypes); - } - - GeckoResult res = new GeckoResult(); - - try { - mFileResponse = res; - mFilePrompt = prompt; - activity.startActivityForResult(intent, filePickerRequestCode); - } catch (final ActivityNotFoundException e) { - Log.e(LOGTAG, "Cannot launch activity", e); - return GeckoResult.fromValue(prompt.dismiss()); - } - - return res; - } - - public void onFileCallbackResult(final int resultCode, final Intent data) { - stopMedia(); - if (mFileResponse == null) { - return; - } - - final GeckoResult res = mFileResponse; - mFileResponse = null; - - final FilePrompt prompt = mFilePrompt; - mFilePrompt = null; - - if (resultCode != Activity.RESULT_OK || data == null) { - res.complete(prompt.dismiss()); - return; - } - - final Uri uri = data.getData(); - final ClipData clip = data.getClipData(); - - if (prompt.type == FilePrompt.Type.SINGLE || - (prompt.type == FilePrompt.Type.MULTIPLE && clip == null)) { - res.complete(prompt.confirm(mActivity, uri)); - } else if (prompt.type == FilePrompt.Type.MULTIPLE) { - if (clip == null) { - Log.w(LOGTAG, "No selected file"); - res.complete(prompt.dismiss()); - return; - } - final int count = clip.getItemCount(); - final ArrayList uris = new ArrayList<>(count); - for (int i = 0; i < count; i++) { - uris.add(clip.getItemAt(i).getUri()); - } - res.complete(prompt.confirm(mActivity, uris.toArray(new Uri[uris.size()]))); - } - } - - public void onPermissionPrompt(final GeckoSession session, final String title, - final GeckoSession.PermissionDelegate.Callback callback) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - callback.reject(); - return; - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(title) - .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - callback.reject(); - } - }) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - callback.grant(); - } - }); - - final AlertDialog dialog = builder.create(); - dialog.show(); - } - - public void onSlowScriptPrompt(GeckoSession geckoSession, String title, GeckoResult reportAction) { - stopMedia(); - final Activity activity = mActivity; - if (activity == null) { - return; - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(title) - .setNegativeButton("Wait", new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - reportAction.complete(SlowScriptResponse.CONTINUE); - } - }) - .setPositiveButton("Stop", new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - reportAction.complete(SlowScriptResponse.STOP); - } - }); - - final AlertDialog dialog = builder.create(); - dialog.show(); - } - - private Spinner addMediaSpinner(final Context context, final ViewGroup container, - final GeckoSession.PermissionDelegate.MediaSource[] sources, final String[] sourceNames) { - final ArrayAdapter adapter = new ArrayAdapter( - context, android.R.layout.simple_spinner_item) { - private View convertView(final int position, final View view) { - if (view != null) { - final GeckoSession.PermissionDelegate.MediaSource item = getItem(position); - ((TextView) view).setText(sourceNames != null ? sourceNames[position] : "media"); - } - return view; - } - - @Override - public View getView(final int position, View view, - final ViewGroup parent) { - return convertView(position, super.getView(position, view, parent)); - } - - @Override - public View getDropDownView(final int position, final View view, - final ViewGroup parent) { - return convertView(position, super.getDropDownView(position, view, parent)); - } - }; - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - adapter.addAll(sources); - - final Spinner spinner = new Spinner(context); - spinner.setAdapter(adapter); - spinner.setSelection(0); - container.addView(spinner); - return spinner; - } - - public void onMediaPrompt(final GeckoSession session, final String title, - final GeckoSession.PermissionDelegate.MediaSource[] video, final GeckoSession.PermissionDelegate.MediaSource[] audio, - final String[] videoNames, final String[] audioNames, - final GeckoSession.PermissionDelegate.MediaCallback callback) { - final Activity activity = mActivity; - stopMedia(); - if (activity == null || (video == null && audio == null)) { - callback.reject(); - return; - } - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - final LinearLayout container = addStandardLayout(builder, title, /* msg */ null); - - final Spinner videoSpinner; - if (video != null) { - videoSpinner = addMediaSpinner(builder.getContext(), container, video, videoNames); - } else { - videoSpinner = null; - } - - final Spinner audioSpinner; - if (audio != null) { - audioSpinner = addMediaSpinner(builder.getContext(), container, audio, audioNames); - } else { - audioSpinner = null; - } - - builder.setNegativeButton(android.R.string.cancel, /* listener */ null) - .setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - final GeckoSession.PermissionDelegate.MediaSource video = (videoSpinner != null) - ? (GeckoSession.PermissionDelegate.MediaSource) videoSpinner.getSelectedItem() : null; - final GeckoSession.PermissionDelegate.MediaSource audio = (audioSpinner != null) - ? (GeckoSession.PermissionDelegate.MediaSource) audioSpinner.getSelectedItem() : null; - callback.grant(video, audio); - } - }); - - final AlertDialog dialog = builder.create(); - dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(final DialogInterface dialog) { - callback.reject(); - } - }); - dialog.show(); - } - - public void onMediaPrompt(final GeckoSession session, final String title, - final GeckoSession.PermissionDelegate.MediaSource[] video, final GeckoSession.PermissionDelegate.MediaSource[] audio, - final GeckoSession.PermissionDelegate.MediaCallback callback) { - stopMedia(); - onMediaPrompt(session, title, video, audio, null, null, callback); - } - - @Override - public GeckoResult onPopupPrompt(final GeckoSession session, - final PopupPrompt prompt) { - stopMedia(); - return GeckoResult.fromValue(prompt.confirm(AllowOrDeny.ALLOW)); - } +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.ActivityNotFoundException; +import android.content.ClipData; +import android.content.ContentResolver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.res.TypedArray; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.net.Uri; +import android.os.Build; +import android.text.InputType; +import android.text.format.DateFormat; +import android.util.Log; +import android.view.InflateException; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.MimeTypeMap; +import android.widget.ArrayAdapter; +import android.widget.CheckedTextView; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.ScrollView; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.TimePicker; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ShareCompat; +import com.hiddenservices.onionservices.appManager.activityContextManager; +import java.io.File; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; +import org.mozilla.geckoview.AllowOrDeny; +import org.mozilla.geckoview.GeckoResult; +import org.mozilla.geckoview.GeckoSession; +import org.mozilla.geckoview.SlowScriptResponse; + +public final class promptDelegate implements GeckoSession.PromptDelegate { + + private final AppCompatActivity mActivity; + private GeckoResult mFileResponse; + private FilePrompt mFilePrompt; + + static final String LOGTAG = "BasicGeckoViewPrompt"; + public int filePickerRequestCode = 1; + + public promptDelegate(final AppCompatActivity activity) { + mActivity = activity; + } + + public void stopMedia(){ + try { + activityContextManager.getInstance().getHomeController().onKillMedia(); + }catch (Exception ex){} + } + + @Override + public GeckoResult onAlertPrompt(@NonNull final GeckoSession session, + @NonNull final AlertPrompt prompt) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + return GeckoResult.fromValue(prompt.dismiss()); + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity) + .setTitle(prompt.title) + .setMessage(prompt.message) + .setPositiveButton(android.R.string.ok, null); + GeckoResult res = new GeckoResult<>(); + createStandardDialog(builder, prompt, res).show(); + return res; + } + + @Override + public GeckoResult onButtonPrompt(@NonNull final GeckoSession session, + @NonNull final ButtonPrompt prompt) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + return GeckoResult.fromValue(prompt.dismiss()); + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity) + .setTitle(prompt.title) + .setMessage(prompt.message); + + GeckoResult res = new GeckoResult<>(); + + final DialogInterface.OnClickListener listener = + (dialog, which) -> { + if (which == DialogInterface.BUTTON_POSITIVE) { + res.complete(prompt.confirm(ButtonPrompt.Type.POSITIVE)); + } else if (which == DialogInterface.BUTTON_NEGATIVE) { + res.complete(prompt.confirm(ButtonPrompt.Type.NEGATIVE)); + } else { + res.complete(prompt.dismiss()); + } + }; + + builder.setPositiveButton(android.R.string.ok, listener); + builder.setNegativeButton(android.R.string.cancel, listener); + + createStandardDialog(builder, prompt, res).show(); + return res; + } + + public static String getMimeType(Context context, Uri uri) { + String extension; + + //Check uri format to avoid null + if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { + //If scheme is a content + final MimeTypeMap mime = MimeTypeMap.getSingleton(); + extension = mime.getExtensionFromMimeType(context.getContentResolver().getType(uri)); + } else { + //If scheme is a File + //This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file name with spaces and special characters. + extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString()); + + } + + return extension; + } + + static boolean mPopupOpened = false; + @Override + public GeckoResult onSharePrompt(@NonNull final GeckoSession session, + @NonNull final SharePrompt prompt) { + stopMedia(); + new Thread(){ + public void run(){ + try { + sleep(4000); + mPopupOpened = false; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }.start(); + if(!mPopupOpened){ + mPopupOpened = true; + }else { + return GeckoResult.fromValue(prompt.confirm(SharePrompt.Result.ABORT)); + } + try { + String m_data = prompt.uri; + if(prompt.text!=null){ + m_data += " : " + prompt.text; + } + + ShareCompat.IntentBuilder.from(mActivity) + .setType("text/x-uri") + .setChooserTitle(prompt.title) + .setText(m_data) + .startChooser(); + }catch (Exception ex){} + + return GeckoResult.fromValue(prompt.confirm(SharePrompt.Result.SUCCESS)); + + } + + @Nullable + @Override + public GeckoResult onRepostConfirmPrompt(@NonNull final GeckoSession session, + @NonNull final RepostConfirmPrompt prompt) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + return GeckoResult.fromValue(prompt.dismiss()); + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity) + .setTitle("Are you sure?") + .setMessage("To display this page, GeckoViewExample must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."); + + GeckoResult res = new GeckoResult<>(); + + final DialogInterface.OnClickListener listener = (dialog, which) -> { + if (which == DialogInterface.BUTTON_POSITIVE) { + res.complete(prompt.confirm(AllowOrDeny.ALLOW)); + } else if (which == DialogInterface.BUTTON_NEGATIVE) { + res.complete(prompt.confirm(AllowOrDeny.DENY)); + } else { + res.complete(prompt.dismiss()); + } + }; + + builder.setPositiveButton("Resend", listener); + builder.setNegativeButton("Cancel", listener); + + try { + if(mActivity!=null && !mActivity.isFinishing()) + { + createStandardDialog(builder, prompt, res).show(); + } + }catch (Exception ex){} + return res; + } + + @Nullable + @Override + public GeckoResult onBeforeUnloadPrompt(@NonNull final GeckoSession session, + @NonNull final BeforeUnloadPrompt prompt) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + return GeckoResult.fromValue(prompt.dismiss()); + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity) + .setTitle("Are you sure?") + .setMessage("This page is asking you to confirm that you want to leave - data you have entered may not be saved"); + + GeckoResult res = new GeckoResult<>(); + + final DialogInterface.OnClickListener listener = (dialog, which) -> { + if (which == DialogInterface.BUTTON_POSITIVE) { + res.complete(prompt.confirm(AllowOrDeny.ALLOW)); + } else if (which == DialogInterface.BUTTON_NEGATIVE) { + res.complete(prompt.confirm(AllowOrDeny.DENY)); + } else { + res.complete(prompt.dismiss()); + } + }; + + builder.setPositiveButton("Leave Page", listener); + builder.setNegativeButton("Stay on Page", listener); + + createStandardDialog(builder, prompt, res).show(); + return res; + } + + private int getViewPadding(final AlertDialog.Builder builder) { + stopMedia(); + final TypedArray attr = builder.getContext().obtainStyledAttributes( + new int[]{android.R.attr.listPreferredItemPaddingLeft}); + final int padding = attr.getDimensionPixelSize(0, 1); + attr.recycle(); + return padding; + } + + private LinearLayout addStandardLayout(final AlertDialog.Builder builder, + final String title, final String msg) { + stopMedia(); + final ScrollView scrollView = new ScrollView(builder.getContext()); + final LinearLayout container = new LinearLayout(builder.getContext()); + final int horizontalPadding = getViewPadding(builder); + final int verticalPadding = (msg == null || msg.isEmpty()) ? horizontalPadding : 0; + container.setOrientation(LinearLayout.VERTICAL); + container.setPadding(/* left */ horizontalPadding, /* top */ verticalPadding, + /* right */ horizontalPadding, /* bottom */ verticalPadding); + scrollView.addView(container); + builder.setTitle(title) + .setMessage(msg) + .setView(scrollView); + return container; + } + + private AlertDialog createStandardDialog(final AlertDialog.Builder builder, + final BasePrompt prompt, + final GeckoResult response) { + final AlertDialog dialog = builder.create(); + stopMedia(); + dialog.setOnDismissListener(dialog1 -> { + if (!prompt.isComplete()) { + response.complete(prompt.dismiss()); + } + }); + return dialog; + } + + @Override + public GeckoResult onTextPrompt(@NonNull final GeckoSession session, + @NonNull final TextPrompt prompt) { + final Activity activity = mActivity; + stopMedia(); + if (activity == null) { + return GeckoResult.fromValue(prompt.dismiss()); + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + final LinearLayout container = addStandardLayout(builder, prompt.title, prompt.message); + final EditText editText = new EditText(builder.getContext()); + editText.setText(prompt.defaultValue); + container.addView(editText); + + GeckoResult res = new GeckoResult<>(); + + builder.setNegativeButton(android.R.string.cancel, /* listener */ null) + .setPositiveButton(android.R.string.ok, + (dialog, which) -> res.complete(prompt.confirm(editText.getText().toString()))); + + createStandardDialog(builder, prompt, res).show(); + return res; + } + + @Override + public GeckoResult onAuthPrompt(@NonNull final GeckoSession session, + @NonNull final AuthPrompt prompt) { + final Activity activity = mActivity; + stopMedia(); + if (activity == null) { + return GeckoResult.fromValue(prompt.dismiss()); + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + final LinearLayout container = addStandardLayout(builder, prompt.title, prompt.message); + + final int flags = prompt.authOptions.flags; + final int level = prompt.authOptions.level; + final EditText username; + if ((flags & AuthPrompt.AuthOptions.Flags.ONLY_PASSWORD) == 0) { + username = new EditText(builder.getContext()); + username.setHint("Username"); + username.setText(prompt.authOptions.username); + container.addView(username); + } else { + username = null; + } + + final EditText password = new EditText(builder.getContext()); + password.setHint("Password"); + password.setText(prompt.authOptions.password); + password.setInputType(InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_PASSWORD); + container.addView(password); + + if (level != AuthPrompt.AuthOptions.Level.NONE) { + final ImageView secure = new ImageView(builder.getContext()); + secure.setImageResource(android.R.drawable.ic_lock_lock); + container.addView(secure); + } + + GeckoResult res = new GeckoResult<>(); + + builder.setNegativeButton(android.R.string.cancel, /* listener */ null) + .setPositiveButton(android.R.string.ok, + (dialog, which) -> { + if ((flags & AuthPrompt.AuthOptions.Flags.ONLY_PASSWORD) == 0) { + res.complete(prompt.confirm(username.getText().toString(), + password.getText().toString())); + + } else { + res.complete(prompt.confirm(password.getText().toString())); + } + }); + createStandardDialog(builder, prompt, res).show(); + + return res; + } + + private static class ModifiableChoice { + public boolean modifiableSelected; + public String modifiableLabel; + public final ChoicePrompt.Choice choice; + + public ModifiableChoice(ChoicePrompt.Choice c) { + choice = c; + modifiableSelected = choice.selected; + modifiableLabel = choice.label; + } + } + + private void addChoiceItems(final int type, final ArrayAdapter list, + final ChoicePrompt.Choice[] items, final String indent) { + stopMedia(); + if (type == ChoicePrompt.Type.MENU) { + for (final ChoicePrompt.Choice item : items) { + list.add(new ModifiableChoice(item)); + } + return; + } + + for (final ChoicePrompt.Choice item : items) { + final ModifiableChoice modItem = new ModifiableChoice(item); + + final ChoicePrompt.Choice[] children = item.items; + + if (indent != null && children == null) { + modItem.modifiableLabel = indent + modItem.modifiableLabel; + } + list.add(modItem); + + if (children != null) { + final String newIndent; + if (type == ChoicePrompt.Type.SINGLE || type == ChoicePrompt.Type.MULTIPLE) { + newIndent = (indent != null) ? indent + '\t' : "\t"; + } else { + newIndent = null; + } + addChoiceItems(type, list, children, newIndent); + } + } + } + + private void onChoicePromptImpl(final String title, + final String message, final int type, + final ChoicePrompt.Choice[] choices, final ChoicePrompt prompt, + final GeckoResult res) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + res.complete(prompt.dismiss()); + return; + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + addStandardLayout(builder, title, message); + + final ListView list = new ListView(builder.getContext()); + if (type == ChoicePrompt.Type.MULTIPLE) { + list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + } + + final ArrayAdapter adapter = new ArrayAdapter( + builder.getContext(), android.R.layout.simple_list_item_1) { + private static final int TYPE_MENU_ITEM = 0; + private static final int TYPE_MENU_CHECK = 1; + private static final int TYPE_SEPARATOR = 2; + private static final int TYPE_GROUP = 3; + private static final int TYPE_SINGLE = 4; + private static final int TYPE_MULTIPLE = 5; + private static final int TYPE_COUNT = 6; + + private LayoutInflater mInflater; + private View mSeparator; + + @Override + public int getViewTypeCount() { + return TYPE_COUNT; + } + + @Override + public int getItemViewType(final int position) { + final ModifiableChoice item = getItem(position); + if (item.choice.separator) { + return TYPE_SEPARATOR; + } else if (type == ChoicePrompt.Type.MENU) { + return item.modifiableSelected ? TYPE_MENU_CHECK : TYPE_MENU_ITEM; + } else if (item.choice.items != null) { + return TYPE_GROUP; + } else if (type == ChoicePrompt.Type.SINGLE) { + return TYPE_SINGLE; + } else if (type == ChoicePrompt.Type.MULTIPLE) { + return TYPE_MULTIPLE; + } else { + throw new UnsupportedOperationException(); + } + } + + @Override + public boolean isEnabled(final int position) { + final ModifiableChoice item = getItem(position); + return !item.choice.separator && !item.choice.disabled && + ((type != ChoicePrompt.Type.SINGLE && + type != ChoicePrompt.Type.MULTIPLE) || + item.choice.items == null); + } + + @Override + public View getView(final int position, View view, + final ViewGroup parent) { + final int itemType = getItemViewType(position); + final int layoutId; + if (itemType == TYPE_SEPARATOR) { + if (mSeparator == null) { + mSeparator = new View(getContext()); + mSeparator.setLayoutParams(new ListView.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, 2, itemType)); + final TypedArray attr = getContext().obtainStyledAttributes( + new int[]{android.R.attr.listDivider}); + mSeparator.setBackgroundResource(attr.getResourceId(0, 0)); + attr.recycle(); + } + return mSeparator; + } else if (itemType == TYPE_MENU_ITEM) { + layoutId = android.R.layout.simple_list_item_1; + } else if (itemType == TYPE_MENU_CHECK) { + layoutId = android.R.layout.simple_list_item_checked; + } else if (itemType == TYPE_GROUP) { + layoutId = android.R.layout.preference_category; + } else if (itemType == TYPE_SINGLE) { + layoutId = android.R.layout.simple_list_item_single_choice; + } else if (itemType == TYPE_MULTIPLE) { + layoutId = android.R.layout.simple_list_item_multiple_choice; + } else { + throw new UnsupportedOperationException(); + } + + if (view == null) { + if (mInflater == null) { + mInflater = LayoutInflater.from(builder.getContext()); + } + view = mInflater.inflate(layoutId, parent, false); + } + + final ModifiableChoice item = getItem(position); + final TextView text = (TextView) view; + text.setEnabled(!item.choice.disabled); + text.setText(item.modifiableLabel); + if (view instanceof CheckedTextView) { + final boolean selected = item.modifiableSelected; + if (itemType == TYPE_MULTIPLE) { + list.setItemChecked(position, selected); + } else { + ((CheckedTextView) view).setChecked(selected); + } + } + return view; + } + }; + addChoiceItems(type, adapter, choices, /* indent */ null); + + list.setAdapter(adapter); + builder.setView(list); + + final AlertDialog dialog; + if (type == ChoicePrompt.Type.SINGLE || type == ChoicePrompt.Type.MENU) { + dialog = createStandardDialog(builder, prompt, res); + list.setOnItemClickListener((parent, v, position, id) -> { + final ModifiableChoice item = adapter.getItem(position); + if (type == ChoicePrompt.Type.MENU) { + final ChoicePrompt.Choice[] children = item.choice.items; + if (children != null) { + // Show sub-menu. + dialog.setOnDismissListener(null); + dialog.dismiss(); + onChoicePromptImpl(item.modifiableLabel, /* msg */ null, + type, children, prompt, res); + return; + } + } + res.complete(prompt.confirm(item.choice)); + dialog.dismiss(); + }); + } else if (type == ChoicePrompt.Type.MULTIPLE) { + list.setOnItemClickListener((parent, v, position, id) -> { + final ModifiableChoice item = adapter.getItem(position); + item.modifiableSelected = ((CheckedTextView) v).isChecked(); + }); + builder.setNegativeButton(android.R.string.cancel, /* listener */ null) + .setPositiveButton(android.R.string.ok, + (dialog1, which) -> { + final int len = adapter.getCount(); + ArrayList items = new ArrayList<>(len); + for (int i = 0; i < len; i++) { + final ModifiableChoice item = adapter.getItem(i); + if (item.modifiableSelected) { + items.add(item.choice.id); + } + } + res.complete(prompt.confirm(items.toArray(new String[0]))); + }); + dialog = createStandardDialog(builder, prompt, res); + } else { + throw new UnsupportedOperationException(); + } + try { + if(mActivity!=null && !mActivity.isFinishing()) + { + dialog.show(); + } + }catch (Exception ex){} + } + + @Override + public GeckoResult onChoicePrompt(@NonNull final GeckoSession session, + @NonNull final ChoicePrompt prompt) { + stopMedia(); + final GeckoResult res = new GeckoResult<>(); + onChoicePromptImpl(prompt.title, prompt.message, prompt.type, prompt.choices, + prompt, res); + return res; + } + + private static int parseColor(final String value, final int def) { + try { + return Color.parseColor(value); + } catch (final IllegalArgumentException e) { + return def; + } + } + + @Override + public GeckoResult onColorPrompt(@NonNull final GeckoSession session, + @NonNull final ColorPrompt prompt) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + return GeckoResult.fromValue(prompt.dismiss()); + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + addStandardLayout(builder, prompt.title, /* msg */ null); + + final int initial = parseColor(prompt.defaultValue, /* def */ 0); + final ArrayAdapter adapter = new ArrayAdapter( + builder.getContext(), android.R.layout.simple_list_item_1) { + private LayoutInflater mInflater; + + @Override + public int getViewTypeCount() { + return 2; + } + + @Override + public int getItemViewType(final int position) { + return (getItem(position) == initial) ? 1 : 0; + } + + @Override + public View getView(final int position, View view, + final ViewGroup parent) { + if (mInflater == null) { + mInflater = LayoutInflater.from(builder.getContext()); + } + final int color = getItem(position); + if (view == null) { + view = mInflater.inflate((color == initial) ? + android.R.layout.simple_list_item_checked : + android.R.layout.simple_list_item_1, parent, false); + } + view.setBackgroundResource(android.R.drawable.editbox_background); + view.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY); + return view; + } + }; + + adapter.addAll(0xffff4444 /* holo_red_light */, + 0xffcc0000 /* holo_red_dark */, + 0xffffbb33 /* holo_orange_light */, + 0xffff8800 /* holo_orange_dark */, + 0xff99cc00 /* holo_green_light */, + 0xff669900 /* holo_green_dark */, + 0xff33b5e5 /* holo_blue_light */, + 0xff0099cc /* holo_blue_dark */, + 0xffaa66cc /* holo_purple */, + 0xffffffff /* white */, + 0xffaaaaaa /* lighter_gray */, + 0xff555555 /* darker_gray */, + 0xff000000 /* black */); + + final ListView list = new ListView(builder.getContext()); + list.setAdapter(adapter); + builder.setView(list); + + GeckoResult res = new GeckoResult<>(); + + final AlertDialog dialog = createStandardDialog(builder, prompt, res); + list.setOnItemClickListener((parent, v, position, id) -> { + res.complete(prompt.confirm(String.format("#%06x", 0xffffff & adapter.getItem(position)))); + dialog.dismiss(); + }); + dialog.show(); + + return res; + } + + private static Date parseDate(final SimpleDateFormat formatter, + final String value, + final boolean defaultToNow) { + try { + if (value != null && !value.isEmpty()) { + return formatter.parse(value); + } + } catch (final ParseException e) { + } + return defaultToNow ? new Date() : null; + } + + @SuppressWarnings("deprecation") + private static void setTimePickerTime(final TimePicker picker, final Calendar cal) { + if (Build.VERSION.SDK_INT >= 23) { + picker.setHour(cal.get(Calendar.HOUR_OF_DAY)); + picker.setMinute(cal.get(Calendar.MINUTE)); + } else { + picker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY)); + picker.setCurrentMinute(cal.get(Calendar.MINUTE)); + } + } + + @SuppressWarnings("deprecation") + private static void setCalendarTime(final Calendar cal, final TimePicker picker) { + if (Build.VERSION.SDK_INT >= 23) { + cal.set(Calendar.HOUR_OF_DAY, picker.getHour()); + cal.set(Calendar.MINUTE, picker.getMinute()); + } else { + cal.set(Calendar.HOUR_OF_DAY, picker.getCurrentHour()); + cal.set(Calendar.MINUTE, picker.getCurrentMinute()); + } + } + + @Override + public GeckoResult onDateTimePrompt(@NonNull final GeckoSession session, + @NonNull final DateTimePrompt prompt) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + return GeckoResult.fromValue(prompt.dismiss()); + } + final String format; + if (prompt.type == DateTimePrompt.Type.DATE) { + format = "yyyy-MM-dd"; + } else if (prompt.type == DateTimePrompt.Type.MONTH) { + format = "yyyy-MM"; + } else if (prompt.type == DateTimePrompt.Type.WEEK) { + format = "yyyy-'W'ww"; + } else if (prompt.type == DateTimePrompt.Type.TIME) { + format = "HH:mm"; + } else if (prompt.type == DateTimePrompt.Type.DATETIME_LOCAL) { + format = "yyyy-MM-dd'T'HH:mm"; + } else { + throw new UnsupportedOperationException(); + } + + final SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ROOT); + final Date minDate = parseDate(formatter, prompt.minValue, /* defaultToNow */ false); + final Date maxDate = parseDate(formatter, prompt.maxValue, /* defaultToNow */ false); + final Date date = parseDate(formatter, prompt.defaultValue, /* defaultToNow */ true); + final Calendar cal = formatter.getCalendar(); + cal.setTime(date); + + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + final LayoutInflater inflater = LayoutInflater.from(builder.getContext()); + final DatePicker datePicker; + if (prompt.type == DateTimePrompt.Type.DATE || prompt.type == DateTimePrompt.Type.MONTH || + prompt.type == DateTimePrompt.Type.WEEK || prompt.type == DateTimePrompt.Type.DATETIME_LOCAL) { + @SuppressLint("DiscouragedApi") final int resId = builder.getContext().getResources().getIdentifier( + "date_picker_dialog", "layout", "android"); + DatePicker picker = null; + if (resId != 0) { + try { + picker = (DatePicker) inflater.inflate(resId, /* root */ null); + } catch (final ClassCastException | InflateException e) { + } + } + if (picker == null) { + picker = new DatePicker(builder.getContext()); + } + picker.init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), + cal.get(Calendar.DAY_OF_MONTH), /* listener */ null); + if (minDate != null) { + picker.setMinDate(minDate.getTime()); + } + if (maxDate != null) { + picker.setMaxDate(maxDate.getTime()); + } + datePicker = picker; + } else { + datePicker = null; + } + + final TimePicker timePicker; + if (prompt.type == DateTimePrompt.Type.TIME || prompt.type == DateTimePrompt.Type.DATETIME_LOCAL) { + @SuppressLint("DiscouragedApi") final int resId = builder.getContext().getResources().getIdentifier( + "time_picker_dialog", "layout", "android"); + TimePicker picker = null; + if (resId != 0) { + try { + picker = (TimePicker) inflater.inflate(resId, /* root */ null); + } catch (final ClassCastException | InflateException e) { + } + } + if (picker == null) { + picker = new TimePicker(builder.getContext()); + } + setTimePickerTime(picker, cal); + picker.setIs24HourView(DateFormat.is24HourFormat(builder.getContext())); + timePicker = picker; + } else { + timePicker = null; + } + + final LinearLayout container = addStandardLayout(builder, prompt.title, /* msg */ null); + container.setPadding(/* left */ 0, /* top */ 0, /* right */ 0, /* bottom */ 0); + if (datePicker != null) { + container.addView(datePicker); + } + if (timePicker != null) { + container.addView(timePicker); + } + + GeckoResult res = new GeckoResult<>(); + + final DialogInterface.OnClickListener listener = + (dialog, which) -> { + if (which == DialogInterface.BUTTON_NEUTRAL) { + // Clear + res.complete(prompt.confirm("")); + return; + } + if (datePicker != null) { + cal.set(datePicker.getYear(), datePicker.getMonth(), + datePicker.getDayOfMonth()); + } + if (timePicker != null) { + setCalendarTime(cal, timePicker); + } + res.complete(prompt.confirm(formatter.format(cal.getTime()))); + }; + builder.setNegativeButton(android.R.string.cancel, /* listener */ null) + .setNeutralButton("Clear", listener) + .setPositiveButton(android.R.string.ok, listener); + createStandardDialog(builder, prompt, res).show(); + + return res; + } + + @Override + public GeckoResult onFilePrompt(@NonNull GeckoSession session, @NonNull FilePrompt prompt) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + return GeckoResult.fromValue(prompt.dismiss()); + } + + // Merge all given MIME types into one, using wildcard if needed. + String mimeType = null; + String mimeSubtype = null; + if (prompt.mimeTypes != null) { + for (final String rawType : prompt.mimeTypes) { + final String normalizedType = rawType.trim().toLowerCase(Locale.ROOT); + final int len = normalizedType.length(); + int slash = normalizedType.indexOf('/'); + if (slash < 0) { + slash = len; + } + final String newType = normalizedType.substring(0, slash); + final String newSubtype = normalizedType.substring(Math.min(slash + 1, len)); + if (mimeType == null) { + mimeType = newType; + } else if (!mimeType.equals(newType)) { + mimeType = "*"; + } + if (mimeSubtype == null) { + mimeSubtype = newSubtype; + } else if (!mimeSubtype.equals(newSubtype)) { + mimeSubtype = "*"; + } + } + } + + final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType((mimeType != null ? mimeType : "*") + '/' + + (mimeSubtype != null ? mimeSubtype : "*")); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); + if (prompt.type == FilePrompt.Type.MULTIPLE) { + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + } + if (prompt.mimeTypes.length > 0) { + intent.putExtra(Intent.EXTRA_MIME_TYPES, prompt.mimeTypes); + } + + GeckoResult res = new GeckoResult<>(); + + try { + mFileResponse = res; + mFilePrompt = prompt; + activity.startActivityForResult(intent, filePickerRequestCode); + } catch (final ActivityNotFoundException e) { + Log.e(LOGTAG, "Cannot launch activity", e); + return GeckoResult.fromValue(prompt.dismiss()); + } + + return res; + } + + public void onFileCallbackResult(final int resultCode, final Intent data) { + stopMedia(); + if (mFileResponse == null) { + return; + } + + final GeckoResult res = mFileResponse; + mFileResponse = null; + + final FilePrompt prompt = mFilePrompt; + mFilePrompt = null; + + if (resultCode != Activity.RESULT_OK || data == null) { + res.complete(prompt.dismiss()); + return; + } + + final Uri uri = data.getData(); + final ClipData clip = data.getClipData(); + + if (prompt.type == FilePrompt.Type.SINGLE || + (prompt.type == FilePrompt.Type.MULTIPLE && clip == null)) { + res.complete(prompt.confirm(mActivity, uri)); + } else if (prompt.type == FilePrompt.Type.MULTIPLE) { + if (clip == null) { + Log.w(LOGTAG, "No selected file"); + res.complete(prompt.dismiss()); + return; + } + final int count = clip.getItemCount(); + final ArrayList uris = new ArrayList<>(count); + for (int i = 0; i < count; i++) { + uris.add(clip.getItemAt(i).getUri()); + } + res.complete(prompt.confirm(mActivity, uris.toArray(new Uri[0]))); + } + } + + public void onPermissionPrompt(final String title, + final GeckoSession.PermissionDelegate.Callback callback) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + callback.reject(); + return; + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(title) + .setNegativeButton(android.R.string.cancel, (dialog, which) -> callback.reject()) + .setPositiveButton(android.R.string.ok, (dialog, which) -> callback.grant()); + + final AlertDialog dialog = builder.create(); + dialog.show(); + } + + public void onSlowScriptPrompt(String title, GeckoResult reportAction) { + stopMedia(); + final Activity activity = mActivity; + if (activity == null) { + return; + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(title) + .setNegativeButton("Wait", (dialog, which) -> reportAction.complete(SlowScriptResponse.CONTINUE)) + .setPositiveButton("Stop", (dialog, which) -> reportAction.complete(SlowScriptResponse.STOP)); + + final AlertDialog dialog = builder.create(); + dialog.show(); + } + + private Spinner addMediaSpinner(final Context context, final ViewGroup container, + final GeckoSession.PermissionDelegate.MediaSource[] sources, final String[] sourceNames) { + final ArrayAdapter adapter = new ArrayAdapter( + context, android.R.layout.simple_spinner_item) { + private View convertView(final int position, final View view) { + if (view != null) { + ((TextView) view).setText(sourceNames != null ? sourceNames[position] : "media"); + } + return view; + } + + @Override + public View getView(final int position, View view, + final ViewGroup parent) { + return convertView(position, super.getView(position, view, parent)); + } + + @Override + public View getDropDownView(final int position, final View view, + @NonNull final ViewGroup parent) { + return convertView(position, super.getDropDownView(position, view, parent)); + } + }; + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + adapter.addAll(sources); + + final Spinner spinner = new Spinner(context); + spinner.setAdapter(adapter); + spinner.setSelection(0); + container.addView(spinner); + return spinner; + } + + public void onMediaPrompt(final String title, + final GeckoSession.PermissionDelegate.MediaSource[] video, final GeckoSession.PermissionDelegate.MediaSource[] audio, + final String[] videoNames, final String[] audioNames, + final GeckoSession.PermissionDelegate.MediaCallback callback) { + final Activity activity = mActivity; + stopMedia(); + if (activity == null || (video == null && audio == null)) { + callback.reject(); + return; + } + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + final LinearLayout container = addStandardLayout(builder, title, null); + + final Spinner videoSpinner; + if (video != null) { + videoSpinner = addMediaSpinner(builder.getContext(), container, video, videoNames); + } else { + videoSpinner = null; + } + + final Spinner audioSpinner; + if (audio != null) { + audioSpinner = addMediaSpinner(builder.getContext(), container, audio, audioNames); + } else { + audioSpinner = null; + } + + builder.setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(android.R.string.ok, + (dialog, which) -> { + final GeckoSession.PermissionDelegate.MediaSource video1 = (videoSpinner != null) + ? (GeckoSession.PermissionDelegate.MediaSource) videoSpinner.getSelectedItem() : null; + final GeckoSession.PermissionDelegate.MediaSource audio1 = (audioSpinner != null) + ? (GeckoSession.PermissionDelegate.MediaSource) audioSpinner.getSelectedItem() : null; + callback.grant(video1, audio1); + }); + + final AlertDialog dialog = builder.create(); + dialog.setOnDismissListener(dialog1 -> callback.reject()); + dialog.show(); + } + + public void onMediaPrompt(final String title, + final GeckoSession.PermissionDelegate.MediaSource[] video, final GeckoSession.PermissionDelegate.MediaSource[] audio, + final GeckoSession.PermissionDelegate.MediaCallback callback) { + stopMedia(); + onMediaPrompt(title, video, audio, null, null, callback); + } + + @Override + public GeckoResult onPopupPrompt(@NonNull final GeckoSession session, + final PopupPrompt prompt) { + stopMedia(); + return GeckoResult.fromValue(prompt.confirm(AllowOrDeny.ALLOW)); + } } \ No newline at end of file diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/scrollDelegate.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/scrollDelegate.java new file mode 100644 index 00000000..333a9930 --- /dev/null +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/scrollDelegate.java @@ -0,0 +1,51 @@ +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel; + + +import android.util.Log; +import androidx.annotation.NonNull; +import androidx.annotation.UiThread; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.dataModel.geckoDataModel; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.geckoSession; +import com.hiddenservices.onionservices.constants.enums; +import com.hiddenservices.onionservices.eventObserver; +import com.hiddenservices.onionservices.helperManager.helperMethod; +import org.mozilla.geckoview.GeckoSession; +import java.util.Arrays; + +public class scrollDelegate implements GeckoSession.ScrollDelegate { + + /*Private Variables*/ + + private eventObserver.eventListener mEvent; + private geckoDataModel mGeckoDataModel; + + private int mScollOffset = 0; + + /*Initializations*/ + + public scrollDelegate(eventObserver.eventListener pEvent, geckoDataModel pGeckoDataModel) { + this.mEvent = pEvent; + this.mGeckoDataModel = pGeckoDataModel; + } + + /*Scroll Delegate*/ + @UiThread + public void onScrollChanged(@NonNull GeckoSession session, int scrollX, int scrollY) { + Log.i("fucker111 : ", scrollY + ""); + mScollOffset = scrollY; + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme), enums.etype.M_UPDATE_PIXEL_BACKGROUND); + if (scrollY <= 3) { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme), enums.etype.M_ON_SCROLL_TOP_BOUNDARIES); + } else if (scrollY <= helperMethod.pxFromDp(30)) { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme), enums.etype.M_ON_SCROLL_BOUNDARIES); + } else { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme), enums.etype.M_ON_SCROLL_NO_BOUNDARIES); + } + + } + + public int getScrollOffset() { + return mScollOffset; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/selectionActionDelegate.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/selectionDelegate.java similarity index 89% rename from app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/selectionActionDelegate.java rename to app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/selectionDelegate.java index fa9937df..3e4ea8cf 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/selectionActionDelegate.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/selectionDelegate.java @@ -1,473 +1,478 @@ -package com.hiddenservices.onionservices.appManager.homeManager.geckoManager; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.graphics.Matrix; -import android.graphics.Rect; -import android.graphics.RectF; -import android.os.Build; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.UiThread; - -import android.util.Log; -import android.view.ActionMode; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; - -import com.hiddenservices.onionservices.appManager.activityContextManager; - -import org.mozilla.gecko.util.ThreadUtils; -import org.mozilla.geckoview.GeckoSession; - -/** - * Class that implements a basic SelectionActionDelegate. This class is used by GeckoView by - * default if the consumer does not explicitly set a SelectionActionDelegate. - *

- * To provide custom actions, extend this class and override the following methods, - *

- * 1) Override {@link #getAllActions} to include custom action IDs in the returned array. This - * array must include all actions, available or not, and must not change over the class lifetime. - *

- * 2) Override {@link #isActionAvailable} to return whether a custom action is currently available. - *

- * 3) Override {@link #prepareAction} to set custom title and/or icon for a custom action. - *

- * 4) Override {@link #performAction} to perform a custom action when used. - */ -@UiThread -public class selectionActionDelegate implements ActionMode.Callback, - GeckoSession.SelectionActionDelegate { - private static final String LOGTAG = "BasicSelectionAction"; - - protected static final String ACTION_PROCESS_TEXT = Intent.ACTION_PROCESS_TEXT; - - private static final String[] FLOATING_TOOLBAR_ACTIONS = new String[]{ - ACTION_CUT, ACTION_COPY, ACTION_PASTE, ACTION_SELECT_ALL, "SEARCH" - }; - private static final String[] FIXED_TOOLBAR_ACTIONS = new String[]{ - ACTION_SELECT_ALL, ACTION_CUT, ACTION_COPY, ACTION_PASTE, "SEARCH" - }; - - protected final @NonNull - Activity mActivity; - protected final boolean mUseFloatingToolbar; - protected final @NonNull - Matrix mTempMatrix = new Matrix(); - protected final @NonNull - RectF mTempRect = new RectF(); - private boolean mFullScreen = false; - - private boolean mExternalActionsEnabled; - - protected @Nullable - ActionMode mActionMode; - protected @Nullable - GeckoSession mSession; - protected @Nullable - Selection mSelection; - protected boolean mRepopulatedMenu; - - public void setFullScreen(boolean pFullScreen) { - mFullScreen = pFullScreen; - } - - @TargetApi(Build.VERSION_CODES.M) - private class Callback2Wrapper extends ActionMode.Callback2 { - @Override - public boolean onCreateActionMode(final ActionMode actionMode, final Menu menu) { - return selectionActionDelegate.this.onCreateActionMode(actionMode, menu); - } - - @Override - public boolean onPrepareActionMode(final ActionMode actionMode, final Menu menu) { - return selectionActionDelegate.this.onPrepareActionMode(actionMode, menu); - } - - @Override - public boolean onActionItemClicked(final ActionMode actionMode, final MenuItem menuItem) { - return selectionActionDelegate.this.onActionItemClicked(actionMode, menuItem); - } - - @Override - public void onDestroyActionMode(final ActionMode actionMode) { - selectionActionDelegate.this.onDestroyActionMode(actionMode); - } - - @Override - public void onGetContentRect(final ActionMode mode, final View view, final Rect outRect) { - super.onGetContentRect(mode, view, outRect); - selectionActionDelegate.this.onGetContentRect(mode, view, outRect); - } - } - - @SuppressWarnings("checkstyle:javadocmethod") - public selectionActionDelegate(final @NonNull Activity activity) { - this(activity, Build.VERSION.SDK_INT >= 23); - } - - @SuppressWarnings("checkstyle:javadocmethod") - public selectionActionDelegate(final @NonNull Activity activity, - final boolean useFloatingToolbar) { - mActivity = activity; - mUseFloatingToolbar = useFloatingToolbar; - mExternalActionsEnabled = true; - } - - /** - * Set whether to include text actions from other apps in the floating toolbar. - * - * @param enable True if external actions should be enabled. - */ - public void enableExternalActions(final boolean enable) { - ThreadUtils.assertOnUiThread(); - mExternalActionsEnabled = enable; - - if (mActionMode != null) { - mActionMode.invalidate(); - } - } - - /** - * Get whether text actions from other apps are enabled. - * - * @return True if external actions are enabled. - */ - public boolean areExternalActionsEnabled() { - return mExternalActionsEnabled; - } - - /** - * Return list of all actions in proper order, regardless of their availability at present. - * Override to add to or remove from the default set. - * - * @return Array of action IDs in proper order. - */ - protected @NonNull - String[] getAllActions() { - return mUseFloatingToolbar ? FLOATING_TOOLBAR_ACTIONS - : FIXED_TOOLBAR_ACTIONS; - } - - /** - * Return whether an action is presently available. Override to indicate - * availability for custom actions. - * - * @param id Action ID. - * @return True if the action is presently available. - */ - protected boolean isActionAvailable(final @NonNull String id) { - if (mSelection == null || mSelection.text.length() < 1 || mSelection.text.getBytes().length >= 500000) { - return false; - } - - if (mExternalActionsEnabled && !mSelection.text.isEmpty() && - ACTION_PROCESS_TEXT.equals(id)) { - final PackageManager pm = mActivity.getPackageManager(); - return pm.resolveActivity(getProcessTextIntent(), PackageManager.MATCH_DEFAULT_ONLY) != null; - } - if (id.equals("SEARCH") && !mSelection.text.isEmpty() && mExternalActionsEnabled) { - return true; - } - - return mSelection.isActionAvailable(id); - } - - /** - * Provides access to whether there are text selection actions available. Override to indicate - * availability for custom actions. - * - * @return True if there are text selection actions available. - */ - public boolean isActionAvailable() { - if (mSelection == null) { - return false; - } - - return isActionAvailable(ACTION_PROCESS_TEXT) || - !mSelection.availableActions.isEmpty(); - } - - /** - * Prepare a menu item corresponding to a certain action. Override to prepare - * menu item for custom action. - * - * @param id Action ID. - * @param item New menu item to prepare. - */ - protected void prepareAction(final @NonNull String id, final @NonNull MenuItem item) { - - if (mFullScreen) { - return; - } - switch (id) { - case ACTION_CUT: - item.setTitle(android.R.string.cut); - break; - case ACTION_COPY: - item.setTitle(android.R.string.copy); - break; - case "SEARCH": - item.setTitle("Search"); - break; - case ACTION_PASTE: - item.setTitle(android.R.string.paste); - break; - case ACTION_SELECT_ALL: - item.setTitle(android.R.string.selectAll); - break; - case ACTION_PROCESS_TEXT: - throw new IllegalStateException("Unexpected action"); - } - } - - /** - * Perform the specified action. Override to perform custom actions. - * - * @param id Action ID. - * @param item Nenu item for the action. - * @return True if the action was performed. - */ - protected boolean performAction(final @NonNull String id, final @NonNull MenuItem item) { - if (ACTION_PROCESS_TEXT.equals(id)) { - try { - mActivity.startActivity(item.getIntent()); - } catch (final ActivityNotFoundException e) { - Log.e(LOGTAG, "Cannot perform action", e); - return false; - } - return true; - } - - if (mSelection == null) { - return false; - } - if (id.equals("SEARCH")) { - if (activityContextManager.getInstance() != null && activityContextManager.getInstance().getHomeController() != null) { - activityContextManager.getInstance().getHomeController().onSearchString(mSelection.text); - } - clearSelection(); - mActionMode.finish(); - return false; - } - mSelection.execute(id); - - if (ACTION_COPY.equals(id)) { - if (mUseFloatingToolbar) { - clearSelection(); - } else { - mActionMode.finish(); - } - } - return true; - } - - /** - * Get the current selection object. This object should not be stored as it does not update - * when the selection becomes invalid. Stale actions are ignored. - * - * @return The {@link GeckoSession.SelectionActionDelegate.Selection} attached to the current - * action menu. null if no action menu is active. - */ - public @Nullable - Selection getSelection() { - return mSelection; - } - - /** - * Clear the current selection, if possible. - */ - public void clearSelection() { - if (mSelection == null) { - return; - } - - if (isActionAvailable(ACTION_COLLAPSE_TO_END)) { - mSelection.collapseToEnd(); - } else if (isActionAvailable(ACTION_UNSELECT)) { - mSelection.unselect(); - } else { - mSelection.hide(); - } - } - - private Intent getProcessTextIntent() { - final Intent intent = new Intent(Intent.ACTION_PROCESS_TEXT); - intent.addCategory(Intent.CATEGORY_DEFAULT); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_PROCESS_TEXT, mSelection.text); - // TODO: implement ability to replace text in Gecko for editable selection (bug 1453137). - intent.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true); - return intent; - } - - @Override - public boolean onCreateActionMode(final ActionMode actionMode, final Menu menu) { - ThreadUtils.assertOnUiThread(); - final String[] allActions = getAllActions(); - for (final String actionId : allActions) { - if (isActionAvailable(actionId)) { - if (!mUseFloatingToolbar && ( - Build.VERSION.SDK_INT == 22 || Build.VERSION.SDK_INT == 23)) { - // Android bug where onPrepareActionMode is not called initially. - onPrepareActionMode(actionMode, menu); - } - return true; - } - } - return false; - } - - @Override - public boolean onPrepareActionMode(final ActionMode actionMode, final Menu menu) { - ThreadUtils.assertOnUiThread(); - final String[] allActions = getAllActions(); - boolean changed = false; - - // Whether we are repopulating an existing menu. - mRepopulatedMenu = menu.size() != 0; - - // For each action, see if it's available at present, and if necessary, - // add to or remove from menu. - for (int i = 0; i < allActions.length; i++) { - final String actionId = allActions[i]; - final int menuId = i + Menu.FIRST; - - if (ACTION_PROCESS_TEXT.equals(actionId)) { - if (mExternalActionsEnabled && !mSelection.text.isEmpty()) { - menu.addIntentOptions(menuId, menuId, menuId, - mActivity.getComponentName(), - /* specifiec */ null, getProcessTextIntent(), - /* flags */ 0, /* items */ null); - changed = true; - } else if (menu.findItem(menuId) != null) { - menu.removeGroup(menuId); - changed = true; - } - continue; - } - - if (isActionAvailable(actionId)) { - if (menu.findItem(menuId) == null) { - prepareAction(actionId, menu.add(/* group */ Menu.NONE, menuId, - menuId, /* title */ "")); - changed = true; - } - } else if (menu.findItem(menuId) != null) { - menu.removeItem(menuId); - changed = true; - } - } - return changed; - } - - @Override - public boolean onActionItemClicked(final ActionMode actionMode, final MenuItem menuItem) { - ThreadUtils.assertOnUiThread(); - MenuItem realMenuItem = null; - if (mRepopulatedMenu) { - // When we repopulate an existing menu, Android can sometimes give us an old, - // deleted MenuItem. Find the current MenuItem that corresponds to the old one. - final Menu menu = actionMode.getMenu(); - final int size = menu.size(); - for (int i = 0; i < size; i++) { - final MenuItem item = menu.getItem(i); - if (item == menuItem || (item.getItemId() == menuItem.getItemId() && - item.getTitle().equals(menuItem.getTitle()))) { - realMenuItem = item; - break; - } - } - } else { - realMenuItem = menuItem; - } - - if (realMenuItem == null) { - return false; - } - final String[] allActions = getAllActions(); - return performAction(allActions[realMenuItem.getItemId() - Menu.FIRST], realMenuItem); - } - - @Override - public void onDestroyActionMode(final ActionMode actionMode) { - ThreadUtils.assertOnUiThread(); - if (!mUseFloatingToolbar) { - clearSelection(); - } - mSession = null; - mSelection = null; - mActionMode = null; - } - - @SuppressWarnings("checkstyle:javadocmethod") - public void onGetContentRect(final @Nullable ActionMode mode, final @Nullable View view, - final @NonNull Rect outRect) { - ThreadUtils.assertOnUiThread(); - if (mSelection == null || mSelection.clientRect == null) { - return; - } - mSession.getClientToScreenMatrix(mTempMatrix); - mTempMatrix.mapRect(mTempRect, mSelection.clientRect); - mTempRect.roundOut(outRect); - } - - @TargetApi(Build.VERSION_CODES.M) - @Override - public void onShowActionRequest(final GeckoSession session, final Selection selection) { - ThreadUtils.assertOnUiThread(); - mSession = session; - mSelection = selection; - - - try { - if (mActionMode != null) { - if (isActionAvailable()) { - mActionMode.invalidate(); - } else { - mActionMode.finish(); - } - return; - } - if (mUseFloatingToolbar) { - String strManufacturer = android.os.Build.MANUFACTURER; - if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1 || (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1 && (strManufacturer.toLowerCase().contains("samsung") || android.os.Build.MODEL.toLowerCase().contains("samsung") || Build.PRODUCT.toLowerCase().contains("samsung")))) { - mActionMode = mActivity.startActionMode(this); - } else { - mActionMode = mActivity.startActionMode(new Callback2Wrapper(), ActionMode.TYPE_FLOATING); - } - } else { - mActionMode = mActivity.startActionMode(this); - } - } catch (Exception ignored) { - } - } - - @Override - public void onHideAction(final GeckoSession session, final int reason) { - ThreadUtils.assertOnUiThread(); - if (mActionMode == null) { - return; - } - - switch (reason) { - case HIDE_REASON_ACTIVE_SCROLL: - case HIDE_REASON_ACTIVE_SELECTION: - case HIDE_REASON_INVISIBLE_SELECTION: - if (mUseFloatingToolbar) { - // Hide the floating toolbar when scrolling/selecting. - mActionMode.finish(); - } - break; - - case HIDE_REASON_NO_SELECTION: - mActionMode.finish(); - break; - } - } +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel; + +import android.annotation.TargetApi; +import android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.graphics.Matrix; +import android.graphics.Rect; +import android.graphics.RectF; +import android.os.Build; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; +import androidx.annotation.UiThread; + +import android.util.Log; +import android.view.ActionMode; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; + +import com.hiddenservices.onionservices.appManager.activityContextManager; + +import org.mozilla.gecko.util.ThreadUtils; +import org.mozilla.geckoview.GeckoSession; + +/** + * Class that implements a basic SelectionActionDelegate. This class is used by GeckoView by + * default if the consumer does not explicitly set a SelectionActionDelegate. + *

+ * To provide custom actions, extend this class and override the following methods, + *

+ * 1) Override {@link #getAllActions} to include custom action IDs in the returned array. This + * array must include all actions, available or not, and must not change over the class lifetime. + *

+ * 2) Override {@link #isActionAvailable} to return whether a custom action is currently available. + *

+ * 3) Override {@link #prepareAction} to set custom title and/or icon for a custom action. + *

+ * 4) Override {@link #performAction} to perform a custom action when used. + */ +@UiThread +public class selectionDelegate implements ActionMode.Callback, + GeckoSession.SelectionActionDelegate { + private static final String LOGTAG = "BasicSelectionAction"; + + protected static final String ACTION_PROCESS_TEXT = "android.intent.action.PROCESS_TEXT"; + + private static final String[] FLOATING_TOOLBAR_ACTIONS = new String[]{ + ACTION_CUT, ACTION_COPY, ACTION_PASTE, ACTION_SELECT_ALL, "SEARCH" + }; + private static final String[] FIXED_TOOLBAR_ACTIONS = new String[]{ + ACTION_SELECT_ALL, ACTION_CUT, ACTION_COPY, ACTION_PASTE, "SEARCH" + }; + + protected final @NonNull + Activity mActivity; + protected final boolean mUseFloatingToolbar; + protected final @NonNull + Matrix mTempMatrix = new Matrix(); + protected final @NonNull + RectF mTempRect = new RectF(); + private boolean mFullScreen = false; + + private boolean mExternalActionsEnabled; + + protected @Nullable + ActionMode mActionMode; + protected @Nullable + GeckoSession mSession; + protected @Nullable + Selection mSelection; + protected boolean mRepopulatedMenu; + + public void setFullScreen(boolean pFullScreen) { + mFullScreen = pFullScreen; + } + + @TargetApi(Build.VERSION_CODES.M) + private class Callback2Wrapper extends ActionMode.Callback2 { + @Override + public boolean onCreateActionMode(final ActionMode actionMode, final Menu menu) { + return selectionDelegate.this.onCreateActionMode(actionMode, menu); + } + + @Override + public boolean onPrepareActionMode(final ActionMode actionMode, final Menu menu) { + return selectionDelegate.this.onPrepareActionMode(actionMode, menu); + } + + @Override + public boolean onActionItemClicked(final ActionMode actionMode, final MenuItem menuItem) { + return selectionDelegate.this.onActionItemClicked(actionMode, menuItem); + } + + @Override + public void onDestroyActionMode(final ActionMode actionMode) { + selectionDelegate.this.onDestroyActionMode(actionMode); + } + + @Override + public void onGetContentRect(final ActionMode mode, final View view, final Rect outRect) { + super.onGetContentRect(mode, view, outRect); + selectionDelegate.this.onGetContentRect(mode, view, outRect); + } + } + + @SuppressWarnings("checkstyle:javadocmethod") + public selectionDelegate(final @NonNull Activity activity) { + this(activity, Build.VERSION.SDK_INT >= 23); + } + + @SuppressWarnings("checkstyle:javadocmethod") + public selectionDelegate(final @NonNull Activity activity, + final boolean useFloatingToolbar) { + mActivity = activity; + mUseFloatingToolbar = useFloatingToolbar; + mExternalActionsEnabled = true; + } + + /** + * Set whether to include text actions from other apps in the floating toolbar. + * + * @param enable True if external actions should be enabled. + */ + public void enableExternalActions(final boolean enable) { + ThreadUtils.assertOnUiThread(); + mExternalActionsEnabled = enable; + + if (mActionMode != null) { + mActionMode.invalidate(); + } + } + + /** + * Get whether text actions from other apps are enabled. + * + * @return True if external actions are enabled. + */ + public boolean areExternalActionsEnabled() { + return mExternalActionsEnabled; + } + + /** + * Return list of all actions in proper order, regardless of their availability at present. + * Override to add to or remove from the default set. + * + * @return Array of action IDs in proper order. + */ + protected @NonNull + String[] getAllActions() { + return mUseFloatingToolbar ? FLOATING_TOOLBAR_ACTIONS + : FIXED_TOOLBAR_ACTIONS; + } + + /** + * Return whether an action is presently available. Override to indicate + * availability for custom actions. + * + * @param id Action ID. + * @return True if the action is presently available. + */ + protected boolean isActionAvailable(final @NonNull String id) { + if (mSelection == null || mSelection.text.length() < 1 || mSelection.text.getBytes().length >= 500000) { + return false; + } + + if (mExternalActionsEnabled && !mSelection.text.isEmpty() && + ACTION_PROCESS_TEXT.equals(id)) { + final PackageManager pm = mActivity.getPackageManager(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + return pm.resolveActivity(getProcessTextIntent(), PackageManager.MATCH_DEFAULT_ONLY) != null; + } + } + if (id.equals("SEARCH") && !mSelection.text.isEmpty() && mExternalActionsEnabled) { + return true; + } + + return mSelection.isActionAvailable(id); + } + + /** + * Provides access to whether there are text selection actions available. Override to indicate + * availability for custom actions. + * + * @return True if there are text selection actions available. + */ + public boolean isActionAvailable() { + if (mSelection == null) { + return false; + } + + return isActionAvailable(ACTION_PROCESS_TEXT) || + !mSelection.availableActions.isEmpty(); + } + + /** + * Prepare a menu item corresponding to a certain action. Override to prepare + * menu item for custom action. + * + * @param id Action ID. + * @param item New menu item to prepare. + */ + protected void prepareAction(final @NonNull String id, final @NonNull MenuItem item) { + + if (mFullScreen) { + return; + } + switch (id) { + case ACTION_CUT: + item.setTitle(android.R.string.cut); + break; + case ACTION_COPY: + item.setTitle(android.R.string.copy); + break; + case "SEARCH": + item.setTitle("Search"); + break; + case ACTION_PASTE: + item.setTitle(android.R.string.paste); + break; + case ACTION_SELECT_ALL: + item.setTitle(android.R.string.selectAll); + break; + case ACTION_PROCESS_TEXT: + throw new IllegalStateException("Unexpected action"); + } + } + + /** + * Perform the specified action. Override to perform custom actions. + * + * @param id Action ID. + * @param item Nenu item for the action. + * @return True if the action was performed. + */ + protected boolean performAction(final @NonNull String id, final @NonNull MenuItem item) { + if (ACTION_PROCESS_TEXT.equals(id)) { + try { + mActivity.startActivity(item.getIntent()); + } catch (final ActivityNotFoundException e) { + Log.e(LOGTAG, "Cannot perform action", e); + return false; + } + return true; + } + + if (mSelection == null) { + return false; + } + if (id.equals("SEARCH")) { + if (activityContextManager.getInstance() != null && activityContextManager.getInstance().getHomeController() != null) { + activityContextManager.getInstance().getHomeController().onSearchString(mSelection.text); + } + clearSelection(); + mActionMode.finish(); + return false; + } + mSelection.execute(id); + + if (ACTION_COPY.equals(id)) { + if (mUseFloatingToolbar) { + clearSelection(); + } else { + mActionMode.finish(); + } + } + return true; + } + + /** + * Get the current selection object. This object should not be stored as it does not update + * when the selection becomes invalid. Stale actions are ignored. + * + * @return The {@link GeckoSession.SelectionActionDelegate.Selection} attached to the current + * action menu. null if no action menu is active. + */ + public @Nullable + Selection getSelection() { + return mSelection; + } + + /** + * Clear the current selection, if possible. + */ + public void clearSelection() { + if (mSelection == null) { + return; + } + + if (isActionAvailable(ACTION_COLLAPSE_TO_END)) { + mSelection.collapseToEnd(); + } else if (isActionAvailable(ACTION_UNSELECT)) { + mSelection.unselect(); + } else { + mSelection.hide(); + } + } + + @RequiresApi(api = Build.VERSION_CODES.M) + private Intent getProcessTextIntent() { + final Intent intent = new Intent(Intent.ACTION_PROCESS_TEXT); + intent.addCategory(Intent.CATEGORY_DEFAULT); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_PROCESS_TEXT, mSelection.text); + intent.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true); + return intent; + } + + @Override + public boolean onCreateActionMode(final ActionMode actionMode, final Menu menu) { + ThreadUtils.assertOnUiThread(); + final String[] allActions = getAllActions(); + for (final String actionId : allActions) { + if (isActionAvailable(actionId)) { + if (!mUseFloatingToolbar && ( + Build.VERSION.SDK_INT == 22 || Build.VERSION.SDK_INT == 23)) { + // Android bug where onPrepareActionMode is not called initially. + onPrepareActionMode(actionMode, menu); + } + return true; + } + } + return false; + } + + @Override + public boolean onPrepareActionMode(final ActionMode actionMode, final Menu menu) { + ThreadUtils.assertOnUiThread(); + final String[] allActions = getAllActions(); + boolean changed = false; + + // Whether we are repopulating an existing menu. + mRepopulatedMenu = menu.size() != 0; + + // For each action, see if it's available at present, and if necessary, + // add to or remove from menu. + for (int i = 0; i < allActions.length; i++) { + final String actionId = allActions[i]; + final int menuId = i + Menu.FIRST; + + if (ACTION_PROCESS_TEXT.equals(actionId)) { + if (mExternalActionsEnabled && !mSelection.text.isEmpty()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + menu.addIntentOptions(menuId, menuId, menuId, + mActivity.getComponentName(), + /* specifiec */ null, getProcessTextIntent(), + /* flags */ 0, /* items */ null); + } + changed = true; + } else if (menu.findItem(menuId) != null) { + menu.removeGroup(menuId); + changed = true; + } + continue; + } + + if (isActionAvailable(actionId)) { + if (menu.findItem(menuId) == null) { + prepareAction(actionId, menu.add(/* group */ Menu.NONE, menuId, + menuId, /* title */ "")); + changed = true; + } + } else if (menu.findItem(menuId) != null) { + menu.removeItem(menuId); + changed = true; + } + } + return changed; + } + + @Override + public boolean onActionItemClicked(final ActionMode actionMode, final MenuItem menuItem) { + ThreadUtils.assertOnUiThread(); + MenuItem realMenuItem = null; + if (mRepopulatedMenu) { + // When we repopulate an existing menu, Android can sometimes give us an old, + // deleted MenuItem. Find the current MenuItem that corresponds to the old one. + final Menu menu = actionMode.getMenu(); + final int size = menu.size(); + for (int i = 0; i < size; i++) { + final MenuItem item = menu.getItem(i); + if (item == menuItem || (item.getItemId() == menuItem.getItemId() && + item.getTitle().equals(menuItem.getTitle()))) { + realMenuItem = item; + break; + } + } + } else { + realMenuItem = menuItem; + } + + if (realMenuItem == null) { + return false; + } + final String[] allActions = getAllActions(); + return performAction(allActions[realMenuItem.getItemId() - Menu.FIRST], realMenuItem); + } + + @Override + public void onDestroyActionMode(final ActionMode actionMode) { + ThreadUtils.assertOnUiThread(); + if (!mUseFloatingToolbar) { + clearSelection(); + } + mSession = null; + mSelection = null; + mActionMode = null; + } + + @SuppressWarnings("checkstyle:javadocmethod") + public void onGetContentRect(final @Nullable ActionMode mode, final @Nullable View view, + final @NonNull Rect outRect) { + ThreadUtils.assertOnUiThread(); + if (mSelection == null || mSelection.clientRect == null) { + return; + } + mSession.getClientToScreenMatrix(mTempMatrix); + mTempMatrix.mapRect(mTempRect, mSelection.clientRect); + mTempRect.roundOut(outRect); + } + + @TargetApi(Build.VERSION_CODES.M) + @Override + public void onShowActionRequest(@NonNull final GeckoSession session, @NonNull final Selection selection) { + ThreadUtils.assertOnUiThread(); + mSession = session; + mSelection = selection; + + + try { + if (mActionMode != null) { + if (isActionAvailable()) { + mActionMode.invalidate(); + } else { + mActionMode.finish(); + } + return; + } + if (mUseFloatingToolbar) { + String strManufacturer = android.os.Build.MANUFACTURER; + if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1 || (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1 && (strManufacturer.toLowerCase().contains("samsung") || android.os.Build.MODEL.toLowerCase().contains("samsung") || Build.PRODUCT.toLowerCase().contains("samsung")))) { + mActionMode = mActivity.startActionMode(this); + } else { + mActionMode = mActivity.startActionMode(new Callback2Wrapper(), ActionMode.TYPE_FLOATING); + } + } else { + mActionMode = mActivity.startActionMode(this); + } + } catch (Exception ignored) { + } + } + + @Override + public void onHideAction(@NonNull final GeckoSession session, final int reason) { + ThreadUtils.assertOnUiThread(); + if (mActionMode == null) { + return; + } + + switch (reason) { + case HIDE_REASON_ACTIVE_SCROLL: + case HIDE_REASON_ACTIVE_SELECTION: + case HIDE_REASON_INVISIBLE_SELECTION: + if (mUseFloatingToolbar) { + // Hide the floating toolbar when scrolling/selecting. + mActionMode.finish(); + } + break; + + case HIDE_REASON_NO_SELECTION: + mActionMode.finish(); + break; + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoClients.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoClients.java index c00cc1a7..26057b98 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoClients.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoClients.java @@ -7,13 +7,8 @@ import android.net.Uri; import android.os.Handler; import android.util.Log; import android.widget.ImageView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; - import com.hiddenservices.onionservices.appManager.activityContextManager; -import com.hiddenservices.onionservices.appManager.homeManager.homeController.homeController; import com.hiddenservices.onionservices.appManager.kotlinHelperLibraries.BrowserIconManager; import com.hiddenservices.onionservices.constants.*; import com.hiddenservices.onionservices.dataManager.dataController; @@ -25,14 +20,12 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import java.util.List; import static com.hiddenservices.onionservices.constants.constants.CONST_GENESIS_URL_CACHED; import static com.hiddenservices.onionservices.constants.constants.CONST_GENESIS_URL_CACHED_DARK; import static com.hiddenservices.onionservices.constants.constants.CONST_PRIVACY_POLICY_URL_NON_TOR; import static com.hiddenservices.onionservices.constants.constants.CONST_REPORT_URL; -import static com.hiddenservices.onionservices.constants.enums.etype.M_INDEX_WEBSITE; import static com.hiddenservices.onionservices.constants.enums.etype.on_handle_external_intent; import static org.mozilla.geckoview.GeckoSessionSettings.USER_AGENT_MODE_MOBILE; import static org.mozilla.geckoview.StorageController.ClearFlags.AUTH_SESSIONS; @@ -44,15 +37,10 @@ import static org.mozilla.geckoview.StorageController.ClearFlags.PERMISSIONS; import static org.mozilla.geckoview.StorageController.ClearFlags.SITE_DATA; import static org.mozilla.geckoview.StorageController.ClearFlags.SITE_SETTINGS; -import org.json.JSONObject; -import org.mozilla.gecko.EventDispatcher; -import org.mozilla.gecko.util.GeckoBundle; import org.mozilla.geckoview.ContentBlocking; -import org.mozilla.geckoview.GeckoResult; import org.mozilla.geckoview.GeckoRuntime; import org.mozilla.geckoview.GeckoRuntimeSettings; import org.mozilla.geckoview.GeckoView; -import org.mozilla.geckoview.WebExtension; import org.mozilla.geckoview.WebResponse; import org.torproject.android.service.wrapper.orbotLocalConstants; @@ -211,126 +199,6 @@ public class geckoClients { return cacheFile.getAbsolutePath(); } -/* - @SuppressLint("WrongThread") - public void installExtension() { - - mRuntime.getWebExtensionController() - .ensureBuiltIn("resource://android/assets/parser/", "messaging@example.com") - .accept( - extension -> { - Log.i("MessageDelegate", "Extension installed: " + extension); - extension.setMessageDelegate(mMessagingDelegate, "browser"); - }, - e -> { - Log.e("MessageDelegate", "Error registering WebExtension", e); - } - ); - - mRuntime.getWebExtensionController() - .ensureBuiltIn("resource://android/assets/adblock/", "messaging@example.com") - .accept( - extension -> { - Log.i("MessageDelegate", "Extension installed: " + extension); - extension.setMessageDelegate(mMessagingDelegate, "browser"); - }, - e -> { - Log.e("MessageDelegate", "Error registering WebExtension", e); - } - ); - } - - private final WebExtension.MessageDelegate mMessagingDelegate = new WebExtension.MessageDelegate() { - - @Override - public void onConnect(@NonNull WebExtension.Port port) { - Log.e("MessageDelegate", "onConnect"); - mPort = port; - mPort.setDelegate(mPortDelegate); - } - - @Override - public GeckoResult onMessage(final @NonNull String nativeApp, final @NonNull Object message, final @NonNull WebExtension.MessageSender sender) { - Log.e("MessageDelegate", "onConnect"); - return null; - } - - }; - - private final WebExtension.PortDelegate mPortDelegate = new WebExtension.PortDelegate() { - @Override - public void onPortMessage(final @NonNull Object message, final @NonNull WebExtension.Port port) { - if(mSession!=null){ - if (message != null && mSession.getProgress() == 100 && !mSession.mCloseRequested && mSession.isFirstPaintExecuted && !mSession.mOnBackPressed) { - //event.invokeObserver(Arrays.asList(message, mSession.getCurrentURL()), M_INDEX_WEBSITE); - } - mSession.mOnBackPressed = false; - } - } - - @Override - public void onDisconnect(final @NonNull WebExtension.Port port) { - Log.e("MessageDelegate:", "onDisconnect"); - if (port == mPort) { - mPort = null; - } - } - }; - - private WebExtension.Port mPort; - - public void onExtentionClicked() { - try { - if (mPort == null) { - return; - } - long id = System.currentTimeMillis(); - Log.e("evalJavascript:id:", id + ""); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("action", "evalJavascript"); - jsonObject.put("data", "evalJavascript"); - jsonObject.put("id", id); - Log.e("evalJavascript:", jsonObject.toString()); - mPort.postMessage(jsonObject); - } catch (Exception e) { - e.printStackTrace(); - } - } - - static boolean mCreated = false;*/ - - /* package *//* class Pref { - public final String name; - public final T defaultValue; - private T mValue; - private boolean mIsSet; - - public Pref(@NonNull final String name, final T defaultValue) { - this.name = name; - this.defaultValue = defaultValue; - mValue = defaultValue; - - } - public void add() { - final GeckoBundle prefs = new GeckoBundle(1); - prefs.putInt(this.name, (Integer)this.defaultValue); - EventDispatcher.getInstance().dispatch("GeckoView:SetDefaultPrefs", prefs); - addToBundle(prefs); - } - - private void addToBundle(final GeckoBundle bundle) { - final T value = mIsSet ? mValue : defaultValue; - if (value instanceof String) { - bundle.putString(name, (String) value); - } else if (value instanceof Integer) { - bundle.putInt(name, (Integer) value); - } else if (value instanceof Boolean) { - bundle.putBoolean(name, (Boolean) value); - } else { - throw new UnsupportedOperationException("Unhandled pref type for " + name); - } - } - }*/ @SuppressLint("WrongConstant") public void initRuntimeSettings(AppCompatActivity context) { @@ -375,7 +243,7 @@ public class geckoClients { public void onGetFavIcon(ImageView pImageView, String pURL, AppCompatActivity pcontext) { - if(status.sLowMemory != enums.MemoryStatus.CRITICAL_MEMORY){ + if(status.sLowMemory != enums.MemoryStatus.CRITICAL_MEMORY && status.sLowMemory != enums.MemoryStatus.LOW_MEMORY){ initBrowserManager(pcontext); pURL = helperMethod.completeURL(helperMethod.getDomainName(pURL)); Log.i("FUCKSSS1111","111"); @@ -407,22 +275,22 @@ public class geckoClients { } public void onKillMedia(){ - mSession.onKillMedia(); + mSession.getMediaSessionDelegate().onTrigger(enums.MediaController.DESTROY); } public void onPlayMedia(){ - mSession.onPlayMedia(); + mSession.getMediaSessionDelegate().onTrigger(enums.MediaController.PLAY); } public void onPauseMedia(){ - mSession.onPauseMedia(); + mSession.getMediaSessionDelegate().onTrigger(enums.MediaController.PAUSE); } public void onSkipForwardMedia(){ - mSession.onSkipForwardMedia(); + mSession.getMediaSessionDelegate().onTrigger(enums.MediaController.SKIP_FORWARD); } public void onSkipBackwardMedia(){ - mSession.onSkipBackwardMedia(); + mSession.getMediaSessionDelegate().onTrigger(enums.MediaController.SKIP_BACKWARD); } @@ -446,7 +314,7 @@ public class geckoClients { } public void onStopMedia() { - mSession.onStopMedia(); + mSession.getMediaSessionDelegate().onTrigger(enums.MediaController.STOP); } public void onUploadRequest(int resultCode, Intent data) { @@ -521,7 +389,7 @@ public class geckoClients { } public void onRedrawPixel(AppCompatActivity pcontext) { - if(status.sLowMemory != enums.MemoryStatus.CRITICAL_MEMORY){ + if(status.sLowMemory != enums.MemoryStatus.CRITICAL_MEMORY && status.sLowMemory != enums.MemoryStatus.LOW_MEMORY){ mSession.onRedrawPixel(); onLoadFavIcon(pcontext); } @@ -605,7 +473,7 @@ public class geckoClients { } public boolean getFullScreenStatus() { - return mSession.getFullScreenStatus(); + return mSession.getContentDelegate().getFullScreenStatus(); } public void onExitFullScreen() { @@ -740,18 +608,25 @@ public class geckoClients { } public int getScrollOffset() { - return mSession.getScrollOffset(); + return mSession.getmScrollDelegate().getScrollOffset(); } public class geckoViewClientCallback implements eventObserver.eventListener { @Override public Object invokeObserver(List data, Object e_type) { + if (e_type.equals(enums.etype.ON_FULL_SCREEN)) { + mSession.onFullScreenInvoke((boolean)data.get(0)); + } + if (e_type.equals(enums.etype.ON_DESTROY_MEDIA)) { + mSession.getMediaSessionDelegate().onTrigger(enums.MediaController.DESTROY); + } if (e_type.equals(enums.etype.M_CHANGE_HOME_THEME)) { reinitHomeTheme(); - } else if (mSession != null) { + } + else if (mSession != null) { if (e_type.equals(enums.etype.SESSION_ID)) { return mSession.getSessionID(); - } else if (mSessionID != null && mSessionID.equals(data.get(1)) || e_type.equals(enums.etype.ON_INVOKE_PARSER) || e_type.equals(enums.etype.M_RATE_COUNT) || e_type.equals(enums.etype.FINDER_RESULT_CALLBACK) || e_type.equals(enums.etype.ON_UPDATE_TAB_TITLE) || e_type.equals(enums.etype.on_update_favicon) || e_type.equals(enums.etype.on_update_history) || e_type.equals(enums.etype.on_request_completed) || e_type.equals(enums.etype.on_update_suggestion) || e_type.equals(enums.etype.on_update_suggestion_url)) { + } else if (mSessionID != null && mSessionID.equals(data.get(1)) || e_type.equals(enums.etype.ON_INVOKE_PARSER) || e_type.equals(enums.etype.M_RATE_COUNT) || e_type.equals(enums.etype.FINDER_RESULT_CALLBACK) || e_type.equals(enums.etype.ON_UPDATE_TAB_TITLE) || e_type.equals(enums.etype.on_update_favicon) || e_type.equals(enums.etype.ON_UPDATE_HISTORY) || e_type.equals(enums.etype.on_request_completed) || e_type.equals(enums.etype.on_update_suggestion) || e_type.equals(enums.etype.on_update_suggestion_url)) { if (mSession != null && mSession.isClosed()) { return null; } diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoDownloadManager.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoDownloadManager.java index 992ed186..f2dedcff 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoDownloadManager.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoDownloadManager.java @@ -20,15 +20,15 @@ import java.util.Arrays; import mozilla.components.support.utils.DownloadUtils; -class geckoDownloadManager { +public class geckoDownloadManager { private Uri downloadURL; private String downloadFile = strings.GENERIC_EMPTY_STR; - geckoDownloadManager() { + public geckoDownloadManager() { } - void downloadFile(WebResponse response, geckoSession session, AppCompatActivity context, eventObserver.eventListener event) { + public void downloadFile(WebResponse response, geckoSession session, AppCompatActivity context, eventObserver.eventListener event) { session.getUserAgent().accept(userAgent -> downloadFile(response, userAgent, context, session, event), exception -> { throw new IllegalStateException("Could not get UserAgent string."); @@ -62,11 +62,11 @@ class geckoDownloadManager { event.invokeObserver(Arrays.asList(downloadFile, session.getSessionID(), downloadURL), enums.etype.download_file_popup); } - Uri getDownloadURL() { + public Uri getDownloadURL() { return downloadURL; } - String getDownloadFile() { + public String getDownloadFile() { return downloadFile; } diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoSession.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoSession.java index 3bada960..06d7b27b 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoSession.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/geckoSession.java @@ -3,16 +3,11 @@ package com.hiddenservices.onionservices.appManager.homeManager.geckoManager; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; -import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.graphics.Bitmap; -import android.graphics.Matrix; -import android.graphics.Rect; -import android.graphics.RectF; import android.media.MediaScannerConnection; import android.net.Uri; import android.os.Build; @@ -20,13 +15,24 @@ import android.os.Environment; import android.os.Handler; import android.util.Base64; import android.util.Log; -import android.view.autofill.AutofillManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.UiThread; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.NotificationCompat; import androidx.core.content.FileProvider; +import com.hiddenservices.onionservices.R; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.dataModel.geckoDataModel; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel.autofillDelegate; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel.contentDelegate; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel.promptDelegate; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel.historyDelegate; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel.mediaDelegate; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel.mediaSessionDelegate; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel.scrollDelegate; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.delegateModel.selectionDelegate; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses.preferences; +import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses.errorHandler; import com.hiddenservices.onionservices.constants.constants; import com.hiddenservices.onionservices.constants.enums; import com.hiddenservices.onionservices.constants.status; @@ -37,21 +43,14 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.libs.trueTime.trueTimeEncryption; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; import org.json.JSONException; import org.json.JSONObject; -import org.mozilla.gecko.EventDispatcher; -import org.mozilla.gecko.util.GeckoBundle; import org.mozilla.geckoview.AllowOrDeny; -import org.mozilla.geckoview.Autofill; import org.mozilla.geckoview.GeckoResult; import org.mozilla.geckoview.GeckoSession; import org.mozilla.geckoview.GeckoView; -import org.mozilla.geckoview.MediaSession; -import org.mozilla.geckoview.SlowScriptResponse; import org.mozilla.geckoview.WebExtension; import org.mozilla.geckoview.WebRequestError; -import org.mozilla.geckoview.WebResponse; import org.torproject.android.service.wrapper.orbotLocalConstants; import java.io.File; import java.io.FileOutputStream; @@ -72,161 +71,76 @@ import static com.hiddenservices.onionservices.constants.constants.CONST_GENESIS import static com.hiddenservices.onionservices.constants.constants.CONST_GENESIS_URL_CACHED_DARK; import static com.hiddenservices.onionservices.constants.enums.etype.M_DEFAULT_BROWSER; import static com.hiddenservices.onionservices.constants.enums.etype.M_RATE_COUNT; -import static com.hiddenservices.onionservices.pluginManager.pluginEnums.eMessageManager.M_LONG_PRESS_URL; -import static com.hiddenservices.onionservices.pluginManager.pluginEnums.eMessageManager.M_LONG_PRESS_WITH_LINK; +import static com.hiddenservices.onionservices.pluginManager.pluginEnums.eMessageManagerCallbacks.M_RATE_APPLICATION; import static org.mozilla.geckoview.GeckoSessionSettings.USER_AGENT_MODE_DESKTOP; import static org.mozilla.geckoview.GeckoSessionSettings.USER_AGENT_MODE_MOBILE; -public class geckoSession extends GeckoSession implements MediaSession.Delegate, GeckoSession.MediaDelegate, GeckoSession.ScrollDelegate, GeckoSession.PermissionDelegate, GeckoSession.ProgressDelegate, GeckoSession.HistoryDelegate, GeckoSession.NavigationDelegate, GeckoSession.ContentDelegate { - private eventObserver.eventListener event; +public class geckoSession extends GeckoSession implements GeckoSession.MediaDelegate, GeckoSession.ScrollDelegate, GeckoSession.PermissionDelegate, GeckoSession.ProgressDelegate, GeckoSession.NavigationDelegate { + + private eventObserver.eventListener mEvent; + private geckoDataModel mGeckoDataModel; + private mediaSessionDelegate mMediaSessionDelegate; + private selectionDelegate mSelectionActionDelegate; + private historyDelegate mHistoryDelegate; + private promptDelegate mPromptDelegate; + private contentDelegate mContentDelegate; + private scrollDelegate mScrollDelegate; + private autofillDelegate mAutofillDelegate; + private boolean wasBackPressed = false; - private String mSessionID; private boolean mCanGoBack = false; private boolean mCanGoForward = false; - private boolean mFullScreen = false; private boolean isPageLoading = false; private int mProgress = 0; - private boolean isMediaRunning = false; private String mPrevURL = "about:blank"; - private String mCurrentTitle = "loading"; - private String mCurrentURL = "about:blank"; - private String mMediaTitle = ""; - private Bitmap mMediaImage; private Uri mUriPermission = null; private WeakReference mContext; - private geckoDownloadManager mDownloadManager; - private String mTheme = null; private boolean mPreviousErrorPage = false; private boolean mRemovableFromBackPressed = false; - private boolean mThemeChanged = false; - private int mScollOffset = 0; - private selectionActionDelegate mSelectionActionDelegate; private SecurityInformation securityInfo = null; /*Temp Variables*/ - private GeckoSession.HistoryDelegate.HistoryList mHistoryList = null; - private int m_current_url_id = -1; - private GeckoView mGeckoView; private boolean mIsLoaded = false; public boolean isFirstPaintExecuted = false; private boolean mIsProgressBarChanging = false; private Handler mFindHandler; private boolean mClosed = false; - public boolean mCloseRequested = false; public boolean mOnBackPressed = false; public SessionState mSessionState; - public mediaDelegate mediaDelegateItem; - MediaSession mMediaSession = null; + public mediaDelegate mMediaDelegate; - geckoSession(eventObserver.eventListener event, String mSessionID, AppCompatActivity mContext, GeckoView pGeckoView) { + geckoSession(eventObserver.eventListener event, String pSessionID, AppCompatActivity mContext, GeckoView pGeckoView) { - this.mGeckoView = pGeckoView; this.mContext = new WeakReference(mContext); - this.mSessionID = mSessionID; - this.event = event; + this.mEvent = event; + this.mGeckoDataModel = new geckoDataModel(); + this.mGeckoDataModel.mSessionID = pSessionID; + + this.mMediaDelegate = new mediaDelegate(this.mContext); + this.mSelectionActionDelegate = new selectionDelegate(mContext, true); + this.mMediaSessionDelegate = new mediaSessionDelegate(this.mContext, mGeckoDataModel, mMediaDelegate); + this.mHistoryDelegate = new historyDelegate(this.mContext, mEvent, mGeckoDataModel, this); + this.mPromptDelegate = new promptDelegate(mContext); + this.mContentDelegate = new contentDelegate(this.mContext, mEvent, mGeckoDataModel, this); + this.mScrollDelegate = new scrollDelegate(mEvent, mGeckoDataModel); + this.mAutofillDelegate = new autofillDelegate(pGeckoView); onSessionReinit(); + setSelectionActionDelegate(this.mSelectionActionDelegate); + setMediaSessionDelegate(this.mMediaSessionDelegate); + setHistoryDelegate(this.mHistoryDelegate); + setPromptDelegate(this.mPromptDelegate); + setContentDelegate(this.mContentDelegate); + setMediaDelegate(this.mMediaDelegate); + setScrollDelegate(this.mScrollDelegate); + setAutofillDelegate(this.mAutofillDelegate); + setProgressDelegate(this); - setHistoryDelegate(this); setNavigationDelegate(this); - setContentDelegate(this); - setAutoFillDelegate(); setPermissionDelegate(this); - setScrollDelegate(this); - setMediaSessionDelegate(this); - mediaDelegateItem = new mediaDelegate(mContext, mContext); - - - setMediaDelegate(mediaDelegateItem); - mDownloadManager = new geckoDownloadManager(); - mSelectionActionDelegate = new selectionActionDelegate(mContext, true); - setPromptDelegate(new geckoPromptView(mContext)); - setSelectionActionDelegate(mSelectionActionDelegate); } - @Override - public void onActivated(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { - MediaSession.Delegate.super.onActivated(session, mediaSession); - mMediaSession = mediaSession; - isMediaRunning = true; - } - - @Override - public void onDeactivated(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { - MediaSession.Delegate.super.onPause(session, mediaSession); - if(isMediaRunning){ - mediaDelegateItem.onHideDefaultNotification(); - } - isMediaRunning = false; - } - - @Override - public void onMetadata(@NonNull GeckoSession session, @NonNull MediaSession mediaSession, @NonNull MediaSession.Metadata meta) { - mMediaTitle = meta.title; - isPageLoading = false; - - if(mediaDelegateItem == null){ - return; - } - - new Thread(){ - public void run(){ - try { - mMediaImage = meta.artwork.getBitmap(250).poll(2500); - if(isMediaRunning && mMediaSession!=null){ - mediaDelegateItem.showNotification(mContext.get(), mMediaTitle, helperMethod.getHost(mCurrentURL), mMediaImage, !isMediaRunning); - } - } catch (Throwable e) { - e.printStackTrace(); - } - } - }.start(); - MediaSession.Delegate.super.onMetadata(session, mediaSession, meta); - if(isMediaRunning){ - mediaDelegateItem.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mCurrentURL), mMediaImage, !isMediaRunning); - } - } - - @Override - public void onFeatures(@NonNull GeckoSession session, @NonNull MediaSession mediaSession, long features) { - MediaSession.Delegate.super.onFeatures(session, mediaSession, features); - } - - @Override - public void onPlay(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { - MediaSession.Delegate.super.onPlay(session, mediaSession); - mediaDelegateItem.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mCurrentURL), mMediaImage, false); - isMediaRunning = true; - } - - @Override - public void onPause(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { - MediaSession.Delegate.super.onPause(session, mediaSession); - if(isMediaRunning){ - mediaDelegateItem.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mCurrentURL), mMediaImage, true); - } - isMediaRunning = false; - } - - @Override - public void onStop(@NonNull GeckoSession session, @NonNull MediaSession mediaSession) { - MediaSession.Delegate.super.onStop(session, mediaSession); - if(isMediaRunning){ - mediaDelegateItem.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mCurrentURL), mMediaImage, true); - } - isMediaRunning = false; - } - - @Override - public void onPositionState(@NonNull GeckoSession session, @NonNull MediaSession mediaSession, @NonNull MediaSession.PositionState state) { - MediaSession.Delegate.super.onPositionState(session, mediaSession, state); - } - - @Override - public void onFullscreen(@NonNull GeckoSession session, @NonNull MediaSession mediaSession, boolean enabled, @Nullable @org.jetbrains.annotations.Nullable MediaSession.ElementMetadata meta) { - MediaSession.Delegate.super.onFullscreen(session, mediaSession, enabled, meta); - } public void onDestroy() { close(); @@ -234,17 +148,12 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate setHistoryDelegate(null); setNavigationDelegate(null); setContentDelegate(null); - setAutoFillDelegate(); setPermissionDelegate(null); setScrollDelegate(null); - mDownloadManager = null; setPromptDelegate(null); - event = null; + mEvent = null; mContext = null; - mDownloadManager = null; - mHistoryList = null; mFindHandler = null; - mGeckoView = null; } public void onSetInitializeFromStartup() { @@ -258,79 +167,26 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate public boolean onValidateInitializeFromStartup() { if (!mIsLoaded) { mIsLoaded = true; - initURL(mCurrentURL); + initURL(mGeckoDataModel.mCurrentURL); return true; } return false; } void onFileUploadRequest(int resultCode, Intent data) { - - geckoPromptView mPromptDelegate = (geckoPromptView) getPromptDelegate(); Objects.requireNonNull(mPromptDelegate).onFileCallbackResult(resultCode, data); } - public void onKillMedia() { - isMediaRunning = false; - if(mMediaSession!=null){ - mMediaSession.pause(); - mediaDelegateItem.onHideDefaultNotification(); - } - } - - public void onDestroyMedia() { - isMediaRunning = false; - if(mMediaSession!=null){ - mMediaSession.stop(); - mediaDelegateItem.onHideDefaultNotification(); - mMediaSession = null; - } - mediaDelegateItem.onHideDefaultNotification(); - } - - public void onStopMedia() { - if (mMediaSession != null) { - mMediaSession.pause(); - } - } - - public void onPlayMedia(){ - isMediaRunning = true; - if(mMediaSession != null){ - mediaDelegateItem.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mCurrentURL), mMediaImage, false); - mMediaSession.play(); - } - } - - public void onPauseMedia(){ - if(mMediaSession != null){ - mediaDelegateItem.showNotification(this.mContext.get(), mMediaTitle, helperMethod.getHost(mCurrentURL), mMediaImage, true); - mMediaSession.pause(); - } - } - - public void onSkipForwardMedia(){ - if(mMediaSession != null){ - mMediaSession.nextTrack(); - } - } - - public void onSkipBackwardMedia(){ - if(mMediaSession != null){ - mMediaSession.previousTrack(); - } - } - public void onSessionReinit() { if (mClosed) { return; } - mCrashCount = 0; + mContentDelegate.resetCrash(); if (!isFirstPaintExecuted) { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id), enums.etype.ON_SESSION_REINIT); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID), enums.etype.ON_SESSION_REINIT); } else { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id), enums.etype.ON_FIRST_PAINT); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID), enums.etype.ON_FIRST_PAINT); } mFindHandler = new Handler(); @@ -344,97 +200,28 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } + public historyDelegate getHistoryDelegate(){ + return mHistoryDelegate; + } + void initURL(String url) { if (mIsLoaded) { - mCrashCount = 0; + mContentDelegate.resetCrash(); isPageLoading = true; - setURL(url); - mCurrentTitle = mCurrentURL; + mHistoryDelegate.setURL(url); + mGeckoDataModel.mCurrentTitle = mGeckoDataModel.mCurrentURL; - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle), enums.etype.on_update_suggestion); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle), enums.etype.on_update_suggestion); if (!url.equals("about:blank") && !url.equals("about:config")) { mProgress = 5; onProgressStart(); } - m_current_url_id = -1; + mGeckoDataModel.mCurrentURL_ID = -1; } } - /*Scroll Delegate*/ - @UiThread - public void onScrollChanged(@NonNull GeckoSession session, int scrollX, int scrollY) { - Log.i("fucker111 : ", scrollY + ""); - mScollOffset = scrollY; - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme), enums.etype.M_UPDATE_PIXEL_BACKGROUND); - if (scrollY <= 3) { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme), enums.etype.M_ON_SCROLL_TOP_BOUNDARIES); - } else if (scrollY <= helperMethod.pxFromDp(30)) { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme), enums.etype.M_ON_SCROLL_BOUNDARIES); - } else { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme), enums.etype.M_ON_SCROLL_NO_BOUNDARIES); - } - - } - - public int getScrollOffset() { - return mScollOffset; - } - /*Autofill Delegate*/ - public void setAutoFillDelegate() { - this.setAutofillDelegate(new AndroidAutofillDelegate()); - } - - private class AndroidAutofillDelegate implements Autofill.Delegate { - - private Rect displayRectForId(@NonNull final GeckoSession session, - @NonNull final Autofill.Node node) { - final Matrix matrix = new Matrix(); - final RectF rectF = new RectF(node.getDimensions()); - session.getPageToScreenMatrix(matrix); - matrix.mapRect(rectF); - - final Rect screenRect = new Rect(); - rectF.roundOut(screenRect); - return screenRect; - } - - @Override - public void onNodeUpdate( - @NonNull final GeckoSession session, - @NonNull final Autofill.Node node, - @NonNull final Autofill.NodeData data) { - - final AutofillManager manager; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - manager = mGeckoView.getContext().getSystemService(AutofillManager.class); - if (manager == null) { - return; - } - manager.notifyViewEntered(mGeckoView, data.getId(),displayRectForId(session, node)); - } - - } - - @Override - public void onNodeFocus( - @NonNull final GeckoSession session, - @NonNull final Autofill.Node node, - @NonNull final Autofill.NodeData data) { - - final AutofillManager manager; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - manager = mGeckoView.getContext().getSystemService(AutofillManager.class); - if (manager == null) { - return; - } - manager.notifyViewEntered(mGeckoView, data.getId(),displayRectForId(session, node)); - } - } - - - } /*Progress Delegate*/ @UiThread @@ -442,80 +229,54 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate this.securityInfo = securityInfo; } - - - - - - - - - - - - - - - - - - - - - - @Override public void onPageStart(@NonNull GeckoSession var1, @NonNull String var2) { - mCloseRequested = false; isFirstPaintExecuted = false; + mEvent.invokeObserver(Arrays.asList(var2, mGeckoDataModel.mSessionID), enums.etype.search_update); if (mIsLoaded) { - if (!mCurrentURL.equals("about:config") && !var2.equals("about:blank") && helperMethod.getHost(var2).endsWith(".onion")) { + if (!mGeckoDataModel.mCurrentURL.equals("about:config") && !var2.equals("about:blank") && helperMethod.getHost(var2).endsWith(".onion")) { var2 = var2.replace("www.", ""); } - if(mCurrentURL.replace("http","https://").equals(var2)){ - mCurrentURL = var2; + if(mGeckoDataModel.mCurrentURL.replace("http","https://").equals(var2)){ + mGeckoDataModel.mCurrentURL = var2; + this.mGeckoDataModel.mCurrentURL = var2; } - if (!mCurrentURL.equals("about:config") && !mCurrentURL.equals("about:blank")) { - //event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); - mContext.get().runOnUiThread(() -> event.invokeObserver(Arrays.asList(5, mSessionID), enums.etype.progress_update)); + if (!mGeckoDataModel.mCurrentURL.equals("about:config") && !mGeckoDataModel.mCurrentURL.equals("about:blank") && !var2.equals("about:blank")) { + //event.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.m_current_url_id, mGeckoDataModel.mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); + mContext.get().runOnUiThread(() -> mEvent.invokeObserver(Arrays.asList(5, mGeckoDataModel.mSessionID), enums.etype.progress_update)); + mHistoryDelegate.setURL(var2); + //mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); } if (!isPageLoading) { - mCurrentTitle = "loading"; - m_current_url_id = -1; - mThemeChanged = false; + mGeckoDataModel.mCurrentTitle = "loading"; + mGeckoDataModel.mCurrentURL_ID = -1; + mGeckoDataModel.mThemeChanged = false; } isPageLoading = true; - if (!mCurrentURL.equals("about:config") && !mCurrentURL.equals("about:blank") && !mCurrentTitle.equals("loading")) { + if (!mGeckoDataModel.mCurrentURL.equals("about:config") && !mGeckoDataModel.mCurrentURL.equals("about:blank") && !mGeckoDataModel.mCurrentTitle.equals("loading")) { mProgress = 5; - mContext.get().runOnUiThread(() -> event.invokeObserver(Arrays.asList(5, mSessionID), enums.etype.progress_update)); - mThemeChanged = false; + mContext.get().runOnUiThread(() -> mEvent.invokeObserver(Arrays.asList(5, mGeckoDataModel.mSessionID), enums.etype.progress_update)); + mGeckoDataModel.mThemeChanged = false; } } } - @UiThread - public @Nullable - GeckoResult onSlowScript(@NonNull final GeckoSession geckoSession, @NonNull final String scriptFileName) { - return null; - } - @UiThread public void onPageStop(@NonNull GeckoSession var1, boolean var2) { - mCloseRequested = !var2; if (var2) { if (mProgress >= 100) { - event.invokeObserver(Arrays.asList(null, mSessionID), enums.etype.on_page_loaded); + mEvent.invokeObserver(Arrays.asList(null, mGeckoDataModel.mSessionID), enums.etype.on_page_loaded); - if (!mThemeChanged) { + if (!mGeckoDataModel.mThemeChanged) { new Handler().postDelayed(() -> { - if (!mThemeChanged) { - mTheme = null; - if (event != null) { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), enums.etype.ON_UPDATE_THEME); + if (!mGeckoDataModel.mThemeChanged) { + mGeckoDataModel.mTheme = null; + if (mEvent != null) { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), enums.etype.ON_UPDATE_THEME); } } }, 500); @@ -527,28 +288,28 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate @Override public void onProgressChange(@NonNull GeckoSession session, int progress) { - if (!mFullScreen) { + if (!mGeckoDataModel.mFullScreenStatus) { mProgress = progress; if (progress <= 20) { mIsProgressBarChanging = false; - mContext.get().runOnUiThread(() -> event.invokeObserver(Arrays.asList(5, mSessionID), enums.etype.progress_update)); + mContext.get().runOnUiThread(() -> mEvent.invokeObserver(Arrays.asList(5, mGeckoDataModel.mSessionID), enums.etype.progress_update)); } else { if (progress == 100) { - event.invokeObserver(Arrays.asList(mSessionID, mCurrentTitle, m_current_url_id, mTheme, this), enums.etype.ON_INVOKE_PARSER); - if (!mCurrentURL.startsWith(constants.CONST_GENESIS_DOMAIN_URL) && !mCurrentURL.contains("genesis") && !wasPreviousErrorPage()) { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme, this), enums.etype.ON_INVOKE_PARSER); + if (!mGeckoDataModel.mCurrentURL.startsWith(constants.CONST_GENESIS_DOMAIN_URL) && !mGeckoDataModel.mCurrentURL.contains("genesis") && !wasPreviousErrorPage()) { checkApplicationRate(); } if (!mIsProgressBarChanging) { mIsProgressBarChanging = true; mContext.get().runOnUiThread(() -> { - event.invokeObserver(Arrays.asList(mProgress, mSessionID), enums.etype.progress_update); + mEvent.invokeObserver(Arrays.asList(mProgress, mGeckoDataModel.mSessionID), enums.etype.progress_update); }); } mPreviousErrorPage = false; } else { mIsProgressBarChanging = false; - mContext.get().runOnUiThread(() -> event.invokeObserver(Arrays.asList(mProgress, mSessionID), enums.etype.progress_update)); + mContext.get().runOnUiThread(() -> mEvent.invokeObserver(Arrays.asList(mProgress, mGeckoDataModel.mSessionID), enums.etype.progress_update)); } } } @@ -589,12 +350,12 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate public void onProgressStart() { if (!getCurrentURL().equals("about:config") && !getCurrentURL().equals("about:blank") && !getCurrentURL().contains("167.86.99.31") && !wasPreviousErrorPage() && !getCurrentURL().startsWith(CONST_GENESIS_URL_CACHED) && !getCurrentURL().startsWith(CONST_GENESIS_URL_CACHED_DARK) && !getCurrentURL().startsWith(CONST_GENESIS_HELP_URL_CACHE) && !getCurrentURL().startsWith(CONST_GENESIS_HELP_URL_CACHE_DARK)) { - mContext.get().runOnUiThread(() -> event.invokeObserver(Arrays.asList(5, mSessionID), enums.etype.progress_update)); + mContext.get().runOnUiThread(() -> mEvent.invokeObserver(Arrays.asList(5, mGeckoDataModel.mSessionID), enums.etype.progress_update)); } } public void onRedrawPixel() { - event.invokeObserver(Arrays.asList("", mSessionID, mCurrentTitle, m_current_url_id, mTheme, false), dataEnums.eTabCommands.M_UPDATE_PIXEL); + mEvent.invokeObserver(Arrays.asList("", mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme, false), dataEnums.eTabCommands.M_UPDATE_PIXEL); } public boolean isLoaded() { @@ -602,43 +363,11 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } /*History Delegate*/ - @Override - public GeckoResult onVisited(@NonNull GeckoSession var1, @NonNull String var2, @Nullable String var3, int var4) { - - return null; - } - - int mHistoryListSize = 0; - @UiThread - public void onHistoryStateChange(@NonNull GeckoSession var1, @NonNull GeckoSession.HistoryDelegate.HistoryList var2) { - mHistoryList = var2; - - - if(mHistoryList!=null){ - setURL(mHistoryList.get(mHistoryList.getCurrentIndex()).getUri()); - event.invokeObserver(Arrays.asList(mHistoryList, mSessionID), enums.etype.on_url_load); - if(mHistoryListSize == var2.size()){ - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mHistoryList.get(mHistoryList.getCurrentIndex()).getTitle(), m_current_url_id, mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); - Object mID = event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mHistoryList.get(mHistoryList.getCurrentIndex()).getTitle(), m_current_url_id, mTheme, this, wasBackPressed), enums.etype.on_update_history); - if (mID != null) { - m_current_url_id = (int) mID; - } - }else { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mHistoryList.get(mHistoryList.getCurrentIndex()).getTitle(), m_current_url_id, mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); - Object mID = event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mHistoryList.get(mHistoryList.getCurrentIndex()).getTitle(), -1, mTheme, this, wasBackPressed), enums.etype.on_update_history); - if (mID != null) { - m_current_url_id = (int) mID; - } - } - mHistoryListSize = var2.size(); - onDestroyMedia(); - } - } @UiThread public void onSessionStateChange(@NonNull GeckoSession session, @NonNull SessionState sessionState) { mSessionState = sessionState; - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme, sessionState.toString()), enums.etype.M_UPDATE_SESSION_STATE); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mCurrentURL_ID, mGeckoDataModel.mTheme, sessionState.toString()), enums.etype.M_UPDATE_SESSION_STATE); } @@ -652,6 +381,13 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } } + @UiThread + @Nullable + public GeckoResult onNewSession(@NonNull final GeckoSession session, @NonNull final String uri) { + initURL(uri); + return null; + } + /*Navigation Delegate*/ public void onLocationChange(@NonNull GeckoSession var1, @Nullable String var2) { @@ -661,8 +397,8 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate boolean mPastURLVerify = false; try { - if (mHistoryList.getCurrentIndex() - 1 >= 0 && mHistoryList.getCurrentIndex() - 1 < mHistoryList.size()) { - mPastURLVerify = mHistoryList.get(mHistoryList.getCurrentIndex() - 1).getUri().equals(var2); + if (mHistoryDelegate.isHistoryEmpty()) { + //mPastURLVerify = mHistoryList.get(mHistoryList.getCurrentIndex() - 1).getUri().equals(var2); } } catch (Exception ignored) { } @@ -671,10 +407,10 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate if (var2.equals("http://167.86.99.31") || var2.startsWith(CONST_GENESIS_URL_CACHED) || var2.startsWith(CONST_GENESIS_URL_CACHED_DARK)) { if (var2.startsWith(CONST_GENESIS_URL_CACHED_DARK) && (status.sTheme == enums.Theme.THEME_LIGHT || helperMethod.isDayMode(mContext.get()))) { isPageLoading = false; - event.invokeObserver(null, enums.etype.M_CHANGE_HOME_THEME); + mEvent.invokeObserver(null, enums.etype.M_CHANGE_HOME_THEME); } else if (var2.startsWith(CONST_GENESIS_URL_CACHED) && (status.sTheme != enums.Theme.THEME_LIGHT && !helperMethod.isDayMode(mContext.get()))) { isPageLoading = false; - event.invokeObserver(null, enums.etype.M_CHANGE_HOME_THEME); + mEvent.invokeObserver(null, enums.etype.M_CHANGE_HOME_THEME); } } } @@ -682,25 +418,16 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate wasBackPressed = false; String newUrl = Objects.requireNonNull(var2).split("#")[0]; - if (!mCurrentTitle.equals("loading")) { - //Object mURL = event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme, this, false), enums.etype.on_update_history); - //if (mURL != null) { - // m_current_url_id = (int) mURL; - //} - } if (newUrl.startsWith(CONST_GENESIS_URL_CACHED) || newUrl.startsWith(CONST_GENESIS_URL_CACHED_DARK)) { - setURL(constants.CONST_GENESIS_DOMAIN_URL); + mHistoryDelegate.setURL(constants.CONST_GENESIS_DOMAIN_URL); } else if (newUrl.equals(constants.CONST_GENESIS_HELP_URL_CACHE)) { if (status.sTheme == enums.Theme.THEME_LIGHT || helperMethod.isDayMode(mContext.get())) { - setURL(constants.CONST_GENESIS_HELP_URL); + mHistoryDelegate.setURL(constants.CONST_GENESIS_HELP_URL); } else { - setURL(constants.CONST_GENESIS_HELP_URL_CACHE_DARK); + mHistoryDelegate.setURL(constants.CONST_GENESIS_HELP_URL_CACHE_DARK); } } else if (!newUrl.equals("about:blank")) { - setURL(newUrl); - } - if (!mCurrentURL.equals("about:blank")) { - //event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); + mHistoryDelegate.setURL(newUrl); } } @@ -717,48 +444,17 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } } - /* package */ class Pref { - public final String name; - public final T defaultValue; - private T mValue; - private boolean mIsSet; - - public Pref(@NonNull final String name, final T defaultValue) { - this.name = name; - this.defaultValue = defaultValue; - mValue = defaultValue; - - } - public void add() { - final GeckoBundle prefs = new GeckoBundle(1); - prefs.putInt(this.name, (Integer)this.defaultValue); - EventDispatcher.getInstance().dispatch("GeckoView:SetDefaultPrefs", prefs); - addToBundle(prefs); - } - - private void addToBundle(final GeckoBundle bundle) { - final T value = mIsSet ? mValue : defaultValue; - if (value instanceof String) { - bundle.putString(name, (String) value); - } else if (value instanceof Integer) { - bundle.putInt(name, (Integer) value); - } else if (value instanceof Boolean) { - bundle.putBoolean(name, (Boolean) value); - } else { - throw new UnsupportedOperationException("Unhandled pref type for " + name); - } - } - } - public GeckoResult onLoadRequest(@NonNull GeckoSession var2, @NonNull GeckoSession.NavigationDelegate.LoadRequest var1) { - if(mMediaSession!=null){ - mMediaSession.stop(); - mediaDelegateItem.onHideDefaultNotification(); + if(mMediaSessionDelegate!=null){ + mMediaSessionDelegate.onTrigger(enums.MediaController.STOP); + mMediaSessionDelegate.onTrigger(enums.MediaController.DESTROY); + + mMediaDelegate.onHideDefaultNotification(); } if (var1.uri.contains("167.86.99.31")) { - new Pref("network.proxy.type", 0).add(); + new preferences<>("network.proxy.type", 0).add(); }else { - new Pref("network.proxy.type", 1).add(); + new preferences<>("network.proxy.type", 1).add(); } String m_url = var1.uri; @@ -768,13 +464,13 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate if (m_url.endsWith("genesisconfigurenewidentity.com/")) { initURL(mPrevURL); - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), enums.etype.M_NEW_IDENTITY_MESSAGED); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), enums.etype.M_NEW_IDENTITY_MESSAGED); return GeckoResult.fromValue(AllowOrDeny.DENY); } String mNormalizeURL = helperMethod.normalize(m_url); if (mNormalizeURL != null && mNormalizeURL.endsWith("167.86.99.31")) { initURL(constants.CONST_GENESIS_DOMAIN_URL); - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, false), enums.etype.M_LOAD_HOMEPAGE_GENESIS); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, false), enums.etype.M_LOAD_HOMEPAGE_GENESIS); return GeckoResult.fromValue(AllowOrDeny.DENY); } if (!m_url.contains(constants.CONST_GENESIS_GMT_TIME_GET_KEY) && !m_url.startsWith(CONST_GENESIS_URL_CACHED) && !m_url.startsWith(CONST_GENESIS_URL_CACHED_DARK) && var1.uri.startsWith("http://167.86.99.31") && !var1.uri.contains(constants.CONST_GENESIS_LOCAL_TIME_GET_KEY) && !var1.uri.contains(constants.CONST_GENESIS_LOCAL_TIME_GET_KEY)) { @@ -784,44 +480,43 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate loadUri(mVerificationURL); return GeckoResult.fromValue(AllowOrDeny.DENY); } else if (m_url.startsWith("mailto")) { - event.invokeObserver(Arrays.asList(m_url, mSessionID), enums.etype.M_ON_MAIL); + mEvent.invokeObserver(Arrays.asList(m_url, mGeckoDataModel.mSessionID), enums.etype.M_ON_MAIL); return GeckoResult.fromValue(AllowOrDeny.ALLOW); } else if (m_url.contains("167.86.99.31/advert__")) { - event.invokeObserver(Arrays.asList(m_url, mSessionID), enums.etype.on_playstore_load); + mEvent.invokeObserver(Arrays.asList(m_url, mGeckoDataModel.mSessionID), enums.etype.on_playstore_load); return GeckoResult.fromValue(AllowOrDeny.DENY); } else if (m_url.equals(constants.CONST_GENESIS_DOMAIN_URL_SLASHED) || m_url.startsWith("http://167.86.99.31/?")) { initURL(constants.CONST_GENESIS_DOMAIN_URL); - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, false), enums.etype.M_LOAD_HOMEPAGE_GENESIS); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, false), enums.etype.M_LOAD_HOMEPAGE_GENESIS); return GeckoResult.fromValue(AllowOrDeny.DENY); } else if (m_url.equals("about:blank") && mIsLoaded) { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), enums.etype.ON_EXPAND_TOP_BAR); - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, false), enums.etype.M_ON_BANNER_UPDATE); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), enums.etype.ON_EXPAND_TOP_BAR); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, false), enums.etype.M_ON_BANNER_UPDATE); return GeckoResult.fromValue(AllowOrDeny.ALLOW); } else if (var1.target == 2) { - event.invokeObserver(Arrays.asList(m_url, mSessionID), enums.etype.open_new_tab); - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), enums.etype.ON_EXPAND_TOP_BAR); + mEvent.invokeObserver(Arrays.asList(m_url, mGeckoDataModel.mSessionID), enums.etype.open_new_tab); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), enums.etype.ON_EXPAND_TOP_BAR); return GeckoResult.fromValue(AllowOrDeny.DENY); } else if (!m_url.equals("about:blank")) { - if (mCurrentURL.startsWith(CONST_GENESIS_URL_CACHED) || mCurrentURL.startsWith(CONST_GENESIS_URL_CACHED_DARK)) { - setURL(constants.CONST_GENESIS_DOMAIN_URL); - } else if (mCurrentURL.equals(constants.CONST_GENESIS_HELP_URL_CACHE)) { + if (mGeckoDataModel.mCurrentURL.startsWith(CONST_GENESIS_URL_CACHED) || mGeckoDataModel.mCurrentURL.startsWith(CONST_GENESIS_URL_CACHED_DARK)) { + mHistoryDelegate.setURL(constants.CONST_GENESIS_DOMAIN_URL); + } else if (mGeckoDataModel.mCurrentURL.equals(constants.CONST_GENESIS_HELP_URL_CACHE)) { if (status.sTheme == enums.Theme.THEME_LIGHT || helperMethod.isDayMode(mContext.get())) { - setURL(constants.CONST_GENESIS_HELP_URL); + mHistoryDelegate.setURL(constants.CONST_GENESIS_HELP_URL); } else { - setURL(constants.CONST_GENESIS_HELP_URL_CACHE_DARK); + mHistoryDelegate.setURL(constants.CONST_GENESIS_HELP_URL_CACHE_DARK); } } else if (!m_url.startsWith("resource://android/assets/homepage/")) { - setURL(m_url); + mHistoryDelegate.setURL(m_url); } - event.invokeObserver(Arrays.asList(m_url, mSessionID), enums.etype.start_proxy); - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID), enums.etype.search_update); + mEvent.invokeObserver(Arrays.asList(m_url, mGeckoDataModel.mSessionID), enums.etype.start_proxy); /* Its Absence causes delay on first launch*/ - //event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); + //event.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.m_current_url_id, mGeckoDataModel.mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); - if (!m_url.equals("about:config") && !mCurrentURL.contains("167.86.99.31")) { + if (!m_url.equals("about:config") && !mGeckoDataModel.mCurrentURL.contains("167.86.99.31")) { mProgress = 5; onProgressStart(); } @@ -833,39 +528,26 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } public void onUpdateBannerAdvert() { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, false), enums.etype.M_ON_BANNER_UPDATE); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, false), enums.etype.M_ON_BANNER_UPDATE); } public void onClose() { stop(); if (!mPrevURL.equals("about:blank")) { - mCurrentURL = mPrevURL; + this.mGeckoDataModel.mCurrentURL = mPrevURL; } else { - mPrevURL = mCurrentURL; + mPrevURL = mGeckoDataModel.mCurrentURL; } - if (mediaDelegateItem != null) { - mediaDelegateItem.onHideDefaultNotification(); + if (mMediaDelegate != null) { + mMediaDelegate.onHideDefaultNotification(); } - //mIsLoaded = false; - //isPageLoading = false; } - @Override - public void onCanGoBack(@NonNull GeckoSession session, boolean var2) { - mCanGoBack = var2; - } - - @Override - public void onCanGoForward(@NonNull GeckoSession session, boolean var2) { - mCanGoForward = var2; - } - - public GeckoResult onLoadError(@NonNull GeckoSession var1, @Nullable String var2, @NonNull WebRequestError var3) { try { - if(mediaDelegateItem!=null){ - mediaDelegateItem.onHideDefaultNotification(); + if(mMediaDelegate !=null){ + mMediaDelegate.onHideDefaultNotification(); } if (helperMethod.getHost(var2).endsWith(".onion")) { var2 = var2.replace("www.", ""); @@ -873,17 +555,18 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate if (var2.startsWith("https://trcip42ymcgvv5hsa7nxpwdnott46ebomnn5pm5lovg5hpszyo4n35yd")) { var2 = var2.replace("https", "http"); - mCurrentURL = var2; + mGeckoDataModel.mCurrentURL = var2; + this.mGeckoDataModel.mCurrentURL = var2; } - if (mCurrentURL.contains("orion.onion")) { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), enums.etype.M_NEW_IDENTITY); + if (mGeckoDataModel.mCurrentURL.contains("orion.onion")) { + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), enums.etype.M_NEW_IDENTITY); } if (status.sSettingIsAppStarted && orbotLocalConstants.mIsTorInitialized) { errorHandler handler = new errorHandler(); mProgress = 0; mPreviousErrorPage = true; - event.invokeObserver(Arrays.asList(var2, mSessionID), enums.etype.on_load_error); - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), enums.etype.ON_UPDATE_THEME); + mEvent.invokeObserver(Arrays.asList(var2, mGeckoDataModel.mSessionID), enums.etype.on_load_error); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), enums.etype.ON_UPDATE_THEME); InputStream mResourceURL = null; try { @@ -906,9 +589,10 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate return GeckoResult.fromValue("data:text/html," + handler.createErrorPage(var3.category, var3.code, mContext.get(), var2, mResourceURL)); } else { - event.invokeObserver(Arrays.asList(var2, mSessionID), enums.etype.M_ORBOT_LOADING); - mCurrentURL = mPrevURL; - //event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); + mEvent.invokeObserver(Arrays.asList(var2, mGeckoDataModel.mSessionID), enums.etype.M_ORBOT_LOADING); + mGeckoDataModel.mCurrentURL = mPrevURL; + this.mGeckoDataModel.mCurrentURL = mPrevURL; + //event.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.m_current_url_id, mGeckoDataModel.mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); } return null; } catch (Exception ex) { @@ -917,59 +601,6 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } /*Content Delegate*/ - @UiThread - @Override - public void onExternalResponse(@NonNull GeckoSession session, @NonNull WebResponse response) { - try { - if (response.headers.containsKey("Content-Disposition")) { - mDownloadManager.downloadFile(response, this, mContext.get(), event); - } else if (response.headers.containsKey("Content-Type")) { - mDownloadManager.downloadFile(response, this, mContext.get(), event); - } - } catch (ActivityNotFoundException e) { - event.invokeObserver(Arrays.asList(response, mSessionID), enums.etype.on_handle_external_intent); - stop(); - } - } - - @UiThread - public void onFirstContentfulPaint(@NonNull GeckoSession var1) { - - isFirstPaintExecuted = true; - - - if (mPreviousErrorPage || mCurrentURL.contains("167.86.99.31") || mCurrentURL.startsWith(CONST_GENESIS_URL_CACHED) || mCurrentURL.startsWith(CONST_GENESIS_URL_CACHED_DARK) || mCurrentURL.startsWith(CONST_GENESIS_HELP_URL_CACHE) || mCurrentURL.startsWith(CONST_GENESIS_HELP_URL_CACHE_DARK)) { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, false), enums.etype.M_ON_BANNER_UPDATE); - } else { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, true), enums.etype.M_ON_BANNER_UPDATE); - } - - if (!mCurrentURL.equals("about:blank")) { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme), enums.etype.ON_FIRST_PAINT); - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme), enums.etype.ON_LOAD_REQUEST); - } else { - onSessionReinit(); - } - - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), enums.etype.ON_EXPAND_TOP_BAR); - mPrevURL = mCurrentURL; - } - - @UiThread - public void onWebAppManifest(@NonNull GeckoSession var1, @NonNull JSONObject var2) { - try { - mThemeChanged = true; - mTheme = var2.getString("theme_color"); - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), enums.etype.ON_UPDATE_THEME); - // event.invokeObserver(Arrays.asList(mCurrentURL,mSessionID,mCurrentTitle, m_current_url_id, mTheme), enums.etype.M_INDEX_WEBSITE); - } catch (Exception ex) { - mTheme = null; - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), enums.etype.ON_UPDATE_THEME); - ex.printStackTrace(); - } - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme), enums.etype.ON_UPDATE_TAB_TITLE); - } - @Nullable public GeckoResult onMessage(final @NonNull String nativeApp, final @NonNull Object message, final @NonNull WebExtension.MessageSender sender) { if (message instanceof JSONObject) { @@ -986,126 +617,16 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate return null; } - @UiThread - public void onTitleChange(@NonNull GeckoSession var1, @Nullable String var2) { - if (var2 != null && !var2.equals(strings.GENERIC_EMPTY_STR) && var2.length() > 2 && !var2.equals("about:blank") && mIsLoaded) { - mCurrentTitle = var2; - } + + public void onFullScreenInvoke(boolean var2) { + mSelectionActionDelegate.setFullScreen(mGeckoDataModel.mFullScreenStatus); + this.mSelectionActionDelegate.enableExternalActions(!var2); } - @UiThread - public void onCloseRequest(@NonNull GeckoSession var1) { - if (!canGoBack() && !mClosed) { - mCloseRequested = true; - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle), enums.etype.back_list_empty); - if(mediaDelegateItem!=null){ - mediaDelegateItem.onHideDefaultNotification(); - } - } - } - - int mCrashCount = 0; - - @UiThread - public void onCrash(@NonNull GeckoSession session) { - if(mediaDelegateItem!=null){ - mediaDelegateItem.onHideDefaultNotification(); - } - mCloseRequested = true; - if (!mClosed && status.sSettingIsAppStarted) { - if (event == null) { - return; - } - Object mSessionObject = event.invokeObserver(null, enums.etype.SESSION_ID); - if (mSessionObject == null || getSessionID() == null) { - return; - } - String mSessionID = (String) mSessionObject; - if (mSessionID.equals(getSessionID())) { - if (mCrashCount <= 5) { - final Handler handler = new Handler(); - handler.postDelayed(() -> { - try { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme, this), enums.etype.M_OPEN_SESSION); - } catch (Exception ignored) { - } - }, mCrashCount * 500); - } - mCrashCount += 1; - } - } - } - - @UiThread - public void onKill(@NonNull GeckoSession session) { - if(mediaDelegateItem!=null){ - mediaDelegateItem.onHideDefaultNotification(); - } - mCloseRequested = true; - if (!mClosed && status.sSettingIsAppStarted) { - if (event == null) { - return; - } - Object mSessionObject = event.invokeObserver(null, enums.etype.SESSION_ID); - if (mSessionObject == null || getSessionID() == null) { - return; - } - String mSessionID = (String) mSessionObject; - - - if (mSessionID.equals(getSessionID())) { - if (mCrashCount <= 5) { - final Handler handler = new Handler(); - handler.postDelayed(() -> { - if (status.sSettingIsAppStarted && !session.isOpen()) { - try { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme, this), enums.etype.M_OPEN_SESSION); - } catch (Exception ignored) { - } - } - }, mCrashCount * 500); - } - mCrashCount += 1; - } - } - } - - @Override - public void onFullScreen(@NonNull GeckoSession var1, boolean var2) { - mFullScreen = var2; - mSelectionActionDelegate.setFullScreen(mFullScreen); - event.invokeObserver(Arrays.asList(var2, mSessionID), enums.etype.on_full_screen); - } - - @UiThread - @Override - public void onContextMenu(@NonNull GeckoSession var1, int var2, int var3, @NonNull GeckoSession.ContentDelegate.ContextElement var4) { - - String title = strings.GENERIC_EMPTY_STR; - if (var4.title != null) { - title = var4.title; - } - if (var4.type != 0 && var4.srcUri != null) { - if (var4.linkUri != null) { - event.invokeObserver(Arrays.asList(var4.linkUri, mSessionID, var4.srcUri, title, mTheme, var4.altText, this, mContext.get()), M_LONG_PRESS_WITH_LINK); - } else { - try { - String mTitle = var4.title; - if (mTitle == null || mTitle.length() <= 0) { - mTitle = helperMethod.getDomainName(mCurrentURL) + "\n" + var4.srcUri; - } - event.invokeObserver(Arrays.asList(var4.srcUri, mSessionID, mTitle, mTheme, this, mContext.get()), enums.etype.on_long_press); - } catch (Exception ex) { - ex.printStackTrace(); - Log.i("", ""); - } - } - } else if (var4.linkUri != null) { - event.invokeObserver(Arrays.asList(var4.linkUri, mSessionID, title, mTheme, this, mContext.get()), M_LONG_PRESS_URL); - } - } void downloadRequestedFile() { + geckoDownloadManager mDownloadManager = mContentDelegate.getDownloadManager(); + if (mDownloadManager.getDownloadURL() != null && mDownloadManager.getDownloadFile() != null) { if (!createAndSaveFileFromBase64Url(mDownloadManager.getDownloadURL().toString())) { pluginController.getInstance().onDownloadInvoke(Arrays.asList(mDownloadManager.getDownloadURL(), mDownloadManager.getDownloadFile()), pluginEnums.eDownloadManager.M_WEB_DOWNLOAD_REQUEST); @@ -1231,6 +752,18 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } } + public mediaSessionDelegate getMediaSessionDelegate(){ + return mMediaSessionDelegate; + } + + public scrollDelegate getmScrollDelegate(){ + return mScrollDelegate; + } + + public contentDelegate getContentDelegate(){ + return mContentDelegate; + } + /*Helper Methods*/ void toogleUserAgent() { @@ -1247,11 +780,11 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } public String getCurrentURL() { - return mCurrentURL; + return mGeckoDataModel.mCurrentURL; } public String getTitle() { - return mCurrentTitle; + return mGeckoDataModel.mCurrentTitle; } public int getProgress() { @@ -1259,19 +792,7 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } public void setTitle(String title) { - mCurrentTitle = title; - } - - public void setURL(String pURL) { - if (helperMethod.getHost(pURL).endsWith(".onion")) { - pURL = pURL.replace("www.", ""); - } - mCurrentURL = pURL; - if(pURL.startsWith("tel:")){ - Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(pURL)); - mContext.get().startActivity(intent); - } - //event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id, mTheme, this), enums.etype.ON_UPDATE_SEARCH_BAR); + mGeckoDataModel.mCurrentTitle = title; } public void setRemovableFromBackPressed(boolean pStatus) { @@ -1279,7 +800,7 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } public boolean getRemovableFromBackPressed() { - if (mCurrentURL.startsWith("data") || mCurrentURL.startsWith("blob")) { + if (mGeckoDataModel.mCurrentURL.startsWith("data") || mGeckoDataModel.mCurrentURL.startsWith("blob")) { return true; } else { return mRemovableFromBackPressed; @@ -1287,15 +808,26 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } public void setTheme(String pTheme) { - mTheme = pTheme; + mGeckoDataModel.mTheme = pTheme; } public String getTheme() { - return mTheme; + return mGeckoDataModel.mTheme; } + @Override + public void onCanGoBack(@NonNull GeckoSession session, boolean var2) { + mCanGoBack = var2; + } + + @Override + public void onCanGoForward(@NonNull GeckoSession session, boolean var2) { + mCanGoForward = var2; + } + + boolean canGoBack() { - if (mHistoryList == null || mHistoryList.size() == 0) { + if (mHistoryDelegate.isHistoryEmpty()) { return false; } return mCanGoBack; @@ -1310,30 +842,26 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } public String getSessionID() { - return mSessionID; + return mGeckoDataModel.mSessionID; } public void setSessionID(String pSession) { - mSessionID = pSession; + mGeckoDataModel.mSessionID = pSession; } void exitScreen() { this.exitFullScreen(); } - boolean getFullScreenStatus() { - return !mFullScreen; - } - public void closeSession() { - event.invokeObserver(Arrays.asList(null, mSessionID), enums.etype.on_close_sesson); + mEvent.invokeObserver(Arrays.asList(null, mGeckoDataModel.mSessionID), enums.etype.on_close_sesson); } public void closeSessionInstant() { - if (mediaDelegateItem != null) { - mediaDelegateItem.onHideDefaultNotification(); + if (mMediaDelegate != null) { + mMediaDelegate.onHideDefaultNotification(); } - mSessionID = "-1"; + mGeckoDataModel.mSessionID = "-1"; new Handler().postDelayed(() -> { mClosed = true; @@ -1368,7 +896,7 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate try { FinderResult mResult = mFinder.poll(1000); - event.invokeObserver(Arrays.asList(mResult.total, mResult.current), enums.etype.FINDER_RESULT_CALLBACK); + mEvent.invokeObserver(Arrays.asList(mResult.total, mResult.current), enums.etype.FINDER_RESULT_CALLBACK); } catch (Throwable throwable) { throwable.printStackTrace(); } @@ -1378,55 +906,22 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate } void goBackSession() { - if(mMediaSession!=null){ - isMediaRunning = false; - mMediaSession.stop(); - mediaDelegateItem.onHideDefaultNotification(); + if(mMediaSessionDelegate!=null){ + mMediaSessionDelegate.onTrigger(enums.MediaController.DESTROY); + mMediaDelegate.onHideDefaultNotification(); } wasBackPressed = true; - m_current_url_id = -1; - - mCurrentTitle = mHistoryList.get(mHistoryList.getCurrentIndex()).getTitle(); + mGeckoDataModel.mCurrentURL_ID = -1; goBack(); - - try { - if (mHistoryList != null && mHistoryList.size() >= 1) { - if (mHistoryList.getCurrentIndex() - 1 >= 0 && mHistoryList.getCurrentIndex() - 1 < mHistoryList.size()) { - String mURL = mHistoryList.get(mHistoryList.getCurrentIndex() - 1).getUri(); - if (mURL.startsWith("resource://")) { - new Handler().postDelayed(() -> - { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, false), enums.etype.M_ON_BANNER_UPDATE); - }, 0); - } - } - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, m_current_url_id), enums.etype.ON_FIRST_PAINT); - } - } catch (Exception ignored) { - } } void goForwardSession() { - - if (mHistoryList != null) { - stop(); - int index = mHistoryList.getCurrentIndex() + 1; - initURL(mHistoryList.get(index).getUri()); - if (mHistoryList.size() > index) { - event.invokeObserver(Arrays.asList(mHistoryList.get(index).getUri(), mSessionID), enums.etype.start_proxy); - } - final Handler handler = new Handler(); - handler.postDelayed(this::goForward, 100); - mProgress = 5; - event.invokeObserver(Arrays.asList(5, mSessionID, mCurrentURL), enums.etype.progress_update_forced); - event.invokeObserver(Arrays.asList(5, mSessionID, mCurrentURL), enums.etype.M_ADMOB_BANNER_RECHECK); - } else { - final Handler handler = new Handler(); - handler.postDelayed(this::goForward, 100); - mProgress = 5; - event.invokeObserver(Arrays.asList(5, mSessionID, mCurrentURL), enums.etype.progress_update_forced); - event.invokeObserver(Arrays.asList(5, mSessionID, mCurrentURL), enums.etype.M_ADMOB_BANNER_RECHECK); + if(mMediaSessionDelegate!=null){ + mMediaSessionDelegate.onTrigger(enums.MediaController.STOP); + mMediaDelegate.onHideDefaultNotification(); } + + goForward(); } boolean isLoading() { @@ -1444,13 +939,13 @@ public class geckoSession extends GeckoSession implements MediaSession.Delegate private void checkApplicationRate() { if (status.sSettingIsAppStarted) { if (status.sGlobalURLCount == 10) { - // event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), M_RATE_APPLICATION); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), M_RATE_APPLICATION); } else if ( status.sGlobalURLCount == 20 || status.sGlobalURLCount == 80) { - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), M_DEFAULT_BROWSER); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), M_DEFAULT_BROWSER); } status.sGlobalURLCount += 1; - event.invokeObserver(Arrays.asList(mCurrentURL, mSessionID, mCurrentTitle, mTheme), M_RATE_COUNT); + mEvent.invokeObserver(Arrays.asList(mGeckoDataModel.mCurrentURL, mGeckoDataModel.mSessionID, mGeckoDataModel.mCurrentTitle, mGeckoDataModel.mTheme), M_RATE_COUNT); } } } diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/errorHandler.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/errorHandler.java similarity index 97% rename from app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/errorHandler.java rename to app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/errorHandler.java index 04639b3e..4b272f90 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/errorHandler.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/errorHandler.java @@ -1,179 +1,179 @@ -package com.hiddenservices.onionservices.appManager.homeManager.geckoManager; - -import androidx.appcompat.app.AppCompatActivity; - -import com.hiddenservices.onionservices.constants.status; -import com.hiddenservices.onionservices.constants.strings; -import com.hiddenservices.onionservices.helperManager.helperMethod; -import com.example.myapplication.R; - -import org.mozilla.geckoview.WebRequestError; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class errorHandler { - private AppCompatActivity mContext; - private String mErrorTemplate; - - public String createErrorPage(final int category, final int error, AppCompatActivity mContext, String url, InputStream mResourceURL) { - this.mContext = mContext; - if (mErrorTemplate == null) { - StringBuilder builder = new StringBuilder(); - try { - - InputStream stream = mResourceURL; - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - String line; - while ((line = reader.readLine()) != null) { - builder.append(line); - builder.append("\n"); - } - - mErrorTemplate = builder.toString(); - } catch (Exception ex) { - return null; - } - } - String title = helperMethod.getHost(url); - - if (url == null) { - url = "Hidden Error"; - } - if (title == null) { - title = "Hidden Error"; - } - - String replaceUrl = errorToString(error).replace("$URL", url); - String errorPage = createErrorPage("CODE : " + categoryToString(category) + "
TYPE : " + replaceUrl.replace("$TITLE", title), url, mResourceURL); - errorPage = translateMessage(errorPage, "CODE : " + categoryToString(category)); - return errorPage; - } - - private String translateMessage(String message, String error) { - message = message.replace("$ERROR_M1", mContext.getString(R.string.ERROR_M1)); - message = message.replace("$ERROR_M2", mContext.getString(R.string.ERROR_M2)); - message = message.replace("$ERROR_M3", mContext.getString(R.string.ERROR_M3)); - message = message.replace("$ERROR_M4", mContext.getString(R.string.ERROR_M4)); - message = message.replace("$ERROR_M5", mContext.getString(R.string.ERROR_M5)); - message = message.replace("$ERROR_M6", mContext.getString(R.string.ERROR_M6)); - - if (status.sTorBrowsing) { - message = message.replace("$ERROR_M7", "block"); - } else { - message = message.replace("$ERROR_M7", "none"); - } - - message = message.replace("$ERROR", error); - - return message; - } - - private String errorToString(final int error) { - switch (error) { - case WebRequestError.ERROR_UNKNOWN: - return "ERROR_UNKNOWN | The network request tried to use an unknown socket type"; - case WebRequestError.ERROR_SECURITY_SSL: - return "ERROR_SECURITY_SSL | SSL negotiation problems has occured"; - case WebRequestError.ERROR_SECURITY_BAD_CERT: - return "ERROR_SECURITY_BAD_CERT | SSL certificate validation error has occured"; - case WebRequestError.ERROR_NET_RESET: - return "ERROR_NET_RESET | The connection was reset"; - case WebRequestError.ERROR_NET_INTERRUPT: - return "ERROR_NET_INTERRUPT | The network connection was interrupted"; - case WebRequestError.ERROR_NET_TIMEOUT: - return "ERROR_NET_TIMEOUT | The network request timed out"; - case WebRequestError.ERROR_CONNECTION_REFUSED: - return "ERROR_CONNECTION_REFUSED | The network request was refused by the server"; - case WebRequestError.ERROR_UNKNOWN_PROTOCOL: - return "ERROR_UNKNOWN_PROTOCOL | An unknown protocol was specified"; - case WebRequestError.ERROR_UNKNOWN_HOST: - return "ERROR_UNKNOWN_HOST | The host could not be resolved"; - case WebRequestError.ERROR_UNKNOWN_SOCKET_TYPE: - return "ERROR_UNKNOWN_SOCKET_TYPE | The network request tried to use an unknown socket type"; - case WebRequestError.ERROR_UNKNOWN_PROXY_HOST: - return "ERROR_UNKNOWN_PROXY_HOST | The host name of the proxy server could not be resolved"; - case WebRequestError.ERROR_MALFORMED_URI: - return "ERROR_MALFORMED_URI | An invalid URL was specified"; - case WebRequestError.ERROR_REDIRECT_LOOP: - return "ERROR_REDIRECT_LOOP | A redirect loop was detected"; - case WebRequestError.ERROR_SAFEBROWSING_PHISHING_URI: - return "ERROR_SAFEBROWSING_PHISHING_URI | The requested URI was present in the \"phishing\" blocklist"; - case WebRequestError.ERROR_SAFEBROWSING_MALWARE_URI: - return "ERROR_SAFEBROWSING_MALWARE_URI | The requested URI was present in the \"malware\" blocklist"; - case WebRequestError.ERROR_SAFEBROWSING_UNWANTED_URI: - return "ERROR_SAFEBROWSING_UNWANTED_URI | The requested URI was present in the \"unwanted\" blocklist"; - case WebRequestError.ERROR_SAFEBROWSING_HARMFUL_URI: - return "ERROR_SAFEBROWSING_HARMFUL_URI | The requested URI was present in the \"harmful\" blocklist"; - case WebRequestError.ERROR_CONTENT_CRASHED: - return "ERROR_CONTENT_CRASHED | The content process crashed"; - case WebRequestError.ERROR_OFFLINE: - return "ERROR_OFFLINE | This device does not have a network connection"; - case WebRequestError.ERROR_PORT_BLOCKED: - return "ERROR_PORT_BLOCKED | The request tried to use a port that is blocked by either the OS or Gecko"; - case WebRequestError.ERROR_PROXY_CONNECTION_REFUSED: - return "ERROR_PROXY_CONNECTION_REFUSED | The proxy server refused the connection"; - case WebRequestError.ERROR_FILE_NOT_FOUND: - return "ERROR_FILE_NOT_FOUND | A file was not found"; - case WebRequestError.ERROR_FILE_ACCESS_DENIED: - return "ERROR_FILE_ACCESS_DENIED | The OS blocked access to a file"; - case WebRequestError.ERROR_INVALID_CONTENT_ENCODING: - return "ERROR_INVALID_CONTENT_ENCODING | The content has an invalid encoding"; - case WebRequestError.ERROR_UNSAFE_CONTENT_TYPE: - return "ERROR_UNSAFE_CONTENT_TYPE | A content type was returned which was deemed unsafe"; - case WebRequestError.ERROR_CORRUPTED_CONTENT: - return "ERROR_CORRUPTED_CONTENT | The content returned was corrupted"; - default: - return "UNKNOWN"; - } - } - - private String categoryToString(final int category) { - switch (category) { - case WebRequestError.ERROR_CATEGORY_UNKNOWN: - return "ERROR_CATEGORY_UNKNOWN | " + "Unknown error occured from the server side"; - case WebRequestError.ERROR_CATEGORY_SECURITY: - return "ERROR_CATEGORY_SECURITY | SSL certificate validation error has occured"; - case WebRequestError.ERROR_CATEGORY_NETWORK: - return "ERROR_CATEGORY_NETWORK | A network related problem has occured"; - case WebRequestError.ERROR_CATEGORY_CONTENT: - return "ERROR_CATEGORY_CONTENT | Invalid or corrupt webpage"; - case WebRequestError.ERROR_CATEGORY_URI: - return "ERROR_CATEGORY_URI"; - case WebRequestError.ERROR_CATEGORY_PROXY: - return "ERROR_CATEGORY_PROXY"; - case WebRequestError.ERROR_CATEGORY_SAFEBROWSING: - return "ERROR_CATEGORY_SAFEBROWSING"; - default: - return "UNKNOWN"; - } - } - - private String createErrorPage(final String error, String url, InputStream mResourceURL) { - if (error == null) { - return strings.GENERIC_EMPTY_STR; - } - - if (mErrorTemplate == null) { - StringBuilder builder = new StringBuilder(); - try (InputStream stream = mResourceURL; BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) { - - String line; - while ((line = reader.readLine()) != null) { - builder.append(line); - builder.append("\n"); - } - - mErrorTemplate = builder.toString(); - } catch (IOException e) { - return null; - } - } - String replaceUrl = mErrorTemplate.replace("$URL", url); - - return replaceUrl; - } - -} +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses; + +import androidx.appcompat.app.AppCompatActivity; + +import com.hiddenservices.onionservices.constants.status; +import com.hiddenservices.onionservices.constants.strings; +import com.hiddenservices.onionservices.helperManager.helperMethod; +import com.hiddenservices.onionservices.R; + +import org.mozilla.geckoview.WebRequestError; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class errorHandler { + private AppCompatActivity mContext; + private String mErrorTemplate; + + public String createErrorPage(final int category, final int error, AppCompatActivity mContext, String url, InputStream mResourceURL) { + this.mContext = mContext; + if (mErrorTemplate == null) { + StringBuilder builder = new StringBuilder(); + try { + + InputStream stream = mResourceURL; + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + String line; + while ((line = reader.readLine()) != null) { + builder.append(line); + builder.append("\n"); + } + + mErrorTemplate = builder.toString(); + } catch (Exception ex) { + return null; + } + } + String title = helperMethod.getHost(url); + + if (url == null) { + url = "Hidden Error"; + } + if (title == null) { + title = "Hidden Error"; + } + + String replaceUrl = errorToString(error).replace("$URL", url); + String errorPage = createErrorPage("CODE : " + categoryToString(category) + "
TYPE : " + replaceUrl.replace("$TITLE", title), url, mResourceURL); + errorPage = translateMessage(errorPage, "CODE : " + categoryToString(category)); + return errorPage; + } + + private String translateMessage(String message, String error) { + message = message.replace("$ERROR_M1", mContext.getString(R.string.ERROR_M1)); + message = message.replace("$ERROR_M2", mContext.getString(R.string.ERROR_M2)); + message = message.replace("$ERROR_M3", mContext.getString(R.string.ERROR_M3)); + message = message.replace("$ERROR_M4", mContext.getString(R.string.ERROR_M4)); + message = message.replace("$ERROR_M5", mContext.getString(R.string.ERROR_M5)); + message = message.replace("$ERROR_M6", mContext.getString(R.string.ERROR_M6)); + + if (status.sTorBrowsing) { + message = message.replace("$ERROR_M7", "block"); + } else { + message = message.replace("$ERROR_M7", "none"); + } + + message = message.replace("$ERROR", error); + + return message; + } + + private String errorToString(final int error) { + switch (error) { + case WebRequestError.ERROR_UNKNOWN: + return "ERROR_UNKNOWN | The network request tried to use an unknown socket type"; + case WebRequestError.ERROR_SECURITY_SSL: + return "ERROR_SECURITY_SSL | SSL negotiation problems has occured"; + case WebRequestError.ERROR_SECURITY_BAD_CERT: + return "ERROR_SECURITY_BAD_CERT | SSL certificate validation error has occured"; + case WebRequestError.ERROR_NET_RESET: + return "ERROR_NET_RESET | The connection was reset"; + case WebRequestError.ERROR_NET_INTERRUPT: + return "ERROR_NET_INTERRUPT | The network connection was interrupted"; + case WebRequestError.ERROR_NET_TIMEOUT: + return "ERROR_NET_TIMEOUT | The network request timed out"; + case WebRequestError.ERROR_CONNECTION_REFUSED: + return "ERROR_CONNECTION_REFUSED | The network request was refused by the server"; + case WebRequestError.ERROR_UNKNOWN_PROTOCOL: + return "ERROR_UNKNOWN_PROTOCOL | An unknown protocol was specified"; + case WebRequestError.ERROR_UNKNOWN_HOST: + return "ERROR_UNKNOWN_HOST | The host could not be resolved"; + case WebRequestError.ERROR_UNKNOWN_SOCKET_TYPE: + return "ERROR_UNKNOWN_SOCKET_TYPE | The network request tried to use an unknown socket type"; + case WebRequestError.ERROR_UNKNOWN_PROXY_HOST: + return "ERROR_UNKNOWN_PROXY_HOST | The host name of the proxy server could not be resolved"; + case WebRequestError.ERROR_MALFORMED_URI: + return "ERROR_MALFORMED_URI | An invalid URL was specified"; + case WebRequestError.ERROR_REDIRECT_LOOP: + return "ERROR_REDIRECT_LOOP | A redirect loop was detected"; + case WebRequestError.ERROR_SAFEBROWSING_PHISHING_URI: + return "ERROR_SAFEBROWSING_PHISHING_URI | The requested URI was present in the \"phishing\" blocklist"; + case WebRequestError.ERROR_SAFEBROWSING_MALWARE_URI: + return "ERROR_SAFEBROWSING_MALWARE_URI | The requested URI was present in the \"malware\" blocklist"; + case WebRequestError.ERROR_SAFEBROWSING_UNWANTED_URI: + return "ERROR_SAFEBROWSING_UNWANTED_URI | The requested URI was present in the \"unwanted\" blocklist"; + case WebRequestError.ERROR_SAFEBROWSING_HARMFUL_URI: + return "ERROR_SAFEBROWSING_HARMFUL_URI | The requested URI was present in the \"harmful\" blocklist"; + case WebRequestError.ERROR_CONTENT_CRASHED: + return "ERROR_CONTENT_CRASHED | The content process crashed"; + case WebRequestError.ERROR_OFFLINE: + return "ERROR_OFFLINE | This device does not have a network connection"; + case WebRequestError.ERROR_PORT_BLOCKED: + return "ERROR_PORT_BLOCKED | The request tried to use a port that is blocked by either the OS or Gecko"; + case WebRequestError.ERROR_PROXY_CONNECTION_REFUSED: + return "ERROR_PROXY_CONNECTION_REFUSED | The proxy server refused the connection"; + case WebRequestError.ERROR_FILE_NOT_FOUND: + return "ERROR_FILE_NOT_FOUND | A file was not found"; + case WebRequestError.ERROR_FILE_ACCESS_DENIED: + return "ERROR_FILE_ACCESS_DENIED | The OS blocked access to a file"; + case WebRequestError.ERROR_INVALID_CONTENT_ENCODING: + return "ERROR_INVALID_CONTENT_ENCODING | The content has an invalid encoding"; + case WebRequestError.ERROR_UNSAFE_CONTENT_TYPE: + return "ERROR_UNSAFE_CONTENT_TYPE | A content type was returned which was deemed unsafe"; + case WebRequestError.ERROR_CORRUPTED_CONTENT: + return "ERROR_CORRUPTED_CONTENT | The content returned was corrupted"; + default: + return "UNKNOWN"; + } + } + + private String categoryToString(final int category) { + switch (category) { + case WebRequestError.ERROR_CATEGORY_UNKNOWN: + return "ERROR_CATEGORY_UNKNOWN | " + "Unknown error occured from the server side"; + case WebRequestError.ERROR_CATEGORY_SECURITY: + return "ERROR_CATEGORY_SECURITY | SSL certificate validation error has occured"; + case WebRequestError.ERROR_CATEGORY_NETWORK: + return "ERROR_CATEGORY_NETWORK | A network related problem has occured"; + case WebRequestError.ERROR_CATEGORY_CONTENT: + return "ERROR_CATEGORY_CONTENT | Invalid or corrupt webpage"; + case WebRequestError.ERROR_CATEGORY_URI: + return "ERROR_CATEGORY_URI"; + case WebRequestError.ERROR_CATEGORY_PROXY: + return "ERROR_CATEGORY_PROXY"; + case WebRequestError.ERROR_CATEGORY_SAFEBROWSING: + return "ERROR_CATEGORY_SAFEBROWSING"; + default: + return "UNKNOWN"; + } + } + + private String createErrorPage(final String error, String url, InputStream mResourceURL) { + if (error == null) { + return strings.GENERIC_EMPTY_STR; + } + + if (mErrorTemplate == null) { + StringBuilder builder = new StringBuilder(); + try (InputStream stream = mResourceURL; BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) { + + String line; + while ((line = reader.readLine()) != null) { + builder.append(line); + builder.append("\n"); + } + + mErrorTemplate = builder.toString(); + } catch (IOException e) { + return null; + } + } + String replaceUrl = mErrorTemplate.replace("$URL", url); + + return replaceUrl; + } + +} diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/intentHandler.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/intentHandler.java new file mode 100644 index 00000000..9cbb56c6 --- /dev/null +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/intentHandler.java @@ -0,0 +1,14 @@ +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses; + +import android.content.Intent; +import android.net.Uri; +import androidx.appcompat.app.AppCompatActivity; +import java.lang.ref.WeakReference; + +public class intentHandler { + + public static void actionDial(String pIntentHander, WeakReference mContext) { + Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(pIntentHander)); + mContext.get().startActivity(intent); + } +} diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/preferences.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/preferences.java new file mode 100644 index 00000000..8b759807 --- /dev/null +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/preferences.java @@ -0,0 +1,37 @@ +package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses; + +import androidx.annotation.NonNull; +import org.mozilla.gecko.EventDispatcher; +import org.mozilla.gecko.util.GeckoBundle; + +public class preferences { + public final String name; + public final T defaultValue; + private T mValue; + + public preferences(@NonNull final String name, final T defaultValue) { + this.name = name; + this.defaultValue = defaultValue; + mValue = defaultValue; + + } + public void add() { + final GeckoBundle prefs = new GeckoBundle(1); + prefs.putInt(this.name, (Integer)this.defaultValue); + EventDispatcher.getInstance().dispatch("GeckoView:SetDefaultPrefs", prefs); + addToBundle(prefs); + } + + private void addToBundle(final GeckoBundle bundle) { + final T value = mValue; + if (value instanceof String) { + bundle.putString(name, (String) value); + } else if (value instanceof Integer) { + bundle.putInt(name, (Integer) value); + } else if (value instanceof Boolean) { + bundle.putBoolean(name, (Boolean) value); + } else { + throw new UnsupportedOperationException("Unhandled pref type for " + name); + } + } +} diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/hintManager/hintAdapter.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/hintManager/hintAdapter.java index fd6efda5..465b5338 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/hintManager/hintAdapter.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/hintManager/hintAdapter.java @@ -29,7 +29,7 @@ import com.hiddenservices.onionservices.constants.enums; import com.hiddenservices.onionservices.constants.strings; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.helperManager.helperMethod; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.io.IOException; import java.util.ArrayList; @@ -210,7 +210,7 @@ public class hintAdapter extends RecyclerView.Adapter + { + if(status.sSettingIsAppStarted) { + pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_SHOW_BANNER); + } + }, 3000); } } @@ -783,7 +791,7 @@ public class homeController extends AppCompatActivity implements ComponentCallba public void onLoadTab(geckoSession mTempSession, boolean isSessionClosed, boolean pExpandAppBar, boolean pForced, boolean pGeneratePixel) { - mGeckoClient.getSession().onKillMedia(); + mGeckoClient.getSession().getMediaSessionDelegate().onTrigger(enums.MediaController.DESTROY); if (!isSessionClosed) { dataController.getInstance().invokeTab(dataEnums.eTabCommands.MOVE_TAB_TO_TOP, Collections.singletonList(mTempSession)); } @@ -1103,7 +1111,7 @@ public class homeController extends AppCompatActivity implements ComponentCallba } NotificationManagerCompat.from(this).cancel(1025); if(mGeckoClient.getSession() !=null){ - mGeckoClient.getSession().onDestroyMedia(); + mGeckoClient.getSession().getMediaSessionDelegate().onTrigger(enums.MediaController.DESTROY); onHideDefaultNotification(); } if (!status.sSettingIsAppStarted) { @@ -1563,7 +1571,7 @@ public class homeController extends AppCompatActivity implements ComponentCallba geckoSession mNewSession = mGeckoClient.initializeBackground(mGeckoView, new geckoViewCallback(), this, true); onSaveCurrentTab(mNewSession, false); - mNewSession.setURL(url); + mNewSession.getHistoryDelegate().setURL(url); mHomeViewController.progressBarReset(); initTabCountForced(); mNewSession.loadUri(url); @@ -1574,7 +1582,7 @@ public class homeController extends AppCompatActivity implements ComponentCallba } public void onNewTab(boolean isKeyboardOpenedTemp, boolean isKeyboardOpened) { - mGeckoClient.getSession().onKillMedia(); + mGeckoClient.getSession().getMediaSessionDelegate().onTrigger(enums.MediaController.DESTROY); try { if(status.sLowMemory != enums.MemoryStatus.STABLE){ mRenderedBitmap = mGeckoView.capturePixels(); @@ -1735,7 +1743,9 @@ public class homeController extends AppCompatActivity implements ComponentCallba ((hintAdapter) Objects.requireNonNull(mHintListView.getAdapter())).onClearAdapter(); } else if (!mGeckoClient.getFullScreenStatus()) { mGeckoClient.onExitFullScreen(); - pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_SHOW_BANNER); + if(status.sSettingIsAppStarted){ + pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_SHOW_BANNER); + } mHomeViewController.onUpdateStatusBarTheme(mGeckoClient.getTheme(), false); mHomeViewController.updateBannerAdvertStatus(false, (boolean) pluginController.getInstance().onAdsInvoke(null, pluginEnums.eAdManager.M_IS_ADVERT_LOADED)); } else if (mSearchbar.isFocused() || isKeyboardOpened) { @@ -1789,7 +1799,9 @@ public class homeController extends AppCompatActivity implements ComponentCallba mHomeViewController.removeBanner(); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { if(mGeckoClient.getFullScreenStatus()){ - pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_SHOW_BANNER); + if(status.sSettingIsAppStarted){ + pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_SHOW_BANNER); + } }else { pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_HIDE_BANNER); } @@ -1837,7 +1849,9 @@ public class homeController extends AppCompatActivity implements ComponentCallba if(!mGeckoClient.getFullScreenStatus()){ mGeckoClient.onExitFullScreen(); } - pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_SHOW_BANNER); + if(status.sSettingIsAppStarted){ + pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_SHOW_BANNER); + } mHomeViewController.onUpdateStatusBarTheme(mGeckoClient.getTheme(), false); pluginController.getInstance().onMessageManagerInvoke(null, M_RESET); pluginController.getInstance().onNotificationInvoke(Collections.singletonList(172800000), pluginEnums.eNotificationManager.M_CREATE_NOTIFICATION); @@ -1852,7 +1866,7 @@ public class homeController extends AppCompatActivity implements ComponentCallba mHomeViewController.onUpdateSearchBar(mGeckoClient.getSession().getCurrentURL(), false, false, true); if (mGeckoClient.getSession() != null && mGeckoClient != null) { - mGeckoClient.onStopMedia(); + mGeckoClient.onPauseMedia(); } } @@ -2710,7 +2724,9 @@ public class homeController extends AppCompatActivity implements ComponentCallba if((boolean)data.get(0)){ pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_HIDE_BANNER); }else { - pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_SHOW_BANNER); + if(status.sSettingIsAppStarted){ + pluginController.getInstance().onAdsInvoke(Collections.singletonList(this), pluginEnums.eAdManager.M_SHOW_BANNER); + } } } else if (e_type.equals(enums.etype.M_ON_BANNER_UPDATE)) { Object mStatus = pluginController.getInstance().onAdsInvoke(null, pluginEnums.eAdManager.M_IS_ADVERT_LOADED); @@ -2986,7 +3002,7 @@ public class homeController extends AppCompatActivity implements ComponentCallba mHomeViewController.onUpdateStatusBarTheme(mGeckoClient.getTheme(), false); } else if (e_type.equals(enums.etype.start_proxy)) { pluginController.getInstance().onOrbotInvoke(data, pluginEnums.eOrbotManager.M_SET_PROXY); - } else if (e_type.equals(enums.etype.on_update_history)) { + } else if (e_type.equals(enums.etype.ON_UPDATE_HISTORY)) { return dataController.getInstance().invokeHistory(dataEnums.eHistoryCommands.M_ADD_HISTORY, data); } else if (e_type.equals(enums.etype.on_page_loaded)) { onInvokePixelGenerator(); @@ -3014,10 +3030,10 @@ public class homeController extends AppCompatActivity implements ComponentCallba mData.addAll(data); mData.add(homeController.this); pluginController.getInstance().onMessageManagerInvoke(mData, M_DOWNLOAD_SINGLE); - } else if (e_type.equals(enums.etype.on_full_screen)) { + } else if (e_type.equals(enums.etype.ON_FULL_SCREEN)) { boolean status = (Boolean) data.get(0); if(!status){ - mGeckoClient.onStopMedia(); + mGeckoClient.onPauseMedia(); } mHomeViewController.onFullScreenUpdate(status); mHomeViewController.onUpdateSearchEngineBar(false, 0); diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/homeController/homeViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/homeController/homeViewController.java index e5a82b50..d83b108a 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/homeController/homeViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/homeController/homeViewController.java @@ -51,7 +51,7 @@ import com.hiddenservices.onionservices.dataManager.dataEnums; import com.hiddenservices.onionservices.libs.views.ColorAnimator; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.helperManager.helperMethod; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.appbar.AppBarLayout; import org.mozilla.geckoview.GeckoView; @@ -115,6 +115,7 @@ class homeViewController { private CoordinatorLayout mCoordinatorLayout; private ImageView mImageDivider; private ImageButton mPanicButton; + private ImageButton mSupportButton; private ImageButton mPanicButtonLandscape; private ImageView mGenesisLogo; private ImageView mTorDisabled; @@ -127,7 +128,7 @@ class homeViewController { private boolean mIsTopBarExpanded = true; private NestedScrollView.MarginLayoutParams mDefaultMargin = null; - void initialization(eventObserver.eventListener event, AppCompatActivity context, Button mNewTab, ConstraintLayout webviewContainer, TextView loadingText, ProgressBar progressBar, editTextManager searchbar, ConstraintLayout splashScreen, ImageView loading, View banner_ads, ImageButton gateway_splash, LinearLayout top_bar, GeckoView gecko_view, ImageView backsplash, Button connect_button, Button connect_no_tor_button, View pFindBar, EditText pFindText, TextView pFindCount, androidx.constraintlayout.widget.ConstraintLayout pTopLayout, ImageButton pVoiceInput, ImageButton pMenu, androidx.core.widget.NestedScrollView pNestedScroll, ImageView pBlocker, ImageView pBlockerFullSceen, View mSearchEngineBar, TextView pCopyright, RecyclerView pHistListView, com.google.android.material.appbar.AppBarLayout pAppBar, ImageButton pOrbotLogManager, ConstraintLayout pInfoLandscape, ConstraintLayout pInfoPortrait, ProgressBar pProgressBarIndeterminate, FragmentContainerView pTabFragment, LinearLayout pTopBarContainer, ImageView pSearchLock, ImageView pTopBarHider, ImageView pNewTabBlocker, CoordinatorLayout mCoordinatorLayout, ImageView pImageDivider, ImageButton pPanicButton, ImageView pGenesisLogo, ImageButton pPanicButtonLandscape, ImageView pTorDisabled) { + void initialization(eventObserver.eventListener event, AppCompatActivity context, Button mNewTab, ConstraintLayout webviewContainer, TextView loadingText, ProgressBar progressBar, editTextManager searchbar, ConstraintLayout splashScreen, ImageView loading, View banner_ads, ImageButton gateway_splash, LinearLayout top_bar, GeckoView gecko_view, ImageView backsplash, Button connect_button, Button connect_no_tor_button, View pFindBar, EditText pFindText, TextView pFindCount, androidx.constraintlayout.widget.ConstraintLayout pTopLayout, ImageButton pVoiceInput, ImageButton pMenu, androidx.core.widget.NestedScrollView pNestedScroll, ImageView pBlocker, ImageView pBlockerFullSceen, View mSearchEngineBar, TextView pCopyright, RecyclerView pHistListView, com.google.android.material.appbar.AppBarLayout pAppBar, ImageButton pOrbotLogManager, ConstraintLayout pInfoLandscape, ConstraintLayout pInfoPortrait, ProgressBar pProgressBarIndeterminate, FragmentContainerView pTabFragment, LinearLayout pTopBarContainer, ImageView pSearchLock, ImageView pTopBarHider, ImageView pNewTabBlocker, CoordinatorLayout mCoordinatorLayout, ImageView pImageDivider, ImageButton pPanicButton, ImageView pGenesisLogo, ImageButton pPanicButtonLandscape, ImageView pTorDisabled, ImageButton pSupportButton) { this.mContext = context; this.mProgressBar = progressBar; this.mSearchbar = searchbar; @@ -171,6 +172,7 @@ class homeViewController { this.mPanicButtonLandscape = pPanicButtonLandscape; this.mLogHandler = new LogHandler(); this.mTorDisabled = pTorDisabled; + this.mSupportButton = pSupportButton; initSplashScreen(); createUpdateUiHandler(); @@ -530,7 +532,7 @@ class homeViewController { public void initStatusBarColor(boolean mInstant) { int mDelay = 1500; - if (!status.sTorBrowsing || status.mThemeApplying || mInstant || status.sSettingIsAppStarted) { + if (status.mThemeApplying || mInstant || status.sSettingIsAppStarted) { mDelay = 0; } @@ -566,7 +568,7 @@ class homeViewController { }); animator.start(); } else { - mSplashScreen.animate().alpha(0).setDuration(200).setStartDelay(mDelay).withEndAction(() -> onPostScreenDisable()); + mSplashScreen.animate().alpha(0).setDuration(200).setStartDelay(2000).withEndAction(() -> onPostScreenDisable()); } } @@ -582,6 +584,7 @@ class homeViewController { mConnectButton.setVisibility(View.GONE); mConnectNoTorButton.setVisibility(View.GONE); mPanicButton.setVisibility(View.GONE); + mSupportButton.setVisibility(View.GONE); mPanicButtonLandscape.setVisibility(View.GONE); mEvent.invokeObserver(null, enums.etype.M_CACHE_UPDATE_TAB); @@ -1386,24 +1389,12 @@ class homeViewController { mProgressBar.setAlpha(1); mProgressBar.animate().cancel(); mProgressBar.animate().alpha(0); - value = 100; mProgressBar.animate().alpha(0).withEndAction(() -> mProgressBar.setProgress(0)); return; } if (value == 100) { changeRefreshMenu(); - new Handler().postDelayed(() -> - { - if(mProgressBar.getProgress()==100){ - progressAnimator.cancel(); - mProgressBar.setAlpha(1); - mProgressBar.animate().cancel(); - mProgressBar.animate().alpha(0).withEndAction(() -> mProgressBar.setProgress(0)); - } - onResetTabAnimation(); - }, 2000); - } mProgressBar = activityContextManager.getInstance().getHomeController().mProgressBar; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageAdapter.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageAdapter.java index 664a9720..9250a702 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageAdapter.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageAdapter.java @@ -17,7 +17,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.ArrayList; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageController.java index 07c43496..245651a5 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageController.java @@ -29,7 +29,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.ArrayList; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageViewController.java index a1bccf39..aae11a2b 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/languageManager/languageViewController.java @@ -11,7 +11,7 @@ import androidx.appcompat.app.AppCompatDelegate; import androidx.core.content.ContextCompat; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.List; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotLogManager/orbotLogAdapter.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotLogManager/orbotLogAdapter.java index 89876664..9ee1ba98 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotLogManager/orbotLogAdapter.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotLogManager/orbotLogAdapter.java @@ -15,7 +15,7 @@ import com.hiddenservices.onionservices.appManager.activityContextManager; import com.hiddenservices.onionservices.appManager.tabManager.tabEnums; import com.hiddenservices.onionservices.constants.constants; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import org.torproject.android.service.wrapper.logRowModel; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotLogManager/orbotLogController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotLogManager/orbotLogController.java index a8830e46..c1eed92f 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotLogManager/orbotLogController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotLogManager/orbotLogController.java @@ -27,7 +27,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.floatingactionbutton.FloatingActionButton; import org.torproject.android.service.wrapper.logRowModel; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotManager/orbotController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotManager/orbotController.java index 1c096f4d..ddc0a975 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotManager/orbotController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/orbotManager/orbotController.java @@ -18,7 +18,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/accessibilityManager/settingAccessibilityController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/accessibilityManager/settingAccessibilityController.java index 1037556a..7b82e181 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/accessibilityManager/settingAccessibilityController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/accessibilityManager/settingAccessibilityController.java @@ -22,7 +22,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/accessibilityManager/settingAccessibilityViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/accessibilityManager/settingAccessibilityViewController.java index d0ed520a..ac0f0846 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/accessibilityManager/settingAccessibilityViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/accessibilityManager/settingAccessibilityViewController.java @@ -14,7 +14,7 @@ import androidx.core.content.ContextCompat; import com.hiddenservices.onionservices.constants.constants; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.List; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceController.java index 77c8ac00..e2afb008 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceController.java @@ -22,7 +22,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.ArrayList; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceModel.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceModel.java index 0bcc1bf2..6c1d7abe 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceModel.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceModel.java @@ -4,7 +4,7 @@ import android.view.View; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.List; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceViewController.java index 0fea8c63..bcce7151 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advanceManager/settingAdvanceViewController.java @@ -13,7 +13,7 @@ import androidx.core.content.ContextCompat; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.ArrayList; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advertSetttings/advertSettingController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advertSetttings/advertSettingController.java index 018d18b6..a304040a 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advertSetttings/advertSettingController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/advertSetttings/advertSettingController.java @@ -16,7 +16,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.ArrayList; import java.util.Collections; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/clearManager/settingClearController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/clearManager/settingClearController.java index f60ee3a3..d47c8feb 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/clearManager/settingClearController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/clearManager/settingClearController.java @@ -25,7 +25,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import org.mozilla.geckoview.ContentBlocking; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/clearManager/settingClearViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/clearManager/settingClearViewController.java index 51f97dba..bb6f5ca1 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/clearManager/settingClearViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/clearManager/settingClearViewController.java @@ -12,7 +12,7 @@ import androidx.appcompat.app.AppCompatDelegate; import androidx.core.content.ContextCompat; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/generalManager/settingGeneralController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/generalManager/settingGeneralController.java index 0a03263d..32d9a5d1 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/generalManager/settingGeneralController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/generalManager/settingGeneralController.java @@ -29,7 +29,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/generalManager/settingGeneralViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/generalManager/settingGeneralViewController.java index e01c91c6..4563382d 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/generalManager/settingGeneralViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/generalManager/settingGeneralViewController.java @@ -16,7 +16,7 @@ import com.hiddenservices.onionservices.constants.enums; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.helperManager.helperMethod; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.Collections; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/logManager/settingLogController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/logManager/settingLogController.java index 7c537c6a..d5892d80 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/logManager/settingLogController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/logManager/settingLogController.java @@ -19,7 +19,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/notificationManager/settingNotificationController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/notificationManager/settingNotificationController.java index fa9bb468..7d0832de 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/notificationManager/settingNotificationController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/notificationManager/settingNotificationController.java @@ -19,7 +19,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/notificationManager/settingNotificationViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/notificationManager/settingNotificationViewController.java index 9ff281f9..4ae90406 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/notificationManager/settingNotificationViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/notificationManager/settingNotificationViewController.java @@ -11,7 +11,7 @@ import androidx.core.content.ContextCompat; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; class settingNotificationViewController { diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyController.java index b3e171f5..484c27f9 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyController.java @@ -21,7 +21,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.ArrayList; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyModel.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyModel.java index a426de0a..44dbc238 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyModel.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyModel.java @@ -4,7 +4,7 @@ import android.view.View; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.List; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyViewController.java index b9a9b690..66d2f03d 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/privacyManager/settingPrivacyViewController.java @@ -13,7 +13,7 @@ import androidx.core.content.ContextCompat; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.ArrayList; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/proxyStatusManager/proxyStatusController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/proxyStatusManager/proxyStatusController.java index 07c250b4..1e2f8f80 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/proxyStatusManager/proxyStatusController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/proxyStatusManager/proxyStatusController.java @@ -17,7 +17,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/proxyStatusManager/proxyStatusViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/proxyStatusManager/proxyStatusViewController.java index 4c0aaa63..5e24d2b5 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/proxyStatusManager/proxyStatusViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/proxyStatusManager/proxyStatusViewController.java @@ -11,7 +11,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; import androidx.core.content.ContextCompat; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import com.hiddenservices.onionservices.constants.status; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/searchEngineManager/settingSearchController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/searchEngineManager/settingSearchController.java index 72080585..b93b9252 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/searchEngineManager/settingSearchController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/searchEngineManager/settingSearchController.java @@ -23,7 +23,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.ArrayList; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/searchEngineManager/settingSearchViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/searchEngineManager/settingSearchViewController.java index a044604d..65f0ce03 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/searchEngineManager/settingSearchViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/searchEngineManager/settingSearchViewController.java @@ -18,7 +18,7 @@ import androidx.core.content.ContextCompat; import com.hiddenservices.onionservices.constants.constants; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import com.hiddenservices.onionservices.pluginManager.pluginController; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/settingHomeManager/settingHomeController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/settingHomeManager/settingHomeController.java index 55531bf0..eb4824d9 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/settingHomeManager/settingHomeController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/settingHomeManager/settingHomeController.java @@ -33,7 +33,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/settingHomeManager/settingHomeViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/settingHomeManager/settingHomeViewController.java index 93ceb1f1..b207d69f 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/settingHomeManager/settingHomeViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/settingHomeManager/settingHomeViewController.java @@ -14,7 +14,7 @@ import com.hiddenservices.onionservices.appManager.activityContextManager; import com.hiddenservices.onionservices.constants.constants; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.hiddenservices.onionservices.helperManager.helperMethod; import java.util.List; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingController.java index 75bb1ffb..43826ddc 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingController.java @@ -20,7 +20,7 @@ import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.ArrayList; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingModel.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingModel.java index b04022e5..a6fc2e4c 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingModel.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingModel.java @@ -4,7 +4,7 @@ import android.view.View; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import org.mozilla.geckoview.ContentBlocking; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingViewController.java index 0d793f13..7acd2d10 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/settingManager/trackingManager/settingTrackingViewController.java @@ -13,7 +13,7 @@ import androidx.core.content.ContextCompat; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import org.mozilla.geckoview.ContentBlocking; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabAdapter.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabAdapter.java index 6719a977..3c729122 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabAdapter.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabAdapter.java @@ -29,7 +29,7 @@ import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.dataManager.models.tabRowModel; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.helperManager.helperMethod; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.ArrayList; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabController.java index 67130a66..c2094656 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabController.java @@ -39,7 +39,7 @@ import com.hiddenservices.onionservices.dataManager.models.tabRowModel; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.pluginManager.pluginController; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.ArrayList; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabViewController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabViewController.java index 4fbd305c..e0c91ee1 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabViewController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/tabManager/tabViewController.java @@ -27,7 +27,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.hiddenservices.onionservices.constants.enums; import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.helperManager.helperMethod; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.List; diff --git a/app/src/main/java/com/hiddenservices/onionservices/constants/enums.java b/app/src/main/java/com/hiddenservices/onionservices/constants/enums.java index e2045d49..877283a3 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/constants/enums.java +++ b/app/src/main/java/com/hiddenservices/onionservices/constants/enums.java @@ -3,11 +3,11 @@ package com.hiddenservices.onionservices.constants; public class enums { /*Settings Manager*/ public enum etype { - M_CHANGE_HOME_THEME, M_IS_ERROR_PAGE, on_update_favicon, M_RELOAD, ON_UPDATE_TAB_TITLE, ON_OPEN_TAB_VIEW, ON_NEW_TAB_ANIMATION, M_UPDATE_SESSION_STATE, ON_LOAD_REQUEST, GECKO_SCROLL_UP, GECKO_SCROLL_UP_ALWAYS, GECKO_SCROLL_DOWN, WAS_SCROLL_CHANGED, GECKO_SCROLL_DOWN_MOVE, GECKO_SCROLL_UP_MOVE, GECKO_SCROLL_DOWN_CALLER, ON_UPDATE_SEARCH_BAR, M_ON_MAIL, SESSION_ID, M_UPDATE_PIXEL_BACKGROUND, M_ON_SCROLL_BOUNDARIES, M_ON_SCROLL_TOP_BOUNDARIES, M_ON_SCROLL_NO_BOUNDARIES, M_ON_STOP_SCROLL, M_INIT_PADDING, M_RATE_COUNT, M_CACHE_UPDATE_TAB, M_DEFAULT_BROWSER, + M_CHANGE_HOME_THEME, M_IS_ERROR_PAGE, on_update_favicon, M_RELOAD, ON_UPDATE_TAB_TITLE, ON_OPEN_TAB_VIEW, ON_NEW_TAB_ANIMATION, M_UPDATE_SESSION_STATE, ON_LOAD_REQUEST, GECKO_SCROLL_UP, GECKO_SCROLL_UP_ALWAYS, GECKO_SCROLL_DOWN, WAS_SCROLL_CHANGED, GECKO_SCROLL_DOWN_MOVE, GECKO_SCROLL_UP_MOVE, GECKO_SCROLL_DOWN_CALLER, ON_UPDATE_SEARCH_BAR, ON_DESTROY_MEDIA, M_ON_MAIL, SESSION_ID, M_UPDATE_PIXEL_BACKGROUND, M_ON_SCROLL_BOUNDARIES, M_ON_SCROLL_TOP_BOUNDARIES, M_ON_SCROLL_NO_BOUNDARIES, M_ON_STOP_SCROLL, M_INIT_PADDING, M_RATE_COUNT, M_CACHE_UPDATE_TAB, M_DEFAULT_BROWSER, on_verify_selected_url_menu, FINDER_RESULT_CALLBACK, M_ADMOB_BANNER_RECHECK, M_OPEN_SESSION, M_DOWNLOAD_FAILURE, M_ADVERT_LOADED, welcome, reload, download_folder, M_UPDATE_THEME, M_ON_BANNER_UPDATE, M_LOAD_HOMEPAGE_GENESIS, M_INIT_TAB_COUNT_FORCED, M_GET_SSL_STATUS, M_SPLASH_DISABLE, M_NEW_LINK_IN_NEW_TAB, M_NEW_LINK_IN_NEW_TAB_LOAD, M_RESET_SUGGESTION, url_triggered, url_triggered_new_tab, url_clear, fetch_favicon, M_OPEN_BOOKMARK_SETTING, M_COPY_URL, url_clear_at, remove_from_database, is_empty, M_HOME_PAGE, M_PRELOAD_URL, ON_KEYBOARD_CLOSE, M_CLOSE_TAB, M_CLOSE_TAB_BACK, - on_close_sesson, on_long_press, on_full_screen, on_handle_external_intent, on_update_suggestion_url, progress_update, progress_update_forced, ON_EXPAND_TOP_BAR, recheck_orbot, on_url_load, on_playstore_load, back_list_empty, start_proxy, ON_UPDATE_THEME, M_NEW_IDENTITY, M_INDEX_WEBSITE, M_INIT_RUNTIME_SETTINGS, M_INIT_TOR, M_NEW_IDENTITY_MESSAGED, M_INITIALIZE_TAB_SINGLE, M_HOME_BUTTON_PRESSED, M_INITIALIZE_TAB_LINK, on_request_completed, on_update_history, on_update_suggestion, M_WELCOME_MESSAGE, ON_FIRST_PAINT, ON_INVOKE_PARSER, ON_LOAD_TAB_ON_RESUME, ON_LOAD_ADVERT, ON_SESSION_REINIT, on_page_loaded, on_load_error, M_ORBOT_LOADING, download_file_popup, on_init_ads, on_full_screen_ads, M_GET_CURRENT_URL, search_update, open_new_tab, open_new_tab_instant + on_close_sesson, on_long_press, ON_FULL_SCREEN, on_handle_external_intent, on_update_suggestion_url, progress_update, progress_update_forced, ON_EXPAND_TOP_BAR, recheck_orbot, on_url_load, on_playstore_load, back_list_empty, start_proxy, ON_UPDATE_THEME, M_NEW_IDENTITY, M_INDEX_WEBSITE, M_INIT_RUNTIME_SETTINGS, M_INIT_TOR, M_NEW_IDENTITY_MESSAGED, M_INITIALIZE_TAB_SINGLE, M_HOME_BUTTON_PRESSED, M_INITIALIZE_TAB_LINK, on_request_completed, ON_UPDATE_HISTORY, on_update_suggestion, M_WELCOME_MESSAGE, ON_FIRST_PAINT, ON_INVOKE_PARSER, ON_LOAD_TAB_ON_RESUME, ON_LOAD_ADVERT, ON_SESSION_REINIT, on_page_loaded, on_load_error, M_ORBOT_LOADING, download_file_popup, on_init_ads, on_full_screen_ads, M_GET_CURRENT_URL, search_update, open_new_tab, open_new_tab_instant } /*General Enums*/ @@ -25,6 +25,10 @@ public class enums { public static final int CRITICAL_MEMORY = 3; } + public enum MediaController { + DESTROY, PLAY, PAUSE, SKIP_FORWARD, SKIP_BACKWARD, STOP; + } + public static class AddTabCallback { public static final int TAB_ADDED = 0; public static final int TAB_FULL = 1; @@ -42,12 +46,6 @@ public class enums { public static final int SEARCHBAR = 2; } - public static class ImageQueueStatus { - public static final int M_IMAGE_LOADING = 0; - public static final int M_IMAGE_LOADED_SUCCESSFULLY = 1; - public static final int M_IMAGE_LOADING_FAILED = 2; - } - public static class ScrollDirection { public static final int HORIZONTAL = 0; public static final int VERTICAL = 1; @@ -58,11 +56,5 @@ public class enums { public static final String OPEN_VOICE = "mOpenVoice"; } - public static class LandingPageTypes { - public static final int M_LANDING_WELCOME = 0; - public static final int M_LANDING_INTRO = 1; - public static final int M_LANDING_START = 2; - } - } \ No newline at end of file diff --git a/app/src/main/java/com/hiddenservices/onionservices/dataManager/bookmarkDataModel.java b/app/src/main/java/com/hiddenservices/onionservices/dataManager/bookmarkDataModel.java index 992d8f80..4ad14ae0 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/dataManager/bookmarkDataModel.java +++ b/app/src/main/java/com/hiddenservices/onionservices/dataManager/bookmarkDataModel.java @@ -31,9 +31,10 @@ public class bookmarkDataModel { void initializebookmark(ArrayList pBookmark) { mBookmarks = pBookmark; - for (int mCounter = 0; mCounter < pBookmark.size(); mCounter++) { + for (int mCounter = pBookmark.size()-1; mCounter >= 0; mCounter--) { if (mAvailableBookmark.containsKey(pBookmark.get(mCounter).getDescription())) { deleteBookmark(pBookmark.get(mCounter).getID()); + mCounter++; } else { mAvailableBookmark.put(pBookmark.get(mCounter).getDescription(), pBookmark.get(mCounter).getID()); } diff --git a/app/src/main/java/com/hiddenservices/onionservices/dataManager/models/tabRowModel.java b/app/src/main/java/com/hiddenservices/onionservices/dataManager/models/tabRowModel.java index 4a500e9e..5acd5f5b 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/dataManager/models/tabRowModel.java +++ b/app/src/main/java/com/hiddenservices/onionservices/dataManager/models/tabRowModel.java @@ -52,7 +52,7 @@ public class tabRowModel { public void setSession(geckoSession pSession, String pURL, String pTitle, String pTheme, GeckoSession.SessionState pSessionState) { mSession = pSession; mSession.setTitle(pTitle); - mSession.setURL(pURL); + mSession.getHistoryDelegate().setURL(pURL); mSession.setTheme(pTheme); if (pSessionState != null) { @@ -63,7 +63,7 @@ public class tabRowModel { if (!status.sSettingIsAppStarted) { if (pTitle.equals("$TITLE") || pTitle.startsWith("http://loading") || pTitle.startsWith("loading") || pURL.equals("$TITLE") || pURL.startsWith("http://loading") || pURL.startsWith("loading")) { mSession.setTitle("about:blank"); - mSession.setURL("about:blank"); + mSession.getHistoryDelegate().setURL("about:blank"); } } } diff --git a/app/src/main/java/com/hiddenservices/onionservices/helperManager/helperMethod.java b/app/src/main/java/com/hiddenservices/onionservices/helperManager/helperMethod.java index d28a733a..c0eee041 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/helperManager/helperMethod.java +++ b/app/src/main/java/com/hiddenservices/onionservices/helperManager/helperMethod.java @@ -56,7 +56,7 @@ import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import androidx.core.graphics.ColorUtils; -import com.example.myapplication.BuildConfig; +import com.hiddenservices.onionservices.BuildConfig; import com.hiddenservices.onionservices.appManager.activityContextManager; import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.geckoSession; import com.hiddenservices.onionservices.appManager.kotlinHelperLibraries.defaultBrowser; @@ -66,7 +66,7 @@ import com.hiddenservices.onionservices.constants.keys; import com.hiddenservices.onionservices.constants.strings; import com.hiddenservices.onionservices.libs.trueTime.trueTimeEncryption; import com.hiddenservices.onionservices.pluginManager.pluginController; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -387,9 +387,9 @@ public class helperMethod { ss.setSpan(new ForegroundColorSpan(Color.GRAY), 5, 8, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if(pTheme != enums.Theme.THEME_DARK){ - ss.setSpan(new ForegroundColorSpan(Color.BLACK), getHost(url).length()+7, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + ss.setSpan(new ForegroundColorSpan(Color.BLACK), getHost(url).length()+8, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }else { - ss.setSpan(new ForegroundColorSpan(Color.WHITE), getHost(url).length()+7, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + ss.setSpan(new ForegroundColorSpan(Color.WHITE), getHost(url).length()+8, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return ss; }else { diff --git a/app/src/main/java/com/hiddenservices/onionservices/helperManager/sharedUIMethod.java b/app/src/main/java/com/hiddenservices/onionservices/helperManager/sharedUIMethod.java index 472f5fa8..be67ac60 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/helperManager/sharedUIMethod.java +++ b/app/src/main/java/com/hiddenservices/onionservices/helperManager/sharedUIMethod.java @@ -15,7 +15,7 @@ import com.hiddenservices.onionservices.appManager.activityContextManager; import com.hiddenservices.onionservices.appManager.activityThemeManager; import com.hiddenservices.onionservices.pluginManager.pluginController; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.Collections; diff --git a/app/src/main/java/com/hiddenservices/onionservices/libs/netcipher/client/StrongHttpsClient.java b/app/src/main/java/com/hiddenservices/onionservices/libs/netcipher/client/StrongHttpsClient.java index 211d423e..65062e46 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/libs/netcipher/client/StrongHttpsClient.java +++ b/app/src/main/java/com/hiddenservices/onionservices/libs/netcipher/client/StrongHttpsClient.java @@ -19,7 +19,7 @@ package com.hiddenservices.onionservices.libs.netcipher.client; import android.content.Context; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.io.IOException; import java.io.InputStream; diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/adPluginManager/appLovinManager.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/adPluginManager/appLovinManager.java index 5bead076..ae44276f 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/adPluginManager/appLovinManager.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/adPluginManager/appLovinManager.java @@ -22,32 +22,32 @@ public class appLovinManager { public appLovinManager(eventObserver.eventListener pEvent, View pBannerAds, AppCompatActivity pContext) { this.mEvent = pEvent; this.mContext = pContext; - - onInitializeAdvertisement(pContext); } - private void onInitializeAdvertisement(AppCompatActivity pContext) { - AppLovinSdk.getInstance(pContext).getSettings().setVerboseLogging(true); - AppLovinSdk.getInstance(pContext).setMediationProvider("max"); - AppLovinSdk.initializeSdk(pContext, configuration -> { - if(!mLowMemoryReached){ - this.mSupportManager = new applovinSupportManager(pContext); - this.mBannerManager = new applovinBannerManager(pContext, mEvent); - } - }); + private void onInitializeAdvertisement() { + if(!mLowMemoryReached){ + AppLovinSdk.getInstance(mContext).getSettings().setVerboseLogging(true); + AppLovinSdk.getInstance(mContext).setMediationProvider("max"); + AppLovinSdk.initializeSdk(mContext, configuration -> { + if(!mLowMemoryReached){ + this.mSupportManager = new applovinSupportManager(mContext); + this.mBannerManager = new applovinBannerManager(mContext, mEvent); + } + }); + } } /*Local Helper Methods*/ private void onShowInterstitial() { - if(AppLovinSdk.getInstance(mContext).isInitialized()){ + if(AppLovinSdk.getInstance(mContext).isInitialized() && this.mSupportManager!=null){ this.mSupportManager.onShow(); } } private void onToggleBannerShow(boolean pStatus) { - if(AppLovinSdk.getInstance(mContext).isInitialized()){ - this.mBannerManager.onShow(pStatus); + if(AppLovinSdk.getInstance(mContext).isInitialized() && this.mBannerManager!=null){ + this.mBannerManager.onShowToggle(pStatus); } } @@ -55,7 +55,9 @@ public class appLovinManager { private void onDestroy() { mLowMemoryReached = true; - mBannerManager.onDestroy(); + if(mBannerManager!=null){ + mBannerManager.onDestroy(); + } } /*External Triggers*/ @@ -71,6 +73,8 @@ public class appLovinManager { onToggleBannerShow(false); } else if (pEventType.equals(pluginEnums.eAdManager.M_SHOW_INTERSTITIAL)) { onShowInterstitial(); + } else if (pEventType.equals(pluginEnums.eAdManager.M_INIT_ADS)) { + onInitializeAdvertisement(); } return null; } diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/adPluginManager/applovinBannerManager.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/adPluginManager/applovinBannerManager.java index 81fc1ebf..e529fe2d 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/adPluginManager/applovinBannerManager.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/adPluginManager/applovinBannerManager.java @@ -20,7 +20,7 @@ public class applovinBannerManager implements MaxAdViewAdListener{ private static final String S_UNIT_ID = "642ec6302c7cecd2"; private MaxAdView mBanner; - eventObserver.eventListener mEvent; + private eventObserver.eventListener mEvent; /* Initializations */ @@ -46,7 +46,7 @@ public class applovinBannerManager implements MaxAdViewAdListener{ /* Helper Methods */ - public void onShow(boolean pStatus) { + public void onShowToggle(boolean pStatus) { if(mBanner!=null){ if(pStatus){ mBanner.startAutoRefresh(); diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/blobDownloader.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/blobDownloader.java index 7b1814c7..a907f5c7 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/blobDownloader.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/blobDownloader.java @@ -9,7 +9,7 @@ import android.webkit.JavascriptInterface; import androidx.core.app.NotificationCompat; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.io.File; import java.io.FileOutputStream; diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/downloadReciever.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/downloadReciever.java index dd02da30..4dded143 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/downloadReciever.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/downloadReciever.java @@ -26,7 +26,7 @@ import com.hiddenservices.onionservices.constants.status; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.libs.netcipher.client.StrongHttpsClient; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import org.torproject.android.service.wrapper.orbotLocalConstants; diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/messagePluginManager/messageManager.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/messagePluginManager/messageManager.java index b0b11a43..9222d61f 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/messagePluginManager/messageManager.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/messagePluginManager/messageManager.java @@ -31,7 +31,7 @@ import com.hiddenservices.onionservices.constants.strings; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.helperManager.helperMethod; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.google.android.material.switchmaterial.SwitchMaterial; import org.mozilla.geckoview.ContentBlocking; import java.util.Arrays; diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/notificationPluginManager/localEngagementManager.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/notificationPluginManager/localEngagementManager.java index 26f1ac67..b8b6eb9f 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/notificationPluginManager/localEngagementManager.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/notificationPluginManager/localEngagementManager.java @@ -15,7 +15,7 @@ import androidx.core.app.NotificationCompat; import com.hiddenservices.onionservices.appManager.activityContextManager; import com.hiddenservices.onionservices.constants.strings; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.Random; diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/notificationPluginManager/notifictionManager.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/notificationPluginManager/notifictionManager.java index 1e88aec2..f0945a29 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/notificationPluginManager/notifictionManager.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/notificationPluginManager/notifictionManager.java @@ -14,7 +14,7 @@ import androidx.core.app.NotificationCompat; import com.hiddenservices.onionservices.eventObserver; import com.hiddenservices.onionservices.pluginManager.pluginEnums; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.lang.ref.WeakReference; import java.util.List; diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/pluginEnums.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/pluginEnums.java index 773f199b..e2c0da39 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/pluginEnums.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/pluginEnums.java @@ -4,7 +4,7 @@ public class pluginEnums { /*Advert Manager*/ public enum eAdManager { - M_IS_ADVERT_LOADED, M_LOW_MEMORY_DESTROY, M_HIDE_BANNER, M_SHOW_BANNER, M_SHOW_INTERSTITIAL + M_IS_ADVERT_LOADED, M_LOW_MEMORY_DESTROY, M_HIDE_BANNER, M_SHOW_BANNER, M_SHOW_INTERSTITIAL, M_INIT_ADS } public enum eAdManagerCallbacks { diff --git a/app/src/main/java/com/widget/onionservices/widgetManager/widgetController.java b/app/src/main/java/com/widget/onionservices/widgetManager/widgetController.java index 67306fbd..dfcfa7b8 100644 --- a/app/src/main/java/com/widget/onionservices/widgetManager/widgetController.java +++ b/app/src/main/java/com/widget/onionservices/widgetManager/widgetController.java @@ -10,7 +10,7 @@ import android.os.Bundle; import android.util.Log; import android.widget.RemoteViews; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import com.widget.onionservices.helperMethod.helperMethod; import java.util.Arrays; diff --git a/app/src/main/java/com/widget/onionservices/widgetManager/widgetViewController.java b/app/src/main/java/com/widget/onionservices/widgetManager/widgetViewController.java index 8cac3026..b84d1dcc 100644 --- a/app/src/main/java/com/widget/onionservices/widgetManager/widgetViewController.java +++ b/app/src/main/java/com/widget/onionservices/widgetManager/widgetViewController.java @@ -6,7 +6,7 @@ import android.view.View; import android.widget.RemoteViews; import com.hiddenservices.onionservices.eventObserver; -import com.example.myapplication.R; +import com.hiddenservices.onionservices.R; import java.util.List; diff --git a/app/src/main/res/custom-xml/bookmark/xml/bx_border_recycleview.xml b/app/src/main/res/custom-xml/bookmark/xml/bx_border_recycleview.xml new file mode 100644 index 00000000..302b6743 --- /dev/null +++ b/app/src/main/res/custom-xml/bookmark/xml/bx_border_recycleview.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layouts/bookmark/layout/bookmark_view.xml b/app/src/main/res/layouts/bookmark/layout/bookmark_view.xml index 9b1fe5ad..5a6b8505 100644 --- a/app/src/main/res/layouts/bookmark/layout/bookmark_view.xml +++ b/app/src/main/res/layouts/bookmark/layout/bookmark_view.xml @@ -156,7 +156,7 @@ android:layout_marginTop="0dp" android:layout_marginEnd="0dp" android:layout_weight="17" - android:background="@xml/gx_ripple_blue" + android:background="@xml/bx_border_recycleview" android:textAllCaps="false" android:paddingStart="20dp" android:stateListAnimator="@null" @@ -179,6 +179,7 @@ android:id="@+id/pRecycleView" android:layout_width="match_parent" android:layout_height="match_parent" + android:layout_marginBottom="100dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> diff --git a/app/src/main/res/layouts/history/layout/history_view.xml b/app/src/main/res/layouts/history/layout/history_view.xml index 93076bcf..ff490b60 100644 --- a/app/src/main/res/layouts/history/layout/history_view.xml +++ b/app/src/main/res/layouts/history/layout/history_view.xml @@ -180,6 +180,7 @@ android:id="@+id/pRecycleView" android:layout_width="match_parent" android:layout_height="match_parent" + android:layout_marginBottom="100dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> diff --git a/app/src/main/res/layouts/home/layout/hint_view.xml b/app/src/main/res/layouts/home/layout/hint_view.xml index bfa5d0d9..9851d683 100644 --- a/app/src/main/res/layouts/home/layout/hint_view.xml +++ b/app/src/main/res/layouts/home/layout/hint_view.xml @@ -70,6 +70,7 @@ android:layout_marginEnd="10dp" android:clickable="false" android:ellipsize="end" + android:textAlignment="viewStart" android:maxLines="1" android:paddingStart="10dp" android:paddingEnd="0dp" diff --git a/app/src/main/res/layouts/home/layout/home_view.xml b/app/src/main/res/layouts/home/layout/home_view.xml index 8c6f20c9..163ef1dd 100644 --- a/app/src/main/res/layouts/home/layout/home_view.xml +++ b/app/src/main/res/layouts/home/layout/home_view.xml @@ -473,7 +473,7 @@ android:background="@xml/hox_rounded_corner_splash_right" android:contentDescription="@string/GENERAL_TODO" android:onClick="onSupportSplash" - app:tint="@color/c_setting_icon_tint" + app:tint="#425e8a" android:padding="6dp" android:scaleType="fitCenter" android:src="@xml/ic_baseline_support" diff --git a/app/src/main/res/layouts/setting/layout/setting.xml b/app/src/main/res/layouts/setting/layout/setting.xml index 0a826e65..0eb2ee13 100644 --- a/app/src/main/res/layouts/setting/layout/setting.xml +++ b/app/src/main/res/layouts/setting/layout/setting.xml @@ -166,9 +166,10 @@ @@ -1026,13 +1027,6 @@ - - #f9f9f9 /* Orbot Setting */ - #e6e6e6 + #f2f2f2 #e6e6e6 /* Tab */ diff --git a/app/variables.gradle b/app/variables.gradle index 1e6f1b86..19a9bff3 100755 --- a/app/variables.gradle +++ b/app/variables.gradle @@ -2,6 +2,8 @@ project.ext.vname = 'Build | Dark-Origin 1.0.9.2' project.ext.vcode = 510 project.ext.buildType = 'release' +project.ext.jvmTarget = "1.8" +project.ext.applovin_key = "pCPe4EeU2ZQVwQPeHLgseRqHBX1V5pvo9Piuu4J809dRhadEgukXa1A8po_UeXu5hmPOTaP1v4QPaMKIEOhh50" /* dimension */ project.ext.dimen = 'product' diff --git a/memory-20230120T201423.alloc b/memory-20230120T201423.alloc deleted file mode 100644 index e69de29b..00000000