Skip to content

WIP - New feature: Upload traces directly to Github #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ apply plugin: 'kotlin-android-extensions'
android {

useLibrary 'org.apache.http.legacy'
compileSdkVersion 29
compileSdkVersion 29 //modify because case an error (before 29)
buildToolsVersion = '29.0.2'

defaultConfig {
applicationId "net.osmtracker"
minSdkVersion 16
targetSdkVersion 29
targetSdkVersion 29 //modify because case an error (before 29)
multiDexEnabled true

testApplicationId "net.osmtracker.test"
Expand Down Expand Up @@ -104,6 +104,10 @@ dependencies {
implementation 'com.github.AppIntro:AppIntro:6.0.0'
implementation 'com.google.android.material:material:1.1.0'

// Required for the GitHub REST API
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.google.code.gson:gson:2.8.6'


}

Expand Down
18 changes: 17 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/HighContrast"
android:requestLegacyExternalStorage="true">
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true" >

<uses-library
android:name="org.apache.http.legacy"
Expand Down Expand Up @@ -66,6 +67,21 @@
android:scheme="osmtracker" />
</intent-filter>
</activity>
<activity
android:name=".activity.GitHubUpload"
android:label="Github" />
<activity
android:name=".activity.GitHubConfig"
android:label="Github" />
<activity
android:name=".activity.GitHubNewRepo"
android:label="Github" />
<activity
android:name=".activity.GitHubNewFork"
android:label="Github" />
<activity
android:name=".activity.GitHubPullRequest"
android:label="Github" />
<activity
android:name=".activity.About"
android:label="@string/about" />
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/java/net/osmtracker/GitHubUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.osmtracker;

public class GitHubUser {

private int id;
private String username;
private String token;

public GitHubUser() {
setId(-1);
setUsername("");
setToken("");
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}
}
88 changes: 88 additions & 0 deletions app/src/main/java/net/osmtracker/activity/GitHubConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package net.osmtracker.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import net.osmtracker.R;
import net.osmtracker.db.DBGitHelper;
import net.osmtracker.db.DbGitHubUser;

public class GitHubConfig extends Activity {

private final static String GitHubToken_URL = "https://github.com/settings/tokens";

EditText editTextUserName, editTextUserToken;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.github_configuration_token);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

editTextUserName = findViewById(R.id.git_configuration_user_name);
editTextUserToken = findViewById(R.id.git_configuration_user_token);

final Button btnGitHub = (Button) findViewById(R.id.git_link_create_token_btn_ok);
btnGitHub.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(GitHubToken_URL));
startActivity(intent);
}
});

final Button btnSave = (Button) findViewById(R.id.git_save_credentials_btn_ok);
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

DBGitHelper dbGitHelper = new DBGitHelper( GitHubConfig.this);
SQLiteDatabase db = dbGitHelper.getWritableDatabase();

if(db == null){
Toast.makeText(GitHubConfig.this, "Error con la base de datos", Toast.LENGTH_SHORT).show();
}else {
//Toast.makeText(GitHubConfig.this, "Creado correctamente", Toast.LENGTH_SHORT).show();
}

DbGitHubUser dbGitHubUser = new DbGitHubUser(GitHubConfig.this);
long id = dbGitHubUser.insertUser(editTextUserName.getText().toString().trim(),editTextUserToken.getText().toString().trim());

if (id > 0){
Toast.makeText(GitHubConfig.this, "Guardado correctamente", Toast.LENGTH_SHORT).show();
//Intent i = new Intent(GitHubConfig.this, GitHubUpload.class);
//startActivity(i);
finish();
}else {
Toast.makeText(GitHubConfig.this, "Error al guardar", Toast.LENGTH_SHORT).show();
}

}
});

final Button btnCancel = (Button) findViewById(R.id.git_back_credentials_btn_cancel);
btnCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

finish();
}
});



// Do not show soft keyboard by default
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
}
140 changes: 140 additions & 0 deletions app/src/main/java/net/osmtracker/activity/GitHubNewFork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package net.osmtracker.activity;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

import net.osmtracker.GitHubUser;
import net.osmtracker.R;
import net.osmtracker.db.DbGitHubUser;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class GitHubNewFork extends Activity {

EditText editTextRootUsername, editTextRootRepo;
private String BaseURL = "https://api.github.com";
GitHubUser gitHubUser;
private String newForkFullName;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.git_create_fork);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

DbGitHubUser dbGitHubUser = new DbGitHubUser(GitHubNewFork.this);
gitHubUser = dbGitHubUser.getUser();

editTextRootUsername = findViewById(R.id.git_username_to_fork_editText_user);
editTextRootRepo = findViewById(R.id.git_repo_to_fork_editText_name);

editTextRootUsername.setHint("Usuario raíz del repositorio");
editTextRootRepo.setHint("Nombre del repositorio raíz");
//editTextRootUsername.setText("Usuario raíz del repositorio");
//editTextRootRepo.setText("Nombre del repositorio raíz");

final Button btnCreate = (Button) findViewById(R.id.git_create_newfork_btn_ok);
btnCreate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
createNewFork();
//Toast.makeText(GitHubNewFork.this, "Creado correctamente", Toast.LENGTH_SHORT).show();
finish();

}
});


final Button btnCancel = (Button) findViewById(R.id.git_back_newfork_btn_cancel);
btnCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

finish();
}
});

// Do not show soft keyboard by default
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}

private void createNewFork() {
//ArrayListRepos.removeAll(ArrayListRepos);
String fullURL = getBaseURL() + "/repos/"+ editTextRootUsername.getText().toString().trim() +"/"+ editTextRootRepo.getText().toString().trim() +"/forks?name=fork";

JsonObjectRequest postResquest= new JsonObjectRequest(
Request.Method.POST,
fullURL,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
System.out.println("=========================" + response.getString("full_name"));
setNewForkFullName(response.getString("full_name"));
Toast.makeText(GitHubNewFork.this, "Creado correctamente", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
System.out.println("=========================Error");
Toast.makeText(GitHubNewFork.this, "Error al crear", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
}){
@Override
public Map getHeaders() throws AuthFailureError
{
HashMap headers = new HashMap();
headers.put("Authorization", "Bearer " + gitHubUser.getToken());
//headers.put("Accept", "*/*");
//headers.put("Accept-Encoding", "gzip, deflate, br");
//headers.put("Connection", "keep-alive");
return headers;
}

};
Volley.newRequestQueue(this).add(postResquest);

//return ArrayListRepos;
}

public String getBaseURL() {
return BaseURL;
}

public void setBaseURL(String baseURL) {
BaseURL = baseURL;
}

public String getNewForkFullName() {
return newForkFullName;
}

public void setNewForkFullName(String newForkFullName) {
this.newForkFullName = newForkFullName;
}
}
Loading