diff options
-rw-r--r-- | build.gradle | 4 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java | 5 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java | 114 | ||||
-rw-r--r-- | src/main/res/layout/welcome.xml | 20 | ||||
-rw-r--r-- | src/main/res/values/ids.xml | 1 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 3 |
6 files changed, 142 insertions, 5 deletions
diff --git a/build.gradle b/build.gradle index 4f4d46295..9d144585f 100644 --- a/build.gradle +++ b/build.gradle @@ -72,9 +72,9 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 23 - versionCode 147 + versionCode 150 - versionName "1.13.0" + versionName "1.13.1" archivesBaseName += "-$versionName" applicationId "de.pixart.messenger" diff --git a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java index b47b0c1dd..e1e15452f 100644 --- a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java @@ -103,11 +103,10 @@ public class UpdaterActivity extends Activity { private void ExportDatabase() throws IOException { // Get hold of the db: - InputStream myInput = new - FileInputStream(this.getDatabasePath(DatabaseBackend.DATABASE_NAME)); + InputStream myInput = new FileInputStream(this.getDatabasePath(DatabaseBackend.DATABASE_NAME)); // Set the output folder on the SDcard - File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Pix-Art Messenger/.Database/"); + File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/.Database/"); // Create the folder if it doesn't exist: if (!directory.exists()) { diff --git a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java index d4e8fa9f6..55bb7140f 100644 --- a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java @@ -1,12 +1,26 @@ package eu.siacs.conversations.ui; import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.Intent; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteException; import android.os.Bundle; +import android.os.Environment; import android.view.View; import android.widget.Button; +import android.widget.TextView; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import eu.siacs.conversations.R; +import eu.siacs.conversations.persistance.DatabaseBackend; public class WelcomeActivity extends Activity { @@ -14,6 +28,62 @@ public class WelcomeActivity extends Activity { protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.welcome); + boolean dbExist = checkDatabase(); + boolean backup_existing = false; + + //check if there is a backed up database -- + if (dbExist) { + //copy db from public storage to private storage + backup_existing = true; + } else { + //if copy fails, show dialog + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(R.string.import_failed) + .setCancelable(false) + .setPositiveButton(R.string.create_account, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Intent intent = new Intent(WelcomeActivity.this, MagicCreateActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + } + }) + .setNegativeButton(R.string.use_existing_accout, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + startActivity(new Intent(WelcomeActivity.this, EditAccountActivity.class)); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + //throw new Error("Error copying database"); + } + + final Button ImportDatabase = (Button) findViewById(R.id.import_database); + final TextView ImportText = (TextView) findViewById(R.id.import_text); + + if (backup_existing) { + ImportDatabase.setVisibility(View.VISIBLE); + ImportText.setVisibility(View.VISIBLE); + } + + ImportDatabase.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //ToDo add import DB from local storage to system storage and wait until copy is complete + try { + ImportDatabase(); + } catch (IOException e) { + e.printStackTrace(); + } + //ask user to uninstall old eu.siacs.conversations before restart + + //restart app + Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName()); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + }); + final Button createAccount = (Button) findViewById(R.id.create_account); createAccount.setOnClickListener(new View.OnClickListener() { @Override @@ -33,4 +103,48 @@ public class WelcomeActivity extends Activity { } + private boolean checkDatabase() { + + SQLiteDatabase checkDB = null; + String DB_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/.Database/"; + String DB_NAME = "Database.bak"; + + try { + String myPath = DB_PATH + DB_NAME; + checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); + } catch (SQLiteException e) { + //database does't exist yet. + } + + if (checkDB != null) { + checkDB.close(); + } + return checkDB != null ? true : false; + } + + private void ImportDatabase() throws IOException { + + // Set location for the db: + OutputStream myOutput = new FileOutputStream(this.getDatabasePath(DatabaseBackend.DATABASE_NAME)); + + // Set the folder on the SDcard + File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/.Database/"); + + // Set the input file stream up: + InputStream myInput = new FileInputStream(directory.getPath() + "/Database.bak"); + + // Transfer bytes from the input file to the output file + byte[] buffer = new byte[1024]; + int length; + while ((length = myInput.read(buffer)) > 0) { + myOutput.write(buffer, 0, length); + } + + // Close and clear the streams + myOutput.flush(); + myOutput.close(); + myInput.close(); + } + + } diff --git a/src/main/res/layout/welcome.xml b/src/main/res/layout/welcome.xml index 813570759..2fb9667a5 100644 --- a/src/main/res/layout/welcome.xml +++ b/src/main/res/layout/welcome.xml @@ -43,6 +43,26 @@ android:textColor="@color/black87" android:textSize="?attr/TextSizeBody" /> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:text="@string/import_text" + android:textColor="@color/black87" + android:textSize="?attr/TextSizeBody" + android:visibility="gone" + android:id="@id/import_text" /> + + <Button + android:id="@+id/import_database" + style="?android:attr/borderlessButtonStyle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="right" + android:text="@string/import_database" + android:textColor="@color/accent" + android:visibility="gone" /> + <Button android:id="@+id/create_account" style="?android:attr/borderlessButtonStyle" diff --git a/src/main/res/values/ids.xml b/src/main/res/values/ids.xml index 75f75673b..0786006cf 100644 --- a/src/main/res/values/ids.xml +++ b/src/main/res/values/ids.xml @@ -3,4 +3,5 @@ <item name="snackbar_location_message" type="id" /> <item name="message_image_view" type="id" /> <item name="message_video_view" type="id" /> + <item name="import_text" type="id" /> </resources>
\ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index f25918008..b71122003 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -642,5 +642,8 @@ <string name="conference_subject">Subject</string> <string name="choose_participants">Choose participants</string> <string name="creating_conference">Creating conferenceā¦</string> + <string name="import_text">There is a backup on your device. Shall the backup be imported?</string> + <string name="import_database">import backup</string> + <string name="import_failed">The import has failed</string> </resources> |