mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-23 18:35:54 +00:00
Show button to open logs if Syncthing takes long to load (ref #687)
This commit is contained in:
parent
d58a3c9634
commit
1aa6bc4af3
3 changed files with 91 additions and 32 deletions
|
@ -1,25 +1,27 @@
|
|||
package com.nutomic.syncthingandroid.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
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.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.databinding.DialogLoadingBinding;
|
||||
import com.nutomic.syncthingandroid.service.SyncthingService;
|
||||
import com.nutomic.syncthingandroid.util.Util;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Handles loading/disabled dialogs.
|
||||
*/
|
||||
public abstract class StateDialogActivity extends SyncthingActivity {
|
||||
|
||||
private static final String TAG = "StateDialogActivity";
|
||||
private static final long SLOW_LOADING_TIME = TimeUnit.SECONDS.toMillis(30);
|
||||
|
||||
private AlertDialog mLoadingDialog;
|
||||
private AlertDialog mDisabledDialog;
|
||||
|
@ -89,18 +91,29 @@ public abstract class StateDialogActivity extends SyncthingActivity {
|
|||
if (isFinishing() || mLoadingDialog != null)
|
||||
return;
|
||||
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
@SuppressLint("InflateParams")
|
||||
View dialogLayout = inflater.inflate(R.layout.dialog_loading, null);
|
||||
TextView loadingText = dialogLayout.findViewById(R.id.loading_text);
|
||||
loadingText.setText((getIntent().getBooleanExtra(EXTRA_FIRST_START, false))
|
||||
DialogLoadingBinding binding = DataBindingUtil.inflate(
|
||||
getLayoutInflater(), R.layout.dialog_loading, null, false);
|
||||
boolean isFirstStart = getIntent().getBooleanExtra(EXTRA_FIRST_START, false);
|
||||
binding.loadingText.setText((isFirstStart)
|
||||
? R.string.web_gui_creating_key
|
||||
: R.string.api_loading);
|
||||
|
||||
mLoadingDialog = new AlertDialog.Builder(this)
|
||||
.setCancelable(false)
|
||||
.setView(dialogLayout)
|
||||
.setView(binding.getRoot())
|
||||
.show();
|
||||
|
||||
if (!isFirstStart) {
|
||||
new Handler().postDelayed(() -> {
|
||||
if (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() {
|
||||
|
|
|
@ -1,19 +1,59 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/abc_action_bar_content_inset_material"
|
||||
android:gravity="center"
|
||||
android:theme="?alertDialogTheme">
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<ProgressBar
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="@dimen/abc_action_bar_content_inset_material"
|
||||
android:layout_marginEnd="@dimen/abc_action_bar_content_inset_material" />
|
||||
android:padding="@dimen/abc_action_bar_content_inset_material"
|
||||
android:theme="?alertDialogTheme"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loading_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="@dimen/abc_action_bar_content_inset_material"
|
||||
android:layout_marginEnd="@dimen/abc_action_bar_content_inset_material" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loading_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="@string/api_loading"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/loading_slow_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="24dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/syncthing_loading_slow_message"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/view_logs"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/open_log"
|
||||
style="@style/Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:textColor="@color/accent"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
||||
|
|
|
@ -21,11 +21,6 @@ Please report any problems you encounter via Github.</string>
|
|||
<!-- MainActivity -->
|
||||
|
||||
|
||||
<!-- Text for WebGuiActivity loading view -->
|
||||
<string name="web_gui_loading">Waiting for GUI</string>
|
||||
|
||||
<!-- Shown instead of web_gui_loading if the key does not exist and has to be created -->
|
||||
<string name="web_gui_creating_key">Generating secure keys. This may take a few minutes.</string>
|
||||
|
||||
<!-- Title of the "add folder" menu action -->
|
||||
<string name="add_folder">Add Folder</string>
|
||||
|
@ -36,9 +31,6 @@ Please report any problems you encounter via Github.</string>
|
|||
<!-- Shown in the chooser dialog when sharing a Device ID -->
|
||||
<string name="send_device_id_to">Send Device ID to</string>
|
||||
|
||||
<!-- Text for FoldersFragment and DevicesFragment loading view -->
|
||||
<string name="api_loading">Loading…</string>
|
||||
|
||||
<string name="usage_reporting_dialog_title">Allow Anonymous Usage Reporting?</string>
|
||||
|
||||
<string name="usage_reporting_dialog_description">The encrypted usage report is sent daily. It is used to track common platforms, folder sizes and app versions. If the reported data set is changed you will be prompted with this dialog again.\n\nThe aggregated statistics are publicly available at https://data.syncthing.net.</string>
|
||||
|
@ -62,6 +54,17 @@ Please report any problems you encounter via Github.</string>
|
|||
<string name="dialog_disable_battery_optimization_turn_off">Turn off for Syncthing</string>
|
||||
<string name="dialog_disable_battery_optimizations_not_supported">Your device does not support disabling battery optimizations</string>
|
||||
|
||||
<!-- StateDialogActivity -->
|
||||
|
||||
|
||||
<!-- Text for FoldersFragment and DevicesFragment loading view -->
|
||||
<string name="api_loading">Loading…</string>
|
||||
|
||||
<!-- Shown instead of web_gui_loading if the key does not exist and has to be created -->
|
||||
<string name="web_gui_creating_key">Generating secure keys. This may take a few minutes.</string>
|
||||
|
||||
<string name="syncthing_loading_slow_message">Syncthing is taking very long to load. Use the logs to check for any errors.</string>
|
||||
|
||||
<!-- FoldersFragment -->
|
||||
|
||||
|
||||
|
@ -230,6 +233,9 @@ Please report any problems you encounter via Github.</string>
|
|||
<!-- Title of the web gui activity -->
|
||||
<string name="web_gui_title">Web GUI</string>
|
||||
|
||||
<!-- Text for WebGuiActivity loading view -->
|
||||
<string name="web_gui_loading">Waiting for GUI</string>
|
||||
|
||||
<!-- SettingsFragment -->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue