aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlubenard <lubenard@student.42.fr>2020-07-05 11:23:20 +0000
committerlubenard <lubenard@student.42.fr>2020-07-05 11:23:20 +0000
commit38bf8e3cad645244edaf906b8fd8f01565e8e72a (patch)
treea79a2748b621f09af8f89321515b81b1fdbe1cab
parent4febaa47ce25c494d3313f07cbb4a82f2db03d82 (diff)
downloadAnySoftKeyboard-38bf8e3cad645244edaf906b8fd8f01565e8e72a.tar.gz
AnySoftKeyboard-38bf8e3cad645244edaf906b8fd8f01565e8e72a.tar.bz2
Added custom restore file explorer
-rw-r--r--ime/app/src/main/AndroidManifest.xml9
-rw-r--r--ime/app/src/main/java/com/anysoftkeyboard/ui/FileExplorerCreate.java6
-rw-r--r--ime/app/src/main/java/com/anysoftkeyboard/ui/FileExplorerRestore.java131
-rw-r--r--ime/app/src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java12
-rw-r--r--ime/app/src/main/res/layout/file_explorer_create_main_ui.xml (renamed from ime/app/src/main/res/layout/file_explorer_main_ui.xml)4
-rw-r--r--ime/app/src/main/res/layout/file_explorer_restore_main_ui.xml12
-rw-r--r--ime/app/src/main/res/menu/file_explorer_create_menu.xml (renamed from ime/app/src/main/res/menu/file_explorer_menu.xml)0
-rw-r--r--ime/app/src/main/res/values/styles.xml2
-rw-r--r--ime/prefs/src/main/java/com/anysoftkeyboard/prefs/backup/PrefsXmlStorage.java3
9 files changed, 163 insertions, 16 deletions
diff --git a/ime/app/src/main/AndroidManifest.xml b/ime/app/src/main/AndroidManifest.xml
index ced298325..56f8a8a84 100644
--- a/ime/app/src/main/AndroidManifest.xml
+++ b/ime/app/src/main/AndroidManifest.xml
@@ -126,7 +126,14 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/ime_name"
android:roundIcon="@mipmap/ic_launcher_round"
- android:theme="@style/Theme.AskTest" />
+ android:theme="@style/Theme.AskFileExplorer" />
+
+ <activity
+ android:name="com.anysoftkeyboard.ui.FileExplorerRestore"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/ime_name"
+ android:roundIcon="@mipmap/ic_launcher_round"
+ android:theme="@style/Theme.AskFileExplorer" />
</application>
</manifest>
diff --git a/ime/app/src/main/java/com/anysoftkeyboard/ui/FileExplorerCreate.java b/ime/app/src/main/java/com/anysoftkeyboard/ui/FileExplorerCreate.java
index ef4a51c37..d4a367620 100644
--- a/ime/app/src/main/java/com/anysoftkeyboard/ui/FileExplorerCreate.java
+++ b/ime/app/src/main/java/com/anysoftkeyboard/ui/FileExplorerCreate.java
@@ -1,8 +1,5 @@
package com.anysoftkeyboard.ui;
-import android.annotation.SuppressLint;
-import android.app.Activity;
-import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.util.Pair;
@@ -105,7 +102,7 @@ public class FileExplorerCreate extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.file_explorer_main_ui);
+ setContentView(R.layout.file_explorer_create_main_ui);
TextView filenameTextView = (TextView) findViewById(R.id.file_explorer_filename);
ImageButton filenameButton = (ImageButton) findViewById(R.id.file_explorer_filename_button);
@@ -120,7 +117,6 @@ public class FileExplorerCreate extends AppCompatActivity {
listFile(basePath);
filenameButton.setOnClickListener(new View.OnClickListener() {
- @SuppressLint("CheckResult")
@Override
public void onClick(View v) {
if (filenameTextView.length() > 0)
diff --git a/ime/app/src/main/java/com/anysoftkeyboard/ui/FileExplorerRestore.java b/ime/app/src/main/java/com/anysoftkeyboard/ui/FileExplorerRestore.java
new file mode 100644
index 000000000..8eeb66741
--- /dev/null
+++ b/ime/app/src/main/java/com/anysoftkeyboard/ui/FileExplorerRestore.java
@@ -0,0 +1,131 @@
+package com.anysoftkeyboard.ui;
+
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.os.Environment;
+import android.support.v4.util.Pair;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatActivity;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import com.anysoftkeyboard.base.utils.Logger;
+import com.anysoftkeyboard.prefs.GlobalPrefsBackup;
+import com.anysoftkeyboard.rx.RxSchedulers;
+import com.anysoftkeyboard.ui.settings.MainFragment;
+import com.menny.android.anysoftkeyboard.R;
+
+import net.evendanan.pixel.RxProgressDialog;
+
+import java.io.File;
+
+import io.reactivex.disposables.Disposable;
+
+public class FileExplorerRestore extends AppCompatActivity {
+ private ListView listViewFiles;
+ private File basePath;
+ private File currentFolder;
+
+ private Disposable launch_restore() {
+ return RxProgressDialog.create(
+ new Pair<>(MainFragment.supportedProviders, MainFragment.checked),
+ this,
+ getText(R.string.take_a_while_progress_message),
+ R.layout.progress_window)
+ .subscribeOn(RxSchedulers.background())
+ .flatMap(GlobalPrefsBackup::restore)
+ .observeOn(RxSchedulers.mainThread())
+ .subscribe(
+ providerDetails ->
+ Logger.i(
+ "MainFragment",
+ "Finished restore up %s",
+ providerDetails.provider.providerId()),
+ e -> {
+ Logger.w(
+ "MainFragment",
+ e,
+ "Failed to do operation due to %s",
+ e.getMessage());
+ Toast.makeText(getApplicationContext(), "Your data have failed to be restored", Toast.LENGTH_LONG).show();
+ },
+ () ->
+ Toast.makeText(getApplicationContext(), "Your data have been restored", Toast.LENGTH_LONG).show());
+ }
+
+ public void create_builder(){
+ new AlertDialog.Builder(this)
+ .setTitle("Select this file ?")
+ .setMessage("Do you want to restore this file ?")
+
+ // The dialog is automatically dismissed when a dialog button is clicked.
+ .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ launch_restore();
+ finish();
+ }
+ })
+
+ // A null listener allows the button to dismiss the dialog and take no further action.
+ .setNegativeButton(android.R.string.cancel, null)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .show();
+
+ }
+
+ public void listFile(File basePath)
+ {
+ File[] files = basePath.listFiles();
+ ArrayAdapter<File> adapter = new ArrayAdapter<File>(this,
+ R.layout.file_explorer_single_item, files);
+ listViewFiles.setAdapter(adapter);
+
+ //Set onclickListener for all element of listView
+ listViewFiles.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ Object o = listViewFiles.getItemAtPosition(position);
+ if (new File(o.toString()).isDirectory()) {
+ currentFolder = new File(o.toString());
+ setTitle(o.toString());
+ listFile(currentFolder);
+ }
+ else if (new File(o.toString()).isFile())
+ create_builder();
+ }
+ });
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (!currentFolder.equals(basePath))
+ {
+ int sep = currentFolder.toString().lastIndexOf("/");
+ setTitle(currentFolder.toString().substring(0, sep));
+ listFile(new File(currentFolder.toString().substring(0, sep)));
+ }
+ else
+ finish();
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.file_explorer_restore_main_ui);
+
+ listViewFiles = (ListView) findViewById(R.id.file_explorer_list_view);
+
+ basePath = Environment.getExternalStorageDirectory();
+
+ currentFolder = basePath;
+
+ setTitle(basePath.toString());
+
+ listFile(basePath);
+ }
+
+}
diff --git a/ime/app/src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java b/ime/app/src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java
index b0ba1cb3e..51e79f919 100644
--- a/ime/app/src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java
+++ b/ime/app/src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java
@@ -41,6 +41,7 @@ import com.anysoftkeyboard.prefs.GlobalPrefsBackup;
import com.anysoftkeyboard.prefs.backup.PrefsXmlStorage;
import com.anysoftkeyboard.rx.RxSchedulers;
import com.anysoftkeyboard.ui.FileExplorerCreate;
+import com.anysoftkeyboard.ui.FileExplorerRestore;
import com.anysoftkeyboard.ui.settings.setup.SetUpKeyboardWizardFragment;
import com.anysoftkeyboard.ui.settings.setup.SetupSupport;
import com.anysoftkeyboard.ui.tutorials.ChangeLogFragment;
@@ -439,15 +440,20 @@ public class MainFragment extends Fragment {
}
} else {
- Intent intent;
- intent = new Intent(getContext(), FileExplorerCreate.class);
+ Intent intent = null;
+ if (optionId == R.id.backup_prefs){
+ intent = new Intent(getContext(), FileExplorerCreate.class);
+ }
+ else if (optionId == R.id.restore_prefs){
+ intent = new Intent(getContext(), FileExplorerRestore.class);
+ }
startActivity(intent);
}
}
});
}
- public Disposable launchBackupRestore() {
+ private Disposable launchBackupRestore() {
return RxProgressDialog.create(
new Pair<>(supportedProviders, checked),
getActivity(),
diff --git a/ime/app/src/main/res/layout/file_explorer_main_ui.xml b/ime/app/src/main/res/layout/file_explorer_create_main_ui.xml
index 5074f15de..d3cbae068 100644
--- a/ime/app/src/main/res/layout/file_explorer_main_ui.xml
+++ b/ime/app/src/main/res/layout/file_explorer_create_main_ui.xml
@@ -30,8 +30,4 @@
android:layout_height="match_parent"
app:srcCompat="@android:drawable/ic_menu_send" />
</LinearLayout>
-
-
-
-
</LinearLayout> \ No newline at end of file
diff --git a/ime/app/src/main/res/layout/file_explorer_restore_main_ui.xml b/ime/app/src/main/res/layout/file_explorer_restore_main_ui.xml
new file mode 100644
index 000000000..9312aa9bd
--- /dev/null
+++ b/ime/app/src/main/res/layout/file_explorer_restore_main_ui.xml
@@ -0,0 +1,12 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:orientation="vertical" android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ListView
+ android:id="@+id/file_explorer_list_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:clipToPadding="false">
+ </ListView>
+</LinearLayout> \ No newline at end of file
diff --git a/ime/app/src/main/res/menu/file_explorer_menu.xml b/ime/app/src/main/res/menu/file_explorer_create_menu.xml
index a869f2191..a869f2191 100644
--- a/ime/app/src/main/res/menu/file_explorer_menu.xml
+++ b/ime/app/src/main/res/menu/file_explorer_create_menu.xml
diff --git a/ime/app/src/main/res/values/styles.xml b/ime/app/src/main/res/values/styles.xml
index 205883fe5..9caf30f6e 100644
--- a/ime/app/src/main/res/values/styles.xml
+++ b/ime/app/src/main/res/values/styles.xml
@@ -60,7 +60,7 @@
<item name="android:textAppearanceLarge">@style/Ask.Text.Large</item>
</style>
- <style name="Theme.AskTest"
+ <style name="Theme.AskFileExplorer"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColorLink">@color/text_color_link</item>
<item name="colorAccent">@color/app_accent</item>
diff --git a/ime/prefs/src/main/java/com/anysoftkeyboard/prefs/backup/PrefsXmlStorage.java b/ime/prefs/src/main/java/com/anysoftkeyboard/prefs/backup/PrefsXmlStorage.java
index 7f2a6f882..db86f7b87 100644
--- a/ime/prefs/src/main/java/com/anysoftkeyboard/prefs/backup/PrefsXmlStorage.java
+++ b/ime/prefs/src/main/java/com/anysoftkeyboard/prefs/backup/PrefsXmlStorage.java
@@ -72,9 +72,8 @@ public class PrefsXmlStorage {
}
}
- public static void writePrefItems(XmlWriter output, Iterable<PrefItem> items, boolean atRoot)
+ private static void writePrefItems(XmlWriter output, Iterable<PrefItem> items, boolean atRoot)
throws IOException {
- Logger.d("PrefsXmlStorage", "Currently writing into output");
for (PrefItem item : items) {
if (!atRoot) output.writeEntity("pref");