Skip to content

Commit

Permalink
Merge pull request #18 from kotvertolet/'release_1.1.2'
Browse files Browse the repository at this point in the history
Release 1.1.2
  • Loading branch information
antonyhaman authored Apr 17, 2020
2 parents f334093 + 7bd2f28 commit 6569974
Show file tree
Hide file tree
Showing 77 changed files with 959 additions and 726 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ All notable changes to this project will be documented in this file.
- Slightly changed logic for sliding player panel elements transformations
- Moved to [Fastlane](https://gitlab.com/snippets/1895688) file structure
- Turned on Proguard
- Various tiny fixes and optimizations
- Various tiny fixes and optimizations

## [1.1.2]
- Fixed numerous bugs and improved stability
- Moved to official Retrofit RxJava2 Adapter
- Bumped Exoplayer version
- Min SDK level is 21
17 changes: 6 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.github.kotvertolet.youtubeaudioplayer"
minSdkVersion 19
targetSdkVersion 29
versionCode 2
versionName "1.1.1"
versionCode 3
versionName "1.1.2"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -47,9 +47,9 @@ dependencies {
implementation 'com.google.android.material:material:1.2.0-alpha05'

// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.7.2'
implementation "com.squareup.retrofit2:retrofit:2.7.2"
implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.2'

// Gson
implementation 'com.google.code.gson:gson:2.8.6'
Expand All @@ -61,10 +61,6 @@ dependencies {
// Sliding panel
implementation 'com.sothree.slidinguppanel:library:3.3.1'

//TODO: Remove when min sdk >= 21
// Ripple for SDK 14+
implementation 'com.balysv:material-ripple:1.0.2'

// Joda
implementation 'joda-time:joda-time:2.10.1'

Expand All @@ -84,9 +80,8 @@ dependencies {
implementation 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:1.0.1'

// Exo Player
implementation 'com.google.android.exoplayer:exoplayer-core:2.9.6'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.9.6'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.9.6'
implementation 'com.google.android.exoplayer:exoplayer-core:2.11.4'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.11.4'

// Multidex
implementation 'com.android.support:multidex:1.0.3'
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.Manifest.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:name=".App"
Expand All @@ -21,6 +22,8 @@
android:supportsRtl="false"
android:theme="@style/AppTheme"
android:versionName="ver"


tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".activities.splash.SplashActivity"
Expand All @@ -39,7 +42,8 @@
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:screenOrientation="fullSensor"
android:theme="@style/AppTheme"/>
android:theme="@style/AppTheme" />

<service
android:name=".services.ExoPlayerService"
android:enabled="true"
Expand All @@ -48,6 +52,9 @@
android:name=".services.PlayerNotificationService"
android:enabled="true"
android:exported="false" />
<service
android:name=".services.ExoDownloadService"
android:exported="false" />
</application>

</manifest>
116 changes: 114 additions & 2 deletions app/src/main/java/com/github/kotvertolet/youtubeaudioplayer/App.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
package com.github.kotvertolet.youtubeaudioplayer;

import android.app.Application;
import android.content.SharedPreferences;

import com.github.kotvertolet.youtubeaudioplayer.custom.CachingTasksManager;
import com.github.kotvertolet.youtubeaudioplayer.db.AppDatabase;
import com.github.kotvertolet.youtubeaudioplayer.utilities.common.Constants;
import com.google.android.exoplayer2.database.DatabaseProvider;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.offline.ActionFileUpgradeUtil;
import com.google.android.exoplayer2.offline.DefaultDownloadIndex;
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory;
import com.google.android.exoplayer2.offline.DownloadManager;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.ui.DownloadNotificationHelper;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.FileDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.cache.Cache;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
import com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.exoplayer2.util.Log;

import java.io.File;
import java.io.IOException;

public class App extends Application {
import androidx.multidex.MultiDexApplication;

import static com.github.kotvertolet.youtubeaudioplayer.utilities.common.Constants.USER_AGENT;

public class App extends MultiDexApplication {

public static final String DOWNLOAD_NOTIFICATION_CHANNEL_ID = "download_channel";
private static final String TAG = "DemoApplication";
private static final String DOWNLOAD_ACTION_FILE = "actions";
private static final String DOWNLOAD_TRACKER_ACTION_FILE = "tracked_actions";
private static final String DOWNLOAD_CONTENT_DIRECTORY = "downloads";
private static App instance;
private AppDatabase database;
private SharedPreferences sharedPreferences;
private SimpleCache playerCache;
private CachingTasksManager cachingTasksManager;
private DownloadNotificationHelper downloadNotificationHelper;
private DatabaseProvider databaseProvider;
private File downloadDirectory;
private Cache downloadCache;
private DownloadManager downloadManager;

public static synchronized App getInstance() {
return instance;
Expand All @@ -27,6 +58,15 @@ public static void setInstance(App instance) {
App.instance = instance;
}

protected static CacheDataSourceFactory buildReadOnlyCacheDataSource(
DataSource.Factory upstreamFactory, Cache cache) {
return new CacheDataSourceFactory(
cache,
upstreamFactory,
new FileDataSource.Factory(),null,
CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, null);
}

public AppDatabase getDatabase() {
return database;
}
Expand All @@ -53,10 +93,82 @@ public void onCreate() {
cachingTasksManager = new CachingTasksManager();
}

public DownloadNotificationHelper getDownloadNotificationHelper() {
if (downloadNotificationHelper == null) {
downloadNotificationHelper =
new DownloadNotificationHelper(this, DOWNLOAD_NOTIFICATION_CHANNEL_ID);
}
return downloadNotificationHelper;
}

private SimpleCache prepareCache() {
File cacheFolder = new File(App.getInstance().getCacheDir(), "media");
int cacheSize = sharedPreferences.getInt(Constants.PREFERENCE_CACHE_SIZE, 250);
LeastRecentlyUsedCacheEvictor cacheEvictor = new LeastRecentlyUsedCacheEvictor(cacheSize * 1000000);
return new SimpleCache(cacheFolder, cacheEvictor);
}

private synchronized void initDownloadManager() {
if (downloadManager == null) {
DefaultDownloadIndex downloadIndex = new DefaultDownloadIndex(getDatabaseProvider());
upgradeActionFile(
DOWNLOAD_ACTION_FILE, downloadIndex, false);
upgradeActionFile(
DOWNLOAD_TRACKER_ACTION_FILE, downloadIndex, true);
DownloaderConstructorHelper downloaderConstructorHelper =
new DownloaderConstructorHelper(getDownloadCache(), buildHttpDataSourceFactory());
downloadManager =
new DownloadManager(
this, downloadIndex, new DefaultDownloaderFactory(downloaderConstructorHelper));
}
}

/**
* Returns a {@link HttpDataSource.Factory}.
*/
public HttpDataSource.Factory buildHttpDataSourceFactory() {
return new DefaultHttpDataSourceFactory(USER_AGENT);
}

private void upgradeActionFile(
String fileName, DefaultDownloadIndex downloadIndex, boolean addNewDownloadsAsCompleted) {
try {
ActionFileUpgradeUtil.upgradeAndDelete(
new File(getDownloadDirectory(), fileName),null,
downloadIndex, true, addNewDownloadsAsCompleted);
} catch (IOException e) {
Log.e(TAG, "Failed to upgrade action file: " + fileName, e);
}
}

private DatabaseProvider getDatabaseProvider() {
if (databaseProvider == null) {
databaseProvider = new ExoDatabaseProvider(this);
}
return databaseProvider;
}

public DownloadManager getDownloadManager() {
initDownloadManager();
return downloadManager;
}

private File getDownloadDirectory() {
if (downloadDirectory == null) {
downloadDirectory = getExternalFilesDir(null);
if (downloadDirectory == null) {
downloadDirectory = getFilesDir();
}
}
return downloadDirectory;
}

protected synchronized Cache getDownloadCache() {
if (downloadCache == null) {
File downloadContentDirectory = new File(getDownloadDirectory(), DOWNLOAD_CONTENT_DIRECTORY);
downloadCache =
new SimpleCache(downloadContentDirectory, new NoOpCacheEvictor(), getDatabaseProvider());
}
return downloadCache;
}
}
Loading

0 comments on commit 6569974

Please sign in to comment.