diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a6b2329f3..f0b7c3825 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,6 +53,17 @@ android:noHistory="true" android:label="@string/app_name" /> + + . */ +package fr.gouv.etalab.mastodon.activities; + +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.design.widget.TabLayout; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.view.PagerAdapter; +import android.support.v4.view.ViewPager; +import android.support.v7.app.AppCompatActivity; +import android.view.MenuItem; +import android.view.View; +import android.widget.RelativeLayout; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.List; + +import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask; +import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.client.Entities.Results; +import fr.gouv.etalab.mastodon.client.Entities.Status; +import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment; +import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface; +import mastodon.etalab.gouv.fr.mastodon.R; + + +/** + * Created by Thomas on 26/05/2017. + * Show search results within two tabs: Toots and accounts + */ + +public class SearchResultActivity extends AppCompatActivity implements OnRetrieveSearchInterface { + + + private static final int NUM_PAGES = 2; + private ViewPager mPager; + private TabLayout tabLayout; + private boolean searchDone = false; + private List accounts; + private List statuses; + private String search; + private RelativeLayout loader; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_search_result); + + + statuses = new ArrayList<>(); + accounts = new ArrayList<>(); + + loader = (RelativeLayout) findViewById(R.id.loader); + tabLayout = (TabLayout) findViewById(R.id.search_tabLayout); + loader.setVisibility(View.VISIBLE); + tabLayout.setVisibility(View.GONE); + Bundle b = getIntent().getExtras(); + if(b != null){ + search = b.getString("search"); + if( search != null) + new RetrieveSearchAsyncTask(getApplicationContext(), search.trim(), SearchResultActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else + Toast.makeText(this,R.string.toast_error_loading_account,Toast.LENGTH_LONG).show(); + }else{ + Toast.makeText(this,R.string.toast_error_loading_account,Toast.LENGTH_LONG).show(); + } + if( getSupportActionBar() != null) + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + setTitle(search); + + + + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + + @Override + public void onRetrieveSearch(Results results) { + if( results == null ){ + Toast.makeText(getApplicationContext(),R.string.toast_error,Toast.LENGTH_LONG).show(); + loader.setVisibility(View.GONE); + tabLayout.setVisibility(View.VISIBLE); + return; + } + accounts = results.getAccounts(); + statuses = results.getStatuses(); + tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots))); + tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.accounts))); + loader.setVisibility(View.GONE); + tabLayout.setVisibility(View.VISIBLE); + mPager = (ViewPager) findViewById(R.id.search_viewpager); + PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); + mPager.setAdapter(mPagerAdapter); + + mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + @Override + public void onPageSelected(int position) { + TabLayout.Tab tab = tabLayout.getTabAt(position); + if( tab != null) + tab.select(); + } + @Override + public void onPageScrollStateChanged(int state) { + + } + }); + + tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { + @Override + public void onTabSelected(TabLayout.Tab tab) { + mPager.setCurrentItem(tab.getPosition()); + } + @Override + public void onTabUnselected(TabLayout.Tab tab) { + + } + @Override + public void onTabReselected(TabLayout.Tab tab) { + + } + }); + + } + + + /* + * Pager adapter for the 2 fragments (status and accounts) coming from search results + */ + private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { + ScreenSlidePagerAdapter(FragmentManager fm) { + super(fm); + } + @Override + public Fragment getItem(int position) { + Bundle bundle = new Bundle(); + switch (position){ + case 0: + DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment(); + bundle.putParcelableArrayList("statuses", new ArrayList<>(statuses)); + displayStatusFragment.setArguments(bundle); + return displayStatusFragment; + case 1: + DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment(); + bundle.putParcelableArrayList("accounts", new ArrayList<>(accounts)); + displayAccountsFragment.setArguments(bundle); + return displayAccountsFragment; + } + return null; + } + + @Override + public int getCount() { + return NUM_PAGES; + } + } + +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java index 317da269c..9ff4c7552 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java @@ -22,6 +22,7 @@ import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; @@ -87,6 +88,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi private BroadcastReceiver hide_header; private TextView account_note; private String userId; + private static boolean isHiddingShowing = false; public enum action{ FOLLOW, @@ -182,19 +184,39 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi hide_header = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - boolean hide = intent.getBooleanExtra("hide", false); - if( hide){ - account_follow.setVisibility(View.GONE); - account_note.setVisibility(View.GONE); - tabLayout.setVisibility(View.GONE); - }else { - account_follow.setVisibility(View.VISIBLE); - if( accountId != null && accountId.equals(userId)){ + if( !isHiddingShowing ){ + isHiddingShowing = true; + ImageView account_pp = (ImageView) findViewById(R.id.account_pp); + TextView account_ac = (TextView) findViewById(R.id.account_ac); + boolean hide = intent.getBooleanExtra("hide", false); + if( hide){ account_follow.setVisibility(View.GONE); + account_note.setVisibility(View.GONE); + tabLayout.setVisibility(View.GONE); + account_ac.setVisibility(View.GONE); + account_pp.getLayoutParams().width = (int) Helper.convertDpToPixel(50, context); + account_pp.getLayoutParams().height = (int) Helper.convertDpToPixel(50, context); + }else { + account_follow.setVisibility(View.VISIBLE); + if( accountId != null && accountId.equals(userId)){ + account_follow.setVisibility(View.GONE); + } + account_ac.setVisibility(View.VISIBLE); + account_pp.getLayoutParams().width = (int) Helper.convertDpToPixel(80, context); + account_pp.getLayoutParams().height = (int) Helper.convertDpToPixel(80, context); + tabLayout.setVisibility(View.VISIBLE); + account_note.setVisibility(View.VISIBLE); } - tabLayout.setVisibility(View.VISIBLE); - account_note.setVisibility(View.VISIBLE); + account_pp.requestLayout(); + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + isHiddingShowing = false; + } + }, 1000); } + } }; LocalBroadcastManager.getInstance(this).registerReceiver(hide_header, new IntentFilter(Helper.HEADER_ACCOUNT)); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index ccb90b636..1bd898ac5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -23,7 +23,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; -import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; @@ -33,11 +32,9 @@ import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.text.Html; import android.text.TextWatcher; -import android.util.Log; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.webkit.WebView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; @@ -48,7 +45,6 @@ import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; -import android.widget.VideoView; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; @@ -62,22 +58,19 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask; -import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; -import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask; +import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAccountsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.UploadActionAsyncTask; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Attachment; -import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.drawers.AccountsSearchAdapter; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface; -import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountsInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAttachmentInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; -import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import mastodon.etalab.gouv.fr.mastodon.R; @@ -88,7 +81,7 @@ import mastodon.etalab.gouv.fr.mastodon.R; * Toot activity class */ -public class TootActivity extends AppCompatActivity implements OnRetrieveSearchInterface, OnRetrieveAttachmentInterface, OnPostActionInterface, OnRetrieveFeedsInterface { +public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAccountshInterface, OnRetrieveAttachmentInterface, OnPostActionInterface, OnRetrieveFeedsInterface { private String inReplyTo = null; @@ -279,7 +272,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearchI Matcher m = sPattern.matcher(s.toString()); if(m.matches()) { String search = m.group(2); - new RetrieveSearchAsyncTask(getApplicationContext(),search,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveSearchAccountsAsyncTask(getApplicationContext(),search,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }else{ toot_show_accounts.setVisibility(View.GONE); } @@ -522,10 +515,11 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearchI } + @Override - public void onRetrieveSearch(Results results) { - if( results != null && results.getAccounts() != null && results.getAccounts().size() > 0){ - AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, results.getAccounts()); + public void onRetrieveSearchAccounts(List accounts) { + if( accounts != null && accounts.size() > 0){ + AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, accounts); toot_lv_accounts.setAdapter(accountsListAdapter); accountsListAdapter.notifyDataSetChanged(); toot_show_accounts.setVisibility(View.VISIBLE); 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 new file mode 100644 index 000000000..952c923cb --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java @@ -0,0 +1,182 @@ +/* Copyright 2017 Thomas Schneider + * + * This file is a part of Mastodon Etalab for mastodon.etalab.gouv.fr + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Mastodon Etalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Thomas Schneider; if not, + * see . */ + +package fr.gouv.etalab.mastodon.activities; + + +import android.content.Context; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Build; +import android.os.Bundle; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.webkit.CookieManager; +import android.webkit.CookieSyncManager; +import android.webkit.WebChromeClient; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.ProgressBar; + +import com.loopj.android.http.AsyncHttpResponseHandler; +import com.loopj.android.http.RequestParams; + +import org.json.JSONException; +import org.json.JSONObject; + +import cz.msebera.android.httpclient.Header; +import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask; +import fr.gouv.etalab.mastodon.client.OauthClient; +import fr.gouv.etalab.mastodon.helper.Helper; +import mastodon.etalab.gouv.fr.mastodon.R; + +/** + * Created by Thomas on 24/04/2017. + * Webview to connect accounts + */ +public class WebviewActivity extends AppCompatActivity { + + + private WebView webView; + private AlertDialog alert; + private String clientId, clientSecret; + + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_webview); + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + clientId = sharedpreferences.getString(Helper.CLIENT_ID, null); + clientSecret = sharedpreferences.getString(Helper.CLIENT_SECRET, null); + + webView = (WebView) findViewById(R.id.webviewConnect); + clearCookies(getApplicationContext()); + final ProgressBar pbar = (ProgressBar) findViewById(R.id.progress_bar); + webView.setWebChromeClient(new WebChromeClient() { + @Override + public void onProgressChanged(WebView view, int progress) { + if (progress < 100 && pbar.getVisibility() == ProgressBar.GONE) { + pbar.setVisibility(ProgressBar.VISIBLE); + } + pbar.setProgress(progress); + if (progress == 100) { + pbar.setVisibility(ProgressBar.GONE); + } + } + }); + + + webView.setWebViewClient(new WebViewClient() { + @SuppressWarnings("deprecation") + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url){ + super.shouldOverrideUrlLoading(view,url); + if( url.contains(Helper.REDIRECT_CONTENT_WEB)){ + String val[] = url.split("code="); + String code = val[1]; + + String action = "/oauth/token"; + RequestParams parameters = new RequestParams(); + parameters.add(Helper.CLIENT_ID, clientId); + parameters.add(Helper.CLIENT_SECRET, clientSecret); + parameters.add(Helper.REDIRECT_URI,Helper.REDIRECT_CONTENT_WEB); + parameters.add("grant_type", "authorization_code"); + parameters.add("code",code); + new OauthClient().post(action, parameters, new AsyncHttpResponseHandler() { + @Override + public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { + String response = new String(responseBody); + JSONObject resobj; + try { + resobj = new JSONObject(response); + String token = resobj.get("access_token").toString(); + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token); + editor.apply(); + //Update the account with the token; + new UpdateAccountInfoAsyncTask(WebviewActivity.this, token).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } catch (JSONException e) { + e.printStackTrace(); + } + + } + + @Override + public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { + error.printStackTrace(); + } + }); + + + return true; + } + return false; + } + + }); + webView.loadUrl(redirectUserToAuthorizeAndLogin()); + } + + + @Override + public void onBackPressed() { + if (webView != null && webView.canGoBack()) { + webView.goBack(); + } else { + super.onBackPressed(); + } + } + + + + private String redirectUserToAuthorizeAndLogin() { + + String queryString = Helper.CLIENT_ID + "="+ clientId; + queryString += "&" + Helper.REDIRECT_URI + "="+ Uri.encode(Helper.REDIRECT_CONTENT_WEB); + queryString += "&" + Helper.RESPONSE_TYPE +"=code"; + queryString += "&" + Helper.SCOPE +"=" + Helper.OAUTH_SCOPES; + return "https://" + Helper.INSTANCE + Helper.EP_AUTHORIZE + "?" + queryString; + } + + + @Override + public void onDestroy() { + super.onDestroy(); + if (alert != null) { + alert.dismiss(); + alert = null; + } + } + + @SuppressWarnings("deprecation") + public static void clearCookies(Context context) + { + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { + CookieManager.getInstance().removeAllCookies(null); + CookieManager.getInstance().flush(); + } else { + CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context); + cookieSyncMngr.startSync(); + CookieManager cookieManager=CookieManager.getInstance(); + cookieManager.removeAllCookie(); + cookieManager.removeSessionCookie(); + cookieSyncMngr.stopSync(); + cookieSyncMngr.sync(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAccountsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAccountsAsyncTask.java new file mode 100644 index 000000000..dce7ec62d --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAccountsAsyncTask.java @@ -0,0 +1,59 @@ +/* Copyright 2017 Thomas Schneider + * + * This file is a part of Mastodon Etalab for mastodon.etalab.gouv.fr + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Mastodon Etalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Thomas Schneider; if not, + * see . */ +package fr.gouv.etalab.mastodon.asynctasks; + +import android.content.Context; +import android.os.AsyncTask; + +import java.util.List; + +import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface; + + +/** + * Created by Thomas on 25/05/2017. + * Retrieves accounts from search (ie: starting with @ when writing a toot) + */ + +public class RetrieveSearchAccountsAsyncTask extends AsyncTask { + + private Context context; + private String query; + private List accounts; + private OnRetrieveSearcAccountshInterface listener; + + + public RetrieveSearchAccountsAsyncTask(Context context, String query, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){ + this.context = context; + this.query = query; + this.listener = onRetrieveSearcAccountshInterface; + } + + + @Override + protected Void doInBackground(Void... params) { + + accounts = new API(context).searchAccounts(query); + return null; + } + + @Override + protected void onPostExecute(Void result) { + listener.onRetrieveSearchAccounts(accounts); + } + +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAsyncTask.java index ed57d586c..50f442ff1 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAsyncTask.java @@ -23,8 +23,8 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface; /** - * Created by Thomas on 05/05/2017. - * Retrieves accounts from search (ie: starting with @ when writing a toot) + * Created by Thomas on 25/05/2017. + * Retrieves accounts and toots from search */ public class RetrieveSearchAsyncTask extends AsyncTask { @@ -41,6 +41,7 @@ public class RetrieveSearchAsyncTask extends AsyncTask { this.listener = onRetrieveSearchInterface; } + @Override protected Void doInBackground(Void... params) { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java index fa8c5154a..b482cffbf 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java @@ -38,7 +38,6 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask { private Context context; private String token; - public UpdateAccountInfoAsyncTask(Context context, String token){ this.context = context; this.token = token; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 2e3da2279..c8a8b15d3 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.client; import android.content.Context; import android.content.SharedPreferences; +import android.util.Log; import android.widget.Toast; import com.loopj.android.http.AsyncHttpResponseHandler; @@ -804,7 +805,7 @@ public class API { /** - * Retrieves Accounts when searching (ie: via @...) *synchronously* + * Retrieves Accounts and feeds when searching *synchronously* * * @param query String search * @return List @@ -812,9 +813,8 @@ public class API { public Results search(String query) { RequestParams params = new RequestParams(); - params.put("q", query); + params.add("q", query); //params.put("resolve","false"); - params.put("limit","4"); get("/search", params, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { @@ -828,6 +828,38 @@ public class API { return results; } + /** + * Retrieves Accounts when searching (ie: via @...) *synchronously* + * + * @param query String search + * @return List + */ + public List searchAccounts(String query) { + + RequestParams params = new RequestParams(); + params.add("q", query); + //params.put("resolve","false"); + params.add("limit", "4"); + get("/accounts/search", params, new JsonHttpResponseHandler() { + + @Override + public void onSuccess(int statusCode, Header[] headers, JSONObject response) { + accounts = new ArrayList<>(); + account = parseAccountResponse(response); + accounts.add(account); + } + + @Override + public void onSuccess(int statusCode, Header[] headers, JSONArray response) { + accounts = parseAccountResponse(response); + } + @Override + public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){ + + } + }); + return accounts; + } /** * Parse json response an unique account diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java index 43aecff89..221b89afe 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java @@ -14,13 +14,17 @@ * see . */ package fr.gouv.etalab.mastodon.client.Entities; +import android.os.Parcel; +import android.os.Parcelable; + import java.util.Date; /** * Created by Thomas on 23/04/2017. + * Manage accounts */ -public class Account { +public class Account implements Parcelable { private String id; private String username; @@ -40,6 +44,39 @@ public class Account { private String token; private String instance; + protected Account(Parcel in) { + id = in.readString(); + username = in.readString(); + acct = in.readString(); + display_name = in.readString(); + locked = in.readByte() != 0; + followers_count = in.readInt(); + following_count = in.readInt(); + statuses_count = in.readInt(); + note = in.readString(); + url = in.readString(); + avatar = in.readString(); + avatar_static = in.readString(); + header = in.readString(); + header_static = in.readString(); + token = in.readString(); + instance = in.readString(); + } + + public Account(){} + + public static final Creator CREATOR = new Creator() { + @Override + public Account createFromParcel(Parcel in) { + return new Account(in); + } + + @Override + public Account[] newArray(int size) { + return new Account[size]; + } + }; + public String getId() { return id; } @@ -175,4 +212,29 @@ public class Account { public void setInstance(String instance) { this.instance = instance; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(id); + dest.writeString(username); + dest.writeString(acct); + dest.writeString(display_name); + dest.writeByte((byte) (locked ? 1 : 0)); + dest.writeInt(followers_count); + dest.writeInt(following_count); + dest.writeInt(statuses_count); + dest.writeString(note); + dest.writeString(url); + dest.writeString(avatar); + dest.writeString(avatar_static); + dest.writeString(header); + dest.writeString(header_static); + dest.writeString(token); + dest.writeString(instance); + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java index 055e26ce3..0fec5fef2 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java @@ -15,15 +15,18 @@ package fr.gouv.etalab.mastodon.client.Entities; +import android.os.Parcel; +import android.os.Parcelable; + import java.util.Date; import java.util.List; /** * Created by Thomas on 23/04/2017. - * + * Manage Status (ie: toots) */ -public class Status { +public class Status implements Parcelable { private String id; private String uri; @@ -43,6 +46,38 @@ public class Status { private String visibility; private boolean attachmentShown = false; + protected Status(Parcel in) { + id = in.readString(); + uri = in.readString(); + url = in.readString(); + in_reply_to_id = in.readString(); + in_reply_to_account_id = in.readString(); + reblog = in.readParcelable(Status.class.getClassLoader()); + content = in.readString(); + reblogs_count = in.readInt(); + favourites_count = in.readInt(); + reblogged = in.readByte() != 0; + favourited = in.readByte() != 0; + sensitive = in.readByte() != 0; + spoiler_text = in.readString(); + visibility = in.readString(); + attachmentShown = in.readByte() != 0; + } + + public Status(){} + + public static final Creator CREATOR = new Creator() { + @Override + public Status createFromParcel(Parcel in) { + return new Status(in); + } + + @Override + public Status[] newArray(int size) { + return new Status[size]; + } + }; + public String getId() { return id; } @@ -217,4 +252,28 @@ public class Status { public void setAttachmentShown(boolean attachmentShown) { this.attachmentShown = attachmentShown; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(id); + dest.writeString(uri); + dest.writeString(url); + dest.writeString(in_reply_to_id); + dest.writeString(in_reply_to_account_id); + dest.writeParcelable(reblog, flags); + dest.writeString(content); + dest.writeInt(reblogs_count); + dest.writeInt(favourites_count); + dest.writeByte((byte) (reblogged ? 1 : 0)); + dest.writeByte((byte) (favourited ? 1 : 0)); + dest.writeByte((byte) (sensitive ? 1 : 0)); + dest.writeString(spoiler_text); + dest.writeString(visibility); + dest.writeByte((byte) (attachmentShown ? 1 : 0)); + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java index 0b144a899..0cd6d4dfd 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java @@ -18,9 +18,11 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Parcelable; import android.support.v4.app.Fragment; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.widget.SwipeRefreshLayout; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -61,6 +63,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou private int accountPerPage; private String targetedId; private boolean hideHeader = false; + private boolean comesFromSearch = false; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -69,15 +72,24 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou context = getContext(); Bundle bundle = this.getArguments(); + accounts = new ArrayList<>(); if (bundle != null) { type = (RetrieveAccountsAsyncTask.Type) bundle.get("type"); targetedId = bundle.getString("targetedId", null); hideHeader = bundle.getBoolean("hideHeader", false); + if( bundle.containsKey("accounts")){ + ArrayList accountsReceived = bundle.getParcelableArrayList("accounts"); + assert accountsReceived != null; + for(Parcelable account: accountsReceived){ + accounts.add((Account)account); + } + comesFromSearch = true; + } } max_id = null; firstLoad = true; flag_loading = true; - accounts = new ArrayList<>(); + swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); @@ -91,79 +103,89 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou nextElementLoader.setVisibility(View.GONE); accountsListAdapter = new AccountsListAdapter(context, type, this.accounts); lv_accounts.setAdapter(accountsListAdapter); - lv_accounts.setOnScrollListener(new AbsListView.OnScrollListener() { - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) { - } - public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - - if(firstVisibleItem + visibleItemCount == totalItemCount ) { - if(!flag_loading ) { - flag_loading = true; - if( type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING) - asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else - asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - nextElementLoader.setVisibility(View.VISIBLE); - } - } else { - nextElementLoader.setVisibility(View.GONE); - } - } - }); - - //Hide account header when scrolling for ShowAccountActivity - if( hideHeader ) { + if( !comesFromSearch) { lv_accounts.setOnScrollListener(new AbsListView.OnScrollListener() { - int lastFirstVisibleItem = 0; - @Override public void onScrollStateChanged(AbsListView view, int scrollState) { + } - @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - if (view.getId() == lv_accounts.getId() && totalItemCount > visibleItemCount) { - final int currentFirstVisibleItem = lv_accounts.getFirstVisiblePosition(); - if (currentFirstVisibleItem > lastFirstVisibleItem) { - Intent intent = new Intent(Helper.HEADER_ACCOUNT); - intent.putExtra("hide", true); - LocalBroadcastManager.getInstance(context).sendBroadcast(intent); - } else if (currentFirstVisibleItem < lastFirstVisibleItem) { - Intent intent = new Intent(Helper.HEADER_ACCOUNT); - intent.putExtra("hide", false); - LocalBroadcastManager.getInstance(context).sendBroadcast(intent); + if (firstVisibleItem + visibleItemCount == totalItemCount) { + if (!flag_loading) { + flag_loading = true; + if (type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING) + asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else + asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + nextElementLoader.setVisibility(View.VISIBLE); } - lastFirstVisibleItem = currentFirstVisibleItem; + } else { + nextElementLoader.setVisibility(View.GONE); } } }); - } - swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - max_id = null; - accounts = new ArrayList<>(); - firstLoad = true; - flag_loading = true; - if( type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING) - asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else - asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + //Hide account header when scrolling for ShowAccountActivity + if (hideHeader) { + lv_accounts.setOnScrollListener(new AbsListView.OnScrollListener() { + int lastFirstVisibleItem = 0; + + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) { + } + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + if (view.getId() == lv_accounts.getId() && totalItemCount > visibleItemCount) { + final int currentFirstVisibleItem = lv_accounts.getFirstVisiblePosition(); + + if (currentFirstVisibleItem > lastFirstVisibleItem) { + Intent intent = new Intent(Helper.HEADER_ACCOUNT); + intent.putExtra("hide", true); + LocalBroadcastManager.getInstance(context).sendBroadcast(intent); + } else if (currentFirstVisibleItem < lastFirstVisibleItem) { + Intent intent = new Intent(Helper.HEADER_ACCOUNT); + intent.putExtra("hide", false); + LocalBroadcastManager.getInstance(context).sendBroadcast(intent); + } + lastFirstVisibleItem = currentFirstVisibleItem; + } + } + }); } - }); - swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, - R.color.colorPrimary, - R.color.colorPrimaryDark); + + swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + max_id = null; + accounts = new ArrayList<>(); + firstLoad = true; + flag_loading = true; + if (type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING) + asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else + asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + }); + swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, + R.color.colorPrimary, + R.color.colorPrimaryDark); - if( type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING) - asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else - asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING) + asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else + asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }else { + accountsListAdapter.notifyDataSetChanged(); + mainLoader.setVisibility(View.GONE); + nextElementLoader.setVisibility(View.GONE); + if( accounts == null || accounts.size() == 0 ) + textviewNoAction.setVisibility(View.VISIBLE); + } return rootView; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 84466e8fe..033a5ab14 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -19,10 +19,10 @@ import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Parcelable; import android.support.v4.app.Fragment; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.widget.SwipeRefreshLayout; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -67,12 +67,13 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private String tag; private boolean hideHeader = false; private int tootsPerPage; + private boolean comesFromSearch = false; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_status, container, false); - + statuses = new ArrayList<>(); context = getContext(); Bundle bundle = this.getArguments(); if (bundle != null) { @@ -80,11 +81,19 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn targetedId = bundle.getString("targetedId", null); tag = bundle.getString("tag", null); hideHeader = bundle.getBoolean("hideHeader", false); + if( bundle.containsKey("statuses")){ + ArrayList statusesReceived = bundle.getParcelableArrayList("statuses"); + assert statusesReceived != null; + for(Parcelable status: statusesReceived){ + statuses.add((Status) status); + } + comesFromSearch = true; + } } max_id = null; flag_loading = true; firstLoad = true; - statuses = new ArrayList<>(); + boolean isOnWifi = Helper.isOnWIFI(context); swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); @@ -99,85 +108,95 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn nextElementLoader.setVisibility(View.GONE); statusListAdapter = new StatusListAdapter(context, type, isOnWifi, behaviorWithAttachments, this.statuses); lv_status.setAdapter(statusListAdapter); - lv_status.setOnScrollListener(new AbsListView.OnScrollListener() { - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) { - } - public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - if(firstVisibleItem + visibleItemCount == totalItemCount ) { - if(!flag_loading ) { - flag_loading = true; - if( type == RetrieveFeedsAsyncTask.Type.USER) - asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else if( type == RetrieveFeedsAsyncTask.Type.TAG) - asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else - asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - nextElementLoader.setVisibility(View.VISIBLE); - } - } else { - nextElementLoader.setVisibility(View.GONE); - } - } - }); - - //Hide account header when scrolling for ShowAccountActivity - if( hideHeader ) { + if( !comesFromSearch){ lv_status.setOnScrollListener(new AbsListView.OnScrollListener() { - int lastFirstVisibleItem = 0; - @Override public void onScrollStateChanged(AbsListView view, int scrollState) { + } - - @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - if (view.getId() == lv_status.getId() && totalItemCount > visibleItemCount) { - final int currentFirstVisibleItem = lv_status.getFirstVisiblePosition(); + if(firstVisibleItem + visibleItemCount == totalItemCount ) { + if(!flag_loading ) { + flag_loading = true; + if( type == RetrieveFeedsAsyncTask.Type.USER) + asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else if( type == RetrieveFeedsAsyncTask.Type.TAG) + asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else + asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - if (currentFirstVisibleItem > lastFirstVisibleItem) { - Intent intent = new Intent(Helper.HEADER_ACCOUNT); - intent.putExtra("hide", true); - LocalBroadcastManager.getInstance(context).sendBroadcast(intent); - } else if (currentFirstVisibleItem < lastFirstVisibleItem) { - Intent intent = new Intent(Helper.HEADER_ACCOUNT); - intent.putExtra("hide", false); - LocalBroadcastManager.getInstance(context).sendBroadcast(intent); + nextElementLoader.setVisibility(View.VISIBLE); } - lastFirstVisibleItem = currentFirstVisibleItem; + } else { + nextElementLoader.setVisibility(View.GONE); } } }); + + //Hide account header when scrolling for ShowAccountActivity + if( hideHeader ) { + lv_status.setOnScrollListener(new AbsListView.OnScrollListener() { + int lastFirstVisibleItem = 0; + + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) { + } + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + if (view.getId() == lv_status.getId() && totalItemCount > visibleItemCount) { + final int currentFirstVisibleItem = lv_status.getFirstVisiblePosition(); + + if (currentFirstVisibleItem > lastFirstVisibleItem) { + Intent intent = new Intent(Helper.HEADER_ACCOUNT); + intent.putExtra("hide", true); + LocalBroadcastManager.getInstance(context).sendBroadcast(intent); + } else if (currentFirstVisibleItem < lastFirstVisibleItem) { + Intent intent = new Intent(Helper.HEADER_ACCOUNT); + intent.putExtra("hide", false); + LocalBroadcastManager.getInstance(context).sendBroadcast(intent); + } + lastFirstVisibleItem = currentFirstVisibleItem; + } + } + }); + } + + swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + max_id = null; + statuses = new ArrayList<>(); + firstLoad = true; + flag_loading = true; + if( type == RetrieveFeedsAsyncTask.Type.USER) + asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else if( type == RetrieveFeedsAsyncTask.Type.TAG) + asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else + asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + }); + swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, + R.color.colorPrimary, + R.color.colorPrimaryDark); + + + if( type == RetrieveFeedsAsyncTask.Type.USER) + asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else if( type == RetrieveFeedsAsyncTask.Type.TAG) + asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else + asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }else { + statusListAdapter.notifyDataSetChanged(); + mainLoader.setVisibility(View.GONE); + nextElementLoader.setVisibility(View.GONE); + if( statuses == null || statuses.size() == 0 ) + textviewNoAction.setVisibility(View.VISIBLE); } - swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - max_id = null; - statuses = new ArrayList<>(); - firstLoad = true; - flag_loading = true; - if( type == RetrieveFeedsAsyncTask.Type.USER) - asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else if( type == RetrieveFeedsAsyncTask.Type.TAG) - asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else - asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - }); - swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, - R.color.colorPrimary, - R.color.colorPrimaryDark); - - - if( type == RetrieveFeedsAsyncTask.Type.USER) - asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else if( type == RetrieveFeedsAsyncTask.Type.TAG) - asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else - asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); return rootView; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index a0fb5f826..d157c8252 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Resources; import android.graphics.Bitmap; import android.media.RingtoneManager; import android.net.ConnectivityManager; @@ -33,6 +34,7 @@ import android.os.Build; import android.os.Environment; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationManagerCompat; +import android.util.DisplayMetrics; import android.view.WindowManager; import android.widget.Toast; @@ -73,6 +75,7 @@ public class Helper { public static final String PREF_KEY_OAUTH_TOKEN = "oauth_token"; public static final String PREF_KEY_ID = "userID"; public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob"; + public static final String REDIRECT_CONTENT_WEB = "mastalab://backtomastalab"; public static final int EXTERNAL_STORAGE_REQUEST_CODE = 84; //Some definitions @@ -413,4 +416,11 @@ public class Helper { notificationBuilder.setLargeIcon(icon); notificationManager.notify(notificationId, notificationBuilder.build()); } + + + public static float convertDpToPixel(float dp, Context context){ + Resources resources = context.getResources(); + DisplayMetrics metrics = resources.getDisplayMetrics(); + return dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveSearcAccountshInterface.java b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveSearcAccountshInterface.java new file mode 100644 index 000000000..8be83b934 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveSearcAccountshInterface.java @@ -0,0 +1,28 @@ +/* Copyright 2017 Thomas Schneider + * + * This file is a part of Mastodon Etalab for mastodon.etalab.gouv.fr + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Mastodon Etalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Thomas Schneider; if not, + * see . */ +package fr.gouv.etalab.mastodon.interfaces; + +import java.util.List; + +import fr.gouv.etalab.mastodon.client.Entities.Account; + + +/** + * Created by Thomas on 25/05/2017. + * Interface for search accounts + */ +public interface OnRetrieveSearcAccountshInterface { + void onRetrieveSearchAccounts(List accounts); +} diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index e8f35ad13..53a6e9d1d 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -52,6 +52,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> +