diff --git a/android/app/src/main/java/com/example/journal/GitRmTask.java b/android/app/src/main/java/com/example/journal/GitRmTask.java new file mode 100644 index 00000000..71672dcc --- /dev/null +++ b/android/app/src/main/java/com/example/journal/GitRmTask.java @@ -0,0 +1,54 @@ +package com.example.journal; + +import android.os.AsyncTask; +import android.util.Log; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.RmCommand; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.TransportException; + +import java.io.File; + +import io.flutter.plugin.common.MethodChannel.Result; + +public class GitRmTask extends AsyncTask { + private final static String TAG = "GitRm"; + private Result result; + + public GitRmTask(Result _result) { + result = _result; + } + + protected Void doInBackground(String... params) { + final String cloneDirPath = params[0]; + final String filePattern = params[1]; + + File cloneDir = new File(cloneDirPath); + Log.d("GitClone Directory", cloneDirPath); + + try { + Git git = Git.open(cloneDir); + + RmCommand rmCommand = git.rm(); + rmCommand.addFilepattern(filePattern); + rmCommand.call(); + + } catch (TransportException e) { + Log.d(TAG, e.toString()); + result.error("FAILED", e.toString(), null); + return null; + } catch (GitAPIException e) { + Log.d(TAG, e.toString()); + result.error("FAILED", e.toString(), null); + return null; + } catch (Exception e) { + Log.d(TAG, e.toString()); + result.error("FAILED", e.toString(), null); + return null; + } + + result.success(null); + return null; + } +} diff --git a/android/app/src/main/java/com/example/journal/MainActivity.java b/android/app/src/main/java/com/example/journal/MainActivity.java index fc05bf3b..7a7d48c9 100644 --- a/android/app/src/main/java/com/example/journal/MainActivity.java +++ b/android/app/src/main/java/com/example/journal/MainActivity.java @@ -91,6 +91,19 @@ public class MainActivity extends FlutterActivity { new GitAddTask(result).execute(cloneLocation, filePattern); return; + } else if (call.method.equals("gitRm")) { + String folderName = call.argument("folderName"); + String filePattern = call.argument("filePattern"); + + if (folderName.isEmpty() || filePattern.isEmpty()) { + result.error("Invalid Parameters", "Arguments Invalid", null); + return; + } + + String cloneLocation = filesDir + "/" + folderName; + + new GitRmTask(result).execute(cloneLocation, filePattern); + return; } else if (call.method.equals("gitCommit")) { String folderName = call.argument("folderName"); String authorName = call.argument("authorName"); diff --git a/lib/storage/git.dart b/lib/storage/git.dart index 9a58de73..2c428714 100644 --- a/lib/storage/git.dart +++ b/lib/storage/git.dart @@ -61,6 +61,19 @@ Future gitAdd() async { } } +Future gitRm() async { + print("Going to git rm"); + try { + await _platform.invokeMethod('gitRm', { + 'folderName': "journal", + 'filePattern': "1", + }); + print("Done"); + } on PlatformException catch (e) { + print("gitRm Failed: '${e.message}'."); + } +} + Future gitPush() async { print("Going to git push"); try {