Skip to content

Commit

Permalink
Improving/fixing some sharing issues, Audio now properly plays when a…
Browse files Browse the repository at this point in the history
…pp is in background, and some laying tweaks/improvements.
  • Loading branch information
GottaGetSwifty committed Feb 18, 2016
1 parent f156764 commit 34f80df
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 141 deletions.

Large diffs are not rendered by default.

36 changes: 26 additions & 10 deletions app/app/src/main/java/activity/reading/BaseReadingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import activity.AnimationParadigm;
import activity.UWBaseActivity;
Expand Down Expand Up @@ -203,7 +205,7 @@ private void downloadEnded(DownloadResult result){
Toast.makeText(this, "Download " + resultText, Toast.LENGTH_SHORT).show();
Book book = getBook();
book.refresh();
DataFileManager.getStateOfContent(getApplicationContext(), book.getVersion(), MediaType.MEDIA_TYPE_AUDIO, new DataFileManager.GetDownloadStateResponse() {
DataFileManager.getStateOfContent(getApplicationContext(), Arrays.asList(book.getVersion()), MediaType.MEDIA_TYPE_AUDIO, new DataFileManager.GetDownloadStateResponse() {
@Override
public void foundDownloadState(DownloadState state) {
audioPlayerViewGroup.handleDownloadState(state);
Expand Down Expand Up @@ -308,7 +310,6 @@ protected void onPause() {
}

unregisterListeners();
UWAudioPlayer.getInstance(getApplicationContext()).reset();
}

private void unregisterListeners(){
Expand All @@ -322,6 +323,12 @@ public void onBackPressed(boolean isSharing) {
}
}

@Override
protected void handleBack() {
super.handleBack();
UWAudioPlayer.getInstance(getApplicationContext()).reset();
}

@Override
public AnimationParadigm getAnimationParadigm() {
return AnimationParadigm.ANIMATION_LEFT_RIGHT;
Expand Down Expand Up @@ -554,25 +561,32 @@ private void shareVersion(){

private void shareVersion(Version version){

if(version.hasVideo() || version.hasAudio()){
ResourceChoosingFragment.newInstance(version).show(getSupportFragmentManager(), "ResourceChoosingFragment");
setLoadingFragmentVisibility(true, "Preparing...", false);
if(version.hasVideo() || (version.hasAudio())){

Version[] versions = {version};
setLoadingFragmentVisibility(false, "", false);
ResourceChoosingFragment.newInstance(versions).show(getSupportFragmentManager(), "ResourceChoosingFragment");
}
else{
shareVersion(new ArrayList<MediaType>(), version);
Map<Version, List<MediaType>> sharingChoices = new HashMap<>();
sharingChoices.put(version, Arrays.asList(MediaType.MEDIA_TYPE_TEXT));
setLoadingFragmentVisibility(false, "", false);
shareVersion(sharingChoices);
}
}

@Override
public void resourcesChosen(DialogFragment dialogFragment, List<MediaType> types) {

shareVersion(types, getSharingVersion());
@Override
public void resourcesChosen(DialogFragment dialogFragment, Map<Version, List<MediaType>> sharingChoices) {
shareVersion(sharingChoices);
dialogFragment.dismiss();
}

private void shareVersion(List<MediaType> types, Version version){
private void shareVersion(Map<Version, List<MediaType>> sharingChoices){

setLoadingFragmentVisibility(true, "Preparing Sharable Version", false);
SharingHelper.getShareInformation(getApplicationContext(), version, types, new SharingHelper.SideLoadInformationResponse() {
SharingHelper.getShareInformation(getApplicationContext(), sharingChoices, new SharingHelper.SideLoadInformationResponse() {
@Override
public void informationLoaded(SideLoadInformation information) {
TypeChoosingFragment.constructFragment(information)
Expand Down Expand Up @@ -623,6 +637,7 @@ VersionSelectionActivity.PROJECT_PARAM, getProject())
.putExtra(VersionSelectionActivity.IS_SECOND_VERSION_PARAM, isSecondVersion), 1);
overridePendingTransition(R.anim.enter_from_bottom, R.anim.enter_center);
// }
UWAudioPlayer.getInstance(getApplicationContext()).reset();
}

@Override
Expand Down Expand Up @@ -652,6 +667,7 @@ private void goToChapterActivity(){
startActivity(new Intent(getApplicationContext(), BookSelectionActivity.class).putExtra(BookSelectionActivity.PROJECT_PARAM, getProject()));
overridePendingTransition(R.anim.enter_from_bottom, R.anim.enter_center);
}
UWAudioPlayer.getInstance(getApplicationContext()).reset();
}

//endregion
Expand Down
27 changes: 17 additions & 10 deletions app/app/src/main/java/activity/sharing/ShareActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import org.unfoldingword.mobile.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import activity.AnimationParadigm;
import activity.UWBaseActivity;
Expand Down Expand Up @@ -72,37 +75,41 @@ private void addFragment(){

public void shareClicked(View view) {

final Version version = selectionFragment.getSelectedVersion();
if(version != null) {
final List<Version> versions = selectionFragment.getSelectedVersions();
if(versions != null) {

DataFileManager.getStateOfContent(getApplicationContext(), version, MediaType.MEDIA_TYPE_AUDIO, new DataFileManager.GetDownloadStateResponse() {
DataFileManager.getStateOfContent(getApplicationContext(), versions, MediaType.MEDIA_TYPE_AUDIO, new DataFileManager.GetDownloadStateResponse() {
@Override
public void foundDownloadState(DownloadState state) {

if(state == DownloadState.DOWNLOAD_STATE_DOWNLOADED){

ResourceChoosingFragment.newInstance(version, new ResourceChoosingFragment.ResourceChoosingListener() {
ResourceChoosingFragment.newInstance(versions.toArray(new Version[versions.size()]), new ResourceChoosingFragment.ResourceChoosingListener() {

@Override
public void resourcesChosen(DialogFragment dialogFragment, List<MediaType> types) {
shareVersion(types, version);
public void resourcesChosen(DialogFragment dialogFragment, Map<Version, List<MediaType>> sharingChoices) {
shareVersions(sharingChoices);
dialogFragment.dismiss();
}
}).show(getSupportFragmentManager(), "ResourceChoosingFragment");

}
else{
shareVersion(new ArrayList<MediaType>(), version);
Map<Version, List<MediaType>> shareInfo = new HashMap<Version, List<MediaType>>();
for(Version version : versions) {
shareInfo.put(version, Arrays.asList(MediaType.MEDIA_TYPE_TEXT));
}
shareVersions(shareInfo);
}

}
});
}
}

private void shareVersion(List<MediaType> types, Version version){
private void shareVersions(Map<Version, List<MediaType>> versions){

setLoadingFragmentVisibility(true, "Preparing Sharable Version", false);
SharingHelper.getShareInformation(getApplicationContext(), version, types, new SharingHelper.SideLoadInformationResponse() {
SharingHelper.getShareInformation(getApplicationContext(), versions, new SharingHelper.SideLoadInformationResponse() {
@Override
public void informationLoaded(SideLoadInformation information) {

Expand Down
4 changes: 4 additions & 0 deletions app/app/src/main/java/adapters/ResourceChoosingAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import butterknife.Bind;
import butterknife.ButterKnife;
import model.daoModels.Version;
import model.parsers.MediaType;

//import android.widget.IconTextView;

Expand Down Expand Up @@ -143,7 +145,9 @@ void updateCheckMark(){

public interface ResourceChoosingAdapterProtocol {

Version getVersion();
String getName();
Drawable getImage();
MediaType getType();
}
}
53 changes: 38 additions & 15 deletions app/app/src/main/java/adapters/sharing/SharingAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.unfoldingword.mobile.R;

import java.util.ArrayList;
import java.util.List;

import model.daoModels.Version;
Expand All @@ -30,21 +31,29 @@ public class SharingAdapter implements ExpandableListAdapter {

// private final static String TAG = "CollapseVersionAdapter";

private SharingAdapterListener listener;
// private SharingAdapterListener listener;
private Fragment parentFragment;

private List<SharingLanguageViewModel> models;
// private VersionAdapterListener listener;
private long selectedVersionId;

private Version selectedVersion;
private List<List<Boolean>> selectionList = new ArrayList<>();

//region setup

public SharingAdapter(Fragment fragment, List<SharingLanguageViewModel> models, SharingAdapterListener listener) {
public SharingAdapter(Fragment fragment, List<SharingLanguageViewModel> models) {
this.parentFragment = fragment;
this.models = models;
this.listener = listener;
seedSelectionList();
}

private void seedSelectionList(){

for( SharingLanguageViewModel model : models) {
List<Boolean> selections = new ArrayList<>();
for(int i = 0; i < model.getVersions().size(); i++ ) {
selections.add(i, false);
}
selectionList.add(selections);
}
}

@Override
Expand Down Expand Up @@ -140,18 +149,32 @@ public View getChildView(final int groupPosition, final int childPosition,
holder = (SharingAdapterVersionViewGroup) convertView.getTag();
}

holder.updateWithVersion(getChild(groupPosition, childPosition), new SharingAdapterVersionViewGroup.SharingAdapterVersionViewGroupListener() {
holder.updateWithVersion(getChild(groupPosition, childPosition), groupPosition, childPosition, new SharingAdapterVersionViewGroup.SharingAdapterVersionViewGroupListener() {

@Override
public void clicked(Version version) {
selectedVersion = version;
listener.versionChosen(version);
public void clicked(SharingAdapterVersionViewGroup viewGroup) {
selectionList.get(viewGroup.section).set(viewGroup.row, viewGroup.isChecked);
}
});

holder.setChecked(selectedVersion != null && holder.getVersion().getId().equals(selectedVersion.getId()));
holder.setChecked(selectionList.get(groupPosition).get(childPosition));
return convertView;
}

public List<Version> getSelectedVersions() {

List<Version> versions = new ArrayList<>();
for(int i = 0; i < selectionList.size(); i++) {
List<Boolean> list = selectionList.get(i);
for(int j = 0; j < list.size(); j++){
if(list.get(j)) {
versions.add(models.get(i).getVersions().get(j));
}
}
}
return versions;
}

//endregion

//region helpers
Expand Down Expand Up @@ -204,8 +227,8 @@ public void onGroupCollapsed(int groupPosition) {

//endregion

public interface SharingAdapterListener{
void versionChosen(Version version);
}
// public interface SharingAdapterListener{
// void versionChosen(Version version);
// }
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public class SharingAdapterVersionViewGroup {
@Bind(R.id.share_selection_checkbox_image)
ImageView checkMarkImageView;

public int section;
public int row;
public boolean isChecked = false;

private SharingAdapterVersionViewGroupListener listener;

public SharingAdapterVersionViewGroup(View view) {
baseView = view;
ButterKnife.bind(this, view);
Expand All @@ -34,24 +40,35 @@ public Version getVersion() {
return version;
}

public void updateWithVersion(final Version version, final SharingAdapterVersionViewGroupListener listener){
public void updateWithVersion(final Version version, int section, int row, final SharingAdapterVersionViewGroupListener listener){
this.version = version;
this.listener = listener;
this.section = section;
this.row = row;
titleTextView.setText(version.getName());

baseView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.clicked(version);
wasClicked();
}
});
}
private void wasClicked() {
toggleChecked();
listener.clicked(this);
}

private void toggleChecked(){
setChecked(!isChecked);
}
public void setChecked(boolean checked){
this.isChecked = checked;
checkMarkImageView.setImageResource((checked) ? R.drawable.check_box_checked : R.drawable.check_box_empty);
}

public interface SharingAdapterVersionViewGroupListener{

void clicked(Version version);
void clicked(SharingAdapterVersionViewGroup viewGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
public class SharingLanguageViewModel implements Comparable<SharingLanguageViewModel> {

private String title;

private List<Version> versions = new ArrayList<>();


Expand Down
Loading

0 comments on commit 34f80df

Please sign in to comment.