Skip to content

Commit

Permalink
fix merging and toggleVisibility
Browse files Browse the repository at this point in the history
  • Loading branch information
wizmer committed Jun 20, 2016
1 parent 27e4acd commit 7a25a98
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 53 deletions.
@@ -1,36 +1,32 @@
package com.matburt.mobileorg2.Gui.Outline;

import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;

import com.matburt.mobileorg2.OrgData.OrgContract;
import com.matburt.mobileorg2.OrgData.OrgFile;
import com.matburt.mobileorg2.OrgData.OrgProviderUtils;
import com.matburt.mobileorg2.OrgNodeListActivity;
import com.matburt.mobileorg2.R;
import com.matburt.mobileorg2.Synchronizers.JGitWrapper;
import com.matburt.mobileorg2.Synchronizers.SynchronizerManager;
import com.matburt.mobileorg2.util.OrgFileNotFoundException;
import com.matburt.mobileorg2.util.OrgUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class ConflictResolverActivity extends AppCompatActivity {

EditText editText;
String filename;
Long nodeId;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -48,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Create the detail fragment and add it to the activity
// using a fragment transaction.
Bundle arguments = new Bundle();
Long nodeId = getIntent().getLongExtra(OrgContract.NODE_ID, -1);
nodeId = getIntent().getLongExtra(OrgContract.NODE_ID, -1);

editText = (EditText)findViewById(R.id.conflict_resolver_text);
try {
Expand Down Expand Up @@ -84,7 +80,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.edit_menu_ok:
if(this.filename!=null && !this.filename.equals("")){
OrgUtils.writeToFile(this.filename, editText.getText().toString());
new JGitWrapper.MergeTask(this).execute();
new JGitWrapper.MergeTask(this, this.filename).execute();
OrgFile f = null;
try {
f = new OrgFile(nodeId, this.getContentResolver());
ContentValues values = new ContentValues();
values.put("comment", "");
f.updateFileInDB(this.getContentResolver(), values);
Log.v("conflict", "conflict resolved");
} catch (OrgFileNotFoundException e) {
e.printStackTrace();
}

}
NavUtils.navigateUpTo(this, new Intent(this, OrgNodeListActivity.class));
return true;
Expand Down
Expand Up @@ -90,8 +90,8 @@ private static void fillMap(TreeMap<Long, OrgNodeTree> map, OrgNodeTree tree, lo

if (tree.visibility == Visibility.folded) return;

// for(OrgNodeTree child: tree.children) fillMap(map, child);
for (OrgNodeTree child : tree.children) map.put(idConstructor++, child);
for (OrgNodeTree child : tree.children) fillMap(map, child, idConstructor);
// for (OrgNodeTree child : tree.children) map.put(idConstructor++, child);
}

public Visibility getVisibility(){
Expand All @@ -105,7 +105,10 @@ public Visibility getVisibility(){
public void toggleVisibility(){
if(visibility==Visibility.folded){
visibility = Visibility.children;
for(OrgNodeTree child: children) child.visibility = Visibility.folded;
for (OrgNodeTree child : children) {
Log.v("children", "child : " + child.node.name);
child.visibility = Visibility.folded;
}
} else if(visibility==Visibility.children){
visibility = Visibility.subtree;
for(OrgNodeTree child: children) child.cascadeVisibility(Visibility.subtree);
Expand Down
Expand Up @@ -285,11 +285,12 @@ public class SecondaryRecyclerViewAdapter
public SecondaryRecyclerViewAdapter(OrgNodeTree root) {
tree = root;
refreshVisibility();
items = tree.getVisibleNodesArray();
}

void refreshVisibility() {
items = tree.getVisibleNodesArray();
notifyDataSetChanged();

}

@Override
Expand All @@ -315,8 +316,8 @@ public void onClick(View v) {
return;
}

// item.mItem.toggleVisibility();
// refreshVisibility();
tree.toggleVisibility();
refreshVisibility();
}
});

Expand Down
Expand Up @@ -33,8 +33,6 @@
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Ref;
Expand All @@ -47,19 +45,15 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


public class JGitWrapper {

final static String CONFLICT_FILES = "conflict_files";
// The git dir inside the Context.getFilesDir() folder
public static String GIT_DIR = "git_dir";

final static String CONFLICT_FILES = "conflict_files";

public static void add(String filename, Context context) {
File repoDir = new File(context.getFilesDir() + "/" + GIT_DIR + "/.git");
try {
Expand Down Expand Up @@ -158,6 +152,28 @@ public static SyncResult pull(final Context context) {
return result;
}

private static void handleMergeConflict(Git git, Context context) {
Status status = null;

try {
status = git.status().call();
ContentResolver resolver = context.getContentResolver();
for (String file : status.getConflicting()) {
OrgFile f = new OrgFile(file, resolver);
ContentValues values = new ContentValues();
values.put("comment", "conflict");
f.updateFileInDB(resolver, values);
}

} catch (GitAPIException e1) {
e1.printStackTrace();
return;
} catch (OrgFileNotFoundException e) {
e.printStackTrace();
}


}

static public class CloneGitRepoTask extends AsyncTask<String, Void, Object> {
Context context;
Expand Down Expand Up @@ -308,9 +324,11 @@ protected Void doInBackground(String... params) {

static public class MergeTask extends AsyncTask<String, Void, Void> {
Context context;
String filename;

public MergeTask(Context context) {
public MergeTask(Context context, String filename) {
this.context = context;
this.filename = filename;
}

protected Void doInBackground(String... params) {
Expand All @@ -334,7 +352,7 @@ protected Void doInBackground(String... params) {
.call();

git.add()
.addFilepattern("google.org").call();
.addFilepattern(filename).call();

org.eclipse.jgit.api.Status status = git.status().call();
System.out.println("Added: " + status.getAdded());
Expand All @@ -345,11 +363,11 @@ protected Void doInBackground(String... params) {
System.out.println("Removed: " + status.getRemoved());
System.out.println("Untracked: " + status.getUntracked());

AuthData authData = AuthData.getInstance(context);
git.push()
.setCredentialsProvider(new CredentialsProviderAllowHost(authData.getUser(), authData.getPassword()))
.call();
System.out.println("Committed all changes to repository at ");
// AuthData authData = AuthData.getInstance(context);
// git.push()
// .setCredentialsProvider(new CredentialsProviderAllowHost(authData.getUser(), authData.getPassword()))
// .call();
// System.out.println("Committed all changes to repository at ");
} catch (IOException | UnmergedPathsException e) {
e.printStackTrace();
} catch (WrongRepositoryStateException e) {
Expand All @@ -372,27 +390,4 @@ static class UnableToPushException extends Exception {

}

private static void handleMergeConflict(Git git, Context context){
Status status = null;

try {
status = git.status().call();
ContentResolver resolver = context.getContentResolver();
for(String file: status.getConflicting()){
OrgFile f = new OrgFile(file, resolver);
ContentValues values = new ContentValues();
values.put("comment","conflict");
f.updateFileInDB(resolver, values);
}

} catch (GitAPIException e1) {
e1.printStackTrace();
return;
} catch (OrgFileNotFoundException e) {
e.printStackTrace();
}


}

}

0 comments on commit 7a25a98

Please sign in to comment.