Skip to content

Commit 7947131

Browse files
committed
jgit 6.2.0 still works on Android.
1 parent c3bd20a commit 7947131

18 files changed

+290
-78
lines changed

build.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
// root build.gradle
22
buildscript {
33
ext {
4-
agp_version = '7.4.2'
4+
agp_version = '8.0.1'
55
nav_version = '2.5.3'
6-
fragment_version = '1.5.6'
6+
fragment_version = '1.5.7'
77
room_version = '2.5.1'
88
annotation_version = '1.6.0'
9-
material_version = '1.8.0'
9+
material_version = '1.9.0'
1010
flexbox_version = '3.0.0'
1111
appcompat_version = '1.6.1'
12-
splash_version = '1.0.0'
12+
splash_version = '1.0.1'
1313
recyclerview_version = '1.3.0'
1414
preference_version = '1.2.0'
1515
cardview_version = '1.0.0'
1616
retrofit_version = '2.9.0'
1717
gson_version = '2.10.1'
18+
// DirCacheCheckout.java uses InputStream.transferTo() since 6.3; no such method on Android.
19+
jgit_version = '6.2.0.202206071550-r' // instead of 6.5.0.202303070854-r
20+
slf4j_version = '2.0.7'
1821
junit_version = '4.13.2'
1922
uiautomator_version = '2.2.0'
2023
espresso_version = '3.5.1'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Oct 15 19:41:28 CEST 2020
1+
#Mon May 15 03:22:49 CEST 2023
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip

mobile/build.gradle

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ android {
1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2020
testBuildType "debug"
2121
multiDexEnabled true
22-
compileOptions {
23-
sourceCompatibility JavaVersion.VERSION_11
24-
targetCompatibility JavaVersion.VERSION_11
25-
}
22+
2623
javaCompileOptions {
2724
annotationProcessorOptions {
2825
arguments = ["room.schemaLocation": "$rootDir/schema".toString()]
2926
}
3027
}
3128
}
3229

30+
compileOptions {
31+
sourceCompatibility JavaVersion.VERSION_17
32+
targetCompatibility JavaVersion.VERSION_17
33+
}
34+
3335
sourceSets {
3436
main {
3537
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
@@ -41,7 +43,8 @@ android {
4143
}
4244

4345
buildFeatures {
44-
dataBinding = true
46+
buildConfig true
47+
dataBinding true
4548
}
4649

4750
signingConfigs {
@@ -53,14 +56,6 @@ android {
5356
}
5457
}
5558

56-
lint {
57-
lintConfig rootProject.file('lint.xml')
58-
checkAllWarnings true
59-
warningsAsErrors true
60-
abortOnError false
61-
showAll false
62-
}
63-
6459
buildTypes {
6560
debug {
6661
applicationIdSuffix ".debug"
@@ -92,6 +87,14 @@ android {
9287
debuggable false
9388
}
9489
}
90+
91+
lint {
92+
lintConfig rootProject.file('lint.xml')
93+
checkAllWarnings true
94+
warningsAsErrors true
95+
abortOnError false
96+
showAll false
97+
}
9598
}
9699

97100
dependencies {
@@ -132,6 +135,13 @@ dependencies {
132135
exclude group: "com.google.code.gson", module: "gson"
133136
}
134137

138+
// https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit
139+
implementation "org.eclipse.jgit:org.eclipse.jgit:$jgit_version"
140+
141+
// https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
142+
// api "org.slf4j:slf4j-nop:$slf4j_version"
143+
api "org.slf4j:slf4j-simple:$slf4j_version"
144+
135145
// jUnit
136146
testImplementation "junit:junit:$junit_version"
137147

mobile/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
1111
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
1212

13+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
14+
tools:ignore="ScopedStorage"
15+
android:maxSdkVersion="32"/>
16+
1317
<!-- Permissions: Lollipop MR1 -->
1418
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" android:maxSdkVersion="22"/>
1519
<uses-permission android:name="android.permission.USE_CREDENTIALS" android:maxSdkVersion="22"/>

mobile/src/main/java/io/syslogic/github/Constants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public final class Constants {
2929
@NonNull public static final Integer RECYCLERVIEW_DEFAULT_PAGE_SIZE = 30;
3030

3131
/** Preference Keys */
32-
@NonNull public static final String PREFERENCE_KEY_ACCOUNT_SETTINGS = "account_settings";
32+
@NonNull public static final String PREFERENCE_KEY_PERSONAL_ACCESS_TOKEN = "personal_access_token";
33+
@NonNull public static final String PREFERENCE_KEY_WORKSPACE_DIRECTORY = "workspace_directory";
34+
3335
@NonNull public static final String PREFERENCE_KEY_SHOW_REPOSITORY_TOPICS = "show_repository_topics";
3436
@NonNull public static final String PREFERENCE_KEY_DEBUG_LOGGING = "debug_logging";
3537

mobile/src/main/java/io/syslogic/github/adapter/BaseArrayAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import androidx.annotation.Nullable;
1313
import androidx.appcompat.widget.AppCompatTextView;
1414

15-
import io.syslogic.github.R;
1615
import io.syslogic.github.model.SpinnerItem;
1716

1817
import java.util.ArrayList;
@@ -53,7 +52,7 @@ public long getItemId(int position) {
5352
@Override
5453
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
5554
if (convertView == null) {
56-
convertView = this.layoutInflater.inflate(R.layout.support_simple_spinner_dropdown_item, parent, false);
55+
convertView = this.layoutInflater.inflate(com.google.android.material.R.layout.support_simple_spinner_dropdown_item, parent, false);
5756
}
5857
convertView.setTag(this.mItems.get(position));
5958
AppCompatTextView textView = convertView.findViewById(android.R.id.text1);
@@ -72,6 +71,7 @@ void setItems(@NonNull Context context, @NonNull @ArrayRes Integer arrayKeys, @N
7271
}
7372
}
7473

74+
@SuppressWarnings("unused")
7575
void setItems(List<SpinnerItem> items) {
7676
this.clearItems();
7777
this.mItems.addAll(items);

mobile/src/main/java/io/syslogic/github/fragment/BaseFragment.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
164164
abstract protected void setDataBinding(@NonNull ViewDataBinding binding);
165165

166166
@Nullable
167-
protected String getAccessToken(@NonNull Context context) {
168-
return TokenHelper.getAccessToken(context);
167+
protected String getPersonalAccessToken() {
168+
return TokenHelper.getAccessToken(requireContext());
169169
}
170170

171171
@Nullable
@@ -187,8 +187,7 @@ protected void setUser(@NonNull String accessToken, @Nullable final TokenCallbac
187187
@Override
188188
public void onResponse(@NonNull Call<User> call, @NonNull Response<User> response) {
189189
switch (response.code()) {
190-
191-
case 200: {
190+
case 200 -> {
192191
if (response.body() != null) {
193192
User item = response.body();
194193
if (mDebug) {
@@ -201,10 +200,8 @@ public void onResponse(@NonNull Call<User> call, @NonNull Response<User> respons
201200
}
202201
setCurrentUser(item);
203202
}
204-
break;
205203
}
206-
207-
case 403: {
204+
case 403 -> {
208205
if (response.errorBody() != null) {
209206
try {
210207
String errors = response.errorBody().string();
@@ -220,7 +217,6 @@ public void onResponse(@NonNull Call<User> call, @NonNull Response<User> respons
220217
}
221218
}
222219
}
223-
break;
224220
}
225221
}
226222
}

mobile/src/main/java/io/syslogic/github/fragment/PreferencesFragment.java

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
package io.syslogic.github.fragment;
22

3+
import android.Manifest;
4+
import android.app.Activity;
35
import android.content.ActivityNotFoundException;
46
import android.content.Context;
57
import android.content.Intent;
68
import android.content.SharedPreferences;
9+
import android.content.pm.PackageManager;
10+
import android.net.Uri;
711
import android.os.Build;
812
import android.os.Bundle;
13+
import android.os.Environment;
14+
import android.provider.DocumentsContract;
915
import android.provider.Settings;
1016
import android.util.Log;
1117

18+
import androidx.activity.result.ActivityResultLauncher;
19+
import androidx.activity.result.contract.ActivityResultContracts;
1220
import androidx.annotation.NonNull;
1321
import androidx.annotation.Nullable;
22+
import androidx.core.content.ContextCompat;
1423
import androidx.preference.Preference;
1524
import androidx.preference.PreferenceFragmentCompat;
1625
import androidx.preference.PreferenceManager;
1726
import androidx.preference.PreferenceScreen;
1827

28+
import java.io.File;
29+
1930
import io.syslogic.github.BuildConfig;
2031
import io.syslogic.github.Constants;
32+
2133
import io.syslogic.github.R;
2234
import io.syslogic.github.network.TokenHelper;
2335

@@ -63,7 +75,9 @@ public void onAttach(@NonNull Context context) {
6375
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
6476

6577
this.setPreferencesFromResource(resId, rootKey);
66-
Preference pref = this.findPreference(Constants.PREFERENCE_KEY_ACCOUNT_SETTINGS);
78+
79+
/* Preference: Account Manager */
80+
Preference pref = this.findPreference(Constants.PREFERENCE_KEY_PERSONAL_ACCESS_TOKEN);
6781
if (pref != null) {
6882

6983
String accessToken = TokenHelper.getAccessToken(requireContext());
@@ -90,6 +104,38 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable S
90104
}
91105
});
92106
}
107+
108+
/* Preference: Workspace Directory */
109+
Preference pref2 = this.findPreference(Constants.PREFERENCE_KEY_WORKSPACE_DIRECTORY);
110+
if (pref2 != null) {
111+
if (pref2.getSummary() == null) {
112+
assert this.prefs != null;
113+
String directory = this.prefs.getString(Constants.PREFERENCE_KEY_WORKSPACE_DIRECTORY, Environment.getExternalStorageDirectory() + "/Workspace");
114+
File defaultDir = new File(directory);
115+
if (! defaultDir.exists()) {
116+
if (! defaultDir.mkdir()) {
117+
118+
/* Try internal storage instead */
119+
Log.w(LOG_TAG, "workspace not created: " + defaultDir.getAbsolutePath());
120+
defaultDir = new File(requireContext().getExternalFilesDir(null).toURI());
121+
Log.d(LOG_TAG, "workspace using internal storage: " + defaultDir.getAbsolutePath());
122+
}
123+
}
124+
if (! directory.equals(defaultDir.getAbsolutePath())) {
125+
this.prefs.edit().putString(Constants.PREFERENCE_KEY_WORKSPACE_DIRECTORY, defaultDir.getAbsolutePath()).apply();
126+
}
127+
pref2.setSummary(defaultDir.getAbsolutePath());
128+
}
129+
130+
pref2.setOnPreferenceClickListener(preference -> {
131+
if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
132+
// chooseDirectory();
133+
} else {
134+
requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE);
135+
}
136+
return true;
137+
});
138+
}
93139
}
94140

95141
/**
@@ -112,4 +158,39 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable S
112158
public void onSharedPreferenceChanged(@NonNull SharedPreferences preferences, @NonNull String key) {
113159
if (mDebug) {Log.d(LOG_TAG, "onSharedPreferenceChanged " + key);}
114160
}
161+
162+
private void chooseDirectory() {
163+
164+
String defaultDir = Environment.getExternalStorageDirectory() + "/Workspace/";
165+
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
166+
intent.addCategory(Intent.CATEGORY_OPENABLE);
167+
Uri uri = Uri.parse(defaultDir);
168+
intent.setDataAndType(uri, DocumentsContract.Document.MIME_TYPE_DIR);
169+
try {
170+
requestFileChooserResult.launch(intent);
171+
} catch (ActivityNotFoundException e) {
172+
Log.e(LOG_TAG, e.getMessage());
173+
}
174+
}
175+
176+
/** Register the permissions callback. */
177+
final ActivityResultLauncher<String> requestPermissionLauncher =
178+
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
179+
if (isGranted) {
180+
// chooseDirectory();
181+
}
182+
});
183+
184+
/** Register the file-chooser callback. */
185+
final ActivityResultLauncher<Intent> requestFileChooserResult =
186+
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
187+
if (result.getResultCode() == Activity.RESULT_OK) {
188+
// There are no request codes
189+
Intent data = result.getData();
190+
191+
} else if(result.getResultCode() == Activity.RESULT_CANCELED) {
192+
193+
}
194+
});
195+
115196
}

mobile/src/main/java/io/syslogic/github/fragment/ProfileFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void onPageCommitVisible (WebView view, String url) {
7171
}
7272
});
7373

74-
String token = this.getAccessToken(this.getContext());
74+
String token = this.getPersonalAccessToken();
7575
if (getCurrentUser() == null && token != null) {
7676
this.setUser(token, this);
7777
}

mobile/src/main/java/io/syslogic/github/fragment/RepositoriesFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void onNetworkAvailable() {
147147

148148
super.onNetworkAvailable();
149149

150-
String token = this.getAccessToken(requireContext());
150+
String token = this.getPersonalAccessToken();
151151
if (getCurrentUser() == null && token != null) {
152152
this.setUser(token, this);
153153
}

0 commit comments

Comments
 (0)