Skip to content

Commit

Permalink
Merge pull request trikita#14 from l2dy/master
Browse files Browse the repository at this point in the history
Allow ringtones from file managers
  • Loading branch information
zserge authored Oct 24, 2016
2 parents 132c7c7 + c47bb94 commit 8701347
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ env:
android:
components:
- tools
- build-tools-24.0.0
- android-23
- build-tools-25.0.0
- android-25

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
Expand Down
12 changes: 5 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.6'
}
}
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'android-apt'

android {
compileSdkVersion 'android-23'
buildToolsVersion '24.0.0'
compileSdkVersion 'android-25'
buildToolsVersion '25.0.0'

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
targetSdkVersion 25
versionCode 19
versionName '3.9'
}
Expand Down Expand Up @@ -55,7 +53,7 @@ dependencies {
compile 'com.github.trikita:promote:-SNAPSHOT'
compile 'co.trikita:anvil-sdk15:0.3.1'
compile 'org.immutables:gson:2.1.14'
apt 'org.immutables:value:2.1.14'
annotationProcessor 'org.immutables:value:2.1.14'
provided 'org.immutables:value:2.1.14'
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
10 changes: 3 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ case "`uname`" in
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
Expand All @@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

Expand Down Expand Up @@ -114,6 +109,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/trikita/talalarmo/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public class App extends Application {

private Store<Action, State> store;

public static State dispatch(Action action) {
return instance.store.dispatch(action);
}

public static State getState() {
return instance.store.getState();
}

@Override
public void onCreate() {
super.onCreate();
Expand All @@ -34,12 +42,4 @@ public void onCreate() {

this.store.subscribe(Anvil::render);
}

public static State dispatch(Action action) {
return instance.store.dispatch(action);
}

public static State getState() {
return instance.store.getState();
}
}
6 changes: 3 additions & 3 deletions src/main/java/trikita/talalarmo/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
break;
case "ringtone_setting":
String s = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM).toString();
if (prefs.getString(key, s).startsWith("content://media/external/audio/media/") &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& prefs.getString(key, s).startsWith("content://media/external/")
&& checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
}
App.dispatch(new Action<>(Actions.Settings.SET_RINGTONE, prefs.getString(key, s)));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/trikita/talalarmo/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
@Gson.TypeAdapters
public interface State {

Settings settings();

Alarm alarm();

@Value.Immutable
interface Settings {
boolean vibrate();
Expand Down Expand Up @@ -51,10 +55,6 @@ public Calendar nextAlarm() {
}
}

Settings settings();

Alarm alarm();

class Default {
public static State build() {
return ImmutableState.builder()
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/trikita/talalarmo/alarm/AlarmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ private void startPlayer() {
}
// Player setup is here
String ringtone = App.getState().settings().ringtone();
if (ringtone.startsWith("content://media/external/audio/media/") &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& ringtone.startsWith("content://media/external/")
&& checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM).toString();
}
mPlayer.setDataSource(this, Uri.parse(ringtone));
Expand All @@ -127,6 +127,8 @@ private void startPlayer() {

if (App.getState().settings().ramping()) {
mHandler.postDelayed(mVolumeRunnable, VOLUME_INCREASE_DELAY);
} else {
mPlayer.setVolume(MAX_VOLUME, MAX_VOLUME);
}
} catch (Exception e) {
if (mPlayer.isPlaying()) {
Expand Down

0 comments on commit 8701347

Please sign in to comment.