Skip to content

Commit

Permalink
Added oreo support
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuliyer95 committed Apr 7, 2018
1 parent 9a9cf12 commit 718a78e
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 113 deletions.
69 changes: 36 additions & 33 deletions app/build.gradle
@@ -1,25 +1,25 @@
apply plugin: 'com.android.application'
apply plugin: "com.android.application"

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
compileSdkVersion 27
buildToolsVersion "27.0.3"

lintOptions{
disable 'MissingTranslation'
disable "MissingTranslation"
abortOnError false
}

defaultConfig {
applicationId "com.phantom.onetapvideodownload"
minSdkVersion 15
targetSdkVersion 26
targetSdkVersion 27
versionCode 46
versionName "5.5"
}

sourceSets {
main {
assets.srcDirs = ['assets', 'src/main/assets', 'src/main/assets/']
assets.srcDirs = ["assets", "src/main/assets", "src/main/assets/"]
}
}

Expand All @@ -28,55 +28,58 @@ android {
minifyEnabled true
zipAlignEnabled true
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}

release {
minifyEnabled true
zipAlignEnabled true
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}

dependencies {
provided fileTree(dir: 'libs', include: ['XposedBridgeApi-20150213.jar'])
// Xposed-Bridge
compileOnly fileTree(dir: 'libs', include: ['XposedBridgeApi-20150213.jar'])
// compileOnly "de.robv.android.xposed:api:82"
// compileOnly "de.robv.android.xposed:api:82:sources"

compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile "com.android.support:preference-v7:26.1.0"
compile 'com.android.support:cardview-v7:26.1.0'
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.android.support:recyclerview-v7:27.1.1"
implementation "com.android.support:design:27.1.1"
implementation "com.android.support:preference-v7:27.1.1"
implementation "com.android.support:cardview-v7:27.1.1"

compile 'com.google.firebase:firebase-core:11.4.2'
compile 'com.google.firebase:firebase-crash:11.4.2'
compile 'com.google.android.gms:play-services-plus:11.4.2'
compile 'com.google.firebase:firebase-messaging:11.4.2'
compile 'com.github.HaarigerHarald:android-youtubeExtractor:v1.6.0'
implementation "com.google.firebase:firebase-core:12.0.1"
implementation "com.google.firebase:firebase-crash:12.0.1"
implementation "com.google.android.gms:play-services-plus:12.0.1"
implementation "com.google.firebase:firebase-messaging:12.0.1"
implementation "com.github.HaarigerHarald:android-youtubeExtractor:v1.6.0"

compile 'com.afollestad.material-dialogs:core:0.9.4.2'
compile 'com.afollestad.material-dialogs:commons:0.9.4.2'
compile 'net.xpece.android:support-preference:1.2.1'
compile 'com.squareup.okhttp3:okhttp:3.8.0'
compile 'com.squareup.okio:okio:1.13.0'
compile 'me.zhanghai.android.materialprogressbar:library:1.3.0@aar'
compile 'org.solovyev.android.views:linear-layout-manager:0.5@aar'
compile 'com.anjlab.android.iab.v3:library:1.0.+'
compile 'com.github.bluejamesbond:textjustify-android:2.1.6'
compile 'com.evernote:android-job:1.1.7'
implementation "com.afollestad.material-dialogs:core:0.9.4.2"
implementation "com.afollestad.material-dialogs:commons:0.9.4.2"
implementation "net.xpece.android:support-preference:1.2.1"
implementation "com.squareup.okhttp3:okhttp:3.8.0"
implementation "com.squareup.okio:okio:1.13.0"
implementation "me.zhanghai.android.materialprogressbar:library:1.3.0@aar"
implementation "org.solovyev.android.views:linear-layout-manager:0.5@aar"
implementation "com.anjlab.android.iab.v3:library:1.0.44"
implementation "com.github.bluejamesbond:textjustify-android:2.1.6"
implementation "com.evernote:android-job:1.1.7"

testCompile 'junit:junit:4.12'
testImplementation "junit:junit:4.12"
}

apply plugin: 'com.google.gms.google-services'
apply plugin: "com.google.gms.google-services"

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.0'
details.useVersion "27.1.1"
}
}
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) thr
}

final XC_MethodHook methodHook = new XC_MethodHook() {
protected void afterHookedMethod(XC_MethodHook.MethodHookParam hookParams) throws Throwable {
protected void afterHookedMethod(XC_MethodHook.MethodHookParam hookParams) {
try {
Uri uri = (Uri) hookParams.args[0];
ApplicationLogMaintainer.sendBroadcast(context, "Facebook Main URL : " + uri.toString());
Expand Down
Expand Up @@ -84,6 +84,7 @@ void writeToLog(String message, boolean appendMode) {

File logFile = new File(getLogFilePath());
if (!logFile.getParentFile().exists()) {
//noinspection ResultOfMethodCallIgnored
logFile.getParentFile().mkdirs();
}

Expand Down
60 changes: 47 additions & 13 deletions app/src/main/java/com/phantom/onetapvideodownload/IpcService.java
@@ -1,6 +1,8 @@
package com.phantom.onetapvideodownload;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
Expand All @@ -12,7 +14,9 @@
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.support.v7.app.NotificationCompat;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.ServiceCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.util.SparseArray;

Expand Down Expand Up @@ -45,6 +49,8 @@ public class IpcService extends Service implements Invokable<Video, Integer> {
public static final String EXTRA_PARAM_STRING = PACKAGE_NAME + ".extra.url";
public static final String EXTRA_PACKAGE_NAME = PACKAGE_NAME + ".extra.package_name";

private static final String NOTIFICATION_CHANNEL_NAME = "Xposed One Tap Video Download";

private Handler mHandler = new Handler();
private final IBinder mBinder = new LocalBinder();
private static final AtomicInteger notificationId = new AtomicInteger();
Expand All @@ -60,33 +66,46 @@ public static void startSaveUrlAction(Context context, String uri, String packag
intent.setClassName(PACKAGE_NAME, CLASS_NAME);
intent.putExtra(EXTRA_URL, uri);
intent.putExtra(EXTRA_PACKAGE_NAME, packageName);
context.startService(intent);
ContextCompat.startForegroundService(context, intent);
}

public static void startSaveYoutubeVideoAction(Context context, String paramString) {
Intent intent = new Intent(ACTION_SAVE_YOUTUBE_VIDEO);
intent.setClassName(PACKAGE_NAME, CLASS_NAME);
intent.putExtra(EXTRA_PARAM_STRING, paramString);
context.startService(intent);
ContextCompat.startForegroundService(context, intent);
}

public static void startInspectMediaUriAction(Context context, String uri, String packageName) {
Intent intent = new Intent(ACTION_INSPECT_MEDIA_URI);
intent.setClassName(PACKAGE_NAME, CLASS_NAME);
intent.putExtra(EXTRA_URL, uri);
intent.putExtra(EXTRA_PACKAGE_NAME, packageName);
context.startService(intent);
ContextCompat.startForegroundService(context, intent);
}

@Override
public void onCreate() {
super.onCreate();
// On Oreo, we need a notification to show that the app is running in background
// Refer - https://stackoverflow.com/a/47654126 - for more information
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
startForeground(1024, new Notification());
}

@Override
public void onDestroy() {
super.onDestroy();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE);
}

@Override
public IBinder onBind(Intent intent) {
return mBinder;
}

public class LocalBinder extends Binder {
public IpcService getServiceInstance() {
return IpcService.this;
}
private class LocalBinder extends Binder {
}

@Override
Expand Down Expand Up @@ -133,7 +152,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
}

private void showNotification(String url, String title, long videoId) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, PACKAGE_NAME);
mBuilder.setSmallIcon(R.drawable.one_tap_small);
mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.one_tap_large));
mBuilder.setContentTitle(title);
Expand All @@ -143,7 +162,7 @@ private void showNotification(String url, String title, long videoId) {

// 0 if vibration is disabled.
long vibrationAmount = CheckPreferences.vibrationAmount(this);
mBuilder.setVibrate(new long[] {0, vibrationAmount});
mBuilder.setVibrate(new long[]{0, vibrationAmount});

int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (CheckPreferences.headsUpEnabled(this) && currentApiVersion >= Build.VERSION_CODES.JELLY_BEAN) {
Expand All @@ -162,7 +181,7 @@ private void showNotification(String url, String title, long videoId) {
instantDownloadIntent = ProxyDownloadManager.getActionBrowserDownload(this, videoId,
title, CheckPreferences.getDownloadLocation(this));
} else if (VideoDatabase.VIDEO_TYPE_YOUTUBE == videoDatabase.getCategory(videoId)) {
YoutubeVideo video = (YoutubeVideo)videoDatabase.getVideo(videoId);
YoutubeVideo video = (YoutubeVideo) videoDatabase.getVideo(videoId);
int itag = video.getBestVideoFormat().itag;
instantDownloadIntent = ProxyDownloadManager.getActionYoutubeDownload(this, videoId,
title, CheckPreferences.getDownloadLocation(this), itag);
Expand Down Expand Up @@ -203,8 +222,12 @@ private void showNotification(String url, String title, long videoId) {
mBuilder.setContentIntent(downloadPendingIntent);

final NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (notificationmanager == null)
return;

final int id = possibleId;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
notificationmanager.createNotificationChannel(getNotificationChannel());
notificationmanager.notify(id, mBuilder.build());
int delayInSeconds = CheckPreferences.notificationDismissTime(this);

Expand Down Expand Up @@ -252,20 +275,25 @@ private void handleActionSaveYoutubeVideo(String paramString) {

if (invalidId) {
final NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (notificationmanager == null)
return;
int possibleId = notificationId.getAndIncrement();
if (possibleId >= CheckPreferences.notificationCountAllowed(this)) {
possibleId = 0;
notificationId.set(possibleId);
}
final int id = possibleId;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, PACKAGE_NAME);
mBuilder.setSmallIcon(R.drawable.one_tap_small);
mBuilder.setChannelId(PACKAGE_NAME);
mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.one_tap_large));
mBuilder.setContentTitle(getResources().getString(R.string.youtube_next_video_title));
mBuilder.setContentInfo(getResources().getString(R.string.youtube_next_video_summary));
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(getResources().getString(R.string.youtube_next_video_summary)));
mBuilder.setAutoCancel(true);
mBuilder.setOnlyAlertOnce(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
notificationmanager.createNotificationChannel(getNotificationChannel());
notificationmanager.notify(id, mBuilder.build());
return;
}
Expand All @@ -275,7 +303,7 @@ private void handleActionSaveYoutubeVideo(String paramString) {
@Override
public Integer invoke(Video video) {
if (video != null) {
YoutubeVideo youtubeVideo = (YoutubeVideo)video;
YoutubeVideo youtubeVideo = (YoutubeVideo) video;
youtubeVideo.setPackageName("com.google.android.youtube");
String bestFormatUrl = youtubeVideo.getBestVideoFormat().url;
if (bestFormatUrl == null
Expand All @@ -291,4 +319,10 @@ public Integer invoke(Video video) {
}
return 0;
}

@TargetApi(Build.VERSION_CODES.O)
private NotificationChannel getNotificationChannel() {
return new NotificationChannel(PACKAGE_NAME, NOTIFICATION_CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT);
}
}
Expand Up @@ -5,7 +5,6 @@
import android.content.Intent;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.IntentCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

Expand All @@ -14,7 +13,7 @@
public class ThemeManager {
public static void applyTheme(AppCompatActivity activity) {
activity.setTheme(ThemeManager.getTheme(activity));
Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
Toolbar toolbar = activity.findViewById(R.id.toolbar);
toolbar.setBackgroundColor(ThemeManager.getPrimaryColor(activity));
toolbar.setPopupTheme(getPopupMenuTheme(activity));
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand All @@ -26,19 +25,19 @@ public static void applyTheme(AppCompatActivity activity) {
public static void onThemeChanged(Activity activity) {
activity.finish();
final Intent intent = activity.getIntent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.startActivity(intent);
}

public static int getTheme(Context context) {
private static int getTheme(Context context) {
if (CheckPreferences.getDarkThemeEnabled(context)) {
return R.style.AppTheme_Dark;
} else {
return R.style.AppTheme;
}
}

public static int getPopupMenuTheme(Context context) {
private static int getPopupMenuTheme(Context context) {
if (CheckPreferences.getDarkThemeEnabled(context)) {
return R.style.AppTheme_ThemeOverlay_AppCompat_Dark;
} else {
Expand Down Expand Up @@ -70,15 +69,15 @@ public static int getLightBackgroundColor(Context context) {
}
}

public static int getPrimaryDarkColor(Context context) {
private static int getPrimaryDarkColor(Context context) {
if (CheckPreferences.getDarkThemeEnabled(context)) {
return ContextCompat.getColor(context, R.color.dark_background);
} else {
return ContextCompat.getColor(context, R.color.dark_primary);
}
}

public static int getNavigationBarColor(Context context) {
private static int getNavigationBarColor(Context context) {
if (CheckPreferences.getDarkThemeEnabled(context)) {
return ContextCompat.getColor(context, R.color.black);
} else {
Expand Down
Expand Up @@ -14,7 +14,7 @@
import android.os.IBinder;
import android.support.v4.content.ContextCompat;
import android.support.v4.util.Pair;
import android.support.v7.app.NotificationCompat;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.view.View;

Expand Down Expand Up @@ -59,7 +59,7 @@ public class DownloadManager extends Service {
@Override
public void onCreate() {
mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(this);
mBuilder = new NotificationCompat.Builder(this, PACKAGE_NAME + "." + TAG);

DownloadDatabase downloadDatabase = DownloadDatabase.getDatabase(this);
List<DownloadInfo> downloadInfos = downloadDatabase.getAllDownloads();
Expand Down Expand Up @@ -220,7 +220,8 @@ public boolean checkPermissionGranted(AppPermissions permission) {
private void requestPermission(AppPermissions permission) {
String title = "Storage permission required";
String description = "Please enable this permission and restart your download.";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
PACKAGE_NAME + "." + TAG);
builder.setSmallIcon(R.drawable.one_tap_small);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.one_tap_large));
builder.setContentTitle(title);
Expand Down

0 comments on commit 718a78e

Please sign in to comment.