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

Commit f957233

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents cafe421 + 757828b commit f957233

File tree

11 files changed

+90
-71
lines changed

11 files changed

+90
-71
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* InfosheetActivity.java
33
* Implements the app's infosheet activity
4-
* The infosheet activity sets up the infosheet html textview
4+
* The infosheet activity sets up infosheet screens for "About" and "How to"
55
*
66
* This file is part of
77
* TRANSISTOR - Radio App for Android
@@ -37,7 +37,6 @@ protected void onCreate(Bundle savedInstanceState) {
3737

3838
// get activity title from intent
3939
Intent intent = this.getIntent();
40-
String title = intent.getExtras().getString(EXTRA_INFOSHEET_TITLE);
4140

4241
// set activity title
4342
if (intent.hasExtra(EXTRA_INFOSHEET_TITLE)) {

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

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.y20k.transistor.core.Collection;
3535
import org.y20k.transistor.helpers.StorageHelper;
3636

37+
import java.io.File;
38+
3739

3840
/**
3941
* MainActivity class
@@ -49,16 +51,19 @@ public final class MainActivity extends AppCompatActivity {
4951
private static final String ACTION_CHANGE_VIEW_SELECTION = "org.y20k.transistor.action.CHANGE_VIEW_SELECTION";
5052
private static final String ACTION_COLLECTION_CHANGED = "org.y20k.transistor.action.COLLECTION_CHANGED";
5153
private static final String EXTRA_STATION_ID = "EXTRA_STATION_ID";
54+
private static final String EXTRA_STREAM_URI = "EXTRA_STREAM_URI";
5255
private static final String EXTRA_PLAYBACK_STATE = "EXTRA_PLAYBACK_STATE";
5356
private static final String ARG_STATION_ID = "ArgStationID";
5457
private static final String ARG_TWO_PANE = "ArgTwoPane";
5558
private static final String ARG_PLAYBACK = "ArgPlayback";
5659
private static final String PREF_TWO_PANE = "prefTwoPane";
60+
private static final String PREF_STATION_ID_SELECTED = "prefStationIDSelected";
5761
private static final String PLAYERFRAGMENT_TAG = "PFTAG";
5862

5963

6064
/* Main class variables */
6165
private boolean mTwoPane;
66+
private File mFolder;
6267
private Collection mCollection;
6368
private View mContainer;
6469

@@ -80,15 +85,18 @@ protected void onCreate(Bundle savedInstanceState) {
8085
protected void onResume() {
8186
super.onResume();
8287

88+
// get collection folder from external storage
89+
StorageHelper storageHelper = new StorageHelper(this);
90+
mFolder = storageHelper.getCollectionDirectory();
91+
8392

8493
// if player_container is present two-pane layout has been loaded
8594
mContainer = findViewById(R.id.player_container);
8695
mTwoPane = mContainer != null;
8796

8897

8998
// load collection
90-
StorageHelper storageHelper = new StorageHelper(this);
91-
mCollection = new Collection(storageHelper.getCollectionDirectory());
99+
mCollection = new Collection(mFolder);
92100

93101
// get intent
94102
Intent intent = getIntent();
@@ -103,11 +111,23 @@ protected void onResume() {
103111

104112
// get id of station from intent
105113
if (intent.hasExtra(EXTRA_STATION_ID)) {
114+
// get station from notification
106115
stationID = intent.getIntExtra(EXTRA_STATION_ID, 0);
107-
} else {
116+
} else if (intent.hasExtra(EXTRA_STREAM_URI)) {
117+
// get station from home screen shortcut
118+
stationID = mCollection.findStationID(intent.getStringExtra(EXTRA_STREAM_URI));
119+
}
120+
else {
121+
// default station
108122
stationID = 0;
109123
}
110124

125+
// save station id as selected station (TODO: put into saveAppState)
126+
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
127+
SharedPreferences.Editor editor = settings.edit();
128+
editor.putInt(PREF_STATION_ID_SELECTED, stationID);
129+
editor.apply();
130+
111131
// get playback action from intent
112132
if (intent.hasExtra(EXTRA_PLAYBACK_STATE)) {
113133
startPlayback = intent.getBooleanExtra(EXTRA_PLAYBACK_STATE, false);
@@ -205,11 +225,21 @@ private void initializeBroadcastReceivers() {
205225
BroadcastReceiver collectionChangedReceiver = new BroadcastReceiver() {
206226
@Override
207227
public void onReceive(Context context, Intent intent) {
228+
// load collection
229+
mCollection = new Collection(mFolder);
230+
208231
if (mTwoPane && mCollection.getStations().isEmpty()) {
209232
// make room for action call
210233
mContainer.setVisibility(View.GONE);
211-
} else if (mTwoPane) {
234+
} else if (mTwoPane && mCollection.getStations().size() == 1) {
212235
mContainer.setVisibility(View.VISIBLE);
236+
Bundle playerArgs = new Bundle();
237+
playerArgs.putBoolean(ARG_TWO_PANE, mTwoPane);
238+
PlayerActivityFragment playerActivityFragment = new PlayerActivityFragment();
239+
playerActivityFragment.setArguments(playerArgs);
240+
getFragmentManager().beginTransaction()
241+
.replace(R.id.player_container, playerActivityFragment, PLAYERFRAGMENT_TAG)
242+
.commit();
213243
}
214244
}
215245
};

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ public final class MainActivityFragment extends Fragment {
8383
private static final String ACTION_COLLECTION_CHANGED = "org.y20k.transistor.action.COLLECTION_CHANGED";
8484
private static final String EXTRA_COLLECTION_CHANGE = "COLLECTION_CHANGE";
8585
private static final String EXTRA_STATION_URI_CURRENT = "STATION_URI_CURRENT";
86-
private static final String EXTRA_STATION_NEW_NAME = "STATION_NEW_NAME";
87-
private static final String EXTRA_STATION_NEW_POSITION = "STATION_NEW_POSITION";
88-
private static final String EXTRA_STATION_OLD_POSITION = "STATION_OLD_POSITION";
89-
private static final String EXTRA_STATION_ADDED = "STATION_ADDED";
90-
private static final String EXTRA_STATION_RENAMED = "STATION_RENAMED";
91-
private static final String EXTRA_STATION_DELETED = "STATION_DELETED";
9286
private static final String EXTRA_STATION_ID = "STATION_ID";
9387
private static final String EXTRA_TIMER_REMAINING = "TIMER_REMAINING";
9488
private static final String EXTRA_INFOSHEET_TITLE = "INFOSHEET_TITLE";
@@ -116,9 +110,9 @@ public final class MainActivityFragment extends Fragment {
116110
private CollectionAdapter mCollectionAdapter = null;
117111
private File mFolder;
118112
private LinkedList<String> mStationNames;
119-
private LinkedList<Uri> mStationUris;
120113
private LinkedList<Bitmap> mStationImages;
121114
private View mRootView;
115+
private View mActionCallView;
122116
private RecyclerView mRecyclerView;
123117
private RecyclerView.LayoutManager mLayoutManager;
124118
private Parcelable mListState;
@@ -170,9 +164,8 @@ public void onCreate(Bundle savedInstanceState) {
170164

171165
// create adapter for collection
172166
mStationNames = new LinkedList<>();
173-
mStationUris = new LinkedList<>();
174167
mStationImages = new LinkedList<>();
175-
mCollectionAdapter = new CollectionAdapter(mActivity, mStationNames, mStationUris, mStationImages);
168+
mCollectionAdapter = new CollectionAdapter(mActivity, mStationNames, mStationImages);
176169

177170
// initialize broadcast receivers
178171
initializeBroadcastReceivers();
@@ -191,7 +184,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
191184
// inflate rootview from xml
192185
mRootView = inflater.inflate(R.layout.fragment_main, container, false);
193186

194-
// get reference to list view from inflated root view
187+
188+
// get reference to action call view from inflated root view
189+
mActionCallView = mRootView.findViewById(R.id.main_actioncall_layout);
190+
191+
// get reference to recycler list view from inflated root view
195192
mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.main_recyclerview_collection);
196193

197194
// use this setting to improve performance if you know that changes
@@ -219,7 +216,7 @@ public void onResume() {
219216
super.onResume();
220217

221218
// handle incoming intent
222-
handleNewStationIntent();
219+
handleIncomingIntent();
223220

224221
// refresh playback state
225222
loadAppState(mActivity);
@@ -312,9 +309,6 @@ private void fillCollectionAdapter() {
312309
// add name to linked list of names
313310
mStationNames.add(station.getStationName());
314311

315-
// add Uri to linked list of Uris
316-
mStationUris.add(station.getStreamUri());
317-
318312
// set image for station
319313
if (station.getStationImageFile().exists()) {
320314
// get image from collection
@@ -339,36 +333,33 @@ private void fillCollectionAdapter() {
339333
private void refreshStationList() {
340334

341335
// clear and refill mCollection adapter
342-
if (!mStationNames.isEmpty() && !mStationUris.isEmpty() && !mStationImages.isEmpty()) {
336+
if (!mStationNames.isEmpty() && !mStationImages.isEmpty()) {
343337
mStationNames.clear();
344-
mStationUris.clear();
345338
mStationImages.clear();
346339
}
347340
fillCollectionAdapter();
348341

349342
// show call to action, if necessary
350-
View actioncall = mRootView.findViewById(R.id.main_actioncall_layout);
351-
View recyclerview = mRootView.findViewById(R.id.main_recyclerview_collection);
352343
if (mCollectionAdapter.getItemCount() == 0) {
353-
actioncall.setVisibility(View.VISIBLE);
354-
recyclerview.setVisibility(View.GONE);
344+
mActionCallView.setVisibility(View.VISIBLE);
345+
mRecyclerView.setVisibility(View.GONE);
355346
} else {
356-
actioncall.setVisibility(View.GONE);
357-
recyclerview.setVisibility(View.VISIBLE);
347+
mActionCallView.setVisibility(View.GONE);
348+
mRecyclerView.setVisibility(View.VISIBLE);
358349
}
359350

360351
Log.v(LOG_TAG, "Refreshing list of stations");
361352

362353
}
363354

364355

365-
/* handles external taps on streaming links */
366-
private void handleNewStationIntent() {
356+
/* handles incoming intent */
357+
private void handleIncomingIntent() {
367358

368359
// get intent
369360
Intent intent = mActivity.getIntent();
370361

371-
// check for intent of tyoe VIEW
362+
// handles external taps on streaming links
372363
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
373364

374365
mNewStationUri = intent.getData();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* PlayerActivity.java
33
* Implements the app's player activity
4-
* The player activity sets up the now playing view and inflates a menubar menu
4+
* The player activity sets up the now playing view for phone mode and inflates a menubar menu
55
*
66
* This file is part of
77
* TRANSISTOR - Radio App for Android
@@ -48,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
4848
Intent intent = getIntent();
4949

5050
// CASE: show player in phone mode
51-
if (intent != null && ACTION_SHOW_PLAYER.equals(intent.getAction()) && savedInstanceState == null) {
51+
if (intent != null && ACTION_SHOW_PLAYER.equals(intent.getAction())) {
5252

5353
// get id of station from intent
5454
int stationID;

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

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public final class PlayerActivityFragment extends Fragment {
7474
private static final String ACTION_PLAYBACK_STOPPED = "org.y20k.transistor.action.PLAYBACK_STOPPED";
7575
private static final String ACTION_CREATE_SHORTCUT_REQUESTED = "org.y20k.transistor.action.CREATE_SHORTCUT_REQUESTED";
7676
private static final String EXTRA_COLLECTION_CHANGE = "COLLECTION_CHANGE";
77-
private static final String EXTRA_STATION_NEW_POSITION = "STATION_NEW_POSITION";
7877
private static final String EXTRA_STATION_NEW_NAME = "STATION_NEW_NAME";
79-
private static final String EXTRA_STATION_DELETED = "STATION_DELETED";
8078
private static final String EXTRA_STATION_ID = "STATION_ID";
8179
private static final String ARG_STATION_ID = "ArgStationID";
8280
private static final String ARG_TWO_PANE = "ArgTwoPane";
@@ -146,13 +144,6 @@ public void onCreate(Bundle savedInstanceState) {
146144
mTwoPane = false;
147145
}
148146

149-
// // set station ID if not in arguments
150-
// if (mStationID == -1 && mStationIDCurrent == -1) {
151-
// mStationID = 0;
152-
// } else if (mStationID == -1 ) {
153-
// mStationID = mStationIDCurrent;
154-
// }
155-
156147
// get URL and name for stream
157148
mStreamUri = mCollection.getStations().get(mStationID).getStreamUri().toString();
158149
mStationName = mCollection.getStations().get(mStationID).getStationName();
@@ -230,7 +221,7 @@ public void onClick(View view) {
230221
@Override
231222
public void onViewCreated(View view, Bundle savedInstanceState) {
232223
super.onViewCreated(view, savedInstanceState);
233-
setVisualState();
224+
// setVisualState();
234225
}
235226

236227

@@ -539,7 +530,7 @@ private void loadAppState(Context context) {
539530
mStationIDLast = settings.getInt(PREF_STATION_ID_LAST, -1);
540531
mStationID = settings.getInt(PREF_STATION_ID_SELECTED, 0);
541532
mPlayback = settings.getBoolean(PREF_PLAYBACK, false);
542-
Log.v(LOG_TAG, "Loading state ("+ mStationIDCurrent + " / " + mStationIDLast + " / " + mPlayback + ")");
533+
Log.v(LOG_TAG, "Loading state ("+ mStationIDCurrent + " / " + mStationIDLast + " / " + mPlayback + " / " + mStationID + ")");
543534
}
544535

545536

@@ -632,6 +623,32 @@ private void handleCollectionChanges(Intent intent) {
632623
startActivity(mainActivityStartIntent);
633624
// finish player activity
634625
mActivity.finish();
626+
} else {
627+
// get collection from external storage
628+
StorageHelper storageHelper = new StorageHelper(mActivity);
629+
mCollection = new Collection(storageHelper.getCollectionDirectory());
630+
631+
int collectionSize = mCollection.getStations().size();
632+
633+
if (mStationID > collectionSize) {
634+
// station at the end of the list was deleted
635+
mStationID = collectionSize - 1;
636+
}
637+
638+
if (collectionSize != 0 && mStationID >= 0) {
639+
// get URL and name for stream
640+
mStreamUri = mCollection.getStations().get(mStationID).getStreamUri().toString();
641+
mStationName = mCollection.getStations().get(mStationID).getStationName();
642+
643+
mStationNameView.setText(mStationName);
644+
645+
// set station image
646+
Bitmap stationImage = createStationImage();
647+
if (stationImage != null) {
648+
mStationImageView.setImageBitmap(stationImage);
649+
}
650+
}
651+
635652
}
636653
break;
637654
}

app/src/main/java/org/y20k/transistor/helpers/CollectionAdapter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import android.content.IntentFilter;
2222
import android.content.SharedPreferences;
2323
import android.graphics.Bitmap;
24-
import android.net.Uri;
2524
import android.os.Bundle;
2625
import android.os.Vibrator;
2726
import android.preference.PreferenceManager;
@@ -67,7 +66,6 @@ public final class CollectionAdapter extends RecyclerView.Adapter<CollectionAda
6766

6867
/* Main class variables */
6968
private final LinkedList<String> mStationNames;
70-
private final LinkedList<Uri> mStationUris;
7169
private final LinkedList<Bitmap> mStationImages;
7270
private final Activity mActivity;
7371
private final PlayerService mPlayerService;
@@ -88,11 +86,10 @@ public interface CollectionChangedListener {
8886

8987

9088
/* Constructor */
91-
public CollectionAdapter(Activity activity, LinkedList<String> stationNames, LinkedList<Uri> stationUris, LinkedList<Bitmap> stationImage) {
89+
public CollectionAdapter(Activity activity, LinkedList<String> stationNames, LinkedList<Bitmap> stationImage) {
9290
// set main variables
9391
mActivity = activity;
9492
mStationNames = stationNames;
95-
mStationUris = stationUris;
9693
mStationImages = stationImage;
9794
mCollection = null;
9895
mCollectionChangedListener = null;
@@ -185,7 +182,7 @@ public void onClick(View view) {
185182
public void onClick(View view, int pos, boolean isLongClick) {
186183
mStationIDSelected = pos;
187184
saveAppState(mActivity);
188-
Log.v(LOG_TAG, "!!! sel-pos: " + mStationIDSelected);
185+
Log.v(LOG_TAG, "Selected station (ID): " + mStationIDSelected);
189186
if (isLongClick && !mTwoPane) {
190187
// long click in phone mode
191188
handleLongClick(pos);

app/src/main/java/org/y20k/transistor/helpers/NotificationHelper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@
3333
*/
3434
public final class NotificationHelper {
3535

36+
/* Define log tag */
37+
private static final String LOG_TAG = NotificationHelper.class.getSimpleName();
38+
39+
3640
/* Keys */
3741
private static final int PLAYER_SERVICE_NOTIFICATION_ID = 1;
3842
private static final String ACTION_STOP = "org.y20k.transistor.action.STOP";
3943
private static final String ACTION_SHOW_PLAYER = "org.y20k.transistor.action.SHOW_PLAYER";
4044
private static final String EXTRA_STATION_ID = "EXTRA_STATION_ID";
41-
private static final String EXTRA_PLAYBACK_STATE = "EXTRA_PLAYBACK_STATE";
4245

4346

4447
/* Main class variables */

0 commit comments

Comments
 (0)