Skip to content

Commit 726632a

Browse files
committed
some code cleanup.
1 parent b79071d commit 726632a

21 files changed

+135
-77
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The JitPack repository URL would be: `maven { url 'https://jitpack.io' }`
2929

3030
dependencies {
3131
// implementation "io.syslogic:androidx-github:master-SNAPSHOT"
32-
implementation "io.syslogic:androidx-github:1.1.8"
32+
implementation "io.syslogic:androidx-github:1.1.9"
3333
}
3434

3535
[![Release](https://jitpack.io/v/syslogic/androidx-github.svg)](https://jitpack.io/#io.syslogic/androidx-github)

build.gradle

+6-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ plugins {
55
alias(libs.plugins.androidx.navigation.safeargs) apply false
66
}
77

8-
/** Version Settings, loaded from file `version.properties` */
9-
def version = new Properties()
10-
version.load(new FileInputStream(rootProject.file('version.properties')))
11-
project.ext.set('versionCode', new Integer(version['versionCode']))
12-
project.ext.set('versionName', version['versionName'])
13-
148
/* JitPack: use tag as versionName. */
159
if (System.env.JITPACK) {
1610
project.ext.set('version_name', System.env.VERSION)
@@ -22,13 +16,15 @@ project.ext.set('archiveBuildTypes', ['debug', 'release'])
2216
/** Keystore Settings, loaded from keystore.properties */
2317
if (rootProject.file('keystore.properties').exists()) {
2418
def keystore = new Properties()
25-
keystore.load(new FileInputStream(rootProject.file('keystore.properties')))
19+
def ins = new FileInputStream(rootProject.file('keystore.properties'))
20+
keystore.load(ins)
2621
project.ext.set('debugKeystorePass', keystore['debugKeystorePass'])
2722
project.ext.set('debugKeyAlias', keystore['debugKeyAlias'])
2823
project.ext.set('debugKeyPass', keystore['debugKeyPass'])
2924
project.ext.set('releaseKeystorePass', keystore['releaseKeystorePass'])
3025
project.ext.set('releaseKeyAlias', keystore['releaseKeyAlias'])
3126
project.ext.set('releaseKeyPass', keystore['releaseKeyPass'])
27+
ins.close()
3228
}
3329

3430
/** Modules */
@@ -40,7 +36,9 @@ allprojects {
4036
def requested = details.requested
4137
if (requested.group == 'org.jetbrains.kotlin') {
4238
List<String> list = ['kotlin-stdlib', 'kotlin-stdlib-jdk7', 'kotlin-stdlib-jdk8', 'kotlin-stdlib-common']
43-
if (list.contains(requested.name)) { details.useVersion libs.versions.kotlin.get() }
39+
if (list.contains(requested.name)) {
40+
details.useVersion libs.versions.kotlin.get()
41+
}
4442
}
4543
}
4644
}

gradle/libs.versions.toml

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
[versions]
2-
android_gradle_plugin = '8.6.0'
2+
app_version_code = '4'
3+
app_version_name = '1.0.4'
4+
android_build_tools = '35.0.0'
5+
android_compile_sdk = '35'
6+
android_target_sdk = '35'
7+
android_min_sdk = '22'
8+
9+
# Gradle Plugins
10+
android_gradle_plugin = '8.7.0'
311
kotlin = '2.0.20'
412
material_design = '1.12.0'
513
retrofit = '2.11.0'
6-
gson = '2.10.1'
14+
gson = '2.11.0'
715
junit = '4.13.2'
816
flexbox = '3.0.0'
917
# Note: DirCacheCheckout.java uses InputStream.transferTo() since jgit 6.3; no such method on Android.
1018
jgit = '6.2.0.202206071550-r'
1119
slf4j = '2.0.13'
1220
androidx_appcompat = '1.7.0'
1321
androidx_annotation = '1.8.2'
14-
androidx_navigation = '2.8.0'
15-
androidx_fragment = '1.8.3'
22+
androidx_navigation = '2.8.2'
23+
androidx_fragment = '1.8.4'
1624
androidx_recyclerview = '1.3.2'
1725
androidx_cardview = '1.0.0'
1826
androidx_preference = '1.2.1'

library/build.gradle

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ plugins {
55
}
66

77
base {
8-
archivesName = 'androidx_github_' + rootProject.ext.get('versionName')
8+
String versionName = libs.versions.app.version.name.get()
9+
archivesName = "androidx_github_$versionName"
910
}
1011

1112
android {
1213
namespace 'io.syslogic.github.api'
13-
buildToolsVersion = '35.0.0'
14-
compileSdk 35
14+
buildToolsVersion = libs.versions.android.build.tools.get()
15+
compileSdk Integer.parseInt(libs.versions.android.compile.sdk.get())
1516
defaultConfig {
16-
minSdk 22
17-
targetSdk 35
17+
minSdk Integer.parseInt(libs.versions.android.min.sdk.get())
18+
targetSdk Integer.parseInt(libs.versions.android.target.sdk.get())
1819
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1920
consumerProguardFile "${project.rootDir}/proguard/consumer.pro"
2021
}
@@ -165,15 +166,15 @@ artifacts {
165166
}
166167

167168
group = 'io.syslogic'
168-
version = rootProject.ext.get('versionName')
169+
version = libs.versions.app.version.name.get()
169170

170171
afterEvaluate {
171172
publishing {
172173
publications {
173174
release(MavenPublication) {
174175
groupId = group
175176
artifactId = 'androidx-github'
176-
version = rootProject.ext.get('versionName')
177+
version = libs.versions.app.version.name.get()
177178
from components.getByName('release')
178179
pom {
179180
name = 'GitHub API Client'

mobile/build.gradle

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ if (rootProject.file('token.properties').exists()) {
1919
}
2020

2121
base {
22-
archivesName = 'github_client_' + rootProject.ext.get('versionName')
22+
String versionName = libs.versions.app.version.name.get()
23+
archivesName = "github_client_$versionName"
2324
}
2425

2526
android {
2627
namespace 'io.syslogic.github'
27-
buildToolsVersion = '35.0.0'
28-
compileSdk 35
28+
buildToolsVersion = libs.versions.android.build.tools.get()
29+
compileSdk Integer.parseInt(libs.versions.android.compile.sdk.get())
2930
defaultConfig {
30-
minSdk 22
31-
targetSdk 35
31+
minSdk Integer.parseInt(libs.versions.android.min.sdk.get())
32+
targetSdk Integer.parseInt(libs.versions.android.target.sdk.get())
33+
versionCode Integer.parseInt(libs.versions.app.version.code.get())
34+
versionName libs.versions.app.version.name.get()
3235
applicationId 'io.syslogic.github'
3336
//noinspection GroovyConstructorNamedArguments
3437
manifestPlaceholders = [ accessToken: "" ]
35-
versionName rootProject.ext.get('versionName')
36-
versionCode rootProject.ext.get('versionCode')
3738
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3839
testBuildType "debug"
3940
multiDexEnabled true

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

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public final class Constants {
2525
/** Deprecated SDK Constant */
2626
@NonNull public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
2727

28+
/** The default query-string default query-string is being used, when table `query_strings` is empty. */
29+
@NonNull public static final String DEFAULT_QUERY_STRING = "topic:android";
30+
2831
/** Table Names */
2932
@NonNull public static final String TABLE_QUERY_STRINGS = "query_strings";
3033

mobile/src/main/java/io/syslogic/github/content/RepositorySyncAdapter.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.accounts.Account;
44
import android.app.Activity;
5+
import android.app.Application;
56
import android.content.AbstractThreadedSyncAdapter;
67
import android.content.ContentProviderClient;
78
import android.content.Context;
@@ -45,7 +46,7 @@ public class RepositorySyncAdapter extends AbstractThreadedSyncAdapter {
4546

4647
private final SharedPreferences prefs;
4748

48-
private final String accessToken;
49+
private String accessToken = null;
4950

5051
private final String username;
5152

@@ -62,7 +63,12 @@ public RepositorySyncAdapter(@NonNull Context context, boolean autoInitialize, b
6263
super(context, autoInitialize, allowParallelSyncs);
6364
this.prefs = PreferenceManager.getDefaultSharedPreferences(context);
6465
this.dao = Abstraction.getInstance(context).repositoriesDao();
65-
this.accessToken = TokenHelper.getAccessToken((Activity) context);
66+
67+
if (context instanceof Activity activity) {
68+
this.accessToken = TokenHelper.getAccessToken(activity);
69+
} else if (context instanceof Application app) {
70+
this.accessToken = TokenHelper.getAccessToken(app.getBaseContext());
71+
}
6672
this.username = TokenHelper.getUsername(context);
6773
}
6874

mobile/src/main/java/io/syslogic/github/dialog/BaseDialogFragment.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99

1010
import androidx.annotation.NonNull;
1111
import androidx.annotation.Nullable;
12-
import androidx.core.content.ContextCompat;
1312
import androidx.databinding.ViewDataBinding;
1413
import androidx.fragment.app.DialogFragment;
1514
import androidx.preference.PreferenceManager;
1615

1716
import io.syslogic.github.BuildConfig;
18-
import io.syslogic.github.R;
1917

2018
/**
2119
* Base {@link DialogFragment}
@@ -61,8 +59,10 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
6159
this.dialog = new Dialog(this.requireContext());
6260
this.dialog.setCanceledOnTouchOutside(this.cancelOnTouchOutSide);
6361
if (this.dialog.getWindow() != null) {
64-
this.dialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
65-
this.dialog.getWindow().setNavigationBarColor(ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark));
62+
this.dialog.getWindow().setLayout(
63+
ViewGroup.LayoutParams.WRAP_CONTENT,
64+
ViewGroup.LayoutParams.WRAP_CONTENT
65+
);
6666
}
6767
return this.dialog;
6868
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
5656
}
5757
}
5858

59-
/* Navigating to RepositoriesFragment */
59+
/* Navigate to RepositoriesFragment */
6060
this.mDataBinding.buttonUserRepositories
6161
.setOnClickListener(view -> activity.getNavController()
62-
.navigate(R.id.action_homeScreenFragment_to_repositoriesGraph));
62+
.navigate(R.id.action_homeScreenFragment_to_repositoriesGraph));
6363

64-
/* Navigating to RepositorySearchFragment */
64+
/* Navigate to RepositorySearchFragment */
6565
this.mDataBinding.buttonRepositorySearch
6666
.setOnClickListener(view -> activity.getNavController()
6767
.navigate(R.id.action_homeScreenFragment_to_repositorySearchFragment));
6868

69-
/* Navigating to GitHub Sponsors */
69+
/* Navigate to GitHub Sponsors */
7070
this.mDataBinding.textGitHubSponsors
7171
.setOnClickListener(view -> activity.startActivity(
7272
new Intent(Intent.ACTION_VIEW, Uri.parse(activity.getString(R.string.url_git_hub_sponsors)))

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

+21-12
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,31 @@ public void onNothingSelected(AdapterView<?> parent) {}
107107
Abstraction.executorService.execute(() -> {
108108
try {
109109
assert dao != null;
110+
String queryString = null;
110111
List<QueryString> items = dao.getItems();
111-
if (items.size() > 0) {
112-
String queryString = items.get(0).toQueryString();
113-
requireActivity().runOnUiThread(() -> {
114-
RepositorySearchAdapter adapter = new RepositorySearchAdapter(requireContext(), queryString, showRepositoryTopics, 1);
115-
getDataBinding().recyclerviewRepositorySearch.setAdapter(adapter);
116-
PagerState pagerState = getDataBinding().getPagerState();
117-
if (pagerState != null) {
118-
pagerState.setQueryString(queryString);
119-
getDataBinding().setPagerState(pagerState);
120-
}
121-
});
112+
if (! items.isEmpty()) {
113+
queryString = items.get(0).toQueryString();
114+
122115
} else {
123-
if (mDebug) {Log.e(LOG_TAG, "table `query_strings` has no records.");}
124116
this.getDataBinding().toolbarRepositorySearch.spinnerQueryString.setVisibility(View.INVISIBLE);
117+
queryString = Constants.DEFAULT_QUERY_STRING;
118+
if (mDebug) {
119+
Log.w(LOG_TAG, "Table `query_strings` currently has no records.");
120+
Log.w(LOG_TAG, "Using thr default value: \"" + Constants.DEFAULT_QUERY_STRING + "\".");
121+
}
125122
}
123+
124+
String finalQueryString = queryString;
125+
requireActivity().runOnUiThread(() -> {
126+
RepositorySearchAdapter adapter = new RepositorySearchAdapter(requireContext(), finalQueryString, showRepositoryTopics, 1);
127+
getDataBinding().recyclerviewRepositorySearch.setAdapter(adapter);
128+
PagerState pagerState = getDataBinding().getPagerState();
129+
if (pagerState != null) {
130+
pagerState.setQueryString(finalQueryString);
131+
getDataBinding().setPagerState(pagerState);
132+
}
133+
});
134+
126135
} catch (IllegalStateException e) {
127136
if (mDebug) {Log.e(LOG_TAG, "" + e.getMessage());}
128137
}

mobile/src/main/java/io/syslogic/github/network/TokenHelper.java

+17-15
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,34 @@ public class TokenHelper {
4747
static final boolean mDebug = BuildConfig.DEBUG;
4848

4949
@Nullable
50-
public static String getAccessToken(@NonNull Activity activity) {
51-
AccountManager accountManager = AccountManager.get(activity);
50+
public static String getAccessToken(@NonNull Context context) {
51+
AccountManager accountManager = AccountManager.get(context);
5252
Account account = getAccount(accountManager, 0);
5353
if (account != null) {
5454
/* Default: Load the access token from AccountManager. */
5555
return accountManager.getUserData(account, "token");
5656
} else if (mDebug) {
5757
/* Debug: Try to load and validate the access token. */
58-
return loadTokenFromPackageMeta(activity, accountManager);
58+
return loadTokenFromPackageMeta(context, accountManager);
5959
} else {
6060
Log.e(LOG_TAG, "Account not found: " + Constants.ACCOUNT_TYPE);
6161
return null;
6262
}
6363
}
6464

65-
public static void setAccessToken(Activity activity, @Nullable String token) {
66-
AccountManager accountManager = AccountManager.get(activity);
65+
public static void setAccessToken(Context context, @Nullable String token) {
66+
AccountManager accountManager = AccountManager.get(context);
6767
Account account = getAccount(accountManager, 0);
6868
if (account != null && token == null) {
69-
accountManager.removeAccount(account, activity, accountManagerFuture -> {
70-
Log.d(LOG_TAG, "Account removed: " + Constants.ACCOUNT_TYPE);
71-
}, new Handler(Looper.getMainLooper()));
69+
if (context instanceof Activity activity) {
70+
accountManager.removeAccount(account, activity, accountManagerFuture -> {
71+
Log.d(LOG_TAG, "Account removed: " + Constants.ACCOUNT_TYPE);
72+
}, new Handler(Looper.getMainLooper()));
73+
}
7274
} else if (account == null && token == null) {
7375
/* This maybe happen when the token loaded from package-meta has expired. */
74-
Intent intent = new Intent(activity, AuthenticatorActivity.class);
75-
activity.startActivity(intent);
76+
Intent intent = new Intent(context, AuthenticatorActivity.class);
77+
context.startActivity(intent);
7678
}
7779
}
7880

@@ -91,16 +93,16 @@ public static String getUsername(@NonNull Context context) {
9193
}
9294

9395
@Nullable
94-
private static String loadTokenFromPackageMeta(@NonNull Activity activity, AccountManager accountManager) {
96+
private static String loadTokenFromPackageMeta(@NonNull Context context, AccountManager accountManager) {
9597
String token = null;
9698
try {
9799

98100
ApplicationInfo app;
99101
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
100102
PackageManager.ApplicationInfoFlags flags = PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA);
101-
app = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), flags);
103+
app = context.getPackageManager().getApplicationInfo(context.getPackageName(), flags);
102104
} else {
103-
app = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA);
105+
app = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
104106
}
105107

106108
if (mDebug && app.metaData.keySet().contains("com.github.ACCESS_TOKEN")) {
@@ -134,9 +136,9 @@ public void onResponse(@NonNull Call<User> call, @NonNull Response<User> respons
134136
if (message.equals("\"Bad credentials\"")) {
135137

136138
// Remove the token, it is invalid anyway.
137-
TokenHelper.setAccessToken(activity, null);
139+
TokenHelper.setAccessToken(context, null);
138140

139-
if (activity instanceof NavHostActivity activity2) {
141+
if (context instanceof NavHostActivity activity2) {
140142
if (activity2.getCurrentFragment() instanceof HomeScreenFragment) {
141143
activity2.getNavController().navigate(
142144
R.id.action_homeScreenFragment_to_preferencesFragment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:tint="#FFFFFF"
4+
android:viewportHeight="24"
5+
android:viewportWidth="24"
6+
android:height="48dp"
7+
android:width="48dp">
8+
9+
<path
10+
android:fillColor="@android:color/white"
11+
android:pathData="M21,7h-2v2h-2V7h-2V5h2V3h2v2h2V7zM19,21l-7,-3l-7,3V5c0,-1.1 0.9,-2 2,-2l7,0c-0.63,0.84 -1,1.87 -1,3c0,2.76 2.24,5 5,5c0.34,0 0.68,-0.03 1,-0.1V21z"/>
12+
13+
</vector>

mobile/src/main/res/drawable-night/ic_baseline_bookmarks_48.xml

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
<vector
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:tint="#FFFFFF"
5-
android:height="48dp"
6-
android:width="48dp"
75
android:viewportHeight="24"
8-
android:viewportWidth="24">
6+
android:viewportWidth="24"
7+
android:height="48dp"
8+
android:width="48dp">
9+
910
<path
1011
android:fillColor="@android:color/white"
1112
android:pathData="M19,18l2,1V3c0,-1.1 -0.9,-2 -2,-2H8.99C7.89,1 7,1.9 7,3h10c1.1,0 2,0.9 2,2v13zM15,5H5c-1.1,0 -2,0.9 -2,2v16l7,-3 7,3V7c0,-1.1 -0.9,-2 -2,-2z"/>
13+
1214
</vector>

0 commit comments

Comments
 (0)