Skip to content
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

Upload traces directly to Github. Corrections to PR361 #460

Draft
wants to merge 35 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1e07965
first look
JeanMarcoRU Sep 14, 2022
303e4da
add label in spanish
JeanMarcoRU Sep 25, 2022
a20695c
create github activity
JeanMarcoRU Sep 26, 2022
bdcd2d7
before repo spiner
JeanMarcoRU Sep 26, 2022
752a0ba
upload view activity done
JeanMarcoRU Sep 26, 2022
d4071bd
Required for the GitHub REST API
JeanMarcoRU Sep 26, 2022
aad1eb3
Navigation between activitys
JeanMarcoRU Sep 26, 2022
feaa0ed
get list of repos from rest api
JeanMarcoRU Sep 27, 2022
10fd4f1
save git credentials
JeanMarcoRU Sep 28, 2022
e850264
settings on upload github activity
JeanMarcoRU Sep 28, 2022
b4ccf40
create new fork activity
JeanMarcoRU Sep 28, 2022
24eca50
create new fork ready
JeanMarcoRU Sep 28, 2022
cd898f8
create new repo done
JeanMarcoRU Sep 28, 2022
d4da84d
Update GitHubConfig.java
JeanMarcoRU Sep 29, 2022
18558ef
send gpx in base64 encode
JeanMarcoRU Sep 29, 2022
639c06b
commit done!!!
JeanMarcoRU Sep 29, 2022
f00cbdb
create pull request done
JeanMarcoRU Sep 30, 2022
71e04a1
Update GitHubUpload.java
JeanMarcoRU Oct 10, 2022
818057a
delete usless code
JeanMarcoRU Oct 11, 2022
12c6b0f
Gradle update
miltonials Oct 21, 2024
90908aa
Target SDK update from 33 to 35
miltonials Oct 21, 2024
e823c06
Explicit execution of buttons presets window
miltonials Oct 21, 2024
23b005e
Fix: Enabled UI buttons for marking waypoint features after accurate …
miltonials Oct 23, 2024
ae8490a
Add distributionSha256Sum for integrity verification in Gradle wrapper
miltonials Oct 29, 2024
ce9ca31
Fixed: SDK version and a new switch conflicts
miltonials Oct 31, 2024
d8da992
Refactor: Avoid TransactionTooLargeException by passing GPX Base64 as…
miltonials Oct 31, 2024
82b112f
small fix
FR3DD221 Nov 8, 2024
d3671fa
Merge branch 'develop' into develop
Binnette Nov 19, 2024
b113cb0
Merge branch 'develop' into pr-361
miltonials Nov 20, 2024
d5f23c8
Merge remote-tracking branch 'upstream/develop' into pr-361-trace-to-gh
miltonials Nov 21, 2024
aed6fa4
Merge remote-tracking branch 'upstream/develop' into pr-361-trace-to-gh
miltonials Nov 24, 2024
8da7449
Fix: replaced hardcoded strings with references to values/strings.xml…
miltonials Nov 25, 2024
9f555ee
Feat: added Spanish support in values-es/strings.xml for 'Upload to G…
miltonials Nov 25, 2024
aad41c2
Merge remote-tracking branch 'upstream/develop' into pr-361-trace-to-gh
miltonials Nov 25, 2024
d9bf375
Elimination of unnecessary commented code and minor correction of @st…
miltonials Nov 25, 2024
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ dependencies {
// For upload traces to osm server
implementation 'net.openid:appauth:0.11.1'
implementation 'de.westnordost:osmapi-traces:3.1'
implementation 'com.android.volley:volley:1.2.1'

// Required for local unit tests (JUnit 4 framework)
testImplementation 'junit:junit:4.12'
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 @@ -24,7 +24,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 @@ -72,6 +73,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;
}
}
82 changes: 82 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,82 @@
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, R.string.db_error, 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, R.string.successfully_saved, Toast.LENGTH_SHORT).show();
finish();
}else {
Toast.makeText(GitHubConfig.this, R.string.saving_error, 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);
}
}
130 changes: 130 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,130 @@
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");

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, R.string.successfully_created, 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() {
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 {
setNewForkFullName(response.getString("full_name"));
Toast.makeText(GitHubNewFork.this, R.string.successfully_created, Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
Toast.makeText(GitHubNewFork.this, R.string.error_creating, 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());
return headers;
}

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

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