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 @@ - - - - - - - - - - - - - - - - - -