Adds 2FA support via webview
This commit is contained in:
parent
4aa44f1af6
commit
32046c3c87
|
@ -53,6 +53,17 @@
|
|||
android:noHistory="true"
|
||||
android:label="@string/app_name"
|
||||
/>
|
||||
<activity android:name="fr.gouv.etalab.mastodon.activities.WebviewActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:launchMode="singleTask"
|
||||
/>
|
||||
<activity android:name="fr.gouv.etalab.mastodon.activities.SearchResultActivity"
|
||||
android:windowSoftInputMode="stateAlwaysHidden"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:noHistory="true"
|
||||
android:label="@string/app_name"
|
||||
/>
|
||||
<activity android:name="fr.gouv.etalab.mastodon.activities.ShowConversationActivity"
|
||||
android:windowSoftInputMode="stateAlwaysHidden"
|
||||
android:configChanges="orientation|screenSize"
|
||||
|
|
|
@ -15,13 +15,18 @@
|
|||
package fr.gouv.etalab.mastodon.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Paint;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.loopj.android.http.AsyncHttpClient;
|
||||
|
@ -53,6 +58,10 @@ import static fr.gouv.etalab.mastodon.helper.Helper.USER_AGENT;
|
|||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
private String client_id;
|
||||
private String client_secret;
|
||||
private TextView login_two_step;
|
||||
private static boolean client_id_for_webview = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -61,15 +70,27 @@ public class LoginActivity extends AppCompatActivity {
|
|||
|
||||
Button connectionButton = (Button) findViewById(R.id.login_button);
|
||||
connectionButton.setEnabled(false);
|
||||
|
||||
login_two_step = (TextView) findViewById(R.id.login_two_step);
|
||||
login_two_step.setVisibility(View.GONE);
|
||||
login_two_step.setPaintFlags(login_two_step.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
login_two_step.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
client_id_for_webview = true;
|
||||
retrievesClientId();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume(){
|
||||
super.onResume();
|
||||
Button connectionButton = (Button) findViewById(R.id.login_button);
|
||||
if( !connectionButton.isEnabled())
|
||||
if( client_id_for_webview || !connectionButton.isEnabled()) {
|
||||
connectionButton.setEnabled(false);
|
||||
client_id_for_webview = false;
|
||||
retrievesClientId();
|
||||
}
|
||||
}
|
||||
|
||||
private void retrievesClientId(){
|
||||
|
@ -77,7 +98,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
String action = "/api/v1/apps";
|
||||
RequestParams parameters = new RequestParams();
|
||||
parameters.add(Helper.CLIENT_NAME, Helper.OAUTH_REDIRECT_HOST);
|
||||
parameters.add(Helper.REDIRECT_URIS, Helper.REDIRECT_CONTENT);
|
||||
parameters.add(Helper.REDIRECT_URIS, client_id_for_webview?Helper.REDIRECT_CONTENT_WEB:Helper.REDIRECT_CONTENT);
|
||||
parameters.add(Helper.SCOPES, Helper.OAUTH_SCOPES);
|
||||
parameters.add(Helper.WEBSITE,"https://" + Helper.INSTANCE);
|
||||
new OauthClient().post(action, parameters, new AsyncHttpResponseHandler() {
|
||||
|
@ -87,8 +108,8 @@ public class LoginActivity extends AppCompatActivity {
|
|||
JSONObject resobj;
|
||||
try {
|
||||
resobj = new JSONObject(response);
|
||||
String client_id = resobj.get(Helper.CLIENT_ID).toString();
|
||||
String client_secret = resobj.get(Helper.CLIENT_SECRET).toString();
|
||||
client_id = resobj.get(Helper.CLIENT_ID).toString();
|
||||
client_secret = resobj.get(Helper.CLIENT_SECRET).toString();
|
||||
|
||||
String id = resobj.get(Helper.ID).toString();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
@ -98,6 +119,11 @@ public class LoginActivity extends AppCompatActivity {
|
|||
editor.putString(Helper.ID, id);
|
||||
editor.apply();
|
||||
connectionButton.setEnabled(true);
|
||||
login_two_step.setVisibility(View.VISIBLE);
|
||||
if( client_id_for_webview){
|
||||
Intent i = new Intent(LoginActivity.this, WebviewActivity.class);
|
||||
startActivity(i);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -115,6 +141,11 @@ public class LoginActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
connectionButton.setEnabled(false);
|
||||
if( client_id_for_webview ){
|
||||
client_id_for_webview = false;
|
||||
retrievesClientId();
|
||||
return;
|
||||
}
|
||||
AsyncHttpClient client = new AsyncHttpClient();
|
||||
RequestParams requestParams = new RequestParams();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
|
|
@ -272,20 +272,15 @@ public class MainActivity extends AppCompatActivity
|
|||
}else{
|
||||
String searchTag = ((EditText) toolbar.getChildAt(i)).getText().toString();
|
||||
toot.setVisibility(View.VISIBLE);
|
||||
DisplayStatusFragment statusFragment = new DisplayStatusFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.TAG);
|
||||
bundle.putString("tag", searchTag);
|
||||
statusFragment.setArguments(bundle);
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, statusFragment).commit();
|
||||
View view = this.getCurrentFocus();
|
||||
//Hide keyboard
|
||||
if (view != null) {
|
||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
Intent intent = new Intent(MainActivity.this, SearchResultActivity.class);
|
||||
intent.putExtra("search", searchTag);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
/* 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 <http://www.gnu.org/licenses>. */
|
||||
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<Account> accounts;
|
||||
private List<Status> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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));
|
||||
|
|
|
@ -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<Account> 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);
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
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<Void, Void, Void> {
|
||||
|
||||
private Context context;
|
||||
private String query;
|
||||
private List<Account> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Void, Void, Void> {
|
||||
|
@ -41,6 +41,7 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.listener = onRetrieveSearchInterface;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private Context context;
|
||||
private String token;
|
||||
|
||||
|
||||
public UpdateAccountInfoAsyncTask(Context context, String token){
|
||||
this.context = context;
|
||||
this.token = token;
|
||||
|
|
|
@ -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<Account>
|
||||
|
@ -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<Account>
|
||||
*/
|
||||
public List<Account> 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
|
||||
|
|
|
@ -14,13 +14,17 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
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<Account> CREATOR = new Creator<Account>() {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Status> CREATOR = new Creator<Status>() {
|
||||
@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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Parcelable> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Parcelable> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
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<Account> accounts);
|
||||
}
|
|
@ -52,6 +52,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/login_button"
|
||||
android:textAllCaps="false"
|
||||
|
@ -71,6 +72,20 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/login" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/login_two_step"
|
||||
android:textAllCaps="false"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:drawablePadding="10dp"
|
||||
android:padding="20dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:text="@string/two_factor_authentification" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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 <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<android.support.design.widget.AppBarLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:background="@android:color/white"
|
||||
android:layout_height="wrap_content">
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/search_tabLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/white"
|
||||
app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
|
||||
app:tabMode="fixed"
|
||||
app:tabGravity="fill"
|
||||
/>
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/search_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/white"
|
||||
/>
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
<!-- Main Loader -->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/loader"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
|
@ -24,80 +24,75 @@
|
|||
android:orientation="vertical"
|
||||
>
|
||||
<LinearLayout
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<ImageView
|
||||
android:padding="10dp"
|
||||
android:id="@+id/account_pp"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
<LinearLayout
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:padding="10dp"
|
||||
android:id="@+id/account_pp"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/account_dn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
<TextView
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:id="@+id/account_un"
|
||||
android:layout_width="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:visibility="gone"
|
||||
android:id="@+id/account_followed_by"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:text="@string/followed_by"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:layout_marginTop="5dp"
|
||||
android:id="@+id/account_ac"
|
||||
android:gravity="center"
|
||||
android:textSize="16sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<Button
|
||||
android:layout_marginTop="10dp"
|
||||
android:id="@+id/account_follow"
|
||||
android:textAllCaps="false"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:maxLines="1"
|
||||
android:id="@+id/account_dn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginBottom="10dp"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:text="@string/action_follow" />
|
||||
android:textSize="18sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
<TextView
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:id="@+id/account_un"
|
||||
android:layout_width="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:visibility="gone"
|
||||
android:id="@+id/account_followed_by"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:text="@string/followed_by"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:layout_marginTop="5dp"
|
||||
android:id="@+id/account_ac"
|
||||
android:gravity="center"
|
||||
android:textSize="16sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<Button
|
||||
android:layout_marginTop="10dp"
|
||||
android:id="@+id/account_follow"
|
||||
android:textAllCaps="false"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:maxLines="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginBottom="10dp"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:text="@string/action_follow" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
|
@ -113,6 +108,7 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:background="@android:color/white"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.design.widget.TabLayout
|
||||
|
@ -120,6 +116,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/white"
|
||||
app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
|
||||
app:tabMode="fixed"
|
||||
app:tabGravity="fill"
|
||||
/>
|
||||
|
|
|
@ -167,8 +167,11 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingLeft="@dimen/drawer_padding"
|
||||
android:paddingRight="@dimen/drawer_padding"
|
||||
android:padding="@dimen/drawer_padding"
|
||||
android:layout_marginStart="@dimen/activity_vertical_margin"
|
||||
android:layout_marginLeft="@dimen/activity_vertical_margin"
|
||||
android:layout_marginEnd="@dimen/activity_vertical_margin"
|
||||
android:layout_marginRight="@dimen/activity_vertical_margin"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:drawableStart="@drawable/dr_favorites"
|
||||
|
@ -180,8 +183,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:layout_marginLeft="30dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:drawableStart="@drawable/dr_reblogs"
|
||||
android:drawableLeft="@drawable/dr_reblogs"
|
||||
android:drawablePadding="2dp"
|
||||
|
@ -191,13 +194,14 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<ImageView
|
||||
android:layout_marginLeft="30dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:id="@+id/status_reply"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/ic_reply"/>
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:src="@drawable/ic_reply"
|
||||
tools:ignore="ContentDescription" />
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
|
@ -211,17 +215,17 @@
|
|||
android:layout_marginEnd="20dp"
|
||||
android:id="@+id/status_privacy"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:background="@color/light_grey"
|
||||
/>
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
<ImageView
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:id="@+id/status_more"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/ic_action_more"/>
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:src="@drawable/ic_action_more"
|
||||
tools:ignore="ContentDescription" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -19,6 +19,10 @@
|
|||
<string name="download_file">Télécharger %1$s</string>
|
||||
<string name="password">Mot de passe</string>
|
||||
<string name="email">Email</string>
|
||||
<string name="accounts">Comptes</string>
|
||||
<string name="toots">Pouets</string>
|
||||
<string name="token">Jeton</string>
|
||||
<string name="two_factor_authentification">Authentification en deux étapes ?</string>
|
||||
<!--- Menu -->
|
||||
<string name="home_menu">Accueil</string>
|
||||
<string name="home_timeline">Accueil</string>
|
||||
|
|
Loading…
Reference in New Issue