-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
1,341 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
app/src/main/java/fr/nuage/souvenirs/model/AudioElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package fr.nuage.souvenirs.model; | ||
|
||
import androidx.lifecycle.MutableLiveData; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
|
||
public class AudioElement extends Element { | ||
|
||
private String audioPath; | ||
private boolean stop; | ||
private MutableLiveData<String> ldAudioPath = new MutableLiveData<>(); | ||
private MutableLiveData<Boolean> ldStop = new MutableLiveData<>(); | ||
|
||
public AudioElement(String audioPath, boolean stop) { | ||
super(); | ||
setAudioPath(audioPath,false); | ||
setStop(stop,false); | ||
} | ||
|
||
public AudioElement() { | ||
this("",false); | ||
} | ||
|
||
@Override | ||
public JSONObject completeToJSON(JSONObject json) throws JSONException { | ||
json.put("audio",Utils.getRelativePath(pageParent.getAlbum().getAlbumPath(),audioPath)); | ||
json.put("stop",stop); | ||
return json; | ||
} | ||
|
||
@Override | ||
public void completeFromJSON(JSONObject jsonObject) throws JSONException { | ||
if (jsonObject.has("audio")) { | ||
setAudioPath(new File(pageParent.getAlbum().getAlbumPath(),jsonObject.getString("audio")).getPath(),false); | ||
} | ||
if (jsonObject.has("stop")) { | ||
setStop(jsonObject.getBoolean("stop"),false); | ||
} | ||
} | ||
|
||
public void setAudioPath(String audioPath, boolean save) { | ||
this.audioPath = audioPath; | ||
ldAudioPath.postValue(audioPath); | ||
if (save) { | ||
onChange(); | ||
} | ||
} | ||
|
||
public void setStop(boolean stop, boolean save) { | ||
this.stop = stop; | ||
ldStop.postValue(stop); | ||
if (save) { | ||
onChange(); | ||
} | ||
} | ||
|
||
public String getAudioPath() { | ||
return audioPath; | ||
} | ||
|
||
public boolean isStop() { | ||
return stop; | ||
} | ||
|
||
public MutableLiveData<String> getLdAudioPath() { | ||
return ldAudioPath; | ||
} | ||
|
||
public MutableLiveData<Boolean> getLdStop() { | ||
return ldStop; | ||
} | ||
|
||
public void setAudio(InputStream input, String mimeType) { | ||
String audioPath = pageParent.getAlbum().createDataFile(input,mimeType); | ||
if (audioPath != null) { | ||
setAudioPath(audioPath,true); | ||
} else { | ||
setAudioPath("",true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.