From 0bfc7e3e2742af85863615fb836f5fb68a197209 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Wed, 22 Aug 2018 22:23:35 +0200 Subject: [PATCH] Remove "loading" overlay dialog as the status tab tells (#22) us if syncthing is starting or restarting. --- .../activities/MainActivity.java | 2 +- .../activities/ShareActivity.java | 2 +- .../activities/StateDialogActivity.java | 107 ------------------ .../activities/WebGuiActivity.java | 2 +- app/src/main/res/layout/dialog_loading.xml | 59 ---------- app/src/main/res/values-ar/strings.xml | 1 - app/src/main/res/values-bg/strings.xml | 1 - app/src/main/res/values-ca-rES/strings.xml | 2 - app/src/main/res/values-cs/strings.xml | 2 - app/src/main/res/values-da/strings.xml | 1 - app/src/main/res/values-de/strings.xml | 2 - app/src/main/res/values-el/strings.xml | 2 - app/src/main/res/values-es-rMX/strings.xml | 1 - app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-fi/strings.xml | 2 - app/src/main/res/values-fr/strings.xml | 2 - app/src/main/res/values-hu/strings.xml | 2 - app/src/main/res/values-in/strings.xml | 2 - app/src/main/res/values-it/strings.xml | 2 - app/src/main/res/values-ja/strings.xml | 2 - app/src/main/res/values-ko/strings.xml | 2 - app/src/main/res/values-nb/strings.xml | 1 - app/src/main/res/values-nl/strings.xml | 2 - app/src/main/res/values-nn/strings.xml | 1 - app/src/main/res/values-pl/strings.xml | 2 - app/src/main/res/values-pt-rBR/strings.xml | 2 - app/src/main/res/values-pt/strings.xml | 1 - app/src/main/res/values-ro/strings.xml | 2 - app/src/main/res/values-ru/strings.xml | 2 - app/src/main/res/values-sk/strings.xml | 1 - app/src/main/res/values-sv/strings.xml | 2 - app/src/main/res/values-tr/strings.xml | 1 - app/src/main/res/values-uk/strings.xml | 1 - app/src/main/res/values-vi/strings.xml | 1 - app/src/main/res/values-zh-rCN/strings.xml | 2 - app/src/main/res/values-zh-rTW/strings.xml | 2 - app/src/main/res/values/strings.xml | 5 - 37 files changed, 3 insertions(+), 224 deletions(-) delete mode 100644 app/src/main/java/com/nutomic/syncthingandroid/activities/StateDialogActivity.java delete mode 100644 app/src/main/res/layout/dialog_loading.xml diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index 5ca888ac..154861e0 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -65,7 +65,7 @@ import static java.lang.Math.min; * {@link DeviceListFragment} in different tabs, and * {@link DrawerFragment} in the navigation drawer. */ -public class MainActivity extends StateDialogActivity +public class MainActivity extends SyncthingActivity implements SyncthingService.OnServiceStateChangeListener { private static final String TAG = "MainActivity"; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/ShareActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/ShareActivity.java index 429f12c1..3913dab0 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/ShareActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/ShareActivity.java @@ -45,7 +45,7 @@ import java.util.Map; * {@link #getDisplayNameForUri} and {@link #getDisplayNameFromContentResolver} are taken from * ownCloud Android {@see https://github.com/owncloud/android/blob/79664304fdb762b2e04f1ac505f50d0923ddd212/src/com/owncloud/android/utils/UriUtils.java#L193} */ -public class ShareActivity extends StateDialogActivity +public class ShareActivity extends SyncthingActivity implements SyncthingActivity.OnServiceConnectedListener, SyncthingService.OnServiceStateChangeListener { private static final String TAG = "ShareActivity"; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/StateDialogActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/StateDialogActivity.java deleted file mode 100644 index 2f77e7e7..00000000 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/StateDialogActivity.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.nutomic.syncthingandroid.activities; - -import android.app.AlertDialog; -import android.content.Intent; -import android.databinding.DataBindingUtil; -import android.os.Bundle; -import android.os.Handler; -import android.support.annotation.Nullable; -import android.support.v4.app.ActivityCompat; -import android.view.View; - -import com.nutomic.syncthingandroid.R; -import com.nutomic.syncthingandroid.databinding.DialogLoadingBinding; -import com.nutomic.syncthingandroid.service.SyncthingService; -import com.nutomic.syncthingandroid.service.SyncthingService.State; -import com.nutomic.syncthingandroid.util.Util; - -import java.util.concurrent.TimeUnit; - -/** - * Handles loading/disabled dialogs. - */ -public abstract class StateDialogActivity extends SyncthingActivity { - - private static final long SLOW_LOADING_TIME = TimeUnit.SECONDS.toMillis(30); - - private State mServiceState = State.INIT; - private AlertDialog mLoadingDialog; - private AlertDialog mDisabledDialog; - private boolean mIsPaused = true; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - registerOnServiceConnectedListener(() -> - getService().registerOnServiceStateChangeListener(this::onServiceStateChange)); - } - - @Override - protected void onResume() { - super.onResume(); - mIsPaused = false; - } - - @Override - protected void onPause() { - super.onPause(); - mIsPaused = true; - dismissLoadingDialog(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (getService() != null) { - getService().unregisterOnServiceStateChangeListener(this::onServiceStateChange); - } - } - - private void onServiceStateChange(SyncthingService.State currentState) { - mServiceState = currentState; - switch (mServiceState) { - case INIT: // fallthrough - case STARTING: - showLoadingDialog(); - break; - case ACTIVE: - dismissLoadingDialog(); - break; - case DISABLED: // fallthrough - case ERROR: // fallthrough - default: - break; - } - } - - /** - * Shows the loading dialog with the correct text ("creating keys" or "loading"). - */ - private void showLoadingDialog() { - if (mIsPaused || mLoadingDialog != null) - return; - - DialogLoadingBinding binding = DataBindingUtil.inflate( - getLayoutInflater(), R.layout.dialog_loading, null, false); - binding.loadingText.setText(R.string.api_loading); - - mLoadingDialog = new AlertDialog.Builder(this) - .setCancelable(false) - .setView(binding.getRoot()) - .show(); - - new Handler().postDelayed(() -> { - if (this.isFinishing() || mLoadingDialog == null) - return; - - binding.loadingSlowMessage.setVisibility(View.VISIBLE); - binding.viewLogs.setOnClickListener(v -> - startActivity(new Intent(this, LogActivity.class))); - }, SLOW_LOADING_TIME); - } - - private void dismissLoadingDialog() { - Util.dismissDialogSafe(mLoadingDialog, this); - mLoadingDialog = null; - } -} 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 04688ce0..da9bc10c 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/WebGuiActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/WebGuiActivity.java @@ -48,7 +48,7 @@ import java.util.Properties; /** * Holds a WebView that shows the web ui of the local syncthing instance. */ -public class WebGuiActivity extends StateDialogActivity +public class WebGuiActivity extends SyncthingActivity implements SyncthingService.OnServiceStateChangeListener { private static final String TAG = "WebGuiActivity"; diff --git a/app/src/main/res/layout/dialog_loading.xml b/app/src/main/res/layout/dialog_loading.xml deleted file mode 100644 index 7eb92ae8..00000000 --- a/app/src/main/res/layout/dialog_loading.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - -