Skip to content

Commit 7f72dd1

Browse files
committed
Move the URL of the repo to be more accessible
1 parent 518052d commit 7f72dd1

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ Add the entirety of the package `selfupdate`.
5454

5555
In the onCreate of your activity, add this to check if there is an update at the start of the application :
5656
```java
57-
if (savedInstanceState == null) SelfUpdate.checkUpdate(this);
57+
if (savedInstanceState == null)
58+
SelfUpdate.checkUpdate(this, "https://api.github.com/repos/burgyl/SelfUpdatingApp/releases/latest");
5859
```
5960

60-
In the class `SelfUpdateHttpClient` adapt the URL on [this line](https://github.com/burgyl/SelfUpdatingApp/blob/53539ead515fd4475d9413be8d68f79773bcdb97/app/src/main/java/ch/lburgy/selfupdatingapp/selfupdate/SelfUpdateHttpClient.java#L30) to correspond to your repo and his owner.
61+
You have to adapt the above URL to match your repository.
6162

6263
### Resources
6364

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "ch.lburgy.selfupdatingapp"
99
minSdkVersion 21
1010
targetSdkVersion 29
11-
versionCode 11
12-
versionName "1.0.10"
11+
versionCode 12
12+
versionName "1.0.11"
1313

1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1515
}

app/src/main/java/ch/lburgy/selfupdatingapp/MainActivity.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ protected void onCreate(Bundle savedInstanceState) {
2121
versionName.setText(BuildConfig.VERSION_NAME);
2222

2323
// Check if an update is available at startup
24-
if (savedInstanceState == null) SelfUpdate.checkUpdate(this);
24+
if (savedInstanceState == null)
25+
SelfUpdate.checkUpdate(this, "https://api.github.com/repos/burgyl/SelfUpdatingApp/releases/latest");
2526
}
2627
}

app/src/main/java/ch/lburgy/selfupdatingapp/selfupdate/SelfUpdate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class SelfUpdate {
3434
private static AppCompatActivity activity;
3535
private static SelfUpdateHttpClient httpClient;
3636

37-
public static void checkUpdate(AppCompatActivity activity) {
37+
public static void checkUpdate(AppCompatActivity activity, final String url) {
3838
SelfUpdate.activity = activity;
3939
httpClient = new SelfUpdateHttpClient(activity);
4040

@@ -44,7 +44,7 @@ public static void checkUpdate(AppCompatActivity activity) {
4444
public void run() {
4545
Release release = null;
4646
try {
47-
release = httpClient.getLastRelease();
47+
release = httpClient.getLastRelease(url);
4848
} catch (Exception e) {
4949
e.printStackTrace();
5050
}

app/src/main/java/ch/lburgy/selfupdatingapp/selfupdate/SelfUpdateHttpClient.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
2828
public class SelfUpdateHttpClient {
2929

30-
private static final String URL_APP_REPO = "https://api.github.com/repos/burgyL/SelfUpdatingApp/releases/latest";
31-
3230
private OkHttpClient simpleOkHttpClient;
3331
private final Context context;
3432

@@ -37,8 +35,8 @@ public SelfUpdateHttpClient(Context context) {
3735
simpleOkHttpClient = new OkHttpClient();
3836
}
3937

40-
public Release getLastRelease() throws HttpException, IOException, NoInternetConnectionException {
41-
String body = get(URL_APP_REPO);
38+
public Release getLastRelease(String url) throws HttpException, IOException, NoInternetConnectionException {
39+
String body = get(url);
4240
Moshi moshi = new Moshi.Builder().build();
4341
JsonAdapter<Release> jsonAdapter = moshi.adapter(Release.class);
4442
return jsonAdapter.fromJson(body);

0 commit comments

Comments
 (0)