diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/VersioningDialogActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/VersioningDialogActivity.java index 075f4e012..4fe305355 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/VersioningDialogActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/VersioningDialogActivity.java @@ -3,13 +3,12 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentTransaction; import android.view.View; import android.widget.AdapterView; -import android.widget.Button; -import android.widget.Spinner; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentTransaction; import com.nutomic.syncthingandroid.R; +import com.nutomic.syncthingandroid.databinding.ActivityVersioningDialogBinding; import com.nutomic.syncthingandroid.fragments.dialog.ExternalVersioningFragment; import com.nutomic.syncthingandroid.fragments.dialog.NoVersioningFragment; import com.nutomic.syncthingandroid.fragments.dialog.SimpleVersioningFragment; @@ -27,10 +26,13 @@ public class VersioningDialogActivity extends ThemedAppCompatActivity { private Bundle mArguments; + private ActivityVersioningDialogBinding binding; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.fragment_versioning_dialog); + binding = ActivityVersioningDialogBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); if (savedInstanceState != null) { mArguments = savedInstanceState.getBundle("arguments"); @@ -44,8 +46,7 @@ protected void onCreate(Bundle savedInstanceState) { } private void initiateFinishBtn() { - Button finishBtn = findViewById(R.id.finish_btn); - finishBtn.setOnClickListener(v -> { + binding.finishBtn.setOnClickListener(v -> { saveConfiguration(); finish(); }); @@ -58,9 +59,8 @@ private void saveConfiguration() { } private void initiateSpinner() { - Spinner versioningTypeSpinner = findViewById(R.id.versioningTypeSpinner); - versioningTypeSpinner.setSelection(mTypes.indexOf(getIntent().getExtras().getString("type"))); - versioningTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + binding.versioningTypeSpinner.setSelection(mTypes.indexOf(getIntent().getExtras().getString("type"))); + binding.versioningTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { if (position != mTypes.indexOf(getIntent().getExtras().getString("type"))) { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/WebGuiActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/WebGuiActivity.java index db64881c6..8e3dc1d69 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/WebGuiActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/WebGuiActivity.java @@ -6,10 +6,10 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.net.Proxy; import android.net.Uri; import android.net.http.SslCertificate; import android.net.http.SslError; -import android.net.Proxy; import android.os.Build; import android.os.Bundle; import android.os.IBinder; @@ -18,13 +18,13 @@ import android.util.Base64; import android.util.Log; import android.view.View; -import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast; import com.nutomic.syncthingandroid.R; +import com.nutomic.syncthingandroid.databinding.ActivityWebGuiBinding; import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.SyncthingService; import com.nutomic.syncthingandroid.service.SyncthingServiceBinder; @@ -37,7 +37,6 @@ import java.io.InputStream; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -58,14 +57,12 @@ public class WebGuiActivity extends StateDialogActivity private static final String TAG = "WebGuiActivity"; - private WebView mWebView; - - private View mLoadingView; - private X509Certificate mCaCert; private ConfigXml mConfig; + private ActivityWebGuiBinding binding; + /** * Hides the loading screen and shows the WebView once it is fully loaded. */ @@ -110,8 +107,8 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { @Override public void onPageFinished(WebView view, String url) { - mWebView.setVisibility(View.VISIBLE); - mLoadingView.setVisibility(View.GONE); + binding.webview.setVisibility(View.VISIBLE); + binding.loading.setVisibility(View.GONE); } }; @@ -124,18 +121,16 @@ public void onPageFinished(WebView view, String url) { @SuppressLint("SetJavaScriptEnabled") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + binding = ActivityWebGuiBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); - setContentView(R.layout.activity_web_gui); - - mLoadingView = findViewById(R.id.loading); mConfig = new ConfigXml(this); loadCaCert(); - mWebView = findViewById(R.id.webview); - mWebView.getSettings().setJavaScriptEnabled(true); - mWebView.getSettings().setDomStorageEnabled(true); - mWebView.setWebViewClient(mWebViewClient); - mWebView.clearCache(true); + binding.webview.getSettings().setJavaScriptEnabled(true); + binding.webview.getSettings().setDomStorageEnabled(true); + binding.webview.setWebViewClient(mWebViewClient); + binding.webview.clearCache(true); // SyncthingService needs to be started from this activity as the user // can directly launch this activity from the recent activity switcher. @@ -158,26 +153,26 @@ public void onServiceConnected(ComponentName componentName, IBinder iBinder) { public void onServiceStateChange(SyncthingService.State newState) { Log.v(TAG, "onServiceStateChange(" + newState + ")"); if (newState == SyncthingService.State.ACTIVE) { - if (mWebView == null) { + if (binding.webview == null) { Log.v(TAG, "onWebGuiAvailable: Skipped event due to mWebView == null"); return; } - if (mWebView.getUrl() == null) { - mWebView.stopLoading(); - setWebViewProxy(mWebView.getContext().getApplicationContext(), "", 0, "localhost|0.0.0.0|127.*|[::1]"); + if (binding.webview.getUrl() == null) { + binding.webview.stopLoading(); + setWebViewProxy(binding.webview.getContext().getApplicationContext(), "", 0, "localhost|0.0.0.0|127.*|[::1]"); String credentials = mConfig.getUserName() + ":" + mConfig.getApiKey(); String b64Credentials = Base64.encodeToString(credentials.getBytes(UTF_8), Base64.NO_WRAP); Map headers = new HashMap<>(); headers.put("Authorization", "Basic " + b64Credentials); - mWebView.loadUrl(getService().getWebGuiUrl().toString(), headers); + binding.webview.loadUrl(getService().getWebGuiUrl().toString(), headers); } } } @Override public void onBackPressed() { - if (mWebView.canGoBack()) { - mWebView.goBack(); + if (binding.webview.canGoBack()) { + binding.webview.goBack(); } else { finish(); super.onBackPressed(); @@ -186,16 +181,16 @@ public void onBackPressed() { @Override public void onPause() { - mWebView.onPause(); - mWebView.pauseTimers(); + binding.webview.onPause(); + binding.webview.pauseTimers(); super.onPause(); } @Override public void onResume() { super.onResume(); - mWebView.resumeTimers(); - mWebView.onResume(); + binding.webview.resumeTimers(); + binding.webview.onResume(); } @Override @@ -204,8 +199,7 @@ protected void onDestroy() { if (mSyncthingService != null) { mSyncthingService.unregisterOnServiceStateChangeListener(this); } - mWebView.destroy(); - mWebView = null; + binding.webview.destroy(); super.onDestroy(); } diff --git a/app/src/main/res/layout/fragment_versioning_dialog.xml b/app/src/main/res/layout/activity_versioning_dialog.xml similarity index 98% rename from app/src/main/res/layout/fragment_versioning_dialog.xml rename to app/src/main/res/layout/activity_versioning_dialog.xml index 0e70f568f..7af4bd8aa 100644 --- a/app/src/main/res/layout/fragment_versioning_dialog.xml +++ b/app/src/main/res/layout/activity_versioning_dialog.xml @@ -5,7 +5,6 @@ android:padding="?dialogPreferredPadding" style="@style/Theme.Syncthing.Dialog"> - - \ No newline at end of file +