mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
Added HTTPS request to get version data. Added APK flaor for github and fdroid.
This commit is contained in:
parent
2a45a13f73
commit
75a44fb30a
@ -14,12 +14,14 @@ android {
|
|||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled true
|
minifyEnabled true
|
||||||
shrinkResources true
|
shrinkResources true
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
|
|
||||||
debug {
|
debug {
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
|
|
||||||
@ -34,10 +36,25 @@ android {
|
|||||||
// but continue the build even when errors are found:
|
// but continue the build even when errors are found:
|
||||||
abortOnError false
|
abortOnError false
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flavorDimensions "apkSource"
|
||||||
|
productFlavors {
|
||||||
|
github {
|
||||||
|
dimension "apkSource"
|
||||||
|
applicationIdSuffix ".github"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fdroid {
|
||||||
|
dimension "apkSource"
|
||||||
|
applicationIdSuffix ".fdroid"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
|
@ -24,6 +24,7 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@ -47,6 +48,8 @@ import android.widget.Button;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.fragments.BackPressable;
|
import org.schabi.newpipe.fragments.BackPressable;
|
||||||
@ -61,6 +64,13 @@ import org.schabi.newpipe.util.ServiceHelper;
|
|||||||
import org.schabi.newpipe.util.StateSaver;
|
import org.schabi.newpipe.util.StateSaver;
|
||||||
import org.schabi.newpipe.util.ThemeHelper;
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
private static final String TAG = "MainActivity";
|
private static final String TAG = "MainActivity";
|
||||||
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
|
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
|
||||||
@ -80,6 +90,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
|
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
|
||||||
|
|
||||||
|
if (BuildConfig.FLAVOR.equals("github")) {
|
||||||
|
new versionCheckTask().execute();
|
||||||
|
}
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
@ -409,4 +423,101 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
|
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AsyncTask to check if there is a newer version of the github apk available or not.
|
||||||
|
* If there is a newer version we show a notification, informing the user. On tapping
|
||||||
|
* the notification, the user will be directed to download link.
|
||||||
|
*/
|
||||||
|
private static class versionCheckTask extends AsyncTask<Void, Void, String> {
|
||||||
|
|
||||||
|
String newPipeApiUrl = "https://api.myjson.com/bins/19gx44";
|
||||||
|
int timeoutPeriod = 10000;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doInBackground(Void... voids) {
|
||||||
|
|
||||||
|
String output;
|
||||||
|
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
URL url = new URL(newPipeApiUrl);
|
||||||
|
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setConnectTimeout(timeoutPeriod);
|
||||||
|
connection.setReadTimeout(timeoutPeriod);
|
||||||
|
connection.setRequestProperty("Content-length", "0");
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setAllowUserInteraction(false);
|
||||||
|
connection.connect();
|
||||||
|
|
||||||
|
int responseStatus = connection.getResponseCode();
|
||||||
|
|
||||||
|
switch (responseStatus) {
|
||||||
|
|
||||||
|
case 200:
|
||||||
|
case 201:
|
||||||
|
BufferedReader bufferedReader
|
||||||
|
= new BufferedReader(
|
||||||
|
new InputStreamReader(connection.getInputStream()));
|
||||||
|
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
String line;
|
||||||
|
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
stringBuilder.append(line + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferedReader.close();
|
||||||
|
output = stringBuilder.toString();
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (connection != null) {
|
||||||
|
try {
|
||||||
|
connection.disconnect();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String output) {
|
||||||
|
|
||||||
|
if (output != null) {
|
||||||
|
|
||||||
|
Log.i("output---", output);
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONObject mainObject = new JSONObject(output);
|
||||||
|
JSONObject flavoursObject = mainObject.getJSONObject("flavors");
|
||||||
|
JSONObject githubObject = flavoursObject.getJSONObject("github");
|
||||||
|
JSONObject githubStableObject = githubObject.getJSONObject("stable");
|
||||||
|
|
||||||
|
String version = githubStableObject.getString("version");
|
||||||
|
// String versionCode = githubStableObject.getString("version_code");
|
||||||
|
String apkLocationUrl = githubStableObject.getString("apk");
|
||||||
|
|
||||||
|
Log.i("jsonConvert---", version + " " + apkLocationUrl);
|
||||||
|
} catch (JSONException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ buildscript {
|
|||||||
google()
|
google()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.1.2'
|
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
Loading…
Reference in New Issue
Block a user