mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Add backup export function.
This commit is contained in:
@@ -192,6 +192,8 @@ public class MrMailbox {
|
||||
public final static int MR_EVENT_CONFIGURE_ENDED = 2040;
|
||||
public final static int MR_EVENT_CONFIGURE_PROGRESS = 2041;
|
||||
|
||||
public final static int MR_EVENT_EXPORT_ENDED = 2050;
|
||||
public final static int MR_EVENT_EXPORT_PROGRESS = 2051;
|
||||
public final static int MR_EVENT_EXPORT_FILE_WRITTEN = 2052;
|
||||
|
||||
public final static int MR_EVENT_IS_ONLINE = 2080;
|
||||
@@ -227,6 +229,24 @@ public class MrMailbox {
|
||||
});
|
||||
return 0;
|
||||
|
||||
case MR_EVENT_EXPORT_ENDED:
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.exportEnded, (int)data1);
|
||||
}
|
||||
});
|
||||
return 0;
|
||||
|
||||
case MR_EVENT_EXPORT_PROGRESS:
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.exportProgress, (int)data1);
|
||||
}
|
||||
});
|
||||
return 0;
|
||||
|
||||
case MR_EVENT_EXPORT_FILE_WRITTEN: {
|
||||
final String file_name = CPtr2String(data1);
|
||||
final String file_mime = CPtr2String(data2);
|
||||
|
||||
@@ -33,6 +33,8 @@ public class NotificationCenter {
|
||||
|
||||
public static final int configureEnded = totalEvents++;
|
||||
public static final int configureProgress = totalEvents++;
|
||||
public static final int exportEnded = totalEvents++;
|
||||
public static final int exportProgress = totalEvents++;
|
||||
public static final int didReceivedNewMessages = totalEvents++;
|
||||
public static final int updateInterfaces = totalEvents++;
|
||||
public static final int dialogsNeedReload = totalEvents++;
|
||||
|
||||
@@ -54,8 +54,6 @@ import com.b44t.ui.Cells.TextInfoCell;
|
||||
import com.b44t.ui.Cells.TextSettingsCell;
|
||||
import com.b44t.ui.Components.LayoutHelper;
|
||||
|
||||
import static android.app.ProgressDialog.STYLE_HORIZONTAL;
|
||||
|
||||
|
||||
public class SettingsAccountActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ package com.b44t.ui;
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -37,13 +38,13 @@ import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.AndroidUtilities;
|
||||
import com.b44t.messenger.MediaController;
|
||||
import com.b44t.messenger.ApplicationLoader;
|
||||
import com.b44t.messenger.MrChat;
|
||||
import com.b44t.messenger.MrMailbox;
|
||||
import com.b44t.messenger.NotificationCenter;
|
||||
import com.b44t.messenger.R;
|
||||
import com.b44t.ui.Adapters.BaseFragmentAdapter;
|
||||
import com.b44t.ui.Cells.ShadowSectionCell;
|
||||
@@ -56,7 +57,7 @@ import com.b44t.ui.Components.LayoutHelper;
|
||||
import java.io.File;
|
||||
|
||||
|
||||
public class SettingsAdvActivity extends BaseFragment {
|
||||
public class SettingsAdvActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
||||
|
||||
// the list
|
||||
private int directShareRow, cacheRow, raiseToSpeakRow, sendByEnterRow, autoplayGifsRow, showUnknownSendersRow, finalShadowRow;
|
||||
@@ -83,6 +84,9 @@ public class SettingsAdvActivity extends BaseFragment {
|
||||
public boolean onFragmentCreate() {
|
||||
super.onFragmentCreate();
|
||||
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.exportEnded);
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.exportProgress);
|
||||
|
||||
rowCount = 0;
|
||||
accountSettingsRow = rowCount++;
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
@@ -104,6 +108,13 @@ public class SettingsAdvActivity extends BaseFragment {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentDestroy() {
|
||||
super.onFragmentDestroy();
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.exportEnded);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.exportProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(Context context)
|
||||
{
|
||||
@@ -231,14 +242,7 @@ public class SettingsAdvActivity extends BaseFragment {
|
||||
showDialog(builder2.create());
|
||||
}
|
||||
else /*export*/ {
|
||||
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
getParentActivity().requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
|
||||
return;
|
||||
}
|
||||
File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||
downloadsDir.mkdirs();
|
||||
MrMailbox.exportStuff(MrMailbox.MR_IMEX_SELF_KEYS, downloadsDir.getAbsolutePath());
|
||||
AndroidUtilities.showDoneHint(ApplicationLoader.applicationContext);
|
||||
startExport(MrMailbox.MR_IMEX_SELF_KEYS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,7 +251,7 @@ public class SettingsAdvActivity extends BaseFragment {
|
||||
}
|
||||
else if( i == backupRow )
|
||||
{
|
||||
Toast.makeText(getParentActivity(), ApplicationLoader.applicationContext.getString(R.string.NotYetImplemented), Toast.LENGTH_SHORT).show();
|
||||
startExport(MrMailbox.MR_EXPORT_BACKUP);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -255,6 +259,75 @@ public class SettingsAdvActivity extends BaseFragment {
|
||||
return fragmentView;
|
||||
}
|
||||
|
||||
private ProgressDialog progressDialog = null;
|
||||
|
||||
private void startExport(int what)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
getParentActivity().requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
if( progressDialog!=null ) {
|
||||
progressDialog.dismiss();
|
||||
progressDialog = null;
|
||||
}
|
||||
|
||||
progressDialog = new ProgressDialog(getParentActivity());
|
||||
progressDialog.setMessage(ApplicationLoader.applicationContext.getString(R.string.OneMoment));
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
synchronized (MrMailbox.m_lastErrorLock) {
|
||||
MrMailbox.m_showNextErrorAsToast = false;
|
||||
MrMailbox.m_lastErrorString = "";
|
||||
}
|
||||
|
||||
File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||
downloadsDir.mkdirs();
|
||||
MrMailbox.exportStuff(what, downloadsDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didReceivedNotification(int id, Object... args) {
|
||||
if( id==NotificationCenter.exportProgress ) {
|
||||
if( progressDialog!=null ) {
|
||||
// we want the spinner together with a progress info
|
||||
int percent = (Integer)args[0];
|
||||
progressDialog.setMessage(ApplicationLoader.applicationContext.getString(R.string.OneMoment)+String.format(" %d%%", percent));
|
||||
}
|
||||
}
|
||||
else if( id==NotificationCenter.exportEnded ) {
|
||||
final String errorString;
|
||||
|
||||
synchronized (MrMailbox.m_lastErrorLock) {
|
||||
MrMailbox.m_showNextErrorAsToast = true;
|
||||
errorString = MrMailbox.m_lastErrorString;
|
||||
}
|
||||
|
||||
if( progressDialog!=null ) {
|
||||
progressDialog.dismiss();
|
||||
progressDialog = null;
|
||||
}
|
||||
|
||||
if( (int)args[0]==1 ) {
|
||||
AndroidUtilities.showDoneHint(ApplicationLoader.applicationContext);
|
||||
}
|
||||
else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||
builder.setMessage(errorString.isEmpty()? "Export error." : errorString);
|
||||
builder.setPositiveButton(ApplicationLoader.applicationContext.getString(R.string.OK), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
;
|
||||
}
|
||||
});
|
||||
showDialog(builder.create());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ListAdapter extends BaseFragmentAdapter {
|
||||
private Context mContext;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user