diff options
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java')
-rw-r--r-- | app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java index 411a186f0..cc191d39b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java @@ -16,10 +16,12 @@ package fr.gouv.etalab.mastodon.activities; import android.Manifest; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.support.v4.app.ActivityCompat; @@ -34,12 +36,19 @@ import android.webkit.WebView; import android.widget.FrameLayout; import android.widget.Toast; +import java.lang.ref.WeakReference; +import java.util.List; + +import es.dmoral.toasty.Toasty; +import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.webview.MastalabWebChromeClient; import fr.gouv.etalab.mastodon.webview.MastalabWebViewClient; -import fr.gouv.etalab.mastodon.R; import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE; +import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT; import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads; @@ -51,9 +60,10 @@ import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads; public class WebviewActivity extends BaseActivity { private String url; + private String peertubeLinkToFetch; + private boolean peertubeLink; private WebView webView; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -75,15 +85,17 @@ public class WebviewActivity extends BaseActivity { setContentView(R.layout.activity_webview); Bundle b = getIntent().getExtras(); - if(b != null) + if(b != null) { url = b.getString("url", null); + peertubeLinkToFetch = b.getString("peertubeLinkToFetch", null); + peertubeLink = b.getBoolean("peertubeLink", false); + } if( url == null) finish(); if( getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); webView = Helper.initializeWebview(WebviewActivity.this, R.id.webview); - setTitle(""); FrameLayout webview_container = findViewById(R.id.webview_container); final ViewGroup videoLayout = findViewById(R.id.videoLayout); // Your own view, read class comments @@ -135,6 +147,14 @@ public class WebviewActivity extends BaseActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_webview, menu); + if( peertubeLink ){ + menu.findItem(R.id.action_go).setVisible(false); + menu.findItem(R.id.action_comment).setVisible(true); + } + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + if( theme == THEME_LIGHT) + Helper.colorizeIconMenu(menu, R.color.black); return true; } @Override @@ -148,9 +168,46 @@ public class WebviewActivity extends BaseActivity { try { startActivity(browserIntent); }catch (Exception e){ - Toast.makeText(WebviewActivity.this, R.string.toast_error, Toast.LENGTH_LONG).show(); + Toasty.error(WebviewActivity.this,getString(R.string.toast_error),Toast.LENGTH_LONG).show(); } return true; + case R.id.action_comment: + Toasty.info(WebviewActivity.this, getString(R.string.retrieve_remote_status), Toast.LENGTH_LONG).show(); + new AsyncTask<Void, Void, Void>() { + + private List<fr.gouv.etalab.mastodon.client.Entities.Status> remoteStatuses; + private WeakReference<Context> contextReference = new WeakReference<>(WebviewActivity.this); + + @Override + protected Void doInBackground(Void... voids) { + + if(url != null) { + Results search = new API(contextReference.get()).search(peertubeLinkToFetch); + if (search != null) { + remoteStatuses = search.getStatuses(); + } + } + return null; + } + + @Override + protected void onPostExecute(Void result) { + Intent intent = new Intent(contextReference.get(), TootActivity.class); + Bundle b = new Bundle(); + if( remoteStatuses == null || remoteStatuses.size() == 0){ + Toasty.error(contextReference.get(),getString(R.string.toast_error),Toast.LENGTH_LONG).show(); + return; + } + if( remoteStatuses.get(0).getReblog() != null ) { + b.putParcelable("tootReply", remoteStatuses.get(0).getReblog()); + }else { + b.putParcelable("tootReply", remoteStatuses.get(0)); + } + intent.putExtras(b); //Put your id to your next Intent + contextReference.get().startActivity(intent); + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR ); + return true; default: return super.onOptionsItemSelected(item); } |