Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance boost and code clean-up #97

Merged
merged 11 commits into from
Dec 3, 2024
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies {
implementation 'androidx.browser:browser:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'androidx.webkit:webkit:1.7.0'
implementation "com.google.android.material:material:1.9.0"
implementation 'com.google.code.gson:gson:2.8.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.PictureInPictureParams;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand Down Expand Up @@ -84,7 +83,6 @@ public class BrowserActivity extends AppCompatActivity {
private SharedPreferences sharedPref;
private WebViewManager manager;
private WebViewL mContentView;
private ProgressDialog downloadDialog;
private ScreenshotNotification screenshotNotification;
private final K3dPatcher k3dPatcher = new K3dPatcher();
private final KenPatcher kenPatcher = new KenPatcher();
Expand All @@ -95,7 +93,6 @@ public class BrowserActivity extends AppCompatActivity {
private boolean isStartedFlag = false;
private boolean isAdjustChangedByUser = false;
private List<String> connector_info;
private boolean pause_flag = false;
private boolean isMuteMode, isCaptureMode, isLockMode, isKeepMode, isCaptionMode;
private boolean isSubtitleLoaded = false;
private TextView subtitleText;
Expand Down Expand Up @@ -160,7 +157,6 @@ protected void onCreate(Bundle savedInstanceState) {
if (isKeepMode) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

kcCameraButton = findViewById(R.id.kc_camera);
downloadDialog = new ProgressDialog(BrowserActivity.this);

// Browser Panel Buttons
View menuRefresh = findViewById(R.id.menu_refresh);
Expand Down Expand Up @@ -213,10 +209,8 @@ protected void onCreate(Bundle savedInstanceState) {
subtitleText.setVisibility(isKcBrowserMode && isCaptionMode ? View.VISIBLE : View.GONE);
subtitleText.setOnClickListener(v -> clearSubHandler.postDelayed(clearSubtitle, 250));

// defaultSubtitleMargin = getDefaultSubtitleMargin();
//setSubtitleMargin(sharedPref.getInt(PREF_PADDING, 0));
String subtitle_local = sharedPref.getString(PREF_SUBTITLE_LOCALE, "");
if (subtitle_local.length() > 0) {
if (!subtitle_local.isEmpty()) {
isSubtitleLoaded = SubtitleProviderUtils.getSubtitleProvider(subtitle_local)
.loadQuoteData(getApplicationContext(), subtitle_local);
}
Expand Down Expand Up @@ -298,7 +292,6 @@ protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
// | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Expand All @@ -316,7 +309,6 @@ protected void onStart() {
@Override
protected void onStop() {
super.onStop();
pause_flag = true;
manager.runMuteScript(mContentView, true, true);
sendIsFrontChanged(false);
}
Expand All @@ -333,7 +325,6 @@ protected void onResume() {
super.onResume();
Log.e("GOTO", "onResume");
Log.e("GOTO", isAdjustChangedByUser + " " + isInPictureInPictureMode + " " + isMultiWindowMode());
pause_flag = false;
mContentView.resumeTimers();
sendIsFrontChanged(true);
if (isAdjustChangedByUser || isInPictureInPictureMode || isMultiWindowMode()) {
Expand Down Expand Up @@ -406,12 +397,10 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
}
}

public ProgressDialog getDownloadDialog() { return downloadDialog; }
public boolean isKcMode() { return isKcBrowserMode; }
public boolean isMuteMode() { return isMuteMode; }
public boolean isCaptionAvailable() { return isCaptionMode; }
public boolean isSubtitleAvailable() { return isSubtitleLoaded; }
public boolean isBrowserPaused() { return pause_flag; }
public void setStartedFlag() { isStartedFlag = true; }

private void setMuteMode(View v) {
Expand Down Expand Up @@ -673,13 +662,6 @@ public void showLogoutDialog() {
alertDialog.show();
}

/*
public void setSubtitleMargin(int value) {
FrameLayout.LayoutParams param = (FrameLayout.LayoutParams) subtitleText.getLayoutParams();
param.setMargins(param.leftMargin + value, param.topMargin, param.rightMargin + value, param.bottomMargin);
subtitleText.setLayoutParams(param);
}*/

public void setMultiwindowMargin() {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mContentView.getLayoutParams();
if (isMultiWindowMode() && !isInPictureInPictureMode) {
Expand Down Expand Up @@ -710,7 +692,7 @@ public void showScreenshotNotification(Bitmap bitmap, Uri uri) {
screenshotNotification.showNotification(bitmap, uri);
}

private Runnable clearSubtitle = new Runnable() {
private final Runnable clearSubtitle = new Runnable() {
@Override
public void run() {
subtitleText.setText("");
Expand All @@ -733,6 +715,7 @@ public void onUserLeaveHint() {

@Override
public void onPictureInPictureModeChanged(boolean newMode, Configuration newConfig) {
super.onPictureInPictureModeChanged(newMode, newConfig);
isInPictureInPictureMode = newMode;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !isStartedFlag) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,6 @@ protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
}

@Override
protected void onDestroy() {
super.onDestroy();
}

private void showConnectorSelectionDialog() {
SwitchCompat silentSwitch = findViewById(R.id.switch_silent);
final String[] listItems = getResources().getStringArray(R.array.connector_list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.antest1.gotobrowser.R;
import com.antest1.gotobrowser.Subtitle.SubtitleProviderUtils;
import com.google.android.material.snackbar.Snackbar;
import com.google.gson.JsonObject;

import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -123,15 +122,6 @@ public static void setInitialSettings(SharedPreferences sharedPref) {
editor.apply();
}

public static Locale getCurrentLocale(Context context){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
return context.getResources().getConfiguration().getLocales().get(0);
} else{
//noinspection deprecation
return context.getResources().getConfiguration().locale;
}
}

public static class SettingsFragment extends PreferenceFragmentCompat
implements Preference.OnPreferenceChangeListener,
SharedPreferences.OnSharedPreferenceChangeListener,
Expand Down Expand Up @@ -239,7 +229,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
if (preference instanceof EditTextPreference) {
String stringValue = (String) newValue;
if (stringValue.length() == 0) stringValue = DEFAULT_ALTER_GADGET_URL;
if (stringValue.isEmpty()) stringValue = DEFAULT_ALTER_GADGET_URL;
sharedPref.edit().putString(key, stringValue).apply();
preference.setSummary(stringValue);
}
Expand All @@ -260,7 +250,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {

private void updateSubtitleDescriptionText() {
String subtitleLocale = sharedPref.getString(PREF_SUBTITLE_LOCALE, "");
if (subtitleLocale.length() > 0) {
if (!subtitleLocale.isEmpty()) {
setSubtitlePreference(subtitleLocale);
} else {
findPreference(PREF_SUBTITLE_UPDATE).setEnabled(false);
Expand All @@ -282,7 +272,6 @@ private void setSubtitlePreference(String subtitleLocaleCode) {
}

private void updateKantaiEnDescriptionText() {
Preference kantaiEn = findPreference(PREF_MOD_KANTAIEN);
Preference kantaiEnUpdate = findPreference(PREF_MOD_KANTAIEN_UPDATE);

if (sharedPref.getBoolean(PREF_MOD_KANTAIEN, false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
import com.antest1.gotobrowser.R;

public class BrowserGestureListener extends GestureDetector.SimpleOnGestureListener {
private final BrowserActivity activity;
private final View browserPanel;

public BrowserGestureListener(BrowserActivity activity, View.OnClickListener onClickListener) {
this.activity = activity;
this.onClickListener = onClickListener;
browserPanel = activity.findViewById(R.id.browser_panel);
}
Expand Down
Loading