rework update message

This commit is contained in:
Christian Schneppe 2020-11-17 17:19:27 +01:00
parent 0eee8d2da0
commit 89c7171d11
No known key found for this signature in database
GPG key ID: F30B8D686B44D87E
3 changed files with 158 additions and 90 deletions

View file

@ -58,6 +58,8 @@ import eu.siacs.conversations.xmpp.InvalidJid;
import eu.siacs.conversations.xmpp.mam.MamReference;
import eu.siacs.conversations.xmpp.Jid;
import static eu.siacs.conversations.ui.util.UpdateHelper.moveData;
public class DatabaseBackend extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "history";
@ -585,67 +587,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
if (oldVersion < 53 && newVersion >= 53) {
final File oldMainDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/");
final File oldPicturesDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Media/Pix-Art Messenger Images/");
final File oldFilesDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Media/Pix-Art Messenger Files/");
final File oldAudiosDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Media/Pix-Art Messenger Audios/");
final File oldVideosDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Media/Pix-Art Messenger Videos/");
if (oldPicturesDirectory.exists() && oldPicturesDirectory.isDirectory()) {
final File newPicturesDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/blabber.im Images/");
newPicturesDirectory.getParentFile().mkdirs();
final File[] files = oldPicturesDirectory.listFiles();
if (files == null) {
return;
}
if (oldPicturesDirectory.renameTo(newPicturesDirectory)) {
Log.d(Config.LOGTAG, "moved " + oldPicturesDirectory.getAbsolutePath() + " to " + newPicturesDirectory.getAbsolutePath());
}
}
if (oldFilesDirectory.exists() && oldFilesDirectory.isDirectory()) {
final File newFilesDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/blabber.im Files/");
newFilesDirectory.mkdirs();
final File[] files = oldFilesDirectory.listFiles();
if (files == null) {
return;
}
if (oldFilesDirectory.renameTo(newFilesDirectory)) {
Log.d(Config.LOGTAG, "moved " + oldFilesDirectory.getAbsolutePath() + " to " + newFilesDirectory.getAbsolutePath());
}
}
if (oldAudiosDirectory.exists() && oldAudiosDirectory.isDirectory()) {
final File newAudiosDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/blabber.im Audios/");
newAudiosDirectory.mkdirs();
final File[] files = oldAudiosDirectory.listFiles();
if (files == null) {
return;
}
if (oldAudiosDirectory.renameTo(newAudiosDirectory)) {
Log.d(Config.LOGTAG, "moved " + oldAudiosDirectory.getAbsolutePath() + " to " + newAudiosDirectory.getAbsolutePath());
}
}
if (oldVideosDirectory.exists() && oldVideosDirectory.isDirectory()) {
final File newVideosDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/blabber.im Videos/");
newVideosDirectory.mkdirs();
final File[] files = oldVideosDirectory.listFiles();
if (files == null) {
return;
}
if (oldVideosDirectory.renameTo(newVideosDirectory)) {
Log.d(Config.LOGTAG, "moved " + oldVideosDirectory.getAbsolutePath() + " to " + newVideosDirectory.getAbsolutePath());
}
}
if (oldMainDirectory.exists() && oldMainDirectory.isDirectory()) {
final File newMainDirectory = new File(Environment.getExternalStorageDirectory() + "/blabber.im/");
newMainDirectory.mkdirs();
final File[] files = oldMainDirectory.listFiles();
if (files == null) {
return;
}
if (oldMainDirectory.renameTo(newMainDirectory)) {
Log.d(Config.LOGTAG, "moved " + oldMainDirectory.getAbsolutePath() + " to " + newMainDirectory.getAbsolutePath());
}
}
moveData();
}
}

View file

@ -7,11 +7,14 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -19,20 +22,31 @@ import java.util.Locale;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.ui.ConversationsActivity;
import eu.siacs.conversations.ui.WelcomeActivity;
import me.drakeet.support.toast.ToastCompat;
public class UpdateHelper {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
private static final String INSTALL_DATE = "2020-11-01";
private static final String blabber_message = "BLABBER.IM_UPDATE_MESSAGE";
private static boolean moveData = true;
private static boolean dataMoved = false;
private static final File oldMainDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/");
private static final File newMainDirectory = new File(Environment.getExternalStorageDirectory() + "/blabber-im/");
private static final File oldPicturesDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Media/Pix-Art Messenger Images/");
private static final File oldFilesDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Media/Pix-Art Messenger Files/");
private static final File oldAudiosDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Media/Pix-Art Messenger Audios/");
private static final File oldVideosDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pix-Art Messenger/Media/Pix-Art Messenger Videos/");
public static void showPopup(Activity activity) {
Thread t = new Thread(() -> {
String blabber_message = "BLABBER.IM_UPDATE_MESSAGE";
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(activity.getBaseContext());
String Message = "message_shown_" + blabber_message;
boolean SHOW_MESSAGE = getPrefs.getBoolean(Message, true);
if (SHOW_MESSAGE && updateInstalled(activity) && Config.SHOW_MIGRATION_INFO) {
final SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(activity.getBaseContext());
final String Message = "message_shown_" + blabber_message;
final boolean SHOW_MESSAGE = getPrefs.getBoolean(Message, true);
if (activity instanceof ConversationsActivity && (SHOW_MESSAGE && updateInstalled(activity) && Config.SHOW_MIGRATION_INFO)) {
Log.d(Config.LOGTAG, "UpdateHelper: installed update from Pix-Art Messenger to blabber.im");
activity.runOnUiThread(() -> {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(activity.getString(R.string.title_activity_updater));
@ -42,32 +56,141 @@ public class UpdateHelper {
);
builder.create().show();
});
} else if (SHOW_MESSAGE && newInstalled(activity) && !Config.SHOW_MIGRATION_INFO && PAMInstalled(activity)) {
activity.runOnUiThread(() -> {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(activity.getString(R.string.title_activity_updater));
builder.setMessage(activity.getString(R.string.updated_to_blabber_google));
builder.setCancelable(false);
builder.setPositiveButton(R.string.link, (dialog, which) -> {
SaveMessageShown(activity, blabber_message);
try {
final Uri uri = Uri.parse(Config.migrationURL);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(browserIntent);
} catch (Exception e) {
ToastCompat.makeText(activity, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
}
}
);
builder.setNegativeButton(R.string.cancel, (dialog, which) -> SaveMessageShown(activity, blabber_message)
);
builder.create().show();
});
} else if (activity instanceof WelcomeActivity && (SHOW_MESSAGE && newInstalled(activity) && !Config.SHOW_MIGRATION_INFO && PAMInstalled(activity))) {
Log.d(Config.LOGTAG, "UpdateHelper: new installed blabber.im");
showNewInstalledDialog(activity);
}
});
t.start();
}
private static void showNewInstalledDialog(Activity activity) {
checkOldData();
activity.runOnUiThread(() -> {
if (dataMoved) {
ToastCompat.makeText(activity, R.string.data_successfully_moved, Toast.LENGTH_LONG).show();
}
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(activity.getString(R.string.title_activity_updater));
builder.setMessage(activity.getString(R.string.updated_to_blabber_google));
builder.setCancelable(false);
builder.setPositiveButton(R.string.link, (dialog, which) -> {
SaveMessageShown(activity, blabber_message);
try {
final Uri uri = Uri.parse(Config.migrationURL);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(browserIntent);
showNewInstalledDialog(activity);
} catch (Exception e) {
ToastCompat.makeText(activity, R.string.no_application_found_to_open_link, Toast.LENGTH_LONG).show();
showNewInstalledDialog(activity);
}
}
);
builder.setNegativeButton(R.string.move_data, (dialog, which) -> {
SaveMessageShown(activity, blabber_message);
try {
if (!moveData) {
ToastCompat.makeText(activity, R.string.error_moving_data, Toast.LENGTH_LONG).show();
} else {
moveData();
}
showNewInstalledDialog(activity);
} catch (Exception e) {
ToastCompat.makeText(activity, R.string.error_moving_data, Toast.LENGTH_LONG).show();
showNewInstalledDialog(activity);
}
}
);
builder.setNeutralButton(R.string.done, (dialog, which) -> SaveMessageShown(activity, blabber_message)
);
AlertDialog dialog = builder.create();
dialog.show();
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setEnabled(!dataMoved);
});
}
private static void checkOldData() {
if (oldMainDirectory.exists() && oldMainDirectory.isDirectory()) {
if (newMainDirectory.exists() && newMainDirectory.isDirectory()) {
moveData = false;
} else {
moveData = true;
}
} else {
moveData = false;
}
Log.d(Config.LOGTAG, "UpdateHelper: old data available: " + moveData);
}
public static void moveData() {
if (oldPicturesDirectory.exists() && oldPicturesDirectory.isDirectory()) {
final File newPicturesDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/blabber.im Images/");
newPicturesDirectory.getParentFile().mkdirs();
final File[] files = oldPicturesDirectory.listFiles();
if (files == null) {
return;
}
if (oldPicturesDirectory.renameTo(newPicturesDirectory)) {
Log.d(Config.LOGTAG, "moved " + oldPicturesDirectory.getAbsolutePath() + " to " + newPicturesDirectory.getAbsolutePath());
} else {
Log.d(Config.LOGTAG, "could not move " + oldPicturesDirectory.getAbsolutePath() + " to " + newPicturesDirectory.getAbsolutePath());
}
}
if (oldFilesDirectory.exists() && oldFilesDirectory.isDirectory()) {
final File newFilesDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/blabber.im Files/");
newFilesDirectory.mkdirs();
final File[] files = oldFilesDirectory.listFiles();
if (files == null) {
return;
}
if (oldFilesDirectory.renameTo(newFilesDirectory)) {
Log.d(Config.LOGTAG, "moved " + oldFilesDirectory.getAbsolutePath() + " to " + newFilesDirectory.getAbsolutePath());
} else {
Log.d(Config.LOGTAG, "could not move " + oldFilesDirectory.getAbsolutePath() + " to " + newFilesDirectory.getAbsolutePath());
}
}
if (oldAudiosDirectory.exists() && oldAudiosDirectory.isDirectory()) {
final File newAudiosDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/blabber.im Audios/");
newAudiosDirectory.mkdirs();
final File[] files = oldAudiosDirectory.listFiles();
if (files == null) {
return;
}
if (oldAudiosDirectory.renameTo(newAudiosDirectory)) {
Log.d(Config.LOGTAG, "moved " + oldAudiosDirectory.getAbsolutePath() + " to " + newAudiosDirectory.getAbsolutePath());
} else {
Log.d(Config.LOGTAG, "could not move " + oldAudiosDirectory.getAbsolutePath() + " to " + newAudiosDirectory.getAbsolutePath());
}
}
if (oldVideosDirectory.exists() && oldVideosDirectory.isDirectory()) {
final File newVideosDirectory = new File(Environment.getExternalStorageDirectory() + "/Pix-Art Messenger/Media/blabber.im Videos/");
newVideosDirectory.mkdirs();
final File[] files = oldVideosDirectory.listFiles();
if (files == null) {
return;
}
if (oldVideosDirectory.renameTo(newVideosDirectory)) {
Log.d(Config.LOGTAG, "moved " + oldVideosDirectory.getAbsolutePath() + " to " + newVideosDirectory.getAbsolutePath());
} else {
Log.d(Config.LOGTAG, "could not move " + oldVideosDirectory.getAbsolutePath() + " to " + newVideosDirectory.getAbsolutePath());
}
}
if (oldMainDirectory.exists() && oldMainDirectory.isDirectory()) {
newMainDirectory.mkdirs();
final File[] files = oldMainDirectory.listFiles();
if (files == null) {
return;
}
if (oldMainDirectory.renameTo(newMainDirectory)) {
dataMoved = true;
Log.d(Config.LOGTAG, "moved " + oldMainDirectory.getAbsolutePath() + " to " + newMainDirectory.getAbsolutePath());
} else {
Log.d(Config.LOGTAG, "could not move " + oldMainDirectory.getAbsolutePath() + " to " + newMainDirectory.getAbsolutePath());
}
}
}
private static boolean updateInstalled(Activity activity) {
PackageManager pm = activity.getPackageManager();
PackageInfo packageInfo;
@ -131,6 +254,6 @@ public class UpdateHelper {
String Message = "message_shown_" + message;
SharedPreferences.Editor e = getPrefs.edit();
e.putBoolean(Message, false);
e.apply();
//e.apply();
}
}

View file

@ -1071,7 +1071,10 @@
<string name="pref_invidious_host_summary">Use a custom invidious host</string>
<string name="pref_invidious_host">Invidious host</string>
<string name="updated_to_blabber">We have successfully updated Pix-Art Messenger to blabber.im\n\nThe cooperation of the two projects blabber.im and Pix-Art Messenger was expanded in November 2020. In the future, the Android app Pix-Art Messenger will be continued under the name blabber.im.\n\nWhat you can expect:\n- Range of functions remains the same\n- Support chat rooms are merged\n- Colors and logos are adapted to blabber.im\n- App is still available for free in Google Play Store and F-Droid Store\n\nYour blabber.im Team</string>
<string name="updated_to_blabber_google">We have to apologize that we could not update directly to blabber.im. Under the following link you will receive instructions on how to transfer all your profiles from Pix-Art Messenger to blabber.im.</string>
<string name="updated_to_blabber_google">We have to apologize that we could not update directly to blabber.im. Under the following link you will receive instructions on how to transfer all your profiles from Pix-Art Messenger to blabber.im. By clicking on move data we try to move all sent and received files from Pix-Art Messenger to blabber.im. After a successfully migration keep in mind to remove Pix-Art Messenger from your device.</string>
<string name="link">Link</string>
<string name="no_application_found">No application found</string>
<string name="move_data">Move data</string>
<string name="error_moving_data">An error occurred while moving your old data. Please move them manually.</string>
<string name="data_successfully_moved">Your data has been moved successfully.</string>
</resources>