3434import com .kieronquinn .monetcompat .core .MonetCompat ;
3535import com .noti .main .Application ;
3636import com .noti .main .R ;
37+ import com .noti .main .service .backend .PacketBonding ;
3738import com .noti .main .service .mirnoti .NotificationActionProcess ;
3839import com .noti .main .ui .prefs .ServerPingActivity ;
3940import com .noti .main .ui .prefs .custom .CustomFragment ;
@@ -71,6 +72,7 @@ public class OtherPreference extends PreferenceFragmentCompat {
7172
7273 Preference UseBackendProxy ;
7374 Preference EnforceBackendProxy ;
75+ Preference ProxyPacketBondingDelay ;
7476 Preference UseSplitData ;
7577 Preference SplitInterval ;
7678 Preference SplitAfterEncryption ;
@@ -122,6 +124,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
122124
123125 UseBackendProxy = findPreference ("UseBackendProxy" );
124126 EnforceBackendProxy = findPreference ("EnforceBackendProxy" );
127+ ProxyPacketBondingDelay = findPreference ("ProxyPacketBondingDelay" );
125128 UseSplitData = findPreference ("UseSplitData" );
126129 SplitInterval = findPreference ("SplitInterval" );
127130 SplitAfterEncryption = findPreference ("SplitAfterEncryption" );
@@ -172,9 +175,13 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
172175 });
173176
174177 boolean useProxy = prefs .getBoolean ("UseBackendProxy" , true );
178+ long packetBondingDelay = prefs .getLong ("ProxyPacketBondingDelay" , PacketBonding .DEFAULT_DELAY );
175179 EnforceBackendProxy .setVisible (useProxy );
180+ ProxyPacketBondingDelay .setVisible (useProxy );
181+ ProxyPacketBondingDelay .setSummary ("Now : " + (packetBondingDelay == 300 ? "300 ms (Default)" : (packetBondingDelay < 1 ? "0 ms (Disabled)" : packetBondingDelay + " ms" )));
176182 UseBackendProxy .setOnPreferenceChangeListener ((preference , newValue ) -> {
177183 EnforceBackendProxy .setVisible ((boolean ) newValue );
184+ ProxyPacketBondingDelay .setVisible ((boolean ) newValue );
178185 if ((boolean )(newValue )) {
179186 prefs .edit ().putBoolean ("UseBackendProxy" , false ).apply ();
180187 ((SwitchedPreference )UseSplitData ).setChecked (false );
@@ -194,6 +201,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
194201 ((SwitchedPreference )UseBackendProxy ).setChecked (false );
195202 prefs .edit ().putBoolean ("UseBackendProxy" , false ).apply ();
196203 EnforceBackendProxy .setVisible (false );
204+ ProxyPacketBondingDelay .setVisible (false );
197205 }
198206
199207 SplitInterval .setVisible ((boolean ) newValue );
@@ -462,6 +470,58 @@ public boolean onPreferenceTreeClick(Preference preference) {
462470 startActivity (new Intent (mContext , ServerPingActivity .class ));
463471 break ;
464472
473+ case "ProxyPacketBondingDelay" :
474+ dialog = new MaterialAlertDialogBuilder (new ContextThemeWrapper (mContext , R .style .Theme_App_Palette_Dialog ));
475+ dialog .setIcon (R .drawable .ic_fluent_edit_24_regular );
476+ dialog .setCancelable (false );
477+ dialog .setTitle ("Bonding Threshold" );
478+ dialog .setMessage ("""
479+ Packet Bonding is a method of bundling multiple packets into one and transmitting them at once through a proxy server when multiple transmissions are requested consecutively within a short period of time.
480+
481+ At this time, Threshold is the time to wait for the next packet. If this value is high, it is energy efficient because a large number of requests can be processed with a single network operation, but the network delay time increases accordingly.
482+
483+ Some real-time aware packets (e.g., pairing requests) may be excluded from these feature and processed.
484+
485+ The interval maximum limit is 2147483647 ms and Input 0 or lower to disable this option.
486+ """ );
487+
488+ editText = new EditText (mContext );
489+ editText .setInputType (InputType .TYPE_CLASS_NUMBER );
490+ editText .setHint ("Input interval value" );
491+ editText .setGravity (Gravity .CENTER );
492+ editText .setText (String .valueOf (prefs .getLong ("ProxyPacketBondingDelay" , PacketBonding .DEFAULT_DELAY )));
493+
494+ parentLayout = new LinearLayout (mContext );
495+ layoutParams = new LinearLayout .LayoutParams (
496+ LinearLayout .LayoutParams .MATCH_PARENT ,
497+ LinearLayout .LayoutParams .WRAP_CONTENT );
498+ layoutParams .setMargins (30 , 16 , 30 , 16 );
499+ editText .setLayoutParams (layoutParams );
500+ parentLayout .addView (editText );
501+ dialog .setView (parentLayout );
502+
503+ dialog .setPositiveButton ("Apply" , (d , w ) -> {
504+ String value = editText .getText ().toString ();
505+ if (value .isEmpty ()) {
506+ ToastHelper .show (mContext , "Please Input Value" , "DISMISS" ,ToastHelper .LENGTH_SHORT );
507+ } else {
508+ int IntValue = Integer .parseInt (value );
509+ if (IntValue > 0x7FFFFFFF - 1 ) {
510+ ToastHelper .show (mContext , "Value must be lower than 2147483647" , "DISMISS" ,ToastHelper .LENGTH_SHORT );
511+ } else {
512+ prefs .edit ().putLong ("ProxyPacketBondingDelay" , IntValue ).apply ();
513+ ProxyPacketBondingDelay .setSummary ("Now : " + (IntValue == 300 ? "300 ms (Default)" : (IntValue < 1 ? "0 ms (Disabled)" : IntValue + " ms" )));
514+ }
515+ }
516+ });
517+ dialog .setNeutralButton ("Reset Default" , (d , w ) -> {
518+ prefs .edit ().putLong ("ProxyPacketBondingDelay" , PacketBonding .DEFAULT_DELAY ).apply ();
519+ ProxyPacketBondingDelay .setSummary ("Now : 300 ms (Default)" );
520+ });
521+ dialog .setNegativeButton ("Cancel" , (d , w ) -> {});
522+ dialog .show ();
523+ break ;
524+
465525 case "SplitInterval" :
466526 dialog = new MaterialAlertDialogBuilder (new ContextThemeWrapper (mContext , R .style .Theme_App_Palette_Dialog ));
467527 dialog .setIcon (R .drawable .ic_fluent_edit_24_regular );
0 commit comments