use of com.naman14.timber.utils.PreferencesUtility in project Timber by naman14.
the class RestServiceFactory method createStatic.
public static <T> T createStatic(final Context context, String baseUrl, Class<T> clazz) {
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setCache(new Cache(context.getApplicationContext().getCacheDir(), CACHE_SIZE));
okHttpClient.setConnectTimeout(40, TimeUnit.SECONDS);
RequestInterceptor interceptor = new RequestInterceptor() {
PreferencesUtility prefs = PreferencesUtility.getInstance(context);
@Override
public void intercept(RequestFacade request) {
// 7-days cache
request.addHeader("Cache-Control", String.format("max-age=%d,%smax-stale=%d", Integer.valueOf(60 * 60 * 24 * 7), prefs.loadArtistAndAlbumImages() ? "" : "only-if-cached,", Integer.valueOf(31536000)));
request.addHeader("Connection", "keep-alive");
}
};
RestAdapter.Builder builder = new RestAdapter.Builder().setEndpoint(baseUrl).setRequestInterceptor(interceptor).setClient(new OkClient(okHttpClient));
return builder.build().create(clazz);
}
use of com.naman14.timber.utils.PreferencesUtility in project Timber by naman14.
the class MusicService method onCreate.
@Override
public void onCreate() {
if (D)
Log.d(TAG, "Creating service");
super.onCreate();
mNotificationManager = NotificationManagerCompat.from(this);
createNotificationChannel();
// gets a pointer to the playback state store
mPlaybackStateStore = MusicPlaybackState.getInstance(this);
mSongPlayCount = SongPlayCount.getInstance(this);
mRecentStore = RecentStore.getInstance(this);
mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
mHandlerThread.start();
mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
setUpMediaSession();
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
setUpRemoteControlClient();
mPreferences = getSharedPreferences("Service", 0);
mCardId = getCardId();
registerExternalStorageListener();
mPlayer = new MultiPlayer(this);
mPlayer.setHandler(mPlayerHandler);
// Initialize the intent filter and each action
final IntentFilter filter = new IntentFilter();
filter.addAction(SERVICECMD);
filter.addAction(TOGGLEPAUSE_ACTION);
filter.addAction(PAUSE_ACTION);
filter.addAction(STOP_ACTION);
filter.addAction(NEXT_ACTION);
filter.addAction(PREVIOUS_ACTION);
filter.addAction(PREVIOUS_FORCE_ACTION);
filter.addAction(REPEAT_ACTION);
filter.addAction(SHUFFLE_ACTION);
filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
filter.addAction(Intent.ACTION_SCREEN_ON);
// Attach the broadcast listener
registerReceiver(mIntentReceiver, filter);
mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver);
getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver);
// Initialize the wake lock
final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
mWakeLock.setReferenceCounted(false);
final Intent shutdownIntent = new Intent(this, MusicService.class);
shutdownIntent.setAction(SHUTDOWN);
mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);
scheduleDelayedShutdown();
reloadQueueAfterPermissionCheck();
notifyChange(QUEUE_CHANGED);
notifyChange(META_CHANGED);
// Try to push LastFMCache
if (LastfmUserSession.getSession(this) != null) {
LastFmClient.getInstance(this).Scrobble(null);
}
PreferencesUtility pref = PreferencesUtility.getInstance(this);
mShowAlbumArtOnLockscreen = pref.getSetAlbumartLockscreen();
mActivateXTrackSelector = pref.getXPosedTrackselectorEnabled();
}
use of com.naman14.timber.utils.PreferencesUtility in project Timber by naman14.
the class TimberApp method onCreate.
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
ImageLoaderConfiguration localImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(this).imageDownloader(new BaseImageDownloader(this) {
PreferencesUtility prefs = PreferencesUtility.getInstance(TimberApp.this);
@Override
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
if (prefs.loadArtistAndAlbumImages())
return super.getStreamFromNetwork(imageUri, extra);
throw new IOException();
}
}).build();
ImageLoader.getInstance().init(localImageLoaderConfiguration);
L.writeLogs(false);
L.disableLogging();
L.writeDebugLogs(false);
Nammu.init(this);
if (!ATE.config(this, "light_theme").isConfigured()) {
ATE.config(this, "light_theme").activityTheme(R.style.AppThemeLight).primaryColorRes(R.color.colorPrimaryLightDefault).accentColorRes(R.color.colorAccentLightDefault).coloredNavigationBar(false).usingMaterialDialogs(true).commit();
}
if (!ATE.config(this, "dark_theme").isConfigured()) {
ATE.config(this, "dark_theme").activityTheme(R.style.AppThemeDark).primaryColorRes(R.color.colorPrimaryDarkDefault).accentColorRes(R.color.colorAccentDarkDefault).coloredNavigationBar(false).usingMaterialDialogs(true).commit();
}
if (!ATE.config(this, "light_theme_notoolbar").isConfigured()) {
ATE.config(this, "light_theme_notoolbar").activityTheme(R.style.AppThemeLight).coloredActionBar(false).primaryColorRes(R.color.colorPrimaryLightDefault).accentColorRes(R.color.colorAccentLightDefault).coloredNavigationBar(false).usingMaterialDialogs(true).commit();
}
if (!ATE.config(this, "dark_theme_notoolbar").isConfigured()) {
ATE.config(this, "dark_theme_notoolbar").activityTheme(R.style.AppThemeDark).coloredActionBar(false).primaryColorRes(R.color.colorPrimaryDarkDefault).accentColorRes(R.color.colorAccentDarkDefault).coloredNavigationBar(true).usingMaterialDialogs(true).commit();
}
}
Aggregations