Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zinnatullin committed Sep 11, 2014
2 parents 783565e + 2e3782a commit 2acf2be
Show file tree
Hide file tree
Showing 29 changed files with 661 additions and 60 deletions.
1 change: 1 addition & 0 deletions wail-app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/
custom_env.gradle
30 changes: 19 additions & 11 deletions wail-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// for applying custom environment properties
if (new File('wail-app/custom_env.gradle').exists()) {
apply from: 'custom_env.gradle'
}

apply plugin: 'com.android.application'

repositories {
Expand All @@ -16,30 +21,33 @@ android {
}

signingConfigs {
release
googlePlay
}

buildTypes {
debug {
versionNameSuffix ' debug ' + getDateForVersionName()
signingConfig signingConfigs.googlePlay
}

release {
signingConfig signingConfigs.release
signingConfig signingConfigs.googlePlay
}
}

if (project.hasProperty('signingConfig.storeFile')
&& project.hasProperty('signingConfig.storePassword')
&& project.hasProperty('signingConfig.keyAlias')
&& project.hasProperty('signingConfig.keyPassword')
if (project.hasProperty('signingConfigStoreFile')
&& project.hasProperty('signingConfigStorePassword')
&& project.hasProperty('signingConfigKeyAlias')
&& project.hasProperty('signingConfigKeyPassword')
) {
android.signingConfigs.release.storeFile = file(project.getProperty('signingConfig.storeFile'))
android.signingConfigs.release.storePassword = project.getProperty('signingConfig.storePassword')
android.signingConfigs.release.keyAlias = project.getProperty('signingConfig.keyAlias')
android.signingConfigs.release.keyPassword = project.getProperty('signingConfig.keyPassword')
android.signingConfigs.googlePlay.storeFile = file(project.ext['signingConfigStoreFile'])
android.signingConfigs.googlePlay.storePassword = project.ext['signingConfigStorePassword']
android.signingConfigs.googlePlay.keyAlias = project.ext['signingConfigKeyAlias']
android.signingConfigs.googlePlay.keyPassword = project.ext['signingConfigKeyPassword']
} else {
buildTypes.release.signingConfig = null
buildTypes.all { bt ->
bt.signingConfig = null
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions wail-app/custom_env.gradle.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// sample file for setting custom environment params
// rename it to custom_env.gradle and our build.gradle will apply it

project.ext {
customPropery = 'customValue'
}
10 changes: 10 additions & 0 deletions wail-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@
android:windowSoftInputMode="stateHidden|adjustResize"
android:label="@string/lastfm_login_activity_label" />

<activity
android:name=".ui.activity.settings.SettingsSelectLanguageActivity"
android:windowSoftInputMode="stateHidden"
android:label="@string/settings_select_language_activity_label" />

<activity
android:name=".ui.activity.settings.SettingsSoundNotificationsActivity"
android:windowSoftInputMode="stateHidden"
android:label="@string/settings_sound_notifications_activity_label" />

<activity
android:name=".ui.activity.settings.SettingsStatusBarNotificationsActivity"
android:windowSoftInputMode="stateHidden"
android:label="@string/settings_status_bar_notifications_activity_label" />

<service
android:name=".service.WAILService"
android:enabled="true"
Expand Down
14 changes: 9 additions & 5 deletions wail-app/src/main/java/com/artemzin/android/wail/WAILApp.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.artemzin.android.wail;

import android.app.Application;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;

import com.artemzin.android.wail.service.WAILService;
import com.artemzin.android.wail.storage.WAILSettings;
import com.artemzin.android.wail.storage.db.PlayersDBHelper;
import com.artemzin.android.wail.ui.activity.MainActivity;
import com.artemzin.android.wail.util.AsyncTaskExecutor;
import com.artemzin.android.wail.util.LocaleUtil;
import com.artemzin.android.wail.util.Loggi;
import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.MapBuilder;
Expand All @@ -23,11 +20,18 @@ public class WAILApp extends Application {

@Override
public void onCreate() {
LocaleUtil.updateLanguage(this, null);
super.onCreate();
Loggi.w("WAILApp onCreate()");
updateSupportedPlayersDB();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
LocaleUtil.updateLanguage(this, WAILSettings.getLanguage(this));
}

private void updateSupportedPlayersDB() {
AsyncTaskExecutor.executeConcurrently(new AsyncTask<Void, Void, Void>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.artemzin.android.wail.sound;
package com.artemzin.android.wail.notifications;

import android.content.Context;
import android.media.MediaPlayer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.artemzin.android.wail.notifications;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;

import com.artemzin.android.wail.R;
import com.artemzin.android.wail.storage.WAILSettings;
import com.artemzin.android.wail.storage.model.Track;
import com.artemzin.android.wail.ui.activity.MainActivity;
import com.artemzin.android.wail.util.Loggi;

/**
* @author Ilya Murzinov [murz42@gmail.com]
*/

public class StatusBarNotificationsManager {
private static final int NOTIFICATION_ID = 1;

private static volatile StatusBarNotificationsManager instance;
private Context context;

private StatusBarNotificationsManager(Context context) {
this.context = context;
}

public static StatusBarNotificationsManager getInstance(Context context) {
if (instance == null) {
synchronized (StatusBarNotificationsManager.class) {
if (instance == null) {
instance = new StatusBarNotificationsManager(context);
}
}
}
return instance;
}

public void showTrackScrobblingStatusBarNotification(Track track) {
if (!WAILSettings.isStatusBarNotificationTrackScrobblingEnabled(context)) {
Loggi.i("StatusBarNotificationsManager: Status bar notifications are disabled, skipping");
return;
}

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE);

Intent resultIntent = new Intent(context, MainActivity.class);
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
taskStackBuilder.addParentStack(MainActivity.class);
taskStackBuilder.addNextIntent(resultIntent);
PendingIntent intent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

Notification notification = new NotificationCompat.Builder(context)
.setContentTitle("Now scrobbling")
.setContentText(track.getArtist() + " - " + track.getTrack())
.setSmallIcon(R.drawable.ic_status_wail_notifications)
.setContentIntent(intent)
.build();
notification.flags = Notification.FLAG_ONGOING_EVENT;

notificationManager.notify(NOTIFICATION_ID, notification);
}

public void hideTrackScrobblingStatusBarNotification() {
if (!WAILSettings.isStatusBarNotificationTrackScrobblingEnabled(context)) {
Loggi.i("StatusBarNotificationsManager: Status bar notifications are disabled, skipping");
return;
}

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
}

public void cancelAllNotifications() {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import com.artemzin.android.wail.api.lastfm.model.request.LFTrackRequestModel;
import com.artemzin.android.wail.api.network.NetworkException;
import com.artemzin.android.wail.receiver.music.CommonMusicAppReceiver;
import com.artemzin.android.wail.sound.SoundNotificationsManager;
import com.artemzin.android.wail.notifications.SoundNotificationsManager;
import com.artemzin.android.wail.notifications.StatusBarNotificationsManager;
import com.artemzin.android.wail.storage.db.TracksDBHelper;
import com.artemzin.android.wail.storage.WAILSettings;
import com.artemzin.android.wail.storage.model.Track;
Expand Down Expand Up @@ -107,11 +108,13 @@ protected Void doInBackground(Void... params) {
final Track currentTrack = CommonMusicAppReceiver.parseFromIntentExtras(intent);

if (isCurrentTrackPlaying) {
WAILSettings.setNowScrobblingTrack(
getApplicationContext(),
currentTrack.getArtist() + " - " + currentTrack.getTrack());
WAILSettings.setNowScrobblingTrack(getApplicationContext(), currentTrack);
StatusBarNotificationsManager.getInstance(getApplicationContext())
.showTrackScrobblingStatusBarNotification(currentTrack);
updateNowPlaying(currentTrack);
} else {
StatusBarNotificationsManager.getInstance(getApplicationContext())
.hideTrackScrobblingStatusBarNotification();
WAILSettings.setNowScrobblingTrack(getApplicationContext(), null);
}
LocalBroadcastManager.getInstance(getApplicationContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
import com.artemzin.android.bytes.common.StringUtil;
import com.artemzin.android.wail.api.lastfm.model.response.LFUserResponseModel;
import com.artemzin.android.wail.service.WAILService;
import com.artemzin.android.wail.storage.model.Track;
import com.artemzin.android.wail.util.LocaleUtil;

import java.util.Locale;

public class WAILSettings {

private static final String APP_SETTINGS = "APP_SETTINGS";

// region keys
private static final String KEY_LOCALE = "KEY_LOCALE";
private static final String KEY_IS_ENABLED = "KEY_IS_ENABLED";
private static final String KEY_START_ON_BOOT = "KEY_START_ON_BOOT";
private static final String KEY_LASTFM_SESSION_KEY = "KEY_LASTFM_SESSION_KEY";
Expand All @@ -31,7 +36,10 @@ public class WAILSettings {
private static final String KEY_SOUND_NOTIFICATION_TRACK_MARKED_AS_SCROBBLED_ENABLED = "KEY_SOUND_NOTIFICATION_TRACK_MARKED_AS_SCROBBLED_ENABLED";
private static final String KEY_SOUND_NOTIFICATION_TRACK_SKIPPED_ENABLED = "KEY_SOUND_NOTIFICATION_TRACK_SKIPPED_ENABLED";

private static final String KEY_NOW_SCROBBLING_TRACK = "KEY_NOW_SCROBBLING_TRACK";
private static final String KEY_STATUS_BAR_NOTIFICATION_TRACK_SCROBBLING = "KEY_SOUND_NOTIFICATION_TRACK_MARKED_AS_SCROBBLED_ENABLED";

private static final String KEY_NOW_SCROBBLING_TRACK_ARTIST = "KEY_NOW_SCROBBLING_TRACK_ARTIST";
private static final String KEY_NOW_SCROBBLING_TRACK_TITLE = "KEY_NOW_SCROBBLING_TRACK_TITLE";

private static final String KEY_SHOULD_SHOW_NOTIFICATION_ABOUT_MIN_TRACK_DURATION_BEHAVIOR_CHANGED = "KEY_SHOULD_SHOW_NOTIFICATION_ABOUT_MIN_TRACK_DURATION_BEHAVIOR_CHANGED";

Expand All @@ -55,6 +63,8 @@ public class WAILSettings {

private static Boolean soundNotificationTrackScrobbledEnabled;
private static Boolean soundNotificationTrackSkippedEnabled;

private static Boolean statusBarNotificationTrackScrobblingEnabled;
// endregion

private WAILSettings() {}
Expand All @@ -79,6 +89,28 @@ public static synchronized void clearAllSettings(Context context) {
getSharedPreferences(context).edit().clear().commit();
}

public static synchronized String getLanguageOrNullIfAuto(Context context) {
String savedLang = getSharedPreferences(context).getString(KEY_LOCALE, null);

String defaultLang = Locale.getDefault().getDisplayLanguage();

if (savedLang == null) {
return null;
} else if (savedLang.equals(defaultLang) || savedLang.equals(LocaleUtil.lang(defaultLang))) {
return null;
} else {
return savedLang;
}
}

public static synchronized String getLanguage(Context context) {
return getSharedPreferences(context).getString(KEY_LOCALE, Locale.getDefault().getDisplayLanguage());
}

public static synchronized void setLanguage(Context context, String value) {
getSharedPreferences(context).edit().putString(KEY_LOCALE, value).commit();
}

public static synchronized boolean isAuthorized(Context context) {
return !StringUtil.isNullOrEmpty(getLastfmSessionKey(context));
}
Expand Down Expand Up @@ -250,12 +282,25 @@ public static synchronized void setShowFeedbackRequest(Context context, boolean
getSharedPreferences(context).edit().putBoolean(KEY_IS_SHOW_FEEDBACK_REQUEST, value).commit();
}

public static synchronized String getNowScrobblingTrack(Context context) {
return getSharedPreferences(context).getString(KEY_NOW_SCROBBLING_TRACK, null);
public static synchronized Track getNowScrobblingTrack(Context context) {
String artist = getSharedPreferences(context).getString(KEY_NOW_SCROBBLING_TRACK_ARTIST, null);
String title = getSharedPreferences(context).getString(KEY_NOW_SCROBBLING_TRACK_TITLE, null);
if (artist == null && title == null) {
return null;
}
Track track = new Track();
track.setArtist(artist);
track.setTrack(title);
return track;
}

public static synchronized void setNowScrobblingTrack(Context context, String value) {
getSharedPreferences(context).edit().putString(KEY_NOW_SCROBBLING_TRACK, value).commit();
public static synchronized void setNowScrobblingTrack(Context context, Track track) {
getSharedPreferences(context).edit().putString(KEY_NOW_SCROBBLING_TRACK_ARTIST,
track == null ? null : track.getArtist()
).commit();
getSharedPreferences(context).edit().putString(KEY_NOW_SCROBBLING_TRACK_TITLE,
track == null ? null : track.getTrack()
).commit();
}

public static boolean isDisableScrobblingOverMobileNetwork(Context context) {
Expand All @@ -268,4 +313,15 @@ public static void setDisableScrobblingOverMobileNetwork(Context context, boolea
disableScrobblingOverMobileNetwork = value;
getSharedPreferences(context).edit().putBoolean(KEY_DISABLE_SCROBBLING_OVER_MOBILE_NETWORK, value).commit();
}

public static boolean isStatusBarNotificationTrackScrobblingEnabled(Context context) {
return statusBarNotificationTrackScrobblingEnabled != null
? statusBarNotificationTrackScrobblingEnabled
: getSharedPreferences(context).getBoolean(KEY_STATUS_BAR_NOTIFICATION_TRACK_SCROBBLING, false);
}

public static void setStatusBarNotificationTrackScrobblingEnabled(Context context, boolean value) {
WAILSettings.statusBarNotificationTrackScrobblingEnabled = value;
getSharedPreferences(context).edit().putBoolean(KEY_STATUS_BAR_NOTIFICATION_TRACK_SCROBBLING, value).commit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.artemzin.android.wail.ui.activity.settings;

import android.os.Bundle;

import com.artemzin.android.wail.R;

public class SettingsSelectLanguageActivity extends BaseSettingsActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings_select_language);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.artemzin.android.wail.ui.activity.settings;

import android.os.Bundle;
import com.artemzin.android.wail.R;

/**
* @author Ilya Murzinov [murz42@gmail.com]
*/
public class SettingsStatusBarNotificationsActivity extends BaseSettingsActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings_status_bar_notifications);
}
}

Loading

0 comments on commit 2acf2be

Please sign in to comment.