Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 2db314f

Browse files
committed
bug fixes: renaming, adding, deleting stations while playback should work properly again
1 parent e909caf commit 2db314f

File tree

12 files changed

+246
-75
lines changed

12 files changed

+246
-75
lines changed

app/app.iml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@
6464
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
6565
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
6666
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
67-
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
68-
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
69-
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
70-
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
71-
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
72-
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
73-
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
74-
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
7567
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
7668
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
7769
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
@@ -80,6 +72,14 @@
8072
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
8173
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
8274
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
8383
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
8484
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
8585
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
@@ -113,11 +113,11 @@
113113
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
114114
<orderEntry type="sourceFolder" forTests="false" />
115115
<orderEntry type="library" exported="" name="design-23.4.0" level="project" />
116+
<orderEntry type="library" exported="" name="appcompat-v7-23.4.0" level="project" />
116117
<orderEntry type="library" exported="" name="support-annotations-23.4.0" level="project" />
117118
<orderEntry type="library" exported="" name="animated-vector-drawable-23.4.0" level="project" />
118-
<orderEntry type="library" exported="" name="support-v4-23.4.0" level="project" />
119-
<orderEntry type="library" exported="" name="recyclerview-v7-23.4.0" level="project" />
120119
<orderEntry type="library" exported="" name="support-vector-drawable-23.4.0" level="project" />
121-
<orderEntry type="library" exported="" name="appcompat-v7-23.4.0" level="project" />
120+
<orderEntry type="library" exported="" name="recyclerview-v7-23.4.0" level="project" />
121+
<orderEntry type="library" exported="" name="support-v4-23.4.0" level="project" />
122122
</component>
123123
</module>

app/src/main/java/org/y20k/transistor/MainActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ private void initializeBroadcastReceivers() {
242242
@Override
243243
public void onReceive(Context context, Intent intent) {
244244

245+
// get collection from intent
246+
if (intent.hasExtra(TransistorKeys.EXTRA_COLLECTION)) {
247+
mCollection = intent.getParcelableExtra(TransistorKeys.EXTRA_COLLECTION);
248+
}
249+
250+
// show/hide player layout container
245251
if (mTwoPane && mCollection.getStations().isEmpty()) {
246252
// make room for action call
247253
mContainer.setVisibility(View.GONE);

app/src/main/java/org/y20k/transistor/MainActivityFragment.java

Lines changed: 130 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import org.y20k.transistor.core.Collection;
4848
import org.y20k.transistor.core.Station;
4949
import org.y20k.transistor.helpers.CollectionAdapter;
50-
import org.y20k.transistor.helpers.DialogAddStation;
50+
import org.y20k.transistor.helpers.DialogAdd;
5151
import org.y20k.transistor.helpers.ImageHelper;
5252
import org.y20k.transistor.helpers.NotificationHelper;
5353
import org.y20k.transistor.helpers.ShortcutHelper;
@@ -221,7 +221,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
221221
// CASE ADD
222222
case R.id.menu_add:
223223

224-
DialogAddStation dialog = new DialogAddStation(mActivity, mCollection);
224+
DialogAdd dialog = new DialogAdd(mActivity, mCollection);
225225
dialog.show();
226226
return true;
227227

@@ -480,7 +480,7 @@ else if (mPlayback && !mSleepTimerRunning) {
480480
// CASE: A station is playing, Sleep timer is running
481481
else if (mPlayback) {
482482
startSleepTimer(duration);
483-
Toast.makeText(mActivity, mActivity.getString(R.string.toastmessage_timer_duration_increased) + " [+" + getReadableTime(duration) +"]", Toast.LENGTH_SHORT).show();
483+
Toast.makeText(mActivity, mActivity.getString(R.string.toastmessage_timer_duration_increased) + " [+" + getReadableTime(duration) + "]", Toast.LENGTH_SHORT).show();
484484
}
485485

486486
}
@@ -548,7 +548,7 @@ public void onClick(View view) {
548548

549549

550550
/* Translates milliseconds into minutes and seconds */
551-
private String getReadableTime (long remainingTime) {
551+
private String getReadableTime(long remainingTime) {
552552
return String.format(Locale.getDefault(), "%02d:%02d",
553553
TimeUnit.MILLISECONDS.toMinutes(remainingTime),
554554
TimeUnit.MILLISECONDS.toSeconds(remainingTime) -
@@ -559,7 +559,7 @@ private String getReadableTime (long remainingTime) {
559559
/* Loads app state from preferences */
560560
private void loadAppState(Context context) {
561561
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
562-
mStationIDCurrent = settings.getInt(TransistorKeys.PREF_STATION_ID_CURRENT, -1);
562+
mStationIDCurrent = settings.getInt(TransistorKeys.PREF_STATION_ID_CURRENTLY_PLAYING, -1);
563563
mStationIDLast = settings.getInt(TransistorKeys.PREF_STATION_ID_LAST, -1);
564564
mPlayback = settings.getBoolean(TransistorKeys.PREF_PLAYBACK, false);
565565
mSleepTimerRunning = settings.getBoolean(TransistorKeys.PREF_TIMER_RUNNING, false);
@@ -571,7 +571,7 @@ private void loadAppState(Context context) {
571571
private void saveAppState(Context context) {
572572
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
573573
SharedPreferences.Editor editor = settings.edit();
574-
editor.putInt(TransistorKeys.PREF_STATION_ID_CURRENT, mStationIDCurrent);
574+
editor.putInt(TransistorKeys.PREF_STATION_ID_CURRENTLY_PLAYING, mStationIDCurrent);
575575
editor.putInt(TransistorKeys.PREF_STATION_ID_LAST, mStationIDLast);
576576
editor.putBoolean(TransistorKeys.PREF_PLAYBACK, mPlayback);
577577
editor.putBoolean(TransistorKeys.PREF_TIMER_RUNNING, mSleepTimerRunning);
@@ -628,6 +628,7 @@ public void onReceive(Context context, Intent intent) {
628628
public void onReceive(Context context, Intent intent) {
629629
if (intent != null && intent.hasExtra(TransistorKeys.EXTRA_COLLECTION_CHANGE)) {
630630
handleCollectionChanges(intent);
631+
// handleCollectionChangesNew(intent); // un-comment to test new animations
631632
}
632633
}
633634
};
@@ -715,56 +716,167 @@ private void handleCollectionChanges(Intent intent) {
715716

716717
// CASE: station was added
717718
case TransistorKeys.STATION_ADDED:
719+
// get updated collection
718720
if (intent.hasExtra(TransistorKeys.EXTRA_COLLECTION)) {
719721
mCollection = intent.getParcelableExtra(TransistorKeys.EXTRA_COLLECTION);
722+
mCollectionAdapter.setCollection(mCollection);
720723
}
724+
// get id of currently playing station
725+
if (intent.hasExtra(TransistorKeys.EXTRA_STATION_ID_CURRENTLY_PLAYING)) {
726+
mStationIDCurrent = intent.getIntExtra(TransistorKeys.EXTRA_STATION_ID_CURRENTLY_PLAYING, -1);
727+
}
728+
729+
// save app state
730+
saveAppState(mActivity);
731+
721732
// refresh collection adapter and station list
722733
mCollectionAdapter.refresh();
723734
refreshStationList();
735+
724736
break;
725737

726738
// CASE: station was renamed
727739
case TransistorKeys.STATION_RENAMED:
728-
// keep track of playback state
729-
if (mPlayback && intent.hasExtra(TransistorKeys.EXTRA_STATION_ID) && intent.hasExtra(TransistorKeys.EXTRA_STATION_URI_CURRENT)) {
740+
// get flag for deletion of currently playing station
741+
boolean stationCurrentlyPlayingRenamed = false;
742+
if (intent.hasExtra(TransistorKeys.EXTRA_STATION_CURRENTLY_PLAYING_RENAMED)) {
743+
stationCurrentlyPlayingRenamed = intent.getBooleanExtra(TransistorKeys.EXTRA_STATION_CURRENTLY_PLAYING_RENAMED, false);
744+
}
730745

731-
// retrieve and save ID of currently playing station from Uri
732-
mStationIDCurrent = mCollection.findStationID(intent.getStringExtra(TransistorKeys.EXTRA_STATION_URI_CURRENT));
733-
saveAppState(mActivity);
746+
// get id of currently playing station
747+
if (intent.hasExtra(TransistorKeys.EXTRA_STATION_ID_CURRENTLY_PLAYING)) {
748+
mStationIDCurrent = intent.getIntExtra(TransistorKeys.EXTRA_STATION_ID_CURRENTLY_PLAYING, -1);
749+
}
750+
751+
// get updated collection
752+
if (intent.hasExtra(TransistorKeys.EXTRA_COLLECTION)) {
753+
mCollection = intent.getParcelableExtra(TransistorKeys.EXTRA_COLLECTION);
754+
mCollectionAdapter.setCollection(mCollection);
755+
}
734756

757+
// keep track of playback state
758+
if (stationCurrentlyPlayingRenamed && intent.hasExtra(TransistorKeys.EXTRA_STATION_NEW_NAME)) {
735759
// put up notification
736760
NotificationHelper.initialize(mCollection);
737-
NotificationHelper.setStationName(mCollection.getStations().get(mStationIDCurrent).getStationName());
761+
NotificationHelper.setStationName(intent.getStringExtra(TransistorKeys.EXTRA_STATION_NEW_NAME));
738762
NotificationHelper.setStationID(mStationIDCurrent);
739763
NotificationHelper.updateNotification();
740764
}
741765

766+
// save app state
767+
saveAppState(mActivity);
768+
742769
// refresh collection adapter and station list
743770
mCollectionAdapter.refresh();
744771
refreshStationList();
772+
745773
break;
746774

747775
// CASE: station was deleted
748776
case TransistorKeys.STATION_DELETED:
749-
// keep track of playback state
750-
if (mPlayback && intent.hasExtra(TransistorKeys.EXTRA_STATION_ID) && mStationIDCurrent == intent.getIntExtra(TransistorKeys.EXTRA_STATION_ID, -1)) {
777+
// get flag for deletion of currently playing station
778+
boolean stationCurrentlyPlayingDeleted = false;
779+
if (intent.hasExtra(TransistorKeys.EXTRA_STATION_CURRENTLY_PLAYING_DELETED)) {
780+
stationCurrentlyPlayingDeleted = intent.getBooleanExtra(TransistorKeys.EXTRA_STATION_CURRENTLY_PLAYING_DELETED, false);
781+
}
782+
783+
// get id of currently playing station
784+
if (intent.hasExtra(TransistorKeys.EXTRA_STATION_ID_CURRENTLY_PLAYING)) {
785+
mStationIDCurrent = intent.getIntExtra(TransistorKeys.EXTRA_STATION_ID_CURRENTLY_PLAYING, -1);
786+
}
787+
788+
// get updated collection
789+
if (intent.hasExtra(TransistorKeys.EXTRA_COLLECTION)) {
790+
mCollection = intent.getParcelableExtra(TransistorKeys.EXTRA_COLLECTION);
791+
mCollectionAdapter.setCollection(mCollection);
792+
}
793+
794+
// stop playback if necessary
795+
if (stationCurrentlyPlayingDeleted) {
751796
mPlayback = false;
752797
PlayerService.startActionStop(mActivity);
753-
saveAppState(mActivity);
754-
} else if (mPlayback && intent.hasExtra(TransistorKeys.EXTRA_STATION_URI_CURRENT)) {
755-
mStationIDCurrent = mCollection.findStationID(intent.getStringExtra(TransistorKeys.EXTRA_STATION_URI_CURRENT));
756-
saveAppState(mActivity);
757798
}
758799

800+
// save app state
801+
saveAppState(mActivity);
802+
759803
// refresh collection adapter and station list
760804
mCollectionAdapter.refresh();
761805
refreshStationList();
806+
762807
break;
763808

764809
// TODO station was renamed in PlayerActivityFragment (playback indicator in list)
765810

766811
}
767812

813+
814+
815+
}
816+
817+
818+
/* Handles adding, deleting and renaming of station (New experimental version - unfinished) */
819+
private void handleCollectionChangesNew(Intent intent) {
820+
821+
// load app state
822+
loadAppState(mActivity);
823+
824+
// get updated collection from intent
825+
if (intent.hasExtra(TransistorKeys.EXTRA_COLLECTION)) {
826+
mCollection = intent.getParcelableExtra(TransistorKeys.EXTRA_COLLECTION);
827+
}
828+
829+
switch (intent.getIntExtra(TransistorKeys.EXTRA_COLLECTION_CHANGE, 1)) {
830+
831+
// CASE: station was added
832+
case TransistorKeys.STATION_ADDED:
833+
if (intent.hasExtra(TransistorKeys.EXTRA_STATION_ID) && intent.hasExtra(TransistorKeys.EXTRA_STATION)) {
834+
int stationID = intent.getIntExtra(TransistorKeys.EXTRA_STATION_ID, 0);
835+
Station station = intent.getParcelableExtra(TransistorKeys.EXTRA_STATION);
836+
mCollectionAdapter.add(stationID, station);
837+
mCollectionAdapter.setCollection(mCollection);
838+
// mCollectionAdapter.refresh();
839+
}
840+
// mLayoutManager.addView(1);
841+
break;
842+
843+
// CASE: station was renamed
844+
case TransistorKeys.STATION_RENAMED:
845+
846+
if (intent.hasExtra(TransistorKeys.EXTRA_STATION_ID) && intent.hasExtra(TransistorKeys.EXTRA_STATION_NEW_NAME)) {
847+
int stationID = intent.getIntExtra(TransistorKeys.EXTRA_STATION_ID, 0);
848+
String newStationName = intent.getStringExtra(TransistorKeys.EXTRA_STATION_NEW_NAME);
849+
mCollectionAdapter.change(stationID, newStationName);
850+
mCollectionAdapter.setCollection(mCollection);
851+
// mCollectionAdapter.refresh();
852+
853+
int stationIndexChanged = mCollection.getStationIndexChanged();
854+
if (stationIndexChanged != -1) {
855+
// position of station has changed
856+
View stationImageView = mLayoutManager.getChildAt(stationID);
857+
mLayoutManager.removeViewAt(stationID);
858+
mLayoutManager.addView(stationImageView, stationIndexChanged);
859+
}
860+
861+
}
862+
863+
break;
864+
865+
// CASE: station was deleted
866+
case TransistorKeys.STATION_DELETED:
867+
868+
if (intent.hasExtra(TransistorKeys.EXTRA_STATION_ID)) {
869+
int stationID = intent.getIntExtra(TransistorKeys.EXTRA_STATION_ID, 0);
870+
mCollectionAdapter.remove(stationID);
871+
mCollectionAdapter.setCollection(mCollection);
872+
mCollectionAdapter.refresh();
873+
mLayoutManager.removeViewAt(stationID);
874+
}
875+
876+
break;
877+
878+
}
879+
768880
}
769881

770882
}

app/src/main/java/org/y20k/transistor/PlayerActivityFragment.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ public void onResume() {
233233
// check if activity started from shortcut
234234
Bundle arguments = getArguments();
235235
if (arguments != null && arguments.getBoolean(TransistorKeys.ARG_PLAYBACK)) {
236-
Log.v(LOG_TAG,"!!! arg playback received");
237236
// check if this station is not already playing
238237
if (mStationIDCurrent == mStationID && mPlayback) {
239238
// do nothing
@@ -549,7 +548,7 @@ private void setStationState() {
549548
private void saveAppState(Context context) {
550549
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
551550
SharedPreferences.Editor editor = settings.edit();
552-
editor.putInt(TransistorKeys.PREF_STATION_ID_CURRENT, mStationIDCurrent);
551+
editor.putInt(TransistorKeys.PREF_STATION_ID_CURRENTLY_PLAYING, mStationIDCurrent);
553552
editor.putInt(TransistorKeys.PREF_STATION_ID_LAST, mStationIDLast);
554553
editor.putString(TransistorKeys.PREF_STATION_METADATA, mStationMetadata);
555554
editor.putBoolean(TransistorKeys.PREF_PLAYBACK, mPlayback);
@@ -561,7 +560,7 @@ private void saveAppState(Context context) {
561560
/* Loads app state from preferences */
562561
private void loadAppState(Context context) {
563562
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
564-
mStationIDCurrent = settings.getInt(TransistorKeys.PREF_STATION_ID_CURRENT, -1);
563+
mStationIDCurrent = settings.getInt(TransistorKeys.PREF_STATION_ID_CURRENTLY_PLAYING, -1);
565564
mStationIDLast = settings.getInt(TransistorKeys.PREF_STATION_ID_LAST, -1);
566565
mStationID = settings.getInt(TransistorKeys.PREF_STATION_ID_SELECTED, 0);
567566
mStationMetadata = settings.getString(TransistorKeys.PREF_STATION_METADATA, null);
@@ -628,6 +627,7 @@ private void handleCollectionChanges(Intent intent) {
628627
startActivity(mainActivityStartIntent);
629628
// finish player activity
630629
mActivity.finish();
630+
631631
} else if (mTwoPane) {
632632

633633
// get collection from external storage
@@ -681,7 +681,6 @@ public void onReceive(Context context, Intent intent) {
681681
changeVisualState(context);
682682

683683
// save state of playback to settings
684-
Log.v(LOG_TAG, "playbackStoppedReceiver: saving state");
685684
saveAppState(context);
686685
}
687686
}
@@ -705,7 +704,6 @@ public void onReceive(Context context, Intent intent) {
705704
// save state of playback to settings
706705
mStationIDLast = mStationIDCurrent;
707706
mStationIDCurrent = mStationID;
708-
Log.v(LOG_TAG, "playbackStartedReceiver: saving state");
709707
saveAppState(context);
710708
}
711709
}

0 commit comments

Comments
 (0)