WIP andorid auto

main
h4h13 2019-08-02 18:38:47 +05:30
parent c2759e3ec0
commit 6acac46d45
9 changed files with 79 additions and 26 deletions

View File

@ -259,6 +259,8 @@
<meta-data <meta-data
android:name="com.google.android.gms.car.notification.SmallIcon" android:name="com.google.android.gms.car.notification.SmallIcon"
android:resource="@drawable/ic_notification" /> android:resource="@drawable/ic_notification" />
</application> </application>
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
@ -272,4 +274,8 @@
<uses-permission android:name="com.android.vending.BILLING" /> <uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-feature
android:name="android.hardware.type.automotive"
android:required="true" />
</manifest> </manifest>

View File

@ -55,7 +55,9 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP
return contentView return contentView
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(
savedInstanceState: Bundle?
) {
setDrawUnderStatusBar() setDrawUnderStatusBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -64,12 +66,9 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP
getBottomNavigationView().setOnNavigationItemSelectedListener { getBottomNavigationView().setOnNavigationItemSelectedListener {
PreferenceUtil.getInstance().lastPage = it.itemId PreferenceUtil.getInstance().lastPage = it.itemId
selectedFragment(it.itemId) selectedFragment(it.itemId)
true true
} }
if (savedInstanceState == null) { if (savedInstanceState == null) {
selectedFragment(PreferenceUtil.getInstance().lastPage) selectedFragment(PreferenceUtil.getInstance().lastPage)
} else { } else {

View File

@ -169,7 +169,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
slidingLayout.panelHeight = 0 slidingLayout.panelHeight = 0
collapsePanel() collapsePanel()
} else { } else {
if (!MusicPlayerRemote.playingQueue.isEmpty()) { if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
slidingLayout.panelHeight = if (bottomNavigationView.visibility == View.VISIBLE) heightOfBarWithTabs else heightOfBar slidingLayout.panelHeight = if (bottomNavigationView.visibility == View.VISIBLE) heightOfBarWithTabs else heightOfBar
} }
} }

View File

@ -173,6 +173,7 @@ abstract class AbsThemeActivity : ATHActivity(), Runnable {
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
if (PreferenceUtil.getInstance().fullScreenMode) { if (PreferenceUtil.getInstance().fullScreenMode) {
window.decorView.systemUiVisibility = flags window.decorView.systemUiVisibility = flags
} }

View File

@ -57,9 +57,7 @@ public class AutoMusicProvider {
private static final int PATH_SEGMENT_ID = 0; private static final int PATH_SEGMENT_ID = 0;
private static final int PATH_SEGMENT_TITLE = 1; private static final int PATH_SEGMENT_TITLE = 1;
private static final int PATH_SEGMENT_ARTIST = 2; private static final int PATH_SEGMENT_ARTIST = 2;
private static final int PATH_SEGMENT_ALBUM_ID = 3;
private WeakReference<MusicService> mMusicService;
// Categorized caches for music data // Categorized caches for music data
private ConcurrentMap<Integer, Uri> mMusicListByHistory; private ConcurrentMap<Integer, Uri> mMusicListByHistory;

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.auto;
import android.app.UiModeManager;
import android.content.Context;
import android.content.res.Configuration;
public class CarHelper {
private static final String TAG = "CarHelper";
public static boolean isCarUiMode(Context c) {
UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE);
return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR;
}
}

View File

@ -24,7 +24,9 @@ interface DeezerApiService {
): Call<DeezerResponse> ): Call<DeezerResponse>
companion object { companion object {
operator fun invoke(client: okhttp3.Call.Factory): DeezerApiService { operator fun invoke(
client: okhttp3.Call.Factory
): DeezerApiService {
return Retrofit.Builder() return Retrofit.Builder()
.baseUrl(BASE_URL) .baseUrl(BASE_URL)
.callFactory(client) .callFactory(client)
@ -33,12 +35,16 @@ interface DeezerApiService {
.create() .create()
} }
fun createDefaultOkHttpClient(context: Context): OkHttpClient.Builder = fun createDefaultOkHttpClient(
context: Context
): OkHttpClient.Builder =
OkHttpClient.Builder() OkHttpClient.Builder()
.cache(createDefaultCache(context)) .cache(createDefaultCache(context))
.addInterceptor(createCacheControlInterceptor()) .addInterceptor(createCacheControlInterceptor())
private fun createDefaultCache(context: Context): Cache? { private fun createDefaultCache(
context: Context
): Cache? {
val cacheDir = File(context.applicationContext.cacheDir.absolutePath, "/okhttp-deezer/") val cacheDir = File(context.applicationContext.cacheDir.absolutePath, "/okhttp-deezer/")
if (cacheDir.mkdir() or cacheDir.isDirectory) { if (cacheDir.mkdir() or cacheDir.isDirectory) {
return Cache(cacheDir, 1024 * 1024 * 10) return Cache(cacheDir, 1024 * 1024 * 10)

View File

@ -32,20 +32,25 @@ object AlbumLoader {
fun getAllAlbumsFlowable( fun getAllAlbumsFlowable(
context: Context context: Context
): Observable<ArrayList<Album>> { ): Observable<ArrayList<Album>> {
val songs = SongLoader.getSongsFlowable(SongLoader.makeSongCursor( val songs = SongLoader.getSongsFlowable(
context, null, null, SongLoader.makeSongCursor(
getSongLoaderSortOrder()) context, null, null,
getSongLoaderSortOrder())
) )
return splitIntoAlbumsFlowable(songs) return splitIntoAlbumsFlowable(songs)
} }
fun getAlbumsFlowable(context: Context, query: String): Observable<ArrayList<Album>> { fun getAlbumsFlowable(
val songs = SongLoader.getSongsFlowable(SongLoader.makeSongCursor( context: Context,
context, query: String
AudioColumns.ALBUM + " LIKE ?", ): Observable<ArrayList<Album>> {
arrayOf("%$query%"), val songs = SongLoader.getSongsFlowable(
getSongLoaderSortOrder()) SongLoader.makeSongCursor(
context,
AudioColumns.ALBUM + " LIKE ?",
arrayOf("%$query%"),
getSongLoaderSortOrder())
) )
return splitIntoAlbumsFlowable(songs) return splitIntoAlbumsFlowable(songs)
} }
@ -68,7 +73,14 @@ object AlbumLoader {
albumId: Int albumId: Int
): Observable<Album> { ): Observable<Album> {
return Observable.create { e -> return Observable.create { e ->
val songs = SongLoader.getSongsFlowable(SongLoader.makeSongCursor(context, AudioColumns.ALBUM_ID + "=?", arrayOf(albumId.toString()), getSongLoaderSortOrder())) val songs = SongLoader.getSongsFlowable(
SongLoader.makeSongCursor(
context,
AudioColumns.ALBUM_ID + "=?",
arrayOf(albumId.toString()),
getSongLoaderSortOrder()
)
)
songs.subscribe { songs1 -> songs.subscribe { songs1 ->
e.onNext(Album(songs1)) e.onNext(Album(songs1))
e.onComplete() e.onComplete()
@ -114,9 +126,10 @@ object AlbumLoader {
fun getAllAlbums( fun getAllAlbums(
context: Context context: Context
): ArrayList<Album> { ): ArrayList<Album> {
val songs = SongLoader.getSongs(SongLoader.makeSongCursor( val songs = SongLoader.getSongs(
context, null, null, SongLoader.makeSongCursor(
getSongLoaderSortOrder()) context, null, null,
getSongLoaderSortOrder())
) )
return splitIntoAlbums(songs) return splitIntoAlbums(songs)
@ -178,7 +191,6 @@ object AlbumLoader {
private fun getSongLoaderSortOrder(): String { private fun getSongLoaderSortOrder(): String {
return PreferenceUtil.getInstance().albumSortOrder + ", " + return PreferenceUtil.getInstance().albumSortOrder + ", " +
//PreferenceUtil.getInstance().getAlbumSongSortOrder() + "," +
PreferenceUtil.getInstance().albumDetailSongSortOrder PreferenceUtil.getInstance().albumDetailSongSortOrder
} }
} }

View File

@ -24,8 +24,11 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
class BottomNavigationBarTinted @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : class BottomNavigationBarTinted @JvmOverloads constructor(
BottomNavigationView(context, attrs, defStyleAttr) { context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : BottomNavigationView(context, attrs, defStyleAttr) {
init { init {
labelVisibilityMode = PreferenceUtil.getInstance().tabTitleMode labelVisibilityMode = PreferenceUtil.getInstance().tabTitleMode