mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 03:11:30 +00:00
Added seperate first start activity
This commit is contained in:
parent
6129e00e9e
commit
d464010ee5
4 changed files with 32 additions and 88 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 1188ebbb7b0f4545da4bcfceeb63d3c3ce6bb4ee
|
||||
Subproject commit 3ae51648da5fbed3962c08807f100d7bc79c4ae3
|
|
@ -25,9 +25,8 @@
|
|||
android:supportsRtl="true"
|
||||
android:installLocation="internalOnly">
|
||||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop">
|
||||
android:name=".activities.FirstStartActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
@ -37,6 +36,11 @@
|
|||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.WebGuiActivity"
|
||||
android:label="@string/web_gui_title"
|
||||
|
|
|
@ -1,26 +1,20 @@
|
|||
package com.nutomic.syncthingandroid.activities;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
|
@ -29,14 +23,8 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
|||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.*;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.fragments.DeviceListFragment;
|
||||
import com.nutomic.syncthingandroid.fragments.DrawerFragment;
|
||||
|
@ -44,7 +32,6 @@ import com.nutomic.syncthingandroid.fragments.FolderListFragment;
|
|||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -60,6 +47,8 @@ public class MainActivity extends SyncthingActivity
|
|||
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
static final String EXTRA_FIRST_START = "com.nutomic.syncthing-android.MainActivity.FIRST_START";
|
||||
|
||||
/**
|
||||
* Time after first start when usage reporting dialog should be shown.
|
||||
*
|
||||
|
@ -67,8 +56,6 @@ public class MainActivity extends SyncthingActivity
|
|||
*/
|
||||
private static final long USAGE_REPORTING_DIALOG_DELAY = TimeUnit.DAYS.toMillis(3);
|
||||
|
||||
private static final int REQUEST_WRITE_STORAGE = 142;
|
||||
|
||||
private AlertDialog mLoadingDialog;
|
||||
private AlertDialog mDisabledDialog;
|
||||
|
||||
|
@ -81,8 +68,6 @@ public class MainActivity extends SyncthingActivity
|
|||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
private DrawerLayout mDrawerLayout;
|
||||
|
||||
private SharedPreferences mPreferences;
|
||||
|
||||
/**
|
||||
* Handles various dialogs based on current state.
|
||||
*/
|
||||
|
@ -91,21 +76,10 @@ public class MainActivity extends SyncthingActivity
|
|||
switch (currentState) {
|
||||
case INIT:
|
||||
showLoadingDialog();
|
||||
// Make sure the first start dialog is shown on top.
|
||||
if (isFirstStart()) {
|
||||
showFirstStartDialog();
|
||||
}
|
||||
break;
|
||||
case STARTING:
|
||||
showLoadingDialog();
|
||||
dismissDisabledDialog();
|
||||
int permissionState = ContextCompat.checkSelfPermission(this,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (permissionState != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||
REQUEST_WRITE_STORAGE);
|
||||
}
|
||||
break;
|
||||
case ACTIVE:
|
||||
dismissDisabledDialog();
|
||||
|
@ -136,10 +110,6 @@ public class MainActivity extends SyncthingActivity
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isFirstStart() {
|
||||
return mPreferences.getBoolean("first_start", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unix timestamp at which the app was first installed.
|
||||
*/
|
||||
|
@ -154,22 +124,6 @@ public class MainActivity extends SyncthingActivity
|
|||
return firstInstallTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays information for first app start.
|
||||
*/
|
||||
private void showFirstStartDialog() {
|
||||
new AlertDialog.Builder(MainActivity.this)
|
||||
.setTitle(R.string.welcome_title)
|
||||
.setMessage(R.string.welcome_text)
|
||||
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
mPreferences.edit().putBoolean("first_start", false).apply();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the loading dialog with the correct text ("creating keys" or "loading").
|
||||
*/
|
||||
|
@ -181,7 +135,7 @@ public class MainActivity extends SyncthingActivity
|
|||
@SuppressLint("InflateParams")
|
||||
View dialogLayout = inflater.inflate(R.layout.dialog_loading, null);
|
||||
TextView loadingText = (TextView) dialogLayout.findViewById(R.id.loading_text);
|
||||
loadingText.setText((isFirstStart())
|
||||
loadingText.setText((getIntent().getBooleanExtra(EXTRA_FIRST_START, false))
|
||||
? R.string.web_gui_creating_key
|
||||
: R.string.api_loading);
|
||||
|
||||
|
@ -238,7 +192,6 @@ public class MainActivity extends SyncthingActivity
|
|||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
|
@ -369,7 +322,7 @@ public class MainActivity extends SyncthingActivity
|
|||
/**
|
||||
* Handles drawer opened and closed events, toggling option menu state.
|
||||
*/
|
||||
public class Toggle extends ActionBarDrawerToggle {
|
||||
private class Toggle extends ActionBarDrawerToggle {
|
||||
public Toggle(Activity activity, DrawerLayout drawerLayout) {
|
||||
super(activity, drawerLayout, R.string.app_name, R.string.app_name);
|
||||
}
|
||||
|
@ -489,22 +442,4 @@ public class MainActivity extends SyncthingActivity
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||
@NonNull int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_WRITE_STORAGE:
|
||||
Log.d(TAG, Arrays.toString(grantResults));
|
||||
if (grantResults.length == 0 ||
|
||||
grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(this, R.string.toast_write_storage_permission_required,
|
||||
Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,28 @@
|
|||
|
||||
<string name="app_description">An open, trustworthy and decentralized file synchronization application.</string>
|
||||
|
||||
<!-- FirstStartActivity -->
|
||||
|
||||
|
||||
<!-- Title for dialog displayed on first start -->
|
||||
<string name="welcome_title">Welcome to Syncthing for Android</string>
|
||||
|
||||
<!-- Text for dialog displayed on first start -->
|
||||
<string name="welcome_text">Syncthing is an open-source file synchronization application.\n\
|
||||
To share data with other devices, you need add their unique device ID to the device list. Afterwards you can select which folders to share with which devices.\n\
|
||||
Please report any problems you encounter via Github.</string>
|
||||
|
||||
<string name="cont">Continue</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>
|
||||
|
||||
|
@ -199,20 +218,6 @@
|
|||
<!-- 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>
|
||||
|
||||
<!-- 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 for dialog displayed on first start -->
|
||||
<string name="welcome_title">Welcome to Syncthing for Android</string>
|
||||
|
||||
<!-- Text for dialog displayed on first start -->
|
||||
<string name="welcome_text">Syncthing is an open-source file synchronization application.\n\n\
|
||||
To share data with other devices, you need add their unique device ID to the device list. Afterwards you can select which folders to share with which devices.\n\n
|
||||
Please report any problems you encounter via Github.</string>
|
||||
|
||||
<!-- SettingsFragment -->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue