Skip to content

Commit

Permalink
Merge pull request #60 from tobexyz/feat/issue20
Browse files Browse the repository at this point in the history
Feat/issue20
  • Loading branch information
tobexyz authored Jan 16, 2023
2 parents 7e3ec5d + ba6ed0f commit 94b98e8
Show file tree
Hide file tree
Showing 102 changed files with 687 additions and 838 deletions.
10 changes: 5 additions & 5 deletions yaacc.puml
Original file line number Diff line number Diff line change
Expand Up @@ -8301,7 +8301,7 @@ class org.fourthline.cling.support.model.ProtocolInfo {
+ int hashCode()
+ String toString()
}
class de.yaacc.browser.BrowseItemAdapter {
class de.yaacc.browser.BrowseContentItemAdapter {
- {static} long CHUNK_SIZE
+ {static} Item LOAD_MORE_FAKE_ITEM
- {static} Item LOADING_FAKE_ITEM
Expand Down Expand Up @@ -8335,7 +8335,7 @@ class de.yaacc.browser.BrowseItemAdapter {
+ void onScroll(AbsListView,int,int,int)
+ void loadMore()
}
class de.yaacc.browser.BrowseItemAdapter.ViewHolder {
class de.yaacc.browser.BrowseContentItemAdapter.ViewHolder {
~ ImageView icon
~ TextView name
}
Expand Down Expand Up @@ -14508,9 +14508,9 @@ de.yaacc.R +.. de.yaacc.R.xml
java.util.logging.Handler <|-- org.fourthline.cling.android.FixedAndroidLogHandler
org.fourthline.cling.model.types.AbstractDatatype <|-- org.fourthline.cling.model.types.BooleanDatatype
org.fourthline.cling.controlpoint.ActionCallback <|-- org.fourthline.cling.support.renderingcontrol.callback.GetMute
de.yaacc.browser.OnScrollListener <|.. de.yaacc.browser.BrowseItemAdapter
android.widget.BaseAdapter <|-- de.yaacc.browser.BrowseItemAdapter
de.yaacc.browser.BrowseItemAdapter +.. de.yaacc.browser.BrowseItemAdapter.ViewHolder
de.yaacc.browser.OnScrollListener <|.. de.yaacc.browser.BrowseContentItemAdapter
android.widget.BaseAdapter <|-- de.yaacc.browser.BrowseContentItemAdapter
de.yaacc.browser.BrowseContentItemAdapter +.. de.yaacc.browser.BrowseContentItemAdapter.ViewHolder
org.fourthline.cling.transport.spi.Runnable <|-- org.fourthline.cling.transport.spi.DatagramIO
org.fourthline.cling.model.message.discovery.OutgoingSearchResponse <|-- org.fourthline.cling.model.message.discovery.OutgoingSearchResponseUDN
org.fourthline.cling.transport.spi.StreamClientConfiguration <|.. org.fourthline.cling.transport.spi.AbstractStreamClientConfiguration
Expand Down
21 changes: 5 additions & 16 deletions yaacc/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity
android:name=".browser.TabBrowserActivity"
Expand All @@ -45,6 +45,10 @@
<service
android:name=".upnp.UpnpRegistryService"
android:enabled="true" />
<service
android:name=".player.PlayerService"
android:enabled="true"
android:exported="false" />
<service
android:name=".musicplayer.BackgroundMusicService"
android:enabled="true" />
Expand Down Expand Up @@ -91,17 +95,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".player.ThirdPartieMusicPlayerActivity"
android:exported="true"
android:label="@string/title_activity_music_player">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".player.AVTransportPlayerActivity"
android:exported="true"
Expand Down Expand Up @@ -154,10 +147,6 @@
</intent-filter>
</activity>

<service
android:name=".player.PlayerService"
android:enabled="true"
android:exported="false" />
</application>

</manifest>
15 changes: 13 additions & 2 deletions yaacc/src/main/java/de/yaacc/Yaacc.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package de.yaacc;


import android.app.ActivityManager;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand All @@ -31,6 +32,7 @@
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.NotificationCompat;

import java.util.HashMap;
Expand Down Expand Up @@ -65,6 +67,13 @@ public void onCreate() {
createNotificationChannel();
upnpClient = new UpnpClient(this);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean darkMode = preferences.getBoolean(getString(R.string.settings_dark_mode_key), true);
if (darkMode) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}

int numThreads = Integer.parseInt(preferences.getString(getString(R.string.settings_browse_load_threads_key), "10"));
Log.d(getClass().getName(), "Number of Threads used for content loading: " + numThreads);
if (numThreads <= 0) {
Expand Down Expand Up @@ -129,7 +138,7 @@ public void releaseWakeLock(String tag) {
}

public void exit() {
int p = android.os.Process.myPid();
Log.d(getClass().getName(), "Start shutdown and close");
upnpClient.shutdown();
stopService(new Intent(this, PlayerService.class));
stopService(new Intent(this, BackgroundMusicService.class));
Expand All @@ -142,7 +151,9 @@ public void exit() {
mNotificationManager.cancel(NotificationId.UPNP_SERVER.getId());
mNotificationManager.cancel(NotificationId.PLAYER_SERVICE.getId());
mNotificationManager.cancel(NotificationId.YAACC.getId());
android.os.Process.killProcess(p);
ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
am.getAppTasks().stream().forEach(t -> t.finishAndRemoveTask());
Runtime.getRuntime().exit(0);
}

private void createNotificationChannel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@

import de.yaacc.R;
import de.yaacc.Yaacc;
import de.yaacc.util.ThemeHelper;
import de.yaacc.util.image.IconDownloadTask;

/**
* Adapter for browsing devices.
*
* @author Christoph Haehnel (eyeless)
*/
public class BrowseItemAdapter extends BaseAdapter implements AbsListView.OnScrollListener {
public class BrowseContentItemAdapter extends BaseAdapter implements AbsListView.OnScrollListener {
public static final Item LOAD_MORE_FAKE_ITEM = new Item("LoadMoreFakeItem", (String) null, "...", "", (DIDLObject.Class) null);

private static final Item LOADING_FAKE_ITEM = new Item("LoadingFakeItem", (String) null, "Loading...", "", (DIDLObject.Class) null);
Expand All @@ -71,7 +72,7 @@ public class BrowseItemAdapter extends BaseAdapter implements AbsListView.OnScro
private boolean allItemsFetched;


public BrowseItemAdapter(Context ctx, Navigator navigator) {
public BrowseContentItemAdapter(Context ctx, Navigator navigator) {
initialize(ctx, navigator);
}

Expand Down Expand Up @@ -151,10 +152,10 @@ public View getView(int position, View arg1, ViewGroup parent) {
.getDefaultSharedPreferences(parent.getContext());
context = parent.getContext();
if (arg1 == null) {
arg1 = inflator.inflate(R.layout.browse_item, parent, false);
arg1 = inflator.inflate(R.layout.browse_content_item, parent, false);
holder = new ViewHolder();
holder.icon = arg1.findViewById(R.id.browseItemIcon);
holder.name = arg1.findViewById(R.id.browseItemName);
holder.icon = arg1.findViewById(R.id.browseContentItemIcon);
holder.name = arg1.findViewById(R.id.browseContentItemName);
arg1.setTag(holder);
} else {
holder = (ViewHolder) arg1.getTag();
Expand All @@ -164,12 +165,12 @@ public View getView(int position, View arg1, ViewGroup parent) {
DIDLObject currentObject = (DIDLObject) getItem(position);
holder.name.setText(currentObject.getTitle());
IconDownloadTask iconDownloadTask = new IconDownloadTask(
this, (ListView) parent, position);
this, (ListView) parent, R.id.browseContentItemIcon, position);
asyncTasks.add(iconDownloadTask);
if (currentObject instanceof Container) {
holder.icon.setImageResource(R.drawable.folder);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(getContext().getResources().getDrawable(R.drawable.ic_baseline_folder_open_48, context.getTheme()), getContext().getTheme()));
} else if (currentObject instanceof AudioItem) {
holder.icon.setImageResource(R.drawable.cdtrack);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(getContext().getResources().getDrawable(R.drawable.ic_baseline_audiotrack_48, context.getTheme()), getContext().getTheme()));
if (preferences.getBoolean(
context.getString(R.string.settings_thumbnails_chkbx),
true)) {
Expand All @@ -182,15 +183,15 @@ public View getView(int position, View arg1, ViewGroup parent) {
}
}
} else if (currentObject instanceof ImageItem) {
holder.icon.setImageResource(R.drawable.image);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(getContext().getResources().getDrawable(R.drawable.ic_baseline_image_48, getContext().getTheme()), getContext().getTheme()));
if (preferences.getBoolean(
context.getString(R.string.settings_thumbnails_chkbx),
true))
iconDownloadTask.executeOnExecutor(((Yaacc) getContext().getApplicationContext()).getContentLoadExecutor(),
Uri.parse(((ImageItem) currentObject)
.getFirstResource().getValue()));
} else if (currentObject instanceof VideoItem) {
holder.icon.setImageResource(R.drawable.video);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(getContext().getResources().getDrawable(R.drawable.ic_baseline_movie_48, getContext().getTheme()), getContext().getTheme()));
if (preferences.getBoolean(
context.getString(R.string.settings_thumbnails_chkbx),
true)) {
Expand All @@ -203,15 +204,15 @@ public View getView(int position, View arg1, ViewGroup parent) {
}
}
} else if (currentObject instanceof PlaylistItem) {
holder.icon.setImageResource(R.drawable.playlist);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(getContext().getResources().getDrawable(R.drawable.ic_baseline_library_music_48, getContext().getTheme()), getContext().getTheme()));
} else if (currentObject instanceof TextItem) {
holder.icon.setImageResource(R.drawable.txt);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(getContext().getResources().getDrawable(R.drawable.ic_baseline_text_snippet_48, getContext().getTheme()), getContext().getTheme()));
} else if (currentObject == LOAD_MORE_FAKE_ITEM) {
holder.icon.setImageResource(R.drawable.refresh);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(getContext().getResources().getDrawable(R.drawable.ic_baseline_refresh_48, getContext().getTheme()), getContext().getTheme()));
} else if (currentObject == LOADING_FAKE_ITEM) {
holder.icon.setImageResource(R.drawable.download);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(getContext().getResources().getDrawable(R.drawable.ic_baseline_download_48, getContext().getTheme()), getContext().getTheme()));
} else {
holder.icon.setImageResource(R.drawable.unknown);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(getContext().getResources().getDrawable(R.drawable.ic_baseline_question_mark_48, getContext().getTheme()), getContext().getTheme()));
}
return arg1;
}
Expand Down
16 changes: 10 additions & 6 deletions yaacc/src/main/java/de/yaacc/browser/BrowseDeviceAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
import java.util.LinkedList;

import de.yaacc.R;
import de.yaacc.browser.BrowseItemAdapter.ViewHolder;
import de.yaacc.browser.BrowseContentItemAdapter.ViewHolder;
import de.yaacc.util.ThemeHelper;
import de.yaacc.util.image.IconDownloadTask;

/**
Expand All @@ -47,12 +48,14 @@
public class BrowseDeviceAdapter extends BaseAdapter {

private final LayoutInflater inflator;
private final Context context;
private LinkedList<Device<?, ?, ?>> devices;

public BrowseDeviceAdapter(Context ctx, LinkedList<Device<?, ?, ?>> devices) {
super();

this.devices = devices;
context = ctx;
if (ctx != null) {
inflator = LayoutInflater.from(ctx);
} else {
Expand Down Expand Up @@ -81,11 +84,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;

if (convertView == null && inflator != null) {
convertView = inflator.inflate(R.layout.browse_item, parent, false);
convertView = inflator.inflate(R.layout.browse_device_item, parent, false);

holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.browseItemIcon);
holder.name = (TextView) convertView.findViewById(R.id.browseItemName);
holder.icon = (ImageView) convertView.findViewById(R.id.browseDeviceItemIcon);
holder.name = (TextView) convertView.findViewById(R.id.browseDeviceItemName);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
Expand All @@ -100,14 +103,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
URL iconUri = ((RemoteDevice) device).normalizeURI(icon.getUri());
if (iconUri != null) {
Log.d(getClass().getName(), "Device icon uri:" + iconUri);
new IconDownloadTask((ListView) parent, position).execute(Uri.parse(iconUri.toString()));
new IconDownloadTask((ListView) parent, R.id.browseDeviceItemIcon, position).execute(Uri.parse(iconUri.toString()));
break;

}
}
}
} else {
holder.icon.setImageResource(R.drawable.device);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(context.getResources().getDrawable(R.drawable.ic_baseline_sensors_48, context.getTheme()), context.getTheme()));
}
} else if (device instanceof LocalDevice) {
//We know our icon
Expand All @@ -116,6 +119,7 @@ public View getView(int position, View convertView, ViewGroup parent) {

holder.name.setText(device.getDetails().getFriendlyName());


return convertView;
}

Expand Down
4 changes: 2 additions & 2 deletions yaacc/src/main/java/de/yaacc/browser/BrowseItemLoadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import de.yaacc.upnp.callback.contentdirectory.ContentDirectoryBrowseResult;

public class BrowseItemLoadTask extends AsyncTask<Long, Integer, ContentDirectoryBrowseResult> {
private final BrowseItemAdapter itemAdapter;
private final BrowseContentItemAdapter itemAdapter;
private final Long chunkSize;


public BrowseItemLoadTask(BrowseItemAdapter itemAdapter, Long chunkSize) {
public BrowseItemLoadTask(BrowseContentItemAdapter itemAdapter, Long chunkSize) {
this.itemAdapter = itemAdapter;
this.chunkSize = chunkSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import de.yaacc.R;
import de.yaacc.upnp.UpnpClient;
import de.yaacc.util.ThemeHelper;
import de.yaacc.util.image.IconDownloadTask;

/**
Expand All @@ -48,12 +49,14 @@
public class BrowseReceiverDeviceAdapter extends BaseAdapter {
private final LayoutInflater inflator;
private final LinkedList<Device<?, ?, ?>> selectedDevices;
private final Context context;
private LinkedList<Device<?, ?, ?>> devices;

public BrowseReceiverDeviceAdapter(Context ctx, Collection<Device<?, ?, ?>> devices, Collection<Device<?, ?, ?>> selectedDevices) {
super();
this.devices = new LinkedList<>(devices);
this.selectedDevices = new LinkedList<>(selectedDevices);
context = ctx;
inflator = LayoutInflater.from(ctx);
notifyDataSetChanged();
}
Expand All @@ -70,23 +73,22 @@ public Object getItem(int position) {

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflator.inflate(R.layout.browse_item_checkable, parent, false);
convertView = inflator.inflate(R.layout.browse_receiver_device_item, parent, false);
Log.d(getClass().getName(), "New view created");
holder = new ViewHolder();
holder.icon = (ImageView) convertView
.findViewById(R.id.browseItemIcon);
.findViewById(R.id.browseReceiverDeviceItemIcon);
holder.name = (TextView) convertView
.findViewById(R.id.browseItemName);
.findViewById(R.id.browseReceiverDeviceItemName);
holder.checkBox = (CheckBox) convertView
.findViewById(R.id.browseItemCheckbox);
.findViewById(R.id.browseReceiverDeviceItemCheckbox);
convertView.setTag(holder);
} else {
Log.d(getClass().getName(), "view already there");
Expand All @@ -101,14 +103,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
URL iconUri = ((RemoteDevice) device).normalizeURI(icon.getUri());
if (iconUri != null) {
Log.d(getClass().getName(), "Device icon uri:" + iconUri);
new IconDownloadTask((ListView) parent, position).execute(Uri.parse(iconUri.toString()));
new IconDownloadTask((ListView) parent, R.id.browseReceiverDeviceItemIcon, position).execute(Uri.parse(iconUri.toString()));
break;

}
}
}
} else {
holder.icon.setImageResource(R.drawable.device);
holder.icon.setImageDrawable(ThemeHelper.tintDrawable(context.getResources().getDrawable(R.drawable.ic_baseline_devices_48, context.getTheme()), context.getTheme()));
}
} else if (device instanceof LocalDevice || device instanceof UpnpClient.LocalDummyDevice) {
//We know our icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void onItemClick(AdapterView<?> listView, View itemView,
.getAdapter();
Log.d(getClass().getName(), "position: " + position);
CheckBox checkBox = (CheckBox) itemView
.findViewById(R.id.browseItemCheckbox);
.findViewById(R.id.browseReceiverDeviceItemCheckbox);
Device<?, ?, ?> device = (Device<?, ?, ?>) adapter.getItem(position);
if (checkBox.isChecked()) {
Log.d(getClass().getName(), "isChecked:" + device.getDisplayString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ContentListClickListener(UpnpClient upnpClient, ContentListFragment conte
@Override
public void onItemClick(AdapterView<?> listView, View arg1, int position,
long id) {
BrowseItemAdapter adapter = (BrowseItemAdapter) listView.getAdapter();
BrowseContentItemAdapter adapter = (BrowseContentItemAdapter) listView.getAdapter();
currentObject = adapter.getFolder(position);
if (currentObject instanceof Container) {
//Fixme: Cache should store information for different folders....
Expand All @@ -76,7 +76,7 @@ public void onItemClick(AdapterView<?> listView, View arg1, int position,
navigator.pushPosition(new Position(newObjectId, upnpClient.getProviderDeviceId()));
contentListFragment.populateItemList();
} else if (currentObject instanceof Item) {
if (currentObject == BrowseItemAdapter.LOAD_MORE_FAKE_ITEM) {
if (currentObject == BrowseContentItemAdapter.LOAD_MORE_FAKE_ITEM) {
adapter.loadMore();
} else {
PlayableItem playableItem = new PlayableItem((Item) currentObject, 0);
Expand Down
Loading

0 comments on commit 94b98e8

Please sign in to comment.