audio player now requests permission when hitting play
This commit is contained in:
parent
b5e1bbbdc1
commit
0add9a0ea2
|
@ -85,6 +85,7 @@ public class ConversationActivity extends XmppActivity implements OnConversation
|
||||||
public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm";
|
public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm";
|
||||||
|
|
||||||
public static final int REQUEST_OPEN_MESSAGE = 0x9876;
|
public static final int REQUEST_OPEN_MESSAGE = 0x9876;
|
||||||
|
public static final int REQUEST_PLAY_PAUSE = 0x5432;
|
||||||
|
|
||||||
|
|
||||||
//secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
|
//secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
|
||||||
|
@ -291,6 +292,9 @@ public class ConversationActivity extends XmppActivity implements OnConversation
|
||||||
refreshUiReal();
|
refreshUiReal();
|
||||||
ConversationFragment.openPendingMessage(this);
|
ConversationFragment.openPendingMessage(this);
|
||||||
break;
|
break;
|
||||||
|
case REQUEST_PLAY_PAUSE:
|
||||||
|
ConversationFragment.startStopPending(this);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -424,6 +424,13 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void startStopPending(Activity activity) {
|
||||||
|
ConversationFragment fragment = findConversationFragment(activity);
|
||||||
|
if (fragment != null) {
|
||||||
|
fragment.messageListAdapter.startStopPending();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void downloadFile(Activity activity, Message message) {
|
public static void downloadFile(Activity activity, Message message) {
|
||||||
ConversationFragment fragment = findConversationFragment(activity);
|
ConversationFragment fragment = findConversationFragment(activity);
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.siacs.conversations.ui.adapter;
|
package eu.siacs.conversations.ui.adapter;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
@ -182,6 +183,10 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
||||||
this.mOnContactPictureClickedListener = listener;
|
this.mOnContactPictureClickedListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Activity getActivity() {
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
|
||||||
public void setOnContactPictureLongClicked(
|
public void setOnContactPictureLongClicked(
|
||||||
OnContactPictureLongClicked listener) {
|
OnContactPictureLongClicked listener) {
|
||||||
this.mOnContactPictureLongClickedListener = listener;
|
this.mOnContactPictureLongClickedListener = listener;
|
||||||
|
@ -903,6 +908,10 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
||||||
audioPlayer.stop();
|
audioPlayer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startStopPending() {
|
||||||
|
audioPlayer.startStopPending();
|
||||||
|
}
|
||||||
|
|
||||||
public void openDownloadable(Message message) {
|
public void openDownloadable(Message message) {
|
||||||
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
ConversationFragment.registerPendingMessage(activity, message);
|
ConversationFragment.registerPendingMessage(activity, message);
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package eu.siacs.conversations.ui.service;
|
package eu.siacs.conversations.ui.service;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.media.Image;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
@ -16,7 +20,9 @@ import java.util.Locale;
|
||||||
|
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
|
import eu.siacs.conversations.ui.ConversationActivity;
|
||||||
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
||||||
|
import eu.siacs.conversations.ui.util.PendingItem;
|
||||||
import eu.siacs.conversations.utils.WeakReferenceSet;
|
import eu.siacs.conversations.utils.WeakReferenceSet;
|
||||||
|
|
||||||
public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompletionListener, SeekBar.OnSeekBarChangeListener, Runnable {
|
public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompletionListener, SeekBar.OnSeekBarChangeListener, Runnable {
|
||||||
|
@ -28,6 +34,8 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
|
||||||
private final MessageAdapter messageAdapter;
|
private final MessageAdapter messageAdapter;
|
||||||
private final WeakReferenceSet<RelativeLayout> audioPlayerLayouts = new WeakReferenceSet<>();
|
private final WeakReferenceSet<RelativeLayout> audioPlayerLayouts = new WeakReferenceSet<>();
|
||||||
|
|
||||||
|
private final PendingItem<WeakReference<ImageButton>> pendingOnClickView = new PendingItem<>();
|
||||||
|
|
||||||
private final Handler handler = new Handler();
|
private final Handler handler = new Handler();
|
||||||
|
|
||||||
public AudioPlayer(MessageAdapter adapter) {
|
public AudioPlayer(MessageAdapter adapter) {
|
||||||
|
@ -97,6 +105,11 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startStop(ImageButton playPause) {
|
private void startStop(ImageButton playPause) {
|
||||||
|
if (ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
pendingOnClickView.push(new WeakReference<>(playPause));
|
||||||
|
ActivityCompat.requestPermissions(messageAdapter.getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, ConversationActivity.REQUEST_PLAY_PAUSE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
final RelativeLayout audioPlayer = (RelativeLayout) playPause.getParent();
|
final RelativeLayout audioPlayer = (RelativeLayout) playPause.getParent();
|
||||||
final ViewHolder viewHolder = ViewHolder.get(audioPlayer);
|
final ViewHolder viewHolder = ViewHolder.get(audioPlayer);
|
||||||
final Message message = (Message) audioPlayer.getTag();
|
final Message message = (Message) audioPlayer.getTag();
|
||||||
|
@ -143,6 +156,16 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startStopPending() {
|
||||||
|
WeakReference<ImageButton> reference = pendingOnClickView.pop();
|
||||||
|
if (reference != null) {
|
||||||
|
ImageButton imageButton = reference.get();
|
||||||
|
if (imageButton != null) {
|
||||||
|
startStop(imageButton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean startStop(ViewHolder viewHolder, Message message) {
|
private boolean startStop(ViewHolder viewHolder, Message message) {
|
||||||
if (message == currentlyPlayingMessage && player != null) {
|
if (message == currentlyPlayingMessage && player != null) {
|
||||||
return playPauseCurrent(viewHolder);
|
return playPauseCurrent(viewHolder);
|
||||||
|
|
Loading…
Reference in a new issue