Browse Source

Closes #13 Add a sync button on main menu

isundil 7 years ago
parent
commit
08a065fc53

+ 16 - 10
app/src/main/java/info/knacki/pass/ui/GitPullActivity.java

@@ -93,11 +93,18 @@ public class GitPullActivity extends AppCompatActivity {
                             pg.setProgress(1);
                             TextView logView = findViewById(R.id.logView);
                             logView.append(msg +"\n");
+                            findViewById(R.id.close_bt).setEnabled(true);
                         }
                     });
                 }
             });
         }
+        findViewById(R.id.close_bt).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                GitPullActivity.this.finish();
+            }
+        });
     }
 
     public static String LOCALGIT_HASH_VERSION_FILE;
@@ -211,13 +218,6 @@ public class GitPullActivity extends AppCompatActivity {
     }
 
     void SyncFiles(final GitLocal localVersion, final HashMap<String, GitObject.GitBlob> filesToPull, final Set<String> filesToPush) {
-        log.severe("Sync : ");
-        for (String i: filesToPush)
-            log.severe("PUSH > " +i);
-        for (String i: filesToPull.keySet())
-            log.severe("PULL > " +i);
-        log.severe("End listing files");
-        //*
         final GitInterface.OnStreamResponseListener<Void> allDone = new GitInterface.OnStreamResponseListener<Void>() {
             @Override
             public void onResponse(Void result) {
@@ -230,6 +230,7 @@ public class GitPullActivity extends AppCompatActivity {
                         pg.setProgress(1);
                         localVersion.Write(new File(LOCALGIT_HASH_VERSION_FILE));
                         RmEmptyDirs(new File(PathUtils.GetPassDir(GitPullActivity.this)), true);
+                        findViewById(R.id.close_bt).setEnabled(true);
                     }
                 });
             }
@@ -243,6 +244,7 @@ public class GitPullActivity extends AppCompatActivity {
                         pg.setIndeterminate(false);
                         pg.setMax(1);
                         pg.setProgress(1);
+                        findViewById(R.id.close_bt).setEnabled(true);
                     }
                 });
             }
@@ -256,16 +258,21 @@ public class GitPullActivity extends AppCompatActivity {
         final Runnable afterFetching = new Runnable() {
             @Override
             public void run() {
-                if (filesToPush.size() > 0)
+                if (filesToPush.size() > 0) {
+                    GitPullActivity.this.onMsg("Updating remote repository");
                     PushBlobs(filesToPush, localVersion, allDone);
-                else
+                } else {
+                    GitPullActivity.this.onMsg("Nothing to push");
                     allDone.onResponse(null);
+                }
             }
         };
 
         if (filesToPull.isEmpty()) {
+            onMsg("Nothing to pull");
             afterFetching.run();
         } else {
+            onMsg("Updating local repository");
             DownloadBlobs(filesToPull, localVersion, new GitInterface.OnResponseListener<Void>() {
                 @Override
                 public void onResponse(Void result) {
@@ -278,7 +285,6 @@ public class GitPullActivity extends AppCompatActivity {
                 }
             });
         }
-        //*/
     }
 
     void DownloadBlobs(Map<String, GitObject.GitBlob> blobs, final GitLocal localVersion, final GitInterface.OnResponseListener<Void> resp) {

+ 7 - 0
app/src/main/java/info/knacki/pass/ui/MainActivity.java

@@ -149,6 +149,9 @@ public class MainActivity extends AppCompatActivity implements PasswordEditListe
         switch (item.getItemId()) {
             case 0:
                 break;
+            case R.id.id_sync:
+                startActivity(new Intent(this, GitPullActivity.class));
+                break;
             case R.id.new_folder:
                 CreateNewFolder();
                 break;
@@ -168,6 +171,10 @@ public class MainActivity extends AppCompatActivity implements PasswordEditListe
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         getMenuInflater().inflate(R.menu.main_menu, menu);
+        if (SettingsManager.GetVCS(this) == null) {
+            // Disable sync option
+            menu.removeItem(R.id.id_sync);
+        }
         return super.onCreateOptionsMenu(menu);
     }
 

+ 19 - 1
app/src/main/res/layout/activity_git_pull.xml

@@ -11,13 +11,31 @@
         android:indeterminate="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" />
+
     <ScrollView
         android:layout_width="match_parent"
-        android:layout_height="match_parent">
+        android:layout_height="match_parent"
+        android:layout_weight="1">
+
         <android.support.v7.widget.AppCompatTextView
             android:id="@+id/logView"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:inputType="textMultiLine" />
     </ScrollView>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical"
+        android:layout_weight="0">
+
+        <android.support.v7.widget.AppCompatButton
+            android:id="@+id/close_bt"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:enabled="false"
+            android:text="@string/close" />
+    </LinearLayout>
+
 </LinearLayout>

+ 4 - 0
app/src/main/res/menu/main_menu.xml

@@ -1,5 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:icon="@drawable/ic_sync"
+        android:id="@+id/id_sync"
+        android:title="@string/sync" />
     <item android:title="@string/New">
         <menu>
             <item android:id="@+id/new_folder" android:title="@string/newFolder"/>

+ 2 - 0
app/src/main/res/values-fr/lang.xml

@@ -80,4 +80,6 @@
     <string name="no">Non</string>
     <string name="unprotected_key">Cette clé n\'est pas protégée par un mot de passe, Voulez-vous continuer ?</string>
     <string name="pref_header_gpg_export">Export GPG key</string>
+    <string name="sync">Synchroniser</string>
+    <string name="close">Fermer</string>
 </resources>

+ 2 - 0
app/src/main/res/values/lang.xml

@@ -80,4 +80,6 @@
     <string name="no">No</string>
     <string name="unprotected_key">This key is not protected with a password, do you want to continue ?</string>
     <string name="pref_header_gpg_export">Export GPG key</string>
+    <string name="sync">Synchronize</string>
+    <string name="close">Close</string>
 </resources>