aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-05-31 21:40:45 +0200
committerChristian Schneppe <christian@pix-art.de>2016-05-31 21:40:45 +0200
commit5f8de512f5d14515146d341bc3e0ae0e066837b8 (patch)
tree87f6b90d606db834f2503549b4c82f18bae1a376 /src/main
parentc23642b8cd2c06c5f3e9cf7f88d31ed5c6f78614 (diff)
parent9e724edb42d8cb0fa8745f88a80d914df09f4ff6 (diff)
Merge remote-tracking branch 'refs/remotes/origin/new_version'
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java9
-rw-r--r--src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java43
-rw-r--r--src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java143
-rw-r--r--src/main/res/layout/welcome.xml20
-rw-r--r--src/main/res/values-de/strings.xml3
-rw-r--r--src/main/res/values/ids.xml1
-rw-r--r--src/main/res/values/strings.xml4
8 files changed, 220 insertions, 5 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index f1155b07d..5a7ca7a56 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -51,7 +51,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null;
- private static final String DATABASE_NAME = "history";
+ public static final String DATABASE_NAME = "history";
private static final int DATABASE_VERSION = 27;
private static String CREATE_CONTATCS_STATEMENT = "create table "
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index b8927019f..398ca0a1d 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -346,7 +346,7 @@ public class ConversationActivity extends XmppActivity
}
}
- public boolean isPackageInstalled(String targetPackage){
+ private boolean isPackageInstalled(String targetPackage){
List<ApplicationInfo> packages;
PackageManager pm;
pm = getPackageManager();
@@ -1280,9 +1280,6 @@ public class ConversationActivity extends XmppActivity
if (!isConversationsOverviewVisable() || !isConversationsOverviewHideable()) {
sendReadMarkerIfNecessary(getSelectedConversation());
}
-
- AppUpdate();
-
}
@Override
@@ -1369,6 +1366,10 @@ public class ConversationActivity extends XmppActivity
this.mConversationFragment.setupIme();
}
+ if (xmppConnectionService.getAccounts().size() != 0) {
+ AppUpdate();
+ }
+
if (this.mPostponedActivityResult != null) {
this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
}
diff --git a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java
index a9adfb174..e1e15452f 100644
--- a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java
@@ -27,9 +27,15 @@ import org.json.JSONException;
import org.json.JSONObject;
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.Config;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.services.UpdaterWebService;
public class UpdaterActivity extends Activity {
@@ -94,6 +100,36 @@ public class UpdaterActivity extends Activity {
}
}
+ private void ExportDatabase() throws IOException {
+
+ // Get hold of the db:
+ 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/");
+
+ // Create the folder if it doesn't exist:
+ if (!directory.exists()) {
+ directory.mkdirs();
+ }
+
+ // Set the output file stream up:
+ OutputStream myOutput = new FileOutputStream(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();
+ }
+
+
@Override
public void onDestroy() {
//unregister your receivers
@@ -201,6 +237,13 @@ public class UpdaterActivity extends Activity {
reponseObj = new JSONObject(responseMessage);
boolean success = reponseObj.getBoolean("success");
if (success) {
+ //start backing up database
+ try {
+ ExportDatabase();
+ Log.d(Config.LOGTAG,"AppUpdater: Database successfully exported");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
//Overall information about the contents of a package
//This corresponds to all of the information collected from AndroidManifest.xml.
PackageInfo pInfo = null;
diff --git a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java
index d4e8fa9f6..3e35bd48c 100644
--- a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java
@@ -1,19 +1,68 @@
package eu.siacs.conversations.ui;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
+import android.net.Uri;
import android.os.Bundle;
+import android.os.Environment;
+import android.util.Log;
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 java.util.List;
+
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.persistance.DatabaseBackend;
public class WelcomeActivity extends Activity {
+ boolean dbExist = checkDatabase();
+ boolean backup_existing = false;
+
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
+
+
+ //check if there is a backed up database --
+ if (dbExist) {
+ backup_existing = true;
+ }
+
+ 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) {
+ try {
+ ImportDatabase();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
final Button createAccount = (Button) findViewById(R.id.create_account);
createAccount.setOnClickListener(new View.OnClickListener() {
@Override
@@ -33,4 +82,98 @@ 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);
+ Log.d(Config.LOGTAG,"Backup found");
+ } 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);
+ }
+ Log.d(Config.LOGTAG,"Starting import of backup");
+
+ // Close and clear the streams
+ myOutput.flush();
+ myOutput.close();
+ myInput.close();
+
+ Log.d(Config.LOGTAG, "New Features - Uninstall old version of Pix-Art Messenger");
+ if (isPackageInstalled("eu.siacs.conversations")) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setMessage(R.string.uninstall_app_text)
+ .setPositiveButton(R.string.uninstall, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialogInterface, int i) {
+ //start the deinstallation of old version
+ if (isPackageInstalled("eu.siacs.conversations")) {
+ Uri packageURI_VR = Uri.parse("package:eu.siacs.conversations");
+ Intent uninstallIntent_VR = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI_VR);
+ if (uninstallIntent_VR.resolveActivity(getPackageManager()) != null) {
+ startActivity(uninstallIntent_VR);
+ }
+ }
+ }
+ })
+ .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialogInterface, int i) {
+ Log.d(Config.LOGTAG, "New Features - Uninstall cancled");
+ restart();
+ }
+ });
+ builder.create().show();
+ } else {
+ restart();
+ }
+
+ }
+
+ private void restart() {
+ //restart app
+ Log.d(Config.LOGTAG, "Restarting " + getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName()));
+ 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);
+ }
+
+ private boolean isPackageInstalled(String targetPackage) {
+ List<ApplicationInfo> packages;
+ PackageManager pm;
+ pm = getPackageManager();
+ packages = pm.getInstalledApplications(0);
+ for (ApplicationInfo packageInfo : packages) {
+ if (packageInfo.packageName.equals(targetPackage)) return true;
+ }
+ return false;
+ }
+
}
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-de/strings.xml b/src/main/res/values-de/strings.xml
index f5226722e..e9e8d95b2 100644
--- a/src/main/res/values-de/strings.xml
+++ b/src/main/res/values-de/strings.xml
@@ -610,5 +610,8 @@
<string name="registration_please_wait">Registrierung fehlgeschlagen: Bitte später versuchen</string>
<string name="send_message_to_x">Nachricht an %s senden</string>
<string name="joining_conference">Konferenz beitreten…</string>
+ <string name="import_database">Backup importieren</string>
+ <string name="import_text">Es wurde ein Backup gefunden, welches importiert werden kann.\nMöglicherweise wirst du gefragt, ob du eine ältere Version oder Conversations deinstallieren möchtest und dein Messenger startet während des Importvorgangs neu. Soll das Backup importiert werden?</string>
+ <string name="uninstall_app_text">Es ist eine alte Version von Pix-Art Messenger oder Conversations installiert. Falls du einen alten Pix-Art Messenger installiert hast, solltest du diesen deinstallieren. Nach der Deinstallation, solltest du erneut auf \'Backup importieren\' klicken, damit deine Daten in die neue Version importiert werden.</string>
</resources>
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..aec0e3a43 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -642,5 +642,9 @@
<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 which can be imported.\nPossibly you will be asked to uninstall the old version or Conversations and your Messenger will be restarted during backup process. Shall the backup be imported? </string>
+ <string name="import_database">Import backup</string>
+ <string name="uninstall_app_text">There is an old version of Pix-Art Messenger or Conversations installed. If you have an old Pix-Art Messenger installed, you should uninstall this version. After uninstalled the old versoin, you should choose \'import backup\' again and we will import your data to the new version.</string>
+ <string name="you">You</string>
</resources>