Skip to content

Commit

Permalink
[android] merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
gubatron committed Feb 23, 2016
2 parents 3701da4 + 53aa0f5 commit b3d6730
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 2,598 deletions.
54 changes: 19 additions & 35 deletions android/apollo/src/com/andrew/apollo/MusicPlaybackService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import java.util.TreeSet;

/**
* A backbround {@link Service} used to keep music playing between activities
* A background {@link Service} used to keep music playing between activities
* and when the user moves Apollo into the background.
*/
@SuppressLint("NewApi")
Expand Down Expand Up @@ -837,7 +837,6 @@ private int getCardId() {
if (cursor != null && cursor.moveToFirst()) {
mCardId = cursor.getInt(0);
cursor.close();
cursor = null;
}
return mCardId;
}
Expand Down Expand Up @@ -1271,11 +1270,9 @@ private boolean makeAutoShuffleList() {
}
mAutoShuffleList = list;
return true;
} catch (final RuntimeException e) {
} finally {
} catch (final RuntimeException ignored) {} finally {
if (cursor != null) {
cursor.close();
cursor = null;
}
}
return false;
Expand Down Expand Up @@ -1713,7 +1710,7 @@ public int getAudioSessionId() {
}

/**
* Indicates if the media storeage device has been mounted or not
* Indicates if the media storage device has been mounted or not
*
* @return 1 if Intent.ACTION_MEDIA_MOUNTED is called, 0 otherwise
*/
Expand Down Expand Up @@ -1939,7 +1936,7 @@ public long seek(long position) {
/**
* Returns the current position in time of the currenttrack
*
* @return The current playback position in miliseconds
* @return The current playback position in milliseconds
*/
public long position() {
if (mPlayer != null && mPlayer.isInitialized()) {
Expand All @@ -1951,7 +1948,7 @@ public long position() {
/**
* Returns the full duration of the current track
*
* @return The duration of the current track in miliseconds
* @return The duration of the current track in milliseconds
*/
public long duration() {
if (mPlayer != null && mPlayer.isInitialized()) {
Expand Down Expand Up @@ -2424,7 +2421,7 @@ private static final class MusicPlayerHandler extends Handler {
*/
public MusicPlayerHandler(final MusicPlaybackService service, final Looper looper) {
super(looper);
mService = new WeakReference<MusicPlaybackService>(service);
mService = new WeakReference<>(service);
}

/**
Expand Down Expand Up @@ -2528,9 +2525,9 @@ public void handleMessage(final Message msg) {

private static final class Shuffler {

private final LinkedList<Integer> mHistoryOfNumbers = new LinkedList<Integer>();
private final LinkedList<Integer> mHistoryOfNumbers = new LinkedList<>();

private final TreeSet<Integer> mPreviousNumbers = new TreeSet<Integer>();
private final TreeSet<Integer> mPreviousNumbers = new TreeSet<>();

private final Random mRandom = new Random();

Expand All @@ -2555,7 +2552,7 @@ public int nextInt(final int interval) {
do {
next = mRandom.nextInt(interval);
} while (next == mPrevious && interval > 1
&& !mPreviousNumbers.contains(Integer.valueOf(next)));
&& !mPreviousNumbers.contains(next));
mPrevious = next;
mHistoryOfNumbers.add(mPrevious);
mPreviousNumbers.add(mPrevious);
Expand All @@ -2576,8 +2573,6 @@ private void cleanUpHistory() {
}
}

;

private static final class MultiPlayer implements MediaPlayer.OnErrorListener,
MediaPlayer.OnCompletionListener {

Expand Down Expand Up @@ -2749,7 +2744,7 @@ public boolean isInitialized() {
public void start() {
try {
mCurrentMediaPlayer.start();
} catch (Throwable t) {
} catch (Throwable ignored) {

}
}
Expand All @@ -2773,7 +2768,7 @@ public void release() {
stop();
try {
mCurrentMediaPlayer.release();
} catch (Throwable t) {
} catch (Throwable ignored) {

}
}
Expand All @@ -2784,7 +2779,7 @@ public void release() {
public void pause() {
try {
mCurrentMediaPlayer.pause();
} catch (Throwable t) {
} catch (Throwable ignored) {

}
}
Expand All @@ -2811,7 +2806,7 @@ public long position() {
long result = 0;
try {
result = mCurrentMediaPlayer.getCurrentPosition();
} catch (Throwable t) {
} catch (Throwable ignored) {
}
return result;
}
Expand All @@ -2825,7 +2820,7 @@ public long position() {
public long seek(final long whereto) {
try {
mCurrentMediaPlayer.seekTo((int) whereto);
} catch (Throwable t) {
} catch (Throwable ignored) {

}
return whereto;
Expand Down Expand Up @@ -2909,9 +2904,7 @@ public void onCompletion(final MediaPlayer mp) {
mHandler.sendEmptyMessage(TRACK_ENDED);
mHandler.sendEmptyMessage(RELEASE_WAKELOCK);
}
} catch (Throwable t) {

}
} catch (Throwable ignored) {}
}
}

Expand All @@ -2921,7 +2914,7 @@ private static final class ServiceStub extends IApolloService.Stub {
private final static long[] EMPTY_LONG_ARRAY = new long[0];

private ServiceStub(final MusicPlaybackService service) {
mService = new WeakReference<MusicPlaybackService>(service);
mService = new WeakReference<>(service);
}

/**
Expand Down Expand Up @@ -3069,29 +3062,20 @@ public void refresh() throws RemoteException {
*/
@Override
public boolean isFavorite() throws RemoteException {
if (Ref.alive(mService)) {
return mService.get().isFavorite();
}
return false;
return Ref.alive(mService) && mService.get().isFavorite();
}

/**
* {@inheritDoc}
*/
@Override
public boolean isPlaying() throws RemoteException {
if (Ref.alive(mService)) {
return mService.get().isPlaying();
}
return false;
return Ref.alive(mService) && mService.get().isPlaying();
}

@Override
public boolean isStopped() throws RemoteException {
if (Ref.alive(mService)) {
return mService.get().isStopped();
}
return true;
return !Ref.alive(mService) || mService.get().isStopped();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion android/apollo/src/com/andrew/apollo/utils/ThemeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ public int getColor(final String resourceName) {
if (mResources != null) {
try {
final int resourceId = mResources.getIdentifier(resourceName, "color", mThemePackage);
return mResources.getColor(resourceId);
if (resourceId != 0) { // if not, the color is not here
return mResources.getColor(resourceId);
}
} catch (final Resources.NotFoundException e) {
// If the theme designer wants to allow the user to theme a
// particular object via the color picker, they just remove the
Expand Down
4 changes: 2 additions & 2 deletions android/res/xml/application_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@
<CheckBoxPreference
android:key="frostwire.prefs.gui.vibrate_on_finished_download"
android:title="@string/vibrate_on_finished_download" />
<CheckBoxPreference
<!--<CheckBoxPreference
android:key="frostwire.prefs.core.enable_experimental"
android:title="@string/enable_experimental" />
android:title="@string/enable_experimental" />-->
<CheckBoxPreference
android:key="frostwire.prefs.uxstats.enabled"
android:summary="@string/anonymous_usage_statistics_summary"
Expand Down
2 changes: 1 addition & 1 deletion android/src/com/frostwire/android/AndroidPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean experimental() {

public static boolean saf() {
Platform p = Platforms.get();
return /*p.experimental() &&*/ p.fileSystem() instanceof LollipopFileSystem;
return p.fileSystem() instanceof LollipopFileSystem;
}

private static FileSystem buildFileSystem(Application app) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.preference.PreferenceManager;
import com.frostwire.util.Hex;
import com.frostwire.util.StringUtils;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

import java.io.File;
import java.util.Map;
Expand Down Expand Up @@ -122,14 +121,14 @@ public byte[] getByteArray(String key) {
}

try {
return Hex.decodeHex(str.toCharArray());
} catch (DecoderException e) {
return Hex.decode(str);
} catch (Throwable e) {
return null;
}
}

public void setByteArray(String key, byte[] value) {
setString(key, new String(Hex.encodeHex(value)));
setString(key, new String(Hex.encode(value)));
}

public void resetToDefaults() {
Expand Down
8 changes: 7 additions & 1 deletion android/src/com/frostwire/android/gui/Librarian.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.BaseColumns;
import android.provider.MediaStore.MediaColumns;
import android.util.Log;
Expand Down Expand Up @@ -185,6 +185,12 @@ public void scan(File file) {
scan(file, Transfers.getIgnorableFiles());
}

public void scan(Uri uri) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(uri);
context.sendBroadcast(intent);
}

public Finger finger() {
Finger finger = new Finger();

Expand Down
8 changes: 6 additions & 2 deletions android/src/com/frostwire/android/gui/UniversalScanner.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Created by Angel Leon (@gubatron), Alden Torres (aldenml)
* Copyright (c) 2011-2015, FrostWire(R). All rights reserved.
* Copyright (c) 2011-2016, FrostWire(R). All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -105,6 +105,10 @@ public void onScanCompleted(String path, Uri uri) {
connection.disconnect();
}

if (path == null || path.contains("/Android/data/" + context.getPackageName() + "/files/temp")) {
return;
}

MediaType mt = MediaType.getMediaTypeForExtension(FilenameUtils.getExtension(path));

if (uri != null && !path.contains("/Android/data/" + context.getPackageName())) {
Expand Down Expand Up @@ -140,7 +144,7 @@ private void scanPrivateFile(Uri oldUri, String filePath, MediaType mt) {
try {
int n = context.getContentResolver().delete(oldUri, null, null);
if (n > 0) {
LOG.debug("Deleted from Files provider: " + oldUri);
LOG.debug("Deleted from Files provider: " + oldUri + ", path: " + filePath);
}
nativeScanFile(context, filePath);
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public class HttpDownload implements DownloadTransfer {
this.status = STATUS_SAVE_DIR_ERROR;
}

if (savePath == null || !savePath.isDirectory() && !savePath.mkdirs()) {
FileSystem fs = Platforms.fileSystem();
if (savePath == null || !fs.isDirectory(savePath) && !fs.mkdirs(savePath)) {
this.status = STATUS_SAVE_DIR_ERROR;
}

Expand Down Expand Up @@ -317,7 +318,7 @@ private void classicComplete() {
success = false;
}

performCompletionTasks(success);
performCompletionTasks(success, true);
}

private void safComplete(final FileSystem fs) {
Expand All @@ -329,9 +330,11 @@ public void run() {
if (tempPath.exists() && fs.copy(tempPath, savePath)) {
success = true;
}
performCompletionTasks(success);
performCompletionTasks(success, false);

tempPath.delete();

Librarian.instance().scan(Uri.fromFile(savePath.getAbsoluteFile()));
} catch (Throwable e) {
e.printStackTrace();
error(new Exception("Error"));
Expand All @@ -340,7 +343,7 @@ public void run() {
});
}

private void performCompletionTasks(boolean success) {
private void performCompletionTasks(boolean success, boolean scan) {
if (success) {
if (listener != null) {
listener.onComplete(HttpDownload.this);
Expand All @@ -351,7 +354,7 @@ private void performCompletionTasks(boolean success) {
manager.incrementDownloadsToReview();
Engine.instance().notifyDownloadFinished(getDisplayName(), getSavePath());

if (savePath.getAbsoluteFile().exists()) {
if (scan && savePath.getAbsoluteFile().exists()) {
Librarian.instance().scan(getSavePath().getAbsoluteFile());
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ public void run() {
return;
}

Librarian.instance().scan(finalFile.getAbsoluteFile());
String hash = String.valueOf(getDisplayName().hashCode());
Engine.instance().notifyDownloadFinished(getDisplayName(), finalFile, hash);

file.delete();

Librarian.instance().scan(Uri.fromFile(finalFile.getAbsoluteFile()));
} catch (Throwable e) {
e.printStackTrace();
// TODO: do something here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,10 @@ public void run() {
if (fs.copy(completeFile, finalFile)) {
completeFile.delete();
completeFile = finalFile;
Librarian.instance().scan(getSavePath().getAbsoluteFile());
String hash = String.valueOf(getDisplayName().hashCode());
Engine.instance().notifyDownloadFinished(getDisplayName(), completeFile, hash);

Librarian.instance().scan(Uri.fromFile(finalFile));
} else {
YouTubeDownload.this.status = STATUS_ERROR;
}
Expand Down

0 comments on commit b3d6730

Please sign in to comment.