This repository has been archived by the owner on May 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notification on new release and/or commit to github
- Loading branch information
Showing
7 changed files
with
206 additions
and
11 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
app/src/main/java/com/claha/showtimeremote/GitHubHTTP.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.claha.showtimeremote; | ||
|
||
import android.os.AsyncTask; | ||
import android.util.Log; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GitHubHTTP { | ||
|
||
private static final String URL_GITHUB = "https://github.com/claha/showtimeremote"; | ||
|
||
public void run() { | ||
new Download().execute(); | ||
} | ||
|
||
public interface OnCommitsCountedListener { | ||
public void onCounted(int count); | ||
} | ||
|
||
private OnCommitsCountedListener onCommitsCountedListener; | ||
|
||
public void setOnCommitsCountedListener(OnCommitsCountedListener onCommitsCountedListener) { | ||
this.onCommitsCountedListener = onCommitsCountedListener; | ||
} | ||
|
||
public interface OnReleasesCountedListener { | ||
public void onCounted(int count); | ||
} | ||
|
||
private OnReleasesCountedListener onReleasesCountedListener; | ||
|
||
public void setOnReleasesCountedListener(OnReleasesCountedListener onReleasesCountedListener) { | ||
this.onReleasesCountedListener = onReleasesCountedListener; | ||
} | ||
|
||
private class Download extends AsyncTask { | ||
|
||
private List<String> html; | ||
|
||
@Override | ||
protected Object doInBackground(Object[] params) { | ||
try { | ||
URL url = new URL(URL_GITHUB); | ||
URLConnection connection = url.openConnection(); | ||
InputStream in = connection.getInputStream(); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); | ||
html = new ArrayList<>(); | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
html.add(line); | ||
} | ||
reader.close(); | ||
} catch (Exception e) { | ||
Log.d("GitHubHTTP", "ERROR"); | ||
e.printStackTrace(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(Object o) { | ||
boolean foundCommits = false; | ||
boolean foundReleases = false; | ||
int commits = -1; | ||
int releases = -1; | ||
int i = 0; | ||
while (!(foundCommits && foundReleases)) { | ||
if (!foundCommits) { | ||
if (html.get(i).contains("/commits") && html.get(i).contains("data-pjax")) { | ||
Log.d("GitHubHTTP", html.get(i)); | ||
commits = Integer.parseInt(html.get(i + 3).replace(" ", "")); | ||
foundCommits = true; | ||
} | ||
} else if (!foundReleases) { | ||
if (html.get(i).contains("/releases")) { | ||
Log.d("GitHubHTTP", html.get(i)); | ||
releases = Integer.parseInt(html.get(i + 3).replace(" ", "")); | ||
foundReleases = true; | ||
} | ||
} | ||
i++; | ||
} | ||
onCommitsCountedListener.onCounted(commits); | ||
onReleasesCountedListener.onCounted(releases); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/claha/showtimeremote/ShowtimeNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.claha.showtimeremote; | ||
|
||
import android.app.NotificationManager; | ||
import android.app.PendingIntent; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.support.v4.app.NotificationCompat; | ||
|
||
public class ShowtimeNotification extends NotificationCompat.Builder { | ||
|
||
private final Context context; | ||
private final NotificationManager notificationManager; | ||
private final String message; | ||
private String url = null; | ||
|
||
public ShowtimeNotification(Context context, String message) { | ||
super(context); | ||
this.context = context; | ||
this.message = message; | ||
|
||
notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
|
||
setSmallIcon(R.drawable.ic_launcher); | ||
setContentTitle("Showtime Remote"); | ||
setContentText(message); | ||
setAutoCancel(true); | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
|
||
public void show() { | ||
if (url != null) { | ||
Intent resultIntent = new Intent(Intent.ACTION_VIEW); | ||
resultIntent.setData(Uri.parse(url)); | ||
|
||
PendingIntent pending = PendingIntent.getActivity(context, 0, resultIntent, 0); | ||
setContentIntent(pending); | ||
} | ||
notificationManager.notify(message.hashCode(), build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters