also restart if permissions were changed after first start

This commit is contained in:
Christian Schneppe 2016-06-12 20:02:57 +02:00
parent 01c717753c
commit 8b669b51b9
2 changed files with 32 additions and 29 deletions

View file

@ -1326,34 +1326,34 @@ public class ConversationActivity extends XmppActivity
mPendingConferenceInvite = null;
}
if (FirstStartTime == 0) {
Log.d(Config.LOGTAG, "First start time: " + FirstStartTime + ", restarting App");
//write first start timestamp to file
String PREFS_NAME = "FirstStart";
FirstStartTime = System.currentTimeMillis();
SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = FirstStart.edit();
editor.putLong("FirstStart", FirstStartTime);
editor.commit();
// restart
Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
System.exit(0);
}
if (xmppConnectionService.getAccounts().size() == 0) {
if (mRedirected.compareAndSet(false, true)) {
if (Config.X509_VERIFICATION) {
startActivity(new Intent(this, ManageAccountActivity.class));
} else if (Config.MAGIC_CREATE_DOMAIN != null) {
if (FirstStartTime == 0) {
Log.d(Config.LOGTAG, "First start time: " + FirstStartTime + ", restarting App");
//write first start timestamp to file
String PREFS_NAME = "FirstStart";
FirstStartTime = System.currentTimeMillis();
SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = FirstStart.edit();
editor.putLong("FirstStart", FirstStartTime);
editor.commit();
// restart
Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
System.exit(0);
} else {
Log.d(Config.LOGTAG, "First start time: " + FirstStartTime);
startActivity(new Intent(this, WelcomeActivity.class));
}
} else {
startActivity(new Intent(this, EditAccountActivity.class));
}
finish();
startActivity(new Intent(this, ManageAccountActivity.class));
} else if (Config.MAGIC_CREATE_DOMAIN != null) {
Log.d(Config.LOGTAG, "First start time: " + FirstStartTime);
startActivity(new Intent(this, WelcomeActivity.class));
} else {
startActivity(new Intent(this, EditAccountActivity.class));
}
finish();
}
} else if (conversationList.size() <= 0) {
if (mRedirected.compareAndSet(false, true)) {

View file

@ -12,7 +12,6 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import java.util.Arrays;
import java.util.List;
import eu.siacs.conversations.Config;
@ -20,9 +19,6 @@ import eu.siacs.conversations.R;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
/**
* Created by Christian on 10.06.2016.
*/
public class startUI extends AppCompatActivity
implements EasyPermissions.PermissionCallbacks {
@ -55,6 +51,13 @@ public class startUI extends AppCompatActivity
startActivity(intent);
finish();
} else {
// set first start to 0 if there are permissions to request
String PREFS_NAME = "FirstStart";
long FirstStartTime = 0;
SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = FirstStart.edit();
editor.putLong("FirstStart", FirstStartTime);
editor.commit();
// Do not have permissions, request them now
EasyPermissions.requestPermissions(this, getString(R.string.request_permissions_message),
NeededPermissions, perms);