Adds layouts
This commit is contained in:
parent
26987876d1
commit
d8bb009dc3
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
/* 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.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
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.drawers.WhoToFollowAccountsAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
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 {
|
||||
|
||||
|
||||
|
||||
private String item;
|
||||
|
||||
@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);
|
||||
if( theme == THEME_BLACK)
|
||||
toolbar.setBackgroundColor(ContextCompat.getColor(WhoToFollowActivity.this, R.color.black));
|
||||
setSupportActionBar(toolbar);
|
||||
if( getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
RelativeLayout mainLoader = findViewById(R.id.loader);
|
||||
Bundle b = getIntent().getExtras();
|
||||
if(b != null){
|
||||
item = b.getString("item");
|
||||
}
|
||||
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).after(dateAllowed))
|
||||
new WhoToFollowAsyncTask(WhoToFollowActivity.this, item, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else {
|
||||
String lastList = sharedpreferences.getString(Helper.LAST_LIST_NAME + item, null);
|
||||
List<String> list = Helper.restoreArrayFromString(lastList);
|
||||
displayResults(list);
|
||||
}
|
||||
mainLoader.setVisibility(View.VISIBLE);
|
||||
setTitle(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrieveWhoToFollow(List<String> list) {
|
||||
if( list != 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()));
|
||||
editor.putString(Helper.LAST_LIST_NAME + item, Helper.arrayToStringStorage(list));
|
||||
editor.apply();
|
||||
}
|
||||
displayResults(list);
|
||||
}
|
||||
|
||||
private void displayResults(List<String> list){
|
||||
|
||||
RelativeLayout mainLoader = findViewById(R.id.loader);
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
if( list != null){
|
||||
ListView lv_list = findViewById(R.id.lv_list);
|
||||
WhoToFollowAccountsAdapter whoToFollowAccountsAdapter = new WhoToFollowAccountsAdapter(WhoToFollowActivity.this, list);
|
||||
lv_list.setAdapter(whoToFollowAccountsAdapter);
|
||||
}else{
|
||||
Toast.makeText(WhoToFollowActivity.this, R.string.toast_error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/* 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.List;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
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) {
|
||||
listener.onRetrieveWhoToFollow(response);
|
||||
}
|
||||
|
||||
}
|
|
@ -1893,7 +1893,7 @@ public class API {
|
|||
* Retrieves list from Communitywiki *synchronously*
|
||||
* @return APIResponse
|
||||
*/
|
||||
private ArrayList<String> getCommunitywikiList() {
|
||||
public ArrayList<String> getCommunitywikiList() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
|
@ -1923,7 +1923,7 @@ public class API {
|
|||
* Retrieves list from Communitywiki *synchronously*
|
||||
* @return APIResponse
|
||||
*/
|
||||
private ArrayList<String> getCommunitywikiList(String name) {
|
||||
public ArrayList<String> getCommunitywikiList(String name) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
try {
|
||||
name = URLEncoder.encode(name, "UTF-8");
|
||||
|
@ -1935,7 +1935,7 @@ public class API {
|
|||
JSONArray jsonArray = new JSONArray(response);
|
||||
for(int i = 0; i < jsonArray.length(); i++){
|
||||
try {
|
||||
list.add(jsonArray.getString(i));
|
||||
list.add(jsonArray.getJSONObject(i).getString("acct"));
|
||||
} catch (JSONException ignored) {}
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
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.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.helper.CrossActions;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 10/09/2018.
|
||||
* Adapter for who to follow list
|
||||
*/
|
||||
public class WhoToFollowAccountsAdapter extends BaseAdapter {
|
||||
|
||||
private List<String> lists;
|
||||
private LayoutInflater layoutInflater;
|
||||
private Context context;
|
||||
|
||||
public WhoToFollowAccountsAdapter(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_who_to_follow_account, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.account_to_follow = convertView.findViewById(R.id.account_to_follow);
|
||||
holder.account_to_follow = convertView.findViewById(R.id.account_to_follow);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
holder.account_to_follow.setText(item);
|
||||
|
||||
holder.account_to_follow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Account account = new Account();
|
||||
String[] val = item.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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
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.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;
|
||||
|
||||
@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();
|
||||
RelativeLayout 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).after(dateAllowed))
|
||||
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);
|
||||
}
|
||||
mainLoader.setVisibility(View.VISIBLE);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle saveInstance)
|
||||
{
|
||||
super.onCreate(saveInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveWhoToFollow(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);
|
||||
}
|
||||
|
||||
private void displayResults(List<String> list){
|
||||
|
||||
RelativeLayout mainLoader = rootView.findViewById(R.id.loader);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
@ -1657,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
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/* 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;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 10/09/2018.
|
||||
* Interface for who to follow
|
||||
*/
|
||||
public interface OnRetrieveWhoToFollowInterface {
|
||||
void onRetrieveWhoToFollow(List<String> list);
|
||||
}
|
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 |
|
@ -0,0 +1,95 @@
|
|||
<?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_lists_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>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</android.support.v4.widget.DrawerLayout>
|
|
@ -0,0 +1,46 @@
|
|||
<?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"
|
||||
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" />
|
||||
</LinearLayout>
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
|
@ -585,6 +585,7 @@
|
|||
<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-array translatable="false" name="proxy_type_choice">
|
||||
|
|
Loading…
Reference in New Issue