About page
This commit is contained in:
parent
7ddd55ef91
commit
940ecc2436
|
@ -148,11 +148,8 @@ public class MainActivity extends AppCompatActivity
|
|||
if(notificationsFragment.getUserVisibleHint() && isActivityVisible()){
|
||||
notificationsFragment.updateData(notification);
|
||||
}else{
|
||||
updateNotifCounter();
|
||||
notificationsFragment.refresh(notification);
|
||||
}
|
||||
}else {
|
||||
updateNotifCounter();
|
||||
}
|
||||
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
|
||||
Status status = b.getParcelable("data");
|
||||
|
@ -160,11 +157,8 @@ public class MainActivity extends AppCompatActivity
|
|||
if(homeFragment.getUserVisibleHint() && isActivityVisible()){
|
||||
homeFragment.updateData(status);
|
||||
}else{
|
||||
updateHomeCounter();
|
||||
homeFragment.refresh(status);
|
||||
}
|
||||
}else{
|
||||
updateHomeCounter();
|
||||
}
|
||||
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
|
||||
String id = b.getString("id");
|
||||
|
@ -176,6 +170,8 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
}
|
||||
updateNotifCounter();
|
||||
updateHomeCounter();
|
||||
}
|
||||
};
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
|
||||
|
@ -868,6 +864,8 @@ public class MainActivity extends AppCompatActivity
|
|||
public void onResume(){
|
||||
super.onResume();
|
||||
MainActivity.activityResumed();
|
||||
updateNotifCounter();
|
||||
updateHomeCounter();
|
||||
//Proceeds to update of the authenticated account
|
||||
if(Helper.isLoggedIn(getApplicationContext()))
|
||||
new UpdateAccountInfoByIDAsyncTask(getApplicationContext(), MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
|
|
@ -23,30 +23,28 @@ import android.os.AsyncTask;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextPaint;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveDeveloperAccountsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveRelationshipAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveRemoteAccountsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.drawers.AccountSearchWebAdapter;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
|
||||
import fr.gouv.etalab.mastodon.drawers.AccountSearchDevAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.ExpandableHeightListView;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRelationshipInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchDevelopersAccountshInterface;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
||||
|
||||
|
@ -55,14 +53,12 @@ import mastodon.etalab.gouv.fr.mastodon.R;
|
|||
* About activity
|
||||
*/
|
||||
|
||||
public class AboutActivity extends AppCompatActivity implements OnRetrieveRemoteAccountInterface {
|
||||
public class AboutActivity extends AppCompatActivity implements OnRetrieveRemoteAccountInterface, OnRetrieveSearchDevelopersAccountshInterface, OnRetrieveRelationshipInterface {
|
||||
|
||||
private ListView lv_developers;
|
||||
private ListView lv_contributors;
|
||||
private List<Account> developers = new ArrayList<>();
|
||||
private List<Account> contributors = new ArrayList<>();
|
||||
private AccountSearchWebAdapter accountSearchWebAdapterDeveloper;
|
||||
private AccountSearchWebAdapter accountSearchWebAdapterContributors;
|
||||
private AccountSearchDevAdapter accountSearchWebAdapterDeveloper;
|
||||
private AccountSearchDevAdapter accountSearchWebAdapterContributors;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
|
@ -85,8 +81,8 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveRemote
|
|||
about_version.setText(getResources().getString(R.string.about_vesrion, version));
|
||||
} catch (PackageManager.NameNotFoundException ignored) {}
|
||||
|
||||
lv_developers = (ListView) findViewById(R.id.lv_developers);
|
||||
lv_contributors = (ListView) findViewById(R.id.lv_contributors);
|
||||
ExpandableHeightListView lv_developers = (ExpandableHeightListView) findViewById(R.id.lv_developers);
|
||||
ExpandableHeightListView lv_contributors = (ExpandableHeightListView) findViewById(R.id.lv_contributors);
|
||||
Button about_code = (Button) findViewById(R.id.about_code);
|
||||
Button about_license = (Button) findViewById(R.id.about_license);
|
||||
Button about_thekinrar = (Button) findViewById(R.id.about_thekinrar);
|
||||
|
@ -131,14 +127,13 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveRemote
|
|||
about_license.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
|
||||
}
|
||||
|
||||
accountSearchWebAdapterContributors = new AccountSearchWebAdapter(AboutActivity.this, contributors);
|
||||
lv_contributors.setExpanded(true);
|
||||
lv_developers.setExpanded(true);
|
||||
accountSearchWebAdapterContributors = new AccountSearchDevAdapter(AboutActivity.this, contributors);
|
||||
lv_contributors.setAdapter(accountSearchWebAdapterContributors);
|
||||
accountSearchWebAdapterDeveloper = new AccountSearchWebAdapter(AboutActivity.this, developers);
|
||||
accountSearchWebAdapterDeveloper = new AccountSearchDevAdapter(AboutActivity.this, developers);
|
||||
lv_developers.setAdapter(accountSearchWebAdapterDeveloper);
|
||||
Log.v(Helper.TAG,"here");
|
||||
new RetrieveRemoteAccountsAsyncTask("tschneider", "mastodon.etalab.gouv.fr", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new RetrieveRemoteAccountsAsyncTask("PhotonQyv", "mastodon.xyz", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new RetrieveRemoteAccountsAsyncTask("angrytux", "social.tchncs.de", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new RetrieveDeveloperAccountsAsyncTask(getApplicationContext(), AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
|
||||
|
@ -170,9 +165,10 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveRemote
|
|||
account.setUsername(name);
|
||||
account.setLocked(locked);
|
||||
account.setNote(bio);
|
||||
account.setFollowing(false);
|
||||
account.setRemote(true);
|
||||
|
||||
|
||||
if( username.equals("tschneider")) {
|
||||
if( username.equals("@tschneider")) {
|
||||
developers.add(account);
|
||||
accountSearchWebAdapterDeveloper.notifyDataSetChanged();
|
||||
}else {
|
||||
|
@ -181,4 +177,70 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveRemote
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveSearchDevelopersAccounts(ArrayList<Account> accounts) {
|
||||
if( accounts == null || accounts.size() == 0) {
|
||||
new RetrieveRemoteAccountsAsyncTask("tschneider", "mastodon.etalab.gouv.fr", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new RetrieveRemoteAccountsAsyncTask("PhotonQyv", "mastodon.xyz", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new RetrieveRemoteAccountsAsyncTask("angrytux", "social.tchncs.de", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
return;
|
||||
}
|
||||
boolean tschneider = false;
|
||||
boolean PhotonQyv = false;
|
||||
boolean angrytux = false;
|
||||
for(Account account: accounts){
|
||||
if( account.getUsername().equals("tschneider")){
|
||||
account.setFollowing(false);
|
||||
account.setRemote(false);
|
||||
developers.add(account);
|
||||
accountSearchWebAdapterDeveloper.notifyDataSetChanged();
|
||||
tschneider = true;
|
||||
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
if( account.getUsername().equals("PhotonQyv")){
|
||||
account.setFollowing(false);
|
||||
account.setRemote(false);
|
||||
contributors.add(account);
|
||||
accountSearchWebAdapterContributors.notifyDataSetChanged();
|
||||
PhotonQyv = true;
|
||||
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
if( account.getUsername().equals("angrytux")){
|
||||
account.setFollowing(false);
|
||||
account.setRemote(false);
|
||||
contributors.add(account);
|
||||
accountSearchWebAdapterContributors.notifyDataSetChanged();
|
||||
angrytux = true;
|
||||
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
if( !tschneider)
|
||||
new RetrieveRemoteAccountsAsyncTask("tschneider", "mastodon.etalab.gouv.fr", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( !PhotonQyv)
|
||||
new RetrieveRemoteAccountsAsyncTask("PhotonQyv", "mastodon.xyz", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( !angrytux)
|
||||
new RetrieveRemoteAccountsAsyncTask("angrytux", "social.tchncs.de", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveRelationship(Relationship relationship, Error error) {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
|
||||
if( error != null){
|
||||
return;
|
||||
}
|
||||
for( int i = 0 ; i < developers.size() ; i++){
|
||||
if( developers.get(i).getId().equals(relationship.getId()) && relationship.isFollowing() || userId.trim().equals(relationship.getId())){
|
||||
developers.get(i).setFollowing(true);
|
||||
accountSearchWebAdapterDeveloper.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
for( int i = 0 ; i < contributors.size() ; i++){
|
||||
if( contributors.get(i).getId().equals(relationship.getId()) && relationship.isFollowing() || userId.trim().equals(relationship.getId())){
|
||||
contributors.get(i).setFollowing(true);
|
||||
accountSearchWebAdapterContributors.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,13 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchDevelopersAccountshInterface;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -29,23 +33,32 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface;
|
|||
public class RetrieveDeveloperAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private Context context;
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrieveSearcAccountshInterface listener;
|
||||
private OnRetrieveSearchDevelopersAccountshInterface listener;
|
||||
private ArrayList<Account> accounts;
|
||||
|
||||
public RetrieveDeveloperAccountsAsyncTask(Context context, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){
|
||||
public RetrieveDeveloperAccountsAsyncTask(Context context, OnRetrieveSearchDevelopersAccountshInterface onRetrieveSearchDevelopersAccountshInterface){
|
||||
this.context = context;
|
||||
this.listener = onRetrieveSearcAccountshInterface;
|
||||
this.listener = onRetrieveSearchDevelopersAccountshInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
API api = new API(context);
|
||||
apiResponse = api.searchDeveloper();
|
||||
accounts = new ArrayList<>();
|
||||
APIResponse apiResponse = api.searchAccounts("@tschneider@mastodon.etalab.gouv.fr", 1);
|
||||
if( apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0)
|
||||
accounts.add(apiResponse.getAccounts().get(0));
|
||||
apiResponse = api.searchAccounts("@PhotonQyv@mastodon.xyz",1);
|
||||
if( apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0)
|
||||
accounts.add(apiResponse.getAccounts().get(0));
|
||||
apiResponse = api.searchAccounts("@angrytux@social.tchncs.de",1);
|
||||
if( apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0)
|
||||
accounts.add(apiResponse.getAccounts().get(0));
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveSearchAccounts(apiResponse);
|
||||
listener.onRetrieveSearchDevelopersAccounts(accounts);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,14 +15,11 @@
|
|||
package fr.gouv.etalab.mastodon.asynctasks;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface;
|
||||
|
||||
|
||||
|
@ -45,14 +42,12 @@ public class RetrieveRemoteAccountsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
this.url = "https://" + instance + "/@" + username;
|
||||
this.listener = onRetrieveRemoteAccountInterface;
|
||||
this.instance = instance;
|
||||
Log.v(Helper.TAG,"RetrieveRemoteAccountsAsyncTask");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Log.v(Helper.TAG,"doInBackground");
|
||||
String userAgent = "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36";
|
||||
try {
|
||||
Document document = Jsoup.connect(url).userAgent(userAgent).get();
|
||||
|
@ -62,7 +57,7 @@ public class RetrieveRemoteAccountsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
Elements nameElement = document.getElementsByClass("name");
|
||||
name = nameElement.get(0).getElementsByClass("p-name").get(0).html();
|
||||
username = nameElement.get(0).getElementsByTag("span").get(1).html();
|
||||
islocked = nameElement.get(0).getElementsByClass("fa-lock") != null;
|
||||
islocked = (nameElement.get(0).getElementsByClass("fa-lock") != null && nameElement.get(0).getElementsByClass("fa-lock").size() > 0);
|
||||
|
||||
Elements bioElement = document.getElementsByClass("bio");
|
||||
bio = bioElement.get(0).html();
|
||||
|
@ -79,7 +74,6 @@ public class RetrieveRemoteAccountsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
Log.v(Helper.TAG,"onPostExecute");
|
||||
listener.onRetrieveRemoteAccount(error, name, username, instance, islocked, avatar, bio, statusCount, followingCount, followersCount);
|
||||
}
|
||||
|
||||
|
|
|
@ -1118,37 +1118,6 @@ public class API {
|
|||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves Developer account when searching (ie: via @...) *synchronously*
|
||||
*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse searchDeveloper() {
|
||||
RequestParams params = new RequestParams();
|
||||
params.add("q", "tschneider");
|
||||
get("/accounts/search", params, new JsonHttpResponseHandler() {
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
accounts = new ArrayList<>();
|
||||
account = parseAccountResponse(context, response);
|
||||
accounts.add(account);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
accounts = parseDeveloperResponse(response);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
apiResponse.setAccounts(accounts);
|
||||
return apiResponse;
|
||||
}
|
||||
/**
|
||||
* Retrieves Accounts when searching (ie: via @...) *synchronously*
|
||||
*
|
||||
|
|
|
@ -43,6 +43,8 @@ public class Account implements Parcelable {
|
|||
private String header_static;
|
||||
private String token;
|
||||
private String instance;
|
||||
private boolean isFollowing;
|
||||
private boolean isRemote;
|
||||
|
||||
protected Account(Parcel in) {
|
||||
id = in.readString();
|
||||
|
@ -237,4 +239,20 @@ public class Account implements Parcelable {
|
|||
dest.writeString(token);
|
||||
dest.writeString(instance);
|
||||
}
|
||||
|
||||
public boolean isFollowing() {
|
||||
return isFollowing;
|
||||
}
|
||||
|
||||
public void setFollowing(boolean following) {
|
||||
isFollowing = following;
|
||||
}
|
||||
|
||||
public boolean isRemote() {
|
||||
return isRemote;
|
||||
}
|
||||
|
||||
public void setRemote(boolean remote) {
|
||||
isRemote = remote;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
package fr.gouv.etalab.mastodon.drawers;
|
||||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Mastalab 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 Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 03/09/2017.
|
||||
* Adapter for accounts from web
|
||||
*/
|
||||
public class AccountSearchDevAdapter extends BaseAdapter implements OnPostActionInterface {
|
||||
|
||||
private List<Account> accounts;
|
||||
private LayoutInflater layoutInflater;
|
||||
private Context context;
|
||||
private ViewHolder holder;
|
||||
|
||||
public AccountSearchDevAdapter(Context context, List<Account> accounts){
|
||||
this.context = context;
|
||||
this.accounts = accounts;
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return accounts.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return accounts.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
|
||||
ImageLoader imageLoader = ImageLoader.getInstance();
|
||||
File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name));
|
||||
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(context)
|
||||
.imageDownloader(new PatchBaseImageDownloader(context))
|
||||
.threadPoolSize(5)
|
||||
.threadPriority(Thread.MIN_PRIORITY + 3)
|
||||
.denyCacheImageMultipleSizesInMemory()
|
||||
.diskCache(new UnlimitedDiskCache(cacheDir))
|
||||
.build();
|
||||
if( !imageLoader.isInited())
|
||||
imageLoader.init(configImg);
|
||||
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||
final Account account = accounts.get(position);
|
||||
|
||||
if (convertView == null) {
|
||||
convertView = layoutInflater.inflate(R.layout.drawer_account_search_dev, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.account_pp = (ImageView) convertView.findViewById(R.id.account_pp);
|
||||
holder.account_dn = (TextView) convertView.findViewById(R.id.account_dn);
|
||||
holder.account_un = (TextView) convertView.findViewById(R.id.account_un);
|
||||
holder.account_follow = (FloatingActionButton) convertView.findViewById(R.id.account_follow);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
//Redraws icon for locked accounts
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
if( account != null && account.isLocked()){
|
||||
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_action_lock_closed);
|
||||
img.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (20 * scale + 0.5f));
|
||||
holder.account_dn.setCompoundDrawables( null, null, img, null);
|
||||
}else{
|
||||
holder.account_dn.setCompoundDrawables( null, null, null, null);
|
||||
}
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
holder.account_dn.setText(Html.fromHtml(Helper.shortnameToUnicode(account.getDisplay_name(), true), Html.FROM_HTML_MODE_LEGACY));
|
||||
holder.account_un.setText(Html.fromHtml(Helper.shortnameToUnicode(account.getUsername(), true), Html.FROM_HTML_MODE_LEGACY));
|
||||
}else {
|
||||
//noinspection deprecation
|
||||
holder.account_dn.setText(Html.fromHtml(Helper.shortnameToUnicode(account.getDisplay_name(), true)));
|
||||
holder.account_un.setText(Html.fromHtml(Helper.shortnameToUnicode(account.getUsername(), true)));
|
||||
}
|
||||
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.mastodonC4);
|
||||
//Profile picture
|
||||
imageLoader.displayImage(account.getAvatar(), holder.account_pp, options);
|
||||
|
||||
if( account.isFollowing()){
|
||||
holder.account_follow.setVisibility(View.GONE);
|
||||
}else{
|
||||
holder.account_follow.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if( account.isRemote()) {
|
||||
holder.account_follow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
holder.account_follow.setEnabled(false);
|
||||
new PostActionAsyncTask(context, API.StatusAction.REMOTE_FOLLOW, account.getAcct(), AccountSearchDevAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
}else {
|
||||
holder.account_follow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
holder.account_follow.setEnabled(false);
|
||||
new PostActionAsyncTask(context, API.StatusAction.FOLLOW, account.getId(), AccountSearchDevAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
|
||||
if( error != null){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(context, error.getError(),Toast.LENGTH_LONG).show();
|
||||
holder.account_follow.setEnabled(true);
|
||||
return;
|
||||
}
|
||||
holder.account_follow.setVisibility(View.GONE);
|
||||
Toast.makeText(context, R.string.toast_follow, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
||||
private class ViewHolder {
|
||||
ImageView account_pp;
|
||||
TextView account_dn;
|
||||
TextView account_un;
|
||||
FloatingActionButton account_follow;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package fr.gouv.etalab.mastodon.helper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 03/09/2017.
|
||||
* Expanded listview
|
||||
*/
|
||||
|
||||
public class ExpandableHeightListView extends ListView
|
||||
{
|
||||
|
||||
boolean expanded = false;
|
||||
|
||||
public ExpandableHeightListView(Context context)
|
||||
{
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ExpandableHeightListView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ExpandableHeightListView(Context context, AttributeSet attrs,int defStyle)
|
||||
{
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public boolean isExpanded()
|
||||
{
|
||||
return expanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||
{
|
||||
// HACK! TAKE THAT ANDROID!
|
||||
if (isExpanded())
|
||||
{
|
||||
// Calculate entire height by providing a very large height hint.
|
||||
// But do not use the highest 2 bits of this integer; those are
|
||||
// reserved for the MeasureSpec mode.
|
||||
int expandSpec = View.MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, View.MeasureSpec.AT_MOST);
|
||||
super.onMeasure(widthMeasureSpec, expandSpec);
|
||||
|
||||
ViewGroup.LayoutParams params = getLayoutParams();
|
||||
params.height = getMeasuredHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
|
||||
public void setExpanded(boolean expanded)
|
||||
{
|
||||
this.expanded = expanded;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Mastalab 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 Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 03/09/2017.
|
||||
* Interface for search dev accounts
|
||||
*/
|
||||
public interface OnRetrieveSearchDevelopersAccountshInterface {
|
||||
void onRetrieveSearchDevelopersAccounts(ArrayList<Account> accounts);
|
||||
}
|
|
@ -40,40 +40,42 @@
|
|||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- About developer -->
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:padding="20dp"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:textSize="18sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:padding="5dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:layout_width="200dp"
|
||||
android:textColor="@color/mastodonC4"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/about_developer"
|
||||
android:layout_height="wrap_content" />
|
||||
<Button
|
||||
android:id="@+id/about_developer"
|
||||
android:text="@string/about_developer_action"
|
||||
android:layout_width="150dp"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp"
|
||||
android:textSize="16sp"/>
|
||||
<fr.gouv.etalab.mastodon.helper.ExpandableHeightListView
|
||||
android:id="@+id/lv_developers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
android:divider="@null"/>
|
||||
|
||||
<TextView
|
||||
android:padding="5dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:id="@+id/about_thanks_dev"
|
||||
android:text="@string/thanks_text_dev"
|
||||
android:layout_marginTop="20dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
android:textColor="@color/mastodonC4"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="16sp"
|
||||
android:text="@string/thanks_text_dev"/>
|
||||
|
||||
<fr.gouv.etalab.mastodon.helper.ExpandableHeightListView
|
||||
android:id="@+id/lv_contributors"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
android:divider="@null"/>
|
||||
|
||||
<!-- About license -->
|
||||
<LinearLayout
|
||||
|
|
|
@ -15,11 +15,16 @@
|
|||
You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<!-- About app name -->
|
||||
<TextView
|
||||
android:layout_marginTop="10dp"
|
||||
|
@ -40,43 +45,42 @@
|
|||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- About developer -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="5dp">
|
||||
<TextView
|
||||
android:padding="5dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/mastodonC4"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/about_developer"
|
||||
android:textSize="16sp"/>
|
||||
<ListView
|
||||
<fr.gouv.etalab.mastodon.helper.ExpandableHeightListView
|
||||
android:id="@+id/lv_developers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp">
|
||||
android:scrollbars="none"
|
||||
android:divider="@null"/>
|
||||
|
||||
<TextView
|
||||
android:padding="5dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:id="@+id/about_thanks_dev"
|
||||
android:layout_width="match_parent"
|
||||
android:textColor="@color/mastodonC4"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="16sp"
|
||||
android:text="@string/thanks_text_dev"/>
|
||||
<ListView
|
||||
|
||||
<fr.gouv.etalab.mastodon.helper.ExpandableHeightListView
|
||||
android:id="@+id/lv_contributors"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
android:divider="@null"/>
|
||||
|
||||
<!-- About license -->
|
||||
<LinearLayout
|
||||
|
@ -195,3 +199,4 @@
|
|||
android:text="@string/thanks_text"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2017 Thomas Schneider
|
||||
|
||||
This file is a part of Mastalab
|
||||
|
||||
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.
|
||||
|
||||
Mastalab 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 Mastalab; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:card_view="http://schemas.android.com/tools"
|
||||
style="?attr/cardStyle"
|
||||
android:layout_marginTop="10dp"
|
||||
card_view:cardPreventCornerOverlap="true"
|
||||
app:cardUseCompatPadding="true">
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="UseCompoundDrawables">
|
||||
<ImageView
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:id="@+id/account_pp"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
<LinearLayout
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/account_dn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
<TextView
|
||||
android:id="@+id/account_un"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_gravity="center"
|
||||
app:fabSize="mini"
|
||||
android:id="@+id/account_follow"
|
||||
android:textAllCaps="false"
|
||||
android:src="@drawable/ic_user_plus"
|
||||
android:gravity="center"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
|
@ -422,7 +422,7 @@
|
|||
<string name="thanks_text">Danke an Stéphane für das Logo.</string>
|
||||
|
||||
<string name="thanks_text_dev">
|
||||
Danke an @PhotonQyv für seine Beiträge.
|
||||
Danke an:
|
||||
</string>
|
||||
<string name="new_data">Neue Daten verfügbar sind! Wollen Sie Sie anzeigen?</string>
|
||||
<string name="set_bubble_counter">Display-Zähler</string>
|
||||
|
|
|
@ -421,6 +421,6 @@
|
|||
</string>
|
||||
|
||||
<string name="thanks_text_dev">
|
||||
Merci à @PhotonQyv pour ses contributions.
|
||||
Merci à :
|
||||
</string>
|
||||
</resources>
|
|
@ -430,6 +430,6 @@
|
|||
</string>
|
||||
|
||||
<string name="thanks_text_dev">
|
||||
Thank you to @PhotonQyv for his contributions.
|
||||
Thank you to:
|
||||
</string>
|
||||
</resources>
|
Loading…
Reference in New Issue