Merge branch 'communitywiki' into develop

This commit is contained in:
stom79 2018-09-12 09:50:14 +02:00
commit 3748c00f4f
23 changed files with 1128 additions and 3 deletions

View File

@ -161,6 +161,11 @@
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name=".activities.WhoToFollowActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name=".activities.ShowConversationActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"

View File

@ -98,6 +98,7 @@ import fr.gouv.etalab.mastodon.fragments.DisplayListsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayScheduledTootsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplaySearchFragment;
import fr.gouv.etalab.mastodon.fragments.WhoToFollowFragment;
import fr.gouv.etalab.mastodon.helper.CrossActions;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface;
@ -1502,6 +1503,12 @@ public abstract class BaseMainActivity extends BaseActivity
fragmentTag = "FILTERS";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, displayFiltersFragment, fragmentTag).commit();
}else if(id == R.id.nav_who_to_follow){
toot.setVisibility(View.GONE);
WhoToFollowFragment whoToFollowFragment = new WhoToFollowFragment();
fragmentTag = "WHO_TO_FOLLOW";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, whoToFollowFragment, fragmentTag).commit();
}
populateTitleWithTag(fragmentTag, item.getTitle().toString(), item.getItemId());
@ -1511,7 +1518,7 @@ public abstract class BaseMainActivity extends BaseActivity
}
private void populateTitleWithTag(String tag, String title, int index){
public void populateTitleWithTag(String tag, String title, int index){
if( tag == null)
return;
if ( tagTile.get(tag) == null)

View File

@ -0,0 +1,267 @@
/* Copyright 2018 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.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.WhoToFollowAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.TrunkAccount;
import fr.gouv.etalab.mastodon.drawers.WhoToFollowAccountsAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveWhoToFollowInterface;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
/**
* Created by Thomas on 10/09/2018.
* Display Who to follow accounts
*/
public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoToFollowInterface, OnPostActionInterface, OnListActionInterface {
private String item;
private List<String> followedId;
private List<String> accountListId;
private List<String> toFollowdId;
private TextView progess_action;
private List<TrunkAccount> trunkAccounts;
private RelativeLayout mainLoader;
private String listId, listTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar);
break;
case Helper.THEME_DARK:
setTheme(R.style.AppThemeDark_NoActionBar);
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack_NoActionBar);
break;
default:
setTheme(R.style.AppThemeDark_NoActionBar);
}
setContentView(R.layout.activity_who_to_follow);
Toolbar toolbar = findViewById(R.id.toolbar);
progess_action = findViewById(R.id.progess_action);
if( theme == THEME_BLACK)
toolbar.setBackgroundColor(ContextCompat.getColor(WhoToFollowActivity.this, R.color.black));
setSupportActionBar(toolbar);
if( getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mainLoader = findViewById(R.id.loader);
Bundle b = getIntent().getExtras();
if(b != null){
item = b.getString("item");
}
followedId = new ArrayList<>();
String lastDateListNameRefresh = sharedpreferences.getString(Helper.LAST_DATE_LIST_NAME_REFRESH+item, null);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date( ));
cal.add(Calendar.MINUTE, -5);
Date dateAllowed = cal.getTime();
if( lastDateListNameRefresh == null || Helper.stringToDate(WhoToFollowActivity.this, lastDateListNameRefresh).before(dateAllowed)) {
new WhoToFollowAsyncTask(WhoToFollowActivity.this, item, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
mainLoader.setVisibility(View.VISIBLE);
}else {
String lastList = sharedpreferences.getString(Helper.LAST_LIST_NAME + item, null);
List<String> acctString = Helper.restoreArrayFromString(lastList);
if( acctString != null) {
trunkAccounts = new ArrayList<>();
for (String acct : acctString) {
TrunkAccount trunkAccount = new TrunkAccount();
trunkAccount.setAcct(acct);
trunkAccounts.add(trunkAccount);
}
}
displayResults();
}
setTitle(item);
}
private void displayResults(){
mainLoader.setVisibility(View.GONE);
WhoToFollowAccountsAdapter whoToFollowAccountsAdapter;
if( trunkAccounts != null){
ListView lv_list = findViewById(R.id.lv_list);
whoToFollowAccountsAdapter = new WhoToFollowAccountsAdapter(WhoToFollowActivity.this, trunkAccounts);
lv_list.setAdapter(whoToFollowAccountsAdapter);
}else{
Toast.makeText(WhoToFollowActivity.this, R.string.toast_error, Toast.LENGTH_SHORT).show();
return;
}
Button follow_accounts_select = findViewById(R.id.follow_accounts_select);
follow_accounts_select.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(follow_accounts_select.getText().equals(getString(R.string.select_all))){
follow_accounts_select.setText(R.string.unselect_all);
for(TrunkAccount trunkAccount: trunkAccounts){
trunkAccount.setChecked(true);
}
whoToFollowAccountsAdapter.notifyDataSetChanged();
}else {
follow_accounts_select.setText(R.string.select_all);
for(TrunkAccount trunkAccount: trunkAccounts){
trunkAccount.setChecked(false);
}
whoToFollowAccountsAdapter.notifyDataSetChanged();
}
}
});
Button follow_accounts = findViewById(R.id.follow_accounts);
follow_accounts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
follow_accounts.setEnabled(false);
follow_accounts_select.setEnabled(false);
progess_action.setVisibility(View.VISIBLE);
toFollowdId = new ArrayList<>();
for(TrunkAccount trunkAccount: trunkAccounts){
if( trunkAccount.isChecked()){
toFollowdId.add(trunkAccount.getAcct());
}
}
if(toFollowdId.size() > 0){
Account account = new Account();
String[] val = toFollowdId.get(0).split("@");
progess_action.setText(getString(R.string.follow_trunk, toFollowdId.get(0)));
if( val.length > 1){
account.setAcct(val[0]);
account.setInstance(val[1]);
new PostActionAsyncTask(WhoToFollowActivity.this, null, account, API.StatusAction.FOLLOW, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
});
}
@Override
public void onRetrieveWhoToFollowList(List<String> list) {
}
@Override
public void onRetrieveWhoToFollowAccount(List<TrunkAccount> trunkAccounts) {
if( trunkAccounts != null){
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_DATE_LIST_NAME_REFRESH + item, Helper.dateToString(new Date()));
List<String> accounts = new ArrayList<>();
for(TrunkAccount trunkAccount: trunkAccounts)
accounts.add(trunkAccount.getAcct());
editor.putString(Helper.LAST_LIST_NAME + item, Helper.arrayToStringStorage(accounts));
editor.apply();
this.trunkAccounts = trunkAccounts;
}
displayResults();
}
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
followedId.add(userId);
if( followedId != null && followedId.size() >= toFollowdId.size()) {
progess_action.setText(getString(R.string.create_list_trunk, item));
new ManageListsAsyncTask(WhoToFollowActivity.this, ManageListsAsyncTask.action.CREATE_LIST, null, null, null, item, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else {
Account account = new Account();
String[] val = toFollowdId.get(followedId.size()).split("@");
progess_action.setText(getString(R.string.follow_trunk, toFollowdId.get(followedId.size())));
if( val.length > 1){
account.setAcct(val[0]);
account.setInstance(val[1]);
new PostActionAsyncTask(WhoToFollowActivity.this, null, account, API.StatusAction.FOLLOW, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
@Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
List<fr.gouv.etalab.mastodon.client.Entities.List> lists = apiResponse.getLists();
if( lists!= null && lists.size() > 0 && actionType == ManageListsAsyncTask.action.CREATE_LIST){
String[] accountsId = followedId.toArray(new String[0]);
progess_action.setText(R.string.add_account_list_trunk);
listId = lists.get(0).getId();
listTitle = lists.get(0).getTitle();
new ManageListsAsyncTask(WhoToFollowActivity.this, ManageListsAsyncTask.action.ADD_USERS, new String[]{followedId.get(0)}, null, lists.get(0).getId(), null, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
accountListId = new ArrayList<>();
}else if(accountListId != null){
if( accountListId.size() >= followedId.size() -1) {
progess_action.setText(R.string.account_added_list_trunk);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(WhoToFollowActivity.this, ListActivity.class);
Bundle b = new Bundle();
b.putString("id", listId);
b.putString("title", listTitle);
intent.putExtras(b);
startActivity(intent);
finish();
}
}, 1000);
}else {
accountListId.add(followedId.get(accountListId.size()));
progess_action.setText(R.string.adding_account_list_trunk);
String userIdToAdd = followedId.get(accountListId.size());
new ManageListsAsyncTask(WhoToFollowActivity.this, ManageListsAsyncTask.action.ADD_USERS, new String[]{userIdToAdd}, null, listId, null, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
}

View File

@ -16,7 +16,6 @@ package fr.gouv.etalab.mastodon.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import java.lang.ref.WeakReference;
import java.util.List;

View File

@ -0,0 +1,74 @@
/* Copyright 2018 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.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.TrunkAccount;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveWhoToFollowInterface;
/**
* Created by Thomas on 10/09/2018.
* Retrieves who to follow list
*/
public class WhoToFollowAsyncTask extends AsyncTask<Void, Void, Void> {
private String name;
private List<String> response;
private OnRetrieveWhoToFollowInterface listener;
private WeakReference<Context> contextReference;
public WhoToFollowAsyncTask(Context context, String name, OnRetrieveWhoToFollowInterface onRetrieveWhoToFollowInterface){
this.contextReference = new WeakReference<>(context);
this.name = name;
this.listener = onRetrieveWhoToFollowInterface;
}
@Override
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());
if( name != null)
response = api.getCommunitywikiList(name);
else
response = api.getCommunitywikiList();
return null;
}
@Override
protected void onPostExecute(Void result) {
if( name == null)
listener.onRetrieveWhoToFollowList(response);
else {
List<TrunkAccount> trunkAccounts = null;
if(response != null) {
trunkAccounts = new ArrayList<>();
for (String res : response) {
TrunkAccount trunkAccount = new TrunkAccount();
trunkAccount.setAcct(res);
trunkAccounts.add(trunkAccount);
}
}
listener.onRetrieveWhoToFollowAccount(trunkAccounts);
}
}
}

View File

@ -1885,6 +1885,73 @@ public class API {
return actionCode;
}
/**
* Retrieves list from Communitywiki *synchronously*
* @return APIResponse
*/
public ArrayList<String> getCommunitywikiList() {
ArrayList<String> list = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrlCommunitywiki("/list"), 60, null, prefKeyOauthTokenT);
JSONArray jsonArray = new JSONArray(response);
int len = jsonArray.length();
for (int i=0;i<len;i++){
list.add(jsonArray.get(i).toString());
}
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
return list;
}
/**
* Retrieves list from Communitywiki *synchronously*
* @return APIResponse
*/
public ArrayList<String> getCommunitywikiList(String name) {
ArrayList<String> list = new ArrayList<>();
try {
name = URLEncoder.encode(name, "UTF-8");
} catch (UnsupportedEncodingException ignored) {}
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrlCommunitywiki(String.format("/list/%s", name)), 60, null, prefKeyOauthTokenT);
JSONArray jsonArray = new JSONArray(response);
for(int i = 0; i < jsonArray.length(); i++){
try {
list.add(jsonArray.getJSONObject(i).getString("acct"));
} catch (JSONException ignored) {}
}
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
return list;
}
/**
* Parse json response an unique account
* @param resobj JSONObject
@ -2585,4 +2652,8 @@ public class API {
private String getAbsoluteUrlRemoteInstance(String instanceName) {
return "https://" + instanceName + "/api/v1/timelines/public?local=true";
}
private String getAbsoluteUrlCommunitywiki(String action) {
return "https://communitywiki.org/trunk/api/v1" + action;
}
}

View File

@ -0,0 +1,42 @@
package fr.gouv.etalab.mastodon.client.Entities;
/* Copyright 2018 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>. */
/**
* Created by Thomas on 11/09/2018.
* Adapter for Trunk accounts
*/
public class TrunkAccount {
private String acct;
private boolean isChecked = false;
public String getAcct() {
return acct;
}
public void setAcct(String acct) {
this.acct = acct;
}
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean checked) {
isChecked = checked;
}
}

View File

@ -0,0 +1,116 @@
package fr.gouv.etalab.mastodon.drawers;
/* Copyright 2018 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.support.design.widget.FloatingActionButton;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import java.util.List;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.TrunkAccount;
import fr.gouv.etalab.mastodon.helper.CrossActions;
/**
* Created by Thomas on 10/09/2018.
* Adapter for who to follow list
*/
public class WhoToFollowAccountsAdapter extends BaseAdapter {
private List<TrunkAccount> lists;
private LayoutInflater layoutInflater;
private Context context;
public WhoToFollowAccountsAdapter(Context context, List<TrunkAccount> lists){
this.lists = lists;
layoutInflater = LayoutInflater.from(context);
this.context = context;
}
@Override
public int getCount() {
return lists.size();
}
@Override
public Object getItem(int position) {
return lists.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
TrunkAccount trunkAccount = lists.get(position);
final ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.drawer_who_to_follow_account, parent, false);
holder = new ViewHolder();
holder.account_to_follow_check = convertView.findViewById(R.id.account_to_follow_check);
holder.account_to_follow = convertView.findViewById(R.id.account_to_follow);
holder.account_to_follow_profile = convertView.findViewById(R.id.account_to_follow_profile);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.account_to_follow.setText(trunkAccount.getAcct());
holder.account_to_follow_check.setChecked(trunkAccount.isChecked());
holder.account_to_follow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
trunkAccount.setChecked(!trunkAccount.isChecked());
notifyDataSetChanged();
}
});
holder.account_to_follow_profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Account account = new Account();
String[] val = trunkAccount.getAcct().split("@");
if( val.length > 1){
account.setAcct(val[0]);
account.setInstance(val[1]);
CrossActions.doCrossProfile(context, account);
}
}
});
return convertView;
}
private class ViewHolder {
CheckBox account_to_follow_check;
TextView account_to_follow;
FloatingActionButton account_to_follow_profile;
}
}

View File

@ -0,0 +1,124 @@
package fr.gouv.etalab.mastodon.drawers;
/* Copyright 2018 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.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.List;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.WhoToFollowActivity;
import fr.gouv.etalab.mastodon.helper.Helper;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
/**
* Created by Thomas on 10/09/2018.
* Adapter for who to follow list
*/
public class WhoToFollowAdapter extends BaseAdapter {
private List<String> lists;
private LayoutInflater layoutInflater;
private Context context;
public WhoToFollowAdapter(Context context, List<String> lists){
this.lists = lists;
layoutInflater = LayoutInflater.from(context);
this.context = context;
}
@Override
public int getCount() {
return lists.size();
}
@Override
public Object getItem(int position) {
return lists.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
String item = lists.get(position);
final ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.drawer_search, parent, false);
holder = new ViewHolder();
holder.search_title = convertView.findViewById(R.id.search_keyword);
holder.search_container = convertView.findViewById(R.id.search_container);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT){
holder.search_container.setBackgroundResource(R.color.mastodonC3__);
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.black);
}else if(theme == Helper.THEME_DARK){
holder.search_container.setBackgroundResource(R.color.mastodonC1_);
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.dark_text);
}else if(theme == Helper.THEME_BLACK) {
holder.search_container.setBackgroundResource(R.color.black_2);
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.dark_text);
}
Drawable next = ContextCompat.getDrawable(context, R.drawable.ic_keyboard_arrow_right);
holder.search_title.setText(item);
assert next != null;
final float scale = context.getResources().getDisplayMetrics().density;
next.setBounds(0,0,(int) (30 * scale + 0.5f),(int) (30 * scale + 0.5f));
holder.search_title.setCompoundDrawables(null, null, next, null);
holder.search_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, WhoToFollowActivity.class);
Bundle b = new Bundle();
b.putString("item", item);
intent.putExtras(b);
context.startActivity(intent);
}
});
return convertView;
}
private class ViewHolder {
LinearLayout search_container;
TextView search_title;
}
}

View File

@ -0,0 +1,118 @@
package fr.gouv.etalab.mastodon.fragments;
/* Copyright 2018 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.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.WhoToFollowAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.TrunkAccount;
import fr.gouv.etalab.mastodon.drawers.WhoToFollowAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveWhoToFollowInterface;
/**
* Created by Thomas on 10/09/2018.
* Fragment to display who to follow list
*/
public class WhoToFollowFragment extends Fragment implements OnRetrieveWhoToFollowInterface {
private Context context;
private View rootView;
private RelativeLayout mainLoader;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_who_to_follow, container, false);
context = getContext();
mainLoader = rootView.findViewById(R.id.loader);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String lastDateListRefresh = sharedpreferences.getString(Helper.LAST_DATE_LIST_REFRESH, null);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.MINUTE, -15);
Date dateAllowed = cal.getTime();
if (lastDateListRefresh == null || Helper.stringToDate(context, lastDateListRefresh).before(dateAllowed)){
mainLoader.setVisibility(View.VISIBLE);
new WhoToFollowAsyncTask(context, null, WhoToFollowFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else {
String lastList = sharedpreferences.getString(Helper.LAST_LIST, null);
List<String> list = Helper.restoreArrayFromString(lastList);
displayResults(list);
}
return rootView;
}
@Override
public void onCreate(Bundle saveInstance)
{
super.onCreate(saveInstance);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
this.context = context;
}
private void displayResults(List<String> list){
mainLoader.setVisibility(View.GONE);
if( list != null){
ListView lv_list = rootView.findViewById(R.id.lv_list);
WhoToFollowAdapter whoToFollowAdapter = new WhoToFollowAdapter(context, list);
lv_list.setAdapter(whoToFollowAdapter);
}else{
Toast.makeText(context, R.string.toast_error, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onRetrieveWhoToFollowList(List<String> list) {
if( list != null){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_DATE_LIST_REFRESH, Helper.dateToString(new Date()));
editor.putString(Helper.LAST_LIST, Helper.arrayToStringStorage(list));
editor.apply();
}
displayResults(list);
}
@Override
public void onRetrieveWhoToFollowAccount(List<TrunkAccount> trunkAccounts) {
}
}

View File

@ -217,6 +217,11 @@ public class Helper {
public static final String SEARCH_URL = "search_url";
public static final String CLIP_BOARD = "clipboard";
public static final String INSTANCE_NAME = "instance_name";
public static final String LAST_DATE_LIST_REFRESH = "last_date_list_refresh";
public static final String LAST_DATE_LIST_NAME_REFRESH = "last_date_list_name_refresh";
public static final String LAST_LIST = "last_list";
public static final String LAST_LIST_NAME = "last_list_name";
//Notifications
public static final int NOTIFICATION_INTENT = 1;
public static final int HOME_TIMELINE_INTENT = 2;
@ -353,7 +358,6 @@ public class Helper {
public static final Pattern twitterPattern = Pattern.compile("((@[\\w]+)@twitter\\.com)");
private static final Pattern mentionPattern = Pattern.compile("(@[\\w]+)");
//Event Type
public enum EventStreaming{
UPDATE,
@ -1658,6 +1662,30 @@ public class Helper {
}
/**
* Serialized a List<String>
* @param list List<String> to serialize
* @return String serialized List
*/
public static String arrayToStringStorage(List<String> list){
Gson gson = new Gson();
return gson.toJson(list);
}
/**
* Unserialized a List<String>
* @param serializedArray String serialized array
* @return List<String> list
*/
public static List<String> restoreArrayFromString(String serializedArray){
Gson gson = new Gson();
try {
return gson.fromJson(serializedArray, List.class);
}catch (Exception e){
return null;
}
}
/**
* Serialized an Application class
* @param application Application to serialize

View File

@ -0,0 +1,29 @@
/* Copyright 2018 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.List;
import fr.gouv.etalab.mastodon.client.Entities.TrunkAccount;
/**
* Created by Thomas on 10/09/2018.
* Interface for who to follow
*/
public interface OnRetrieveWhoToFollowInterface {
void onRetrieveWhoToFollowList(List<String> list);
void onRetrieveWhoToFollowAccount(List<TrunkAccount> trunkAccounts);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

View File

@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 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.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="fr.gouv.etalab.mastodon.activities.HashTagActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
android:theme="@style/AppThemeDark_NoActionBar"
app:popupTheme="?attr/popupOverlay"/>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingLeft="@dimen/fab_margin"
android:paddingRight="@dimen/fab_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Listview who to follow -->
<ListView
android:id="@+id/lv_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:divider="@null"
>
</ListView>
<RelativeLayout
android:id="@+id/no_action"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:padding="10dp"
android:gravity="center"
android:textSize="25sp"
android:layout_gravity="center"
android:textStyle="italic|bold"
android:typeface="serif"
android:text="@string/action_who_to_follow_empty_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<!-- 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>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:orientation="horizontal">
<Button
android:id="@+id/follow_accounts_select"
android:gravity="center"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:text="@string/select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/follow_accounts"
android:gravity="center"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:text="@string/follow_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView
android:id="@+id/progess_action"
android:visibility="gone"
android:background="?colorPrimaryDark"
android:layout_gravity="bottom"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="50dp" />
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 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>.
-->
<LinearLayout 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:tools="http://schemas.android.com/tools"
android:id="@+id/search_container"
android:divider="?android:dividerHorizontal"
android:showDividers="end"
android:paddingTop="5dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingBottom="5dp"
android:orientation="horizontal">
<CheckBox
android:id="@+id/account_to_follow_check"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_height="wrap_content" />
<TextView
android:layout_marginLeft="10dp"
android:id="@+id/account_to_follow"
android:textSize="16sp"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="10dp" />
<android.support.design.widget.FloatingActionButton
android:layout_width="30dp"
app:fabSize="mini"
android:layout_margin="5dp"
android:id="@+id/account_to_follow_profile"
app:backgroundTint="?colorAccent"
app:srcCompat="@drawable/ic_remove_red_eye"
tools:ignore="VectorDrawableCompat"
android:layout_height="30dp"/>
</LinearLayout>

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 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>.
-->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="@dimen/fab_margin"
android:paddingRight="@dimen/fab_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Listview who to follow -->
<ListView
android:id="@+id/lv_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:divider="@null"
>
</ListView>
<!-- 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>
</RelativeLayout>

View File

@ -39,6 +39,10 @@
android:id="@+id/nav_follow_request"
android:icon="@drawable/ic_group_add"
android:title="@string/follow_request" />
<item
android:id="@+id/nav_who_to_follow"
android:icon="@drawable/ic_people"
android:title="@string/how_to_follow" />
</group>
</menu>
</item>

View File

@ -585,6 +585,16 @@
<string name="action_filter_delete">Delete filter?</string>
<string name="action_update_filter">Update filter</string>
<string name="action_filter_create">Create filter</string>
<string name="how_to_follow">Who to follow</string>
<string name="action_who_to_follow_empty_content">There is no accounts listed for the moment!</string>
<string name="follow_account">Follow</string>
<string name="select_all">Select all</string>
<string name="unselect_all">Unselect all</string>
<string name="follow_trunk">%s is followed!</string>
<string name="create_list_trunk">Creating the list %s</string>
<string name="add_account_list_trunk">Adding accounts to the list</string>
<string name="account_added_list_trunk">Accounts were added to the list</string>
<string name="adding_account_list_trunk">Adding accounts to the list</string>
<string-array translatable="false" name="proxy_type_choice">