-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sharing image to the Android demo app
Signed-off-by: D4ryl00 <d4ryl00@gmail.com>
- Loading branch information
Showing
15 changed files
with
512 additions
and
71 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
76 changes: 76 additions & 0 deletions
76
android/app/src/main/java/ipfs/gomobile/example/FetchFile.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,76 @@ | ||
package ipfs.gomobile.example; | ||
|
||
import android.content.Intent; | ||
import android.os.AsyncTask; | ||
import android.util.Log; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.Random; | ||
|
||
import ipfs.gomobile.android.IPFS; | ||
|
||
final class FetchFile extends AsyncTask<Void, Void, String> { | ||
private static final String TAG = "FetchIPFSFile"; | ||
|
||
private final WeakReference<MainActivity> activityRef; | ||
private boolean backgroundError; | ||
private byte[] fetchedData; | ||
private String cid; | ||
|
||
FetchFile(MainActivity activity, String cid) { | ||
activityRef = new WeakReference<>(activity); | ||
this.cid = cid; | ||
} | ||
|
||
@Override | ||
protected void onPreExecute() { | ||
MainActivity activity = activityRef.get(); | ||
if (activity == null || activity.isFinishing()) return; | ||
|
||
activity.displayStatusProgress(activity.getString(R.string.titleImageFetching)); | ||
} | ||
|
||
@Override | ||
protected String doInBackground(Void... v) { | ||
MainActivity activity = activityRef.get(); | ||
if (activity == null || activity.isFinishing()) { | ||
cancel(true); | ||
return null; | ||
} | ||
|
||
IPFS ipfs = activity.getIpfs(); | ||
|
||
try { | ||
fetchedData = ipfs.newRequest("cat") | ||
.withArgument(cid) | ||
.send(); | ||
|
||
// Log.d(TAG, "fetched file data=" + MainActivity.bytesToHex(fetchedData)); | ||
return activity.getString(R.string.titleFetchedImage); | ||
} catch (Exception err) { | ||
backgroundError = true; | ||
return MainActivity.exceptionToString(err); | ||
} | ||
} | ||
|
||
protected void onPostExecute(String result) { | ||
MainActivity activity = activityRef.get(); | ||
if (activity == null || activity.isFinishing()) return; | ||
|
||
if (backgroundError) { | ||
activity.displayStatusError(activity.getString(R.string.titleImageFetchingErr), result); | ||
Log.e(TAG, "Ipfs image fetch error: " + result); | ||
} else { | ||
activity.displayStatusSuccess(); | ||
|
||
// Put directly data through this way because of size limit with Intend | ||
DisplayImageActivity.fetchedData = fetchedData; | ||
|
||
Intent intent = new Intent(activity, DisplayImageActivity.class); | ||
intent.putExtra("Title", result); | ||
activity.startActivity(intent); | ||
} | ||
} | ||
} |
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.