1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Cleanup code duplications in FirstStartActivity (ref #622)

This commit is contained in:
Catfriend1 2018-05-27 20:58:02 +02:00 committed by Audrius Butkevicius
parent ec626cd9fe
commit 2e908783ff

View file

@ -9,6 +9,7 @@ import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast; import android.widget.Toast;
@ -21,6 +22,7 @@ import javax.inject.Inject;
public class FirstStartActivity extends Activity implements Button.OnClickListener { public class FirstStartActivity extends Activity implements Button.OnClickListener {
private static String TAG = "FirstStartActivity";
private static final int REQUEST_WRITE_STORAGE = 142; private static final int REQUEST_WRITE_STORAGE = 142;
@Inject SharedPreferences mPreferences; @Inject SharedPreferences mPreferences;
@ -32,18 +34,13 @@ public class FirstStartActivity extends Activity implements Button.OnClickListen
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
((SyncthingApp) getApplication()).component().inject(this); ((SyncthingApp) getApplication()).component().inject(this);
startService(new Intent(this, SyncthingService.class));
if (!isFirstStart()) { if (!isFirstStart()) {
if (haveStoragePermission()) { startApp();
startApp(); return;
return;
}
else {
requestStoragePermission();
}
} }
// Show first start UI.
setContentView(R.layout.activity_first_start); setContentView(R.layout.activity_first_start);
Button cont = findViewById(R.id.cont); Button cont = findViewById(R.id.cont);
cont.setOnClickListener(this); cont.setOnClickListener(this);
@ -54,11 +51,23 @@ public class FirstStartActivity extends Activity implements Button.OnClickListen
} }
private void startApp() { private void startApp() {
if (!haveStoragePermission()) {
requestStoragePermission();
/**
* startApp will be called in {@link #onRequestPermissionsResult()}
* after permission was granted.
*/
return;
}
boolean isFirstStart = isFirstStart(); boolean isFirstStart = isFirstStart();
if (isFirstStart) { if (isFirstStart) {
Log.v(TAG, "User completed first start UI.");
mPreferences.edit().putBoolean("first_start", false).apply(); mPreferences.edit().putBoolean("first_start", false).apply();
} }
startService(new Intent(this, SyncthingService.class));
// In case start_into_web_gui option is enabled, start both activities so that back // In case start_into_web_gui option is enabled, start both activities so that back
// navigation works as expected. // navigation works as expected.
Intent mainIntent = new Intent(this, MainActivity.class); Intent mainIntent = new Intent(this, MainActivity.class);
@ -86,12 +95,7 @@ public class FirstStartActivity extends Activity implements Button.OnClickListen
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (!haveStoragePermission()) { startApp();
requestStoragePermission();
}
else {
startApp();
}
} }
@Override @Override